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