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