]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR75x_GCC/main.c
8f590f92074cb01624a038cde9a5e83299a66720
[freertos] / FreeRTOS / Demo / ARM7_STR75x_GCC / main.c
1 /*\r
2     FreeRTOS V8.0.1 - 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*\r
67  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
68  * documentation provides more details of the demo application tasks.\r
69  *\r
70  * In addition to the standard demo tasks there are two tasks defined within\r
71  * this file:\r
72  *\r
73  * 1 - The check task\r
74  * The 'check' task is responsible for ensuring that all the standard demo\r
75  * tasks are executing as expected.  It only executes every three seconds, but\r
76  * has the highest priority within the system so is guaranteed to get execution\r
77  * time.  Any errors discovered by the check task are latched until the\r
78  * processor is reset.  At the end of each cycle the check task sends either\r
79  * a pass or fail message to the 'print' task for display on the LCD.\r
80  *\r
81  * 2 - The print task\r
82  * The print task is the LCD 'gatekeeper'.  That is, it is the only task that\r
83  * should access the LCD directly so is always guaranteed exclusive (and\r
84  * therefore consistent) access.  The print task simply blocks on a queue\r
85  * to wait for messages from other tasks wishing to display text on the LCD.\r
86  * When a message arrives it displays its contents on the LCD then blocks to\r
87  * wait again.\r
88  */\r
89 \r
90 /* ST includes. */\r
91 #include "lcd.h"\r
92 \r
93 /* Kernel includes. */\r
94 #include "FreeRTOS.h"\r
95 #include "task.h"\r
96 #include "queue.h"\r
97 \r
98 /* Demo application includes. */\r
99 #include "partest.h"\r
100 #include "flash.h"\r
101 #include "integer.h"\r
102 #include "blocktim.h"\r
103 #include "BlockQ.h"\r
104 #include "comtest2.h"\r
105 #include "dynamic.h"\r
106 \r
107 /* Demo application task priorities. */\r
108 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
109 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
110 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
111 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
112 #define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
113 \r
114 /* How often should we check the other tasks? */\r
115 #define mainCHECK_TASK_CYCLE_TIME       ( 3000 )\r
116 \r
117 /* The maximum offset into the pass and fail strings sent to the LCD.  An\r
118 offset is used a simple method of using a different column each time a message\r
119 is written to the LCD. */\r
120 #define mainMAX_WRITE_COLUMN            ( 14 )\r
121 \r
122 /* Baud rate used by the comtest tasks. */\r
123 #define mainCOM_TEST_BAUD_RATE          ( 19200 )\r
124 \r
125 /* The LED used by the comtest tasks. See the comtest.c file for more\r
126 information. */\r
127 #define mainCOM_TEST_LED                        ( 3 )\r
128 \r
129 /* The number of messages that can be queued for display on the LCD at any one\r
130 time. */\r
131 #define mainLCD_QUEUE_LENGTH            ( 2 )\r
132 \r
133 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */\r
134 #define mainNO_DELAY                            ( 0 )\r
135 \r
136 /*-----------------------------------------------------------*/\r
137 \r
138 /* The type that is posted to the LCD queue. */\r
139 typedef struct LCD_MESSAGE\r
140 {\r
141         unsigned char *pucString; /* Points to the string to be displayed. */\r
142         unsigned char ucLine;     /* The line of the LCD that should be used. */\r
143 } LCDMessage;\r
144 \r
145 /*-----------------------------------------------------------*/\r
146 \r
147 /*\r
148  * The task that executes at the highest priority and checks the operation of\r
149  * all the other tasks in the system.  See the description at the top of the\r
150  * file.\r
151  */\r
152 static void vCheckTask( void *pvParameters );\r
153 \r
154 /*\r
155  * ST provided routine to configure the processor.\r
156  */\r
157 static void prvSetupHardware(void);\r
158 \r
159 /*\r
160  * The only task that should access the LCD.  Other tasks wanting to write\r
161  * to the LCD should send a message of type LCDMessage containing the\r
162  * information to display to the print task.  The print task simply blocks\r
163  * waiting for the arrival of such messages, displays the message, then blocks\r
164  * again.\r
165  */\r
166 static void vPrintTask( void *pvParameters );\r
167 \r
168 /*-----------------------------------------------------------*/\r
169 \r
170 /* The queue used to communicate with the LCD print task. */\r
171 static QueueHandle_t xLCDQueue;\r
172 \r
173 /*-----------------------------------------------------------*/\r
174 \r
175 /* Create all the demo application tasks, then start the scheduler. */\r
176 int main( void )\r
177 {\r
178         /* Perform any hardware setup necessary. */\r
179         prvSetupHardware();\r
180         vParTestInitialise();\r
181 \r
182         /* Create the queue used to communicate with the LCD print task. */\r
183         xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );\r
184 \r
185         /* Create the standard demo application tasks.  See the WEB documentation\r
186         for more information on these tasks. */\r
187         vCreateBlockTimeTasks();\r
188         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
189         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
190         vStartDynamicPriorityTasks();\r
191         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
192         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
193 \r
194         /* Create the tasks defined within this file. */\r
195         xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
196         xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
197 \r
198         vTaskStartScheduler();\r
199 \r
200         /* Execution will only reach here if there was insufficient heap to\r
201         start the scheduler. */\r
202         return 0;\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 static void vCheckTask( void *pvParameters )\r
207 {\r
208 static unsigned long ulErrorDetected = pdFALSE;\r
209 TickType_t xLastExecutionTime;\r
210 unsigned char *ucErrorMessage = ( unsigned char * )"              FAIL";\r
211 unsigned char *ucSuccessMessage = ( unsigned char * )"              PASS";\r
212 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;\r
213 LCDMessage xMessage;\r
214 \r
215         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
216         works correctly. */\r
217         xLastExecutionTime = xTaskGetTickCount();\r
218 \r
219         for( ;; )\r
220         {\r
221                 /* Wait until it is time for the next cycle. */\r
222                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );\r
223 \r
224                 /* Has an error been found in any of the standard demo tasks? */\r
225 \r
226                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
227                 {\r
228                         ulErrorDetected = pdTRUE;\r
229                 }\r
230 \r
231                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
232                 {\r
233                         ulErrorDetected = pdTRUE;\r
234                 }\r
235 \r
236                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
237                 {\r
238                         ulErrorDetected = pdTRUE;\r
239                 }\r
240 \r
241                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
242                 {\r
243                         ulErrorDetected = pdTRUE;\r
244                 }\r
245 \r
246                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
247                 {\r
248                         ulErrorDetected = pdTRUE;\r
249                 }\r
250 \r
251                 /* Calculate the LCD line on which we would like the message to\r
252                 be displayed.  The column variable is used for convenience as\r
253                 it is incremented each cycle anyway. */\r
254                 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );\r
255 \r
256                 /* The message displayed depends on whether an error was found or\r
257                 not.  Any discovered error is latched.  Here the column variable\r
258                 is used as an index into the text string as a simple way of moving\r
259                 the text from column to column. */\r
260                 if( ulErrorDetected == pdFALSE )\r
261                 {\r
262                         xMessage.pucString = ucSuccessMessage + uxColumn;\r
263                 }\r
264                 else\r
265                 {\r
266                         xMessage.pucString = ucErrorMessage + uxColumn;\r
267                 }\r
268 \r
269                 /* Send the message to the print task for display. */\r
270                 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );\r
271 \r
272                 /* Make sure the message is printed in a different column the next\r
273                 time around. */\r
274                 uxColumn--;\r
275                 if( uxColumn == 0 )\r
276                 {\r
277                         uxColumn = mainMAX_WRITE_COLUMN;\r
278                 }\r
279         }\r
280 }\r
281 \r
282 /*-----------------------------------------------------------*/\r
283 \r
284 static void vPrintTask( void *pvParameters )\r
285 {\r
286 LCDMessage xMessage;\r
287 \r
288         for( ;; )\r
289         {\r
290                 /* Wait until a message arrives. */\r
291                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );\r
292 \r
293                 /* The message contains the text to display, and the line on which the\r
294                 text should be displayed. */\r
295                 LCD_Clear();\r
296                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );\r
297         }\r
298 }\r
299 /*-----------------------------------------------------------*/\r
300 \r
301 static void prvSetupHardware(void)\r
302 {\r
303 ErrorStatus OSC4MStartUpStatus01;\r
304 \r
305         /* ST provided routine. */\r
306 \r
307         /* MRCC system reset */\r
308         MRCC_DeInit();\r
309 \r
310         /* Wait for OSC4M start-up */\r
311         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();\r
312 \r
313         if(OSC4MStartUpStatus01 == SUCCESS)\r
314         {\r
315                 /* Set HCLK to 60MHz */\r
316                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);\r
317 \r
318                 /* Set CKTIM to 60MHz */\r
319                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);\r
320 \r
321                 /* Set PCLK to 30MHz */\r
322                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);\r
323 \r
324                 /* Enable Flash Burst mode */\r
325                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);\r
326 \r
327                 /* Set CK_SYS to 60 MHz */\r
328                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);\r
329         }\r
330 \r
331         /* GPIO pins optimized for 3V3 operation */\r
332         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);\r
333 \r
334         /* GPIO clock source enable */\r
335         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);\r
336 \r
337         /* EXTIT clock source enable */\r
338         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);\r
339         /* TB clock source enable */\r
340         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);\r
341 \r
342         /* Initialize the demonstration menu */\r
343         LCD_Init();\r
344 \r
345         LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);\r
346         LCD_DisplayString(Line2, ( unsigned char * ) "  STR750 Demo  ", BlackText);\r
347 \r
348         EIC_IRQCmd(ENABLE);\r
349 }\r
350 /*-----------------------------------------------------------*/\r
351 \r