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