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