2 FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the 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.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 /* peripheral library include */
\r
55 /* Scheduler includes. */
\r
56 #include "FreeRTOS.h"
\r
60 /* Demo includes. */
\r
64 * The LCD is written to by more than one task so is controlled by this
\r
65 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
66 * access the LCD directly. Other tasks wanting to display a message send
\r
67 * the message to the gatekeeper.
\r
69 static void vLCDTask( void *pvParameters );
\r
72 * Setup the peripherals required to communicate with the LCD.
\r
74 static void prvSetupLCD( void );
\r
77 * Move to the first (0) or second (1) row of the LCD.
\r
79 static void prvLCDGotoRow( unsigned portSHORT usRow );
\r
82 * Write a string of text to the LCD.
\r
84 static void prvLCDPutString( portCHAR *pcString );
\r
89 static void prvLCDClear( void );
\r
91 /*-----------------------------------------------------------*/
\r
93 /* Brief delay to permit the LCD to catch up with commands. */
\r
94 #define lcdVERY_SHORT_DELAY ( 1 )
\r
95 #define lcdSHORT_DELAY ( 4 / portTICK_RATE_MS )
\r
96 #define lcdLONG_DELAY ( 15 / portTICK_RATE_MS )
\r
98 /* LCD specific definitions. */
\r
99 #define LCD_CLEAR_DISPLAY_CMD 0x01
\r
100 #define LCD_CURSOR_HOME_CMD 0x02
\r
101 #define LCD_ENTRY_MODE_CMD 0x04
\r
102 #define LCD_ENTRY_MODE_INCREASE 0x02
\r
103 #define LCD_DISPLAY_CTRL_CMD 0x08
\r
104 #define LCD_DISPLAY_CTRL_DISPLAY_ON 0x04
\r
105 #define LCD_FUNCTION_SET_CMD 0x20
\r
106 #define LCD_FUNCTION_SET_8_BITS 0x10
\r
107 #define LCD_FUNCTION_SET_2_LINES 0x08
\r
108 #define LCD_FUNCTION_SET_LRG_FONT 0x04
\r
109 #define LCD_NEW_LINE 0xC0
\r
110 #define LCD_COMMAND_ADDRESS 0x00
\r
111 #define LCD_DATA_ADDRESS 0x01
\r
113 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
114 #define lcdQUEUE_SIZE 3
\r
116 /*-----------------------------------------------------------*/
\r
118 /* The queue used to send messages to the LCD task. */
\r
119 xQueueHandle xLCDQueue;
\r
121 /* LCD access functions. */
\r
122 static void prvLCDCommand( portCHAR cCommand );
\r
123 static void prvLCDData( portCHAR cChar );
\r
125 /*-----------------------------------------------------------*/
\r
127 xQueueHandle xStartLCDTask( void )
\r
129 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
130 are received via this queue. */
\r
131 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
\r
133 /* Start the task that will write to the LCD. The LCD hardware is
\r
134 initialised from within the task itself so delays can be used. */
\r
135 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
139 /*-----------------------------------------------------------*/
\r
141 static void prvLCDGotoRow( unsigned portSHORT usRow )
\r
145 prvLCDCommand( LCD_CURSOR_HOME_CMD );
\r
149 prvLCDCommand( LCD_NEW_LINE );
\r
152 /*-----------------------------------------------------------*/
\r
154 static void prvLCDCommand( portCHAR cCommand )
\r
156 PMPSetAddress( LCD_COMMAND_ADDRESS );
\r
157 PMPMasterWrite( cCommand );
\r
158 vTaskDelay( lcdSHORT_DELAY );
\r
160 /*-----------------------------------------------------------*/
\r
162 static void prvLCDData( portCHAR cChar )
\r
164 PMPSetAddress( LCD_DATA_ADDRESS );
\r
165 PMPMasterWrite( cChar );
\r
166 vTaskDelay( lcdVERY_SHORT_DELAY );
\r
168 /*-----------------------------------------------------------*/
\r
170 static void prvLCDPutString( portCHAR *pcString )
\r
172 /* Write out each character with appropriate delay between each. */
\r
175 prvLCDData(*pcString);
\r
177 vTaskDelay(lcdSHORT_DELAY);
\r
180 /*-----------------------------------------------------------*/
\r
182 static void prvLCDClear(void)
\r
184 prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
\r
186 /*-----------------------------------------------------------*/
\r
188 static void prvSetupLCD(void)
\r
190 /* Wait for proper power up. */
\r
191 vTaskDelay( lcdLONG_DELAY );
\r
193 /* Open the PMP port */
\r
194 mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
\r
195 PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
\r
196 PMP_WRITE_POL_HI | PMP_READ_POL_HI),
\r
197 (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
\r
201 /* Wait for the LCD to power up correctly. */
\r
202 vTaskDelay( lcdLONG_DELAY );
\r
203 vTaskDelay( lcdLONG_DELAY );
\r
204 vTaskDelay( lcdLONG_DELAY );
\r
206 /* Set up the LCD function. */
\r
207 prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
\r
209 /* Turn the display on. */
\r
210 prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
\r
212 /* Clear the display. */
\r
213 prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
\r
214 vTaskDelay( lcdLONG_DELAY );
\r
216 /* Increase the cursor. */
\r
217 prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
\r
218 vTaskDelay( lcdLONG_DELAY );
\r
219 vTaskDelay( lcdLONG_DELAY );
\r
220 vTaskDelay( lcdLONG_DELAY );
\r
222 /*-----------------------------------------------------------*/
\r
224 static void vLCDTask(void *pvParameters)
\r
226 xLCDMessage xMessage;
\r
227 unsigned portSHORT usRow = 0;
\r
229 /* Initialise the hardware. This uses delays so must not be called prior
\r
230 to the scheduler being started. */
\r
233 /* Welcome message. */
\r
234 prvLCDPutString( "www.FreeRTOS.org" );
\r
238 /* Wait for a message to arrive that requires displaying. */
\r
239 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
241 /* Clear the current display value. */
\r
244 /* Switch rows each time so we can see that the display is still being
\r
246 prvLCDGotoRow( usRow & 0x01 );
\r
248 prvLCDPutString( xMessage.pcMessage );
\r
250 /* Delay the requested amount of time to ensure the text just written
\r
251 to the LCD is not overwritten. */
\r
252 vTaskDelay( xMessage.xMinDisplayTime );
\r