2 FreeRTOS V7.4.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
77 * documentation provides more details of the demo application tasks.
\r
79 * In addition to the standard demo tasks there are two tasks defined within
\r
82 * 1 - The check task
\r
83 * The 'check' task is responsible for ensuring that all the standard demo
\r
84 * tasks are executing as expected. It only executes every three seconds, but
\r
85 * has the highest priority within the system so is guaranteed to get execution
\r
86 * time. Any errors discovered by the check task are latched until the
\r
87 * processor is reset. At the end of each cycle the check task sends either
\r
88 * a pass or fail message to the 'print' task for display on the LCD.
\r
90 * 2 - The print task
\r
91 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
92 * should access the LCD directly so is always guaranteed exclusive (and
\r
93 * therefore consistent) access. The print task simply blocks on a queue
\r
94 * to wait for messages from other tasks wishing to display text on the LCD.
\r
95 * When a message arrives it displays its contents on the LCD then blocks to
\r
102 /* Kernel includes. */
\r
103 #include "FreeRTOS.h"
\r
107 /* Demo application includes. */
\r
108 #include "partest.h"
\r
110 #include "integer.h"
\r
111 #include "blocktim.h"
\r
112 #include "BlockQ.h"
\r
113 #include "comtest2.h"
\r
114 #include "dynamic.h"
\r
116 /* Demo application task priorities. */
\r
117 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
118 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
119 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
120 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
123 /* How often should we check the other tasks? */
\r
124 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
126 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
127 offset is used a simple method of using a different column each time a message
\r
128 is written to the LCD. */
\r
129 #define mainMAX_WRITE_COLUMN ( 14 )
\r
131 /* Baud rate used by the comtest tasks. */
\r
132 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
134 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
136 #define mainCOM_TEST_LED ( 3 )
\r
138 /* The number of messages that can be queued for display on the LCD at any one
\r
140 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
142 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
143 #define mainNO_DELAY ( 0 )
\r
145 /*-----------------------------------------------------------*/
\r
147 /* The type that is posted to the LCD queue. */
\r
148 typedef struct LCD_MESSAGE
\r
150 unsigned char *pucString; /* Points to the string to be displayed. */
\r
151 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
154 /*-----------------------------------------------------------*/
\r
157 * The task that executes at the highest priority and checks the operation of
\r
158 * all the other tasks in the system. See the description at the top of the
\r
161 static void vCheckTask( void *pvParameters );
\r
164 * ST provided routine to configure the processor.
\r
166 static void prvSetupHardware(void);
\r
169 * The only task that should access the LCD. Other tasks wanting to write
\r
170 * to the LCD should send a message of type LCDMessage containing the
\r
171 * information to display to the print task. The print task simply blocks
\r
172 * waiting for the arrival of such messages, displays the message, then blocks
\r
175 static void vPrintTask( void *pvParameters );
\r
177 /*-----------------------------------------------------------*/
\r
179 /* The queue used to communicate with the LCD print task. */
\r
180 static xQueueHandle xLCDQueue;
\r
182 /*-----------------------------------------------------------*/
\r
184 /* Create all the demo application tasks, then start the scheduler. */
\r
187 /* Perform any hardware setup necessary. */
\r
188 prvSetupHardware();
\r
189 vParTestInitialise();
\r
191 /* Create the queue used to communicate with the LCD print task. */
\r
192 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
194 /* Create the standard demo application tasks. See the WEB documentation
\r
195 for more information on these tasks. */
\r
196 vCreateBlockTimeTasks();
\r
197 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
198 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
199 vStartDynamicPriorityTasks();
\r
200 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
201 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
203 /* Create the tasks defined within this file. */
\r
204 xTaskCreate( vPrintTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
205 xTaskCreate( vCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
207 vTaskStartScheduler();
\r
209 /* Execution will only reach here if there was insufficient heap to
\r
210 start the scheduler. */
\r
213 /*-----------------------------------------------------------*/
\r
215 static void vCheckTask( void *pvParameters )
\r
217 static unsigned long ulErrorDetected = pdFALSE;
\r
218 portTickType xLastExecutionTime;
\r
219 unsigned char *ucErrorMessage = ( unsigned char * )" FAIL";
\r
220 unsigned char *ucSuccessMessage = ( unsigned char * )" PASS";
\r
221 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
222 LCDMessage xMessage;
\r
224 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
225 works correctly. */
\r
226 xLastExecutionTime = xTaskGetTickCount();
\r
230 /* Wait until it is time for the next cycle. */
\r
231 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
233 /* Has an error been found in any of the standard demo tasks? */
\r
235 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
237 ulErrorDetected = pdTRUE;
\r
240 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
242 ulErrorDetected = pdTRUE;
\r
245 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
247 ulErrorDetected = pdTRUE;
\r
250 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
252 ulErrorDetected = pdTRUE;
\r
255 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
257 ulErrorDetected = pdTRUE;
\r
260 /* Calculate the LCD line on which we would like the message to
\r
261 be displayed. The column variable is used for convenience as
\r
262 it is incremented each cycle anyway. */
\r
263 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
265 /* The message displayed depends on whether an error was found or
\r
266 not. Any discovered error is latched. Here the column variable
\r
267 is used as an index into the text string as a simple way of moving
\r
268 the text from column to column. */
\r
269 if( ulErrorDetected == pdFALSE )
\r
271 xMessage.pucString = ucSuccessMessage + uxColumn;
\r
275 xMessage.pucString = ucErrorMessage + uxColumn;
\r
278 /* Send the message to the print task for display. */
\r
279 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
281 /* Make sure the message is printed in a different column the next
\r
284 if( uxColumn == 0 )
\r
286 uxColumn = mainMAX_WRITE_COLUMN;
\r
291 /*-----------------------------------------------------------*/
\r
293 static void vPrintTask( void *pvParameters )
\r
295 LCDMessage xMessage;
\r
299 /* Wait until a message arrives. */
\r
300 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
302 /* The message contains the text to display, and the line on which the
\r
303 text should be displayed. */
\r
305 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
308 /*-----------------------------------------------------------*/
\r
310 static void prvSetupHardware(void)
\r
312 ErrorStatus OSC4MStartUpStatus01;
\r
314 /* ST provided routine. */
\r
316 /* MRCC system reset */
\r
319 /* Wait for OSC4M start-up */
\r
320 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
322 if(OSC4MStartUpStatus01 == SUCCESS)
\r
324 /* Set HCLK to 60MHz */
\r
325 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
327 /* Set CKTIM to 60MHz */
\r
328 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
330 /* Set PCLK to 30MHz */
\r
331 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
333 /* Enable Flash Burst mode */
\r
334 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
336 /* Set CK_SYS to 60 MHz */
\r
337 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
340 /* GPIO pins optimized for 3V3 operation */
\r
341 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
343 /* GPIO clock source enable */
\r
344 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
346 /* EXTIT clock source enable */
\r
347 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
348 /* TB clock source enable */
\r
349 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
351 /* Initialize the demonstration menu */
\r
354 LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
\r
355 LCD_DisplayString(Line2, ( unsigned char * ) " STR750 Demo ", BlackText);
\r
357 EIC_IRQCmd(ENABLE);
\r
359 /*-----------------------------------------------------------*/
\r