2 FreeRTOS.org V5.0.3 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 /* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
\r
53 NOTE: This driver is primarily to test the scheduler functionality. It does
\r
54 not effectively use the buffers or DMA and is therefore not intended to be
\r
55 an example of an efficient driver. */
\r
57 /* Standard include file. */
\r
60 /* Scheduler include files. */
\r
61 #include "FreeRTOS.h"
\r
65 /* Demo app include files. */
\r
68 /* Hardware definitions. */
\r
69 #define serNO_PARITY ( ( unsigned portCHAR ) 0x10 << 3 )
\r
70 #define ser8DATA_BITS ( ( unsigned portCHAR ) 0x11 )
\r
71 #define ser1STOP_BIT ( ( unsigned portCHAR ) 0x111 )
\r
72 #define serSYSTEM_CLOCK ( ( unsigned portCHAR ) 0xdd )
\r
73 #define serTX_OUTPUT ( ( unsigned portCHAR ) 0x04 )
\r
74 #define serRX_INPUT ( ( unsigned portCHAR ) 0x08 )
\r
75 #define serTX_ENABLE ( ( unsigned portCHAR ) 0x04 )
\r
76 #define serRX_ENABLE ( ( unsigned portCHAR ) 0x01 )
\r
77 #define serTX_INT ( ( unsigned portCHAR ) 0x01 )
\r
78 #define serRX_INT ( ( unsigned portCHAR ) 0x02 )
\r
81 /* The queues used to communicate between tasks and ISR's. */
\r
82 static xQueueHandle xRxedChars;
\r
83 static xQueueHandle xCharsForTx;
\r
85 /* Flag used to indicate the tx status. */
\r
86 static portBASE_TYPE xTxHasEnded;
\r
88 /*-----------------------------------------------------------*/
\r
90 /* The UART interrupt handler. */
\r
91 void __attribute__( ( interrupt ) ) __cs3_isr_interrupt_78( void );
\r
93 /*-----------------------------------------------------------*/
\r
95 xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
97 const unsigned portLONG ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32 * ulWantedBaud ) );
\r
99 /* Create the queues used by the com test task. */
\r
100 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
101 xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
103 /* Set the pins to UART mode. */
\r
104 MCF_PAD_PUAPAR |= ( serTX_OUTPUT | serRX_INPUT );
\r
106 /* Configure the UART. */
\r
107 MCF_UART1_UMR1 = serNO_PARITY | ser8DATA_BITS;
\r
108 MCF_UART1_UMR2 = ser1STOP_BIT;
\r
109 MCF_UART1_UCSR = serSYSTEM_CLOCK;
\r
111 MCF_UART1_UBG1 = ( unsigned portCHAR ) ( ( ulBaudRateDivisor >> 8UL ) & 0xffUL );
\r
112 MCF_UART1_UBG2 = ( unsigned portCHAR ) ( ulBaudRateDivisor & 0xffUL );
\r
114 /* Reset the peripheral before turning it on. */
\r
115 MCF_UART1_UCR = MCF_UART_UCR_RESET_MR;
\r
116 MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;
\r
117 MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;
\r
118 MCF_UART1_UCR = MCF_UART_UCR_RESET_ERROR;
\r
119 MCF_UART1_UCR = serTX_ENABLE | serRX_ENABLE;
\r
121 /* Configure the interrupt controller. Run the UARTs above the kernel
\r
122 interrupt priority for demo purposes. */
\r
123 MCF_INTC0_ICR14 = ( ( configKERNEL_INTERRUPT_PRIORITY + 1 ) | ( 1 << 3 ) );
\r
124 MCF_INTC0_IMRL &= ~MCF_INTC_IMRL_INT_MASK14;
\r
126 /* The Tx interrupt is not enabled until there is data to send. */
\r
127 MCF_UART0_UIMR = serRX_INT;
\r
129 /* Only a single port is implemented so we don't need to return anything. */
\r
132 /*-----------------------------------------------------------*/
\r
134 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )
\r
136 /* Only one port is supported. */
\r
139 /* Get the next character from the buffer. Return false if no characters
\r
140 are available or arrive before xBlockTime expires. */
\r
141 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
150 /*-----------------------------------------------------------*/
\r
152 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )
\r
154 /* Only one port is supported. */
\r
157 /* Return false if after the block time there is no room on the Tx queue. */
\r
158 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
\r
163 /* A critical section should not be required as xTxHasEnded will not be
\r
164 written to by the ISR if it is already 0 (is this correct?). */
\r
167 xTxHasEnded = pdFALSE;
\r
168 MCF_UART0_UIMR = serRX_INT | serTX_INT;
\r
173 /*-----------------------------------------------------------*/
\r
175 void vSerialClose( xComPortHandle xPort )
\r
179 /*-----------------------------------------------------------*/
\r
181 void __cs3_isr_interrupt_78( void )
\r
183 unsigned portCHAR ucChar;
\r
184 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, xDoneSomething = pdTRUE;
\r
186 while( xDoneSomething != pdFALSE )
\r
188 xDoneSomething = pdFALSE;
\r
190 /* Does the tx buffer contain space? */
\r
191 if( ( MCF_UART0_USR & MCF_UART_USR_TXRDY ) != 0x00 )
\r
193 /* Are there any characters queued to be sent? */
\r
194 if( xQueueReceiveFromISR( xCharsForTx, &ucChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
196 /* Send the next char. */
\r
197 MCF_UART0_UTB = ucChar;
\r
198 xDoneSomething = pdTRUE;
\r
202 /* Turn off the Tx interrupt until such time as another character
\r
203 is being transmitted. */
204 MCF_UART0_UIMR = serRX_INT;
\r
208 if( MCF_UART0_USR & MCF_UART_USR_RXRDY )
\r
210 ucChar = MCF_UART0_URB;
\r
211 xQueueSendFromISR( xRxedChars, &ucChar, &xHigherPriorityTaskWoken );
\r
212 xDoneSomething = pdTRUE;
\r
216 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r