2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\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 modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or 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 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
69 /* RTOS includes. */
\r
70 #include "FreeRTOS.h"
\r
75 /* Common Demo includes. */
\r
78 #include "blocktim.h"
\r
79 #include "comtest.h"
\r
80 #include "countsem.h"
\r
82 #include "dynamic.h"
\r
85 #include "GenQTest.h"
\r
86 #include "integer.h"
\r
87 #include "IntQueue.h"
\r
88 #include "mevents.h"
\r
89 #include "partest.h"
\r
93 #include "semtest.h"
\r
94 /*---------------------------------------------------------------------------*/
\r
96 /* The time between cycles of the 'check' functionality (defined within the
\r
98 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
99 #define mainCOM_LED ( 3 )
\r
101 /* The number of nano seconds between each processor clock. */
\r
102 #define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
104 /* Task priorities. */
\r
105 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
107 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
108 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
110 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
111 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
112 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 /*---------------------------------------------------------------------------*/
\r
117 * Configures the timers and interrupts for the fast interrupt test as
\r
118 * described at the top of this file.
\r
120 extern void vSetupTimerTest( void );
\r
121 /*---------------------------------------------------------------------------*/
\r
124 * The Check task periodical interrogates each of the running tests to
\r
125 * ensure that they are still executing correctly.
\r
126 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
127 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
128 * If any one of the tests fail, it is indicated with an error code printed on
\r
129 * the display. This indicator won't disappear until the device is reset.
\r
131 void vCheckTask( void *pvParameters );
\r
134 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
136 static void prvHardwareSetup( void );
\r
137 /*---------------------------------------------------------------------------*/
\r
141 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
142 prvHardwareSetup();
\r
144 /* Start the standard demo tasks. These are just here to exercise the
\r
145 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
146 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
147 vCreateBlockTimeTasks();
\r
148 vStartCountingSemaphoreTasks();
\r
149 vStartDynamicPriorityTasks();
\r
150 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
151 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
152 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
153 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
154 vStartQueuePeekTasks();
\r
155 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
156 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
157 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
158 vStartInterruptQueueTasks();
\r
160 /* Start the error checking task. */
\r
161 ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
163 /* Configure the timers used by the fast interrupt timer test. */
\r
166 /* The suicide tasks must be created last as they need to know how many
\r
167 tasks were running prior to their creation in order to ascertain whether
\r
168 or not the correct/expected number of tasks are running at any given time. */
\r
169 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
171 /* Will only get here if there was insufficient memory to create the idle
\r
172 task. The idle task is created within vTaskStartScheduler(). */
\r
173 vTaskStartScheduler();
\r
175 /* Should never reach here as the kernel will now be running. If
\r
176 vTaskStartScheduler() does return then it is very likely that there was
\r
177 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
178 including the idle task that is created within vTaskStartScheduler() itself. */
\r
181 /*---------------------------------------------------------------------------*/
\r
183 void prvHardwareSetup( void )
\r
185 /* Port layer functions that need to be copied into the vector table. */
\r
186 extern void xPortPendSVHandler( void );
\r
187 extern void xPortSysTickHandler( void );
\r
188 extern void vPortSVCHandler( void );
\r
189 extern cyisraddress CyRamVectors[];
\r
191 /* Install the OS Interrupt Handlers. */
\r
192 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
193 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
194 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
196 /* Start-up the peripherals. */
\r
198 /* Enable and clear the LCD Display. */
\r
199 LCD_Character_Display_Start();
\r
200 LCD_Character_Display_ClearDisplay();
\r
201 LCD_Character_Display_Position( 0, 0 );
\r
202 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
203 LCD_Character_Display_Position( 1, 0 );
\r
204 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
206 /* Start the UART. */
\r
209 /* Initialise the LEDs. */
\r
210 vParTestInitialise();
\r
212 /* Start the PWM modules that drive the IntQueue tests. */
\r
213 High_Frequency_PWM_0_Start();
\r
214 High_Frequency_PWM_1_Start();
\r
216 /* Start the timers for the Jitter test. */
\r
217 Timer_20KHz_Start();
\r
218 Timer_48MHz_Start();
\r
220 /*---------------------------------------------------------------------------*/
\r
222 void vCheckTask( void *pvParameters )
\r
224 unsigned long ulRow = 0;
\r
225 portTickType xDelay = 0;
\r
226 unsigned short usErrorCode = 0;
\r
227 unsigned long ulIteration = 0;
\r
228 extern unsigned portSHORT usMaxJitter;
\r
230 /* Intialise the sleeper. */
\r
231 xDelay = xTaskGetTickCount();
\r
235 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
236 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
238 /* Check that all of the Demo tasks are still running. */
\r
239 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
241 usErrorCode |= 0x1;
\r
244 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
246 usErrorCode |= 0x2;
\r
249 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
251 usErrorCode |= 0x4;
\r
254 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
256 usErrorCode |= 0x8;
\r
259 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
261 usErrorCode |= 0x10;
\r
264 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
266 usErrorCode |= 0x20;
\r
269 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
271 usErrorCode |= 0x40;
\r
274 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
276 usErrorCode |= 0x80;
\r
279 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
281 usErrorCode |= 0x100;
\r
284 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
286 usErrorCode |= 0x200;
\r
289 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
291 usErrorCode |= 0x400;
\r
294 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
296 usErrorCode |= 0x800;
\r
299 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
301 usErrorCode |= 0x1000;
\r
304 /* Clear the display. */
\r
305 LCD_Character_Display_ClearDisplay();
\r
306 if( 0 == usErrorCode )
\r
308 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
309 LCD_Character_Display_PrintString( "Pass: " );
\r
310 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
311 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
312 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
313 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
317 /* Do something to indicate the failure. */
\r
318 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
319 LCD_Character_Display_PrintString( "Fail at: " );
\r
320 LCD_Character_Display_PrintNumber( ulIteration );
\r
321 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
322 LCD_Character_Display_PrintString( "Error: 0x" );
\r
323 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
327 /*---------------------------------------------------------------------------*/
\r
329 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
331 /* The stack space has been execeeded for a task, considering allocating more. */
\r
332 taskDISABLE_INTERRUPTS();
\r
335 /*---------------------------------------------------------------------------*/
\r
337 void vApplicationMallocFailedHook( void )
\r
339 /* The heap space has been execeeded. */
\r
340 taskDISABLE_INTERRUPTS();
\r
343 /*---------------------------------------------------------------------------*/
\r