2 FreeRTOS V8.1.0 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
68 /* RTOS includes. */
\r
69 #include "FreeRTOS.h"
\r
74 /* Common Demo includes. */
\r
77 #include "blocktim.h"
\r
78 #include "comtest.h"
\r
79 #include "countsem.h"
\r
81 #include "dynamic.h"
\r
84 #include "GenQTest.h"
\r
85 #include "integer.h"
\r
86 #include "IntQueue.h"
\r
87 #include "mevents.h"
\r
88 #include "partest.h"
\r
92 #include "semtest.h"
\r
93 /*---------------------------------------------------------------------------*/
\r
95 /* The time between cycles of the 'check' functionality (defined within the
\r
97 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
98 #define mainCOM_LED ( 3 )
\r
100 /* The number of nano seconds between each processor clock. */
\r
101 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
103 /* Task priorities. */
\r
104 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
106 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
107 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
108 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
109 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
110 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
111 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
113 /*---------------------------------------------------------------------------*/
\r
116 * Configures the timers and interrupts for the fast interrupt test as
\r
117 * described at the top of this file.
\r
119 extern void vSetupTimerTest( void );
\r
120 /*---------------------------------------------------------------------------*/
\r
123 * The Check task periodical interrogates each of the running tests to
\r
124 * ensure that they are still executing correctly.
\r
125 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
126 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
127 * If any one of the tests fail, it is indicated with an error code printed on
\r
128 * the display. This indicator won't disappear until the device is reset.
\r
130 void vCheckTask( void *pvParameters );
\r
133 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
135 static void prvHardwareSetup( void );
\r
136 /*---------------------------------------------------------------------------*/
\r
140 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
141 prvHardwareSetup();
\r
143 /* Start the standard demo tasks. These are just here to exercise the
\r
144 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
145 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
146 vCreateBlockTimeTasks();
\r
147 vStartCountingSemaphoreTasks();
\r
148 vStartDynamicPriorityTasks();
\r
149 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
150 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
151 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
152 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
153 vStartQueuePeekTasks();
\r
154 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
155 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
156 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
157 vStartInterruptQueueTasks();
\r
159 /* Start the error checking task. */
\r
160 ( void ) xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
162 /* Configure the timers used by the fast interrupt timer test. */
\r
165 /* The suicide tasks must be created last as they need to know how many
\r
166 tasks were running prior to their creation in order to ascertain whether
\r
167 or not the correct/expected number of tasks are running at any given time. */
\r
168 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
170 /* Will only get here if there was insufficient memory to create the idle
\r
171 task. The idle task is created within vTaskStartScheduler(). */
\r
172 vTaskStartScheduler();
\r
174 /* Should never reach here as the kernel will now be running. If
\r
175 vTaskStartScheduler() does return then it is very likely that there was
\r
176 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
177 including the idle task that is created within vTaskStartScheduler() itself. */
\r
180 /*---------------------------------------------------------------------------*/
\r
182 void prvHardwareSetup( void )
\r
184 /* Port layer functions that need to be copied into the vector table. */
\r
185 extern void xPortPendSVHandler( void );
\r
186 extern void xPortSysTickHandler( void );
\r
187 extern void vPortSVCHandler( void );
\r
188 extern cyisraddress CyRamVectors[];
\r
190 /* Install the OS Interrupt Handlers. */
\r
191 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
192 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
193 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
195 /* Start-up the peripherals. */
\r
197 /* Enable and clear the LCD Display. */
\r
198 LCD_Character_Display_Start();
\r
199 LCD_Character_Display_ClearDisplay();
\r
200 LCD_Character_Display_Position( 0, 0 );
\r
201 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
202 LCD_Character_Display_Position( 1, 0 );
\r
203 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
205 /* Start the UART. */
\r
208 /* Initialise the LEDs. */
\r
209 vParTestInitialise();
\r
211 /* Start the PWM modules that drive the IntQueue tests. */
\r
212 High_Frequency_PWM_0_Start();
\r
213 High_Frequency_PWM_1_Start();
\r
215 /* Start the timers for the Jitter test. */
\r
216 Timer_20KHz_Start();
\r
217 Timer_48MHz_Start();
\r
219 /*---------------------------------------------------------------------------*/
\r
221 void vCheckTask( void *pvParameters )
\r
223 unsigned long ulRow = 0;
\r
224 TickType_t xDelay = 0;
\r
225 unsigned short usErrorCode = 0;
\r
226 unsigned long ulIteration = 0;
\r
227 extern unsigned short usMaxJitter;
\r
229 /* Intialise the sleeper. */
\r
230 xDelay = xTaskGetTickCount();
\r
234 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
235 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
237 /* Check that all of the Demo tasks are still running. */
\r
238 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
240 usErrorCode |= 0x1;
\r
243 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
245 usErrorCode |= 0x2;
\r
248 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
250 usErrorCode |= 0x4;
\r
253 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
255 usErrorCode |= 0x8;
\r
258 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
260 usErrorCode |= 0x10;
\r
263 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
265 usErrorCode |= 0x20;
\r
268 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
270 usErrorCode |= 0x40;
\r
273 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
275 usErrorCode |= 0x80;
\r
278 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
280 usErrorCode |= 0x100;
\r
283 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
285 usErrorCode |= 0x200;
\r
288 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
290 usErrorCode |= 0x400;
\r
293 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
295 usErrorCode |= 0x800;
\r
298 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
300 usErrorCode |= 0x1000;
\r
303 /* Clear the display. */
\r
304 LCD_Character_Display_ClearDisplay();
\r
305 if( 0 == usErrorCode )
\r
307 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
308 LCD_Character_Display_PrintString( "Pass: " );
\r
309 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
310 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
311 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
312 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
316 /* Do something to indicate the failure. */
\r
317 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
318 LCD_Character_Display_PrintString( "Fail at: " );
\r
319 LCD_Character_Display_PrintNumber( ulIteration );
\r
320 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
321 LCD_Character_Display_PrintString( "Error: 0x" );
\r
322 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
326 /*---------------------------------------------------------------------------*/
\r
328 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
330 /* The stack space has been execeeded for a task, considering allocating more. */
\r
331 taskDISABLE_INTERRUPTS();
\r
334 /*---------------------------------------------------------------------------*/
\r
336 void vApplicationMallocFailedHook( void )
\r
338 /* The heap space has been execeeded. */
\r
339 taskDISABLE_INTERRUPTS();
\r
342 /*---------------------------------------------------------------------------*/
\r