2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
69 /* peripheral library include */
\r
72 /* Scheduler includes. */
\r
73 #include "FreeRTOS.h"
\r
77 /* Demo includes. */
\r
81 * The LCD is written to by more than one task so is controlled by this
\r
82 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
83 * access the LCD directly. Other tasks wanting to display a message send
\r
84 * the message to the gatekeeper.
\r
86 static void vLCDTask( void *pvParameters );
\r
89 * Setup the peripherals required to communicate with the LCD.
\r
91 static void prvSetupLCD( void );
\r
94 * Move to the first (0) or second (1) row of the LCD.
\r
96 static void prvLCDGotoRow( unsigned short usRow );
\r
99 * Write a string of text to the LCD.
\r
101 static void prvLCDPutString( char *pcString );
\r
106 static void prvLCDClear( void );
\r
108 /*-----------------------------------------------------------*/
\r
110 /* Brief delay to permit the LCD to catch up with commands. */
\r
111 #define lcdVERY_SHORT_DELAY ( 1 )
\r
112 #define lcdSHORT_DELAY ( 4 / portTICK_RATE_MS )
\r
113 #define lcdLONG_DELAY ( 15 / portTICK_RATE_MS )
\r
115 /* LCD specific definitions. */
\r
116 #define LCD_CLEAR_DISPLAY_CMD 0x01
\r
117 #define LCD_CURSOR_HOME_CMD 0x02
\r
118 #define LCD_ENTRY_MODE_CMD 0x04
\r
119 #define LCD_ENTRY_MODE_INCREASE 0x02
\r
120 #define LCD_DISPLAY_CTRL_CMD 0x08
\r
121 #define LCD_DISPLAY_CTRL_DISPLAY_ON 0x04
\r
122 #define LCD_FUNCTION_SET_CMD 0x20
\r
123 #define LCD_FUNCTION_SET_8_BITS 0x10
\r
124 #define LCD_FUNCTION_SET_2_LINES 0x08
\r
125 #define LCD_FUNCTION_SET_LRG_FONT 0x04
\r
126 #define LCD_NEW_LINE 0xC0
\r
127 #define LCD_COMMAND_ADDRESS 0x00
\r
128 #define LCD_DATA_ADDRESS 0x01
\r
130 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
131 #define lcdQUEUE_SIZE 3
\r
133 /*-----------------------------------------------------------*/
\r
135 /* The queue used to send messages to the LCD task. */
\r
136 xQueueHandle xLCDQueue;
\r
138 /* LCD access functions. */
\r
139 static void prvLCDCommand( char cCommand );
\r
140 static void prvLCDData( char cChar );
\r
142 /*-----------------------------------------------------------*/
\r
144 xQueueHandle xStartLCDTask( void )
\r
146 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
147 are received via this queue. */
\r
148 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
\r
150 /* Start the task that will write to the LCD. The LCD hardware is
\r
151 initialised from within the task itself so delays can be used. */
\r
152 xTaskCreate( vLCDTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
156 /*-----------------------------------------------------------*/
\r
158 static void prvLCDGotoRow( unsigned short usRow )
\r
162 prvLCDCommand( LCD_CURSOR_HOME_CMD );
\r
166 prvLCDCommand( LCD_NEW_LINE );
\r
169 /*-----------------------------------------------------------*/
\r
171 static void prvLCDCommand( char cCommand )
\r
173 PMPSetAddress( LCD_COMMAND_ADDRESS );
\r
174 PMPMasterWrite( cCommand );
\r
175 vTaskDelay( lcdSHORT_DELAY );
\r
177 /*-----------------------------------------------------------*/
\r
179 static void prvLCDData( char cChar )
\r
181 PMPSetAddress( LCD_DATA_ADDRESS );
\r
182 PMPMasterWrite( cChar );
\r
183 vTaskDelay( lcdVERY_SHORT_DELAY );
\r
185 /*-----------------------------------------------------------*/
\r
187 static void prvLCDPutString( char *pcString )
\r
189 /* Write out each character with appropriate delay between each. */
\r
192 prvLCDData(*pcString);
\r
194 vTaskDelay(lcdSHORT_DELAY);
\r
197 /*-----------------------------------------------------------*/
\r
199 static void prvLCDClear(void)
\r
201 prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
\r
203 /*-----------------------------------------------------------*/
\r
205 static void prvSetupLCD(void)
\r
207 /* Wait for proper power up. */
\r
208 vTaskDelay( lcdLONG_DELAY );
\r
210 /* Open the PMP port */
\r
211 mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
\r
212 PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
\r
213 PMP_WRITE_POL_HI | PMP_READ_POL_HI),
\r
214 (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
\r
218 /* Wait for the LCD to power up correctly. */
\r
219 vTaskDelay( lcdLONG_DELAY );
\r
220 vTaskDelay( lcdLONG_DELAY );
\r
221 vTaskDelay( lcdLONG_DELAY );
\r
223 /* Set up the LCD function. */
\r
224 prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
\r
226 /* Turn the display on. */
\r
227 prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
\r
229 /* Clear the display. */
\r
230 prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
\r
231 vTaskDelay( lcdLONG_DELAY );
\r
233 /* Increase the cursor. */
\r
234 prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
\r
235 vTaskDelay( lcdLONG_DELAY );
\r
236 vTaskDelay( lcdLONG_DELAY );
\r
237 vTaskDelay( lcdLONG_DELAY );
\r
239 /*-----------------------------------------------------------*/
\r
241 static void vLCDTask(void *pvParameters)
\r
243 xLCDMessage xMessage;
\r
244 unsigned short usRow = 0;
\r
246 /* Initialise the hardware. This uses delays so must not be called prior
\r
247 to the scheduler being started. */
\r
250 /* Welcome message. */
\r
251 prvLCDPutString( "www.FreeRTOS.org" );
\r
255 /* Wait for a message to arrive that requires displaying. */
\r
256 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
258 /* Clear the current display value. */
\r
261 /* Switch rows each time so we can see that the display is still being
\r
263 prvLCDGotoRow( usRow & 0x01 );
\r
265 prvLCDPutString( xMessage.pcMessage );
\r
267 /* Delay the requested amount of time to ensure the text just written
\r
268 to the LCD is not overwritten. */
\r
269 vTaskDelay( xMessage.xMinDisplayTime );
\r