2 FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Scheduler includes. */
\r
67 #include "FreeRTOS.h"
\r
71 /* Demo includes. */
\r
75 * The LCD is written to by more than one task so is controlled by this
\r
76 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
77 * access the LCD directly. Other tasks wanting to display a message send
\r
78 * the message to the gatekeeper.
\r
80 static void vLCDTask( void *pvParameters );
\r
83 * Setup the peripherals required to communicate with the LCD.
\r
85 static void prvSetupLCD( void );
\r
88 * Move to the first (0) or second (1) row of the LCD.
\r
90 static void prvLCDGotoRow( unsigned short usRow );
\r
93 * Write a string of text to the LCD.
\r
95 static void prvLCDPutString( char *pcString );
\r
100 static void prvLCDClear( void );
\r
102 /*-----------------------------------------------------------*/
\r
104 /* Brief delay to permit the LCD to catch up with commands. */
\r
105 #define lcdSHORT_DELAY 3
\r
107 /* SFR that seems to be missing from the standard header files. */
\r
108 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
110 /* LCD commands. */
\r
111 #define lcdDEFAULT_FUNCTION 0x3c
\r
112 #define lcdDISPLAY_CONTROL 0x0c
\r
113 #define lcdCLEAR_DISPLAY 0x01
\r
114 #define lcdENTRY_MODE 0x06
\r
116 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
117 #define lcdQUEUE_SIZE 3
\r
118 /*-----------------------------------------------------------*/
\r
120 /* The queue used to send messages to the LCD task. */
\r
121 QueueHandle_t xLCDQueue;
\r
124 /*-----------------------------------------------------------*/
\r
126 QueueHandle_t xStartLCDTask( void )
\r
128 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
129 are received via this queue. */
\r
130 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
132 /* Start the task that will write to the LCD. The LCD hardware is
\r
133 initialised from within the task itself so delays can be used. */
\r
134 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
138 /*-----------------------------------------------------------*/
\r
140 static void prvLCDGotoRow( unsigned short usRow )
\r
153 vTaskDelay( lcdSHORT_DELAY );
\r
155 /*-----------------------------------------------------------*/
\r
157 static void prvLCDPutString( char *pcString )
\r
159 /* Write out each character with appropriate delay between each. */
\r
163 PMDIN1 = *pcString;
\r
165 vTaskDelay( lcdSHORT_DELAY );
\r
168 /*-----------------------------------------------------------*/
\r
170 static void prvLCDClear( void )
\r
172 /* Clear the display. */
\r
174 PMDIN1 = lcdCLEAR_DISPLAY;
\r
175 vTaskDelay( lcdSHORT_DELAY );
\r
177 /*-----------------------------------------------------------*/
\r
179 static void prvSetupLCD( void )
\r
181 /* Setup the PMP. */
\r
186 vTaskDelay( lcdSHORT_DELAY );
\r
188 /* Set the default function. */
\r
189 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
190 vTaskDelay( lcdSHORT_DELAY );
\r
192 /* Set the display control. */
\r
193 PMDIN1 = lcdDISPLAY_CONTROL;
\r
194 vTaskDelay( lcdSHORT_DELAY );
\r
196 /* Clear the display. */
\r
197 PMDIN1 = lcdCLEAR_DISPLAY;
\r
198 vTaskDelay( lcdSHORT_DELAY );
\r
200 /* Set the entry mode. */
\r
201 PMDIN1 = lcdENTRY_MODE;
\r
202 vTaskDelay( lcdSHORT_DELAY );
\r
204 /*-----------------------------------------------------------*/
\r
206 static void vLCDTask( void *pvParameters )
\r
208 xLCDMessage xMessage;
\r
209 unsigned short usRow = 0;
\r
211 /* Remove compiler warnigns. */
\r
212 ( void ) pvParameters;
\r
214 /* Initialise the hardware. This uses delays so must not be called prior
\r
215 to the scheduler being started. */
\r
218 /* Welcome message. */
\r
219 prvLCDPutString( "www.FreeRTOS.org" );
\r
223 /* Wait for a message to arrive that requires displaying. */
\r
224 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
226 /* Clear the current display value. */
\r
229 /* Switch rows each time so we can see that the display is still being
\r
231 prvLCDGotoRow( usRow & 0x01 );
\r
233 prvLCDPutString( xMessage.pcMessage );
\r
235 /* Delay the requested amount of time to ensure the text just written
\r
236 to the LCD is not overwritten. */
\r
237 vTaskDelay( xMessage.xMinDisplayTime );
\r