2 FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
49 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
50 * documentation provides more details of the demo application tasks.
\r
52 * In addition to the standard demo tasks there are two tasks defined within
\r
55 * 1 - The check task
\r
56 * The 'check' task is responsible for ensuring that all the standard demo
\r
57 * tasks are executing as expected. It only executes every three seconds, but
\r
58 * has the highest priority within the system so is guaranteed to get execution
\r
59 * time. Any errors discovered by the check task are latched until the
\r
60 * processor is reset. At the end of each cycle the check task sends either
\r
61 * a pass or fail message to the 'print' task for display on the LCD.
\r
63 * 2 - The print task
\r
64 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
65 * should access the LCD directly so is always guaranteed exclusive (and
\r
66 * therefore consistent) access. The print task simply blocks on a queue
\r
67 * to wait for messages from other tasks wishing to display text on the LCD.
\r
68 * When a message arrives it displays its contents on the LCD then blocks to
\r
75 /* Kernel includes. */
\r
76 #include "FreeRTOS.h"
\r
80 /* Demo application includes. */
\r
81 #include "partest.h"
\r
83 #include "integer.h"
\r
84 #include "blocktim.h"
\r
86 #include "comtest2.h"
\r
87 #include "dynamic.h"
\r
89 /* Demo application task priorities. */
\r
90 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
91 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
92 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
93 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
94 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
96 /* How often should we check the other tasks? */
\r
97 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
99 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
100 offset is used a simple method of using a different column each time a message
\r
101 is written to the LCD. */
\r
102 #define mainMAX_WRITE_COLUMN ( 14 )
\r
104 /* Baud rate used by the comtest tasks. */
\r
105 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
107 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
109 #define mainCOM_TEST_LED ( 3 )
\r
111 /* The number of messages that can be queued for display on the LCD at any one
\r
113 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
115 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
116 #define mainNO_DELAY ( 0 )
\r
118 /*-----------------------------------------------------------*/
\r
120 /* The type that is posted to the LCD queue. */
\r
121 typedef struct LCD_MESSAGE
\r
123 unsigned portCHAR *pucString; /* Points to the string to be displayed. */
\r
124 unsigned portCHAR ucLine; /* The line of the LCD that should be used. */
\r
127 /*-----------------------------------------------------------*/
\r
130 * The task that executes at the highest priority and checks the operation of
\r
131 * all the other tasks in the system. See the description at the top of the
\r
134 static void vCheckTask( void *pvParameters );
\r
137 * ST provided routine to configure the processor.
\r
139 static void prvSetupHardware(void);
\r
142 * The only task that should access the LCD. Other tasks wanting to write
\r
143 * to the LCD should send a message of type LCDMessage containing the
\r
144 * information to display to the print task. The print task simply blocks
\r
145 * waiting for the arrival of such messages, displays the message, then blocks
\r
148 static void vPrintTask( void *pvParameters );
\r
150 /*-----------------------------------------------------------*/
\r
152 /* The queue used to communicate with the LCD print task. */
\r
153 static xQueueHandle xLCDQueue;
\r
155 /*-----------------------------------------------------------*/
\r
157 /* Create all the demo application tasks, then start the scheduler. */
\r
160 /* Perform any hardware setup necessary. */
\r
161 prvSetupHardware();
\r
162 vParTestInitialise();
\r
164 /* Create the queue used to communicate with the LCD print task. */
\r
165 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
167 /* Create the standard demo application tasks. See the WEB documentation
\r
168 for more information on these tasks. */
\r
169 vCreateBlockTimeTasks();
\r
170 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
171 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
172 vStartDynamicPriorityTasks();
\r
173 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
174 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
176 /* Create the tasks defined within this file. */
\r
177 xTaskCreate( vPrintTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
178 xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
180 vTaskStartScheduler();
\r
182 /* Execution will only reach here if there was insufficient heap to
\r
183 start the scheduler. */
\r
185 /*-----------------------------------------------------------*/
\r
187 static void vCheckTask( void *pvParameters )
\r
189 static unsigned portLONG ulErrorDetected = pdFALSE;
\r
190 portTickType xLastExecutionTime;
\r
191 unsigned portCHAR *cErrorMessage = " FAIL";
\r
192 unsigned portCHAR *cSuccessMessage = " PASS";
\r
193 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
194 LCDMessage xMessage;
\r
196 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
197 works correctly. */
\r
198 xLastExecutionTime = xTaskGetTickCount();
\r
202 /* Wait until it is time for the next cycle. */
\r
203 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
205 /* Has an error been found in any of the standard demo tasks? */
\r
207 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
209 ulErrorDetected = pdTRUE;
\r
212 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
214 ulErrorDetected = pdTRUE;
\r
217 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
219 ulErrorDetected = pdTRUE;
\r
222 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
224 ulErrorDetected = pdTRUE;
\r
227 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
229 ulErrorDetected = pdTRUE;
\r
232 /* Calculate the LCD line on which we would like the message to
\r
233 be displayed. The column variable is used for convenience as
\r
234 it is incremented each cycle anyway. */
\r
235 xMessage.ucLine = ( unsigned portCHAR ) ( uxColumn & 0x01 );
\r
237 /* The message displayed depends on whether an error was found or
\r
238 not. Any discovered error is latched. Here the column variable
\r
239 is used as an index into the text string as a simple way of moving
\r
240 the text from column to column. */
\r
241 if( ulErrorDetected == pdFALSE )
\r
243 xMessage.pucString = cSuccessMessage + uxColumn;
\r
247 xMessage.pucString = cErrorMessage + uxColumn;
\r
250 /* Send the message to the print task for display. */
\r
251 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
253 /* Make sure the message is printed in a different column the next
\r
256 if( uxColumn == 0 )
\r
258 uxColumn = mainMAX_WRITE_COLUMN;
\r
262 /*-----------------------------------------------------------*/
\r
264 static void vPrintTask( void *pvParameters )
\r
266 LCDMessage xMessage;
\r
270 /* Wait until a message arrives. */
\r
271 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
273 /* The message contains the text to display, and the line on which the
\r
274 text should be displayed. */
\r
276 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
279 /*-----------------------------------------------------------*/
\r
281 static void prvSetupHardware(void)
\r
283 ErrorStatus OSC4MStartUpStatus01;
\r
285 /* ST provided routine. */
\r
287 /* MRCC system reset */
\r
290 /* Wait for OSC4M start-up */
\r
291 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
293 if(OSC4MStartUpStatus01 == SUCCESS)
\r
295 /* Set HCLK to 60MHz */
\r
296 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
298 /* Set CKTIM to 60MHz */
\r
299 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
301 /* Set PCLK to 30MHz */
\r
302 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
304 /* Enable Flash Burst mode */
\r
305 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
307 /* Set CK_SYS to 60 MHz */
\r
308 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
311 /* GPIO pins optimized for 3V3 operation */
\r
312 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
314 /* GPIO clock source enable */
\r
315 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
317 /* EXTIT clock source enable */
\r
318 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
319 /* TB clock source enable */
\r
320 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
322 /* Initialize the demonstration menu */
\r
325 LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);
\r
326 LCD_DisplayString(Line2, " STR750 Demo ", BlackText);
\r
328 EIC_IRQCmd(ENABLE);
\r
330 /*-----------------------------------------------------------*/
\r