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
71 /* RTOS includes. */
\r
72 #include "FreeRTOS.h"
\r
77 /* Common Demo includes. */
\r
80 #include "blocktim.h"
\r
81 #include "comtest.h"
\r
82 #include "countsem.h"
\r
84 #include "dynamic.h"
\r
87 #include "GenQTest.h"
\r
88 #include "integer.h"
\r
89 #include "IntQueue.h"
\r
90 #include "mevents.h"
\r
91 #include "partest.h"
\r
95 #include "semtest.h"
\r
96 /*---------------------------------------------------------------------------*/
\r
98 /* The time between cycles of the 'check' functionality (defined within the
\r
100 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
101 #define mainCOM_LED ( 3 )
\r
103 /* The number of nano seconds between each processor clock. */
\r
104 #define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
106 /* Task priorities. */
\r
107 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
108 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
112 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
113 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
114 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
115 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 /*---------------------------------------------------------------------------*/
\r
119 * Configures the timers and interrupts for the fast interrupt test as
\r
120 * described at the top of this file.
\r
122 extern void vSetupTimerTest( void );
\r
123 /*---------------------------------------------------------------------------*/
\r
126 * The Check task periodical interrogates each of the running tests to
\r
127 * ensure that they are still executing correctly.
\r
128 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
129 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
130 * If any one of the tests fail, it is indicated with an error code printed on
\r
131 * the display. This indicator won't disappear until the device is reset.
\r
133 void vCheckTask( void *pvParameters );
\r
136 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
138 static void prvHardwareSetup( void );
\r
139 /*---------------------------------------------------------------------------*/
\r
143 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
144 prvHardwareSetup();
\r
146 /* Start the standard demo tasks. These are just here to exercise the
\r
147 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
148 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
149 vCreateBlockTimeTasks();
\r
150 vStartCountingSemaphoreTasks();
\r
151 vStartDynamicPriorityTasks();
\r
152 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
153 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
154 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
155 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
156 vStartQueuePeekTasks();
\r
157 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
158 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
159 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
160 vStartInterruptQueueTasks();
\r
162 /* Start the error checking task. */
\r
163 ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
165 /* Configure the timers used by the fast interrupt timer test. */
\r
168 /* The suicide tasks must be created last as they need to know how many
\r
169 tasks were running prior to their creation in order to ascertain whether
\r
170 or not the correct/expected number of tasks are running at any given time. */
\r
171 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
173 /* Will only get here if there was insufficient memory to create the idle
\r
174 task. The idle task is created within vTaskStartScheduler(). */
\r
175 vTaskStartScheduler();
\r
177 /* Should never reach here as the kernel will now be running. If
\r
178 vTaskStartScheduler() does return then it is very likely that there was
\r
179 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
180 including the idle task that is created within vTaskStartScheduler() itself. */
\r
183 /*---------------------------------------------------------------------------*/
\r
185 void prvHardwareSetup( void )
\r
187 /* Port layer functions that need to be copied into the vector table. */
\r
188 extern void xPortPendSVHandler( void );
\r
189 extern void xPortSysTickHandler( void );
\r
190 extern void vPortSVCHandler( void );
\r
191 extern cyisraddress CyRamVectors[];
\r
193 /* Install the OS Interrupt Handlers. */
\r
194 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
195 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
196 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
198 /* Start-up the peripherals. */
\r
200 /* Enable and clear the LCD Display. */
\r
201 LCD_Character_Display_Start();
\r
202 LCD_Character_Display_ClearDisplay();
\r
203 LCD_Character_Display_Position( 0, 0 );
\r
204 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
205 LCD_Character_Display_Position( 1, 0 );
\r
206 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
208 /* Start the UART. */
\r
211 /* Initialise the LEDs. */
\r
212 vParTestInitialise();
\r
214 /* Start the PWM modules that drive the IntQueue tests. */
\r
215 High_Frequency_PWM_0_Start();
\r
216 High_Frequency_PWM_1_Start();
\r
218 /* Start the timers for the Jitter test. */
\r
219 Timer_20KHz_Start();
\r
220 Timer_48MHz_Start();
\r
222 /*---------------------------------------------------------------------------*/
\r
224 void vCheckTask( void *pvParameters )
\r
226 unsigned long ulRow = 0;
\r
227 portTickType xDelay = 0;
\r
228 unsigned short usErrorCode = 0;
\r
229 unsigned long ulIteration = 0;
\r
230 extern unsigned portSHORT usMaxJitter;
\r
232 /* Intialise the sleeper. */
\r
233 xDelay = xTaskGetTickCount();
\r
237 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
238 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
240 /* Check that all of the Demo tasks are still running. */
\r
241 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
243 usErrorCode |= 0x1;
\r
246 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
248 usErrorCode |= 0x2;
\r
251 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
253 usErrorCode |= 0x4;
\r
256 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
258 usErrorCode |= 0x8;
\r
261 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
263 usErrorCode |= 0x10;
\r
266 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
268 usErrorCode |= 0x20;
\r
271 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
273 usErrorCode |= 0x40;
\r
276 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
278 usErrorCode |= 0x80;
\r
281 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
283 usErrorCode |= 0x100;
\r
286 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
288 usErrorCode |= 0x200;
\r
291 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
293 usErrorCode |= 0x400;
\r
296 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
298 usErrorCode |= 0x800;
\r
301 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
303 usErrorCode |= 0x1000;
\r
306 /* Clear the display. */
\r
307 LCD_Character_Display_ClearDisplay();
\r
308 if( 0 == usErrorCode )
\r
310 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
311 LCD_Character_Display_PrintString( "Pass: " );
\r
312 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
313 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
314 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
315 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
319 /* Do something to indicate the failure. */
\r
320 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
321 LCD_Character_Display_PrintString( "Fail at: " );
\r
322 LCD_Character_Display_PrintNumber( ulIteration );
\r
323 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
324 LCD_Character_Display_PrintString( "Error: 0x" );
\r
325 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
329 /*---------------------------------------------------------------------------*/
\r
331 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
333 /* The stack space has been execeeded for a task, considering allocating more. */
\r
334 taskDISABLE_INTERRUPTS();
\r
337 /*---------------------------------------------------------------------------*/
\r
339 void vApplicationMallocFailedHook( void )
\r
341 /* The heap space has been execeeded. */
\r
342 taskDISABLE_INTERRUPTS();
\r
345 /*---------------------------------------------------------------------------*/
\r