2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
67 * documentation provides more details of the demo application tasks.
\r
69 * In addition to the standard demo tasks there are two tasks defined within
\r
72 * 1 - The check task
\r
73 * The 'check' task is responsible for ensuring that all the standard demo
\r
74 * tasks are executing as expected. It only executes every three seconds, but
\r
75 * has the highest priority within the system so is guaranteed to get execution
\r
76 * time. Any errors discovered by the check task are latched until the
\r
77 * processor is reset. At the end of each cycle the check task sends either
\r
78 * a pass or fail message to the 'print' task for display on the LCD.
\r
80 * 2 - The print task
\r
81 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
82 * should access the LCD directly so is always guaranteed exclusive (and
\r
83 * therefore consistent) access. The print task simply blocks on a queue
\r
84 * to wait for messages from other tasks wishing to display text on the LCD.
\r
85 * When a message arrives it displays its contents on the LCD then blocks to
\r
92 /* Kernel includes. */
\r
93 #include "FreeRTOS.h"
\r
97 /* Demo application includes. */
\r
98 #include "partest.h"
\r
100 #include "integer.h"
\r
101 #include "blocktim.h"
\r
102 #include "BlockQ.h"
\r
103 #include "comtest2.h"
\r
104 #include "dynamic.h"
\r
106 /* Demo application task priorities. */
\r
107 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
108 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 /* How often should we check the other tasks? */
\r
114 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
116 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
117 offset is used a simple method of using a different column each time a message
\r
118 is written to the LCD. */
\r
119 #define mainMAX_WRITE_COLUMN ( 14 )
\r
121 /* Baud rate used by the comtest tasks. */
\r
122 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
124 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
126 #define mainCOM_TEST_LED ( 3 )
\r
128 /* The number of messages that can be queued for display on the LCD at any one
\r
130 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
132 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
133 #define mainNO_DELAY ( 0 )
\r
135 /*-----------------------------------------------------------*/
\r
137 /* The type that is posted to the LCD queue. */
\r
138 typedef struct LCD_MESSAGE
\r
140 unsigned char *pucString; /* Points to the string to be displayed. */
\r
141 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
144 /*-----------------------------------------------------------*/
\r
147 * The task that executes at the highest priority and checks the operation of
\r
148 * all the other tasks in the system. See the description at the top of the
\r
151 static void vCheckTask( void *pvParameters );
\r
154 * ST provided routine to configure the processor.
\r
156 static void prvSetupHardware(void);
\r
159 * The only task that should access the LCD. Other tasks wanting to write
\r
160 * to the LCD should send a message of type LCDMessage containing the
\r
161 * information to display to the print task. The print task simply blocks
\r
162 * waiting for the arrival of such messages, displays the message, then blocks
\r
165 static void vPrintTask( void *pvParameters );
\r
167 /*-----------------------------------------------------------*/
\r
169 /* The queue used to communicate with the LCD print task. */
\r
170 static xQueueHandle xLCDQueue;
\r
172 /*-----------------------------------------------------------*/
\r
174 /* Create all the demo application tasks, then start the scheduler. */
\r
177 /* Perform any hardware setup necessary. */
\r
178 prvSetupHardware();
\r
179 vParTestInitialise();
\r
181 /* Create the queue used to communicate with the LCD print task. */
\r
182 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
184 /* Create the standard demo application tasks. See the WEB documentation
\r
185 for more information on these tasks. */
\r
186 vCreateBlockTimeTasks();
\r
187 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
188 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
189 vStartDynamicPriorityTasks();
\r
190 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
191 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
193 /* Create the tasks defined within this file. */
\r
194 xTaskCreate( vPrintTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
195 xTaskCreate( vCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
197 vTaskStartScheduler();
\r
199 /* Execution will only reach here if there was insufficient heap to
\r
200 start the scheduler. */
\r
203 /*-----------------------------------------------------------*/
\r
205 static void vCheckTask( void *pvParameters )
\r
207 static unsigned long ulErrorDetected = pdFALSE;
\r
208 portTickType xLastExecutionTime;
\r
209 unsigned char *ucErrorMessage = ( unsigned char * )" FAIL";
\r
210 unsigned char *ucSuccessMessage = ( unsigned char * )" 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 = ucSuccessMessage + uxColumn;
\r
265 xMessage.pucString = ucErrorMessage + 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
281 /*-----------------------------------------------------------*/
\r
283 static void vPrintTask( void *pvParameters )
\r
285 LCDMessage xMessage;
\r
289 /* Wait until a message arrives. */
\r
290 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
292 /* The message contains the text to display, and the line on which the
\r
293 text should be displayed. */
\r
295 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
298 /*-----------------------------------------------------------*/
\r
300 static void prvSetupHardware(void)
\r
302 ErrorStatus OSC4MStartUpStatus01;
\r
304 /* ST provided routine. */
\r
306 /* MRCC system reset */
\r
309 /* Wait for OSC4M start-up */
\r
310 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
312 if(OSC4MStartUpStatus01 == SUCCESS)
\r
314 /* Set HCLK to 60MHz */
\r
315 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
317 /* Set CKTIM to 60MHz */
\r
318 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
320 /* Set PCLK to 30MHz */
\r
321 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
323 /* Enable Flash Burst mode */
\r
324 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
326 /* Set CK_SYS to 60 MHz */
\r
327 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
330 /* GPIO pins optimized for 3V3 operation */
\r
331 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
333 /* GPIO clock source enable */
\r
334 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
336 /* EXTIT clock source enable */
\r
337 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
338 /* TB clock source enable */
\r
339 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
341 /* Initialize the demonstration menu */
\r
344 LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
\r
345 LCD_DisplayString(Line2, ( unsigned char * ) " STR750 Demo ", BlackText);
\r
347 EIC_IRQCmd(ENABLE);
\r
349 /*-----------------------------------------------------------*/
\r