2 * FreeRTOS Kernel V10.1.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
32 * In addition to the standard demo tasks there are two tasks defined within
\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
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
55 /* Kernel includes. */
\r
56 #include "FreeRTOS.h"
\r
60 /* Demo application includes. */
\r
61 #include "partest.h"
\r
63 #include "integer.h"
\r
64 #include "blocktim.h"
\r
66 #include "comtest2.h"
\r
67 #include "dynamic.h"
\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
76 /* How often should we check the other tasks? */
\r
77 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\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
84 /* Baud rate used by the comtest tasks. */
\r
85 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
87 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
89 #define mainCOM_TEST_LED ( 3 )
\r
91 /* The number of messages that can be queued for display on the LCD at any one
\r
93 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
95 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
96 #define mainNO_DELAY ( 0 )
\r
98 /*-----------------------------------------------------------*/
\r
100 /* The type that is posted to the LCD queue. */
\r
101 typedef struct LCD_MESSAGE
\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
107 /*-----------------------------------------------------------*/
\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
114 static void vCheckTask( void *pvParameters );
\r
117 * ST provided routine to configure the processor.
\r
119 static void prvSetupHardware(void);
\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
128 static void vPrintTask( void *pvParameters );
\r
130 /*-----------------------------------------------------------*/
\r
132 /* The queue used to communicate with the LCD print task. */
\r
133 static QueueHandle_t xLCDQueue;
\r
135 /*-----------------------------------------------------------*/
\r
137 /* Create all the demo application tasks, then start the scheduler. */
\r
140 /* Perform any hardware setup necessary. */
\r
141 prvSetupHardware();
\r
142 vParTestInitialise();
\r
144 /* Create the queue used to communicate with the LCD print task. */
\r
145 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\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
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
160 vTaskStartScheduler();
\r
162 /* Execution will only reach here if there was insufficient heap to
\r
163 start the scheduler. */
\r
165 /*-----------------------------------------------------------*/
\r
167 static void vCheckTask( void *pvParameters )
\r
169 static unsigned long ulErrorDetected = pdFALSE;
\r
170 TickType_t xLastExecutionTime;
\r
171 unsigned char *cErrorMessage = " FAIL";
\r
172 unsigned char *cSuccessMessage = " PASS";
\r
173 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
174 LCDMessage xMessage;
\r
176 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
177 works correctly. */
\r
178 xLastExecutionTime = xTaskGetTickCount();
\r
182 /* Wait until it is time for the next cycle. */
\r
183 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
185 /* Has an error been found in any of the standard demo tasks? */
\r
187 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
189 ulErrorDetected = pdTRUE;
\r
192 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
194 ulErrorDetected = pdTRUE;
\r
197 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
199 ulErrorDetected = pdTRUE;
\r
202 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
204 ulErrorDetected = pdTRUE;
\r
207 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
209 ulErrorDetected = pdTRUE;
\r
212 /* Calculate the LCD line on which we would like the message to
\r
213 be displayed. The column variable is used for convenience as
\r
214 it is incremented each cycle anyway. */
\r
215 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
217 /* The message displayed depends on whether an error was found or
\r
218 not. Any discovered error is latched. Here the column variable
\r
219 is used as an index into the text string as a simple way of moving
\r
220 the text from column to column. */
\r
221 if( ulErrorDetected == pdFALSE )
\r
223 xMessage.pucString = cSuccessMessage + uxColumn;
\r
227 xMessage.pucString = cErrorMessage + uxColumn;
\r
230 /* Send the message to the print task for display. */
\r
231 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
233 /* Make sure the message is printed in a different column the next
\r
236 if( uxColumn == 0 )
\r
238 uxColumn = mainMAX_WRITE_COLUMN;
\r
242 /*-----------------------------------------------------------*/
\r
244 static void vPrintTask( void *pvParameters )
\r
246 LCDMessage xMessage;
\r
250 /* Wait until a message arrives. */
\r
251 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
253 /* The message contains the text to display, and the line on which the
\r
254 text should be displayed. */
\r
256 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
259 /*-----------------------------------------------------------*/
\r
261 static void prvSetupHardware(void)
\r
263 ErrorStatus OSC4MStartUpStatus01;
\r
265 /* ST provided routine. */
\r
267 /* MRCC system reset */
\r
270 /* Wait for OSC4M start-up */
\r
271 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
273 if(OSC4MStartUpStatus01 == SUCCESS)
\r
275 /* Set HCLK to 60MHz */
\r
276 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
278 /* Set CKTIM to 60MHz */
\r
279 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
281 /* Set PCLK to 30MHz */
\r
282 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
284 /* Enable Flash Burst mode */
\r
285 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
287 /* Set CK_SYS to 60 MHz */
\r
288 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
291 /* GPIO pins optimized for 3V3 operation */
\r
292 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
294 /* GPIO clock source enable */
\r
295 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
297 /* EXTIT clock source enable */
\r
298 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
299 /* TB clock source enable */
\r
300 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
302 /* Initialize the demonstration menu */
\r
305 LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);
\r
306 LCD_DisplayString(Line2, " STR750 Demo ", BlackText);
\r
308 EIC_IRQCmd(ENABLE);
\r
310 /*-----------------------------------------------------------*/
\r