2 FreeRTOS V5.4.1 - 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 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
48 /* Scheduler includes. */
\r
49 #include "FreeRTOS.h"
\r
53 /* Demo includes. */
\r
57 * The LCD is written to by more than one task so is controlled by this
\r
58 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
59 * access the LCD directly. Other tasks wanting to display a message send
\r
60 * the message to the gatekeeper.
\r
62 static void vLCDTask( void *pvParameters );
\r
65 * Setup the peripherals required to communicate with the LCD.
\r
67 static void prvSetupLCD( void );
\r
70 * Move to the first (0) or second (1) row of the LCD.
\r
72 static void prvLCDGotoRow( unsigned portSHORT usRow );
\r
75 * Write a string of text to the LCD.
\r
77 static void prvLCDPutString( portCHAR *pcString );
\r
82 static void prvLCDClear( void );
\r
84 /*-----------------------------------------------------------*/
\r
86 /* Brief delay to permit the LCD to catch up with commands. */
\r
87 #define lcdSHORT_DELAY 3
\r
89 /* SFR that seems to be missing from the standard header files. */
\r
90 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
93 #define lcdDEFAULT_FUNCTION 0x3c
\r
94 #define lcdDISPLAY_CONTROL 0x0c
\r
95 #define lcdCLEAR_DISPLAY 0x01
\r
96 #define lcdENTRY_MODE 0x06
\r
98 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
99 #define lcdQUEUE_SIZE 3
\r
100 /*-----------------------------------------------------------*/
\r
102 /* The queue used to send messages to the LCD task. */
\r
103 xQueueHandle xLCDQueue;
\r
106 /*-----------------------------------------------------------*/
\r
108 xQueueHandle xStartLCDTask( void )
\r
110 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
111 are received via this queue. */
\r
112 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
114 /* Start the task that will write to the LCD. The LCD hardware is
\r
115 initialised from within the task itself so delays can be used. */
\r
116 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
120 /*-----------------------------------------------------------*/
\r
122 static void prvLCDGotoRow( unsigned portSHORT usRow )
\r
135 vTaskDelay( lcdSHORT_DELAY );
\r
137 /*-----------------------------------------------------------*/
\r
139 static void prvLCDPutString( portCHAR *pcString )
\r
141 /* Write out each character with appropriate delay between each. */
\r
145 PMDIN1 = *pcString;
\r
147 vTaskDelay( lcdSHORT_DELAY );
\r
150 /*-----------------------------------------------------------*/
\r
152 static void prvLCDClear( void )
\r
154 /* Clear the display. */
\r
156 PMDIN1 = lcdCLEAR_DISPLAY;
\r
157 vTaskDelay( lcdSHORT_DELAY );
\r
159 /*-----------------------------------------------------------*/
\r
161 static void prvSetupLCD( void )
\r
163 /* Setup the PMP. */
\r
168 vTaskDelay( lcdSHORT_DELAY );
\r
170 /* Set the default function. */
\r
171 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
172 vTaskDelay( lcdSHORT_DELAY );
\r
174 /* Set the display control. */
\r
175 PMDIN1 = lcdDISPLAY_CONTROL;
\r
176 vTaskDelay( lcdSHORT_DELAY );
\r
178 /* Clear the display. */
\r
179 PMDIN1 = lcdCLEAR_DISPLAY;
\r
180 vTaskDelay( lcdSHORT_DELAY );
\r
182 /* Set the entry mode. */
\r
183 PMDIN1 = lcdENTRY_MODE;
\r
184 vTaskDelay( lcdSHORT_DELAY );
\r
186 /*-----------------------------------------------------------*/
\r
188 static void vLCDTask( void *pvParameters )
\r
190 xLCDMessage xMessage;
\r
191 unsigned portSHORT usRow = 0;
\r
193 /* Initialise the hardware. This uses delays so must not be called prior
\r
194 to the scheduler being started. */
\r
197 /* Welcome message. */
\r
198 prvLCDPutString( "www.FreeRTOS.org" );
\r
202 /* Wait for a message to arrive that requires displaying. */
\r
203 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
205 /* Clear the current display value. */
\r
208 /* Switch rows each time so we can see that the display is still being
\r
210 prvLCDGotoRow( usRow & 0x01 );
\r
212 prvLCDPutString( xMessage.pcMessage );
\r
214 /* Delay the requested amount of time to ensure the text just written
\r
215 to the LCD is not overwritten. */
\r
216 vTaskDelay( xMessage.xMinDisplayTime );
\r