2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
31 /* RTOS includes. */
\r
32 #include "FreeRTOS.h"
\r
37 /* Common Demo includes. */
\r
40 #include "blocktim.h"
\r
41 #include "comtest.h"
\r
42 #include "countsem.h"
\r
44 #include "dynamic.h"
\r
47 #include "GenQTest.h"
\r
48 #include "integer.h"
\r
49 #include "IntQueue.h"
\r
50 #include "mevents.h"
\r
51 #include "partest.h"
\r
55 #include "semtest.h"
\r
56 /*---------------------------------------------------------------------------*/
\r
58 /* The time between cycles of the 'check' functionality (defined within the
\r
60 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
61 #define mainCOM_LED ( 3 )
\r
63 /* The number of nano seconds between each processor clock. */
\r
64 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
66 /* Task priorities. */
\r
67 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
68 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
69 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
70 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
71 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
72 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
73 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
74 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
75 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
76 /*---------------------------------------------------------------------------*/
\r
79 * Configures the timers and interrupts for the fast interrupt test as
\r
80 * described at the top of this file.
\r
82 extern void vSetupTimerTest( void );
\r
83 /*---------------------------------------------------------------------------*/
\r
86 * The Check task periodical interrogates each of the running tests to
\r
87 * ensure that they are still executing correctly.
\r
88 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
89 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
90 * If any one of the tests fail, it is indicated with an error code printed on
\r
91 * the display. This indicator won't disappear until the device is reset.
\r
93 void vCheckTask( void *pvParameters );
\r
96 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
98 static void prvHardwareSetup( void );
\r
99 /*---------------------------------------------------------------------------*/
\r
103 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
104 prvHardwareSetup();
\r
106 /* Start the standard demo tasks. These are just here to exercise the
\r
107 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
108 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
109 vCreateBlockTimeTasks();
\r
110 vStartCountingSemaphoreTasks();
\r
111 vStartDynamicPriorityTasks();
\r
112 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
113 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
114 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
115 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
116 vStartQueuePeekTasks();
\r
117 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
118 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
119 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
120 vStartInterruptQueueTasks();
\r
122 /* Start the error checking task. */
\r
123 ( void ) xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
125 /* Configure the timers used by the fast interrupt timer test. */
\r
128 /* The suicide tasks must be created last as they need to know how many
\r
129 tasks were running prior to their creation in order to ascertain whether
\r
130 or not the correct/expected number of tasks are running at any given time. */
\r
131 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
133 /* Will only get here if there was insufficient memory to create the idle
\r
134 task. The idle task is created within vTaskStartScheduler(). */
\r
135 vTaskStartScheduler();
\r
137 /* Should never reach here as the kernel will now be running. If
\r
138 vTaskStartScheduler() does return then it is very likely that there was
\r
139 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
140 including the idle task that is created within vTaskStartScheduler() itself. */
\r
143 /*---------------------------------------------------------------------------*/
\r
145 void prvHardwareSetup( void )
\r
147 /* Port layer functions that need to be copied into the vector table. */
\r
148 extern void xPortPendSVHandler( void );
\r
149 extern void xPortSysTickHandler( void );
\r
150 extern void vPortSVCHandler( void );
\r
151 extern cyisraddress CyRamVectors[];
\r
153 /* Install the OS Interrupt Handlers. */
\r
154 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
155 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
156 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
158 /* Start-up the peripherals. */
\r
160 /* Enable and clear the LCD Display. */
\r
161 LCD_Character_Display_Start();
\r
162 LCD_Character_Display_ClearDisplay();
\r
163 LCD_Character_Display_Position( 0, 0 );
\r
164 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
165 LCD_Character_Display_Position( 1, 0 );
\r
166 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
168 /* Start the UART. */
\r
171 /* Initialise the LEDs. */
\r
172 vParTestInitialise();
\r
174 /* Start the PWM modules that drive the IntQueue tests. */
\r
175 High_Frequency_PWM_0_Start();
\r
176 High_Frequency_PWM_1_Start();
\r
178 /* Start the timers for the Jitter test. */
\r
179 Timer_20KHz_Start();
\r
180 Timer_48MHz_Start();
\r
182 /*---------------------------------------------------------------------------*/
\r
184 void vCheckTask( void *pvParameters )
\r
186 unsigned long ulRow = 0;
\r
187 TickType_t xDelay = 0;
\r
188 unsigned short usErrorCode = 0;
\r
189 unsigned long ulIteration = 0;
\r
190 extern unsigned short usMaxJitter;
\r
192 /* Intialise the sleeper. */
\r
193 xDelay = xTaskGetTickCount();
\r
197 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
198 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
200 /* Check that all of the Demo tasks are still running. */
\r
201 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
203 usErrorCode |= 0x1;
\r
206 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
208 usErrorCode |= 0x2;
\r
211 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
213 usErrorCode |= 0x4;
\r
216 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
218 usErrorCode |= 0x8;
\r
221 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
223 usErrorCode |= 0x10;
\r
226 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
228 usErrorCode |= 0x20;
\r
231 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
233 usErrorCode |= 0x40;
\r
236 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
238 usErrorCode |= 0x80;
\r
241 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
243 usErrorCode |= 0x100;
\r
246 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
248 usErrorCode |= 0x200;
\r
251 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
253 usErrorCode |= 0x400;
\r
256 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
258 usErrorCode |= 0x800;
\r
261 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
263 usErrorCode |= 0x1000;
\r
266 /* Clear the display. */
\r
267 LCD_Character_Display_ClearDisplay();
\r
268 if( 0 == usErrorCode )
\r
270 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
271 LCD_Character_Display_PrintString( "Pass: " );
\r
272 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
273 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
274 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
275 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
279 /* Do something to indicate the failure. */
\r
280 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
281 LCD_Character_Display_PrintString( "Fail at: " );
\r
282 LCD_Character_Display_PrintNumber( ulIteration );
\r
283 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
284 LCD_Character_Display_PrintString( "Error: 0x" );
\r
285 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
289 /*---------------------------------------------------------------------------*/
\r
291 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
293 /* The stack space has been execeeded for a task, considering allocating more. */
\r
294 taskDISABLE_INTERRUPTS();
\r
297 /*---------------------------------------------------------------------------*/
\r
299 void vApplicationMallocFailedHook( void )
\r
301 /* The heap space has been execeeded. */
\r
302 taskDISABLE_INTERRUPTS();
\r
305 /*---------------------------------------------------------------------------*/
\r