]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR75x_GCC/main.c
720fbceced7a5974826fb276ca490157dda5a05e
[freertos] / FreeRTOS / Demo / ARM7_STR75x_GCC / 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 /*\r
97  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
98  * documentation provides more details of the demo application tasks.\r
99  *\r
100  * In addition to the standard demo tasks there are two tasks defined within\r
101  * this file:\r
102  *\r
103  * 1 - The check task\r
104  * The 'check' task is responsible for ensuring that all the standard demo\r
105  * tasks are executing as expected.  It only executes every three seconds, but\r
106  * has the highest priority within the system so is guaranteed to get execution\r
107  * time.  Any errors discovered by the check task are latched until the\r
108  * processor is reset.  At the end of each cycle the check task sends either\r
109  * a pass or fail message to the 'print' task for display on the LCD.\r
110  *\r
111  * 2 - The print task\r
112  * The print task is the LCD 'gatekeeper'.  That is, it is the only task that\r
113  * should access the LCD directly so is always guaranteed exclusive (and\r
114  * therefore consistent) access.  The print task simply blocks on a queue\r
115  * to wait for messages from other tasks wishing to display text on the LCD.\r
116  * When a message arrives it displays its contents on the LCD then blocks to\r
117  * wait again.\r
118  */\r
119 \r
120 /* ST includes. */\r
121 #include "lcd.h"\r
122 \r
123 /* Kernel includes. */\r
124 #include "FreeRTOS.h"\r
125 #include "task.h"\r
126 #include "queue.h"\r
127 \r
128 /* Demo application includes. */\r
129 #include "partest.h"\r
130 #include "flash.h"\r
131 #include "integer.h"\r
132 #include "blocktim.h"\r
133 #include "BlockQ.h"\r
134 #include "comtest2.h"\r
135 #include "dynamic.h"\r
136 \r
137 /* Demo application task priorities. */\r
138 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
139 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
140 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
141 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
142 #define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
143 \r
144 /* How often should we check the other tasks? */\r
145 #define mainCHECK_TASK_CYCLE_TIME       ( 3000 )\r
146 \r
147 /* The maximum offset into the pass and fail strings sent to the LCD.  An\r
148 offset is used a simple method of using a different column each time a message\r
149 is written to the LCD. */\r
150 #define mainMAX_WRITE_COLUMN            ( 14 )\r
151 \r
152 /* Baud rate used by the comtest tasks. */\r
153 #define mainCOM_TEST_BAUD_RATE          ( 19200 )\r
154 \r
155 /* The LED used by the comtest tasks. See the comtest.c file for more\r
156 information. */\r
157 #define mainCOM_TEST_LED                        ( 3 )\r
158 \r
159 /* The number of messages that can be queued for display on the LCD at any one\r
160 time. */\r
161 #define mainLCD_QUEUE_LENGTH            ( 2 )\r
162 \r
163 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */\r
164 #define mainNO_DELAY                            ( 0 )\r
165 \r
166 /*-----------------------------------------------------------*/\r
167 \r
168 /* The type that is posted to the LCD queue. */\r
169 typedef struct LCD_MESSAGE\r
170 {\r
171         unsigned char *pucString; /* Points to the string to be displayed. */\r
172         unsigned char ucLine;     /* The line of the LCD that should be used. */\r
173 } LCDMessage;\r
174 \r
175 /*-----------------------------------------------------------*/\r
176 \r
177 /*\r
178  * The task that executes at the highest priority and checks the operation of\r
179  * all the other tasks in the system.  See the description at the top of the\r
180  * file.\r
181  */\r
182 static void vCheckTask( void *pvParameters );\r
183 \r
184 /*\r
185  * ST provided routine to configure the processor.\r
186  */\r
187 static void prvSetupHardware(void);\r
188 \r
189 /*\r
190  * The only task that should access the LCD.  Other tasks wanting to write\r
191  * to the LCD should send a message of type LCDMessage containing the\r
192  * information to display to the print task.  The print task simply blocks\r
193  * waiting for the arrival of such messages, displays the message, then blocks\r
194  * again.\r
195  */\r
196 static void vPrintTask( void *pvParameters );\r
197 \r
198 /*-----------------------------------------------------------*/\r
199 \r
200 /* The queue used to communicate with the LCD print task. */\r
201 static QueueHandle_t xLCDQueue;\r
202 \r
203 /*-----------------------------------------------------------*/\r
204 \r
205 /* Create all the demo application tasks, then start the scheduler. */\r
206 int main( void )\r
207 {\r
208         /* Perform any hardware setup necessary. */\r
209         prvSetupHardware();\r
210         vParTestInitialise();\r
211 \r
212         /* Create the queue used to communicate with the LCD print task. */\r
213         xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );\r
214 \r
215         /* Create the standard demo application tasks.  See the WEB documentation\r
216         for more information on these tasks. */\r
217         vCreateBlockTimeTasks();\r
218         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
219         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
220         vStartDynamicPriorityTasks();\r
221         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
222         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
223 \r
224         /* Create the tasks defined within this file. */\r
225         xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
226         xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
227 \r
228         vTaskStartScheduler();\r
229 \r
230         /* Execution will only reach here if there was insufficient heap to\r
231         start the scheduler. */\r
232         return 0;\r
233 }\r
234 /*-----------------------------------------------------------*/\r
235 \r
236 static void vCheckTask( void *pvParameters )\r
237 {\r
238 static unsigned long ulErrorDetected = pdFALSE;\r
239 TickType_t xLastExecutionTime;\r
240 unsigned char *ucErrorMessage = ( unsigned char * )"              FAIL";\r
241 unsigned char *ucSuccessMessage = ( unsigned char * )"              PASS";\r
242 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;\r
243 LCDMessage xMessage;\r
244 \r
245         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
246         works correctly. */\r
247         xLastExecutionTime = xTaskGetTickCount();\r
248 \r
249         for( ;; )\r
250         {\r
251                 /* Wait until it is time for the next cycle. */\r
252                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );\r
253 \r
254                 /* Has an error been found in any of the standard demo tasks? */\r
255 \r
256                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
257                 {\r
258                         ulErrorDetected = pdTRUE;\r
259                 }\r
260 \r
261                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
262                 {\r
263                         ulErrorDetected = pdTRUE;\r
264                 }\r
265 \r
266                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
267                 {\r
268                         ulErrorDetected = pdTRUE;\r
269                 }\r
270 \r
271                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
272                 {\r
273                         ulErrorDetected = pdTRUE;\r
274                 }\r
275 \r
276                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
277                 {\r
278                         ulErrorDetected = pdTRUE;\r
279                 }\r
280 \r
281                 /* Calculate the LCD line on which we would like the message to\r
282                 be displayed.  The column variable is used for convenience as\r
283                 it is incremented each cycle anyway. */\r
284                 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );\r
285 \r
286                 /* The message displayed depends on whether an error was found or\r
287                 not.  Any discovered error is latched.  Here the column variable\r
288                 is used as an index into the text string as a simple way of moving\r
289                 the text from column to column. */\r
290                 if( ulErrorDetected == pdFALSE )\r
291                 {\r
292                         xMessage.pucString = ucSuccessMessage + uxColumn;\r
293                 }\r
294                 else\r
295                 {\r
296                         xMessage.pucString = ucErrorMessage + uxColumn;\r
297                 }\r
298 \r
299                 /* Send the message to the print task for display. */\r
300                 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );\r
301 \r
302                 /* Make sure the message is printed in a different column the next\r
303                 time around. */\r
304                 uxColumn--;\r
305                 if( uxColumn == 0 )\r
306                 {\r
307                         uxColumn = mainMAX_WRITE_COLUMN;\r
308                 }\r
309         }\r
310 }\r
311 \r
312 /*-----------------------------------------------------------*/\r
313 \r
314 static void vPrintTask( void *pvParameters )\r
315 {\r
316 LCDMessage xMessage;\r
317 \r
318         for( ;; )\r
319         {\r
320                 /* Wait until a message arrives. */\r
321                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );\r
322 \r
323                 /* The message contains the text to display, and the line on which the\r
324                 text should be displayed. */\r
325                 LCD_Clear();\r
326                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );\r
327         }\r
328 }\r
329 /*-----------------------------------------------------------*/\r
330 \r
331 static void prvSetupHardware(void)\r
332 {\r
333 ErrorStatus OSC4MStartUpStatus01;\r
334 \r
335         /* ST provided routine. */\r
336 \r
337         /* MRCC system reset */\r
338         MRCC_DeInit();\r
339 \r
340         /* Wait for OSC4M start-up */\r
341         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();\r
342 \r
343         if(OSC4MStartUpStatus01 == SUCCESS)\r
344         {\r
345                 /* Set HCLK to 60MHz */\r
346                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);\r
347 \r
348                 /* Set CKTIM to 60MHz */\r
349                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);\r
350 \r
351                 /* Set PCLK to 30MHz */\r
352                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);\r
353 \r
354                 /* Enable Flash Burst mode */\r
355                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);\r
356 \r
357                 /* Set CK_SYS to 60 MHz */\r
358                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);\r
359         }\r
360 \r
361         /* GPIO pins optimized for 3V3 operation */\r
362         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);\r
363 \r
364         /* GPIO clock source enable */\r
365         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);\r
366 \r
367         /* EXTIT clock source enable */\r
368         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);\r
369         /* TB clock source enable */\r
370         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);\r
371 \r
372         /* Initialize the demonstration menu */\r
373         LCD_Init();\r
374 \r
375         LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);\r
376         LCD_DisplayString(Line2, ( unsigned char * ) "  STR750 Demo  ", BlackText);\r
377 \r
378         EIC_IRQCmd(ENABLE);\r
379 }\r
380 /*-----------------------------------------------------------*/\r
381 \r