2 FreeRTOS V7.6.0 - Copyright (C) 2013 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 distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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
66 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
68 * This file only supports UART 0
\r
71 /* Standard includes. */
\r
74 /* Scheduler includes. */
\r
75 #include "FreeRTOS.h"
\r
79 /* Demo application includes. */
\r
82 /* The queue used to hold received characters. */
\r
83 static xQueueHandle xRxedChars;
\r
85 /* The queue used to hold characters waiting transmission. */
\r
86 static xQueueHandle xCharsForTx;
\r
88 static volatile portSHORT sTHREEmpty;
\r
90 static volatile portSHORT queueFail = pdFALSE;
\r
92 /*-----------------------------------------------------------*/
\r
93 xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
95 /* Initialise the hardware. */
\r
96 portENTER_CRITICAL();
\r
98 /* Create the queues used by the com test task. */
\r
99 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof(signed portCHAR) );
\r
100 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof(signed portCHAR) );
\r
102 if( xRxedChars == 0 )
\r
104 queueFail = pdTRUE;
\r
107 if( xCharsForTx == 0 )
\r
109 queueFail = pdTRUE;
\r
112 /* Initialize UART asynchronous mode */
\r
113 BGR0 = configCLKP1_CLOCK_HZ / ulWantedBaud;
\r
115 SCR0 = 0x17; /* 8N1 */
\r
116 SMR0 = 0x0d; /* enable SOT3, Reset, normal mode */
\r
117 SSR0 = 0x02; /* LSB first, enable receive interrupts */
\r
119 PIER08_IE2 = 1; /* enable input */
\r
120 DDR08_D2 = 0; /* switch P08_2 to input */
\r
121 DDR08_D3 = 1; /* switch P08_3 to output */
\r
123 portEXIT_CRITICAL();
\r
125 /* Unlike other ports, this serial code does not allow for more than one
\r
126 com port. We therefore don't return a pointer to a port structure and can
\r
127 instead just return NULL. */
\r
130 /*-----------------------------------------------------------*/
\r
132 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
\r
134 /* Get the next character from the buffer. Return false if no characters
\r
135 are available, or arrive before xBlockTime expires. */
\r
136 if( xQueueReceive(xRxedChars, pcRxedChar, xBlockTime) )
\r
145 /*-----------------------------------------------------------*/
\r
147 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
\r
149 signed portBASE_TYPE xReturn;
\r
151 /* Transmit a character. */
\r
152 portENTER_CRITICAL();
\r
154 if( sTHREEmpty == pdTRUE )
\r
156 /* If sTHREEmpty is true then the UART Tx ISR has indicated that
\r
157 there are no characters queued to be transmitted - so we can
\r
158 write the character directly to the shift Tx register. */
\r
159 sTHREEmpty = pdFALSE;
\r
165 /* sTHREEmpty is false, so there are still characters waiting to be
\r
166 transmitted. We have to queue this character so it gets
\r
167 transmitted in turn. */
\r
169 /* Return false if after the block time there is no room on the Tx
\r
170 queue. It is ok to block inside a critical section as each task
\r
171 maintains it's own critical section status. */
\r
172 if( xQueueSend(xCharsForTx, &cOutChar, xBlockTime) == pdTRUE )
\r
182 if( pdPASS == xReturn )
\r
184 /* Turn on the Tx interrupt so the ISR will remove the character from the
\r
185 queue and send it. This does not need to be in a critical section as
\r
186 if the interrupt has already removed the character the next interrupt
\r
187 will simply turn off the Tx interrupt again. */
\r
191 portEXIT_CRITICAL();
\r
195 /*-----------------------------------------------------------*/
\r
198 * UART RX interrupt service routine.
\r
200 __interrupt void UART0_RxISR( void )
\r
202 volatile signed portCHAR cChar;
\r
203 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
205 /* Get the character from the UART and post it on the queue of Rxed
\r
209 xQueueSendFromISR( xRxedChars, ( const void *const ) &cChar, &xHigherPriorityTaskWoken );
\r
211 if( xHigherPriorityTaskWoken )
\r
213 /*If the post causes a task to wake force a context switch
\r
214 as the woken task may have a higher priority than the task we have
\r
216 portYIELD_FROM_ISR();
\r
219 /*-----------------------------------------------------------*/
\r
222 * UART Tx interrupt service routine.
\r
224 __interrupt void UART0_TxISR( void )
\r
226 signed portCHAR cChar;
\r
227 signed portBASE_TYPE xTaskWoken = pdFALSE;
\r
229 /* The previous character has been transmitted. See if there are any
\r
230 further characters waiting transmission. */
\r
231 if( xQueueReceiveFromISR(xCharsForTx, &cChar, &xTaskWoken) == pdTRUE )
\r
233 /* There was another character queued - transmit it now. */
\r
238 /* There were no other characters to transmit. */
\r
239 sTHREEmpty = pdTRUE;
\r
241 /* Disable transmit interrupts */
\r