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
68 * BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
70 * This file only supports UART 2
\r
73 /* Standard includes. */
\r
76 /* Scheduler includes. */
\r
77 #include "FreeRTOS.h"
\r
81 /* Demo application includes. */
\r
84 /* The queue used to hold received characters. */
\r
85 static xQueueHandle xRxedChars;
\r
87 /* The queue used to hold characters waiting transmission. */
\r
88 static xQueueHandle xCharsForTx;
\r
90 static volatile short sTHREEmpty;
\r
92 /*-----------------------------------------------------------*/
\r
94 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\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 char ) );
\r
100 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
102 /* Initialize UART asynchronous mode */
\r
103 BGR02 = configPER_CLOCK_HZ / ulWantedBaud;
\r
105 SCR02 = 0x17; /* 8N1 */
\r
106 SMR02 = 0x0d; /* enable SOT3, Reset, normal mode */
\r
107 SSR02 = 0x02; /* LSB first, enable receive interrupts */
\r
109 PFR20_D0 = 1; /* enable UART */
\r
110 PFR20_D1 = 1; /* enable UART */
\r
112 EPFR20_D1 = 0; /* enable UART */
\r
114 portEXIT_CRITICAL();
\r
116 /* Unlike other ports, this serial code does not allow for more than one
\r
117 com port. We therefore don't return a pointer to a port structure and can
\r
118 instead just return NULL. */
\r
121 /*-----------------------------------------------------------*/
\r
123 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
125 /* Get the next character from the buffer. Return false if no characters
\r
126 are available, or arrive before xBlockTime expires. */
\r
127 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
136 /*-----------------------------------------------------------*/
\r
138 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
140 signed portBASE_TYPE xReturn;
\r
142 /* Transmit a character. */
\r
143 portENTER_CRITICAL();
\r
145 if( sTHREEmpty == pdTRUE )
\r
147 /* If sTHREEmpty is true then the UART Tx ISR has indicated that
\r
148 there are no characters queued to be transmitted - so we can
\r
149 write the character directly to the shift Tx register. */
\r
150 sTHREEmpty = pdFALSE;
\r
156 /* sTHREEmpty is false, so there are still characters waiting to be
\r
157 transmitted. We have to queue this character so it gets
\r
158 transmitted in turn. */
\r
160 /* Return false if after the block time there is no room on the Tx
\r
161 queue. It is ok to block inside a critical section as each task
\r
162 maintains it's own critical section status. */
\r
163 if (xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdTRUE)
\r
173 if (pdPASS == xReturn)
\r
175 /* Turn on the Tx interrupt so the ISR will remove the character from the
\r
176 queue and send it. This does not need to be in a critical section as
\r
177 if the interrupt has already removed the character the next interrupt
\r
178 will simply turn off the Tx interrupt again. */
\r
183 portEXIT_CRITICAL();
\r
187 /*-----------------------------------------------------------*/
\r
190 * UART RX interrupt service routine.
\r
192 __interrupt void UART2_RxISR (void)
\r
195 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
197 /* Get the character from the UART and post it on the queue of Rxed
\r
201 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
203 if( xHigherPriorityTaskWoken )
\r
205 /*If the post causes a task to wake force a context switch
\r
206 as the woken task may have a higher priority than the task we have
\r
208 portYIELD_FROM_ISR();
\r
212 /*-----------------------------------------------------------*/
\r
215 * UART Tx interrupt service routine.
\r
217 __interrupt void UART2_TxISR (void)
\r
220 signed portBASE_TYPE xTaskWoken = pdFALSE;
\r
222 /* The previous character has been transmitted. See if there are any
\r
223 further characters waiting transmission. */
\r
224 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWoken ) == pdTRUE )
\r
226 /* There was another character queued - transmit it now. */
\r
231 /* There were no other characters to transmit. */
\r
232 sTHREEmpty = pdTRUE;
\r
234 /* Disable transmit interrupts */
\r