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