#include "serial.h"\r
\r
/* Hardware definitions. */\r
-#define serNO_PARITY ( ( unsigned portCHAR ) 0x10 << 3 )\r
-#define ser8DATA_BITS ( ( unsigned portCHAR ) 0x11 )\r
-#define ser1STOP_BIT ( ( unsigned portCHAR ) 0x111 )\r
+#define serNO_PARITY ( ( unsigned portCHAR ) 0x02 << 3 )\r
+#define ser8DATA_BITS ( ( unsigned portCHAR ) 0x03 )\r
+#define ser1STOP_BIT ( ( unsigned portCHAR ) 0x07 )\r
#define serSYSTEM_CLOCK ( ( unsigned portCHAR ) 0xdd )\r
#define serTX_OUTPUT ( ( unsigned portCHAR ) 0x04 )\r
#define serRX_INPUT ( ( unsigned portCHAR ) 0x08 )\r
static xQueueHandle xCharsForTx;\r
\r
/* Flag used to indicate the tx status. */\r
-static portBASE_TYPE xTxHasEnded;\r
+static portBASE_TYPE xTxHasEnded = pdTRUE;\r
\r
/*-----------------------------------------------------------*/\r
\r
\r
xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
{\r
-const unsigned portLONG ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32 * ulWantedBaud ) );\r
+const unsigned portLONG ulBaudRateDivisor = ( configCPU_CLOCK_HZ / ( 32UL * ulWantedBaud ) );\r
\r
/* Create the queues used by the com test task. */\r
xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );\r
xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );\r
\r
+ xTxHasEnded = pdTRUE;\r
+\r
/* Set the pins to UART mode. */\r
MCF_PAD_PUAPAR |= ( serTX_OUTPUT | serRX_INPUT );\r
\r
+ /* Reset the peripheral. */\r
+ MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;\r
+ MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;\r
+ MCF_UART1_UCR = MCF_UART_UCR_RESET_ERROR;\r
+ MCF_UART1_UCR = MCF_UART_UCR_RESET_BKCHGINT;\r
+ MCF_UART1_UCR = MCF_UART_UCR_RESET_MR | MCF_UART_UCR_RX_DISABLED | MCF_UART_UCR_TX_DISABLED;\r
+\r
/* Configure the UART. */\r
MCF_UART1_UMR1 = serNO_PARITY | ser8DATA_BITS;\r
MCF_UART1_UMR2 = ser1STOP_BIT;\r
MCF_UART1_UBG1 = ( unsigned portCHAR ) ( ( ulBaudRateDivisor >> 8UL ) & 0xffUL );\r
MCF_UART1_UBG2 = ( unsigned portCHAR ) ( ulBaudRateDivisor & 0xffUL );\r
\r
- /* Reset the peripheral before turning it on. */\r
- MCF_UART1_UCR = MCF_UART_UCR_RESET_MR;\r
- MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;\r
- MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;\r
- MCF_UART1_UCR = MCF_UART_UCR_RESET_ERROR;\r
+ /* Turn it on. */\r
MCF_UART1_UCR = serTX_ENABLE | serRX_ENABLE;\r
\r
/* Configure the interrupt controller. Run the UARTs above the kernel\r
interrupt priority for demo purposes. */\r
MCF_INTC0_ICR14 = ( ( configKERNEL_INTERRUPT_PRIORITY + 1 ) | ( 1 << 3 ) );\r
- MCF_INTC0_IMRL &= ~MCF_INTC_IMRL_INT_MASK14;\r
+ MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK14 | 0x01 );\r
\r
/* The Tx interrupt is not enabled until there is data to send. */\r
- MCF_UART0_UIMR = serRX_INT;\r
+ MCF_UART1_UIMR = serRX_INT;\r
\r
/* Only a single port is implemented so we don't need to return anything. */\r
return NULL;\r
\r
/* A critical section should not be required as xTxHasEnded will not be\r
written to by the ISR if it is already 0 (is this correct?). */\r
- if( xTxHasEnded )\r
+ if( xTxHasEnded != pdFALSE )\r
{\r
xTxHasEnded = pdFALSE;\r
- MCF_UART0_UIMR = serRX_INT | serTX_INT;\r
+ MCF_UART1_UIMR = serRX_INT | serTX_INT;\r
}\r
\r
return pdPASS;\r
xDoneSomething = pdFALSE;\r
\r
/* Does the tx buffer contain space? */\r
- if( ( MCF_UART0_USR & MCF_UART_USR_TXRDY ) != 0x00 )\r
+ if( ( MCF_UART1_USR & MCF_UART_USR_TXRDY ) != 0x00 )\r
{\r
/* Are there any characters queued to be sent? */\r
if( xQueueReceiveFromISR( xCharsForTx, &ucChar, &xHigherPriorityTaskWoken ) == pdTRUE )\r
{\r
/* Send the next char. */\r
- MCF_UART0_UTB = ucChar;\r
+ MCF_UART1_UTB = ucChar;\r
xDoneSomething = pdTRUE;\r
}\r
else\r
{\r
/* Turn off the Tx interrupt until such time as another character\r
is being transmitted. */
- MCF_UART0_UIMR = serRX_INT;\r
+ MCF_UART1_UIMR = serRX_INT;\r
+ xTxHasEnded = pdTRUE;\r
}\r
}\r
\r
- if( MCF_UART0_USR & MCF_UART_USR_RXRDY )\r
+ if( MCF_UART1_USR & MCF_UART_USR_RXRDY )\r
{\r
- ucChar = MCF_UART0_URB;\r
+ ucChar = MCF_UART1_URB;\r
xQueueSendFromISR( xRxedChars, &ucChar, &xHigherPriorityTaskWoken );\r
xDoneSomething = pdTRUE;\r
}\r