2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
30 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
31 * documentation provides more details of the standard demo application tasks.
\r
32 * In addition to the standard demo tasks, the following tasks and tests are
\r
33 * defined and/or created within this file:
\r
35 * "Fast Interrupt Test" - A high frequency periodic interrupt is generated
\r
36 * using a free running timer to demonstrate the use of the
\r
37 * configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt
\r
38 * service routine measures the number of processor clocks that occur between
\r
39 * each interrupt - and in so doing measures the jitter in the interrupt timing.
\r
40 * The maximum measured jitter time is latched in the ulMaxJitter variable, and
\r
41 * displayed on the OLED display by the 'OLED' task as described below. The
\r
42 * fast interrupt is configured and handled in the timertest.c source file.
\r
44 * "OLED" task - the OLED task is a 'gatekeeper' task. It is the only task that
\r
45 * is permitted to access the display directly. Other tasks wishing to write a
\r
46 * message to the OLED send the message on a queue to the OLED task instead of
\r
47 * accessing the OLED themselves. The OLED task just blocks on the queue waiting
\r
48 * for messages - waking and displaying the messages as they arrive.
\r
50 * "Check" hook - This only executes every five seconds from the tick hook.
\r
51 * Its main function is to check that all the standard demo tasks are still
\r
52 * operational. Should any unexpected behaviour within a demo task be discovered
\r
53 * the tick hook will write an error to the OLED (via the OLED task). If all the
\r
54 * demo tasks are executing with their expected behaviour then the check task
\r
55 * writes PASS to the OLED (again via the OLED task), as described above.
\r
57 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
58 * processing is performed in this task.
\r
60 * Use the following command to execute in QEMU from the IAR IDE:
\r
61 * qemu-system-arm -machine lm3s6965evb -s -S -kernel [pat_to]\RTOSDemo.out
\r
62 * and set IAR connect GDB server to "localhost,1234" in project debug options.
\r
65 /*************************************************************************
\r
66 * Please ensure to read http://www.freertos.org/portlm3sx965.html
\r
67 * which provides information on configuring and running this demo for the
\r
68 * various Luminary Micro EKs.
\r
69 *************************************************************************/
\r
71 /* Set the following option to 1 to include the WEB server in the build. By
\r
72 default the WEB server is excluded to keep the compiled code size under the 32K
\r
73 limit imposed by the KickStart version of the IAR compiler. The graphics
\r
74 libraries take up a lot of ROM space, hence including the graphics libraries
\r
75 and the TCP/IP stack together cannot be accommodated with the 32K size limit. */
\r
76 #define mainINCLUDE_WEB_SERVER 0
\r
79 /* Standard includes. */
\r
83 /* Scheduler includes. */
\r
84 #include "FreeRTOS.h"
\r
89 /* Hardware library includes. */
\r
90 #include "hw_memmap.h"
\r
91 #include "hw_types.h"
\r
92 #include "hw_sysctl.h"
\r
93 #include "hw_uart.h"
\r
97 #include "rit128x96x4.h"
\r
98 #include "osram128x64x4.h"
\r
99 #include "formike128x128x16.h"
\r
102 /* Demo app includes. */
\r
104 #include "blocktim.h"
\r
106 #include "partest.h"
\r
107 #include "semtest.h"
\r
109 #include "lcd_message.h"
\r
110 #include "bitmap.h"
\r
111 #include "GenQTest.h"
\r
113 #include "recmutex.h"
\r
114 #include "IntQueue.h"
\r
115 #include "QueueSet.h"
\r
116 #include "EventGroupsDemo.h"
\r
117 #include "MessageBufferDemo.h"
\r
118 #include "StreamBufferDemo.h"
\r
120 /*-----------------------------------------------------------*/
\r
122 /* The time between cycles of the 'check' functionality (defined within the
\r
124 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
126 /* Size of the stack allocated to the uIP task. */
\r
127 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )
\r
129 /* The OLED task uses the sprintf function so requires a little more stack too. */
\r
130 #define mainOLED_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE + 50 )
\r
132 /* Task priorities. */
\r
133 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
134 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
135 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
136 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
137 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
139 /* The maximum number of message that can be waiting for display at any one
\r
141 #define mainOLED_QUEUE_SIZE ( 3 )
\r
143 /* Dimensions the buffer into which the jitter time is written. */
\r
144 #define mainMAX_MSG_LEN 25
\r
146 /* The period of the system clock in nano seconds. This is used to calculate
\r
147 the jitter time in nano seconds. */
\r
148 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
150 /* Constants used when writing strings to the display. */
\r
151 #define mainCHARACTER_HEIGHT ( 9 )
\r
152 #define mainMAX_ROWS_128 ( mainCHARACTER_HEIGHT * 14 )
\r
153 #define mainMAX_ROWS_96 ( mainCHARACTER_HEIGHT * 10 )
\r
154 #define mainMAX_ROWS_64 ( mainCHARACTER_HEIGHT * 7 )
\r
155 #define mainFULL_SCALE ( 15 )
\r
156 #define ulSSI_FREQUENCY ( 3500000UL )
\r
158 /*-----------------------------------------------------------*/
\r
161 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
164 extern void vuIP_Task( void *pvParameters );
\r
167 * The display is written two by more than one task so is controlled by a
\r
168 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
169 * access the display directly. Other tasks wanting to display a message send
\r
170 * the message to the gatekeeper.
\r
172 static void vOLEDTask( void *pvParameters );
\r
175 * Configure the hardware for the demo.
\r
177 static void prvSetupHardware( void );
\r
180 * Configures the high frequency timers - those used to measure the timing
\r
181 * jitter while the real time kernel is executing.
\r
183 extern void vSetupHighFrequencyTimer( void );
\r
186 * Hook functions that can get called by the kernel.
\r
188 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName );
\r
189 void vApplicationTickHook( void );
\r
191 static void prvPrintString( const char * pcString );
\r
193 /*-----------------------------------------------------------*/
\r
195 /* The queue used to send messages to the OLED task. */
\r
196 QueueHandle_t xOLEDQueue;
\r
198 /* The welcome text. */
\r
199 const char * const pcWelcomeMessage = " www.FreeRTOS.org";
\r
201 /*-----------------------------------------------------------*/
\r
204 /*************************************************************************
\r
205 * Please ensure to read http://www.freertos.org/portlm3sx965.html
\r
206 * which provides information on configuring and running this demo for the
\r
207 * various Luminary Micro EKs.
\r
208 *************************************************************************/
\r
211 prvSetupHardware();
\r
213 /* Create the queue used by the OLED task. Messages for display on the OLED
\r
214 are received via this queue. */
\r
215 xOLEDQueue = xQueueCreate( mainOLED_QUEUE_SIZE, sizeof( xOLEDMessage ) );
\r
217 /* Start the standard demo tasks. */
\r
218 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
219 vStartInterruptQueueTasks();
\r
220 vStartRecursiveMutexTasks();
\r
221 vCreateBlockTimeTasks();
\r
222 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
223 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
224 vStartQueuePeekTasks();
\r
225 vStartQueueSetTasks();
\r
226 vStartEventGroupTasks();
\r
227 vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );
\r
228 vStartStreamBufferTasks();
\r
230 /* Exclude some tasks if using the kickstart version to ensure we stay within
\r
231 the 32K code size limit. */
\r
232 #if mainINCLUDE_WEB_SERVER != 0
\r
234 /* Create the uIP task if running on a processor that includes a MAC and
\r
236 if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) )
\r
238 xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
243 /* Start the tasks defined within this file/specific to this demo. */
\r
244 xTaskCreate( vOLEDTask, "OLED", mainOLED_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
246 /* The suicide tasks must be created last as they need to know how many
\r
247 tasks were running prior to their creation in order to ascertain whether
\r
248 or not the correct/expected number of tasks are running at any given time. */
\r
249 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
251 /* Uncomment the following line to configure the high frequency interrupt
\r
252 used to measure the interrupt jitter time.
\r
253 vSetupHighFrequencyTimer(); */
\r
255 /* Start the scheduler. */
\r
256 vTaskStartScheduler();
\r
258 /* Will only get here if there was insufficient memory to create the idle
\r
262 /*-----------------------------------------------------------*/
\r
264 void prvSetupHardware( void )
\r
266 /* If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is
\r
267 a workaround to allow the PLL to operate reliably. */
\r
268 if( DEVICE_IS_REVA2 )
\r
270 SysCtlLDOSet( SYSCTL_LDO_2_75V );
\r
273 /* Set the clocking to run from the PLL at 50 MHz */
\r
274 SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );
\r
276 /* Enable Port F for Ethernet LEDs
\r
278 LED1 Bit 2 Output */
\r
279 SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOF );
\r
280 GPIODirModeSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3), GPIO_DIR_MODE_HW );
\r
281 GPIOPadConfigSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3 ), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD );
\r
283 vParTestInitialise();
\r
285 /* Initialise the UART - QEMU usage does not seem to require this
\r
287 SysCtlPeripheralEnable( SYSCTL_PERIPH_UART0 );
\r
288 UARTEnable( UART0_BASE );
\r
290 /*-----------------------------------------------------------*/
\r
292 void vApplicationTickHook( void )
\r
294 static xOLEDMessage xMessage = { "PASS" };
\r
295 static unsigned long ulTicksSinceLastDisplay = 0;
\r
296 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
298 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
299 time to perform our health status check again? */
\r
300 ulTicksSinceLastDisplay++;
\r
301 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
303 ulTicksSinceLastDisplay = 0;
\r
305 /* Has an error been found in any task? */
\r
306 if( xAreStreamBufferTasksStillRunning() != pdTRUE )
\r
308 xMessage.pcMessage = "ERROR IN STRM";
\r
310 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )
\r
312 xMessage.pcMessage = "ERROR IN MSG";
\r
314 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
316 xMessage.pcMessage = "ERROR IN GEN Q";
\r
318 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
320 xMessage.pcMessage = "ERROR IN CREATE";
\r
322 else if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
324 xMessage.pcMessage = "ERROR IN INT QUEUE";
\r
326 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
328 xMessage.pcMessage = "ERROR IN BLOCK TIME";
\r
330 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
332 xMessage.pcMessage = "ERROR IN SEMAPHORE";
\r
334 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
336 xMessage.pcMessage = "ERROR IN POLL Q";
\r
338 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
340 xMessage.pcMessage = "ERROR IN PEEK Q";
\r
342 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
344 xMessage.pcMessage = "ERROR IN REC MUTEX";
\r
346 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
348 xMessage.pcMessage = "ERROR IN Q SET";
\r
350 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
352 xMessage.pcMessage = "ERROR IN EVNT GRP";
\r
355 /* Send the message to the OLED gatekeeper for display. */
\r
356 xHigherPriorityTaskWoken = pdFALSE;
\r
357 xQueueSendFromISR( xOLEDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
360 /* Write to a queue that is in use as part of the queue set demo to
\r
361 demonstrate using queue sets from an ISR. */
\r
362 vQueueSetAccessQueueSetFromISR();
\r
364 /* Call the event group ISR tests. */
\r
365 vPeriodicEventGroupsProcessing();
\r
367 /*-----------------------------------------------------------*/
\r
369 static void prvPrintString( const char * pcString )
\r
371 while( *pcString != 0x00 )
\r
373 UARTCharPut( UART0_BASE, *pcString );
\r
377 /*-----------------------------------------------------------*/
\r
379 void vOLEDTask( void *pvParameters )
\r
381 xOLEDMessage xMessage;
\r
382 unsigned long ulY, ulMaxY;
\r
383 static char cMessage[ mainMAX_MSG_LEN ];
\r
384 extern volatile unsigned long ulMaxJitter;
\r
385 const unsigned char *pucImage;
\r
387 /* Functions to access the OLED. The one used depends on the dev kit
\r
389 void ( *vOLEDInit )( unsigned long ) = NULL;
\r
390 void ( *vOLEDStringDraw )( const char *, unsigned long, unsigned long, unsigned char ) = NULL;
\r
391 void ( *vOLEDImageDraw )( const unsigned char *, unsigned long, unsigned long, unsigned long, unsigned long ) = NULL;
\r
392 void ( *vOLEDClear )( void ) = NULL;
\r
394 /* Map the OLED access functions to the driver functions that are appropriate
\r
395 for the evaluation kit being used. */
\r
396 switch( HWREG( SYSCTL_DID1 ) & SYSCTL_DID1_PRTNO_MASK )
\r
398 case SYSCTL_DID1_PRTNO_6965 :
\r
399 case SYSCTL_DID1_PRTNO_2965 : vOLEDInit = OSRAM128x64x4Init;
\r
400 vOLEDStringDraw = OSRAM128x64x4StringDraw;
\r
401 vOLEDImageDraw = OSRAM128x64x4ImageDraw;
\r
402 vOLEDClear = OSRAM128x64x4Clear;
\r
403 ulMaxY = mainMAX_ROWS_64;
\r
404 pucImage = pucBasicBitmap;
\r
407 case SYSCTL_DID1_PRTNO_1968 :
\r
408 case SYSCTL_DID1_PRTNO_8962 : vOLEDInit = RIT128x96x4Init;
\r
409 vOLEDStringDraw = RIT128x96x4StringDraw;
\r
410 vOLEDImageDraw = RIT128x96x4ImageDraw;
\r
411 vOLEDClear = RIT128x96x4Clear;
\r
412 ulMaxY = mainMAX_ROWS_96;
\r
413 pucImage = pucBasicBitmap;
\r
416 default : vOLEDInit = vFormike128x128x16Init;
\r
417 vOLEDStringDraw = vFormike128x128x16StringDraw;
\r
418 vOLEDImageDraw = vFormike128x128x16ImageDraw;
\r
419 vOLEDClear = vFormike128x128x16Clear;
\r
420 ulMaxY = mainMAX_ROWS_128;
\r
421 pucImage = pucGrLibBitmap;
\r
428 /* Initialise the OLED and display a startup message. */
\r
429 vOLEDInit( ulSSI_FREQUENCY );
\r
430 vOLEDStringDraw( "POWERED BY FreeRTOS", 0, 0, mainFULL_SCALE );
\r
431 vOLEDImageDraw( pucImage, 0, mainCHARACTER_HEIGHT + 1, bmpBITMAP_WIDTH, bmpBITMAP_HEIGHT );
\r
435 /* Wait for a message to arrive that requires displaying. */
\r
436 xQueueReceive( xOLEDQueue, &xMessage, portMAX_DELAY );
\r
438 /* Write the message on the next available row. */
\r
439 ulY += mainCHARACTER_HEIGHT;
\r
440 if( ulY >= ulMaxY )
\r
442 ulY = mainCHARACTER_HEIGHT;
\r
444 vOLEDStringDraw( pcWelcomeMessage, 0, 0, mainFULL_SCALE );
\r
447 /* Display the message along with the maximum jitter time from the
\r
448 high priority time test. */
\r
449 sprintf( cMessage, "%s [%uns]", xMessage.pcMessage, ulMaxJitter * mainNS_PER_CLOCK );
\r
450 vOLEDStringDraw( cMessage, 0, ulY, mainFULL_SCALE );
\r
451 prvPrintString( cMessage );
\r
454 /*-----------------------------------------------------------*/
\r
456 volatile signed char *pcOverflowedTask = NULL;
\r
457 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
\r
460 pcOverflowedTask = pcTaskName;
\r
464 /*-----------------------------------------------------------*/
\r
466 void vAssertCalled( const char *pcFile, unsigned long ulLine )
\r
468 volatile unsigned long ulSetTo1InDebuggerToExit = 0;
\r
470 taskENTER_CRITICAL();
\r
472 while( ulSetTo1InDebuggerToExit == 0 )
\r
474 /* Nothing to do here. Set the loop variable to a non zero value in
\r
475 the debugger to step out of this function to the point that caused
\r
481 taskEXIT_CRITICAL();
\r
484 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
485 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
486 used by the Idle task. */
\r
487 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
489 /* If the buffers to be provided to the Idle task are declared inside this
\r
490 function then they must be declared static - otherwise they will be allocated on
\r
491 the stack and so not exists after this function exits. */
\r
492 static StaticTask_t xIdleTaskTCB;
\r
493 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
495 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
496 state will be stored. */
\r
497 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
499 /* Pass out the array that will be used as the Idle task's stack. */
\r
500 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
502 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
503 Note that, as the array is necessarily of type StackType_t,
\r
504 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
505 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
507 /*-----------------------------------------------------------*/
\r
509 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
510 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
511 to provide the memory that is used by the Timer service task. */
\r
512 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
514 /* If the buffers to be provided to the Timer task are declared inside this
\r
515 function then they must be declared static - otherwise they will be allocated on
\r
516 the stack and so not exists after this function exits. */
\r
517 static StaticTask_t xTimerTaskTCB;
\r
518 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
520 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
521 task's state will be stored. */
\r
522 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
524 /* Pass out the array that will be used as the Timer task's stack. */
\r
525 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
527 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
528 Note that, as the array is necessarily of type StackType_t,
\r
529 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
530 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r