2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 /* RTOS includes. */
\r
73 #include "FreeRTOS.h"
\r
78 /* Common Demo includes. */
\r
81 #include "blocktim.h"
\r
82 #include "comtest.h"
\r
83 #include "countsem.h"
\r
85 #include "dynamic.h"
\r
88 #include "GenQTest.h"
\r
89 #include "integer.h"
\r
90 #include "IntQueue.h"
\r
91 #include "mevents.h"
\r
92 #include "partest.h"
\r
96 #include "semtest.h"
\r
97 /*---------------------------------------------------------------------------*/
\r
99 /* The time between cycles of the 'check' functionality (defined within the
\r
101 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
102 #define mainCOM_LED ( 3 )
\r
104 /* The number of nano seconds between each processor clock. */
\r
105 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
107 /* Task priorities. */
\r
108 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
110 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
113 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
114 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
115 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 /*---------------------------------------------------------------------------*/
\r
120 * Configures the timers and interrupts for the fast interrupt test as
\r
121 * described at the top of this file.
\r
123 extern void vSetupTimerTest( void );
\r
124 /*---------------------------------------------------------------------------*/
\r
127 * The Check task periodical interrogates each of the running tests to
\r
128 * ensure that they are still executing correctly.
\r
129 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
130 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
131 * If any one of the tests fail, it is indicated with an error code printed on
\r
132 * the display. This indicator won't disappear until the device is reset.
\r
134 void vCheckTask( void *pvParameters );
\r
137 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
139 static void prvHardwareSetup( void );
\r
140 /*---------------------------------------------------------------------------*/
\r
144 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
145 prvHardwareSetup();
\r
147 /* Start the standard demo tasks. These are just here to exercise the
\r
148 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
149 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
150 vCreateBlockTimeTasks();
\r
151 vStartCountingSemaphoreTasks();
\r
152 vStartDynamicPriorityTasks();
\r
153 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
154 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
155 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
156 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
157 vStartQueuePeekTasks();
\r
158 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
159 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
160 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
161 vStartInterruptQueueTasks();
\r
163 /* Start the error checking task. */
\r
164 ( void ) xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
166 /* Configure the timers used by the fast interrupt timer test. */
\r
169 /* The suicide tasks must be created last as they need to know how many
\r
170 tasks were running prior to their creation in order to ascertain whether
\r
171 or not the correct/expected number of tasks are running at any given time. */
\r
172 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
174 /* Will only get here if there was insufficient memory to create the idle
\r
175 task. The idle task is created within vTaskStartScheduler(). */
\r
176 vTaskStartScheduler();
\r
178 /* Should never reach here as the kernel will now be running. If
\r
179 vTaskStartScheduler() does return then it is very likely that there was
\r
180 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
181 including the idle task that is created within vTaskStartScheduler() itself. */
\r
184 /*---------------------------------------------------------------------------*/
\r
186 void prvHardwareSetup( void )
\r
188 /* Port layer functions that need to be copied into the vector table. */
\r
189 extern void xPortPendSVHandler( void );
\r
190 extern void xPortSysTickHandler( void );
\r
191 extern void vPortSVCHandler( void );
\r
192 extern cyisraddress CyRamVectors[];
\r
194 /* Install the OS Interrupt Handlers. */
\r
195 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
196 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
197 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
199 /* Start-up the peripherals. */
\r
201 /* Enable and clear the LCD Display. */
\r
202 LCD_Character_Display_Start();
\r
203 LCD_Character_Display_ClearDisplay();
\r
204 LCD_Character_Display_Position( 0, 0 );
\r
205 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
206 LCD_Character_Display_Position( 1, 0 );
\r
207 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
209 /* Start the UART. */
\r
212 /* Initialise the LEDs. */
\r
213 vParTestInitialise();
\r
215 /* Start the PWM modules that drive the IntQueue tests. */
\r
216 High_Frequency_PWM_0_Start();
\r
217 High_Frequency_PWM_1_Start();
\r
219 /* Start the timers for the Jitter test. */
\r
220 Timer_20KHz_Start();
\r
221 Timer_48MHz_Start();
\r
223 /*---------------------------------------------------------------------------*/
\r
225 void vCheckTask( void *pvParameters )
\r
227 unsigned long ulRow = 0;
\r
228 TickType_t xDelay = 0;
\r
229 unsigned short usErrorCode = 0;
\r
230 unsigned long ulIteration = 0;
\r
231 extern unsigned short usMaxJitter;
\r
233 /* Intialise the sleeper. */
\r
234 xDelay = xTaskGetTickCount();
\r
238 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
239 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
241 /* Check that all of the Demo tasks are still running. */
\r
242 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
244 usErrorCode |= 0x1;
\r
247 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
249 usErrorCode |= 0x2;
\r
252 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
254 usErrorCode |= 0x4;
\r
257 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
259 usErrorCode |= 0x8;
\r
262 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
264 usErrorCode |= 0x10;
\r
267 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
269 usErrorCode |= 0x20;
\r
272 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
274 usErrorCode |= 0x40;
\r
277 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
279 usErrorCode |= 0x80;
\r
282 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
284 usErrorCode |= 0x100;
\r
287 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
289 usErrorCode |= 0x200;
\r
292 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
294 usErrorCode |= 0x400;
\r
297 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
299 usErrorCode |= 0x800;
\r
302 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
304 usErrorCode |= 0x1000;
\r
307 /* Clear the display. */
\r
308 LCD_Character_Display_ClearDisplay();
\r
309 if( 0 == usErrorCode )
\r
311 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
312 LCD_Character_Display_PrintString( "Pass: " );
\r
313 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
314 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
315 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
316 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
320 /* Do something to indicate the failure. */
\r
321 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
322 LCD_Character_Display_PrintString( "Fail at: " );
\r
323 LCD_Character_Display_PrintNumber( ulIteration );
\r
324 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
325 LCD_Character_Display_PrintString( "Error: 0x" );
\r
326 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
330 /*---------------------------------------------------------------------------*/
\r
332 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
334 /* The stack space has been execeeded for a task, considering allocating more. */
\r
335 taskDISABLE_INTERRUPTS();
\r
338 /*---------------------------------------------------------------------------*/
\r
340 void vApplicationMallocFailedHook( void )
\r
342 /* The heap space has been execeeded. */
\r
343 taskDISABLE_INTERRUPTS();
\r
346 /*---------------------------------------------------------------------------*/
\r