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