2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
67 * This file only supports UART 0
\r
70 /* Standard includes. */
\r
73 /* Scheduler includes. */
\r
74 #include "FreeRTOS.h"
\r
78 /* Demo application includes. */
\r
81 /* The queue used to hold received characters. */
\r
82 static xQueueHandle xRxedChars;
\r
84 /* The queue used to hold characters waiting transmission. */
\r
85 static xQueueHandle xCharsForTx;
\r
87 static volatile portSHORT sTHREEmpty;
\r
89 static volatile portSHORT queueFail = pdFALSE;
\r
91 /*-----------------------------------------------------------*/
\r
92 xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
94 /* Initialise the hardware. */
\r
95 portENTER_CRITICAL();
\r
97 /* Create the queues used by the com test task. */
\r
98 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof(signed portCHAR) );
\r
99 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof(signed portCHAR) );
\r
101 if( xRxedChars == 0 )
\r
103 queueFail = pdTRUE;
\r
106 if( xCharsForTx == 0 )
\r
108 queueFail = pdTRUE;
\r
111 /* Initialize UART asynchronous mode */
\r
112 BGR0 = configCLKP1_CLOCK_HZ / ulWantedBaud;
\r
114 SCR0 = 0x17; /* 8N1 */
\r
115 SMR0 = 0x0d; /* enable SOT3, Reset, normal mode */
\r
116 SSR0 = 0x02; /* LSB first, enable receive interrupts */
\r
118 PIER08_IE2 = 1; /* enable input */
\r
119 DDR08_D2 = 0; /* switch P08_2 to input */
\r
120 DDR08_D3 = 1; /* switch P08_3 to output */
\r
122 portEXIT_CRITICAL();
\r
124 /* Unlike other ports, this serial code does not allow for more than one
\r
125 com port. We therefore don't return a pointer to a port structure and can
\r
126 instead just return NULL. */
\r
129 /*-----------------------------------------------------------*/
\r
131 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
\r
133 /* Get the next character from the buffer. Return false if no characters
\r
134 are available, or arrive before xBlockTime expires. */
\r
135 if( xQueueReceive(xRxedChars, pcRxedChar, xBlockTime) )
\r
144 /*-----------------------------------------------------------*/
\r
146 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
\r
148 signed portBASE_TYPE xReturn;
\r
150 /* Transmit a character. */
\r
151 portENTER_CRITICAL();
\r
153 if( sTHREEmpty == pdTRUE )
\r
155 /* If sTHREEmpty is true then the UART Tx ISR has indicated that
\r
156 there are no characters queued to be transmitted - so we can
\r
157 write the character directly to the shift Tx register. */
\r
158 sTHREEmpty = pdFALSE;
\r
164 /* sTHREEmpty is false, so there are still characters waiting to be
\r
165 transmitted. We have to queue this character so it gets
\r
166 transmitted in turn. */
\r
168 /* Return false if after the block time there is no room on the Tx
\r
169 queue. It is ok to block inside a critical section as each task
\r
170 maintains it's own critical section status. */
\r
171 if( xQueueSend(xCharsForTx, &cOutChar, xBlockTime) == pdTRUE )
\r
181 if( pdPASS == xReturn )
\r
183 /* Turn on the Tx interrupt so the ISR will remove the character from the
\r
184 queue and send it. This does not need to be in a critical section as
\r
185 if the interrupt has already removed the character the next interrupt
\r
186 will simply turn off the Tx interrupt again. */
\r
190 portEXIT_CRITICAL();
\r
194 /*-----------------------------------------------------------*/
\r
197 * UART RX interrupt service routine.
\r
199 __interrupt void UART0_RxISR( void )
\r
201 volatile signed portCHAR cChar;
\r
202 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
204 /* Get the character from the UART and post it on the queue of Rxed
\r
208 xQueueSendFromISR( xRxedChars, ( const void *const ) &cChar, &xHigherPriorityTaskWoken );
\r
210 if( xHigherPriorityTaskWoken )
\r
212 /*If the post causes a task to wake force a context switch
\r
213 as the woken task may have a higher priority than the task we have
\r
215 portYIELD_FROM_ISR();
\r
218 /*-----------------------------------------------------------*/
\r
221 * UART Tx interrupt service routine.
\r
223 __interrupt void UART0_TxISR( void )
\r
225 signed portCHAR cChar;
\r
226 signed portBASE_TYPE xTaskWoken = pdFALSE;
\r
228 /* The previous character has been transmitted. See if there are any
\r
229 further characters waiting transmission. */
\r
230 if( xQueueReceiveFromISR(xCharsForTx, &cChar, &xTaskWoken) == pdTRUE )
\r
232 /* There was another character queued - transmit it now. */
\r
237 /* There were no other characters to transmit. */
\r
238 sTHREEmpty = pdTRUE;
\r
240 /* Disable transmit interrupts */
\r