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