2 FreeRTOS V9.0.0 - Copyright (C) 2016 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 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
72 * documentation provides more details of the demo application tasks.
\r
74 * In addition to the standard demo tasks there are two tasks defined within
\r
77 * 1 - The check task
\r
78 * The 'check' task is responsible for ensuring that all the standard demo
\r
79 * tasks are executing as expected. It only executes every three seconds, but
\r
80 * has the highest priority within the system so is guaranteed to get execution
\r
81 * time. Any errors discovered by the check task are latched until the
\r
82 * processor is reset. At the end of each cycle the check task sends either
\r
83 * a pass or fail message to the 'print' task for display on the LCD.
\r
85 * 2 - The print task
\r
86 * The print task is the LCD 'gatekeeper'. That is, it is the only task that
\r
87 * should access the LCD directly so is always guaranteed exclusive (and
\r
88 * therefore consistent) access. The print task simply blocks on a queue
\r
89 * to wait for messages from other tasks wishing to display text on the LCD.
\r
90 * When a message arrives it displays its contents on the LCD then blocks to
\r
97 /* Kernel includes. */
\r
98 #include "FreeRTOS.h"
\r
102 /* Demo application includes. */
\r
103 #include "partest.h"
\r
105 #include "integer.h"
\r
106 #include "blocktim.h"
\r
107 #include "BlockQ.h"
\r
108 #include "comtest2.h"
\r
109 #include "dynamic.h"
\r
111 /* Demo application task priorities. */
\r
112 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
113 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
115 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
118 /* How often should we check the other tasks? */
\r
119 #define mainCHECK_TASK_CYCLE_TIME ( 3000 )
\r
121 /* The maximum offset into the pass and fail strings sent to the LCD. An
\r
122 offset is used a simple method of using a different column each time a message
\r
123 is written to the LCD. */
\r
124 #define mainMAX_WRITE_COLUMN ( 14 )
\r
126 /* Baud rate used by the comtest tasks. */
\r
127 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
129 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
131 #define mainCOM_TEST_LED ( 3 )
\r
133 /* The number of messages that can be queued for display on the LCD at any one
\r
135 #define mainLCD_QUEUE_LENGTH ( 2 )
\r
137 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
\r
138 #define mainNO_DELAY ( 0 )
\r
140 /*-----------------------------------------------------------*/
\r
142 /* The type that is posted to the LCD queue. */
\r
143 typedef struct LCD_MESSAGE
\r
145 unsigned char *pucString; /* Points to the string to be displayed. */
\r
146 unsigned char ucLine; /* The line of the LCD that should be used. */
\r
149 /*-----------------------------------------------------------*/
\r
152 * The task that executes at the highest priority and checks the operation of
\r
153 * all the other tasks in the system. See the description at the top of the
\r
156 static void vCheckTask( void *pvParameters );
\r
159 * ST provided routine to configure the processor.
\r
161 static void prvSetupHardware(void);
\r
164 * The only task that should access the LCD. Other tasks wanting to write
\r
165 * to the LCD should send a message of type LCDMessage containing the
\r
166 * information to display to the print task. The print task simply blocks
\r
167 * waiting for the arrival of such messages, displays the message, then blocks
\r
170 static void vPrintTask( void *pvParameters );
\r
172 /*-----------------------------------------------------------*/
\r
174 /* The queue used to communicate with the LCD print task. */
\r
175 static QueueHandle_t xLCDQueue;
\r
177 /*-----------------------------------------------------------*/
\r
179 /* Create all the demo application tasks, then start the scheduler. */
\r
182 /* Perform any hardware setup necessary. */
\r
183 prvSetupHardware();
\r
184 vParTestInitialise();
\r
186 /* Create the queue used to communicate with the LCD print task. */
\r
187 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
\r
189 /* Create the standard demo application tasks. See the WEB documentation
\r
190 for more information on these tasks. */
\r
191 vCreateBlockTimeTasks();
\r
192 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
193 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
194 vStartDynamicPriorityTasks();
\r
195 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
196 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
198 /* Create the tasks defined within this file. */
\r
199 xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
200 xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
202 vTaskStartScheduler();
\r
204 /* Execution will only reach here if there was insufficient heap to
\r
205 start the scheduler. */
\r
208 /*-----------------------------------------------------------*/
\r
210 static void vCheckTask( void *pvParameters )
\r
212 static unsigned long ulErrorDetected = pdFALSE;
\r
213 TickType_t xLastExecutionTime;
\r
214 unsigned char *ucErrorMessage = ( unsigned char * )" FAIL";
\r
215 unsigned char *ucSuccessMessage = ( unsigned char * )" PASS";
\r
216 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
\r
217 LCDMessage xMessage;
\r
219 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
220 works correctly. */
\r
221 xLastExecutionTime = xTaskGetTickCount();
\r
225 /* Wait until it is time for the next cycle. */
\r
226 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
\r
228 /* Has an error been found in any of the standard demo tasks? */
\r
230 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
232 ulErrorDetected = pdTRUE;
\r
235 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
237 ulErrorDetected = pdTRUE;
\r
240 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
242 ulErrorDetected = pdTRUE;
\r
245 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
247 ulErrorDetected = pdTRUE;
\r
250 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
252 ulErrorDetected = pdTRUE;
\r
255 /* Calculate the LCD line on which we would like the message to
\r
256 be displayed. The column variable is used for convenience as
\r
257 it is incremented each cycle anyway. */
\r
258 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
\r
260 /* The message displayed depends on whether an error was found or
\r
261 not. Any discovered error is latched. Here the column variable
\r
262 is used as an index into the text string as a simple way of moving
\r
263 the text from column to column. */
\r
264 if( ulErrorDetected == pdFALSE )
\r
266 xMessage.pucString = ucSuccessMessage + uxColumn;
\r
270 xMessage.pucString = ucErrorMessage + uxColumn;
\r
273 /* Send the message to the print task for display. */
\r
274 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
\r
276 /* Make sure the message is printed in a different column the next
\r
279 if( uxColumn == 0 )
\r
281 uxColumn = mainMAX_WRITE_COLUMN;
\r
286 /*-----------------------------------------------------------*/
\r
288 static void vPrintTask( void *pvParameters )
\r
290 LCDMessage xMessage;
\r
294 /* Wait until a message arrives. */
\r
295 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
\r
297 /* The message contains the text to display, and the line on which the
\r
298 text should be displayed. */
\r
300 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
\r
303 /*-----------------------------------------------------------*/
\r
305 static void prvSetupHardware(void)
\r
307 ErrorStatus OSC4MStartUpStatus01;
\r
309 /* ST provided routine. */
\r
311 /* MRCC system reset */
\r
314 /* Wait for OSC4M start-up */
\r
315 OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
\r
317 if(OSC4MStartUpStatus01 == SUCCESS)
\r
319 /* Set HCLK to 60MHz */
\r
320 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
\r
322 /* Set CKTIM to 60MHz */
\r
323 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
\r
325 /* Set PCLK to 30MHz */
\r
326 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
\r
328 /* Enable Flash Burst mode */
\r
329 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
\r
331 /* Set CK_SYS to 60 MHz */
\r
332 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
\r
335 /* GPIO pins optimized for 3V3 operation */
\r
336 MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
\r
338 /* GPIO clock source enable */
\r
339 MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
\r
341 /* EXTIT clock source enable */
\r
342 MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
\r
343 /* TB clock source enable */
\r
344 MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
\r
346 /* Initialize the demonstration menu */
\r
349 LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
\r
350 LCD_DisplayString(Line2, ( unsigned char * ) " STR750 Demo ", BlackText);
\r
352 EIC_IRQCmd(ENABLE);
\r
354 /*-----------------------------------------------------------*/
\r