2 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 * BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
74 * This file only supports UART 2
\r
77 /* Standard includes. */
\r
80 /* Scheduler includes. */
\r
81 #include "FreeRTOS.h"
\r
85 /* Demo application includes. */
\r
88 /* The queue used to hold received characters. */
\r
89 static QueueHandle_t xRxedChars;
\r
91 /* The queue used to hold characters waiting transmission. */
\r
92 static QueueHandle_t xCharsForTx;
\r
94 static volatile short sTHREEmpty;
\r
96 /*-----------------------------------------------------------*/
\r
98 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
100 portENTER_CRITICAL();
\r
102 /* Create the queues used by the com test task. */
\r
103 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
104 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
106 /* Initialize UART asynchronous mode */
\r
107 BGR02 = configPER_CLOCK_HZ / ulWantedBaud;
\r
109 SCR02 = 0x17; /* 8N1 */
\r
110 SMR02 = 0x0d; /* enable SOT3, Reset, normal mode */
\r
111 SSR02 = 0x02; /* LSB first, enable receive interrupts */
\r
113 PFR20_D0 = 1; /* enable UART */
\r
114 PFR20_D1 = 1; /* enable UART */
\r
116 EPFR20_D1 = 0; /* enable UART */
\r
118 portEXIT_CRITICAL();
\r
120 /* Unlike other ports, this serial code does not allow for more than one
\r
121 com port. We therefore don't return a pointer to a port structure and can
\r
122 instead just return NULL. */
\r
125 /*-----------------------------------------------------------*/
\r
127 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
129 /* Get the next character from the buffer. Return false if no characters
\r
130 are available, or arrive before xBlockTime expires. */
\r
131 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
140 /*-----------------------------------------------------------*/
\r
142 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
144 signed portBASE_TYPE xReturn;
\r
146 /* Transmit a character. */
\r
147 portENTER_CRITICAL();
\r
149 if( sTHREEmpty == pdTRUE )
\r
151 /* If sTHREEmpty is true then the UART Tx ISR has indicated that
\r
152 there are no characters queued to be transmitted - so we can
\r
153 write the character directly to the shift Tx register. */
\r
154 sTHREEmpty = pdFALSE;
\r
160 /* sTHREEmpty is false, so there are still characters waiting to be
\r
161 transmitted. We have to queue this character so it gets
\r
162 transmitted in turn. */
\r
164 /* Return false if after the block time there is no room on the Tx
\r
165 queue. It is ok to block inside a critical section as each task
\r
166 maintains it's own critical section status. */
\r
167 if (xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdTRUE)
\r
177 if (pdPASS == xReturn)
\r
179 /* Turn on the Tx interrupt so the ISR will remove the character from the
\r
180 queue and send it. This does not need to be in a critical section as
\r
181 if the interrupt has already removed the character the next interrupt
\r
182 will simply turn off the Tx interrupt again. */
\r
187 portEXIT_CRITICAL();
\r
191 /*-----------------------------------------------------------*/
\r
194 * UART RX interrupt service routine.
\r
196 __interrupt void UART2_RxISR (void)
\r
199 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
201 /* Get the character from the UART and post it on the queue of Rxed
\r
205 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
207 if( xHigherPriorityTaskWoken )
\r
209 /*If the post causes a task to wake force a context switch
\r
210 as the woken task may have a higher priority than the task we have
\r
212 portYIELD_FROM_ISR();
\r
216 /*-----------------------------------------------------------*/
\r
219 * UART Tx interrupt service routine.
\r
221 __interrupt void UART2_TxISR (void)
\r
224 signed portBASE_TYPE xTaskWoken = pdFALSE;
\r
226 /* The previous character has been transmitted. See if there are any
\r
227 further characters waiting transmission. */
\r
228 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWoken ) == pdTRUE )
\r
230 /* There was another character queued - transmit it now. */
\r
235 /* There were no other characters to transmit. */
\r
236 sTHREEmpty = pdTRUE;
\r
238 /* Disable transmit interrupts */
\r