2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
70 /* Scheduler includes. */
79 * The LCD is written to by more than one task so is controlled by this
80 * 'gatekeeper' task. This is the only task that is actually permitted to
81 * access the LCD directly. Other tasks wanting to display a message send
82 * the message to the gatekeeper.
84 static void vLCDTask( void *pvParameters );
87 * Setup the peripherals required to communicate with the LCD.
89 static void prvSetupLCD( void );
92 * Move to the first (0) or second (1) row of the LCD.
94 static void prvLCDGotoRow( unsigned short usRow );
97 * Write a string of text to the LCD.
99 static void prvLCDPutString( char *pcString );
104 static void prvLCDClear( void );
106 /*-----------------------------------------------------------*/
108 /* Brief delay to permit the LCD to catch up with commands. */
109 #define lcdSHORT_DELAY 3
111 /* SFR that seems to be missing from the standard header files. */
112 #define PMAEN *( ( unsigned short * ) 0x60c )
115 #define lcdDEFAULT_FUNCTION 0x3c
116 #define lcdDISPLAY_CONTROL 0x0c
117 #define lcdCLEAR_DISPLAY 0x01
118 #define lcdENTRY_MODE 0x06
120 /* The length of the queue used to send messages to the LCD gatekeeper task. */
121 #define lcdQUEUE_SIZE 3
122 /*-----------------------------------------------------------*/
124 /* The queue used to send messages to the LCD task. */
125 QueueHandle_t xLCDQueue;
128 /*-----------------------------------------------------------*/
130 QueueHandle_t xStartLCDTask( void )
132 /* Create the queue used by the LCD task. Messages for display on the LCD
133 are received via this queue. */
134 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
136 /* Start the task that will write to the LCD. The LCD hardware is
137 initialised from within the task itself so delays can be used. */
138 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
142 /*-----------------------------------------------------------*/
144 static void prvLCDGotoRow( unsigned short usRow )
157 vTaskDelay( lcdSHORT_DELAY );
159 /*-----------------------------------------------------------*/
161 static void prvLCDPutString( char *pcString )
163 /* Write out each character with appropriate delay between each. */
169 vTaskDelay( lcdSHORT_DELAY );
172 /*-----------------------------------------------------------*/
174 static void prvLCDClear( void )
176 /* Clear the display. */
178 PMDIN1 = lcdCLEAR_DISPLAY;
179 vTaskDelay( lcdSHORT_DELAY );
181 /*-----------------------------------------------------------*/
183 static void prvSetupLCD( void )
190 vTaskDelay( lcdSHORT_DELAY );
192 /* Set the default function. */
193 PMDIN1 = lcdDEFAULT_FUNCTION;
194 vTaskDelay( lcdSHORT_DELAY );
196 /* Set the display control. */
197 PMDIN1 = lcdDISPLAY_CONTROL;
198 vTaskDelay( lcdSHORT_DELAY );
200 /* Clear the display. */
201 PMDIN1 = lcdCLEAR_DISPLAY;
202 vTaskDelay( lcdSHORT_DELAY );
204 /* Set the entry mode. */
205 PMDIN1 = lcdENTRY_MODE;
206 vTaskDelay( lcdSHORT_DELAY );
208 /*-----------------------------------------------------------*/
210 static void vLCDTask( void *pvParameters )
212 xLCDMessage xMessage;
213 unsigned short usRow = 0;
215 /* Remove compiler warnigns. */
216 ( void ) pvParameters;
218 /* Initialise the hardware. This uses delays so must not be called prior
219 to the scheduler being started. */
222 /* Welcome message. */
223 prvLCDPutString( "www.FreeRTOS.org" );
227 /* Wait for a message to arrive that requires displaying. */
228 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
230 /* Clear the current display value. */
233 /* Switch rows each time so we can see that the display is still being
235 prvLCDGotoRow( usRow & 0x01 );
237 prvLCDPutString( xMessage.pcMessage );
239 /* Delay the requested amount of time to ensure the text just written
240 to the LCD is not overwritten. */
241 vTaskDelay( xMessage.xMinDisplayTime );