2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
73 * documentation provides more details of the standard demo application tasks.
\r
74 * In addition to the standard demo tasks, the following tasks and tests are
\r
75 * defined and/or created within this file:
\r
77 * "Fast Interrupt Test" - A high frequency periodic interrupt is generated
\r
78 * using a free running timer to demonstrate the use of the
\r
79 * configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt
\r
80 * service routine measures the number of processor clocks that occur between
\r
81 * each interrupt - and in so doing measures the jitter in the interrupt timing.
\r
82 * The maximum measured jitter time is latched in the ulMaxJitter variable, and
\r
83 * displayed on the OLED display by the 'OLED' task as described below. The
\r
84 * fast interrupt is configured and handled in the timertest.c source file.
\r
86 * "OLED" task - the OLED task is a 'gatekeeper' task. It is the only task that
\r
87 * is permitted to access the display directly. Other tasks wishing to write a
\r
88 * message to the OLED send the message on a queue to the OLED task instead of
\r
89 * accessing the OLED themselves. The OLED task just blocks on the queue waiting
\r
90 * for messages - waking and displaying the messages as they arrive.
\r
92 * "Check" hook - This only executes every five seconds from the tick hook.
\r
93 * Its main function is to check that all the standard demo tasks are still
\r
94 * operational. Should any unexpected behaviour within a demo task be discovered
\r
95 * the tick hook will write an error to the OLED (via the OLED task). If all the
\r
96 * demo tasks are executing with their expected behaviour then the check task
\r
97 * writes PASS to the OLED (again via the OLED task), as described above.
\r
99 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
100 * processing is performed in this task.
\r
106 /*************************************************************************
\r
107 * Please ensure to read http://www.freertos.org/portlm3sx965.html
\r
108 * which provides information on configuring and running this demo for the
\r
109 * various Luminary Micro EKs.
\r
110 *************************************************************************/
\r
112 /* Set the following option to 1 to include the WEB server in the build. By
\r
113 default the WEB server is excluded to keep the compiled code size under the 32K
\r
114 limit imposed by the KickStart version of the IAR compiler. The graphics
\r
115 libraries take up a lot of ROM space, hence including the graphics libraries
\r
116 and the TCP/IP stack together cannot be accommodated with the 32K size limit. */
\r
117 #define mainINCLUDE_WEB_SERVER 0
\r
120 /* Standard includes. */
\r
122 #include <string.h>
\r
124 /* Scheduler includes. */
\r
125 #include "FreeRTOS.h"
\r
128 #include "semphr.h"
\r
130 /* Hardware library includes. */
\r
131 #include "hw_memmap.h"
\r
132 #include "hw_types.h"
\r
133 #include "hw_sysctl.h"
\r
134 #include "sysctl.h"
\r
137 #include "rit128x96x4.h"
\r
138 #include "osram128x64x4.h"
\r
139 #include "formike128x128x16.h"
\r
141 /* Demo app includes. */
\r
142 #include "BlockQ.h"
\r
144 #include "integer.h"
\r
145 #include "blocktim.h"
\r
147 #include "partest.h"
\r
148 #include "semtest.h"
\r
150 #include "lcd_message.h"
\r
151 #include "bitmap.h"
\r
152 #include "GenQTest.h"
\r
154 #include "recmutex.h"
\r
155 #include "IntQueue.h"
\r
156 #include "QueueSet.h"
\r
157 #include "EventGroupsDemo.h"
\r
159 /*-----------------------------------------------------------*/
\r
161 /* The time between cycles of the 'check' functionality (defined within the
\r
163 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
165 /* Size of the stack allocated to the uIP task. */
\r
166 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )
\r
168 /* The OLED task uses the sprintf function so requires a little more stack too. */
\r
169 #define mainOLED_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE + 50 )
\r
171 /* Task priorities. */
\r
172 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
173 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
174 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
175 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
176 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
177 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
178 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
180 /* The maximum number of message that can be waiting for display at any one
\r
182 #define mainOLED_QUEUE_SIZE ( 3 )
\r
184 /* Dimensions the buffer into which the jitter time is written. */
\r
185 #define mainMAX_MSG_LEN 25
\r
187 /* The period of the system clock in nano seconds. This is used to calculate
\r
188 the jitter time in nano seconds. */
\r
189 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
191 /* Constants used when writing strings to the display. */
\r
192 #define mainCHARACTER_HEIGHT ( 9 )
\r
193 #define mainMAX_ROWS_128 ( mainCHARACTER_HEIGHT * 14 )
\r
194 #define mainMAX_ROWS_96 ( mainCHARACTER_HEIGHT * 10 )
\r
195 #define mainMAX_ROWS_64 ( mainCHARACTER_HEIGHT * 7 )
\r
196 #define mainFULL_SCALE ( 15 )
\r
197 #define ulSSI_FREQUENCY ( 3500000UL )
\r
199 /*-----------------------------------------------------------*/
\r
202 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
205 extern void vuIP_Task( void *pvParameters );
\r
208 * The display is written two by more than one task so is controlled by a
\r
209 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
210 * access the display directly. Other tasks wanting to display a message send
\r
211 * the message to the gatekeeper.
\r
213 static void vOLEDTask( void *pvParameters );
\r
216 * Configure the hardware for the demo.
\r
218 static void prvSetupHardware( void );
\r
221 * Configures the high frequency timers - those used to measure the timing
\r
222 * jitter while the real time kernel is executing.
\r
224 extern void vSetupHighFrequencyTimer( void );
\r
227 * Hook functions that can get called by the kernel.
\r
229 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName );
\r
230 void vApplicationTickHook( void );
\r
233 /*-----------------------------------------------------------*/
\r
235 /* The queue used to send messages to the OLED task. */
\r
236 QueueHandle_t xOLEDQueue;
\r
238 /* The welcome text. */
\r
239 const char * const pcWelcomeMessage = " www.FreeRTOS.org";
\r
241 /*-----------------------------------------------------------*/
\r
244 /*************************************************************************
\r
245 * Please ensure to read http://www.freertos.org/portlm3sx965.html
\r
246 * which provides information on configuring and running this demo for the
\r
247 * various Luminary Micro EKs.
\r
248 *************************************************************************/
\r
251 prvSetupHardware();
\r
253 /* Create the queue used by the OLED task. Messages for display on the OLED
\r
254 are received via this queue. */
\r
255 xOLEDQueue = xQueueCreate( mainOLED_QUEUE_SIZE, sizeof( xOLEDMessage ) );
\r
257 /* Start the standard demo tasks. */
\r
258 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
259 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
260 vStartInterruptQueueTasks();
\r
261 vStartRecursiveMutexTasks();
\r
262 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
263 vCreateBlockTimeTasks();
\r
264 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
265 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
266 vStartQueuePeekTasks();
\r
267 vStartQueueSetTasks();
\r
268 vStartEventGroupTasks();
\r
270 /* Exclude some tasks if using the kickstart version to ensure we stay within
\r
271 the 32K code size limit. */
\r
272 #if mainINCLUDE_WEB_SERVER != 0
\r
274 /* Create the uIP task if running on a processor that includes a MAC and
\r
276 if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) )
\r
278 xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
285 /* Start the tasks defined within this file/specific to this demo. */
\r
286 xTaskCreate( vOLEDTask, "OLED", mainOLED_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
288 /* The suicide tasks must be created last as they need to know how many
\r
289 tasks were running prior to their creation in order to ascertain whether
\r
290 or not the correct/expected number of tasks are running at any given time. */
\r
291 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
293 /* Configure the high frequency interrupt used to measure the interrupt
\r
295 vSetupHighFrequencyTimer();
\r
297 /* Start the scheduler. */
\r
298 vTaskStartScheduler();
\r
300 /* Will only get here if there was insufficient memory to create the idle
\r
304 /*-----------------------------------------------------------*/
\r
306 void prvSetupHardware( void )
\r
308 /* If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is
\r
309 a workaround to allow the PLL to operate reliably. */
\r
310 if( DEVICE_IS_REVA2 )
\r
312 SysCtlLDOSet( SYSCTL_LDO_2_75V );
\r
315 /* Set the clocking to run from the PLL at 50 MHz */
\r
316 SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );
\r
318 /* Enable Port F for Ethernet LEDs
\r
320 LED1 Bit 2 Output */
\r
321 SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOF );
\r
322 GPIODirModeSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3), GPIO_DIR_MODE_HW );
\r
323 GPIOPadConfigSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3 ), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD );
\r
325 vParTestInitialise();
\r
327 /*-----------------------------------------------------------*/
\r
329 void vApplicationTickHook( void )
\r
331 static xOLEDMessage xMessage = { "PASS" };
\r
332 static unsigned long ulTicksSinceLastDisplay = 0;
\r
333 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
335 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
336 time to perform our health status check again? */
\r
337 ulTicksSinceLastDisplay++;
\r
338 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
340 ulTicksSinceLastDisplay = 0;
\r
342 /* Has an error been found in any task? */
\r
343 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
345 xMessage.pcMessage = "ERROR IN GEN Q";
\r
347 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
349 xMessage.pcMessage = "ERROR IN CREATE";
\r
351 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
353 xMessage.pcMessage = "ERROR IN MATH";
\r
355 else if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
357 xMessage.pcMessage = "ERROR IN INT QUEUE";
\r
359 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
361 xMessage.pcMessage = "ERROR IN BLOCK Q";
\r
363 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
365 xMessage.pcMessage = "ERROR IN BLOCK TIME";
\r
367 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
369 xMessage.pcMessage = "ERROR IN SEMAPHORE";
\r
371 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
373 xMessage.pcMessage = "ERROR IN POLL Q";
\r
375 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
377 xMessage.pcMessage = "ERROR IN PEEK Q";
\r
379 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
381 xMessage.pcMessage = "ERROR IN REC MUTEX";
\r
383 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
385 xMessage.pcMessage = "ERROR IN Q SET";
\r
387 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
389 xMessage.pcMessage = "ERROR IN EVNT GRP";
\r
392 configASSERT( strcmp( ( const char * ) xMessage.pcMessage, "PASS" ) == 0 );
\r
394 /* Send the message to the OLED gatekeeper for display. */
\r
395 xHigherPriorityTaskWoken = pdFALSE;
\r
396 xQueueSendFromISR( xOLEDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
399 /* Write to a queue that is in use as part of the queue set demo to
\r
400 demonstrate using queue sets from an ISR. */
\r
401 vQueueSetAccessQueueSetFromISR();
\r
403 /* Call the event group ISR tests. */
\r
404 vPeriodicEventGroupsProcessing();
\r
406 /*-----------------------------------------------------------*/
\r
408 void vOLEDTask( void *pvParameters )
\r
410 xOLEDMessage xMessage;
\r
411 unsigned long ulY, ulMaxY;
\r
412 static char cMessage[ mainMAX_MSG_LEN ];
\r
413 extern volatile unsigned long ulMaxJitter;
\r
414 const unsigned char *pucImage;
\r
416 /* Functions to access the OLED. The one used depends on the dev kit
\r
418 void ( *vOLEDInit )( unsigned long ) = NULL;
\r
419 void ( *vOLEDStringDraw )( const char *, unsigned long, unsigned long, unsigned char ) = NULL;
\r
420 void ( *vOLEDImageDraw )( const unsigned char *, unsigned long, unsigned long, unsigned long, unsigned long ) = NULL;
\r
421 void ( *vOLEDClear )( void ) = NULL;
\r
423 /* Map the OLED access functions to the driver functions that are appropriate
\r
424 for the evaluation kit being used. */
\r
425 switch( HWREG( SYSCTL_DID1 ) & SYSCTL_DID1_PRTNO_MASK )
\r
427 case SYSCTL_DID1_PRTNO_6965 :
\r
428 case SYSCTL_DID1_PRTNO_2965 : vOLEDInit = OSRAM128x64x4Init;
\r
429 vOLEDStringDraw = OSRAM128x64x4StringDraw;
\r
430 vOLEDImageDraw = OSRAM128x64x4ImageDraw;
\r
431 vOLEDClear = OSRAM128x64x4Clear;
\r
432 ulMaxY = mainMAX_ROWS_64;
\r
433 pucImage = pucBasicBitmap;
\r
436 case SYSCTL_DID1_PRTNO_1968 :
\r
437 case SYSCTL_DID1_PRTNO_8962 : vOLEDInit = RIT128x96x4Init;
\r
438 vOLEDStringDraw = RIT128x96x4StringDraw;
\r
439 vOLEDImageDraw = RIT128x96x4ImageDraw;
\r
440 vOLEDClear = RIT128x96x4Clear;
\r
441 ulMaxY = mainMAX_ROWS_96;
\r
442 pucImage = pucBasicBitmap;
\r
445 default : vOLEDInit = vFormike128x128x16Init;
\r
446 vOLEDStringDraw = vFormike128x128x16StringDraw;
\r
447 vOLEDImageDraw = vFormike128x128x16ImageDraw;
\r
448 vOLEDClear = vFormike128x128x16Clear;
\r
449 ulMaxY = mainMAX_ROWS_128;
\r
450 pucImage = pucGrLibBitmap;
\r
457 /* Initialise the OLED and display a startup message. */
\r
458 vOLEDInit( ulSSI_FREQUENCY );
\r
459 vOLEDStringDraw( "POWERED BY FreeRTOS", 0, 0, mainFULL_SCALE );
\r
460 vOLEDImageDraw( pucImage, 0, mainCHARACTER_HEIGHT + 1, bmpBITMAP_WIDTH, bmpBITMAP_HEIGHT );
\r
464 /* Wait for a message to arrive that requires displaying. */
\r
465 xQueueReceive( xOLEDQueue, &xMessage, portMAX_DELAY );
\r
467 /* Write the message on the next available row. */
\r
468 ulY += mainCHARACTER_HEIGHT;
\r
469 if( ulY >= ulMaxY )
\r
471 ulY = mainCHARACTER_HEIGHT;
\r
473 vOLEDStringDraw( pcWelcomeMessage, 0, 0, mainFULL_SCALE );
\r
476 /* Display the message along with the maximum jitter time from the
\r
477 high priority time test. */
\r
478 sprintf( cMessage, "%s [%uns]", xMessage.pcMessage, ulMaxJitter * mainNS_PER_CLOCK );
\r
479 vOLEDStringDraw( cMessage, 0, ulY, mainFULL_SCALE );
\r
482 /*-----------------------------------------------------------*/
\r
484 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
\r
487 ( void ) pcTaskName;
\r
491 /*-----------------------------------------------------------*/
\r
493 void vAssertCalled( const char *pcFile, unsigned long ulLine )
\r
495 volatile unsigned long ulSetTo1InDebuggerToExit = 0;
\r
497 taskENTER_CRITICAL();
\r
499 while( ulSetTo1InDebuggerToExit == 0 )
\r
501 /* Nothing do do here. Set the loop variable to a non zero value in
\r
502 the debugger to step out of this function to the point that caused
\r
508 taskEXIT_CRITICAL();
\r