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

📄 sdc.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 3 页
字号:

        /*  Set Configuration Up to do the following:
            1. Enable the UART
            2. Enable the Receiver
            3. Set the Parity Type(Even or ODD )
            4. Set Parity Enabled 
            5. Set the Stop Bits
            6. Set the Data Bits
            7.  Set the RX Ready Interrupt.
            */

        SD_OUTWORD((uart->base_address+USCREG),SD_UART_ENABLE|SD_RX_ENABLE|parity|parity_enabled|
                   stop_bits|data_bits|SD_RX_READY_EN);

        /*  Must Flush the RX Fifo to Initialize for the Receive */

        SD_Flush_Rx_FIFO(uart);

        /*  Set the Interrupt vector in the 68EZ328 Interrupt Vector Address
         *  Note that the UART is a LEVEL 4 vector and you must add 4 to the base
         *  vector to get the actual vector.
         */
        SD_OUTBYTE ((uart->base_address + IVR), SD_UART_VECTOR);

        /*  UnMask the Interrupt Vector for the UART */
        SD_OUTBYTE ((uart->base_address + IMR+3), (SD_INBYTE((uart->base_address + IMR+3)) & 0xFB));

        /* Initialize the error counters. */
        uart -> parity_errors   =
        uart -> frame_errors    =
        uart -> overrun_errors  = 0;

        /*  Clear the Parallel Port E Selection Register Bits 4 and 5
            for TXD and RXD */

        BCLR(PESEL,BIT5|BIT4);
    
        /*  Enable the Transmitter */
        SD_OUTWORD((uart->base_address+USCREG),SD_INWORD((uart->base_address+USCREG)) |SD_TX_ENABLE);

        /* Restore interrupts to previous level */
        NU_Local_Control_Interrupts(int_level);

    }
    else if (status == NU_SUCCESS)
        status = NU_SD_UART_LIST_FULL;

    return (status);
}
/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SD_Send_Break                                                         */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    Sends a Break                                                         */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    SDC_Init_Port                                                         */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    Serial port macros                                                    */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    none                                                                  */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    NU_SUCCESS                                                            */
/*                                                                          */
/****************************************************************************/

STATUS SD_Send_Break(SD_PORT *uart)
{

  SD_OUTBYTE((uart->base_address+UTX_REGS),(SD_INBYTE((uart->base_address+UTX_REGS)) | SD_TX_SEND_BREAK));
  return NU_SUCCESS;

}
/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SD_Flush_Rx_FIFO                                                      */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    Flushes the Receive FIFO upon INitialization                          */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    SDC_Init_Port                                                         */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    Serial port macros                                                    */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    none                                                                  */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    NU_SUCCESS                                                            */
/*                                                                          */
/****************************************************************************/
STATUS SD_Flush_Rx_FIFO(SD_PORT *uart)
{
    volatile unsigned short vl;
    vl=SD_INWORD((uart->base_address+URX_REGS));
    return NU_SUCCESS;
}
/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SDC_Put_Char                                                          */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This writes a character out to the serial port.                       */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    UART_Put_String                                                       */
/*    Applicatoin                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    Serial port macros                                                    */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UNSIGNED_CHAR :   Character to to be written to the serial port.      */
/*    SD_PORT *     :   Serial port to send the char to.                    */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/****************************************************************************/
VOID  SDC_Put_Char(UNSIGNED_CHAR ch, SD_PORT *uart)
{

    volatile unsigned char temp,temp1;
    int i;
    /* Wait until the transmitter buffer is empty */
    while (! (SD_INBYTE ((uart -> base_address + UTX_REGS)) & SD_TX_AVAIL));

    /* Transmit the character */
    SD_OUTBYTE ((uart->base_address + UTX), ch);

}

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SDC_Put_String                                                        */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This writes a null-terminated string out to the serial port.          */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    Application                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    SDC_Put_Char                                                          */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    CHAR *        :   String to be written to the serial port.            */
/*    SD_PORT *     :   Serial port to send the string to.                  */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/****************************************************************************/
VOID SDC_Put_String(CHAR *str, SD_PORT *uart)
{
    for (; *str != 0; str++)
        SDC_Put_Char(*str, uart);
}

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    SDC_Get_Char                                                          */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function reads the last received character from the UART.        */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    Application                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/* 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;

    if ((uart -> buffer.status == NU_SD_BUFFER_FULL) ||
        (uart -> buffer.status == NU_SD_BUFFER_DATA))
    {
        /* Store the character to be returned */
        ch = *(uart -> buffer.read++);

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

⌨️ 快捷键说明

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