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