2 FreeRTOS V6.0.0 - 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 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
49 /* Scheduler includes. */
\r
50 #include "FreeRTOS.h"
\r
54 /* Demo includes. */
\r
58 * The LCD is written to by more than one task so is controlled by this
\r
59 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
60 * access the LCD directly. Other tasks wanting to display a message send
\r
61 * the message to the gatekeeper.
\r
63 static void vLCDTask( void *pvParameters );
\r
66 * Setup the peripherals required to communicate with the LCD.
\r
68 static void prvSetupLCD( void );
\r
71 * Move to the first (0) or second (1) row of the LCD.
\r
73 static void prvLCDGotoRow( unsigned portSHORT usRow );
\r
76 * Write a string of text to the LCD.
\r
78 static void prvLCDPutString( portCHAR *pcString );
\r
83 static void prvLCDClear( void );
\r
85 /*-----------------------------------------------------------*/
\r
87 /* Brief delay to permit the LCD to catch up with commands. */
\r
88 #define lcdSHORT_DELAY 3
\r
90 /* SFR that seems to be missing from the standard header files. */
\r
91 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
94 #define lcdDEFAULT_FUNCTION 0x3c
\r
95 #define lcdDISPLAY_CONTROL 0x0c
\r
96 #define lcdCLEAR_DISPLAY 0x01
\r
97 #define lcdENTRY_MODE 0x06
\r
99 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
100 #define lcdQUEUE_SIZE 3
\r
101 /*-----------------------------------------------------------*/
\r
103 /* The queue used to send messages to the LCD task. */
\r
104 xQueueHandle xLCDQueue;
\r
107 /*-----------------------------------------------------------*/
\r
109 xQueueHandle xStartLCDTask( void )
\r
111 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
112 are received via this queue. */
\r
113 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
115 /* Start the task that will write to the LCD. The LCD hardware is
\r
116 initialised from within the task itself so delays can be used. */
\r
117 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
121 /*-----------------------------------------------------------*/
\r
123 static void prvLCDGotoRow( unsigned portSHORT usRow )
\r
136 vTaskDelay( lcdSHORT_DELAY );
\r
138 /*-----------------------------------------------------------*/
\r
140 static void prvLCDPutString( portCHAR *pcString )
\r
142 /* Write out each character with appropriate delay between each. */
\r
146 PMDIN1 = *pcString;
\r
148 vTaskDelay( lcdSHORT_DELAY );
\r
151 /*-----------------------------------------------------------*/
\r
153 static void prvLCDClear( void )
\r
155 /* Clear the display. */
\r
157 PMDIN1 = lcdCLEAR_DISPLAY;
\r
158 vTaskDelay( lcdSHORT_DELAY );
\r
160 /*-----------------------------------------------------------*/
\r
162 static void prvSetupLCD( void )
\r
164 /* Setup the PMP. */
\r
169 vTaskDelay( lcdSHORT_DELAY );
\r
171 /* Set the default function. */
\r
172 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
173 vTaskDelay( lcdSHORT_DELAY );
\r
175 /* Set the display control. */
\r
176 PMDIN1 = lcdDISPLAY_CONTROL;
\r
177 vTaskDelay( lcdSHORT_DELAY );
\r
179 /* Clear the display. */
\r
180 PMDIN1 = lcdCLEAR_DISPLAY;
\r
181 vTaskDelay( lcdSHORT_DELAY );
\r
183 /* Set the entry mode. */
\r
184 PMDIN1 = lcdENTRY_MODE;
\r
185 vTaskDelay( lcdSHORT_DELAY );
\r
187 /*-----------------------------------------------------------*/
\r
189 static void vLCDTask( void *pvParameters )
\r
191 xLCDMessage xMessage;
\r
192 unsigned portSHORT usRow = 0;
\r
194 /* Initialise the hardware. This uses delays so must not be called prior
\r
195 to the scheduler being started. */
\r
198 /* Welcome message. */
\r
199 prvLCDPutString( "www.FreeRTOS.org" );
\r
203 /* Wait for a message to arrive that requires displaying. */
\r
204 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
206 /* Clear the current display value. */
\r
209 /* Switch rows each time so we can see that the display is still being
\r
211 prvLCDGotoRow( usRow & 0x01 );
\r
213 prvLCDPutString( xMessage.pcMessage );
\r
215 /* Delay the requested amount of time to ensure the text just written
\r
216 to the LCD is not overwritten. */
\r
217 vTaskDelay( xMessage.xMinDisplayTime );
\r