2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
30 /* RTOS includes. */
\r
31 #include "FreeRTOS.h"
\r
36 /* Common Demo includes. */
\r
39 #include "blocktim.h"
\r
40 #include "comtest.h"
\r
41 #include "countsem.h"
\r
43 #include "dynamic.h"
\r
46 #include "GenQTest.h"
\r
47 #include "integer.h"
\r
48 #include "IntQueue.h"
\r
49 #include "mevents.h"
\r
50 #include "partest.h"
\r
54 #include "semtest.h"
\r
55 /*---------------------------------------------------------------------------*/
\r
57 /* The time between cycles of the 'check' functionality (defined within the
\r
59 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
60 #define mainCOM_LED ( 3 )
\r
62 /* The number of nano seconds between each processor clock. */
\r
63 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
65 /* Task priorities. */
\r
66 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
67 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
68 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
69 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
70 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
71 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
72 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
73 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
74 #define mainFLASH_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
75 /*---------------------------------------------------------------------------*/
\r
78 * Configures the timers and interrupts for the fast interrupt test as
\r
79 * described at the top of this file.
\r
81 extern void vSetupTimerTest( void );
\r
82 /*---------------------------------------------------------------------------*/
\r
85 * The Check task periodical interrogates each of the running tests to
\r
86 * ensure that they are still executing correctly.
\r
87 * If all the tests pass, then the LCD is updated with Pass, the number of
\r
88 * iterations and the Jitter time calculated but the Fast Interrupt Test.
\r
89 * If any one of the tests fail, it is indicated with an error code printed on
\r
90 * the display. This indicator won't disappear until the device is reset.
\r
92 void vCheckTask( void *pvParameters );
\r
95 * Installs the RTOS interrupt handlers and starts the peripherals.
\r
97 static void prvHardwareSetup( void );
\r
98 /*---------------------------------------------------------------------------*/
\r
102 /* Place your initialization/startup code here (e.g. MyInst_Start()) */
\r
103 prvHardwareSetup();
\r
105 /* Start the standard demo tasks. These are just here to exercise the
\r
106 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
107 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
108 vCreateBlockTimeTasks();
\r
109 vStartCountingSemaphoreTasks();
\r
110 vStartDynamicPriorityTasks();
\r
111 vStartMathTasks( mainINTEGER_TASK_PRIORITY );
\r
112 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
113 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
114 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
115 vStartQueuePeekTasks();
\r
116 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
117 vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );
\r
118 vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );
\r
119 vStartInterruptQueueTasks();
\r
121 /* Start the error checking task. */
\r
122 ( void ) xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
124 /* Configure the timers used by the fast interrupt timer test. */
\r
127 /* The suicide tasks must be created last as they need to know how many
\r
128 tasks were running prior to their creation in order to ascertain whether
\r
129 or not the correct/expected number of tasks are running at any given time. */
\r
130 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
132 /* Will only get here if there was insufficient memory to create the idle
\r
133 task. The idle task is created within vTaskStartScheduler(). */
\r
134 vTaskStartScheduler();
\r
136 /* Should never reach here as the kernel will now be running. If
\r
137 vTaskStartScheduler() does return then it is very likely that there was
\r
138 insufficient (FreeRTOS) heap space available to create all the tasks,
\r
139 including the idle task that is created within vTaskStartScheduler() itself. */
\r
142 /*---------------------------------------------------------------------------*/
\r
144 void prvHardwareSetup( void )
\r
146 /* Port layer functions that need to be copied into the vector table. */
\r
147 extern void xPortPendSVHandler( void );
\r
148 extern void xPortSysTickHandler( void );
\r
149 extern void vPortSVCHandler( void );
\r
150 extern cyisraddress CyRamVectors[];
\r
152 /* Install the OS Interrupt Handlers. */
\r
153 CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;
\r
154 CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;
\r
155 CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;
\r
157 /* Start-up the peripherals. */
\r
159 /* Enable and clear the LCD Display. */
\r
160 LCD_Character_Display_Start();
\r
161 LCD_Character_Display_ClearDisplay();
\r
162 LCD_Character_Display_Position( 0, 0 );
\r
163 LCD_Character_Display_PrintString( "www.FreeRTOS.org " );
\r
164 LCD_Character_Display_Position( 1, 0 );
\r
165 LCD_Character_Display_PrintString("CY8C5588AX-060 ");
\r
167 /* Start the UART. */
\r
170 /* Initialise the LEDs. */
\r
171 vParTestInitialise();
\r
173 /* Start the PWM modules that drive the IntQueue tests. */
\r
174 High_Frequency_PWM_0_Start();
\r
175 High_Frequency_PWM_1_Start();
\r
177 /* Start the timers for the Jitter test. */
\r
178 Timer_20KHz_Start();
\r
179 Timer_48MHz_Start();
\r
181 /*---------------------------------------------------------------------------*/
\r
183 void vCheckTask( void *pvParameters )
\r
185 unsigned long ulRow = 0;
\r
186 TickType_t xDelay = 0;
\r
187 unsigned short usErrorCode = 0;
\r
188 unsigned long ulIteration = 0;
\r
189 extern unsigned short usMaxJitter;
\r
191 /* Intialise the sleeper. */
\r
192 xDelay = xTaskGetTickCount();
\r
196 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
197 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );
\r
199 /* Check that all of the Demo tasks are still running. */
\r
200 if( pdTRUE != xAreBlockingQueuesStillRunning() )
\r
202 usErrorCode |= 0x1;
\r
205 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )
\r
207 usErrorCode |= 0x2;
\r
210 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )
\r
212 usErrorCode |= 0x4;
\r
215 if( pdTRUE != xIsCreateTaskStillRunning() )
\r
217 usErrorCode |= 0x8;
\r
220 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )
\r
222 usErrorCode |= 0x10;
\r
225 if( pdTRUE != xAreMathsTaskStillRunning() )
\r
227 usErrorCode |= 0x20;
\r
230 if( pdTRUE != xAreGenericQueueTasksStillRunning() )
\r
232 usErrorCode |= 0x40;
\r
235 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )
\r
237 usErrorCode |= 0x80;
\r
240 if( pdTRUE != xArePollingQueuesStillRunning() )
\r
242 usErrorCode |= 0x100;
\r
245 if( pdTRUE != xAreQueuePeekTasksStillRunning() )
\r
247 usErrorCode |= 0x200;
\r
250 if( pdTRUE != xAreSemaphoreTasksStillRunning() )
\r
252 usErrorCode |= 0x400;
\r
255 if( pdTRUE != xAreComTestTasksStillRunning() )
\r
257 usErrorCode |= 0x800;
\r
260 if( pdTRUE != xAreIntQueueTasksStillRunning() )
\r
262 usErrorCode |= 0x1000;
\r
265 /* Clear the display. */
\r
266 LCD_Character_Display_ClearDisplay();
\r
267 if( 0 == usErrorCode )
\r
269 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);
\r
270 LCD_Character_Display_PrintString( "Pass: " );
\r
271 LCD_Character_Display_PrintNumber( ulIteration++ );
\r
272 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
273 LCD_Character_Display_PrintString( "Jitter(ns):" );
\r
274 LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );
\r
278 /* Do something to indicate the failure. */
\r
279 LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );
\r
280 LCD_Character_Display_PrintString( "Fail at: " );
\r
281 LCD_Character_Display_PrintNumber( ulIteration );
\r
282 LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );
\r
283 LCD_Character_Display_PrintString( "Error: 0x" );
\r
284 LCD_Character_Display_PrintHexUint16( usErrorCode );
\r
288 /*---------------------------------------------------------------------------*/
\r
290 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
292 /* The stack space has been execeeded for a task, considering allocating more. */
\r
293 taskDISABLE_INTERRUPTS();
\r
296 /*---------------------------------------------------------------------------*/
\r
298 void vApplicationMallocFailedHook( void )
\r
300 /* The heap space has been execeeded. */
\r
301 taskDISABLE_INTERRUPTS();
\r
304 /*---------------------------------------------------------------------------*/
\r