⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdc.c

📁 test file nucleus source
💻 C
📖 第 1 页 / 共 4 页
字号:
        /**************** Begin Port Specific Section **************/        /* Get the interrupt status and clear all pending interrupts */        iir_status = SD_INBYTE (uart->base_address + SD_IIR_OFFSET);        SD_OUTBYTE (uart->base_address + SD_I_CR_OFFSET, SD_I_CR_INT_CLEAR);        /* Check for receive interrupts (timeout / FIFO level reached) */        if (iir_status & (SD_IIR_RX_INT | SD_IIR_RXTO_INT))        {            /* Process every character in the receive FIFO */            do             {                switch(uart->communication_mode)                {                    case SERIAL_MODE: #ifdef GRAFIX_MOUSE                    case SERIAL_MOUSE: #endif                        /* Get the character and check for error bits */                        receive = SD_INBYTE (uart->base_address + SD_DR_OFFSET);                        /* Get receive status register value */                        temp_byte = SD_INBYTE (uart->base_address + SD_RSR_OFFSET);                        /* Remove any error flags */                        SD_OUTBYTE (uart->base_address + SD_ECR_OFFSET, SD_ECR_RST_ERR_STAT);                        /* Check for a damaged or incorrectly received character */                        if (temp_byte & (SD_RSR_FRAME_ERR | SD_RSR_PARITY_ERR))                        {                            /* Increment necessary counters */                            uart->frame_errors += ((temp_byte & SD_RSR_FRAME_ERR) == SD_RSR_FRAME_ERR);                            uart->parity_errors += ((temp_byte & SD_RSR_PARITY_ERR) == SD_RSR_PARITY_ERR);                        }                        else                        {                            /* If an overrun has occured, log it */                            if (temp_byte & SD_RSR_OVERRUN)                            {                                uart->overrun_errors++;                            }                            /* Ensure receive buffer isn't full */                            if (uart->rx_buffer_status != NU_BUFFER_FULL)                            {                                /* Put the character into the buffer */                                uart->rx_buffer[uart->rx_buffer_write++] = receive;                                                     /* If write pointer is at end, wrap it around */                                if(uart->rx_buffer_write == uart->sd_buffer_size)                                    uart->rx_buffer_write = 0;                                                                    /* Set status field based on latest character */                                if (uart->rx_buffer_write == uart->rx_buffer_read)                                    uart->rx_buffer_status = NU_BUFFER_FULL;                                else                                    uart->rx_buffer_status = NU_BUFFER_DATA;                            }                            else                                uart->busy_errors++;#ifdef GRAFIX_MOUSE                             /* Check if this is a mouse port */                            if(uart->communication_mode == SERIAL_MOUSE)                                 NU_Activate_HISR (&Mouse_HISR);#endif                        }                    break;                    #ifdef NU_ENABLE_PPP                                                /* call PPP processing functions */                    case MDM_NETWORK_COMMUNICATION:                        /* Call this devices receive routine */                        device->dev_receive(device);                    break;                    case MDM_TERMINAL_COMMUNICATION:                        default:                        MDM_Receive(device);                    break;#endif /* NU_ENABLE_PPP */                 }             /* Loop until receive FIFO empty */            } while ( !(SD_INBYTE(uart->base_address + SD_FR_OFFSET) & SD_FR_RXFE ) );        } /* RX Interrupt */        /* Check for a transmit interrupt */        if (iir_status & SD_IIR_TX_INT)        {#ifdef GRAFIX_MOUSE            if ((uart->communication_mode == SERIAL_MODE) ||                (uart->communication_mode == SERIAL_MOUSE))#else            if (uart->communication_mode == SERIAL_MODE)#endif            {                    /* Bump the read pointer past the byte that was just                   transmitted. */                ++(uart->tx_buffer_read);                                /* Check for wrap of buffer. */                if (uart->tx_buffer_read == uart->sd_buffer_size)                    uart->tx_buffer_read = 0;                /* Update the status. */                if (uart->tx_buffer_write == uart->tx_buffer_read)                {                    uart->tx_buffer_status = NU_BUFFER_EMPTY;                    /* Since it is now empty turn off the TX                       interrupt, we do not need it anymore. */                    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);                }                else                {                    /* Wait until the transmitter FIFO is empty */                    while (!(SD_INBYTE (uart->base_address + SD_FR_OFFSET) & SD_FR_TXFE));                                /* Send the next byte in the queue. */                    SD_OUTBYTE (uart->base_address + SD_DR_OFFSET,                          uart->tx_buffer[uart->tx_buffer_read]);                    /* Update the status. */                    uart->tx_buffer_status = NU_BUFFER_DATA;                }            }#ifdef NU_ENABLE_PPP            else            {                /* Check for a transmit interrupt. */                /* Is there another byte in the TX buffer to send? */                if (uart->tx_buffer_read != uart->tx_buffer_write)                {                    /* Wait until the transmitter FIFO is empty */                    while (!(SD_INBYTE (uart->base_address + SD_FR_OFFSET) & SD_FR_TXFE));                                /* Send the next byte in the queue. */                    SD_OUTBYTE (uart->base_address + SD_DR_OFFSET,                                uart->tx_buffer[uart->tx_buffer_read++]);                                             /* Check for wrap of ring buffer. */                    if(uart->tx_buffer_read == uart->sd_buffer_size)                        uart->tx_buffer_read = 0;                }                else                {#ifndef PPP_POLLED_TX                    /* Since it is now empty turn off the TX                       interrupt, we do not need it anymore. */                    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);                    /* Only activate the HISR if we are tranmitting                       network data. */                    if (uart->communication_mode == MDM_NETWORK_COMMUNICATION)                    {                        /* Add this device to the list of PPP devices that have finished                           sending a packet. */                        _ppp_tx_dev_ptr_queue [_ppp_tx_dev_ptr_queue_write++] = device;                        /* Activate the HISR that will take care of processing the                           next packet in queue, if one is ready. */                        NU_Activate_HISR (&PPP_TX_HISR);                        /* Check for wrap of ring buffer. */                        _ppp_tx_dev_ptr_queue_write %= PPP_MAX_TX_QUEUE_PTRS;                    }#endif                }            }#endif /* NU_ENABLE_PPP */        }                /**************** End Port Specific Section **************/        }    else     {        /* No port is associated with the vector */        ERC_System_Error(NU_UNHANDLED_INTERRUPT);    }   }/***************************************************************************** FUNCTION                                                                 *                                                                          *    SDC_Set_Baud_Rate                                                     *                                                                          * DESCRIPTION                                                              *                                                                          *    This function sets the UART buad rate.                                *                                                                          * INPUTS                                                                  *                                                                         *    UINT32      :  The new baud rate.                                  *    SD_PORT *     :  Serial port to set the baud rate.                   *                                                                         * OUTPUTS                                                                 *                                                                         *    none                                                                 *                                                                         ****************************************************************************/static VOID  SDC_Set_Baud_Rate(UINT32 baud_rate, SD_PORT *uart){    UINT16    baud_div;           /* baud rate divisor */        /**************** Begin Port Specific Section **************/    /* Set the baud rate */    baud_div = (UART_CLOCK / (16 * baud_rate)) - 1;    SD_OUTBYTE (uart->base_address + SD_LCRM_OFFSET,               (UINT8)(baud_div >> 8));    SD_OUTBYTE (uart->base_address + SD_LCRL_OFFSET,               (UINT8)(baud_div));    /**************** End Port Specific Section ****************/}/***************************************************************************** FUNCTION                                                                 *                                                                          *    SDC_Get_Char                                                          *                                                                          * DESCRIPTION                                                              *                                                                          *    This function reads the last received character from the UART.        *                                                                          * INPUTS                                                                   *                                                                          *    SD_PORT *      :   Serial port to get the char from.                  *                                                                          * OUTPUTS                                                                  *                                                                          *    CHAR  :  Character read                                               *                                                                          ****************************************************************************/CHAR  SDC_Get_Char(SD_PORT *uart){    CHAR    ch = NU_NULL;    NU_SUPERV_USER_VARIABLES        /* Switch to supervisor mode */    NU_SUPERVISOR_MODE_ISR();    #ifdef GRAFIX_MOUSE    if ((uart->communication_mode == SERIAL_MODE) ||        (uart->communication_mode == SERIAL_MOUSE))#else    if (uart->communication_mode == SERIAL_MODE)#endif    {        if ((uart->rx_buffer_status == NU_BUFFER_FULL) ||            (uart->rx_buffer_status == NU_BUFFER_DATA))        {            /* Store the character to be returned */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -