]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR75x_IAR/main.c
Update version numbers in preparation for new release.
[freertos] / FreeRTOS / Demo / ARM7_STR75x_IAR / main.c
1 /*\r
2     FreeRTOS V8.2.2 - 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 void 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 }\r
207 /*-----------------------------------------------------------*/\r
208 \r
209 static void vCheckTask( void *pvParameters )\r
210 {\r
211 static unsigned long ulErrorDetected = pdFALSE;\r
212 TickType_t xLastExecutionTime;\r
213 unsigned char *cErrorMessage = "              FAIL";\r
214 unsigned char *cSuccessMessage = "              PASS";\r
215 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;\r
216 LCDMessage xMessage;\r
217 \r
218         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
219         works correctly. */\r
220         xLastExecutionTime = xTaskGetTickCount();\r
221 \r
222         for( ;; )\r
223         {\r
224                 /* Wait until it is time for the next cycle. */\r
225                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );\r
226 \r
227                 /* Has an error been found in any of the standard demo tasks? */\r
228 \r
229                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
230                 {\r
231                         ulErrorDetected = pdTRUE;\r
232                 }\r
233 \r
234                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
235                 {\r
236                         ulErrorDetected = pdTRUE;\r
237                 }\r
238 \r
239                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
240                 {\r
241                         ulErrorDetected = pdTRUE;\r
242                 }\r
243 \r
244                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
245                 {\r
246                         ulErrorDetected = pdTRUE;\r
247                 }\r
248 \r
249                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
250                 {\r
251                         ulErrorDetected = pdTRUE;\r
252                 }\r
253 \r
254                 /* Calculate the LCD line on which we would like the message to\r
255                 be displayed.  The column variable is used for convenience as\r
256                 it is incremented each cycle anyway. */\r
257                 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );\r
258 \r
259                 /* The message displayed depends on whether an error was found or\r
260                 not.  Any discovered error is latched.  Here the column variable\r
261                 is used as an index into the text string as a simple way of moving\r
262                 the text from column to column. */\r
263                 if( ulErrorDetected == pdFALSE )\r
264                 {\r
265                         xMessage.pucString = cSuccessMessage + uxColumn;\r
266                 }\r
267                 else\r
268                 {\r
269                         xMessage.pucString = cErrorMessage + uxColumn;\r
270                 }\r
271 \r
272                 /* Send the message to the print task for display. */\r
273                 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );\r
274 \r
275                 /* Make sure the message is printed in a different column the next\r
276                 time around. */\r
277                 uxColumn--;\r
278                 if( uxColumn == 0 )\r
279                 {\r
280                         uxColumn = mainMAX_WRITE_COLUMN;\r
281                 }\r
282         }\r
283 }\r
284 /*-----------------------------------------------------------*/\r
285 \r
286 static void vPrintTask( void *pvParameters )\r
287 {\r
288 LCDMessage xMessage;\r
289 \r
290         for( ;; )\r
291         {\r
292                 /* Wait until a message arrives. */\r
293                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );\r
294 \r
295                 /* The message contains the text to display, and the line on which the\r
296                 text should be displayed. */\r
297                 LCD_Clear();\r
298                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );\r
299         }\r
300 }\r
301 /*-----------------------------------------------------------*/\r
302 \r
303 static void prvSetupHardware(void)\r
304 {\r
305 ErrorStatus OSC4MStartUpStatus01;\r
306 \r
307         /* ST provided routine. */\r
308 \r
309         /* MRCC system reset */\r
310         MRCC_DeInit();\r
311 \r
312         /* Wait for OSC4M start-up */\r
313         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();\r
314 \r
315         if(OSC4MStartUpStatus01 == SUCCESS)\r
316         {\r
317                 /* Set HCLK to 60MHz */\r
318                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);\r
319 \r
320                 /* Set CKTIM to 60MHz */\r
321                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);\r
322 \r
323                 /* Set PCLK to 30MHz */\r
324                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);\r
325 \r
326                 /* Enable Flash Burst mode */\r
327                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);\r
328 \r
329                 /* Set CK_SYS to 60 MHz */\r
330                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);\r
331         }\r
332 \r
333         /* GPIO pins optimized for 3V3 operation */\r
334         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);\r
335 \r
336         /* GPIO clock source enable */\r
337         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);\r
338 \r
339         /* EXTIT clock source enable */\r
340         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);\r
341         /* TB clock source enable */\r
342         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);\r
343 \r
344         /* Initialize the demonstration menu */\r
345         LCD_Init();\r
346 \r
347         LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);\r
348         LCD_DisplayString(Line2, "  STR750 Demo  ", BlackText);\r
349 \r
350         EIC_IRQCmd(ENABLE);\r
351 }\r
352 /*-----------------------------------------------------------*/\r