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