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