]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A2F200_IAR_and_Keil/main-full.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_A2F200_IAR_and_Keil / main-full.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /*\r
30  * main-blinky.c is included when the "Blinky" build configuration is used.\r
31  * main-full.c is included when the "Full" build configuration is used.\r
32  *\r
33  * main-full.c (this file) defines a comprehensive demo that creates many\r
34  * tasks, queues, semaphores and timers.  It also demonstrates how Cortex-M3\r
35  * interrupts can interact with FreeRTOS tasks/timers, and implements a simple\r
36  * and small interactive web server.\r
37  *\r
38  * This project runs on the SmartFusion A2F-EVAL-KIT evaluation board, which\r
39  * is populated with an A2F200M3F SmartFusion mixed signal FPGA.  The A2F200M3F\r
40  * incorporates a Cortex-M3 microcontroller.\r
41  *\r
42  * The main() Function:\r
43  * main() creates two demo specific software timers, one demo specific queue,\r
44  * and three demo specific tasks.  It then creates a whole host of 'standard\r
45  * demo' tasks/queues/semaphores, before starting the scheduler.  The demo\r
46  * specific tasks and timers are described in the comments here.  The standard\r
47  * demo tasks are described on the FreeRTOS.org web site.\r
48  *\r
49  * The standard demo tasks provide no specific functionality.  They are\r
50  * included to both test the FreeRTOS port, and provide examples of how the\r
51  * various FreeRTOS API functions can be used.\r
52  *\r
53  * The Demo Specific Queue Send Task:\r
54  * The queue send task is implemented by the prvQueueSendTask() function in\r
55  * this file.  prvQueueSendTask() sits in a loop that causes it to repeatedly\r
56  * block for 200 milliseconds, before sending the value 100 to the queue that\r
57  * was created within main().  Once the value is sent, the task loops back\r
58  * around to block for another 200 milliseconds.\r
59  *\r
60  * The Demo Specific Queue Receive Task:\r
61  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
62  * in this file.  prvQueueReceiveTask() sits in a loop that causes it to\r
63  * repeatedly attempt to read data from the queue that was created within\r
64  * main().  When data is received, the task checks the value of the data, and\r
65  * if the value equals the expected 100, toggles the green LED.  The 'block\r
66  * time' parameter passed to the queue receive function specifies that the task\r
67  * should be held in the Blocked state indefinitely to wait for data to be\r
68  * available on the queue.  The queue receive task will only leave the Blocked\r
69  * state when the queue send task writes to the queue.  As the queue send task\r
70  * writes to the queue every 200 milliseconds, the queue receive task leaves\r
71  * the Blocked state every 200 milliseconds, and therefore toggles the LED\r
72  * every 200 milliseconds.\r
73  *\r
74  * The Demo Specific OLED Task:\r
75  * The OLED task is a very simple task that just scrolls a message across the\r
76  * OLED.  Ideally this would be done in a timer, but the OLED driver accesses\r
77  * the I2C which is time consuming.\r
78  *\r
79  * The Demo Specific LED Software Timer and the Button Interrupt:\r
80  * The user button SW1 is configured to generate an interrupt each time it is\r
81  * pressed.  The interrupt service routine switches an LED on, and resets the\r
82  * LED software timer.  The LED timer has a 5000 millisecond (5 second) period,\r
83  * and uses a callback function that is defined to just turn the LED off again.\r
84  * Therefore, pressing the user button will turn the LED on, and the LED will\r
85  * remain on until a full five seconds pass without the button being pressed.\r
86  *\r
87  * The Demo Specific "Check" Callback Function:\r
88  * This is called each time the 'check' timer expires.  The check timer\r
89  * callback function inspects all the standard demo tasks to see if they are\r
90  * all executing as expected.  The check timer is initially configured to\r
91  * expire every three seconds, but will shorted this to every 500ms if an error\r
92  * is ever discovered.  The check timer callback toggles the LED defined by\r
93  * the mainCHECK_LED definition each time it executes.  Therefore, if LED\r
94  * mainCHECK_LED is toggling every three seconds, then no error have been found.\r
95  * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has\r
96  * been found.  The task in which the error was discovered is displayed at the\r
97  * bottom of the "task stats" page that is served by the embedded web server.\r
98  *\r
99  * The Demo Specific Idle Hook Function:\r
100  * The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
101  * space that is remaining (see vApplicationIdleHook() defined in this file).\r
102  *\r
103  * The Web Server Task:\r
104  * The IP address used by the SmartFusion target is configured by the\r
105  * definitions configIP_ADDR0 to configIP_ADDR3, which are located in the\r
106  * FreeRTOSConfig.h header file.  See the documentation page for this example\r
107  * on the http://www.FreeRTOS.org web site for further connection information.\r
108  */\r
109 \r
110 /* Kernel includes. */\r
111 #include "FreeRTOS.h"\r
112 #include "task.h"\r
113 #include "queue.h"\r
114 #include "timers.h"\r
115 \r
116 /* Microsemi drivers/libraries includes. */\r
117 #include "mss_gpio.h"\r
118 #include "mss_watchdog.h"\r
119 #include "mss_timer.h"\r
120 #include "mss_ace.h"\r
121 #include "oled.h"\r
122 \r
123 /* Common demo includes. */\r
124 #include "partest.h"\r
125 #include "flash.h"\r
126 #include "BlockQ.h"\r
127 #include "death.h"\r
128 #include "blocktim.h"\r
129 #include "semtest.h"\r
130 #include "GenQTest.h"\r
131 #include "QPeek.h"\r
132 #include "recmutex.h"\r
133 #include "TimerDemo.h"\r
134 \r
135 /* Priorities at which the tasks are created. */\r
136 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
137 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
138 \r
139 /* The rate at which data is sent to the queue, specified in milliseconds, and\r
140 converted to ticks using the portTICK_PERIOD_MS constant. */\r
141 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 200 / portTICK_PERIOD_MS )\r
142 \r
143 /* The number of items the queue can hold.  This is 1 as the receive task\r
144 will remove items as they are added, meaning the send task should always find\r
145 the queue empty. */\r
146 #define mainQUEUE_LENGTH                        ( 1 )\r
147 \r
148 /* The LED toggled by the check timer callback function. */\r
149 #define mainCHECK_LED                           0x07UL\r
150 \r
151 /* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
152 #define mainTIMER_CONTROLLED_LED        0x06UL\r
153 \r
154 /* The LED toggle by the queue receive task. */\r
155 #define mainTASK_CONTROLLED_LED         0x05UL\r
156 \r
157 /* Constant used by the standard timer test functions. */\r
158 #define mainTIMER_TEST_PERIOD           ( 50 )\r
159 \r
160 /* Priorities used by the various different tasks. */\r
161 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
162 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
163 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
164 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
165 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
166 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
167 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
168 #define mainOLED_TASK_PRIORITY          ( tskIDLE_PRIORITY + 1 )\r
169 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
170 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
171 \r
172 /* The WEB server uses string handling functions, which in turn use a bit more\r
173 stack than most of the other tasks. */\r
174 #define mainuIP_STACK_SIZE                      ( configMINIMAL_STACK_SIZE * 3 )\r
175 \r
176 /* The period at which the check timer will expire, in ms, provided no errors\r
177 have been reported by any of the standard demo tasks. */\r
178 #define mainCHECK_TIMER_PERIOD_MS       ( 3000UL / portTICK_PERIOD_MS )\r
179 \r
180 /* The period at which the OLED timer will expire.  Each time it expires, it's\r
181 callback function updates the OLED text. */\r
182 #define mainOLED_PERIOD_MS                      ( 75UL / portTICK_PERIOD_MS )\r
183 \r
184 /* The period at which the check timer will expire, in ms, if an error has been\r
185 reported in one of the standard demo tasks. */\r
186 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 500UL / portTICK_PERIOD_MS )\r
187 \r
188 /* The LED will remain on until the button has not been pushed for a full\r
189 5000ms. */\r
190 #define mainLED_TIMER_PERIOD_MS         ( 5000UL / portTICK_PERIOD_MS )\r
191 \r
192 /* A zero block time. */\r
193 #define mainDONT_BLOCK                          ( 0UL )\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 /*\r
197  * Setup the NVIC, LED outputs, and button inputs.\r
198  */\r
199 static void prvSetupHardware( void );\r
200 \r
201 /*\r
202  * The tasks as described in the comments at the top of this file.\r
203  */\r
204 static void prvQueueReceiveTask( void *pvParameters );\r
205 static void prvQueueSendTask( void *pvParameters );\r
206 \r
207 /*\r
208  * The LED timer callback function.  This does nothing but switch the red LED\r
209  * off.\r
210  */\r
211 static void prvLEDTimerCallback( TimerHandle_t xTimer );\r
212 \r
213 /*\r
214  * The check timer callback function, as described at the top of this file.\r
215  */\r
216 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
217 \r
218 /*\r
219  * This is not a 'standard' partest function, so the prototype is not in\r
220  * partest.h, and is instead included here.\r
221  */\r
222 void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );\r
223 \r
224 /*\r
225  * Contains the implementation of the WEB server.\r
226  */\r
227 extern void vuIP_Task( void *pvParameters );\r
228 \r
229 /*\r
230  * A very simply task that does nothing but scroll the OLED display.  Ideally\r
231  * this would be done within a timer, but it accesses the I2C port which is\r
232  * time consuming.\r
233  */\r
234 static void prvOLEDTask( void * pvParameters);\r
235 \r
236 /*-----------------------------------------------------------*/\r
237 \r
238 /* The queue used by both application specific demo tasks defined in this file. */\r
239 static QueueHandle_t xQueue = NULL;\r
240 \r
241 /* The LED software timer.  This uses prvLEDTimerCallback() as it's callback\r
242 function. */\r
243 static TimerHandle_t xLEDTimer = NULL;\r
244 \r
245 /* The check timer.  This uses prvCheckTimerCallback() as it's callback\r
246 function. */\r
247 static TimerHandle_t xCheckTimer = NULL;\r
248 \r
249 /* The status message that is displayed at the bottom of the "task stats" web\r
250 page, which is served by the uIP task.  This will report any errors picked up\r
251 by the check timer callback. */\r
252 static const char *pcStatusMessage = NULL;\r
253 \r
254 /*-----------------------------------------------------------*/\r
255 \r
256 int main(void)\r
257 {\r
258         /* Configure the NVIC, LED outputs and button inputs. */\r
259         prvSetupHardware();\r
260 \r
261         /* Create the queue. */\r
262         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
263 \r
264         if( xQueue != NULL )\r
265         {\r
266                 /* Start the three application specific demo tasks, as described in the\r
267                 comments at the top of this     file. */\r
268                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
269                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
270                 xTaskCreate( prvOLEDTask, "OLED", configMINIMAL_STACK_SIZE, NULL, mainOLED_TASK_PRIORITY, NULL );\r
271 \r
272                 /* Create the software timer that is responsible for turning off the LED\r
273                 if the button is not pushed within 5000ms, as described at the top of\r
274                 this file. */\r
275                 xLEDTimer = xTimerCreate(       "LEDTimer",                                     /* A text name, purely to help debugging. */\r
276                                                                         ( mainLED_TIMER_PERIOD_MS ),    /* The timer period, in this case 5000ms (5s). */\r
277                                                                         pdFALSE,                                                /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
278                                                                         ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
279                                                                         prvLEDTimerCallback                             /* The callback function that switches the LED off. */\r
280                                                                 );\r
281 \r
282                 /* Create the software timer that performs the 'check' functionality,\r
283                 as described at the top of this file. */\r
284                 xCheckTimer = xTimerCreate( "CheckTimer",                                       /* A text name, purely to help debugging. */\r
285                                                                         ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
286                                                                         pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
287                                                                         ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
288                                                                         prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
289                                                                   );\r
290 \r
291                 /* Create a lot of 'standard demo' tasks. */\r
292                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
293                 vCreateBlockTimeTasks();\r
294                 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
295                 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
296                 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
297                 vStartQueuePeekTasks();\r
298                 vStartRecursiveMutexTasks();\r
299                 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
300 \r
301                 /* Create the web server task. */\r
302                 xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
303                 \r
304                 /* The suicide tasks must be created last, as they need to know how many\r
305                 tasks were running prior to their creation in order to ascertain whether\r
306                 or not the correct/expected number of tasks are running at any given\r
307                 time. */\r
308                 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
309 \r
310                 /* Start the tasks and timer running. */\r
311                 vTaskStartScheduler();\r
312         }\r
313 \r
314         /* If all is well, the scheduler will now be running, and the following line\r
315         will never be reached.  If the following line does execute, then there was\r
316         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
317         to be created.  See the memory management section on the FreeRTOS web site\r
318         for more details. */\r
319         for( ;; );\r
320 }\r
321 /*-----------------------------------------------------------*/\r
322 \r
323 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
324 {\r
325         /* Check the standard demo tasks are running without error.   Latch the\r
326         latest reported error in the pcStatusMessage character pointer. */\r
327         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
328         {\r
329                 pcStatusMessage = "Error: GenQueue";\r
330         }\r
331 \r
332         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
333         {\r
334                 pcStatusMessage = "Error: QueuePeek\r\n";\r
335         }\r
336 \r
337         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
338         {\r
339                 pcStatusMessage = "Error: BlockQueue\r\n";\r
340         }\r
341 \r
342         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
343         {\r
344                 pcStatusMessage = "Error: BlockTime\r\n";\r
345         }\r
346 \r
347         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
348         {\r
349                 pcStatusMessage = "Error: SemTest\r\n";\r
350         }\r
351 \r
352         if( xIsCreateTaskStillRunning() != pdTRUE )\r
353         {\r
354                 pcStatusMessage = "Error: Death\r\n";\r
355         }\r
356 \r
357         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
358         {\r
359                 pcStatusMessage = "Error: RecMutex\r\n";\r
360         }\r
361 \r
362         if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_MS ) ) != pdTRUE )\r
363         {\r
364                 pcStatusMessage = "Error: TimerDemo";\r
365         }\r
366 \r
367         /* Toggle the check LED to give an indication of the system status.  If\r
368         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
369         everything is ok.  A faster toggle indicates an error. */\r
370         vParTestToggleLED( mainCHECK_LED );\r
371 \r
372         /* Have any errors been latch in pcStatusMessage?  If so, shorten the\r
373         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
374         This will result in an increase in the rate at which mainCHECK_LED\r
375         toggles. */\r
376         if( pcStatusMessage != NULL )\r
377         {\r
378                 /* This call to xTimerChangePeriod() uses a zero block time.  Functions\r
379                 called from inside of a timer callback function must *never* attempt\r
380                 to block. */\r
381                 xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
382         }\r
383 }\r
384 /*-----------------------------------------------------------*/\r
385 \r
386 static void prvLEDTimerCallback( TimerHandle_t xTimer )\r
387 {\r
388         /* The timer has expired - so no button pushes have occurred in the last\r
389         five seconds - turn the LED off. */\r
390         vParTestSetLED( mainTIMER_CONTROLLED_LED, pdFALSE );\r
391 }\r
392 /*-----------------------------------------------------------*/\r
393 \r
394 /* The ISR executed when the user button is pushed. */\r
395 void GPIO8_IRQHandler( void )\r
396 {\r
397 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
398 \r
399         /* The button was pushed, so ensure the LED is on before resetting the\r
400         LED timer.  The LED timer will turn the LED off if the button is not\r
401         pushed within 5000ms. */\r
402         vParTestSetLEDFromISR( mainTIMER_CONTROLLED_LED, pdTRUE );\r
403 \r
404         /* This interrupt safe FreeRTOS function can be called from this interrupt\r
405         because the interrupt priority is below the\r
406         configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
407         xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );\r
408 \r
409         /* Clear the interrupt before leaving. */\r
410     MSS_GPIO_clear_irq( MSS_GPIO_8 );\r
411 \r
412         /* If calling xTimerResetFromISR() caused a task (in this case the timer\r
413         service/daemon task) to unblock, and the unblocked task has a priority\r
414         higher than or equal to the task that was interrupted, then\r
415         xHigherPriorityTaskWoken will now be set to pdTRUE, and calling\r
416         portEND_SWITCHING_ISR() will ensure the unblocked task runs next. */\r
417         portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
418 }\r
419 /*-----------------------------------------------------------*/\r
420 \r
421 static void prvQueueSendTask( void *pvParameters )\r
422 {\r
423 TickType_t xNextWakeTime;\r
424 const unsigned long ulValueToSend = 100UL;\r
425 \r
426         /* The timer command queue will have been filled when the timer test tasks\r
427         were created in main() (this is part of the test they perform).  Therefore,\r
428         while the check timer can be created in main(), it cannot be started from \r
429         main().  Once the scheduler has started, the timer service task will drain \r
430         the command queue, and now the check timer can be started successfully. */\r
431         xTimerStart( xCheckTimer, portMAX_DELAY );\r
432 \r
433         /* Initialise xNextWakeTime - this only needs to be done once. */\r
434         xNextWakeTime = xTaskGetTickCount();\r
435 \r
436         for( ;; )\r
437         {\r
438                 /* Place this task in the blocked state until it is time to run again.\r
439                 The block time is specified in ticks, the constant used converts ticks\r
440                 to ms.  While in the Blocked state this task will not consume any CPU\r
441                 time. */\r
442                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
443 \r
444                 /* Send to the queue - causing the queue receive task to unblock and\r
445                 toggle an LED.  0 is used as the block time so the sending operation\r
446                 will not block - it shouldn't need to block as the queue should always\r
447                 be empty at this point in the code. */\r
448                 xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );\r
449         }\r
450 }\r
451 /*-----------------------------------------------------------*/\r
452 \r
453 static void prvQueueReceiveTask( void *pvParameters )\r
454 {\r
455 unsigned long ulReceivedValue;\r
456 \r
457         for( ;; )\r
458         {\r
459                 /* Wait until something arrives in the queue - this task will block\r
460                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
461                 FreeRTOSConfig.h. */\r
462                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
463 \r
464                 /*  To get here something must have been received from the queue, but\r
465                 is it the expected value?  If it is, toggle the LED. */\r
466                 if( ulReceivedValue == 100UL )\r
467                 {\r
468                         vParTestToggleLED( mainTASK_CONTROLLED_LED );\r
469                 }\r
470         }\r
471 }\r
472 /*-----------------------------------------------------------*/\r
473 \r
474 static void prvOLEDTask( void * pvParameters)\r
475 {\r
476 static struct oled_data xOLEDData;\r
477 static unsigned char ucOffset1 = 0, ucOffset2 = 5;\r
478 static TickType_t xLastScrollTime = 0UL;\r
479 \r
480         /* Initialise the display. */\r
481         OLED_init();\r
482 \r
483         /* Initialise the parts of the oled_data structure that do not change. */\r
484         xOLEDData.line1          = FIRST_LINE;\r
485         xOLEDData.string1        = " www.FreeRTOS.org";\r
486         xOLEDData.line2          = SECOND_LINE;\r
487         xOLEDData.string2        = " www.FreeRTOS.org";\r
488         xOLEDData.contrast_val                 = OLED_CONTRAST_VAL;\r
489         xOLEDData.on_off                       = OLED_HORIZ_SCROLL_OFF;\r
490         xOLEDData.column_scrool_per_step       = OLED_HORIZ_SCROLL_STEP;\r
491         xOLEDData.start_page                   = OLED_START_PAGE;\r
492         xOLEDData.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;\r
493         xOLEDData.end_page                     = OLED_END_PAGE;\r
494 \r
495 \r
496         /* Initialise the last scroll time.  This only needs to be done once,\r
497         because from this point on it will get automatically updated in the\r
498         xTaskDelayUntil() API function. */\r
499         xLastScrollTime = xTaskGetTickCount();\r
500 \r
501         for( ;; )\r
502         {\r
503                 /* Wait until it is time to update the OLED again. */\r
504                 vTaskDelayUntil( &xLastScrollTime, mainOLED_PERIOD_MS );\r
505                 \r
506                 xOLEDData.char_offset1   = ucOffset1++;\r
507                 xOLEDData.char_offset2   = ucOffset2++;\r
508         \r
509                 OLED_write_data( &xOLEDData, BOTH_LINES );\r
510         }\r
511 }\r
512 /*-----------------------------------------------------------*/\r
513 \r
514 static void prvSetupHardware( void )\r
515 {\r
516         SystemCoreClockUpdate();\r
517         \r
518         /* Disable the Watch Dog Timer */\r
519         MSS_WD_disable( );\r
520 \r
521         /* Configure the GPIO for the LEDs. */\r
522         vParTestInitialise();\r
523         \r
524         /* ACE Initialization */\r
525         ACE_init();\r
526 \r
527         /* Setup the GPIO and the NVIC for the switch used in this simple demo. */\r
528         NVIC_SetPriority( GPIO8_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
529     NVIC_EnableIRQ( GPIO8_IRQn );\r
530     MSS_GPIO_config( MSS_GPIO_8, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_NEGATIVE );\r
531     MSS_GPIO_enable_irq( MSS_GPIO_8 );\r
532 }\r
533 /*-----------------------------------------------------------*/\r
534 \r
535 void vApplicationMallocFailedHook( void )\r
536 {\r
537         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
538         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
539         internally by FreeRTOS API functions that create tasks, queues, software\r
540         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
541         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
542         for( ;; );\r
543 }\r
544 /*-----------------------------------------------------------*/\r
545 \r
546 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
547 {\r
548         ( void ) pcTaskName;\r
549         ( void ) pxTask;\r
550 \r
551         /* Run time stack overflow checking is performed if\r
552         configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
553         function is called if a stack overflow is detected. */\r
554         taskDISABLE_INTERRUPTS();\r
555         for( ;; );\r
556 }\r
557 /*-----------------------------------------------------------*/\r
558 \r
559 void vApplicationIdleHook( void )\r
560 {\r
561 volatile size_t xFreeStackSpace;\r
562 \r
563         /* This function is called on each cycle of the idle task.  In this case it\r
564         does nothing useful, other than report the amount of FreeRTOS heap that\r
565         remains unallocated. */\r
566         xFreeStackSpace = xPortGetFreeHeapSize();\r
567 \r
568         if( xFreeStackSpace > 100 )\r
569         {\r
570                 /* By now, the kernel has allocated everything it is going to, so\r
571                 if there is a lot of heap remaining unallocated then\r
572                 the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be\r
573                 reduced accordingly. */\r
574         }\r
575 }\r
576 /*-----------------------------------------------------------*/\r
577 \r
578 char *pcGetTaskStatusMessage( void )\r
579 {\r
580         /* Not bothered about a critical section here although technically because\r
581         of the task priorities the pointer could change it will be atomic if not\r
582         near atomic and its not critical. */\r
583         if( pcStatusMessage == NULL )\r
584         {\r
585                 return "All tasks running without error";\r
586         }\r
587         else\r
588         {\r
589                 return ( char * ) pcStatusMessage;\r
590         }\r
591 }\r
592 /*-----------------------------------------------------------*/\r
593 \r
594 void vMainConfigureTimerForRunTimeStats( void )\r
595 {\r
596 const unsigned long ulMax32BitValue = 0xffffffffUL;\r
597 \r
598         MSS_TIM64_init( MSS_TIMER_PERIODIC_MODE );\r
599         MSS_TIM64_load_immediate( ulMax32BitValue, ulMax32BitValue );\r
600         MSS_TIM64_start();\r
601 }\r
602 /*-----------------------------------------------------------*/\r
603 \r
604 unsigned long ulGetRunTimeCounterValue( void )\r
605 {\r
606 unsigned long long ullCurrentValue;\r
607 const unsigned long long ulMax64BitValue = 0xffffffffffffffffULL;\r
608 unsigned long *pulHighWord, *pulLowWord;\r
609 \r
610         pulHighWord = ( unsigned long * ) &ullCurrentValue;\r
611         pulLowWord = pulHighWord++;\r
612         \r
613         MSS_TIM64_get_current_value( ( uint32_t * ) pulHighWord, ( uint32_t * ) pulLowWord );\r
614         \r
615         /* Convert the down count into an upcount. */\r
616         ullCurrentValue = ulMax64BitValue - ullCurrentValue;\r
617         \r
618         /* Scale to a 32bit number of suitable frequency. */\r
619         ullCurrentValue >>= 13;\r
620 \r
621         /* Just return 32 bits. */\r
622         return ( unsigned long ) ullCurrentValue;\r
623 }\r
624 \r