]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/main.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / CORTEX_EFMG890F128_IAR / main.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 \r
67 /*\r
68  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
69  * documentation provides more details of the standard demo application tasks.\r
70  * In addition to the standard demo tasks, the following tasks and tests are\r
71  * defined and/or created within this file:\r
72  *\r
73  * "LCD test" task - the LCD task writes a continually repeating series of patterns\r
74  * to the LCD display.\r
75  *\r
76  * "LED test" task -  This is a very simple task that just turns on user LEDs\r
77  * 8 to 15 in turn, before turning them off again.\r
78  *\r
79  * "Check task" - The check task only runs every five seconds but has the highest\r
80  * priority so is guaranteed to get processing time.  Its main job is to inspect\r
81  * all the other standard demo tasks to ensure they are executing without error.\r
82  * The Check task will toggle LED 0 every five seconds while no errors exist,\r
83  * with the toggle frequency increasing to 200ms should an error be detected in\r
84  * any other task.\r
85  *\r
86  * Both the check task and the idle task place the processor into energy saving\r
87  * mode 1, which will be exited following each tick interrupt.  The check task\r
88  * is the highest priority task in the system, so while it is executing no other\r
89  * task will execute.  If the check task places the processor into a low power\r
90  * mode without blocking then the energy consumption as viewed on the Energy\r
91  * Micro Gecko board will go down noticeably as in effect no tasks will be running.\r
92  * The check task places the processor into low power mode for two out of every\r
93  * five seconds.  The current use of low power modes is very basic.  Future\r
94  * FreeRTOS releases will aim to make significant improvements.\r
95  *\r
96  */\r
97  /* Scheduler includes. */\r
98 #include "FreeRTOS.h"\r
99 #include "croutine.h"\r
100 #include "task.h"\r
101 #include "queue.h"\r
102 #include "semphr.h"\r
103 \r
104 /* Common demo application includes. */\r
105 #include "partest.h"\r
106 #include "GenQTest.h"\r
107 #include "QPeek.h"\r
108 #include "recmutex.h"\r
109 #include "semtest.h"\r
110 \r
111 /* Demo application includes. */\r
112 #include "lcdcontroller.h"\r
113 #include "ledtest.h"\r
114 #include "lcdtest.h"\r
115 #include "chip.h"\r
116 \r
117 /* Task priorities. */\r
118 #define mainLCD_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
119 #define mainLED_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 2 )\r
120 #define mainGEN_Q_TASK_PRIORITY                 ( tskIDLE_PRIORITY )\r
121 #define mainSEMAPHORE_TASK_PRIORITY             ( tskIDLE_PRIORITY + 1 )\r
122 #define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )\r
123 \r
124 /* A period of two seconds, adjusted to use the tick frequency. */\r
125 #define mainTWO_SECONDS                                 ( 2000 / portTICK_PERIOD_MS )\r
126 \r
127 /* The length of the delay between each cycle of the check task when an error\r
128 has / has not been detected. */\r
129 #define mainNO_ERROR_CHECK_FREQUENCY    ( 5000 / portTICK_PERIOD_MS )\r
130 #define mainERROR_CHECK_FREQUENCY               ( 200 / portTICK_PERIOD_MS )\r
131 \r
132 /* The LED that is toggled by the check task.  The rate of the toggle indicates\r
133 whether or not an error has been found, as defined by the\r
134 mainNO_ERROR_CHECK_FREQUENCY and mainERROR_CHECK_FREQUENCY definitions above. */\r
135 #define mainCHECK_LED                                   ( 0 )\r
136 \r
137 /*-----------------------------------------------------------*/\r
138 \r
139 /*\r
140  * Configure the hardware as required by the demo.\r
141  */\r
142 static void prvSetupHardware( void );\r
143 \r
144 /*\r
145  * The check task as described at the top of this file.\r
146  */\r
147 static void prvCheckTask( void *pvParameters );\r
148 \r
149 /*\r
150  * Put the CPU into the least low power low power mode.\r
151  */\r
152 static void prvLowPowerMode1( void );\r
153 \r
154 /*-----------------------------------------------------------*/\r
155 \r
156 int main( void )\r
157 {\r
158         /* Perform the necessary hardware configuration. */\r
159         prvSetupHardware();\r
160 \r
161         /* Create the task that writes various text and patterns to the LCD. */\r
162         xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
163 \r
164         /* Create a task that writes to LEDs 8 to 15. */\r
165         xTaskCreate( vLEDTask, "LEDTask", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );\r
166 \r
167         /* Create some of the standard demo tasks.  These just test the port and\r
168         demonstrate how the FreeRTOS API can be used.  They do not provide any\r
169         specific functionality. */\r
170         vStartGenericQueueTasks( mainGEN_Q_TASK_PRIORITY );\r
171         vStartQueuePeekTasks();\r
172         vStartRecursiveMutexTasks();\r
173         vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY );\r
174         \r
175         /* Create the check task as described at the top of this file. */\r
176         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
177         \r
178         /* Start the scheduler. */\r
179         vTaskStartScheduler();\r
180         \r
181         /* The scheduler should now be running the tasks so the following code should\r
182         never be reached.  If it is reached then there was insufficient heap space\r
183         for the idle task to be created.  In this case the heap size is set by\r
184         configTOTAL_HEAP_SIZE in FreeRTOSConfig.h. */\r
185         for( ;; );\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 void vApplicationIdleHook( void )\r
190 {\r
191         /* Use the idle task to place the CPU into a low power mode.  Greater power\r
192         saving could be achieved by not including any demo tasks that never block. */\r
193         prvLowPowerMode1();\r
194 }\r
195 /*-----------------------------------------------------------*/\r
196 \r
197 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
198 {\r
199         /* This function will be called if a task overflows its stack, if\r
200         configCHECK_FOR_STACK_OVERFLOW != 0.  It might be that the function\r
201         parameters have been corrupted, depending on the severity of the stack\r
202         overflow.  When this is the case pxCurrentTCB can be inspected in the\r
203         debugger to find the offending task. */\r
204         for( ;; );\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 static void prvCheckTask( void *pvParameters )\r
209 {\r
210 TickType_t xLastExecutionTime, xFrequency = mainNO_ERROR_CHECK_FREQUENCY;\r
211 long lCount;\r
212 \r
213         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
214         works correctly. */\r
215         xLastExecutionTime = xTaskGetTickCount();\r
216 \r
217         for( ;; )\r
218         {\r
219                 /* Perform this check at a frequency that indicates whether or not an\r
220                 error has been found. */\r
221                 vTaskDelayUntil( &xLastExecutionTime, xFrequency );\r
222                 \r
223                 /* Check all the other tasks are running without error. */\r
224                 if( xAreGenericQueueTasksStillRunning() != pdPASS )\r
225                 {\r
226                         xFrequency = mainERROR_CHECK_FREQUENCY;\r
227                 }\r
228                 \r
229                 if( xAreQueuePeekTasksStillRunning() != pdPASS )\r
230                 {\r
231                         xFrequency = mainERROR_CHECK_FREQUENCY;\r
232                 }\r
233                 \r
234                 if( xAreRecursiveMutexTasksStillRunning() != pdPASS )\r
235                 {\r
236                         xFrequency = mainERROR_CHECK_FREQUENCY;\r
237                 }\r
238 \r
239                 if( xAreSemaphoreTasksStillRunning() != pdPASS )\r
240                 {\r
241                         xFrequency = mainERROR_CHECK_FREQUENCY;\r
242                 }\r
243                 \r
244                 /* Toggle the LED to show that the check hook function is running.\r
245                 The toggle freequency will increase if an error has been found in any\r
246                 task. */\r
247                 vParTestToggleLED( mainCHECK_LED );\r
248                 \r
249                 /* Just loop around putting the processor into low power mode 1 for\r
250                 a while.  This is the highest priority task, and this loop does not\r
251                 cause it to block, so it will remain as the running task.  Each time it\r
252                 runs for the next two seconds it will simply put the processor to sleep.\r
253                 No other task will run so nothing else will happen.  This periodic two\r
254                 seconds of lower power should be viewable using the Advanced Energy\r
255                 Monitor on the Energy Micro Gecko board. */\r
256                 for( lCount = 0; lCount < mainTWO_SECONDS; lCount++ )\r
257                 {\r
258                         prvLowPowerMode1();\r
259                 }\r
260         }\r
261 }\r
262 /*-----------------------------------------------------------*/\r
263 \r
264 static void prvSetupHardware( void )\r
265 {\r
266         /* Initialise the LEDs. */\r
267         vParTestInitialise();\r
268 \r
269         /* Configure the LCD. */\r
270         LCD_Init( LCD );\r
271 }\r
272 /*-----------------------------------------------------------*/\r
273 \r
274 static void prvLowPowerMode1( void )\r
275 {\r
276         /* Clear SLEEPDEEP for EM1 */\r
277         SCB->SCR &= ~( 1 << SCB_SCR_SLEEPDEEP_Pos );\r
278         \r
279         /* Power down. */\r
280         __DSB();\r
281         __WFI();\r
282 }\r
283 \r
284 \r