2 FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
56 /* RTOS includes. */
\r
57 #include "FreeRTOS.h"
\r
62 /* Common Demo includes. */
\r
65 #include "blocktim.h"
\r
66 #include "comtest.h"
\r
67 #include "countsem.h"
\r
69 #include "dynamic.h"
\r
72 #include "GenQTest.h"
\r
73 #include "integer.h"
\r
74 #include "IntQueue.h"
\r
75 #include "mevents.h"
\r
76 #include "partest.h"
\r
80 #include "semtest.h"
\r
81 /*---------------------------------------------------------------------------*/
\r
83 /* The time between cycles of the 'check' functionality (defined within the
\r
85 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
86 #define mainCOM_LED ( 3 )
\r
88 /* The number of nano seconds between each processor clock. */
\r
89 #define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
91 /* Task priorities. */
\r
92 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
93 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
94 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
95 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
96 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
97 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
98 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
99 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
100 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
101 /*---------------------------------------------------------------------------*/
\r
104 * Configures the timers and interrupts for the fast interrupt test as
\r
105 * described at the top of this file.
\r
107 extern void vSetupTimerTest( void );
\r
108 /*---------------------------------------------------------------------------*/
\r
111 * The Check task periodical interrogates each of the running tests to
\r
112 * ensure that they are still executing correctly.
\r
113 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
114 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
115 * If any one of the tests fail, it is indicated with an error code printed on
\r
116 * the display. This indicator won't disappear until the device is reset.
\r
118 void vCheckTask( void *pvParameters );
\r
121 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
123 static void prvHardwareSetup( void );
\r
124 /*---------------------------------------------------------------------------*/
\r
128 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
129 prvHardwareSetup();
\r
131 /* Start the standard demo tasks. These are just here to exercise the
\r
132 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
133 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
134 vCreateBlockTimeTasks();
\r
135 vStartCountingSemaphoreTasks();
\r
136 vStartDynamicPriorityTasks();
\r
137 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
138 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
139 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
140 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
141 vStartQueuePeekTasks();
\r
142 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
143 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
144 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
145 vStartInterruptQueueTasks();
\r
147 /* Start the error checking task. */
\r
148 ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
150 /* Configure the timers used by the fast interrupt timer test. */
\r
153 /* The suicide tasks must be created last as they need to know how many
\r
154 tasks were running prior to their creation in order to ascertain whether
\r
155 or not the correct/expected number of tasks are running at any given time. */
\r
156 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
158 /* Will only get here if there was insufficient memory to create the idle
\r
159 task. The idle task is created within vTaskStartScheduler(). */
\r
160 vTaskStartScheduler();
\r
162 /* Should never reach here as the kernel will now be running. If
\r
163 vTaskStartScheduler() does return then it is very likely that there was
\r
164 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
165 including the idle task that is created within vTaskStartScheduler() itself. */
\r
168 /*---------------------------------------------------------------------------*/
\r
170 void prvHardwareSetup( void )
\r
172 /* Port layer functions that need to be copied into the vector table. */
\r
173 extern void xPortPendSVHandler( void );
\r
174 extern void xPortSysTickHandler( void );
\r
175 extern void vPortSVCHandler( void );
\r
176 extern cyisraddress CyRamVectors[];
\r
178 /* Install the OS Interrupt Handlers. */
\r
179 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
180 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
181 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
183 /* Start-up the peripherals. */
\r
185 /* Enable and clear the LCD Display. */
\r
186 LCD_Character_Display_Start();
\r
187 LCD_Character_Display_ClearDisplay();
\r
188 LCD_Character_Display_Position( 0, 0 );
\r
189 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
190 LCD_Character_Display_Position( 1, 0 );
\r
191 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
193 /* Start the UART. */
\r
196 /* Initialise the LEDs. */
\r
197 vParTestInitialise();
\r
199 /* Start the PWM modules that drive the IntQueue tests. */
\r
200 High_Frequency_PWM_0_Start();
\r
201 High_Frequency_PWM_1_Start();
\r
203 /* Start the timers for the Jitter test. */
\r
204 Timer_20KHz_Start();
\r
205 Timer_48MHz_Start();
\r
207 /*---------------------------------------------------------------------------*/
\r
209 void vCheckTask( void *pvParameters )
\r
211 unsigned long ulRow = 0;
\r
212 portTickType xDelay = 0;
\r
213 unsigned short usErrorCode = 0;
\r
214 unsigned long ulIteration = 0;
\r
215 extern unsigned portSHORT usMaxJitter;
\r
217 /* Intialise the sleeper. */
\r
218 xDelay = xTaskGetTickCount();
\r
222 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
223 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
225 /* Check that all of the Demo tasks are still running. */
\r
226 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
228 usErrorCode |= 0x1;
\r
231 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
233 usErrorCode |= 0x2;
\r
236 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
238 usErrorCode |= 0x4;
\r
241 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
243 usErrorCode |= 0x8;
\r
246 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
248 usErrorCode |= 0x10;
\r
251 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
253 usErrorCode |= 0x20;
\r
256 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
258 usErrorCode |= 0x40;
\r
261 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
263 usErrorCode |= 0x80;
\r
266 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
268 usErrorCode |= 0x100;
\r
271 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
273 usErrorCode |= 0x200;
\r
276 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
278 usErrorCode |= 0x400;
\r
281 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
283 usErrorCode |= 0x800;
\r
286 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
288 usErrorCode |= 0x1000;
\r
291 /* Clear the display. */
\r
292 LCD_Character_Display_ClearDisplay();
\r
293 if( 0 == usErrorCode )
\r
295 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
296 LCD_Character_Display_PrintString( "Pass: " );
\r
297 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
298 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
299 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
300 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
304 /* Do something to indicate the failure. */
\r
305 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
306 LCD_Character_Display_PrintString( "Fail at: " );
\r
307 LCD_Character_Display_PrintNumber( ulIteration );
\r
308 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
309 LCD_Character_Display_PrintString( "Error: 0x" );
\r
310 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
314 /*---------------------------------------------------------------------------*/
\r
316 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
\r
318 /* The stack space has been execeeded for a task, considering allocating more. */
\r
319 taskDISABLE_INTERRUPTS();
\r
322 /*---------------------------------------------------------------------------*/
\r
324 void vApplicationMallocFailedHook( void )
\r
326 /* The heap space has been execeeded. */
\r
327 taskDISABLE_INTERRUPTS();
\r
330 /*---------------------------------------------------------------------------*/
\r