2 FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the demo application tasks.
\r
70 * In addition to the standard demo tasks there are two tasks defined within
\r
73 * 1 - The check task
\r
74 * The 'check' task is responsible for ensuring that all the standard demo
\r
75 * tasks are executing as expected. It only executes every three seconds, but
\r
76 * has the highest priority within the system so is guaranteed to get execution
\r
77 * time. Any errors discovered by the check task are latched until the
\r
78 * processor is reset. At the end of each cycle the check task sends either
\r
79 * a pass or fail message to the 'print' task for display on the LCD.
\r
81 * 2 - The print task
\r
82 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
83 * should access the LCD directly so is always guaranteed exclusive (and
\r
84 * therefore consistent) access. The print task simply blocks on a queue
\r
85 * to wait for messages from other tasks wishing to display text on the LCD.
\r
86 * When a message arrives it displays its contents on the LCD then blocks to
\r
93 /* Kernel includes. */
\r
94 #include "FreeRTOS.h"
\r
98 /* Demo application includes. */
\r
99 #include "partest.h"
\r
101 #include "integer.h"
\r
102 #include "blocktim.h"
\r
103 #include "BlockQ.h"
\r
104 #include "comtest2.h"
\r
105 #include "dynamic.h"
\r
107 /* Demo application task priorities. */
\r
108 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
109 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 /* How often should we check the other tasks? */
\r
115 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
117 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
118 offset is used a simple method of using a different column each time a message
\r
119 is written to the LCD. */
\r
120 #define mainMAX_WRITE_COLUMN ( 14 )
\r
122 /* Baud rate used by the comtest tasks. */
\r
123 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
125 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
127 #define mainCOM_TEST_LED ( 3 )
\r
129 /* The number of messages that can be queued for display on the LCD at any one
\r
131 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
133 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
134 #define mainNO_DELAY ( 0 )
\r
136 /*-----------------------------------------------------------*/
\r
138 /* The type that is posted to the LCD queue. */
\r
139 typedef struct LCD_MESSAGE
\r
141 unsigned char *pucString; /* Points to the string to be displayed. */
\r
142 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
145 /*-----------------------------------------------------------*/
\r
148 * The task that executes at the highest priority and checks the operation of
\r
149 * all the other tasks in the system. See the description at the top of the
\r
152 static void vCheckTask( void *pvParameters );
\r
155 * ST provided routine to configure the processor.
\r
157 static void prvSetupHardware(void);
\r
160 * The only task that should access the LCD. Other tasks wanting to write
\r
161 * to the LCD should send a message of type LCDMessage containing the
\r
162 * information to display to the print task. The print task simply blocks
\r
163 * waiting for the arrival of such messages, displays the message, then blocks
\r
166 static void vPrintTask( void *pvParameters );
\r
168 /*-----------------------------------------------------------*/
\r
170 /* The queue used to communicate with the LCD print task. */
\r
171 static QueueHandle_t xLCDQueue;
\r
173 /*-----------------------------------------------------------*/
\r
175 /* Create all the demo application tasks, then start the scheduler. */
\r
178 /* Perform any hardware setup necessary. */
\r
179 prvSetupHardware();
\r
180 vParTestInitialise();
\r
182 /* Create the queue used to communicate with the LCD print task. */
\r
183 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
185 /* Create the standard demo application tasks. See the WEB documentation
\r
186 for more information on these tasks. */
\r
187 vCreateBlockTimeTasks();
\r
188 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
189 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
190 vStartDynamicPriorityTasks();
\r
191 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
192 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
194 /* Create the tasks defined within this file. */
\r
195 xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
196 xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
198 vTaskStartScheduler();
\r
200 /* Execution will only reach here if there was insufficient heap to
\r
201 start the scheduler. */
\r
203 /*-----------------------------------------------------------*/
\r
205 static void vCheckTask( void *pvParameters )
\r
207 static unsigned long ulErrorDetected = pdFALSE;
\r
208 TickType_t xLastExecutionTime;
\r
209 unsigned char *cErrorMessage = " FAIL";
\r
210 unsigned char *cSuccessMessage = " PASS";
\r
211 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
212 LCDMessage xMessage;
\r
214 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
215 works correctly. */
\r
216 xLastExecutionTime = xTaskGetTickCount();
\r
220 /* Wait until it is time for the next cycle. */
\r
221 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
223 /* Has an error been found in any of the standard demo tasks? */
\r
225 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
227 ulErrorDetected = pdTRUE;
\r
230 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
232 ulErrorDetected = pdTRUE;
\r
235 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
237 ulErrorDetected = pdTRUE;
\r
240 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
242 ulErrorDetected = pdTRUE;
\r
245 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
247 ulErrorDetected = pdTRUE;
\r
250 /* Calculate the LCD line on which we would like the message to
\r
251 be displayed. The column variable is used for convenience as
\r
252 it is incremented each cycle anyway. */
\r
253 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
255 /* The message displayed depends on whether an error was found or
\r
256 not. Any discovered error is latched. Here the column variable
\r
257 is used as an index into the text string as a simple way of moving
\r
258 the text from column to column. */
\r
259 if( ulErrorDetected == pdFALSE )
\r
261 xMessage.pucString = cSuccessMessage + uxColumn;
\r
265 xMessage.pucString = cErrorMessage + uxColumn;
\r
268 /* Send the message to the print task for display. */
\r
269 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
271 /* Make sure the message is printed in a different column the next
\r
274 if( uxColumn == 0 )
\r
276 uxColumn = mainMAX_WRITE_COLUMN;
\r
280 /*-----------------------------------------------------------*/
\r
282 static void vPrintTask( void *pvParameters )
\r
284 LCDMessage xMessage;
\r
288 /* Wait until a message arrives. */
\r
289 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
291 /* The message contains the text to display, and the line on which the
\r
292 text should be displayed. */
\r
294 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
297 /*-----------------------------------------------------------*/
\r
299 static void prvSetupHardware(void)
\r
301 ErrorStatus OSC4MStartUpStatus01;
\r
303 /* ST provided routine. */
\r
305 /* MRCC system reset */
\r
308 /* Wait for OSC4M start-up */
\r
309 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
311 if(OSC4MStartUpStatus01 == SUCCESS)
\r
313 /* Set HCLK to 60MHz */
\r
314 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
316 /* Set CKTIM to 60MHz */
\r
317 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
319 /* Set PCLK to 30MHz */
\r
320 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
322 /* Enable Flash Burst mode */
\r
323 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
325 /* Set CK_SYS to 60 MHz */
\r
326 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
329 /* GPIO pins optimized for 3V3 operation */
\r
330 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
332 /* GPIO clock source enable */
\r
333 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
335 /* EXTIT clock source enable */
\r
336 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
337 /* TB clock source enable */
\r
338 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
340 /* Initialize the demonstration menu */
\r
343 LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);
\r
344 LCD_DisplayString(Line2, " STR750 Demo ", BlackText);
\r
346 EIC_IRQCmd(ENABLE);
\r
348 /*-----------------------------------------------------------*/
\r