2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
69 * documentation provides more details of the demo application tasks.
\r
71 * In addition to the standard demo tasks there are two tasks defined within
\r
74 * 1 - The check task
\r
75 * The 'check' task is responsible for ensuring that all the standard demo
\r
76 * tasks are executing as expected. It only executes every three seconds, but
\r
77 * has the highest priority within the system so is guaranteed to get execution
\r
78 * time. Any errors discovered by the check task are latched until the
\r
79 * processor is reset. At the end of each cycle the check task sends either
\r
80 * a pass or fail message to the 'print' task for display on the LCD.
\r
82 * 2 - The print task
\r
83 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
84 * should access the LCD directly so is always guaranteed exclusive (and
\r
85 * therefore consistent) access. The print task simply blocks on a queue
\r
86 * to wait for messages from other tasks wishing to display text on the LCD.
\r
87 * When a message arrives it displays its contents on the LCD then blocks to
\r
94 /* Kernel includes. */
\r
95 #include "FreeRTOS.h"
\r
99 /* Demo application includes. */
\r
100 #include "partest.h"
\r
102 #include "integer.h"
\r
103 #include "blocktim.h"
\r
104 #include "BlockQ.h"
\r
105 #include "comtest2.h"
\r
106 #include "dynamic.h"
\r
108 /* Demo application task priorities. */
\r
109 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
110 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
115 /* How often should we check the other tasks? */
\r
116 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
118 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
119 offset is used a simple method of using a different column each time a message
\r
120 is written to the LCD. */
\r
121 #define mainMAX_WRITE_COLUMN ( 14 )
\r
123 /* Baud rate used by the comtest tasks. */
\r
124 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
126 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
128 #define mainCOM_TEST_LED ( 3 )
\r
130 /* The number of messages that can be queued for display on the LCD at any one
\r
132 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
134 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
135 #define mainNO_DELAY ( 0 )
\r
137 /*-----------------------------------------------------------*/
\r
139 /* The type that is posted to the LCD queue. */
\r
140 typedef struct LCD_MESSAGE
\r
142 unsigned char *pucString; /* Points to the string to be displayed. */
\r
143 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
146 /*-----------------------------------------------------------*/
\r
149 * The task that executes at the highest priority and checks the operation of
\r
150 * all the other tasks in the system. See the description at the top of the
\r
153 static void vCheckTask( void *pvParameters );
\r
156 * ST provided routine to configure the processor.
\r
158 static void prvSetupHardware(void);
\r
161 * The only task that should access the LCD. Other tasks wanting to write
\r
162 * to the LCD should send a message of type LCDMessage containing the
\r
163 * information to display to the print task. The print task simply blocks
\r
164 * waiting for the arrival of such messages, displays the message, then blocks
\r
167 static void vPrintTask( void *pvParameters );
\r
169 /*-----------------------------------------------------------*/
\r
171 /* The queue used to communicate with the LCD print task. */
\r
172 static xQueueHandle xLCDQueue;
\r
174 /*-----------------------------------------------------------*/
\r
176 /* Create all the demo application tasks, then start the scheduler. */
\r
179 /* Perform any hardware setup necessary. */
\r
180 prvSetupHardware();
\r
181 vParTestInitialise();
\r
183 /* Create the queue used to communicate with the LCD print task. */
\r
184 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
186 /* Create the standard demo application tasks. See the WEB documentation
\r
187 for more information on these tasks. */
\r
188 vCreateBlockTimeTasks();
\r
189 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
190 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
191 vStartDynamicPriorityTasks();
\r
192 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
193 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
195 /* Create the tasks defined within this file. */
\r
196 xTaskCreate( vPrintTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
197 xTaskCreate( vCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
199 vTaskStartScheduler();
\r
201 /* Execution will only reach here if there was insufficient heap to
\r
202 start the scheduler. */
\r
205 /*-----------------------------------------------------------*/
\r
207 static void vCheckTask( void *pvParameters )
\r
209 static unsigned long ulErrorDetected = pdFALSE;
\r
210 portTickType xLastExecutionTime;
\r
211 unsigned char *ucErrorMessage = ( unsigned char * )" FAIL";
\r
212 unsigned char *ucSuccessMessage = ( unsigned char * )" PASS";
\r
213 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
214 LCDMessage xMessage;
\r
216 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
217 works correctly. */
\r
218 xLastExecutionTime = xTaskGetTickCount();
\r
222 /* Wait until it is time for the next cycle. */
\r
223 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
225 /* Has an error been found in any of the standard demo tasks? */
\r
227 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
229 ulErrorDetected = pdTRUE;
\r
232 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
234 ulErrorDetected = pdTRUE;
\r
237 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
239 ulErrorDetected = pdTRUE;
\r
242 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
244 ulErrorDetected = pdTRUE;
\r
247 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
249 ulErrorDetected = pdTRUE;
\r
252 /* Calculate the LCD line on which we would like the message to
\r
253 be displayed. The column variable is used for convenience as
\r
254 it is incremented each cycle anyway. */
\r
255 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
257 /* The message displayed depends on whether an error was found or
\r
258 not. Any discovered error is latched. Here the column variable
\r
259 is used as an index into the text string as a simple way of moving
\r
260 the text from column to column. */
\r
261 if( ulErrorDetected == pdFALSE )
\r
263 xMessage.pucString = ucSuccessMessage + uxColumn;
\r
267 xMessage.pucString = ucErrorMessage + uxColumn;
\r
270 /* Send the message to the print task for display. */
\r
271 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
273 /* Make sure the message is printed in a different column the next
\r
276 if( uxColumn == 0 )
\r
278 uxColumn = mainMAX_WRITE_COLUMN;
\r
283 /*-----------------------------------------------------------*/
\r
285 static void vPrintTask( void *pvParameters )
\r
287 LCDMessage xMessage;
\r
291 /* Wait until a message arrives. */
\r
292 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
294 /* The message contains the text to display, and the line on which the
\r
295 text should be displayed. */
\r
297 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
300 /*-----------------------------------------------------------*/
\r
302 static void prvSetupHardware(void)
\r
304 ErrorStatus OSC4MStartUpStatus01;
\r
306 /* ST provided routine. */
\r
308 /* MRCC system reset */
\r
311 /* Wait for OSC4M start-up */
\r
312 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
314 if(OSC4MStartUpStatus01 == SUCCESS)
\r
316 /* Set HCLK to 60MHz */
\r
317 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
319 /* Set CKTIM to 60MHz */
\r
320 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
322 /* Set PCLK to 30MHz */
\r
323 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
325 /* Enable Flash Burst mode */
\r
326 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
328 /* Set CK_SYS to 60 MHz */
\r
329 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
332 /* GPIO pins optimized for 3V3 operation */
\r
333 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
335 /* GPIO clock source enable */
\r
336 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
338 /* EXTIT clock source enable */
\r
339 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
340 /* TB clock source enable */
\r
341 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
343 /* Initialize the demonstration menu */
\r
346 LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
\r
347 LCD_DisplayString(Line2, ( unsigned char * ) " STR750 Demo ", BlackText);
\r
349 EIC_IRQCmd(ENABLE);
\r
351 /*-----------------------------------------------------------*/
\r