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