]> git.sur5r.net Git - freertos/blob - Demo/ARM7_STR75x_GCC/main.c
Update in preparation for the V4.3.1 release.
[freertos] / Demo / ARM7_STR75x_GCC / main.c
1 /*\r
2         FreeRTOS.org V4.3.1 - Copyright (C) 2003-2007 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27         See http://www.FreeRTOS.org for documentation, latest information, license\r
28         and contact details.  Please ensure to read the configuration and relevant\r
29         port sections of the online documentation.\r
30 \r
31         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 /*\r
37  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
38  * documentation provides more details of the demo application tasks.\r
39  *\r
40  * In addition to the standard demo tasks there are two tasks defined within\r
41  * this file:\r
42  *\r
43  * 1 - The check task\r
44  * The 'check' task is responsible for ensuring that all the standard demo\r
45  * tasks are executing as expected.  It only executes every three seconds, but\r
46  * has the highest priority within the system so is guaranteed to get execution\r
47  * time.  Any errors discovered by the check task are latched until the\r
48  * processor is reset.  At the end of each cycle the check task sends either\r
49  * a pass or fail message to the 'print' task for display on the LCD.\r
50  *\r
51  * 2 - The print task\r
52  * The print task is the LCD 'gatekeeper'.  That is, it is the only task that\r
53  * should access the LCD directly so is always guaranteed exclusive (and\r
54  * therefore consistent) access.  The print task simply blocks on a queue\r
55  * to wait for messages from other tasks wishing to display text on the LCD.\r
56  * When a message arrives it displays its contents on the LCD then blocks to\r
57  * wait again.\r
58  */\r
59 \r
60 /* ST includes. */\r
61 #include "lcd.h"\r
62 \r
63 /* Kernel includes. */\r
64 #include "FreeRTOS.h"\r
65 #include "Task.h"\r
66 #include "Queue.h"\r
67 \r
68 /* Demo application includes. */\r
69 #include "ParTest.h"\r
70 #include "flash.h"\r
71 #include "integer.h"\r
72 #include "blocktim.h"\r
73 #include "BlockQ.h"\r
74 #include "comtest2.h"\r
75 #include "dynamic.h"\r
76 \r
77 /* Demo application task priorities. */\r
78 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
79 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
80 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
81 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
82 #define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
83 \r
84 /* How often should we check the other tasks? */\r
85 #define mainCHECK_TASK_CYCLE_TIME       ( 3000 )\r
86 \r
87 /* The maximum offset into the pass and fail strings sent to the LCD.  An\r
88 offset is used a simple method of using a different column each time a message\r
89 is written to the LCD. */\r
90 #define mainMAX_WRITE_COLUMN            ( 14 )\r
91 \r
92 /* Baud rate used by the comtest tasks. */\r
93 #define mainCOM_TEST_BAUD_RATE          ( 19200 )\r
94 \r
95 /* The LED used by the comtest tasks. See the comtest.c file for more\r
96 information. */\r
97 #define mainCOM_TEST_LED                        ( 3 )\r
98 \r
99 /* The number of messages that can be queued for display on the LCD at any one\r
100 time. */\r
101 #define mainLCD_QUEUE_LENGTH            ( 2 )\r
102 \r
103 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */\r
104 #define mainNO_DELAY                            ( 0 )\r
105 \r
106 /*-----------------------------------------------------------*/\r
107 \r
108 /* The type that is posted to the LCD queue. */\r
109 typedef struct LCD_MESSAGE\r
110 {\r
111         unsigned portCHAR *pucString; /* Points to the string to be displayed. */\r
112         unsigned portCHAR ucLine;         /* The line of the LCD that should be used. */\r
113 } LCDMessage;\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /*\r
118  * The task that executes at the highest priority and checks the operation of\r
119  * all the other tasks in the system.  See the description at the top of the\r
120  * file.\r
121  */\r
122 static void vCheckTask( void *pvParameters );\r
123 \r
124 /*\r
125  * ST provided routine to configure the processor.\r
126  */\r
127 static void prvSetupHardware(void);\r
128 \r
129 /*\r
130  * The only task that should access the LCD.  Other tasks wanting to write\r
131  * to the LCD should send a message of type LCDMessage containing the\r
132  * information to display to the print task.  The print task simply blocks\r
133  * waiting for the arrival of such messages, displays the message, then blocks\r
134  * again.\r
135  */\r
136 static void vPrintTask( void *pvParameters );\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 /* The queue used to communicate with the LCD print task. */\r
141 static xQueueHandle xLCDQueue;\r
142 \r
143 /*-----------------------------------------------------------*/\r
144 \r
145 /* Create all the demo application tasks, then start the scheduler. */\r
146 int main( void )\r
147 {\r
148         /* Perform any hardware setup necessary. */\r
149         prvSetupHardware();\r
150         vParTestInitialise();\r
151 \r
152         /* Create the queue used to communicate with the LCD print task. */\r
153         xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) ); \r
154         \r
155         /* Create the standard demo application tasks.  See the WEB documentation\r
156         for more information on these tasks. */\r
157         vCreateBlockTimeTasks();\r
158         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
159         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
160         vStartDynamicPriorityTasks();\r
161         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
162         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
163         \r
164         /* Create the tasks defined within this file. */\r
165         xTaskCreate( vPrintTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
166         xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
167         \r
168         vTaskStartScheduler();\r
169         \r
170         /* Execution will only reach here if there was insufficient heap to\r
171         start the scheduler. */\r
172         return 0;\r
173 }\r
174 /*-----------------------------------------------------------*/\r
175 \r
176 static void vCheckTask( void *pvParameters )\r
177 {\r
178 static unsigned portLONG ulErrorDetected = pdFALSE;     \r
179 portTickType xLastExecutionTime;\r
180 unsigned portCHAR *ucErrorMessage = ( unsigned portCHAR * )"              FAIL";\r
181 unsigned portCHAR *ucSuccessMessage = ( unsigned portCHAR * )"              PASS";\r
182 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;\r
183 LCDMessage xMessage;\r
184 \r
185         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
186         works correctly. */\r
187         xLastExecutionTime = xTaskGetTickCount();\r
188 \r
189         for( ;; )\r
190         {\r
191                 /* Wait until it is time for the next cycle. */\r
192                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );\r
193 \r
194                 /* Has an error been found in any of the standard demo tasks? */\r
195                 \r
196                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
197                 {\r
198                         ulErrorDetected = pdTRUE;\r
199                 }\r
200 \r
201                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
202                 {\r
203                         ulErrorDetected = pdTRUE;\r
204                 }\r
205 \r
206                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
207                 {\r
208                         ulErrorDetected = pdTRUE;\r
209                 }\r
210                 \r
211                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
212                 {\r
213                         ulErrorDetected = pdTRUE;\r
214                 }               \r
215                 \r
216                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
217                 {\r
218                         ulErrorDetected = pdTRUE;\r
219                 }               \r
220         \r
221                 /* Calculate the LCD line on which we would like the message to\r
222                 be displayed.  The column variable is used for convenience as\r
223                 it is incremented each cycle anyway. */\r
224                 xMessage.ucLine = ( unsigned portCHAR ) ( uxColumn & 0x01 );\r
225 \r
226                 /* The message displayed depends on whether an error was found or\r
227                 not.  Any discovered error is latched.  Here the column variable\r
228                 is used as an index into the text string as a simple way of moving\r
229                 the text from column to column. */              \r
230                 if( ulErrorDetected == pdFALSE )\r
231                 {\r
232                         xMessage.pucString = ucSuccessMessage + uxColumn;\r
233                 }\r
234                 else\r
235                 {\r
236                         xMessage.pucString = ucErrorMessage + uxColumn;                 \r
237                 }               \r
238 \r
239                 /* Send the message to the print task for display. */\r
240                 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );\r
241                 \r
242                 /* Make sure the message is printed in a different column the next\r
243                 time around. */\r
244                 uxColumn--;\r
245                 if( uxColumn == 0 )\r
246                 {\r
247                         uxColumn = mainMAX_WRITE_COLUMN;\r
248                 }\r
249         }\r
250 }\r
251 \r
252 /*-----------------------------------------------------------*/\r
253 \r
254 static void vPrintTask( void *pvParameters )\r
255 {\r
256 LCDMessage xMessage;\r
257 \r
258         for( ;; )\r
259         {\r
260                 /* Wait until a message arrives. */\r
261                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );\r
262                 \r
263                 /* The message contains the text to display, and the line on which the\r
264                 text should be displayed. */\r
265                 LCD_Clear();\r
266                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );\r
267         }\r
268 }\r
269 /*-----------------------------------------------------------*/\r
270 \r
271 static void prvSetupHardware(void)\r
272 {\r
273 ErrorStatus OSC4MStartUpStatus01;       \r
274 \r
275         /* ST provided routine. */\r
276 \r
277         /* MRCC system reset */\r
278         MRCC_DeInit();\r
279         \r
280         /* Wait for OSC4M start-up */\r
281         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();\r
282         \r
283         if(OSC4MStartUpStatus01 == SUCCESS)\r
284         {\r
285                 /* Set HCLK to 60MHz */\r
286                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);\r
287                 \r
288                 /* Set CKTIM to 60MHz */\r
289                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);\r
290                 \r
291                 /* Set PCLK to 30MHz */\r
292                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);\r
293                 \r
294                 /* Enable Flash Burst mode */\r
295                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);\r
296                 \r
297                 /* Set CK_SYS to 60 MHz */\r
298                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);\r
299         }\r
300         \r
301         /* GPIO pins optimized for 3V3 operation */\r
302         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);\r
303         \r
304         /* GPIO clock source enable */\r
305         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);\r
306         \r
307         /* EXTIT clock source enable */\r
308         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);\r
309         /* TB clock source enable */\r
310         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);\r
311         \r
312         /* Initialize the demonstration menu */\r
313         LCD_Init();\r
314         \r
315         LCD_DisplayString(Line1, ( unsigned portCHAR * ) "www.FreeRTOS.org", BlackText);\r
316         LCD_DisplayString(Line2, ( unsigned portCHAR * ) "  STR750 Demo  ", BlackText);\r
317         \r
318         EIC_IRQCmd(ENABLE);\r
319 }\r
320 /*-----------------------------------------------------------*/\r
321 \r