2 FreeRTOS V7.1.1 - Copyright (C) 2012 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 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
67 /* Scheduler includes. */
\r
68 #include "FreeRTOS.h"
\r
72 /* Demo includes. */
\r
76 * The LCD is written to by more than one task so is controlled by this
\r
77 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
78 * access the LCD directly. Other tasks wanting to display a message send
\r
79 * the message to the gatekeeper.
\r
81 static void vLCDTask( void *pvParameters );
\r
84 * Setup the peripherals required to communicate with the LCD.
\r
86 static void prvSetupLCD( void );
\r
89 * Move to the first (0) or second (1) row of the LCD.
\r
91 static void prvLCDGotoRow( unsigned portSHORT usRow );
\r
94 * Write a string of text to the LCD.
\r
96 static void prvLCDPutString( portCHAR *pcString );
\r
101 static void prvLCDClear( void );
\r
103 /*-----------------------------------------------------------*/
\r
105 /* Brief delay to permit the LCD to catch up with commands. */
\r
106 #define lcdSHORT_DELAY 3
\r
108 /* SFR that seems to be missing from the standard header files. */
\r
109 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
111 /* LCD commands. */
\r
112 #define lcdDEFAULT_FUNCTION 0x3c
\r
113 #define lcdDISPLAY_CONTROL 0x0c
\r
114 #define lcdCLEAR_DISPLAY 0x01
\r
115 #define lcdENTRY_MODE 0x06
\r
117 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
118 #define lcdQUEUE_SIZE 3
\r
119 /*-----------------------------------------------------------*/
\r
121 /* The queue used to send messages to the LCD task. */
\r
122 xQueueHandle xLCDQueue;
\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
154 vTaskDelay( lcdSHORT_DELAY );
\r
156 /*-----------------------------------------------------------*/
\r
158 static void prvLCDPutString( portCHAR *pcString )
\r
160 /* Write out each character with appropriate delay between each. */
\r
164 PMDIN1 = *pcString;
\r
166 vTaskDelay( lcdSHORT_DELAY );
\r
169 /*-----------------------------------------------------------*/
\r
171 static void prvLCDClear( void )
\r
173 /* Clear the display. */
\r
175 PMDIN1 = lcdCLEAR_DISPLAY;
\r
176 vTaskDelay( lcdSHORT_DELAY );
\r
178 /*-----------------------------------------------------------*/
\r
180 static void prvSetupLCD( void )
\r
182 /* Setup the PMP. */
\r
187 vTaskDelay( lcdSHORT_DELAY );
\r
189 /* Set the default function. */
\r
190 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
191 vTaskDelay( lcdSHORT_DELAY );
\r
193 /* Set the display control. */
\r
194 PMDIN1 = lcdDISPLAY_CONTROL;
\r
195 vTaskDelay( lcdSHORT_DELAY );
\r
197 /* Clear the display. */
\r
198 PMDIN1 = lcdCLEAR_DISPLAY;
\r
199 vTaskDelay( lcdSHORT_DELAY );
\r
201 /* Set the entry mode. */
\r
202 PMDIN1 = lcdENTRY_MODE;
\r
203 vTaskDelay( lcdSHORT_DELAY );
\r
205 /*-----------------------------------------------------------*/
\r
207 static void vLCDTask( void *pvParameters )
\r
209 xLCDMessage xMessage;
\r
210 unsigned portSHORT usRow = 0;
\r
212 /* Initialise the hardware. This uses delays so must not be called prior
\r
213 to the scheduler being started. */
\r
216 /* Welcome message. */
\r
217 prvLCDPutString( "www.FreeRTOS.org" );
\r
221 /* Wait for a message to arrive that requires displaying. */
\r
222 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
224 /* Clear the current display value. */
\r
227 /* Switch rows each time so we can see that the display is still being
\r
229 prvLCDGotoRow( usRow & 0x01 );
\r
231 prvLCDPutString( xMessage.pcMessage );
\r
233 /* Delay the requested amount of time to ensure the text just written
\r
234 to the LCD is not overwritten. */
\r
235 vTaskDelay( xMessage.xMinDisplayTime );
\r