2 FreeRTOS V8.1.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR DEMO PURPOSES */
\r
69 #include "FreeRTOS.h"
\r
74 /* Constants required to setup the serial control register. */
\r
75 #define ser8_BIT_MODE ( ( unsigned char ) 0x40 )
\r
76 #define serRX_ENABLE ( ( unsigned char ) 0x10 )
\r
78 /* Constants to setup the timer used to generate the baud rate. */
\r
79 #define serCLOCK_DIV_48 ( ( unsigned char ) 0x03 )
\r
80 #define serUSE_PRESCALED_CLOCK ( ( unsigned char ) 0x10 )
\r
81 #define ser8BIT_WITH_RELOAD ( ( unsigned char ) 0x20 )
\r
82 #define serSMOD ( ( unsigned char ) 0x10 )
\r
84 static QueueHandle_t xRxedChars;
\r
85 static QueueHandle_t xCharsForTx;
\r
87 data static unsigned portBASE_TYPE uxTxEmpty;
\r
89 /*-----------------------------------------------------------*/
\r
91 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
93 unsigned long ulReloadValue;
\r
94 const portFLOAT fBaudConst = ( portFLOAT ) configCPU_CLOCK_HZ * ( portFLOAT ) 2.0;
\r
95 unsigned char ucOriginalSFRPage;
\r
97 portENTER_CRITICAL();
\r
99 ucOriginalSFRPage = SFRPAGE;
\r
102 uxTxEmpty = pdTRUE;
\r
104 /* Create the queues used by the com test task. */
\r
105 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
106 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( char ) );
\r
108 /* Calculate the baud rate to use timer 1. */
\r
109 ulReloadValue = ( unsigned long ) ( ( ( portFLOAT ) 256 - ( fBaudConst / ( portFLOAT ) ( 32 * ulWantedBaud ) ) ) + ( portFLOAT ) 0.5 );
\r
111 /* Set timer one for desired mode of operation. */
\r
113 TMOD |= ser8BIT_WITH_RELOAD;
\r
116 /* Set the reload and start values for the time. */
\r
117 TL1 = ( unsigned char ) ulReloadValue;
\r
118 TH1 = ( unsigned char ) ulReloadValue;
\r
120 /* Setup the control register for standard n, 8, 1 - variable baud rate. */
\r
121 SCON = ser8_BIT_MODE | serRX_ENABLE;
\r
123 /* Enable the serial port interrupts */
\r
126 /* Start the timer. */
\r
129 SFRPAGE = ucOriginalSFRPage;
\r
131 portEXIT_CRITICAL();
\r
133 /* Unlike some ports, this serial code does not allow for more than one
\r
134 com port. We therefore don't return a pointer to a port structure and can
\r
135 instead just return NULL. */
\r
138 /*-----------------------------------------------------------*/
\r
140 void vSerialISR( void ) interrupt 4
\r
143 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
145 /* 8051 port interrupt routines MUST be placed within a critical section
\r
146 if taskYIELD() is used within the ISR! */
\r
148 portENTER_CRITICAL();
\r
152 /* Get the character and post it on the queue of Rxed characters.
\r
153 If the post causes a task to wake force a context switch if the woken task
\r
154 has a higher priority than the task we have interrupted. */
\r
158 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
163 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == ( portBASE_TYPE ) pdTRUE )
\r
165 /* Send the next character queued for Tx. */
\r
170 /* Queue empty, nothing to send. */
\r
171 uxTxEmpty = pdTRUE;
\r
177 if( xHigherPriorityTaskWoken )
\r
182 portEXIT_CRITICAL();
\r
184 /*-----------------------------------------------------------*/
\r
186 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
188 /* There is only one port supported. */
\r
191 /* Get the next character from the buffer. Return false if no characters
\r
192 are available, or arrive before xBlockTime expires. */
\r
193 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
195 return ( portBASE_TYPE ) pdTRUE;
\r
199 return ( portBASE_TYPE ) pdFALSE;
\r
202 /*-----------------------------------------------------------*/
\r
204 portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
206 portBASE_TYPE xReturn;
\r
208 /* There is only one port supported. */
\r
211 portENTER_CRITICAL();
\r
213 if( uxTxEmpty == pdTRUE )
\r
216 uxTxEmpty = pdFALSE;
\r
217 xReturn = ( portBASE_TYPE ) pdTRUE;
\r
221 xReturn = xQueueSend( xCharsForTx, &cOutChar, xBlockTime );
\r
223 if( xReturn == ( portBASE_TYPE ) pdFALSE )
\r
225 xReturn = ( portBASE_TYPE ) pdTRUE;
\r
229 portEXIT_CRITICAL();
\r
233 /*-----------------------------------------------------------*/
\r
235 void vSerialClose( xComPortHandle xPort )
\r
237 /* Not implemented in this port. */
\r
240 /*-----------------------------------------------------------*/
\r