📄 sdc.c
字号:
/* 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 *************/ /* Clear everything */ SD_OUTBYTE (uart->base_address + SD_CR_OFFSET, 0x0); /* Setup baud rate */ SDC_Set_Baud_Rate(uart->baud_rate, uart); /* Setup parity, data bits, and stop bits */ SD_OUTBYTE (uart->base_address + SD_LCRH_OFFSET, (uart->parity | uart->data_bits | uart->stop_bits | SD_ENABLE_FIFO)); /* Enable UART and receive interrupts */ SD_OUTBYTE (uart->base_address + SD_CR_OFFSET, (SD_CR_UART_ENABLE | SD_CR_RX_ENABLE | SD_CR_RX_TO_ENABLE)); /* Clear all pending bits */ SD_OUTBYTE (uart->base_address+ SD_I_CR_OFFSET, SD_I_CR_INT_CLEAR); /* Get the IRQ base value offset */ irq_base_offset = ((SD_INDWORD(SD_CM_STAT) & SD_CM_STAT_MASK) << SD_CM_OFFSET_SHIFT); /* Set the interrupt bit */ if (uart->com_port == SD_UART0) { SD_OUTWORD ((SD_INT_ENABLE | irq_base_offset), SD_INT_UART0); } else /* Otherwise handle UART1. */ { SD_OUTWORD ((SD_INT_ENABLE | irq_base_offset), SD_INT_UART1); } /************** 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 to user mode */ NU_USER_MODE(); 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){ UINT32 int_level; /* old interrupt level */ /************** Begin Port Specific Section *************/ UINT8 temp_byte; NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE_ISR(); /************** End Port Specific Section *************/ #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); /* 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) { /* 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. */ /* 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; /* Restore interrupts to previous level */ NU_Local_Control_Interrupts(int_level); /**************** Begin Port Specific Section **************/ /* Wait until the transmitter FIFO is empty */ while (!(SD_INBYTE (uart->base_address + SD_FR_OFFSET) & SD_FR_TXFE)); /* Transmit the character */ SD_OUTBYTE (uart->base_address + SD_DR_OFFSET, ch); /* Unmask the TX interrupt. */ temp_byte = SD_INBYTE (uart->base_address + SD_CR_OFFSET); temp_byte |= SD_CR_TX_ENABLE; SD_OUTBYTE (uart->base_address + SD_CR_OFFSET, temp_byte); } } /* endif mode */ else { /* Wait until the transmitter FIFO is empty */ while (!(SD_INBYTE (uart->base_address + SD_FR_OFFSET) & SD_FR_TXFE)); /* Transmit the character */ SD_OUTBYTE (uart->base_address + SD_DR_OFFSET, ch);#ifndef PPP_POLLED_TX temp_byte = SD_INBYTE (uart->base_address + SD_CR_OFFSET); temp_byte |= SD_CR_TX_ENABLE; SD_OUTBYTE (uart->base_address + SD_CR_OFFSET, temp_byte); #endif } /***************** End Port Specific Section ***************/ /* Return to user mode */ NU_USER_MODE_ISR();}/**************************************************************************** FUNCTION * * SDC_LISR * * DESCRIPTION * * This is the entry function for the ISR that services the UARTs* on the ARM Integrator* * INPUTS * * INT : Interrupt vector * * OUTPUTS * * none * ****************************************************************************/VOID SDC_LISR(INT vector){ SD_PORT *uart; CHAR receive = 0; INT vector_found = NU_FALSE; UINT8 iir_status; UINT8 temp_byte;#ifdef NU_ENABLE_PPP DV_DEVICE_ENTRY *device;#endif /* NU_ENABLE_PPP */ /* Find the port stucture for this vector. */ while ((SDC_Port_List[receive] != NU_NULL) && (SDC_Port_List[receive] -> vector != vector) && (receive < SD_MAX_UARTS) ) receive++; /* See if we found one. Better have since we got an interrupt from one. */ if (SDC_Port_List[receive] -> vector == vector) { /* Point our local structure to it. */ uart = SDC_Port_List[receive]; vector_found = NU_TRUE; }#ifdef NU_ENABLE_PPP else { /* Find the device for this interrupt */ if ( (device = DEV_Get_Dev_For_Vector(vector)) != NU_NULL) { /* Get the address of the uart structure for this device. */ uart = &((PPP_LAYER *) device->ppp_layer)->uart; vector_found = NU_TRUE; } } #endif /* NU_ENABLE_PPP */ if (vector_found == NU_TRUE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -