2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\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 modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or 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 /* peripheral library include */
\r
57 /* Scheduler includes. */
\r
58 #include "FreeRTOS.h"
\r
62 /* Demo includes. */
\r
66 * The LCD is written to by more than one task so is controlled by this
\r
67 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
68 * access the LCD directly. Other tasks wanting to display a message send
\r
69 * the message to the gatekeeper.
\r
71 static void vLCDTask( void *pvParameters );
\r
74 * Setup the peripherals required to communicate with the LCD.
\r
76 static void prvSetupLCD( void );
\r
79 * Move to the first (0) or second (1) row of the LCD.
\r
81 static void prvLCDGotoRow( unsigned short usRow );
\r
84 * Write a string of text to the LCD.
\r
86 static void prvLCDPutString( char *pcString );
\r
91 static void prvLCDClear( void );
\r
93 /*-----------------------------------------------------------*/
\r
95 /* Brief delay to permit the LCD to catch up with commands. */
\r
96 #define lcdVERY_SHORT_DELAY ( 1 )
\r
97 #define lcdSHORT_DELAY ( 4 / portTICK_RATE_MS )
\r
98 #define lcdLONG_DELAY ( 15 / portTICK_RATE_MS )
\r
100 /* LCD specific definitions. */
\r
101 #define LCD_CLEAR_DISPLAY_CMD 0x01
\r
102 #define LCD_CURSOR_HOME_CMD 0x02
\r
103 #define LCD_ENTRY_MODE_CMD 0x04
\r
104 #define LCD_ENTRY_MODE_INCREASE 0x02
\r
105 #define LCD_DISPLAY_CTRL_CMD 0x08
\r
106 #define LCD_DISPLAY_CTRL_DISPLAY_ON 0x04
\r
107 #define LCD_FUNCTION_SET_CMD 0x20
\r
108 #define LCD_FUNCTION_SET_8_BITS 0x10
\r
109 #define LCD_FUNCTION_SET_2_LINES 0x08
\r
110 #define LCD_FUNCTION_SET_LRG_FONT 0x04
\r
111 #define LCD_NEW_LINE 0xC0
\r
112 #define LCD_COMMAND_ADDRESS 0x00
\r
113 #define LCD_DATA_ADDRESS 0x01
\r
115 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
116 #define lcdQUEUE_SIZE 3
\r
118 /*-----------------------------------------------------------*/
\r
120 /* The queue used to send messages to the LCD task. */
\r
121 xQueueHandle xLCDQueue;
\r
123 /* LCD access functions. */
\r
124 static void prvLCDCommand( char cCommand );
\r
125 static void prvLCDData( char cChar );
\r
127 /*-----------------------------------------------------------*/
\r
129 xQueueHandle xStartLCDTask( void )
\r
131 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
132 are received via this queue. */
\r
133 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
\r
135 /* Start the task that will write to the LCD. The LCD hardware is
\r
136 initialised from within the task itself so delays can be used. */
\r
137 xTaskCreate( vLCDTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
141 /*-----------------------------------------------------------*/
\r
143 static void prvLCDGotoRow( unsigned short usRow )
\r
147 prvLCDCommand( LCD_CURSOR_HOME_CMD );
\r
151 prvLCDCommand( LCD_NEW_LINE );
\r
154 /*-----------------------------------------------------------*/
\r
156 static void prvLCDCommand( char cCommand )
\r
158 PMPSetAddress( LCD_COMMAND_ADDRESS );
\r
159 PMPMasterWrite( cCommand );
\r
160 vTaskDelay( lcdSHORT_DELAY );
\r
162 /*-----------------------------------------------------------*/
\r
164 static void prvLCDData( char cChar )
\r
166 PMPSetAddress( LCD_DATA_ADDRESS );
\r
167 PMPMasterWrite( cChar );
\r
168 vTaskDelay( lcdVERY_SHORT_DELAY );
\r
170 /*-----------------------------------------------------------*/
\r
172 static void prvLCDPutString( char *pcString )
\r
174 /* Write out each character with appropriate delay between each. */
\r
177 prvLCDData(*pcString);
\r
179 vTaskDelay(lcdSHORT_DELAY);
\r
182 /*-----------------------------------------------------------*/
\r
184 static void prvLCDClear(void)
\r
186 prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
\r
188 /*-----------------------------------------------------------*/
\r
190 static void prvSetupLCD(void)
\r
192 /* Wait for proper power up. */
\r
193 vTaskDelay( lcdLONG_DELAY );
\r
195 /* Open the PMP port */
\r
196 mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
\r
197 PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
\r
198 PMP_WRITE_POL_HI | PMP_READ_POL_HI),
\r
199 (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
\r
203 /* Wait for the LCD to power up correctly. */
\r
204 vTaskDelay( lcdLONG_DELAY );
\r
205 vTaskDelay( lcdLONG_DELAY );
\r
206 vTaskDelay( lcdLONG_DELAY );
\r
208 /* Set up the LCD function. */
\r
209 prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
\r
211 /* Turn the display on. */
\r
212 prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
\r
214 /* Clear the display. */
\r
215 prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
\r
216 vTaskDelay( lcdLONG_DELAY );
\r
218 /* Increase the cursor. */
\r
219 prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
\r
220 vTaskDelay( lcdLONG_DELAY );
\r
221 vTaskDelay( lcdLONG_DELAY );
\r
222 vTaskDelay( lcdLONG_DELAY );
\r
224 /*-----------------------------------------------------------*/
\r
226 static void vLCDTask(void *pvParameters)
\r
228 xLCDMessage xMessage;
\r
229 unsigned short usRow = 0;
\r
231 /* Initialise the hardware. This uses delays so must not be called prior
\r
232 to the scheduler being started. */
\r
235 /* Welcome message. */
\r
236 prvLCDPutString( "www.FreeRTOS.org" );
\r
240 /* Wait for a message to arrive that requires displaying. */
\r
241 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
243 /* Clear the current display value. */
\r
246 /* Switch rows each time so we can see that the display is still being
\r
248 prvLCDGotoRow( usRow & 0x01 );
\r
250 prvLCDPutString( xMessage.pcMessage );
\r
252 /* Delay the requested amount of time to ensure the text just written
\r
253 to the LCD is not overwritten. */
\r
254 vTaskDelay( xMessage.xMinDisplayTime );
\r