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