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