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