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