2 FreeRTOS V7.5.2 - 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
66 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
68 NOTE: This driver is primarily to test the scheduler functionality. It does
\r
69 not effectively use the buffers or DMA and is therefore not intended to be
\r
70 an example of an efficient driver. */
\r
72 /* Standard include file. */
\r
75 /* Scheduler include files. */
\r
76 #include "FreeRTOS.h"
\r
80 /* Demo app include files. */
\r
83 /* Hardware definitions. */
\r
84 #define serNO_PARITY ( ( unsigned portCHAR ) 0x02 << 3 )
\r
85 #define ser8DATA_BITS ( ( unsigned portCHAR ) 0x03 )
\r
86 #define ser1STOP_BIT ( ( unsigned portCHAR ) 0x07 )
\r
87 #define serSYSTEM_CLOCK ( ( unsigned portCHAR ) 0xdd )
\r
88 #define serTX_ENABLE ( ( unsigned portCHAR ) 0x04 )
\r
89 #define serRX_ENABLE ( ( unsigned portCHAR ) 0x01 )
\r
90 #define serTX_INT ( ( unsigned portCHAR ) 0x01 )
\r
91 #define serRX_INT ( ( unsigned portCHAR ) 0x02 )
\r
94 /* The queues used to communicate between tasks and ISR's. */
\r
95 static xQueueHandle xRxedChars;
\r
96 static xQueueHandle xCharsForTx;
\r
98 /* Flag used to indicate the tx status. */
\r
99 static portBASE_TYPE xTxHasEnded = pdTRUE;
\r
101 /*-----------------------------------------------------------*/
\r
103 xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
105 const unsigned portLONG ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32UL * ulWantedBaud ) );
\r
107 /* Create the queues used by the com test task. */
\r
108 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
109 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
111 xTxHasEnded = pdTRUE;
\r
113 /* Set the pins to UART mode. */
\r
114 MCF_GPIO_PUAPAR |= MCF_GPIO_PUAPAR_UTXD0_UTXD0;
\r
115 MCF_GPIO_PUAPAR |= MCF_GPIO_PUAPAR_URXD0_URXD0;
\r
117 /* Reset the peripheral. */
\r
118 MCF_UART0_UCR = MCF_UART_UCR_RESET_RX;
\r
119 MCF_UART0_UCR = MCF_UART_UCR_RESET_TX;
\r
120 MCF_UART0_UCR = MCF_UART_UCR_RESET_ERROR;
\r
121 MCF_UART0_UCR = MCF_UART_UCR_RESET_BKCHGINT;
\r
122 MCF_UART0_UCR = MCF_UART_UCR_RESET_MR | MCF_UART_UCR_RX_DISABLED | MCF_UART_UCR_TX_DISABLED;
\r
124 /* Configure the UART. */
\r
125 MCF_UART0_UMR1 = serNO_PARITY | ser8DATA_BITS;
\r
126 MCF_UART0_UMR2 = ser1STOP_BIT;
\r
127 MCF_UART0_UCSR = serSYSTEM_CLOCK;
\r
129 MCF_UART0_UBG1 = ( unsigned portCHAR ) ( ( ulBaudRateDivisor >> 8UL ) & 0xffUL );
\r
130 MCF_UART0_UBG2 = ( unsigned portCHAR ) ( ulBaudRateDivisor & 0xffUL );
\r
133 MCF_UART0_UCR = serTX_ENABLE | serRX_ENABLE;
\r
135 /* Configure the interrupt controller. Run the UARTs above the kernel
\r
136 interrupt priority for demo purposes. */
\r
137 MCF_INTC0_ICR13 = ( ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 1 ) << 3 );
\r
138 MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK13 | 0x01 );
\r
140 /* The Tx interrupt is not enabled until there is data to send. */
\r
141 MCF_UART0_UIMR = serRX_INT;
\r
143 /* Only a single port is implemented so we don't need to return anything. */
\r
146 /*-----------------------------------------------------------*/
\r
148 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
\r
150 /* Only one port is supported. */
\r
153 /* Get the next character from the buffer. Return false if no characters
\r
154 are available or arrive before xBlockTime expires. */
\r
155 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
164 /*-----------------------------------------------------------*/
\r
166 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
\r
168 /* Only one port is supported. */
\r
171 /* Return false if after the block time there is no room on the Tx queue. */
\r
172 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
\r
177 /* A critical section should not be required as xTxHasEnded will not be
\r
178 written to by the ISR if it is already 0 (is this correct?). */
\r
179 if( xTxHasEnded != pdFALSE )
\r
181 xTxHasEnded = pdFALSE;
\r
182 MCF_UART0_UIMR = serRX_INT | serTX_INT;
\r
187 /*-----------------------------------------------------------*/
\r
189 void vSerialClose( xComPortHandle xPort )
\r
193 /*-----------------------------------------------------------*/
\r
195 __declspec(interrupt:0) void vUART0InterruptHandler( void )
\r
197 unsigned portCHAR ucChar;
\r
198 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, xDoneSomething = pdTRUE;
\r
200 while( xDoneSomething != pdFALSE )
\r
202 xDoneSomething = pdFALSE;
\r
204 /* Does the tx buffer contain space? */
\r
205 if( ( MCF_UART0_USR & MCF_UART_USR_TXRDY ) != 0x00 )
\r
207 /* Are there any characters queued to be sent? */
\r
208 if( xQueueReceiveFromISR( xCharsForTx, &ucChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
210 /* Send the next char. */
\r
211 MCF_UART0_UTB = ucChar;
\r
212 xDoneSomething = pdTRUE;
\r
216 /* Turn off the Tx interrupt until such time as another character
\r
217 is being transmitted. */
\r
218 MCF_UART0_UIMR = serRX_INT;
\r
219 xTxHasEnded = pdTRUE;
\r
223 if( MCF_UART0_USR & MCF_UART_USR_RXRDY )
\r
225 ucChar = MCF_UART0_URB;
\r
226 xQueueSendFromISR( xRxedChars, &ucChar, &xHigherPriorityTaskWoken );
\r
227 xDoneSomething = pdTRUE;
\r
231 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r