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

📄 sdc.c

📁 S3C2410上RS485驱动源码,用ADS1.2编译工程,已测试通过.内附文档.
💻 C
📖 第 1 页 / 共 2 页
字号:
                SD_OUTDWORD(uart->base_address + SD_UERSTAT_OFFSET,status);

                /* Get the received character from the receive holding register */
                receive = (UINT8)SD_INDWORD(uart->base_address + SD_URXH_OFFSET);

                /* Check for parity / framing error */
                if (status & (SD_UERSTAT_FRAME | SD_UERSTAT_OVERRUN))
                {
                    /* Update error counts as necessary */
                    uart->frame_errors+=((status & SD_UERSTAT_FRAME)==SD_UERSTAT_FRAME);
                    uart->parity_errors+=((status & SD_UERSTAT_PARITY)==SD_UERSTAT_PARITY);
                }
                else
                {
                    /* Update overrun error count as necessary */
                    uart->overrun_errors+=((status & SD_UERSTAT_OVERRUN)==SD_UERSTAT_OVERRUN);

                    /* Execute based on mode */
                    switch(uart->communication_mode)
                    {
                        case SERIAL_MODE:

                            /* Check if the receive buffer is full */
                            if (uart->rx_buffer_status != NU_BUFFER_FULL)
                            {
                               /* Put the character into the buffer */
                               uart->rx_buffer[uart->rx_buffer_write++] = receive;
                               /*显示字符*/
                               SDC_Put_Char(receive,uart);

                               /* Check for wrap of buffer. */
                               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
                                /* buffer is full, increment busy errors */
                                uart->busy_errors++;
                        break;

                    }

                }

                /* Get UART status */
                status = SD_INDWORD (uart->base_address + SD_UTRSTAT_OFFSET);

            /* Keep looping while receive data ready */
            } while (status & SD_USTAT_RX_RDY);

            /**************** End Board Specific Section **************/
        }


         }
        temp = rSUBSRCPND;
        rSUBSRCPND=temp;
	temp = rSRCPND;
	rSRCPND = temp;
	temp = rINTPND;
	rINTPND = temp;

  
   
 }

void __irq SDC_LISR2(void)
{
    SD_PORT         *uart;
    CHAR            receive;
    UINT32          status;
    INT             vector_found,temp;
	
    	
   
    vector_found = TRUE;
    uart = SDC_Port_List[2];
    /* Ensure vector was found */
    if (vector_found == TRUE)
    {
        /**************** Begin Board Specific Section **************/

        /* Get the uart status */
        status = SD_INDWORD(uart->base_address + SD_UTRSTAT_OFFSET);

        /* Check if receiver is ready - characters received */
        if (status & SD_USTAT_RX_RDY)
        {
            /* Get UART error status */
            status = SD_INDWORD (uart->base_address + SD_UERSTAT_OFFSET);

            /* Process every character in the receive FIFO */
            do
            {
                /* Clear any error bits */
                SD_OUTDWORD(uart->base_address + SD_UERSTAT_OFFSET,status);

                /* Get the received character from the receive holding register */
                receive = (UINT8)SD_INDWORD(uart->base_address + SD_URXH_OFFSET);

                /* Check for parity / framing error */
                if (status & (SD_UERSTAT_FRAME | SD_UERSTAT_OVERRUN))
                {
                    /* Update error counts as necessary */
                    uart->frame_errors+=((status & SD_UERSTAT_FRAME)==SD_UERSTAT_FRAME);
                    uart->parity_errors+=((status & SD_UERSTAT_PARITY)==SD_UERSTAT_PARITY);
                }
                else
                {
                    /* Update overrun error count as necessary */
                    uart->overrun_errors+=((status & SD_UERSTAT_OVERRUN)==SD_UERSTAT_OVERRUN);

                    /* Execute based on mode */
                    switch(uart->communication_mode)
                    {
                        case SERIAL_MODE:

                            /* Check if the receive buffer is full */
                            if (uart->rx_buffer_status != NU_BUFFER_FULL)
                            {
                               /* Put the character into the buffer */
                               uart->rx_buffer[uart->rx_buffer_write++] = receive;
                               /*显示字符*/
                               SDC_Put_Char(receive,uart);

                               /* Check for wrap of buffer. */
                               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
                                /* buffer is full, increment busy errors */
                                uart->busy_errors++;
                        break;

                    }

                }

                /* Get UART status */
                status = SD_INDWORD (uart->base_address + SD_UTRSTAT_OFFSET);

            /* Keep looping while receive data ready */
            } while (status & SD_USTAT_RX_RDY);

            /**************** End Board Specific Section **************/
        }


         }
        temp = rSUBSRCPND;
        rSUBSRCPND=temp;
	temp = rSRCPND;
	rSRCPND = temp;
	temp = rINTPND;
	rINTPND = temp;

  
   
 }



/****************************************************************************
* 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)
{
    UINT32  baud_div;           /* baud rate divisor */


    /**************** Begin Board Specific Section **************/

    /* Update baud rate in uart structure */
    uart->baud_rate = 115200;
    //uart->baud_rate = 57600;  /*如果baud_div = 0x36*/

    /* Calculate the baud rate divisor */
    baud_div =0x1B;
    
    //baud_div = 0x36;

    /* Put baud rate divisor in baud divisor register */
    SD_OUTDWORD (uart->base_address + SD_UBRDIV_OFFSET, baud_div);

    /**************** End Board Specific Section ****************/

}


