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