2 FreeRTOS V7.4.0 - Copyright (C) 2013 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
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
77 /* RTOS includes. */
\r
78 #include "FreeRTOS.h"
\r
83 /* Common Demo includes. */
\r
86 #include "blocktim.h"
\r
87 #include "comtest.h"
\r
88 #include "countsem.h"
\r
90 #include "dynamic.h"
\r
93 #include "GenQTest.h"
\r
94 #include "integer.h"
\r
95 #include "IntQueue.h"
\r
96 #include "mevents.h"
\r
97 #include "partest.h"
\r
101 #include "semtest.h"
\r
102 /*---------------------------------------------------------------------------*/
\r
104 /* The time between cycles of the 'check' functionality (defined within the
\r
106 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
107 #define mainCOM_LED ( 3 )
\r
109 /* The number of nano seconds between each processor clock. */
\r
110 #define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
112 /* Task priorities. */
\r
113 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
115 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
118 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
119 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
120 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
122 /*---------------------------------------------------------------------------*/
\r
125 * Configures the timers and interrupts for the fast interrupt test as
\r
126 * described at the top of this file.
\r
128 extern void vSetupTimerTest( void );
\r
129 /*---------------------------------------------------------------------------*/
\r
132 * The Check task periodical interrogates each of the running tests to
\r
133 * ensure that they are still executing correctly.
\r
134 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
135 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
136 * If any one of the tests fail, it is indicated with an error code printed on
\r
137 * the display. This indicator won't disappear until the device is reset.
\r
139 void vCheckTask( void *pvParameters );
\r
142 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
144 static void prvHardwareSetup( void );
\r
145 /*---------------------------------------------------------------------------*/
\r
149 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
150 prvHardwareSetup();
\r
152 /* Start the standard demo tasks. These are just here to exercise the
\r
153 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
154 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
155 vCreateBlockTimeTasks();
\r
156 vStartCountingSemaphoreTasks();
\r
157 vStartDynamicPriorityTasks();
\r
158 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
159 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
160 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
161 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
162 vStartQueuePeekTasks();
\r
163 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
164 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
165 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
166 vStartInterruptQueueTasks();
\r
168 /* Start the error checking task. */
\r
169 ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
171 /* Configure the timers used by the fast interrupt timer test. */
\r
174 /* The suicide tasks must be created last as they need to know how many
\r
175 tasks were running prior to their creation in order to ascertain whether
\r
176 or not the correct/expected number of tasks are running at any given time. */
\r
177 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
179 /* Will only get here if there was insufficient memory to create the idle
\r
180 task. The idle task is created within vTaskStartScheduler(). */
\r
181 vTaskStartScheduler();
\r
183 /* Should never reach here as the kernel will now be running. If
\r
184 vTaskStartScheduler() does return then it is very likely that there was
\r
185 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
186 including the idle task that is created within vTaskStartScheduler() itself. */
\r
189 /*---------------------------------------------------------------------------*/
\r
191 void prvHardwareSetup( void )
\r
193 /* Port layer functions that need to be copied into the vector table. */
\r
194 extern void xPortPendSVHandler( void );
\r
195 extern void xPortSysTickHandler( void );
\r
196 extern void vPortSVCHandler( void );
\r
197 extern cyisraddress CyRamVectors[];
\r
199 /* Install the OS Interrupt Handlers. */
\r
200 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
201 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
202 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
204 /* Start-up the peripherals. */
\r
206 /* Enable and clear the LCD Display. */
\r
207 LCD_Character_Display_Start();
\r
208 LCD_Character_Display_ClearDisplay();
\r
209 LCD_Character_Display_Position( 0, 0 );
\r
210 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
211 LCD_Character_Display_Position( 1, 0 );
\r
212 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
214 /* Start the UART. */
\r
217 /* Initialise the LEDs. */
\r
218 vParTestInitialise();
\r
220 /* Start the PWM modules that drive the IntQueue tests. */
\r
221 High_Frequency_PWM_0_Start();
\r
222 High_Frequency_PWM_1_Start();
\r
224 /* Start the timers for the Jitter test. */
\r
225 Timer_20KHz_Start();
\r
226 Timer_48MHz_Start();
\r
228 /*---------------------------------------------------------------------------*/
\r
230 void vCheckTask( void *pvParameters )
\r
232 unsigned long ulRow = 0;
\r
233 portTickType xDelay = 0;
\r
234 unsigned short usErrorCode = 0;
\r
235 unsigned long ulIteration = 0;
\r
236 extern unsigned portSHORT usMaxJitter;
\r
238 /* Intialise the sleeper. */
\r
239 xDelay = xTaskGetTickCount();
\r
243 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
244 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
246 /* Check that all of the Demo tasks are still running. */
\r
247 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
249 usErrorCode |= 0x1;
\r
252 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
254 usErrorCode |= 0x2;
\r
257 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
259 usErrorCode |= 0x4;
\r
262 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
264 usErrorCode |= 0x8;
\r
267 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
269 usErrorCode |= 0x10;
\r
272 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
274 usErrorCode |= 0x20;
\r
277 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
279 usErrorCode |= 0x40;
\r
282 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
284 usErrorCode |= 0x80;
\r
287 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
289 usErrorCode |= 0x100;
\r
292 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
294 usErrorCode |= 0x200;
\r
297 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
299 usErrorCode |= 0x400;
\r
302 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
304 usErrorCode |= 0x800;
\r
307 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
309 usErrorCode |= 0x1000;
\r
312 /* Clear the display. */
\r
313 LCD_Character_Display_ClearDisplay();
\r
314 if( 0 == usErrorCode )
\r
316 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
317 LCD_Character_Display_PrintString( "Pass: " );
\r
318 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
319 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
320 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
321 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
325 /* Do something to indicate the failure. */
\r
326 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
327 LCD_Character_Display_PrintString( "Fail at: " );
\r
328 LCD_Character_Display_PrintNumber( ulIteration );
\r
329 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
330 LCD_Character_Display_PrintString( "Error: 0x" );
\r
331 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
335 /*---------------------------------------------------------------------------*/
\r
337 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
339 /* The stack space has been execeeded for a task, considering allocating more. */
\r
340 taskDISABLE_INTERRUPTS();
\r
343 /*---------------------------------------------------------------------------*/
\r
345 void vApplicationMallocFailedHook( void )
\r
347 /* The heap space has been execeeded. */
\r
348 taskDISABLE_INTERRUPTS();
\r
351 /*---------------------------------------------------------------------------*/
\r