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