2 * FreeRTOS Kernel V10.1.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* Scheduler includes. */
\r
29 #include "FreeRTOS.h"
\r
33 /* Demo includes. */
\r
37 * The LCD is written to by more than one task so is controlled by this
\r
38 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
39 * access the LCD directly. Other tasks wanting to display a message send
\r
40 * the message to the gatekeeper.
\r
42 static void vLCDTask( void *pvParameters );
\r
45 * Setup the peripherals required to communicate with the LCD.
\r
47 static void prvSetupLCD( void );
\r
50 * Move to the first (0) or second (1) row of the LCD.
\r
52 static void prvLCDGotoRow( unsigned short usRow );
\r
55 * Write a string of text to the LCD.
\r
57 static void prvLCDPutString( char *pcString );
\r
62 static void prvLCDClear( void );
\r
64 /*-----------------------------------------------------------*/
\r
66 /* Brief delay to permit the LCD to catch up with commands. */
\r
67 #define lcdSHORT_DELAY 3
\r
69 /* SFR that seems to be missing from the standard header files. */
\r
70 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
73 #define lcdDEFAULT_FUNCTION 0x3c
\r
74 #define lcdDISPLAY_CONTROL 0x0c
\r
75 #define lcdCLEAR_DISPLAY 0x01
\r
76 #define lcdENTRY_MODE 0x06
\r
78 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
79 #define lcdQUEUE_SIZE 3
\r
80 /*-----------------------------------------------------------*/
\r
82 /* The queue used to send messages to the LCD task. */
\r
83 QueueHandle_t xLCDQueue;
\r
86 /*-----------------------------------------------------------*/
\r
88 QueueHandle_t xStartLCDTask( void )
\r
90 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
91 are received via this queue. */
\r
92 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
94 /* Start the task that will write to the LCD. The LCD hardware is
\r
95 initialised from within the task itself so delays can be used. */
\r
96 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
100 /*-----------------------------------------------------------*/
\r
102 static void prvLCDGotoRow( unsigned short usRow )
\r
115 vTaskDelay( lcdSHORT_DELAY );
\r
117 /*-----------------------------------------------------------*/
\r
119 static void prvLCDPutString( char *pcString )
\r
121 /* Write out each character with appropriate delay between each. */
\r
125 PMDIN1 = *pcString;
\r
127 vTaskDelay( lcdSHORT_DELAY );
\r
130 /*-----------------------------------------------------------*/
\r
132 static void prvLCDClear( void )
\r
134 /* Clear the display. */
\r
136 PMDIN1 = lcdCLEAR_DISPLAY;
\r
137 vTaskDelay( lcdSHORT_DELAY );
\r
139 /*-----------------------------------------------------------*/
\r
141 static void prvSetupLCD( void )
\r
143 /* Setup the PMP. */
\r
148 vTaskDelay( lcdSHORT_DELAY );
\r
150 /* Set the default function. */
\r
151 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
152 vTaskDelay( lcdSHORT_DELAY );
\r
154 /* Set the display control. */
\r
155 PMDIN1 = lcdDISPLAY_CONTROL;
\r
156 vTaskDelay( lcdSHORT_DELAY );
\r
158 /* Clear the display. */
\r
159 PMDIN1 = lcdCLEAR_DISPLAY;
\r
160 vTaskDelay( lcdSHORT_DELAY );
\r
162 /* Set the entry mode. */
\r
163 PMDIN1 = lcdENTRY_MODE;
\r
164 vTaskDelay( lcdSHORT_DELAY );
\r
166 /*-----------------------------------------------------------*/
\r
168 static void vLCDTask( void *pvParameters )
\r
170 xLCDMessage xMessage;
\r
171 unsigned short usRow = 0;
\r
173 /* Remove compiler warnigns. */
\r
174 ( void ) pvParameters;
\r
176 /* Initialise the hardware. This uses delays so must not be called prior
\r
177 to the scheduler being started. */
\r
180 /* Welcome message. */
\r
181 prvLCDPutString( "www.FreeRTOS.org" );
\r
185 /* Wait for a message to arrive that requires displaying. */
\r
186 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
188 /* Clear the current display value. */
\r
191 /* Switch rows each time so we can see that the display is still being
\r
193 prvLCDGotoRow( usRow & 0x01 );
\r
195 prvLCDPutString( xMessage.pcMessage );
\r
197 /* Delay the requested amount of time to ensure the text just written
\r
198 to the LCD is not overwritten. */
\r
199 vTaskDelay( xMessage.xMinDisplayTime );
\r