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