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

📄 sdc.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 3 页
字号:
            uart -> buffer.read = uart -> buffer.head;

        /* Set the status to reflect removal of the character */
        if (uart -> buffer.write == uart -> buffer.read)
            uart -> buffer.status = NU_SD_BUFFER_EMPTY;
        else
            uart -> buffer.status = NU_SD_BUFFER_DATA;
    }

    return (ch);

}

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SDC_Data_Ready                                                        */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function checks to see if there are any characters in the        */
/*    receive buffer.  A status value is returned indicating whether        */
/*    characters are present in the receive buffer.                         */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    Application                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    SD_PORT *      :   Serial port to check for data.                     */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    STATUS                                The status indicates the        */
/*                                          presence of characters.         */
/*                                                                          */
/****************************************************************************/
STATUS SDC_Data_Ready(SD_PORT *port)
{
    if((port -> buffer.status == NU_SD_BUFFER_FULL) ||
       (port -> buffer.status == NU_SD_BUFFER_DATA))
        return NU_TRUE;
    else
        return NU_FALSE;
}

/****************************************************************************/
/* 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;

    /* Find the port stucture for this vector. */
    receive = 0;
    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];

        /* Process every character in the receive FIFO */
        while (SD_INBYTE ((uart -> base_address + URX_REGS)) & SD_RX_DATA_READY)
        {

            /* Check for a damaged or incorrectly received character */
            if (SD_INBYTE ((uart -> base_address + URX_REGS))
                           & (SD_RX_FRAME_ERROR | SD_RX_PARITY_ERROR))
            {
                if (SD_INBYTE ((uart->base_address + URX_REGS))
                               & SD_RX_FRAME_ERROR)
                    uart -> frame_errors++;

                if (SD_INBYTE (uart -> base_address + URX_REGS)
                               & SD_RX_PARITY_ERROR)
                    uart -> parity_errors++;

                /* Consume the character to clear the error bits */
                receive = SD_INBYTE((uart->base_address + URX));
            }
            else
            {
                /* If an overrun has occured, log it */
                if (SD_INBYTE ((uart -> base_address + URX_REGS))
                               & SD_RX_OVER_RUN)
                    uart -> overrun_errors++;

                /* Put char into buffer */
                receive = SD_INBYTE ((uart ->base_address + URX));

                if (uart -> buffer.status != NU_SD_BUFFER_FULL)
                {
                    /* Put the character into the buffer */
                    *(uart -> buffer.write++) = receive;

                    /* If write pointer is at end, wrap it around */
                    if (uart -> buffer.write > uart -> buffer.tail)
                        uart -> buffer.write = uart -> buffer.head;

                    /* Set status field based on latest character */
                    if (uart -> buffer.write == uart -> buffer.read)
                        uart -> buffer.status = NU_SD_BUFFER_FULL;
                    else
                        uart -> buffer.status = NU_SD_BUFFER_DATA;
                }
            }
        }
    }
}


/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SDC_Set_Baud_Rate                                                     */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function sets the UART buad rate.                                */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    SDC_Init_Port                                                         */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    Serial port macros                                                    */
/*    NU_Local_Control_Interrupts                                           */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UNSIGNED      :  The new baud rate.                                   */
/*    SD_PORT *     :  Serial port to set the baud rate.                    */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/****************************************************************************/
static VOID  SDC_Set_Baud_Rate(UNSIGNED baud_rate, SD_PORT *uart)
{

    short  value;


    /* Set the baud rate */
    if ((baud_rate >= 300) || (baud_rate <= 390625))
    {

        switch(baud_rate)
        {
        case 115200:
            value= SD_BAUD_115200;
            break;
        case 57600:
            value= SD_BAUD_57600;
            break;
        case 38400:
            value= SD_BAUD_38400;
            break;
        case 19200:
            value= SD_BAUD_19200;
            break;
        case 9600:
            value= SD_BAUD_9600;
            break;
        case 4800:
            value= SD_BAUD_4800;
            break;
        case 2400:
            value= SD_BAUD_2400;
            break;
        case 1200:
            value= SD_BAUD_1200;
            break;
        case 600:
            value= SD_BAUD_600;
            break;
        case 300:
            value= SD_BAUD_300;
            break;
        }
        /*  Ouput the Baud Rate */
        SD_OUTWORD((uart->base_address+UBAUDC),value);
    }

}

⌨️ 快捷键说明

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