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