📄 sdc.c
字号:
{
status = NU_Allocate_Memory (&System_Memory,(VOID **)&uart->tx_buffer,
(2 * uart->sd_buffer_size),
NU_NO_SUSPEND);
/* Set the RX buffer to just past the TX buffer. */
uart->rx_buffer = (CHAR *)(uart->tx_buffer + uart->sd_buffer_size);
}
else
{
status = NU_Allocate_Memory (&System_Memory,(VOID **)&uart->tx_buffer,
uart->sd_buffer_size,
NU_NO_SUSPEND);
}
if (status == NU_SUCCESS)
{
/* Setup the RX SD buffer */
uart->rx_buffer_read = uart->rx_buffer_write = 0;
uart->rx_buffer_status = NU_BUFFER_EMPTY;
/* Setup the TX SD buffer */
uart->tx_buffer_read = uart->tx_buffer_write = 0;
uart->tx_buffer_status = NU_BUFFER_EMPTY;
}
}
if (status == NU_SUCCESS)
{
/* Disable interrupts */
int_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
/* Initialize the UART */
/************** Begin Port Specific Section *************/
/* Disable UART interrupts. */
SD_OUTBYTE(uart->base_address + SD_IER_OFFSET, 0x00);
/* Set the modem control register. Assert GPO2, RTS, and DTR. */
SD_OUTBYTE (uart->base_address + SD_MCR_OFFSET, (SD_INBYTE(uart->base_address + SD_MCR_OFFSET)
| SD_MCR_INT_ENABLE
| SD_MCR_DTR
| SD_MCR_RTS));
/* set the parity, stop bits, and char bits. */
SD_OUTBYTE (uart->base_address + SD_LCR_OFFSET,
(uart->parity | uart->data_bits | uart->stop_bits));
/* Setup baud rate */
SDC_Set_Baud_Rate(uart->baud_rate, uart);
/* Read receive register to get rid of any bad data. */
tByte = SD_INBYTE(uart->base_address + SD_DATA_OFFSET);
/* Read IIR register to flush it. */
tByte = SD_INBYTE(uart->base_address + SD_IIR_OFFSET);
/* Read the Line and Modem Status Registers to clear them.*/
tByte = SD_INBYTE(uart->base_address + SD_LSR_OFFSET);
tByte = SD_INBYTE(uart->base_address + SD_MSR_OFFSET);
/* Enable receive and error interrupts. */
SD_OUTBYTE(uart->base_address + SD_IER_OFFSET,
(SD_IER_ENABLE_RCV | SD_IER_ENABLE_ERROR));
/* Disable FIFO for 16550 */
SD_OUTBYTE(uart->base_address + SD_IIR_OFFSET, SD_IIR_FIFO_DISABLE);
/* Setup the interrupt controller - 82C59 */
if (uart->com_port == SD_UART1)
{
/* Enable the UART1 interrupt */
imr_val = SD_INBYTE (SD_BASE + SD_PIC1_BASE_OFFSET + SD_IMR_OFFSET);
imr_val &= ~(SD_IMR_UART1_MASK);
//SD_OUTBYTE (SD_BASE + SD_PIC1_BASE_OFFSET + SD_IMR_OFFSET, imr_val);
SD_OUTBYTE (SD_BASE + SD_PIC1_BASE_OFFSET + SD_IMR_OFFSET, 0x00);
}
else
{
/* Enable the UART2 interrupt */
imr_val = SD_INBYTE (SD_BASE + SD_PIC1_BASE_OFFSET + SD_IMR_OFFSET);
imr_val &= ~(SD_IMR_UART2_MASK);
//SD_OUTBYTE (SD_BASE + SD_PIC1_BASE_OFFSET + SD_IMR_OFFSET, imr_val);
SD_OUTBYTE (SD_BASE + SD_PIC1_BASE_OFFSET + SD_IMR_OFFSET, 0x00);
}
/* read the register to clear any interrupts */
tByte = SD_INBYTE(uart->base_address + SD_LSR_OFFSET);
/* read the PIC to clear any interrupts */
/* Send the PIC 'EOI' End of interrupt */
SD_OUTBYTE(SD_BASE + SD_PIC2_BASE_OFFSET, SD_PIC_EOI);
SD_OUTBYTE(SD_BASE + SD_PIC1_BASE_OFFSET, SD_PIC_EOI);
tByte = SD_INBYTE(SD_BASE + SD_PIC2_BASE_OFFSET);
tByte = SD_INBYTE(SD_BASE + SD_PIC1_BASE_OFFSET);
/* Configure the EPIC external interrupts */
epic_Open_Direct_Int(0, 0, 0, 1, 10, 0x24);
epic_Open_Direct_Int(1, 0, 0, 1, 11, 0x25);
epic_Open_Direct_Int(2, 0, 0, 1, 12, 0x26);
epic_Open_Direct_Int(3, 0, 0, 1, 13, 0x27);
/* Set the process priority to 0 to allow the epic to interrupt */
eumbbar = epic_Read_Config_Word(0x00000078);
temp = epic_EUMB_Read_Word(eumbbar+0x60080);
epic_EUMB_Write_Word(eumbbar+0x60080, 0x00000000);
/************** End Port Specific Section *************/
/* Initialize the error counters. */
uart->parity_errors =
uart->frame_errors =
uart->overrun_errors =
uart->busy_errors =
uart->general_errors = 0;
/* Restore interrupts to previous level */
NU_Local_Control_Interrupts(int_level);
}
return (status);
}
/***************************************************************************
* FUNCTION
*
* SDC_Put_Char
*
* DESCRIPTION
*
* This writes a character out to the serial port.
*
* INPUTS
*
* UINT8 : Character to to be written to the serial port.
* SD_PORT * : Serial port to send the char to.
*
* OUTPUTS
*
* none
*
****************************************************************************/
VOID SDC_Put_Char(UINT8 ch, SD_PORT *uart)
{
INT int_level; /* old interrupt level */
INT i;
#ifdef GRAFIX_MOUSE
if ((uart->communication_mode == SERIAL_MODE) ||
(uart->communication_mode == SERIAL_MOUSE))
#else
if (uart->communication_mode == SERIAL_MODE)
#endif
{
/* If the buffer is full wait for it to empty a little. */
while (uart->tx_buffer_status == NU_BUFFER_FULL)
for (i=1; i<1000; i++);
/* Disable interrupts */
int_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
/* Check the transmit buffer status. If it has data already
just add this byte to the buffer. */
if (( uart->tx_buffer_status == NU_BUFFER_DATA) ||
( uart->tx_buffer_status == NU_BUFFER_FULL) )
{
/* Add byte to buffer. */
uart->tx_buffer[uart->tx_buffer_write++] = ch;
/* Check for wrap of buffer. */
if(uart->tx_buffer_write == uart->sd_buffer_size)
uart->tx_buffer_write = 0;
/* Check for full buffer. */
if (uart->tx_buffer_write == uart->tx_buffer_read)
uart->tx_buffer_status = NU_BUFFER_FULL;
/* Restore interrupts to previous level */
NU_Local_Control_Interrupts(int_level);
}
else
{
/* Otherwise send the data. */
/* Restore interrupts to previous level */
NU_Local_Control_Interrupts(int_level);
/* Add byte to buffer */
uart->tx_buffer[uart->tx_buffer_write++] = ch;
/* Check for wrap of buffer */
if(uart->tx_buffer_write == uart->sd_buffer_size)
uart->tx_buffer_write = 0;
/* Set status */
uart->tx_buffer_status = NU_BUFFER_DATA;
/**************** Begin Port Specific Section **************/
/* Transmit the character */
SD_OUTBYTE (uart->base_address + SD_DATA_OFFSET, ch);
/* Unmask the TX interrupt. */
SD_OUTBYTE (uart->base_address + SD_IER_OFFSET,
(SD_INBYTE(uart->base_address + SD_IER_OFFSET)
| SD_IER_ENABLE_TX));
}
} /* end if SERIAL_MODE (||SERIAL_MOUSE) mode */
else /* PPP mode */
{
/* Wait until the transmitter buffer is empty */
while (! (SD_INBYTE (uart->base_address + SD_LSR_OFFSET)
& SD_LSR_TXRDY));
/* Transmit the character */
SD_OUTBYTE (uart->base_address + SD_DATA_OFFSET, ch);
#ifndef PPP_POLLED_TX
SD_OUTBYTE (uart->base_address + SD_IER_OFFSET,
(SD_INBYTE(uart->base_address + SD_IER_OFFSET)
| SD_IER_ENABLE_TX));
#endif /* PPP_POLLED_TX */
} /* end else PPP mode */
/***************** End Port Specific Section ***************/
}
/****************************************************************************/
/* FUNCTION */
/* */
/* SDC_LISR */
/* */
/* DESCRIPTION */
/* */
/* This is the entry function for the ISR that services the UART. */
/* */
/* CALLED BY */
/* */
/* none */
/* */
/* CALLS */
/* */
/* Serial port macros */
/* */
/* INPUTS */
/* */
/* INT : Interrupt vector */
/* */
/* OUTPUTS */
/* */
/* none */
/* */
/****************************************************************************/
static VOID SDC_LISR(INT vector)
{
SD_PORT *uart;
CHAR receive;
INT vector_found = NU_FALSE;
/***************** Begin Port Specific Section ***************/
CHAR lsr, iir; /* 16550 registers */
CHAR ch;
/****************** End Port Specific Section ****************/
#ifdef NU_ENABLE_PPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -