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 standard demo application tasks.
\r
99 * In addition to the standard demo tasks, the following tasks and tests are
\r
100 * defined and/or created within this file:
\r
102 * "Fast Interrupt Test" - A high frequency periodic interrupt is generated
\r
103 * using a free running timer to demonstrate the use of the
\r
104 * configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt
\r
105 * service routine measures the number of processor clocks that occur between
\r
106 * each interrupt - and in so doing measures the jitter in the interrupt timing.
\r
107 * The maximum measured jitter time is latched in the ulMaxJitter variable, and
\r
108 * displayed on the LCD by the 'Check' task as described below. The
\r
109 * fast interrupt is configured and handled in the timertest.c source file.
\r
111 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
112 * is permitted to access the display directly. Other tasks wishing to write a
\r
113 * message to the LCD send the message on a queue to the LCD task instead of
\r
114 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
115 * for messages - waking and displaying the messages as they arrive.
\r
117 * "Check" task - This only executes every five seconds but has the highest
\r
118 * priority so is guaranteed to get processor time. Its main function is to
\r
119 * check that all the standard demo tasks are still operational. Should any
\r
120 * unexpected behaviour within a demo task be discovered the 'check' task will
\r
121 * write an error to the LCD (via the LCD task). If all the demo tasks are
\r
122 * executing with their expected behaviour then the check task writes PASS
\r
123 * along with the max jitter time to the LCD (again via the LCD task), as
\r
128 /* Standard includes. */
\r
131 /* Scheduler includes. */
\r
132 #include "FreeRTOS.h"
\r
136 /* Library includes. */
\r
137 #include "stm32f10x_it.h"
\r
139 /* Demo app includes. */
\r
141 #include "LCD_Message.h"
\r
142 #include "BlockQ.h"
\r
144 #include "integer.h"
\r
145 #include "blocktim.h"
\r
146 #include "partest.h"
\r
147 #include "semtest.h"
\r
150 #include "comtest2.h"
\r
152 /* Task priorities. */
\r
153 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
154 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
155 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
156 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
157 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
158 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
159 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
160 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
162 /* Constants related to the LCD. */
\r
163 #define mainMAX_LINE ( 240 )
\r
164 #define mainROW_INCREMENT ( 24 )
\r
165 #define mainMAX_COLUMN ( 20 )
\r
166 #define mainCOLUMN_START ( 319 )
\r
167 #define mainCOLUMN_INCREMENT ( 16 )
\r
169 /* The maximum number of message that can be waiting for display at any one
\r
171 #define mainLCD_QUEUE_SIZE ( 3 )
\r
173 /* The check task uses the sprintf function so requires a little more stack. */
\r
174 #define mainCHECK_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE + 50 )
\r
176 /* Dimensions the buffer into which the jitter time is written. */
\r
177 #define mainMAX_MSG_LEN 25
\r
179 /* The time between cycles of the 'check' task. */
\r
180 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
182 /* The number of nano seconds between each processor clock. */
\r
183 #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
185 /* Baud rate used by the comtest tasks. */
\r
186 #define mainCOM_TEST_BAUD_RATE ( 115200 )
\r
188 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
190 #define mainCOM_TEST_LED ( 3 )
\r
192 /*-----------------------------------------------------------*/
\r
195 * Configure the clocks, GPIO and other peripherals as required by the demo.
\r
197 static void prvSetupHardware( void );
\r
200 * Configure the LCD as required by the demo.
\r
202 static void prvConfigureLCD( void );
\r
205 * The LCD is written two by more than one task so is controlled by a
\r
206 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
207 * access the LCD directly. Other tasks wanting to display a message send
\r
208 * the message to the gatekeeper.
\r
210 static void vLCDTask( void *pvParameters );
\r
213 * Retargets the C library printf function to the USART.
\r
215 int fputc( int ch, FILE *f );
\r
218 * Checks the status of all the demo tasks then prints a message to the
\r
219 * display. The message will be either PASS - and include in brackets the
\r
220 * maximum measured jitter time (as described at the to of the file), or a
\r
221 * message that describes which of the standard demo tasks an error has been
\r
224 * Messages are not written directly to the terminal, but passed to vLCDTask
\r
227 static void vCheckTask( void *pvParameters );
\r
230 * Configures the timers and interrupts for the fast interrupt test as
\r
231 * described at the top of this file.
\r
233 extern void vSetupTimerTest( void );
\r
235 /*-----------------------------------------------------------*/
\r
237 /* The queue used to send messages to the LCD task. */
\r
238 QueueHandle_t xLCDQueue;
\r
240 /*-----------------------------------------------------------*/
\r
248 prvSetupHardware();
\r
250 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
251 are received via this queue. */
\r
252 xLCDQueue = xQueueCreate( mainLCD_QUEUE_SIZE, sizeof( xLCDMessage ) );
\r
254 /* Start the standard demo tasks. */
\r
255 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
256 vCreateBlockTimeTasks();
\r
257 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
258 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
259 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
260 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
261 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
263 /* Start the tasks defined within this file/specific to this demo. */
\r
264 xTaskCreate( vCheckTask, "Check", mainCHECK_TASK_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
265 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
267 /* The suicide tasks must be created last as they need to know how many
\r
268 tasks were running prior to their creation in order to ascertain whether
\r
269 or not the correct/expected number of tasks are running at any given time. */
\r
270 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
272 /* Configure the timers used by the fast interrupt timer test. */
\r
275 /* Start the scheduler. */
\r
276 vTaskStartScheduler();
\r
278 /* Will only get here if there was not enough heap space to create the
\r
282 /*-----------------------------------------------------------*/
\r
284 void vLCDTask( void *pvParameters )
\r
286 xLCDMessage xMessage;
\r
288 /* Initialise the LCD and display a startup message. */
\r
290 LCD_DrawMonoPict( ( unsigned long * ) pcBitmap );
\r
294 /* Wait for a message to arrive that requires displaying. */
\r
295 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
297 /* Display the message. Print each message to a different position. */
\r
298 printf( ( char const * ) xMessage.pcMessage );
\r
301 /*-----------------------------------------------------------*/
\r
303 static void vCheckTask( void *pvParameters )
\r
305 TickType_t xLastExecutionTime;
\r
306 xLCDMessage xMessage;
\r
307 static signed char cPassMessage[ mainMAX_MSG_LEN ];
\r
308 extern unsigned short usMaxJitter;
\r
310 xLastExecutionTime = xTaskGetTickCount();
\r
311 xMessage.pcMessage = cPassMessage;
\r
315 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
316 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
\r
318 /* Has an error been found in any task? */
\r
320 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
322 xMessage.pcMessage = "ERROR IN BLOCK Q\n";
\r
324 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
326 xMessage.pcMessage = "ERROR IN BLOCK TIME\n";
\r
328 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
330 xMessage.pcMessage = "ERROR IN SEMAPHORE\n";
\r
332 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
334 xMessage.pcMessage = "ERROR IN POLL Q\n";
\r
336 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
338 xMessage.pcMessage = "ERROR IN CREATE\n";
\r
340 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
342 xMessage.pcMessage = "ERROR IN MATH\n";
\r
344 else if( xAreComTestTasksStillRunning() != pdTRUE )
\r
346 xMessage.pcMessage = "ERROR IN COM TEST\n";
\r
350 sprintf( ( char * ) cPassMessage, "PASS [%uns]\n", ( ( unsigned long ) usMaxJitter ) * mainNS_PER_CLOCK );
\r
353 /* Send the message to the LCD gatekeeper for display. */
\r
354 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
357 /*-----------------------------------------------------------*/
\r
359 static void prvSetupHardware( void )
\r
361 /* Start with the clocks in their expected state. */
\r
364 /* Enable HSE (high speed external clock). */
\r
365 RCC_HSEConfig( RCC_HSE_ON );
\r
367 /* Wait till HSE is ready. */
\r
368 while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET )
\r
372 /* 2 wait states required on the flash. */
\r
373 *( ( unsigned long * ) 0x40022000 ) = 0x02;
\r
375 /* HCLK = SYSCLK */
\r
376 RCC_HCLKConfig( RCC_SYSCLK_Div1 );
\r
379 RCC_PCLK2Config( RCC_HCLK_Div1 );
\r
381 /* PCLK1 = HCLK/2 */
\r
382 RCC_PCLK1Config( RCC_HCLK_Div2 );
\r
384 /* PLLCLK = 8MHz * 9 = 72 MHz. */
\r
385 RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 );
\r
388 RCC_PLLCmd( ENABLE );
\r
390 /* Wait till PLL is ready. */
\r
391 while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
\r
395 /* Select PLL as system clock source. */
\r
396 RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );
\r
398 /* Wait till PLL is used as system clock source. */
\r
399 while( RCC_GetSYSCLKSource() != 0x08 )
\r
403 /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
\r
404 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
\r
405 | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE );
\r
407 /* SPI2 Periph clock enable */
\r
408 RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );
\r
411 /* Set the Vector Table base address at 0x08000000 */
\r
412 NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );
\r
414 NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
\r
416 /* Configure HCLK clock as SysTick clock source. */
\r
417 SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
\r
419 vParTestInitialise();
\r
421 /*-----------------------------------------------------------*/
\r
423 static void prvConfigureLCD( void )
\r
425 GPIO_InitTypeDef GPIO_InitStructure;
\r
427 /* Configure LCD Back Light (PA8) as output push-pull */
\r
428 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
\r
429 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
\r
430 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
\r
431 GPIO_Init( GPIOA, &GPIO_InitStructure );
\r
433 /* Set the Backlight Pin */
\r
434 GPIO_WriteBit(GPIOA, GPIO_Pin_8, Bit_SET);
\r
436 /* Initialize the LCD */
\r
439 /* Set the Back Color */
\r
440 LCD_SetBackColor( White );
\r
442 /* Set the Text Color */
\r
443 LCD_SetTextColor( 0x051F );
\r
447 /*-----------------------------------------------------------*/
\r
449 int fputc( int ch, FILE *f )
\r
451 static unsigned short usColumn = 0, usRefColumn = mainCOLUMN_START;
\r
452 static unsigned char ucLine = 0;
\r
454 if( ( usColumn == 0 ) && ( ucLine == 0 ) )
\r
461 /* Display one character on LCD */
\r
462 LCD_DisplayChar( ucLine, usRefColumn, (u8) ch );
\r
464 /* Decrement the column position by 16 */
\r
465 usRefColumn -= mainCOLUMN_INCREMENT;
\r
467 /* Increment the character counter */
\r
469 if( usColumn == mainMAX_COLUMN )
\r
471 ucLine += mainROW_INCREMENT;
\r
472 usRefColumn = mainCOLUMN_START;
\r
478 /* Move back to the first column of the next line. */
\r
479 ucLine += mainROW_INCREMENT;
\r
480 usRefColumn = mainCOLUMN_START;
\r
484 /* Wrap back to the top of the display. */
\r
485 if( ucLine >= mainMAX_LINE )
\r
492 /*-----------------------------------------------------------*/
\r
495 /* Keep the linker happy. */
\r
496 void assert_failed( unsigned char* pcFile, unsigned long ulLine )
\r