2 FreeRTOS V7.5.3 - 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
67 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
69 * This is not a proper UART driver. It only supports one port, uses loopback
\r
70 * mode, and is used to test interrupts that use the FreeRTOS API as part of
\r
71 * a wider test suite. Nor is it intended to show an efficient implementation
\r
72 * of a UART interrupt service routine as queues are used to pass individual
\r
73 * characters one at a time!
\r
76 /* Standard includes. */
\r
79 /* Scheduler includes. */
\r
80 #include "FreeRTOS.h"
\r
84 /* Demo application includes. */
\r
87 /* Misc. constants. */
\r
88 #define serNO_BLOCK ( ( portTickType ) 0 )
\r
90 /* The queue used to hold received characters. */
\r
91 static xQueueHandle xRxedChars;
\r
93 /* The queue used to hold characters waiting transmission. */
\r
94 static xQueueHandle xCharsForTx;
\r
96 /*-----------------------------------------------------------*/
\r
98 xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
100 unsigned portLONG ulBaudRateCount;
\r
102 /* Initialise the hardware. */
\r
104 /* Generate the baud rate constants for the wanted baud rate. */
\r
105 ulBaudRateCount = configCPU_CLOCK_HZ / ulWantedBaud;
\r
107 portENTER_CRITICAL();
\r
109 /* Create the queues used by the com test task. */
\r
110 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
111 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
114 UCA1CTL1 |= UCSWRST;
\r
117 UCA1CTL1 = UCSSEL0 | UCSSEL1;
\r
119 /* Setup baud rate low byte. */
\r
120 UCA1BR0 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
\r
122 /* Setup baud rate high byte. */
\r
123 ulBaudRateCount >>= 8UL;
\r
124 UCA1BR1 = ( unsigned portCHAR ) ( ulBaudRateCount & ( unsigned portLONG ) 0xff );
\r
126 /* UCLISTEN sets loopback mode! */
\r
127 UCA1STAT = UCLISTEN;
\r
129 /* Enable interrupts. */
\r
132 /* Take out of reset. */
\r
133 UCA1CTL1 &= ~UCSWRST;
\r
135 portEXIT_CRITICAL();
\r
137 /* Note the comments at the top of this file about this not being a generic
\r
141 /*-----------------------------------------------------------*/
\r
143 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
\r
145 /* Get the next character from the buffer. Return false if no characters
\r
146 are available, or arrive before xBlockTime expires. */
\r
147 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
156 /*-----------------------------------------------------------*/
\r
158 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
\r
160 signed portBASE_TYPE xReturn;
\r
162 /* Send the next character to the queue of characters waiting transmission,
\r
163 then enable the UART Tx interrupt, just in case UART transmission has already
\r
164 completed and switched itself off. */
\r
165 xReturn = xQueueSend( xCharsForTx, &cOutChar, xBlockTime );
\r
170 /*-----------------------------------------------------------*/
\r
172 /* The implementation of this interrupt is provided to demonstrate the use
\r
173 of queues from inside an interrupt service routine. It is *not* intended to
\r
174 be an efficient interrupt implementation. A real application should make use
\r
175 of the DMA. Or, as a minimum, transmission and reception could use a simple
\r
176 RAM ring buffer, and synchronise with a task using a semaphore when a complete
\r
177 message has been received or transmitted. */
\r
178 #pragma vector=USCI_A1_VECTOR
\r
179 static __interrupt void prvUSCI_A1_ISR( void )
\r
182 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
184 while( ( UCA1IFG & UCRXIFG ) != 0 )
\r
186 /* Get the character from the UART and post it on the queue of Rxed
\r
189 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
192 /* If there is a Tx interrupt pending and the tx interrupts are enabled. */
\r
193 if( ( UCA1IFG & UCTXIFG ) != 0 )
\r
195 /* The previous character has been transmitted. See if there are any
\r
196 further characters waiting transmission. */
\r
197 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
199 /* There was another character queued - transmit it now. */
\r
204 /* There were no other characters to transmit - disable the Tx
\r
210 __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );
\r
212 /* If writing to a queue caused a task to unblock, and the unblocked task
\r
213 has a priority equal to or above the task that this interrupt interrupted,
\r
214 then lHigherPriorityTaskWoken will have been set to pdTRUE internally within
\r
215 xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this
\r
216 interrupt returns directly to the higher priority unblocked task.
\r
218 THIS MUST BE THE LAST THING DONE IN THE ISR. */
\r
219 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r