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