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