2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /* peripheral library include */
\r
99 /* Scheduler includes. */
\r
100 #include "FreeRTOS.h"
\r
104 /* Demo includes. */
\r
108 * The LCD is written to by more than one task so is controlled by this
\r
109 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
110 * access the LCD directly. Other tasks wanting to display a message send
\r
111 * the message to the gatekeeper.
\r
113 static void vLCDTask( void *pvParameters );
\r
116 * Setup the peripherals required to communicate with the LCD.
\r
118 static void prvSetupLCD( void );
\r
121 * Move to the first (0) or second (1) row of the LCD.
\r
123 static void prvLCDGotoRow( unsigned short usRow );
\r
126 * Write a string of text to the LCD.
\r
128 static void prvLCDPutString( char *pcString );
\r
133 static void prvLCDClear( void );
\r
135 /*-----------------------------------------------------------*/
\r
137 /* Brief delay to permit the LCD to catch up with commands. */
\r
138 #define lcdVERY_SHORT_DELAY ( 1 )
\r
139 #define lcdSHORT_DELAY ( 8 / portTICK_PERIOD_MS )
\r
140 #define lcdLONG_DELAY ( 15 / portTICK_PERIOD_MS )
\r
142 /* LCD specific definitions. */
\r
143 #define LCD_CLEAR_DISPLAY_CMD 0x01
\r
144 #define LCD_CURSOR_HOME_CMD 0x02
\r
145 #define LCD_ENTRY_MODE_CMD 0x04
\r
146 #define LCD_ENTRY_MODE_INCREASE 0x02
\r
147 #define LCD_DISPLAY_CTRL_CMD 0x08
\r
148 #define LCD_DISPLAY_CTRL_DISPLAY_ON 0x04
\r
149 #define LCD_FUNCTION_SET_CMD 0x20
\r
150 #define LCD_FUNCTION_SET_8_BITS 0x10
\r
151 #define LCD_FUNCTION_SET_2_LINES 0x08
\r
152 #define LCD_FUNCTION_SET_LRG_FONT 0x04
\r
153 #define LCD_NEW_LINE 0xC0
\r
154 #define LCD_COMMAND_ADDRESS 0x00
\r
155 #define LCD_DATA_ADDRESS 0x01
\r
157 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
158 #define lcdQUEUE_SIZE 3
\r
160 /*-----------------------------------------------------------*/
\r
162 /* The queue used to send messages to the LCD task. */
\r
163 QueueHandle_t xLCDQueue;
\r
165 /* LCD access functions. */
\r
166 static void prvLCDCommand( char cCommand );
\r
167 static void prvLCDData( char cChar );
\r
169 /*-----------------------------------------------------------*/
\r
171 QueueHandle_t xStartLCDTask( void )
\r
173 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
174 are received via this queue. */
\r
175 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
\r
177 /* Start the task that will write to the LCD. The LCD hardware is
\r
178 initialised from within the task itself so delays can be used. */
\r
179 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
183 /*-----------------------------------------------------------*/
\r
185 static void prvLCDGotoRow( unsigned short usRow )
\r
189 prvLCDCommand( LCD_CURSOR_HOME_CMD );
\r
193 prvLCDCommand( LCD_NEW_LINE );
\r
196 /*-----------------------------------------------------------*/
\r
198 static void prvLCDCommand( char cCommand )
\r
200 PMPSetAddress( LCD_COMMAND_ADDRESS );
\r
201 PMPMasterWrite( cCommand );
\r
202 vTaskDelay( lcdSHORT_DELAY );
\r
204 /*-----------------------------------------------------------*/
\r
206 static void prvLCDData( char cChar )
\r
208 PMPSetAddress( LCD_DATA_ADDRESS );
\r
209 PMPMasterWrite( cChar );
\r
210 vTaskDelay( lcdVERY_SHORT_DELAY );
\r
212 /*-----------------------------------------------------------*/
\r
214 static void prvLCDPutString( char *pcString )
\r
216 /* Write out each character with appropriate delay between each. */
\r
219 prvLCDData(*pcString);
\r
221 vTaskDelay(lcdSHORT_DELAY);
\r
224 /*-----------------------------------------------------------*/
\r
226 static void prvLCDClear(void)
\r
228 prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
\r
230 /*-----------------------------------------------------------*/
\r
232 static void prvSetupLCD(void)
\r
234 /* Wait for proper power up. */
\r
235 vTaskDelay( lcdLONG_DELAY );
\r
237 /* Open the PMP port */
\r
238 mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
\r
239 PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
\r
240 PMP_WRITE_POL_HI | PMP_READ_POL_HI),
\r
241 (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
\r
245 /* Wait for the LCD to power up correctly. */
\r
246 vTaskDelay( lcdLONG_DELAY );
\r
247 vTaskDelay( lcdLONG_DELAY );
\r
248 vTaskDelay( lcdLONG_DELAY );
\r
250 /* Set up the LCD function. */
\r
251 prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
\r
253 /* Turn the display on. */
\r
254 prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
\r
256 /* Clear the display. */
\r
257 prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
\r
258 vTaskDelay( lcdLONG_DELAY );
\r
260 /* Increase the cursor. */
\r
261 prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
\r
262 vTaskDelay( lcdLONG_DELAY );
\r
263 vTaskDelay( lcdLONG_DELAY );
\r
264 vTaskDelay( lcdLONG_DELAY );
\r
266 /*-----------------------------------------------------------*/
\r
268 static void vLCDTask(void *pvParameters)
\r
270 xLCDMessage xMessage;
\r
271 unsigned short usRow = 0;
\r
273 /* Initialise the hardware. This uses delays so must not be called prior
\r
274 to the scheduler being started. */
\r
277 /* Welcome message. */
\r
278 prvLCDPutString( "www.FreeRTOS.org" );
\r
282 /* Wait for a message to arrive that requires displaying. */
\r
283 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
285 /* Clear the current display value. */
\r
288 /* Switch rows each time so we can see that the display is still being
\r
290 prvLCDGotoRow( usRow & 0x01 );
\r
292 prvLCDPutString( xMessage.pcMessage );
\r
294 /* Delay the requested amount of time to ensure the text just written
\r
295 to the LCD is not overwritten. */
\r
296 vTaskDelay( xMessage.xMinDisplayTime );
\r