2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
67 /* RTOS includes. */
\r
68 #include "FreeRTOS.h"
\r
73 /* Common Demo includes. */
\r
76 #include "blocktim.h"
\r
77 #include "comtest.h"
\r
78 #include "countsem.h"
\r
80 #include "dynamic.h"
\r
83 #include "GenQTest.h"
\r
84 #include "integer.h"
\r
85 #include "IntQueue.h"
\r
86 #include "mevents.h"
\r
87 #include "partest.h"
\r
91 #include "semtest.h"
\r
92 /*---------------------------------------------------------------------------*/
\r
94 /* The time between cycles of the 'check' functionality (defined within the
\r
96 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
97 #define mainCOM_LED ( 3 )
\r
99 /* The number of nano seconds between each processor clock. */
\r
100 #define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
102 /* Task priorities. */
\r
103 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
104 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
105 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
106 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
107 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
108 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
109 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
110 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 /*---------------------------------------------------------------------------*/
\r
115 * Configures the timers and interrupts for the fast interrupt test as
\r
116 * described at the top of this file.
\r
118 extern void vSetupTimerTest( void );
\r
119 /*---------------------------------------------------------------------------*/
\r
122 * The Check task periodical interrogates each of the running tests to
\r
123 * ensure that they are still executing correctly.
\r
124 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
125 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
126 * If any one of the tests fail, it is indicated with an error code printed on
\r
127 * the display. This indicator won't disappear until the device is reset.
\r
129 void vCheckTask( void *pvParameters );
\r
132 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
134 static void prvHardwareSetup( void );
\r
135 /*---------------------------------------------------------------------------*/
\r
139 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
140 prvHardwareSetup();
\r
142 /* Start the standard demo tasks. These are just here to exercise the
\r
143 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
144 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
145 vCreateBlockTimeTasks();
\r
146 vStartCountingSemaphoreTasks();
\r
147 vStartDynamicPriorityTasks();
\r
148 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
149 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
150 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
151 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
152 vStartQueuePeekTasks();
\r
153 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
154 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
155 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
156 vStartInterruptQueueTasks();
\r
158 /* Start the error checking task. */
\r
159 ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
161 /* Configure the timers used by the fast interrupt timer test. */
\r
164 /* The suicide tasks must be created last as they need to know how many
\r
165 tasks were running prior to their creation in order to ascertain whether
\r
166 or not the correct/expected number of tasks are running at any given time. */
\r
167 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
169 /* Will only get here if there was insufficient memory to create the idle
\r
170 task. The idle task is created within vTaskStartScheduler(). */
\r
171 vTaskStartScheduler();
\r
173 /* Should never reach here as the kernel will now be running. If
\r
174 vTaskStartScheduler() does return then it is very likely that there was
\r
175 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
176 including the idle task that is created within vTaskStartScheduler() itself. */
\r
179 /*---------------------------------------------------------------------------*/
\r
181 void prvHardwareSetup( void )
\r
183 /* Port layer functions that need to be copied into the vector table. */
\r
184 extern void xPortPendSVHandler( void );
\r
185 extern void xPortSysTickHandler( void );
\r
186 extern void vPortSVCHandler( void );
\r
187 extern cyisraddress CyRamVectors[];
\r
189 /* Install the OS Interrupt Handlers. */
\r
190 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
191 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
192 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
194 /* Start-up the peripherals. */
\r
196 /* Enable and clear the LCD Display. */
\r
197 LCD_Character_Display_Start();
\r
198 LCD_Character_Display_ClearDisplay();
\r
199 LCD_Character_Display_Position( 0, 0 );
\r
200 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
201 LCD_Character_Display_Position( 1, 0 );
\r
202 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
204 /* Start the UART. */
\r
207 /* Initialise the LEDs. */
\r
208 vParTestInitialise();
\r
210 /* Start the PWM modules that drive the IntQueue tests. */
\r
211 High_Frequency_PWM_0_Start();
\r
212 High_Frequency_PWM_1_Start();
\r
214 /* Start the timers for the Jitter test. */
\r
215 Timer_20KHz_Start();
\r
216 Timer_48MHz_Start();
\r
218 /*---------------------------------------------------------------------------*/
\r
220 void vCheckTask( void *pvParameters )
\r
222 unsigned long ulRow = 0;
\r
223 portTickType xDelay = 0;
\r
224 unsigned short usErrorCode = 0;
\r
225 unsigned long ulIteration = 0;
\r
226 extern unsigned portSHORT usMaxJitter;
\r
228 /* Intialise the sleeper. */
\r
229 xDelay = xTaskGetTickCount();
\r
233 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
234 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
236 /* Check that all of the Demo tasks are still running. */
\r
237 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
239 usErrorCode |= 0x1;
\r
242 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
244 usErrorCode |= 0x2;
\r
247 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
249 usErrorCode |= 0x4;
\r
252 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
254 usErrorCode |= 0x8;
\r
257 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
259 usErrorCode |= 0x10;
\r
262 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
264 usErrorCode |= 0x20;
\r
267 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
269 usErrorCode |= 0x40;
\r
272 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
274 usErrorCode |= 0x80;
\r
277 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
279 usErrorCode |= 0x100;
\r
282 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
284 usErrorCode |= 0x200;
\r
287 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
289 usErrorCode |= 0x400;
\r
292 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
294 usErrorCode |= 0x800;
\r
297 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
299 usErrorCode |= 0x1000;
\r
302 /* Clear the display. */
\r
303 LCD_Character_Display_ClearDisplay();
\r
304 if( 0 == usErrorCode )
\r
306 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
307 LCD_Character_Display_PrintString( "Pass: " );
\r
308 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
309 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
310 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
311 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
315 /* Do something to indicate the failure. */
\r
316 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
317 LCD_Character_Display_PrintString( "Fail at: " );
\r
318 LCD_Character_Display_PrintNumber( ulIteration );
\r
319 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
320 LCD_Character_Display_PrintString( "Error: 0x" );
\r
321 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
325 /*---------------------------------------------------------------------------*/
\r
327 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
329 /* The stack space has been execeeded for a task, considering allocating more. */
\r
330 taskDISABLE_INTERRUPTS();
\r
333 /*---------------------------------------------------------------------------*/
\r
335 void vApplicationMallocFailedHook( void )
\r
337 /* The heap space has been execeeded. */
\r
338 taskDISABLE_INTERRUPTS();
\r
341 /*---------------------------------------------------------------------------*/
\r