2 FreeRTOS V8.0.0:rc1 - 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 xQueueHandle 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
204 /*-----------------------------------------------------------*/
\r
206 static void vCheckTask( void *pvParameters )
\r
208 static unsigned long ulErrorDetected = pdFALSE;
\r
209 portTickType xLastExecutionTime;
\r
210 unsigned char *ucErrorMessage = ( unsigned char * )" FAIL";
\r
211 unsigned char *ucSuccessMessage = ( unsigned char * )" PASS";
\r
212 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
213 LCDMessage xMessage;
\r
215 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
216 works correctly. */
\r
217 xLastExecutionTime = xTaskGetTickCount();
\r
221 /* Wait until it is time for the next cycle. */
\r
222 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
224 /* Has an error been found in any of the standard demo tasks? */
\r
226 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
228 ulErrorDetected = pdTRUE;
\r
231 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
233 ulErrorDetected = pdTRUE;
\r
236 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
238 ulErrorDetected = pdTRUE;
\r
241 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
243 ulErrorDetected = pdTRUE;
\r
246 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
248 ulErrorDetected = pdTRUE;
\r
251 /* Calculate the LCD line on which we would like the message to
\r
252 be displayed. The column variable is used for convenience as
\r
253 it is incremented each cycle anyway. */
\r
254 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
256 /* The message displayed depends on whether an error was found or
\r
257 not. Any discovered error is latched. Here the column variable
\r
258 is used as an index into the text string as a simple way of moving
\r
259 the text from column to column. */
\r
260 if( ulErrorDetected == pdFALSE )
\r
262 xMessage.pucString = ucSuccessMessage + uxColumn;
\r
266 xMessage.pucString = ucErrorMessage + uxColumn;
\r
269 /* Send the message to the print task for display. */
\r
270 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
272 /* Make sure the message is printed in a different column the next
\r
275 if( uxColumn == 0 )
\r
277 uxColumn = mainMAX_WRITE_COLUMN;
\r
282 /*-----------------------------------------------------------*/
\r
284 static void vPrintTask( void *pvParameters )
\r
286 LCDMessage xMessage;
\r
290 /* Wait until a message arrives. */
\r
291 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
293 /* The message contains the text to display, and the line on which the
\r
294 text should be displayed. */
\r
296 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
299 /*-----------------------------------------------------------*/
\r
301 static void prvSetupHardware(void)
\r
303 ErrorStatus OSC4MStartUpStatus01;
\r
305 /* ST provided routine. */
\r
307 /* MRCC system reset */
\r
310 /* Wait for OSC4M start-up */
\r
311 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
313 if(OSC4MStartUpStatus01 == SUCCESS)
\r
315 /* Set HCLK to 60MHz */
\r
316 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
318 /* Set CKTIM to 60MHz */
\r
319 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
321 /* Set PCLK to 30MHz */
\r
322 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
324 /* Enable Flash Burst mode */
\r
325 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
327 /* Set CK_SYS to 60 MHz */
\r
328 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
331 /* GPIO pins optimized for 3V3 operation */
\r
332 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
334 /* GPIO clock source enable */
\r
335 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
337 /* EXTIT clock source enable */
\r
338 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
339 /* TB clock source enable */
\r
340 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
342 /* Initialize the demonstration menu */
\r
345 LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
\r
346 LCD_DisplayString(Line2, ( unsigned char * ) " STR750 Demo ", BlackText);
\r
348 EIC_IRQCmd(ENABLE);
\r
350 /*-----------------------------------------------------------*/
\r