]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_CY8C5588_PSoC_Creator_Keil/FreeRTOS_Demo.cydsn/main.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / CORTEX_CY8C5588_PSoC_Creator_Keil / FreeRTOS_Demo.cydsn / main.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 #include <device.h>\r
67 \r
68 /* RTOS includes. */\r
69 #include "FreeRTOS.h"\r
70 #include "task.h"\r
71 #include "queue.h"\r
72 #include "semphr.h"\r
73 \r
74 /* Common Demo includes. */\r
75 #include "serial.h"\r
76 #include "BlockQ.h"\r
77 #include "blocktim.h"\r
78 #include "comtest.h"\r
79 #include "countsem.h"\r
80 #include "death.h"\r
81 #include "dynamic.h"\r
82 #include "flash.h"\r
83 #include "flop.h"\r
84 #include "GenQTest.h"\r
85 #include "integer.h"\r
86 #include "IntQueue.h"\r
87 #include "mevents.h"\r
88 #include "partest.h"\r
89 #include "PollQ.h"\r
90 #include "print.h"\r
91 #include "QPeek.h"\r
92 #include "semtest.h"\r
93 /*---------------------------------------------------------------------------*/\r
94 \r
95 /* The time between cycles of the 'check' functionality (defined within the\r
96 tick hook. */\r
97 #define mainCHECK_DELAY                                         ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )\r
98 #define mainCOM_LED                                                     ( 3 )\r
99 \r
100 /* The number of nano seconds between each processor clock. */\r
101 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )\r
102 \r
103 /* Task priorities. */\r
104 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
105 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
106 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
107 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
108 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
109 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
110 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
111 #define mainCOM_TEST_TASK_PRIORITY                      ( tskIDLE_PRIORITY + 1 )\r
112 #define mainFLASH_TEST_TASK_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
113 /*---------------------------------------------------------------------------*/\r
114 \r
115 /*\r
116  * Configures the timers and interrupts for the fast interrupt test as\r
117  * described at the top of this file.\r
118  */\r
119 extern void vSetupTimerTest( void );\r
120 /*---------------------------------------------------------------------------*/\r
121 \r
122 /*\r
123  * The Check task periodical interrogates each of the running tests to\r
124  * ensure that they are still executing correctly.\r
125  * If all the tests pass, then the LCD is updated with Pass, the number of\r
126  * iterations and the Jitter time calculated but the Fast Interrupt Test.\r
127  * If any one of the tests fail, it is indicated with an error code printed on\r
128  * the display. This indicator won't disappear until the device is reset.\r
129  */\r
130 void vCheckTask( void *pvParameters );\r
131 \r
132 /*\r
133  * Installs the RTOS interrupt handlers and starts the peripherals.\r
134  */\r
135 static void prvHardwareSetup( void );\r
136 /*---------------------------------------------------------------------------*/\r
137 \r
138 void main( void )\r
139 {\r
140     /* Place your initialization/startup code here (e.g. MyInst_Start()) */\r
141         prvHardwareSetup();\r
142 \r
143         /* Start the standard demo tasks.  These are just here to exercise the\r
144         kernel port and provide examples of how the FreeRTOS API can be used. */\r
145         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
146         vCreateBlockTimeTasks();\r
147         vStartCountingSemaphoreTasks();\r
148         vStartDynamicPriorityTasks();\r
149         vStartMathTasks( mainINTEGER_TASK_PRIORITY );\r
150         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
151         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
152         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
153         vStartQueuePeekTasks();\r
154         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
155         vStartLEDFlashTasks( mainFLASH_TEST_TASK_PRIORITY );\r
156         vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, 57600, mainCOM_LED );\r
157         vStartInterruptQueueTasks();\r
158 \r
159         /* Start the error checking task. */\r
160         ( void ) xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
161 \r
162         /* Configure the timers used by the fast interrupt timer test. */\r
163         vSetupTimerTest();\r
164 \r
165         /* The suicide tasks must be created last as they need to know how many\r
166         tasks were running prior to their creation in order to ascertain whether\r
167         or not the correct/expected number of tasks are running at any given time. */\r
168         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
169 \r
170         /* Will only get here if there was insufficient memory to create the idle\r
171     task.  The idle task is created within vTaskStartScheduler(). */\r
172         vTaskStartScheduler();\r
173 \r
174         /* Should never reach here as the kernel will now be running.  If\r
175         vTaskStartScheduler() does return then it is very likely that there was\r
176         insufficient (FreeRTOS) heap space available to create all the tasks,\r
177         including the idle task that is created within vTaskStartScheduler() itself. */\r
178         for( ;; );\r
179 }\r
180 /*---------------------------------------------------------------------------*/\r
181 \r
182 void prvHardwareSetup( void )\r
183 {\r
184 /* Port layer functions that need to be copied into the vector table. */\r
185 extern void xPortPendSVHandler( void );\r
186 extern void xPortSysTickHandler( void );\r
187 extern void vPortSVCHandler( void );\r
188 extern cyisraddress CyRamVectors[];\r
189 \r
190         /* Install the OS Interrupt Handlers. */\r
191         CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler;\r
192         CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler;\r
193         CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler;\r
194 \r
195         /* Start-up the peripherals. */\r
196 \r
197         /* Enable and clear the LCD Display. */\r
198         LCD_Character_Display_Start();\r
199         LCD_Character_Display_ClearDisplay();\r
200         LCD_Character_Display_Position( 0, 0 );\r
201         LCD_Character_Display_PrintString( "www.FreeRTOS.org " );\r
202         LCD_Character_Display_Position( 1, 0 );\r
203         LCD_Character_Display_PrintString("CY8C5588AX-060  ");\r
204 \r
205         /* Start the UART. */\r
206         UART_1_Start();\r
207 \r
208         /* Initialise the LEDs. */\r
209         vParTestInitialise();\r
210 \r
211         /* Start the PWM modules that drive the IntQueue tests. */\r
212         High_Frequency_PWM_0_Start();\r
213         High_Frequency_PWM_1_Start();\r
214 \r
215         /* Start the timers for the Jitter test. */\r
216         Timer_20KHz_Start();\r
217         Timer_48MHz_Start();\r
218 }\r
219 /*---------------------------------------------------------------------------*/\r
220 \r
221 void vCheckTask( void *pvParameters )\r
222 {\r
223 unsigned long ulRow = 0;\r
224 TickType_t xDelay = 0;\r
225 unsigned short usErrorCode = 0;\r
226 unsigned long ulIteration = 0;\r
227 extern unsigned short usMaxJitter;\r
228 \r
229         /* Intialise the sleeper. */\r
230         xDelay = xTaskGetTickCount();\r
231 \r
232         for( ;; )\r
233         {\r
234                 /* Perform this check every mainCHECK_DELAY milliseconds. */\r
235                 vTaskDelayUntil( &xDelay, mainCHECK_DELAY );\r
236 \r
237                 /* Check that all of the Demo tasks are still running. */\r
238                 if( pdTRUE != xAreBlockingQueuesStillRunning() )\r
239                 {\r
240                         usErrorCode |= 0x1;\r
241                 }\r
242 \r
243                 if( pdTRUE != xAreBlockTimeTestTasksStillRunning() )\r
244                 {\r
245                         usErrorCode |= 0x2;\r
246                 }\r
247 \r
248                 if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() )\r
249                 {\r
250                         usErrorCode |= 0x4;\r
251                 }\r
252 \r
253                 if( pdTRUE != xIsCreateTaskStillRunning() )\r
254                 {\r
255                         usErrorCode |= 0x8;\r
256                 }\r
257 \r
258                 if( pdTRUE != xAreDynamicPriorityTasksStillRunning() )\r
259                 {\r
260                         usErrorCode |= 0x10;\r
261                 }\r
262 \r
263                 if( pdTRUE != xAreMathsTaskStillRunning() )\r
264                 {\r
265                         usErrorCode |= 0x20;\r
266                 }\r
267 \r
268                 if( pdTRUE != xAreGenericQueueTasksStillRunning() )\r
269                 {\r
270                         usErrorCode |= 0x40;\r
271                 }\r
272 \r
273                 if( pdTRUE != xAreIntegerMathsTaskStillRunning() )\r
274                 {\r
275                         usErrorCode |= 0x80;\r
276                 }\r
277 \r
278                 if( pdTRUE != xArePollingQueuesStillRunning() )\r
279                 {\r
280                         usErrorCode |= 0x100;\r
281                 }\r
282 \r
283                 if( pdTRUE != xAreQueuePeekTasksStillRunning() )\r
284                 {\r
285                         usErrorCode |= 0x200;\r
286                 }\r
287 \r
288                 if( pdTRUE != xAreSemaphoreTasksStillRunning() )\r
289                 {\r
290                         usErrorCode |= 0x400;\r
291                 }\r
292 \r
293                 if( pdTRUE != xAreComTestTasksStillRunning() )\r
294                 {\r
295                         usErrorCode |= 0x800;\r
296                 }\r
297 \r
298                 if( pdTRUE != xAreIntQueueTasksStillRunning() )\r
299                 {\r
300                         usErrorCode |= 0x1000;\r
301                 }\r
302 \r
303                 /* Clear the display. */\r
304                 LCD_Character_Display_ClearDisplay();\r
305                 if( 0 == usErrorCode )\r
306                 {\r
307                         LCD_Character_Display_Position( ( ulRow ) & 0x1, 0);\r
308                         LCD_Character_Display_PrintString( "Pass: " );\r
309                         LCD_Character_Display_PrintNumber( ulIteration++ );\r
310                         LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );\r
311                         LCD_Character_Display_PrintString( "Jitter(ns):" );\r
312                         LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) );\r
313                 }\r
314                 else\r
315                 {\r
316                         /* Do something to indicate the failure. */\r
317                         LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 );\r
318                         LCD_Character_Display_PrintString( "Fail at: " );\r
319                         LCD_Character_Display_PrintNumber( ulIteration );\r
320                         LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 );\r
321                         LCD_Character_Display_PrintString( "Error: 0x" );\r
322                         LCD_Character_Display_PrintHexUint16( usErrorCode );\r
323                 }\r
324         }\r
325 }\r
326 /*---------------------------------------------------------------------------*/\r
327 \r
328 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
329 {\r
330         /* The stack space has been execeeded for a task, considering allocating more. */\r
331         taskDISABLE_INTERRUPTS();\r
332         for( ;; );\r
333 }\r
334 /*---------------------------------------------------------------------------*/\r
335 \r
336 void vApplicationMallocFailedHook( void )\r
337 {\r
338         /* The heap space has been execeeded. */\r
339         taskDISABLE_INTERRUPTS();\r
340         for( ;; );\r
341 }\r
342 /*---------------------------------------------------------------------------*/\r