2 * FreeRTOS Kernel V10.0.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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
31 * documentation provides more details of the demo application tasks.
\r
33 * In addition to the standard demo tasks there are two tasks defined within
\r
36 * 1 - The check task
\r
37 * The 'check' task is responsible for ensuring that all the standard demo
\r
38 * tasks are executing as expected. It only executes every three seconds, but
\r
39 * has the highest priority within the system so is guaranteed to get execution
\r
40 * time. Any errors discovered by the check task are latched until the
\r
41 * processor is reset. At the end of each cycle the check task sends either
\r
42 * a pass or fail message to the 'print' task for display on the LCD.
\r
44 * 2 - The print task
\r
45 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
46 * should access the LCD directly so is always guaranteed exclusive (and
\r
47 * therefore consistent) access. The print task simply blocks on a queue
\r
48 * to wait for messages from other tasks wishing to display text on the LCD.
\r
49 * When a message arrives it displays its contents on the LCD then blocks to
\r
56 /* Kernel includes. */
\r
57 #include "FreeRTOS.h"
\r
61 /* Demo application includes. */
\r
62 #include "partest.h"
\r
64 #include "integer.h"
\r
65 #include "blocktim.h"
\r
67 #include "comtest2.h"
\r
68 #include "dynamic.h"
\r
70 /* Demo application task priorities. */
\r
71 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
72 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
73 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
74 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
75 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
77 /* How often should we check the other tasks? */
\r
78 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
80 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
81 offset is used a simple method of using a different column each time a message
\r
82 is written to the LCD. */
\r
83 #define mainMAX_WRITE_COLUMN ( 14 )
\r
85 /* Baud rate used by the comtest tasks. */
\r
86 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
88 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
90 #define mainCOM_TEST_LED ( 3 )
\r
92 /* The number of messages that can be queued for display on the LCD at any one
\r
94 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
96 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
97 #define mainNO_DELAY ( 0 )
\r
99 /*-----------------------------------------------------------*/
\r
101 /* The type that is posted to the LCD queue. */
\r
102 typedef struct LCD_MESSAGE
\r
104 unsigned char *pucString; /* Points to the string to be displayed. */
\r
105 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
108 /*-----------------------------------------------------------*/
\r
111 * The task that executes at the highest priority and checks the operation of
\r
112 * all the other tasks in the system. See the description at the top of the
\r
115 static void vCheckTask( void *pvParameters );
\r
118 * ST provided routine to configure the processor.
\r
120 static void prvSetupHardware(void);
\r
123 * The only task that should access the LCD. Other tasks wanting to write
\r
124 * to the LCD should send a message of type LCDMessage containing the
\r
125 * information to display to the print task. The print task simply blocks
\r
126 * waiting for the arrival of such messages, displays the message, then blocks
\r
129 static void vPrintTask( void *pvParameters );
\r
131 /*-----------------------------------------------------------*/
\r
133 /* The queue used to communicate with the LCD print task. */
\r
134 static QueueHandle_t xLCDQueue;
\r
136 /*-----------------------------------------------------------*/
\r
138 /* Create all the demo application tasks, then start the scheduler. */
\r
141 /* Perform any hardware setup necessary. */
\r
142 prvSetupHardware();
\r
143 vParTestInitialise();
\r
145 /* Create the queue used to communicate with the LCD print task. */
\r
146 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
148 /* Create the standard demo application tasks. See the WEB documentation
\r
149 for more information on these tasks. */
\r
150 vCreateBlockTimeTasks();
\r
151 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
152 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
153 vStartDynamicPriorityTasks();
\r
154 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
155 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
157 /* Create the tasks defined within this file. */
\r
158 xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
159 xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
161 vTaskStartScheduler();
\r
163 /* Execution will only reach here if there was insufficient heap to
\r
164 start the scheduler. */
\r
166 /*-----------------------------------------------------------*/
\r
168 static void vCheckTask( void *pvParameters )
\r
170 static unsigned long ulErrorDetected = pdFALSE;
\r
171 TickType_t xLastExecutionTime;
\r
172 unsigned char *cErrorMessage = " FAIL";
\r
173 unsigned char *cSuccessMessage = " PASS";
\r
174 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
175 LCDMessage xMessage;
\r
177 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
178 works correctly. */
\r
179 xLastExecutionTime = xTaskGetTickCount();
\r
183 /* Wait until it is time for the next cycle. */
\r
184 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
186 /* Has an error been found in any of the standard demo tasks? */
\r
188 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
190 ulErrorDetected = pdTRUE;
\r
193 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
195 ulErrorDetected = pdTRUE;
\r
198 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
200 ulErrorDetected = pdTRUE;
\r
203 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
205 ulErrorDetected = pdTRUE;
\r
208 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
210 ulErrorDetected = pdTRUE;
\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
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
224 xMessage.pucString = cSuccessMessage + uxColumn;
\r
228 xMessage.pucString = cErrorMessage + uxColumn;
\r
231 /* Send the message to the print task for display. */
\r
232 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
234 /* Make sure the message is printed in a different column the next
\r
237 if( uxColumn == 0 )
\r
239 uxColumn = mainMAX_WRITE_COLUMN;
\r
243 /*-----------------------------------------------------------*/
\r
245 static void vPrintTask( void *pvParameters )
\r
247 LCDMessage xMessage;
\r
251 /* Wait until a message arrives. */
\r
252 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
254 /* The message contains the text to display, and the line on which the
\r
255 text should be displayed. */
\r
257 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
260 /*-----------------------------------------------------------*/
\r
262 static void prvSetupHardware(void)
\r
264 ErrorStatus OSC4MStartUpStatus01;
\r
266 /* ST provided routine. */
\r
268 /* MRCC system reset */
\r
271 /* Wait for OSC4M start-up */
\r
272 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
274 if(OSC4MStartUpStatus01 == SUCCESS)
\r
276 /* Set HCLK to 60MHz */
\r
277 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
279 /* Set CKTIM to 60MHz */
\r
280 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
282 /* Set PCLK to 30MHz */
\r
283 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
285 /* Enable Flash Burst mode */
\r
286 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
288 /* Set CK_SYS to 60 MHz */
\r
289 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
292 /* GPIO pins optimized for 3V3 operation */
\r
293 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
295 /* GPIO clock source enable */
\r
296 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
298 /* EXTIT clock source enable */
\r
299 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
300 /* TB clock source enable */
\r
301 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
303 /* Initialize the demonstration menu */
\r
306 LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);
\r
307 LCD_DisplayString(Line2, " STR750 Demo ", BlackText);
\r
309 EIC_IRQCmd(ENABLE);
\r
311 /*-----------------------------------------------------------*/
\r