2 FreeRTOS V5.4.2 - 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 /* peripheral library include */
\r
51 /* Scheduler includes. */
\r
52 #include "FreeRTOS.h"
\r
56 /* Demo includes. */
\r
60 * The LCD is written to by more than one task so is controlled by this
\r
61 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
62 * access the LCD directly. Other tasks wanting to display a message send
\r
63 * the message to the gatekeeper.
\r
65 static void vLCDTask( void *pvParameters );
\r
68 * Setup the peripherals required to communicate with the LCD.
\r
70 static void prvSetupLCD( void );
\r
73 * Move to the first (0) or second (1) row of the LCD.
\r
75 static void prvLCDGotoRow( unsigned portSHORT usRow );
\r
78 * Write a string of text to the LCD.
\r
80 static void prvLCDPutString( portCHAR *pcString );
\r
85 static void prvLCDClear( void );
\r
87 /*-----------------------------------------------------------*/
\r
89 /* Brief delay to permit the LCD to catch up with commands. */
\r
90 #define lcdVERY_SHORT_DELAY ( 1 )
\r
91 #define lcdSHORT_DELAY ( 4 / portTICK_RATE_MS )
\r
92 #define lcdLONG_DELAY ( 15 / portTICK_RATE_MS )
\r
94 /* LCD specific definitions. */
\r
95 #define LCD_CLEAR_DISPLAY_CMD 0x01
\r
96 #define LCD_CURSOR_HOME_CMD 0x02
\r
97 #define LCD_ENTRY_MODE_CMD 0x04
\r
98 #define LCD_ENTRY_MODE_INCREASE 0x02
\r
99 #define LCD_DISPLAY_CTRL_CMD 0x08
\r
100 #define LCD_DISPLAY_CTRL_DISPLAY_ON 0x04
\r
101 #define LCD_FUNCTION_SET_CMD 0x20
\r
102 #define LCD_FUNCTION_SET_8_BITS 0x10
\r
103 #define LCD_FUNCTION_SET_2_LINES 0x08
\r
104 #define LCD_FUNCTION_SET_LRG_FONT 0x04
\r
105 #define LCD_NEW_LINE 0xC0
\r
106 #define LCD_COMMAND_ADDRESS 0x00
\r
107 #define LCD_DATA_ADDRESS 0x01
\r
109 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
110 #define lcdQUEUE_SIZE 3
\r
112 /*-----------------------------------------------------------*/
\r
114 /* The queue used to send messages to the LCD task. */
\r
115 xQueueHandle xLCDQueue;
\r
117 /* LCD access functions. */
\r
118 static void prvLCDCommand( portCHAR cCommand );
\r
119 static void prvLCDData( portCHAR cChar );
\r
121 /*-----------------------------------------------------------*/
\r
123 xQueueHandle xStartLCDTask( void )
\r
125 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
126 are received via this queue. */
\r
127 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
\r
129 /* Start the task that will write to the LCD. The LCD hardware is
\r
130 initialised from within the task itself so delays can be used. */
\r
131 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
135 /*-----------------------------------------------------------*/
\r
137 static void prvLCDGotoRow( unsigned portSHORT usRow )
\r
141 prvLCDCommand( LCD_CURSOR_HOME_CMD );
\r
145 prvLCDCommand( LCD_NEW_LINE );
\r
148 /*-----------------------------------------------------------*/
\r
150 static void prvLCDCommand( portCHAR cCommand )
\r
152 PMPSetAddress( LCD_COMMAND_ADDRESS );
\r
153 PMPMasterWrite( cCommand );
\r
154 vTaskDelay( lcdSHORT_DELAY );
\r
156 /*-----------------------------------------------------------*/
\r
158 static void prvLCDData( portCHAR cChar )
\r
160 PMPSetAddress( LCD_DATA_ADDRESS );
\r
161 PMPMasterWrite( cChar );
\r
162 vTaskDelay( lcdVERY_SHORT_DELAY );
\r
164 /*-----------------------------------------------------------*/
\r
166 static void prvLCDPutString( portCHAR *pcString )
\r
168 /* Write out each character with appropriate delay between each. */
\r
171 prvLCDData(*pcString);
\r
173 vTaskDelay(lcdSHORT_DELAY);
\r
176 /*-----------------------------------------------------------*/
\r
178 static void prvLCDClear(void)
\r
180 prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
\r
182 /*-----------------------------------------------------------*/
\r
184 static void prvSetupLCD(void)
\r
186 /* Wait for proper power up. */
\r
187 vTaskDelay( lcdLONG_DELAY );
\r
189 /* Open the PMP port */
\r
190 mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
\r
191 PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
\r
192 PMP_WRITE_POL_HI | PMP_READ_POL_HI),
\r
193 (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
\r
197 /* Wait for the LCD to power up correctly. */
\r
198 vTaskDelay( lcdLONG_DELAY );
\r
199 vTaskDelay( lcdLONG_DELAY );
\r
200 vTaskDelay( lcdLONG_DELAY );
\r
202 /* Set up the LCD function. */
\r
203 prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
\r
205 /* Turn the display on. */
\r
206 prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
\r
208 /* Clear the display. */
\r
209 prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
\r
210 vTaskDelay( lcdLONG_DELAY );
\r
212 /* Increase the cursor. */
\r
213 prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
\r
214 vTaskDelay( lcdLONG_DELAY );
\r
215 vTaskDelay( lcdLONG_DELAY );
\r
216 vTaskDelay( lcdLONG_DELAY );
\r
218 /*-----------------------------------------------------------*/
\r
220 static void vLCDTask(void *pvParameters)
\r
222 xLCDMessage xMessage;
\r
223 unsigned portSHORT usRow = 0;
\r
225 /* Initialise the hardware. This uses delays so must not be called prior
\r
226 to the scheduler being started. */
\r
229 /* Welcome message. */
\r
230 prvLCDPutString( "www.FreeRTOS.org" );
\r
234 /* Wait for a message to arrive that requires displaying. */
\r
235 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
237 /* Clear the current display value. */
\r
240 /* Switch rows each time so we can see that the display is still being
\r
242 prvLCDGotoRow( usRow & 0x01 );
\r
244 prvLCDPutString( xMessage.pcMessage );
\r
246 /* Delay the requested amount of time to ensure the text just written
\r
247 to the LCD is not overwritten. */
\r
248 vTaskDelay( xMessage.xMinDisplayTime );
\r