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