/****************************************************************************
* 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 = 0;
     if (uart->communication_mode == SERIAL_MODE)
    {
        if (uart->rx_buffer_status != NU_BUFFER_EMPTY)
        {
            /* Store the character to be returned */
            ch = uart->rx_buffer[uart->rx_buffer_read++];
         
            /* If read pointer is at end, wrap it around */
            if (uart->rx_buffer_read == uart->sd_buffer_size)
                uart->rx_buffer_read = 0;

            /* Set the status to reflect removal of the character */
            if (uart->rx_buffer_write == uart->rx_buffer_read)
                uart->rx_buffer_status = NU_BUFFER_EMPTY;
            else
                uart->rx_buffer_status = NU_BUFFER_DATA;
        }

    } /* endif mode */

    /* Return the character to the caller */
    return (ch);
}


/****************************************************************************
* FUNCTION
*
*    SDC_Carrier
*
* DESCRIPTION
*
*    This function checks for a carrier.
*
* CALLED BY
*
*    MDM_Hangup
*
* CALLS
*
*    none
*
* INPUTS
*
*    none
*
* OUTPUTS
*
*    STATUS    :  The status of the detection.
*
****************************************************************************/
STATUS SDC_Carrier(SD_PORT *uart)
{
    return (TRUE);
}

/****************************************************************************
 Note: All functions below this point are generic and should not require
       any changes to support other UARTS.
 ****************************************************************************/

/****************************************************************************
* 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)
{

    /* Grab the semaphore so that strings between threads
       do not get mixed. */
    {

        /* Send out the string. */
        for (; *str != 0; str++)
            SDC_Put_Char(*str, uart);

        /* Allow other threads to use this service. */

    }

}


/****************************************************************************
* 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)
{
    /* Check the status. */
    if((port->rx_buffer_status == NU_BUFFER_FULL) ||
       (port->rx_buffer_status == NU_BUFFER_DATA))

        return (TRUE);

    else

        return (FALSE);
}

/****************************************************************************
* FUNCTION
*
*    SDC_Change_Communication_Mode
*
* DESCRIPTION
*
*    This function switches the serial port between terminal mode and
*    network mode.  The mode affects how incoming characters are directed.
*
* CALLED BY
*
*    MDM_Change_Communication_Mode
*
* CALLS
*
*    none
*
* INPUTS
*
*    INT      :  The mode of operation desired.
*
* OUTPUTS
*
*    none
*
****************************************************************************/
VOID SDC_Change_Communication_Mode(INT mode, SD_PORT *uart)
{
    uart->communication_mode = mode;

} /* SDC_Change_Communication_Mode */

/****************************************************************************
* FUNCTION
*
*    SDC_Reset
*
* DESCRIPTION
*
*    This function intializes the data variables associated with a UART
*
* CALLED BY
*
*    PPP_Dial
*    PPP_Wait_For_Client
*
* CALLS
*
*    none
*
* INPUTS
*
*    SD_PORT      * :   Serial port to reset
*
* OUTPUTS
*
*    STATUS      :   Returns URT_SUCCESS if successful initialization,
*                    else a negative value is returned.
*
****************************************************************************/
VOID SDC_Reset (SD_PORT *uart)
{
    /* Ini the error counters */
    uart->frame_errors   = 0;
    uart->overrun_errors = 0;
    uart->parity_errors  = 0;
    uart->busy_errors    = 0;
    uart->general_errors = 0;
}

/***************************************************************************
* FUNCTION
*
*    URT_Init_Port
*
* DESCRIPTION
*
*    This function intializes the data variables associated with a UART
*
* CALLED BY
*
*    PPP_Dial
*    PPP_Wait_For_Client
*
* CALLS
*
*    none
*
* INPUTS
*
*    SD_PORT      * :   Serial port to reset
*
* OUTPUTS
*
*    STATUS      :   Returns URT_SUCCESS if successful initialization,
*                    else a negative value is returned.
*
****************************************************************************/
#ifdef NU_ENABLE_PPP
STATUS  URT_Init_Port(DV_DEVICE_ENTRY *device)
{
    SD_PORT   *uart;
    STATUS    ret_status;

    /* Get a pointer to the UART layer of this device. */
    uart = &((PPP_LAYER *) device->ppp_layer)->uart;

    /* Init the serial port, copy init parameters from the device
       structure. */
    uart->com_port              = device->dev_com_port;
    uart->baud_rate             = device->dev_baud_rate;
    uart->data_bits             = device->dev_data_bits;
    uart->stop_bits             = device->dev_stop_bits;
    uart->parity                = device->dev_parity;
    uart->data_mode             = device->dev_data_mode;
    uart->driver_options        = device->dev_driver_options;
    uart->communication_mode    = MDM_TERMINAL_COMMUNICATION;
    uart->sd_buffer_size        = (2 * (PPP_MTU + PPP_FCS_SIZE +
                                    PPP_MAX_PROTOCOL_SIZE + PPP_MAX_ADDR_CONTROL_SIZE));

    /* Init the port */
    ret_status = NU_SD_Init_Port (uart);

    if (ret_status == NU_SUCCESS)
    {
        /* Copy the vector assigned by the driver into
           the device's structure. */
        device->dev_vect = uart->tx_vector;
    }

    return (ret_status);

}
#endif /* NU_ENABLE_PPP */


⌨️ 快捷键说明

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