2 FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Standard includes. */
\r
57 /* Kernel includes. */
\r
58 #include "FreeRTOS.h"
\r
62 /* Demo application includes. */
\r
63 #include "partest.h"
\r
66 /* ST driver includes. */
\r
67 #include "stm32l1xx_usart.h"
\r
69 /* Eval board includes. */
\r
70 #include "stm32_eval.h"
\r
71 #include "stm32l152_eval_lcd.h"
\r
73 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
74 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
76 #define mainLCD_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
78 #define mainQUEUE_LENGTH ( 5 )
\r
80 #define mainMESSAGE_BUTTON_UP ( 1 )
\r
81 #define mainMESSAGE_BUTTON_DOWN ( 2 )
\r
82 #define mainMESSAGE_BUTTON_LEFT ( 3 )
\r
83 #define mainMESSAGE_BUTTON_RIGHT ( 4 )
\r
84 #define mainMESSAGE_BUTTON_SEL ( 5 )
\r
87 * System configuration is performed prior to main() being called, this function
\r
88 * configures the peripherals used by the demo application.
\r
90 static void prvSetupHardware( void );
\r
91 static void prvLCDTask( void *pvParameters );
\r
92 static void vTempTask( void *pv );
\r
94 static xQueueHandle xLCDQueue = NULL;
\r
104 prvSetupHardware();
\r
106 /* Create the queue used by tasks and interrupts to send strings to the LCD
\r
108 xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );
\r
110 if( xLCDQueue != NULL )
\r
112 xTaskCreate( prvLCDTask, ( signed char * ) "LCD", mainLCD_TASK_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
113 xTaskCreate( vTempTask, ( signed char * ) "Temp", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
116 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
118 vTaskStartScheduler();
\r
122 /*-----------------------------------------------------------*/
\r
124 static void prvLCDTask( void *pvParameters )
\r
126 xQueueMessage xReceivedMessage;
\r
127 long lLine = Line1;
\r
128 const long lFontHeight = (((sFONT *)LCD_GetFont())->Height);
\r
129 static char cBuffer[ 32 ];
\r
133 xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );
\r
135 if( lLine >= Line9 )
\r
141 switch( xReceivedMessage.cMessageID )
\r
143 case mainMESSAGE_BUTTON_UP : sprintf( cBuffer, "Button up = %d", xReceivedMessage.lMessageValue );
\r
145 case mainMESSAGE_BUTTON_DOWN :
\r
147 case mainMESSAGE_BUTTON_LEFT :
\r
149 case mainMESSAGE_BUTTON_RIGHT :
\r
151 case mainMESSAGE_BUTTON_SEL :
\r
153 default : sprintf( cBuffer, "Unknown message" );
\r
157 LCD_DisplayStringLine( lLine, ( uint8_t * ) cBuffer );
\r
158 lLine += lFontHeight;
\r
161 /*-----------------------------------------------------------*/
\r
163 static void vTempTask( void *pv )
\r
165 long lLastState = pdFALSE;
\r
167 xQueueMessage xMessage;
\r
171 lState = STM_EVAL_PBGetState( BUTTON_UP );
\r
172 if( lState != lLastState )
\r
174 xMessage.cMessageID = mainMESSAGE_BUTTON_UP;
\r
175 xMessage.lMessageValue = lState;
\r
176 lLastState = lState;
\r
177 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
183 /*-----------------------------------------------------------*/
\r
185 static void prvSetupHardware( void )
\r
187 /* Initialise the LEDs. */
\r
188 vParTestInitialise();
\r
191 /* Initialise the joystick inputs. */
\r
192 STM_EVAL_PBInit( BUTTON_UP, BUTTON_MODE_GPIO );
\r
193 STM_EVAL_PBInit( BUTTON_DOWN, BUTTON_MODE_GPIO );
\r
194 STM_EVAL_PBInit( BUTTON_LEFT, BUTTON_MODE_GPIO );
\r
195 STM_EVAL_PBInit( BUTTON_RIGHT, BUTTON_MODE_GPIO );
\r
196 STM_EVAL_PBInit( BUTTON_SEL, BUTTON_MODE_GPIO );
\r
199 USART_InitTypeDef USART_InitStructure;
\r
201 USART_InitStructure.USART_BaudRate = 115200;
\r
202 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
\r
203 USART_InitStructure.USART_StopBits = USART_StopBits_1;
\r
204 USART_InitStructure.USART_Parity = USART_Parity_No;
\r
205 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
\r
206 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
\r
208 STM_EVAL_COMInit( COM1, &USART_InitStructure );
\r
211 /* Initialize the LCD */
\r
212 STM32L152_LCD_Init();
\r
215 LCD_SetBackColor(Blue);
\r
216 LCD_SetTextColor(White);
\r
217 LCD_DisplayStringLine(Line0, " www.FreeRTOS.org");
\r
219 /*-----------------------------------------------------------*/
\r