]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RL78_multiple_IAR/main.c
be5c7a47658a2a3ff509761142596e9d208f6703
[freertos] / FreeRTOS / Demo / RL78_multiple_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.0.1\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup and FreeRTOS hook functions.\r
38  *\r
39  * This project does not provide an example of how to write an RTOS compatible\r
40  * interrupt service routine (other than the tick interrupt itself), so this\r
41  * file contains the function vAnExampleISR_C_Handler() as a dummy example (that\r
42  * is not actually installed) that can be used as a reference.  Also see the\r
43  * file ExampleISR.s87, and the documentation page for this demo on the\r
44  * FreeRTOS.org website for full instructions.\r
45  *\r
46  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
47  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
48  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
49  *\r
50  */\r
51 \r
52 /* Scheduler include files. */\r
53 #include "FreeRTOS.h"\r
54 #include "task.h"\r
55 #include "semphr.h"\r
56 \r
57 /* Hardware includes. */\r
58 #include "demo_specific_io.h"\r
59 \r
60 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
61 or 0 to run the more comprehensive test and demo application. */\r
62 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
63 \r
64 /*-----------------------------------------------------------*/\r
65 \r
66 /*\r
67  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
68  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
69  */\r
70 extern void main_blinky( void );\r
71 extern void main_full( void );\r
72 \r
73 /*\r
74  * This function is called from the C startup routine to setup the processor -\r
75  * in particular the clock source.\r
76  */\r
77 int __low_level_init(void);\r
78 \r
79 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
80 within this file. */\r
81 void vApplicationMallocFailedHook( void );\r
82 void vApplicationIdleHook( void );\r
83 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
84 void vApplicationTickHook( void );\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* This variable is not actually used, but provided to allow an example of how\r
89 to write an ISR to be included in this file. */\r
90 static SemaphoreHandle_t xSemaphore = NULL;\r
91 \r
92 /* RL78 Option Byte Definition. Watchdog disabled, LVI enabled, OCD interface\r
93 enabled. */\r
94 __root __far const unsigned char OptionByte[] @ 0x00C0 =\r
95 {\r
96         0x6eU, 0xffU, 0xe8U, 0x85U\r
97 };\r
98 \r
99 /* Security byte definition */\r
100 __root __far const unsigned char ucSecurityCode[]  @ 0x00C4 =\r
101 {\r
102         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
103 };\r
104 \r
105 /*-----------------------------------------------------------*/\r
106 \r
107 void main( void )\r
108 {\r
109         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
110         of this file. */\r
111         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
112         {\r
113                 main_blinky();\r
114         }\r
115         #else\r
116         {\r
117                 main_full();\r
118         }\r
119         #endif\r
120 }\r
121 /*-----------------------------------------------------------*/\r
122 \r
123 void vAnExampleISR_C_Handler( void )\r
124 {\r
125         /*\r
126          * This demo does not include a functional interrupt service routine - so\r
127          * this dummy handler (which is not actually installed) is provided as an\r
128          * example of how an ISR that needs to cause a context switch needs to be\r
129          * implemented.  ISRs that do not cause a context switch have no special\r
130          * requirements and can be written as per the compiler documentation.\r
131          *\r
132          * This C function is called from a wrapper function that is implemented\r
133          * in assembly code.  See vANExampleISR_ASM_Wrapper() in ExampleISR.s87.\r
134          * Also see the documentation page for this demo on the FreeRTOS.org website\r
135          * for full instructions.\r
136          */\r
137 short sHigherPriorityTaskWoken = pdFALSE;\r
138 \r
139         /* Handler code goes here...*/\r
140 \r
141         /* For purposes of demonstration, assume at some point the hander calls\r
142         xSemaphoreGiveFromISR().*/\r
143         xSemaphoreGiveFromISR( xSemaphore, &sHigherPriorityTaskWoken );\r
144 \r
145         /* If giving the semaphore unblocked a task, and the unblocked task has a\r
146         priority higher than or equal to the currently running task, then\r
147         sHigherPriorityTaskWoken will have been set to pdTRUE internally within the\r
148         xSemaphoreGiveFromISR() function.  Passing a pdTRUE     value to\r
149         portYIELD_FROM_ISR() will cause this interrupt to return directly to the\r
150         higher priority unblocked task. */\r
151         portYIELD_FROM_ISR( sHigherPriorityTaskWoken );\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 int __low_level_init(void)\r
156 {\r
157         portDISABLE_INTERRUPTS();\r
158 \r
159         /* Set fMX */\r
160         CMC = 0x00;\r
161         MSTOP = 1U;\r
162 \r
163         /* Set fMAIN */\r
164         MCM0 = 0U;\r
165 \r
166         /* Set fSUB */\r
167         XTSTOP = 1U;\r
168         OSMC = 0x10;\r
169 \r
170         /* Set fCLK */\r
171         CSS = 0U;\r
172 \r
173         /* Set fIH */\r
174         HIOSTOP = 0U;\r
175 \r
176         /* LED port initialization. */\r
177         LED_INIT();\r
178 \r
179         return pdTRUE;\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 void vApplicationMallocFailedHook( void )\r
184 {\r
185         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
186         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
187         internally by FreeRTOS API functions that create tasks, queues, software\r
188         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
189         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
190         taskDISABLE_INTERRUPTS();\r
191         for( ;; );\r
192 }\r
193 /*-----------------------------------------------------------*/\r
194 \r
195 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
196 {\r
197         ( void ) pcTaskName;\r
198         ( void ) pxTask;\r
199 \r
200         /* Run time stack overflow checking is performed if\r
201         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
202         function is called if a stack overflow is detected. */\r
203         taskDISABLE_INTERRUPTS();\r
204         for( ;; );\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 void vApplicationIdleHook( void )\r
209 {\r
210 volatile size_t xFreeHeapSpace;\r
211 \r
212         /* This is just a trivial example of an idle hook.  It is called on each\r
213         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
214         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
215         memory management section on the http://www.FreeRTOS.org web site for memory\r
216         management options.  If there is a lot of heap memory free then the\r
217         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
218         RAM. */\r
219         xFreeHeapSpace = xPortGetFreeHeapSize();\r
220 \r
221         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
222         ( void ) xFreeHeapSpace;\r
223 }\r
224 \r
225 \r