2 FreeRTOS V9.0.1 - Copyright (C) 2017 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
70 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
72 * This file only supports UART 0
\r
75 /* Standard includes. */
\r
78 /* Scheduler includes. */
\r
79 #include "FreeRTOS.h"
\r
83 /* Demo application includes. */
\r
86 /* The queue used to hold received characters. */
\r
87 static QueueHandle_t xRxedChars;
\r
89 /* The queue used to hold characters waiting transmission. */
\r
90 static QueueHandle_t xCharsForTx;
\r
92 static volatile short sTHREEmpty;
\r
94 static volatile short queueFail = pdFALSE;
\r
96 /*-----------------------------------------------------------*/
\r
97 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
99 /* Initialise the hardware. */
\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 if( xRxedChars == 0 )
\r
108 queueFail = pdTRUE;
\r
111 if( xCharsForTx == 0 )
\r
113 queueFail = pdTRUE;
\r
116 /* Initialize UART asynchronous mode */
\r
117 BGR0 = configCLKP1_CLOCK_HZ / ulWantedBaud;
\r
119 SCR0 = 0x17; /* 8N1 */
\r
120 SMR0 = 0x0d; /* enable SOT3, Reset, normal mode */
\r
121 SSR0 = 0x02; /* LSB first, enable receive interrupts */
\r
123 PIER08_IE2 = 1; /* enable input */
\r
124 DDR08_D2 = 0; /* switch P08_2 to input */
\r
125 DDR08_D3 = 1; /* switch P08_3 to output */
\r
127 portEXIT_CRITICAL();
\r
129 /* Unlike other ports, this serial code does not allow for more than one
\r
130 com port. We therefore don't return a pointer to a port structure and can
\r
131 instead just return NULL. */
\r
134 /*-----------------------------------------------------------*/
\r
136 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
138 /* Get the next character from the buffer. Return false if no characters
\r
139 are available, or arrive before xBlockTime expires. */
\r
140 if( xQueueReceive(xRxedChars, pcRxedChar, xBlockTime) )
\r
149 /*-----------------------------------------------------------*/
\r
151 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
153 signed portBASE_TYPE xReturn;
\r
155 /* Transmit a character. */
\r
156 portENTER_CRITICAL();
\r
158 if( sTHREEmpty == pdTRUE )
\r
160 /* If sTHREEmpty is true then the UART Tx ISR has indicated that
\r
161 there are no characters queued to be transmitted - so we can
\r
162 write the character directly to the shift Tx register. */
\r
163 sTHREEmpty = pdFALSE;
\r
169 /* sTHREEmpty is false, so there are still characters waiting to be
\r
170 transmitted. We have to queue this character so it gets
\r
171 transmitted in turn. */
\r
173 /* Return false if after the block time there is no room on the Tx
\r
174 queue. It is ok to block inside a critical section as each task
\r
175 maintains it's own critical section status. */
\r
176 if( xQueueSend(xCharsForTx, &cOutChar, xBlockTime) == pdTRUE )
\r
186 if( pdPASS == xReturn )
\r
188 /* Turn on the Tx interrupt so the ISR will remove the character from the
\r
189 queue and send it. This does not need to be in a critical section as
\r
190 if the interrupt has already removed the character the next interrupt
\r
191 will simply turn off the Tx interrupt again. */
\r
195 portEXIT_CRITICAL();
\r
199 /*-----------------------------------------------------------*/
\r
202 * UART RX interrupt service routine.
\r
204 __interrupt void UART0_RxISR( void )
\r
206 volatile signed char cChar;
\r
207 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
209 /* Get the character from the UART and post it on the queue of Rxed
\r
213 xQueueSendFromISR( xRxedChars, ( const void *const ) &cChar, &xHigherPriorityTaskWoken );
\r
215 if( xHigherPriorityTaskWoken )
\r
217 /*If the post causes a task to wake force a context switch
\r
218 as the woken task may have a higher priority than the task we have
\r
220 portYIELD_FROM_ISR();
\r
223 /*-----------------------------------------------------------*/
\r
226 * UART Tx interrupt service routine.
\r
228 __interrupt void UART0_TxISR( void )
\r
231 signed portBASE_TYPE xTaskWoken = pdFALSE;
\r
233 /* The previous character has been transmitted. See if there are any
\r
234 further characters waiting transmission. */
\r
235 if( xQueueReceiveFromISR(xCharsForTx, &cChar, &xTaskWoken) == pdTRUE )
\r
237 /* There was another character queued - transmit it now. */
\r
242 /* There were no other characters to transmit. */
\r
243 sTHREEmpty = pdTRUE;
\r
245 /* Disable transmit interrupts */
\r