]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_CY8C5588_PSoC_Creator_GCC / FreeRTOS_Demo.cydsn / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 #include <device.h>\r
29 \r
30 /* RTOS includes. */\r
31 #include "FreeRTOS.h"\r
32 #include "task.h"\r
33 #include "queue.h"\r
34 #include "semphr.h"\r
35 \r
36 /* Common Demo includes. */\r
37 #include "serial.h"\r
38 #include "BlockQ.h"\r
39 #include "blocktim.h"\r
40 #include "comtest.h"\r
41 #include "countsem.h"\r
42 #include "death.h"\r
43 #include "dynamic.h"\r
44 #include "flash.h"\r
45 #include "flop.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
51 #include "PollQ.h"\r
52 #include "print.h"\r
53 #include "QPeek.h"\r
54 #include "semtest.h"\r
55 /*---------------------------------------------------------------------------*/\r
56 \r
57 /* The time between cycles of the 'check' functionality (defined within the\r
58 tick hook. */\r
59 #define mainCHECK_DELAY                                         ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )\r
60 #define mainCOM_LED                                                     ( 3 )\r
61 \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
64 \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
76 \r
77 /*\r
78  * Configures the timers and interrupts for the fast interrupt test as\r
79  * described at the top of this file.\r
80  */\r
81 extern void vSetupTimerTest( void );\r
82 /*---------------------------------------------------------------------------*/\r
83 \r
84 /*\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
91  */\r
92 void vCheckTask( void *pvParameters );\r
93 \r
94 /*\r
95  * Installs the RTOS interrupt handlers and starts the peripherals.\r
96  */\r
97 static void prvHardwareSetup( void );\r
98 /*---------------------------------------------------------------------------*/\r
99 \r
100 void main( void )\r
101 {\r
102     /* Place your initialization/startup code here (e.g. MyInst_Start()) */\r
103         prvHardwareSetup();\r
104 \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
120 \r
121         /* Start the error checking task. */\r
122         ( void ) xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
123 \r
124         /* Configure the timers used by the fast interrupt timer test. */\r
125         vSetupTimerTest();\r
126 \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
131 \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
135 \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
140         for( ;; );\r
141 }\r
142 /*---------------------------------------------------------------------------*/\r
143 \r
144 void prvHardwareSetup( void )\r
145 {\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
151 \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
156 \r
157         /* Start-up the peripherals. */\r
158 \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
166 \r
167         /* Start the UART. */\r
168         UART_1_Start();\r
169 \r
170         /* Initialise the LEDs. */\r
171         vParTestInitialise();\r
172 \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
176 \r
177         /* Start the timers for the Jitter test. */\r
178         Timer_20KHz_Start();\r
179         Timer_48MHz_Start();\r
180 }\r
181 /*---------------------------------------------------------------------------*/\r
182 \r
183 void vCheckTask( void *pvParameters )\r
184 {\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
190 \r
191         /* Intialise the sleeper. */\r
192         xDelay = xTaskGetTickCount();\r
193 \r
194         for( ;; )\r
195         {\r
196                 /* Perform this check every mainCHECK_DELAY milliseconds. */\r
197                 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );\r
198 \r
199                 /* Check that all of the Demo tasks are still running. */\r
200                 if( pdTRUE != xAreBlockingQueuesStillRunning() )\r
201                 {\r
202                         usErrorCode |= 0x1;\r
203                 }\r
204 \r
205                 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )\r
206                 {\r
207                         usErrorCode |= 0x2;\r
208                 }\r
209 \r
210                 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )\r
211                 {\r
212                         usErrorCode |= 0x4;\r
213                 }\r
214 \r
215                 if( pdTRUE != xIsCreateTaskStillRunning() )\r
216                 {\r
217                         usErrorCode |= 0x8;\r
218                 }\r
219 \r
220                 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )\r
221                 {\r
222                         usErrorCode |= 0x10;\r
223                 }\r
224 \r
225                 if( pdTRUE != xAreMathsTaskStillRunning() )\r
226                 {\r
227                         usErrorCode |= 0x20;\r
228                 }\r
229 \r
230                 if( pdTRUE != xAreGenericQueueTasksStillRunning() )\r
231                 {\r
232                         usErrorCode |= 0x40;\r
233                 }\r
234 \r
235                 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )\r
236                 {\r
237                         usErrorCode |= 0x80;\r
238                 }\r
239 \r
240                 if( pdTRUE != xArePollingQueuesStillRunning() )\r
241                 {\r
242                         usErrorCode |= 0x100;\r
243                 }\r
244 \r
245                 if( pdTRUE != xAreQueuePeekTasksStillRunning() )\r
246                 {\r
247                         usErrorCode |= 0x200;\r
248                 }\r
249 \r
250                 if( pdTRUE != xAreSemaphoreTasksStillRunning() )\r
251                 {\r
252                         usErrorCode |= 0x400;\r
253                 }\r
254 \r
255                 if( pdTRUE != xAreComTestTasksStillRunning() )\r
256                 {\r
257                         usErrorCode |= 0x800;\r
258                 }\r
259 \r
260                 if( pdTRUE != xAreIntQueueTasksStillRunning() )\r
261                 {\r
262                         usErrorCode |= 0x1000;\r
263                 }\r
264 \r
265                 /* Clear the display. */\r
266                 LCD_Character_Display_ClearDisplay();\r
267                 if( 0 == usErrorCode )\r
268                 {\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
275                 }\r
276                 else\r
277                 {\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
285                 }\r
286         }\r
287 }\r
288 /*---------------------------------------------------------------------------*/\r
289 \r
290 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
291 {\r
292         /* The stack space has been execeeded for a task, considering allocating more. */\r
293         taskDISABLE_INTERRUPTS();\r
294         for( ;; );\r
295 }\r
296 /*---------------------------------------------------------------------------*/\r
297 \r
298 void vApplicationMallocFailedHook( void )\r
299 {\r
300         /* The heap space has been execeeded. */\r
301         taskDISABLE_INTERRUPTS();\r
302         for( ;; );\r
303 }\r
304 /*---------------------------------------------------------------------------*/\r