2 * FreeRTOS Kernel V10.0.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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* Scheduler includes. */
\r
30 #include "FreeRTOS.h"
\r
34 /* Demo includes. */
\r
38 * The LCD is written to by more than one task so is controlled by this
\r
39 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
40 * access the LCD directly. Other tasks wanting to display a message send
\r
41 * the message to the gatekeeper.
\r
43 static void vLCDTask( void *pvParameters );
\r
46 * Setup the peripherals required to communicate with the LCD.
\r
48 static void prvSetupLCD( void );
\r
51 * Move to the first (0) or second (1) row of the LCD.
\r
53 static void prvLCDGotoRow( unsigned short usRow );
\r
56 * Write a string of text to the LCD.
\r
58 static void prvLCDPutString( char *pcString );
\r
63 static void prvLCDClear( void );
\r
65 /*-----------------------------------------------------------*/
\r
67 /* Brief delay to permit the LCD to catch up with commands. */
\r
68 #define lcdSHORT_DELAY 3
\r
70 /* SFR that seems to be missing from the standard header files. */
\r
71 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
74 #define lcdDEFAULT_FUNCTION 0x3c
\r
75 #define lcdDISPLAY_CONTROL 0x0c
\r
76 #define lcdCLEAR_DISPLAY 0x01
\r
77 #define lcdENTRY_MODE 0x06
\r
79 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
80 #define lcdQUEUE_SIZE 3
\r
81 /*-----------------------------------------------------------*/
\r
83 /* The queue used to send messages to the LCD task. */
\r
84 QueueHandle_t xLCDQueue;
\r
87 /*-----------------------------------------------------------*/
\r
89 QueueHandle_t xStartLCDTask( void )
\r
91 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
92 are received via this queue. */
\r
93 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
95 /* Start the task that will write to the LCD. The LCD hardware is
\r
96 initialised from within the task itself so delays can be used. */
\r
97 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
101 /*-----------------------------------------------------------*/
\r
103 static void prvLCDGotoRow( unsigned short usRow )
\r
116 vTaskDelay( lcdSHORT_DELAY );
\r
118 /*-----------------------------------------------------------*/
\r
120 static void prvLCDPutString( char *pcString )
\r
122 /* Write out each character with appropriate delay between each. */
\r
126 PMDIN1 = *pcString;
\r
128 vTaskDelay( lcdSHORT_DELAY );
\r
131 /*-----------------------------------------------------------*/
\r
133 static void prvLCDClear( void )
\r
135 /* Clear the display. */
\r
137 PMDIN1 = lcdCLEAR_DISPLAY;
\r
138 vTaskDelay( lcdSHORT_DELAY );
\r
140 /*-----------------------------------------------------------*/
\r
142 static void prvSetupLCD( void )
\r
144 /* Setup the PMP. */
\r
149 vTaskDelay( lcdSHORT_DELAY );
\r
151 /* Set the default function. */
\r
152 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
153 vTaskDelay( lcdSHORT_DELAY );
\r
155 /* Set the display control. */
\r
156 PMDIN1 = lcdDISPLAY_CONTROL;
\r
157 vTaskDelay( lcdSHORT_DELAY );
\r
159 /* Clear the display. */
\r
160 PMDIN1 = lcdCLEAR_DISPLAY;
\r
161 vTaskDelay( lcdSHORT_DELAY );
\r
163 /* Set the entry mode. */
\r
164 PMDIN1 = lcdENTRY_MODE;
\r
165 vTaskDelay( lcdSHORT_DELAY );
\r
167 /*-----------------------------------------------------------*/
\r
169 static void vLCDTask( void *pvParameters )
\r
171 xLCDMessage xMessage;
\r
172 unsigned short usRow = 0;
\r
174 /* Remove compiler warnigns. */
\r
175 ( void ) pvParameters;
\r
177 /* Initialise the hardware. This uses delays so must not be called prior
\r
178 to the scheduler being started. */
\r
181 /* Welcome message. */
\r
182 prvLCDPutString( "www.FreeRTOS.org" );
\r
186 /* Wait for a message to arrive that requires displaying. */
\r
187 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
189 /* Clear the current display value. */
\r
192 /* Switch rows each time so we can see that the display is still being
\r
194 prvLCDGotoRow( usRow & 0x01 );
\r
196 prvLCDPutString( xMessage.pcMessage );
\r
198 /* Delay the requested amount of time to ensure the text just written
\r
199 to the LCD is not overwritten. */
\r
200 vTaskDelay( xMessage.xMinDisplayTime );
\r