2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
98 * documentation provides more details of the demo application tasks.
\r
100 * In addition to the standard demo tasks there are two tasks defined within
\r
103 * 1 - The check task
\r
104 * The 'check' task is responsible for ensuring that all the standard demo
\r
105 * tasks are executing as expected. It only executes every three seconds, but
\r
106 * has the highest priority within the system so is guaranteed to get execution
\r
107 * time. Any errors discovered by the check task are latched until the
\r
108 * processor is reset. At the end of each cycle the check task sends either
\r
109 * a pass or fail message to the 'print' task for display on the LCD.
\r
111 * 2 - The print task
\r
112 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
113 * should access the LCD directly so is always guaranteed exclusive (and
\r
114 * therefore consistent) access. The print task simply blocks on a queue
\r
115 * to wait for messages from other tasks wishing to display text on the LCD.
\r
116 * When a message arrives it displays its contents on the LCD then blocks to
\r
123 /* Kernel includes. */
\r
124 #include "FreeRTOS.h"
\r
128 /* Demo application includes. */
\r
129 #include "partest.h"
\r
131 #include "integer.h"
\r
132 #include "blocktim.h"
\r
133 #include "BlockQ.h"
\r
134 #include "comtest2.h"
\r
135 #include "dynamic.h"
\r
137 /* Demo application task priorities. */
\r
138 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
139 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
140 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
141 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
142 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
144 /* How often should we check the other tasks? */
\r
145 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
147 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
148 offset is used a simple method of using a different column each time a message
\r
149 is written to the LCD. */
\r
150 #define mainMAX_WRITE_COLUMN ( 14 )
\r
152 /* Baud rate used by the comtest tasks. */
\r
153 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
155 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
157 #define mainCOM_TEST_LED ( 3 )
\r
159 /* The number of messages that can be queued for display on the LCD at any one
\r
161 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
163 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
164 #define mainNO_DELAY ( 0 )
\r
166 /*-----------------------------------------------------------*/
\r
168 /* The type that is posted to the LCD queue. */
\r
169 typedef struct LCD_MESSAGE
\r
171 unsigned char *pucString; /* Points to the string to be displayed. */
\r
172 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
175 /*-----------------------------------------------------------*/
\r
178 * The task that executes at the highest priority and checks the operation of
\r
179 * all the other tasks in the system. See the description at the top of the
\r
182 static void vCheckTask( void *pvParameters );
\r
185 * ST provided routine to configure the processor.
\r
187 static void prvSetupHardware(void);
\r
190 * The only task that should access the LCD. Other tasks wanting to write
\r
191 * to the LCD should send a message of type LCDMessage containing the
\r
192 * information to display to the print task. The print task simply blocks
\r
193 * waiting for the arrival of such messages, displays the message, then blocks
\r
196 static void vPrintTask( void *pvParameters );
\r
198 /*-----------------------------------------------------------*/
\r
200 /* The queue used to communicate with the LCD print task. */
\r
201 static QueueHandle_t xLCDQueue;
\r
203 /*-----------------------------------------------------------*/
\r
205 /* Create all the demo application tasks, then start the scheduler. */
\r
208 /* Perform any hardware setup necessary. */
\r
209 prvSetupHardware();
\r
210 vParTestInitialise();
\r
212 /* Create the queue used to communicate with the LCD print task. */
\r
213 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
215 /* Create the standard demo application tasks. See the WEB documentation
\r
216 for more information on these tasks. */
\r
217 vCreateBlockTimeTasks();
\r
218 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
219 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
220 vStartDynamicPriorityTasks();
\r
221 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
222 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
224 /* Create the tasks defined within this file. */
\r
225 xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
226 xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
228 vTaskStartScheduler();
\r
230 /* Execution will only reach here if there was insufficient heap to
\r
231 start the scheduler. */
\r
234 /*-----------------------------------------------------------*/
\r
236 static void vCheckTask( void *pvParameters )
\r
238 static unsigned long ulErrorDetected = pdFALSE;
\r
239 TickType_t xLastExecutionTime;
\r
240 unsigned char *ucErrorMessage = ( unsigned char * )" FAIL";
\r
241 unsigned char *ucSuccessMessage = ( unsigned char * )" PASS";
\r
242 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
243 LCDMessage xMessage;
\r
245 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
246 works correctly. */
\r
247 xLastExecutionTime = xTaskGetTickCount();
\r
251 /* Wait until it is time for the next cycle. */
\r
252 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
254 /* Has an error been found in any of the standard demo tasks? */
\r
256 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
258 ulErrorDetected = pdTRUE;
\r
261 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
263 ulErrorDetected = pdTRUE;
\r
266 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
268 ulErrorDetected = pdTRUE;
\r
271 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
273 ulErrorDetected = pdTRUE;
\r
276 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
278 ulErrorDetected = pdTRUE;
\r
281 /* Calculate the LCD line on which we would like the message to
\r
282 be displayed. The column variable is used for convenience as
\r
283 it is incremented each cycle anyway. */
\r
284 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
286 /* The message displayed depends on whether an error was found or
\r
287 not. Any discovered error is latched. Here the column variable
\r
288 is used as an index into the text string as a simple way of moving
\r
289 the text from column to column. */
\r
290 if( ulErrorDetected == pdFALSE )
\r
292 xMessage.pucString = ucSuccessMessage + uxColumn;
\r
296 xMessage.pucString = ucErrorMessage + uxColumn;
\r
299 /* Send the message to the print task for display. */
\r
300 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
302 /* Make sure the message is printed in a different column the next
\r
305 if( uxColumn == 0 )
\r
307 uxColumn = mainMAX_WRITE_COLUMN;
\r
312 /*-----------------------------------------------------------*/
\r
314 static void vPrintTask( void *pvParameters )
\r
316 LCDMessage xMessage;
\r
320 /* Wait until a message arrives. */
\r
321 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
323 /* The message contains the text to display, and the line on which the
\r
324 text should be displayed. */
\r
326 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
329 /*-----------------------------------------------------------*/
\r
331 static void prvSetupHardware(void)
\r
333 ErrorStatus OSC4MStartUpStatus01;
\r
335 /* ST provided routine. */
\r
337 /* MRCC system reset */
\r
340 /* Wait for OSC4M start-up */
\r
341 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
343 if(OSC4MStartUpStatus01 == SUCCESS)
\r
345 /* Set HCLK to 60MHz */
\r
346 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
348 /* Set CKTIM to 60MHz */
\r
349 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
351 /* Set PCLK to 30MHz */
\r
352 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
354 /* Enable Flash Burst mode */
\r
355 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
357 /* Set CK_SYS to 60 MHz */
\r
358 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
361 /* GPIO pins optimized for 3V3 operation */
\r
362 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
364 /* GPIO clock source enable */
\r
365 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
367 /* EXTIT clock source enable */
\r
368 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
369 /* TB clock source enable */
\r
370 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
372 /* Initialize the demonstration menu */
\r
375 LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
\r
376 LCD_DisplayString(Line2, ( unsigned char * ) " STR750 Demo ", BlackText);
\r
378 EIC_IRQCmd(ENABLE);
\r
380 /*-----------------------------------------------------------*/
\r