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