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