]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR75x_GCC/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / ARM7_STR75x_GCC / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
30  * documentation provides more details of the demo application tasks.\r
31  *\r
32  * In addition to the standard demo tasks there are two tasks defined within\r
33  * this file:\r
34  *\r
35  * 1 - The check task\r
36  * The 'check' task is responsible for ensuring that all the standard demo\r
37  * tasks are executing as expected.  It only executes every three seconds, but\r
38  * has the highest priority within the system so is guaranteed to get execution\r
39  * time.  Any errors discovered by the check task are latched until the\r
40  * processor is reset.  At the end of each cycle the check task sends either\r
41  * a pass or fail message to the 'print' task for display on the LCD.\r
42  *\r
43  * 2 - The print task\r
44  * The print task is the LCD 'gatekeeper'.  That is, it is the only task that\r
45  * should access the LCD directly so is always guaranteed exclusive (and\r
46  * therefore consistent) access.  The print task simply blocks on a queue\r
47  * to wait for messages from other tasks wishing to display text on the LCD.\r
48  * When a message arrives it displays its contents on the LCD then blocks to\r
49  * wait again.\r
50  */\r
51 \r
52 /* ST includes. */\r
53 #include "lcd.h"\r
54 \r
55 /* Kernel includes. */\r
56 #include "FreeRTOS.h"\r
57 #include "task.h"\r
58 #include "queue.h"\r
59 \r
60 /* Demo application includes. */\r
61 #include "partest.h"\r
62 #include "flash.h"\r
63 #include "integer.h"\r
64 #include "blocktim.h"\r
65 #include "BlockQ.h"\r
66 #include "comtest2.h"\r
67 #include "dynamic.h"\r
68 \r
69 /* Demo application task priorities. */\r
70 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
71 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
72 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
73 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
74 #define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
75 \r
76 /* How often should we check the other tasks? */\r
77 #define mainCHECK_TASK_CYCLE_TIME       ( 3000 )\r
78 \r
79 /* The maximum offset into the pass and fail strings sent to the LCD.  An\r
80 offset is used a simple method of using a different column each time a message\r
81 is written to the LCD. */\r
82 #define mainMAX_WRITE_COLUMN            ( 14 )\r
83 \r
84 /* Baud rate used by the comtest tasks. */\r
85 #define mainCOM_TEST_BAUD_RATE          ( 19200 )\r
86 \r
87 /* The LED used by the comtest tasks. See the comtest.c file for more\r
88 information. */\r
89 #define mainCOM_TEST_LED                        ( 3 )\r
90 \r
91 /* The number of messages that can be queued for display on the LCD at any one\r
92 time. */\r
93 #define mainLCD_QUEUE_LENGTH            ( 2 )\r
94 \r
95 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */\r
96 #define mainNO_DELAY                            ( 0 )\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 /* The type that is posted to the LCD queue. */\r
101 typedef struct LCD_MESSAGE\r
102 {\r
103         unsigned char *pucString; /* Points to the string to be displayed. */\r
104         unsigned char ucLine;     /* The line of the LCD that should be used. */\r
105 } LCDMessage;\r
106 \r
107 /*-----------------------------------------------------------*/\r
108 \r
109 /*\r
110  * The task that executes at the highest priority and checks the operation of\r
111  * all the other tasks in the system.  See the description at the top of the\r
112  * file.\r
113  */\r
114 static void vCheckTask( void *pvParameters );\r
115 \r
116 /*\r
117  * ST provided routine to configure the processor.\r
118  */\r
119 static void prvSetupHardware(void);\r
120 \r
121 /*\r
122  * The only task that should access the LCD.  Other tasks wanting to write\r
123  * to the LCD should send a message of type LCDMessage containing the\r
124  * information to display to the print task.  The print task simply blocks\r
125  * waiting for the arrival of such messages, displays the message, then blocks\r
126  * again.\r
127  */\r
128 static void vPrintTask( void *pvParameters );\r
129 \r
130 /*-----------------------------------------------------------*/\r
131 \r
132 /* The queue used to communicate with the LCD print task. */\r
133 static QueueHandle_t xLCDQueue;\r
134 \r
135 /*-----------------------------------------------------------*/\r
136 \r
137 /* Create all the demo application tasks, then start the scheduler. */\r
138 int main( void )\r
139 {\r
140         /* Perform any hardware setup necessary. */\r
141         prvSetupHardware();\r
142         vParTestInitialise();\r
143 \r
144         /* Create the queue used to communicate with the LCD print task. */\r
145         xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );\r
146 \r
147         /* Create the standard demo application tasks.  See the WEB documentation\r
148         for more information on these tasks. */\r
149         vCreateBlockTimeTasks();\r
150         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
151         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
152         vStartDynamicPriorityTasks();\r
153         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
154         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
155 \r
156         /* Create the tasks defined within this file. */\r
157         xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
158         xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
159 \r
160         vTaskStartScheduler();\r
161 \r
162         /* Execution will only reach here if there was insufficient heap to\r
163         start the scheduler. */\r
164         return 0;\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 static void vCheckTask( void *pvParameters )\r
169 {\r
170 static unsigned long ulErrorDetected = pdFALSE;\r
171 TickType_t xLastExecutionTime;\r
172 unsigned char *ucErrorMessage = ( unsigned char * )"              FAIL";\r
173 unsigned char *ucSuccessMessage = ( unsigned char * )"              PASS";\r
174 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;\r
175 LCDMessage xMessage;\r
176 \r
177         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
178         works correctly. */\r
179         xLastExecutionTime = xTaskGetTickCount();\r
180 \r
181         for( ;; )\r
182         {\r
183                 /* Wait until it is time for the next cycle. */\r
184                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );\r
185 \r
186                 /* Has an error been found in any of the standard demo tasks? */\r
187 \r
188                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
189                 {\r
190                         ulErrorDetected = pdTRUE;\r
191                 }\r
192 \r
193                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
194                 {\r
195                         ulErrorDetected = pdTRUE;\r
196                 }\r
197 \r
198                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
199                 {\r
200                         ulErrorDetected = pdTRUE;\r
201                 }\r
202 \r
203                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
204                 {\r
205                         ulErrorDetected = pdTRUE;\r
206                 }\r
207 \r
208                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
209                 {\r
210                         ulErrorDetected = pdTRUE;\r
211                 }\r
212 \r
213                 /* Calculate the LCD line on which we would like the message to\r
214                 be displayed.  The column variable is used for convenience as\r
215                 it is incremented each cycle anyway. */\r
216                 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );\r
217 \r
218                 /* The message displayed depends on whether an error was found or\r
219                 not.  Any discovered error is latched.  Here the column variable\r
220                 is used as an index into the text string as a simple way of moving\r
221                 the text from column to column. */\r
222                 if( ulErrorDetected == pdFALSE )\r
223                 {\r
224                         xMessage.pucString = ucSuccessMessage + uxColumn;\r
225                 }\r
226                 else\r
227                 {\r
228                         xMessage.pucString = ucErrorMessage + uxColumn;\r
229                 }\r
230 \r
231                 /* Send the message to the print task for display. */\r
232                 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );\r
233 \r
234                 /* Make sure the message is printed in a different column the next\r
235                 time around. */\r
236                 uxColumn--;\r
237                 if( uxColumn == 0 )\r
238                 {\r
239                         uxColumn = mainMAX_WRITE_COLUMN;\r
240                 }\r
241         }\r
242 }\r
243 \r
244 /*-----------------------------------------------------------*/\r
245 \r
246 static void vPrintTask( void *pvParameters )\r
247 {\r
248 LCDMessage xMessage;\r
249 \r
250         for( ;; )\r
251         {\r
252                 /* Wait until a message arrives. */\r
253                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );\r
254 \r
255                 /* The message contains the text to display, and the line on which the\r
256                 text should be displayed. */\r
257                 LCD_Clear();\r
258                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );\r
259         }\r
260 }\r
261 /*-----------------------------------------------------------*/\r
262 \r
263 static void prvSetupHardware(void)\r
264 {\r
265 ErrorStatus OSC4MStartUpStatus01;\r
266 \r
267         /* ST provided routine. */\r
268 \r
269         /* MRCC system reset */\r
270         MRCC_DeInit();\r
271 \r
272         /* Wait for OSC4M start-up */\r
273         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();\r
274 \r
275         if(OSC4MStartUpStatus01 == SUCCESS)\r
276         {\r
277                 /* Set HCLK to 60MHz */\r
278                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);\r
279 \r
280                 /* Set CKTIM to 60MHz */\r
281                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);\r
282 \r
283                 /* Set PCLK to 30MHz */\r
284                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);\r
285 \r
286                 /* Enable Flash Burst mode */\r
287                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);\r
288 \r
289                 /* Set CK_SYS to 60 MHz */\r
290                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);\r
291         }\r
292 \r
293         /* GPIO pins optimized for 3V3 operation */\r
294         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);\r
295 \r
296         /* GPIO clock source enable */\r
297         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);\r
298 \r
299         /* EXTIT clock source enable */\r
300         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);\r
301         /* TB clock source enable */\r
302         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);\r
303 \r
304         /* Initialize the demonstration menu */\r
305         LCD_Init();\r
306 \r
307         LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);\r
308         LCD_DisplayString(Line2, ( unsigned char * ) "  STR750 Demo  ", BlackText);\r
309 \r
310         EIC_IRQCmd(ENABLE);\r
311 }\r
312 /*-----------------------------------------------------------*/\r
313 \r