2 FreeRTOS V8.2.1 - 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 /* peripheral library include */
\r
73 /* Scheduler includes. */
\r
74 #include "FreeRTOS.h"
\r
78 /* Demo includes. */
\r
82 * The LCD is written to by more than one task so is controlled by this
\r
83 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
84 * access the LCD directly. Other tasks wanting to display a message send
\r
85 * the message to the gatekeeper.
\r
87 static void vLCDTask( void *pvParameters );
\r
90 * Setup the peripherals required to communicate with the LCD.
\r
92 static void prvSetupLCD( void );
\r
95 * Move to the first (0) or second (1) row of the LCD.
\r
97 static void prvLCDGotoRow( unsigned short usRow );
\r
100 * Write a string of text to the LCD.
\r
102 static void prvLCDPutString( char *pcString );
\r
107 static void prvLCDClear( void );
\r
109 /*-----------------------------------------------------------*/
\r
111 /* Brief delay to permit the LCD to catch up with commands. */
\r
112 #define lcdVERY_SHORT_DELAY ( 1 )
\r
113 #define lcdSHORT_DELAY ( 8 / portTICK_PERIOD_MS )
\r
114 #define lcdLONG_DELAY ( 15 / portTICK_PERIOD_MS )
\r
116 /* LCD specific definitions. */
\r
117 #define LCD_CLEAR_DISPLAY_CMD 0x01
\r
118 #define LCD_CURSOR_HOME_CMD 0x02
\r
119 #define LCD_ENTRY_MODE_CMD 0x04
\r
120 #define LCD_ENTRY_MODE_INCREASE 0x02
\r
121 #define LCD_DISPLAY_CTRL_CMD 0x08
\r
122 #define LCD_DISPLAY_CTRL_DISPLAY_ON 0x04
\r
123 #define LCD_FUNCTION_SET_CMD 0x20
\r
124 #define LCD_FUNCTION_SET_8_BITS 0x10
\r
125 #define LCD_FUNCTION_SET_2_LINES 0x08
\r
126 #define LCD_FUNCTION_SET_LRG_FONT 0x04
\r
127 #define LCD_NEW_LINE 0xC0
\r
128 #define LCD_COMMAND_ADDRESS 0x00
\r
129 #define LCD_DATA_ADDRESS 0x01
\r
131 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
132 #define lcdQUEUE_SIZE 3
\r
134 /*-----------------------------------------------------------*/
\r
136 /* The queue used to send messages to the LCD task. */
\r
137 QueueHandle_t xLCDQueue;
\r
139 /* LCD access functions. */
\r
140 static void prvLCDCommand( char cCommand );
\r
141 static void prvLCDData( char cChar );
\r
143 /*-----------------------------------------------------------*/
\r
145 QueueHandle_t xStartLCDTask( void )
\r
147 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
148 are received via this queue. */
\r
149 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
\r
151 /* Start the task that will write to the LCD. The LCD hardware is
\r
152 initialised from within the task itself so delays can be used. */
\r
153 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
157 /*-----------------------------------------------------------*/
\r
159 static void prvLCDGotoRow( unsigned short usRow )
\r
163 prvLCDCommand( LCD_CURSOR_HOME_CMD );
\r
167 prvLCDCommand( LCD_NEW_LINE );
\r
170 /*-----------------------------------------------------------*/
\r
172 static void prvLCDCommand( char cCommand )
\r
174 PMPSetAddress( LCD_COMMAND_ADDRESS );
\r
175 PMPMasterWrite( cCommand );
\r
176 vTaskDelay( lcdSHORT_DELAY );
\r
178 /*-----------------------------------------------------------*/
\r
180 static void prvLCDData( char cChar )
\r
182 PMPSetAddress( LCD_DATA_ADDRESS );
\r
183 PMPMasterWrite( cChar );
\r
184 vTaskDelay( lcdVERY_SHORT_DELAY );
\r
186 /*-----------------------------------------------------------*/
\r
188 static void prvLCDPutString( char *pcString )
\r
190 /* Write out each character with appropriate delay between each. */
\r
193 prvLCDData(*pcString);
\r
195 vTaskDelay(lcdSHORT_DELAY);
\r
198 /*-----------------------------------------------------------*/
\r
200 static void prvLCDClear(void)
\r
202 prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
\r
204 /*-----------------------------------------------------------*/
\r
206 static void prvSetupLCD(void)
\r
208 /* Wait for proper power up. */
\r
209 vTaskDelay( lcdLONG_DELAY );
\r
211 /* Open the PMP port */
\r
212 mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
\r
213 PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
\r
214 PMP_WRITE_POL_HI | PMP_READ_POL_HI),
\r
215 (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
\r
219 /* Wait for the LCD to power up correctly. */
\r
220 vTaskDelay( lcdLONG_DELAY );
\r
221 vTaskDelay( lcdLONG_DELAY );
\r
222 vTaskDelay( lcdLONG_DELAY );
\r
224 /* Set up the LCD function. */
\r
225 prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
\r
227 /* Turn the display on. */
\r
228 prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
\r
230 /* Clear the display. */
\r
231 prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
\r
232 vTaskDelay( lcdLONG_DELAY );
\r
234 /* Increase the cursor. */
\r
235 prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
\r
236 vTaskDelay( lcdLONG_DELAY );
\r
237 vTaskDelay( lcdLONG_DELAY );
\r
238 vTaskDelay( lcdLONG_DELAY );
\r
240 /*-----------------------------------------------------------*/
\r
242 static void vLCDTask(void *pvParameters)
\r
244 xLCDMessage xMessage;
\r
245 unsigned short usRow = 0;
\r
247 /* Initialise the hardware. This uses delays so must not be called prior
\r
248 to the scheduler being started. */
\r
251 /* Welcome message. */
\r
252 prvLCDPutString( "www.FreeRTOS.org" );
\r
256 /* Wait for a message to arrive that requires displaying. */
\r
257 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
259 /* Clear the current display value. */
\r
262 /* Switch rows each time so we can see that the display is still being
\r
264 prvLCDGotoRow( usRow & 0x01 );
\r
266 prvLCDPutString( xMessage.pcMessage );
\r
268 /* Delay the requested amount of time to ensure the text just written
\r
269 to the LCD is not overwritten. */
\r
270 vTaskDelay( xMessage.xMinDisplayTime );
\r