]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR75x_IAR/main.c
Prepare for V7.2.0 release.
[freertos] / FreeRTOS / Demo / ARM7_STR75x_IAR / main.c
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43     \r
44     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /*\r
68  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
69  * documentation provides more details of the demo application tasks.\r
70  *\r
71  * In addition to the standard demo tasks there are two tasks defined within\r
72  * this file:\r
73  *\r
74  * 1 - The check task\r
75  * The 'check' task is responsible for ensuring that all the standard demo\r
76  * tasks are executing as expected.  It only executes every three seconds, but\r
77  * has the highest priority within the system so is guaranteed to get execution\r
78  * time.  Any errors discovered by the check task are latched until the\r
79  * processor is reset.  At the end of each cycle the check task sends either\r
80  * a pass or fail message to the 'print' task for display on the LCD.\r
81  *\r
82  * 2 - The print task\r
83  * The print task is the LCD 'gatekeeper'.  That is, it is the only task that\r
84  * should access the LCD directly so is always guaranteed exclusive (and\r
85  * therefore consistent) access.  The print task simply blocks on a queue\r
86  * to wait for messages from other tasks wishing to display text on the LCD.\r
87  * When a message arrives it displays its contents on the LCD then blocks to\r
88  * wait again.\r
89  */\r
90 \r
91 /* ST includes. */\r
92 #include "lcd.h"\r
93 \r
94 /* Kernel includes. */\r
95 #include "FreeRTOS.h"\r
96 #include "task.h"\r
97 #include "queue.h"\r
98 \r
99 /* Demo application includes. */\r
100 #include "partest.h"\r
101 #include "flash.h"\r
102 #include "integer.h"\r
103 #include "blocktim.h"\r
104 #include "BlockQ.h"\r
105 #include "comtest2.h"\r
106 #include "dynamic.h"\r
107 \r
108 /* Demo application task priorities. */\r
109 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
110 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
111 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
112 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
113 #define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
114 \r
115 /* How often should we check the other tasks? */\r
116 #define mainCHECK_TASK_CYCLE_TIME       ( 3000 )\r
117 \r
118 /* The maximum offset into the pass and fail strings sent to the LCD.  An\r
119 offset is used a simple method of using a different column each time a message\r
120 is written to the LCD. */\r
121 #define mainMAX_WRITE_COLUMN            ( 14 )\r
122 \r
123 /* Baud rate used by the comtest tasks. */\r
124 #define mainCOM_TEST_BAUD_RATE          ( 19200 )\r
125 \r
126 /* The LED used by the comtest tasks. See the comtest.c file for more\r
127 information. */\r
128 #define mainCOM_TEST_LED                        ( 3 )\r
129 \r
130 /* The number of messages that can be queued for display on the LCD at any one\r
131 time. */\r
132 #define mainLCD_QUEUE_LENGTH            ( 2 )\r
133 \r
134 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */\r
135 #define mainNO_DELAY                            ( 0 )\r
136 \r
137 /*-----------------------------------------------------------*/\r
138 \r
139 /* The type that is posted to the LCD queue. */\r
140 typedef struct LCD_MESSAGE\r
141 {\r
142         unsigned char *pucString; /* Points to the string to be displayed. */\r
143         unsigned char ucLine;     /* The line of the LCD that should be used. */\r
144 } LCDMessage;\r
145 \r
146 /*-----------------------------------------------------------*/\r
147 \r
148 /*\r
149  * The task that executes at the highest priority and checks the operation of\r
150  * all the other tasks in the system.  See the description at the top of the\r
151  * file.\r
152  */\r
153 static void vCheckTask( void *pvParameters );\r
154 \r
155 /*\r
156  * ST provided routine to configure the processor.\r
157  */\r
158 static void prvSetupHardware(void);\r
159 \r
160 /*\r
161  * The only task that should access the LCD.  Other tasks wanting to write\r
162  * to the LCD should send a message of type LCDMessage containing the\r
163  * information to display to the print task.  The print task simply blocks\r
164  * waiting for the arrival of such messages, displays the message, then blocks\r
165  * again.\r
166  */\r
167 static void vPrintTask( void *pvParameters );\r
168 \r
169 /*-----------------------------------------------------------*/\r
170 \r
171 /* The queue used to communicate with the LCD print task. */\r
172 static xQueueHandle xLCDQueue;\r
173 \r
174 /*-----------------------------------------------------------*/\r
175 \r
176 /* Create all the demo application tasks, then start the scheduler. */\r
177 void main( void )\r
178 {\r
179         /* Perform any hardware setup necessary. */\r
180         prvSetupHardware();\r
181         vParTestInitialise();\r
182 \r
183         /* Create the queue used to communicate with the LCD print task. */\r
184         xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) ); \r
185         \r
186         /* Create the standard demo application tasks.  See the WEB documentation\r
187         for more information on these tasks. */\r
188         vCreateBlockTimeTasks();\r
189         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
190         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
191         vStartDynamicPriorityTasks();\r
192         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
193         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
194         \r
195         /* Create the tasks defined within this file. */\r
196         xTaskCreate( vPrintTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
197         xTaskCreate( vCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
198         \r
199         vTaskStartScheduler();\r
200         \r
201         /* Execution will only reach here if there was insufficient heap to\r
202         start the scheduler. */\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 static void vCheckTask( void *pvParameters )\r
207 {\r
208 static unsigned long ulErrorDetected = pdFALSE; \r
209 portTickType xLastExecutionTime;\r
210 unsigned char *cErrorMessage = "              FAIL";\r
211 unsigned char *cSuccessMessage = "              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 = cSuccessMessage + uxColumn;\r
263                 }\r
264                 else\r
265                 {\r
266                         xMessage.pucString = cErrorMessage + 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 static void vPrintTask( void *pvParameters )\r
284 {\r
285 LCDMessage xMessage;\r
286 \r
287         for( ;; )\r
288         {\r
289                 /* Wait until a message arrives. */\r
290                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );\r
291                 \r
292                 /* The message contains the text to display, and the line on which the\r
293                 text should be displayed. */\r
294                 LCD_Clear();\r
295                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );\r
296         }\r
297 }\r
298 /*-----------------------------------------------------------*/\r
299 \r
300 static void prvSetupHardware(void)\r
301 {\r
302 ErrorStatus OSC4MStartUpStatus01;       \r
303 \r
304         /* ST provided routine. */\r
305 \r
306         /* MRCC system reset */\r
307         MRCC_DeInit();\r
308         \r
309         /* Wait for OSC4M start-up */\r
310         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();\r
311         \r
312         if(OSC4MStartUpStatus01 == SUCCESS)\r
313         {\r
314                 /* Set HCLK to 60MHz */\r
315                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);\r
316                 \r
317                 /* Set CKTIM to 60MHz */\r
318                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);\r
319                 \r
320                 /* Set PCLK to 30MHz */\r
321                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);\r
322                 \r
323                 /* Enable Flash Burst mode */\r
324                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);\r
325                 \r
326                 /* Set CK_SYS to 60 MHz */\r
327                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);\r
328         }\r
329         \r
330         /* GPIO pins optimized for 3V3 operation */\r
331         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);\r
332         \r
333         /* GPIO clock source enable */\r
334         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);\r
335         \r
336         /* EXTIT clock source enable */\r
337         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);\r
338         /* TB clock source enable */\r
339         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);\r
340         \r
341         /* Initialize the demonstration menu */\r
342         LCD_Init();\r
343         \r
344         LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);\r
345         LCD_DisplayString(Line2, "  STR750 Demo  ", BlackText);\r
346         \r
347         EIC_IRQCmd(ENABLE);\r
348 }\r
349 /*-----------------------------------------------------------*/\r