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

📄 sdc.c

📁 文件内包含了nuclues的内核代码和针对Power PC的编译器。需要用VirtNet生成一个虚拟网卡才可使用
💻 C
📖 第 1 页 / 共 4 页
字号:

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

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

        return (ch);
    } /* endif mode */

#ifdef NU_ENABLE_PPP  
    else if (uart->communication_mode == MDM_TERMINAL_COMMUNICATION || 
             uart->communication_mode == MDM_NETWORK_COMMUNICATION)

    /**************** Begin Port Specific Section **************/

             return (SD_INBYTE (uart->base_address + SD_DATA_OFFSET));

    /**************** End Port Specific Section ****************/

#endif /* NU_ENABLE_PPP */

}

/****************************************************************************
* FUNCTION                                                                 
*                                                                          
*    SDC_Carrier                                                           
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*    This function checks for a carrier.                                   
*                                                                          
* INPUTS                                                                   
*                                                                          
*    none                                                                  
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    STATUS    :  The status of the detection.                             
*                                                                          
****************************************************************************/
STATUS SDC_Carrier(SD_PORT *uart)
{
    return (NU_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.         
*                                                                         
* 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)
{
    STATUS status;
    /* Grab the semaphore so that strings between threads
       do not get mixed. */
    if (status = NU_Obtain_Semaphore(uart->sd_semaphore, NU_NO_SUSPEND) == NU_SUCCESS)
    {

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

        /* Allow other threads to use this service. */
        NU_Release_Semaphore (uart->sd_semaphore);
    }
    else
    {
        status = 0;
    }

}


/****************************************************************************
* 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.                         
*                                                                          
* 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 (NU_TRUE);

    else

        return (NU_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. 
*                                                                          
* 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   
*                                                                         
* 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    
*                                                                          
* 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->vector                = device->dev_vect;
    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 back into the device entry just in case
           the UART driver changed it. */
        device->dev_vect = uart->vector;
    }

    return (ret_status);

}
#endif /* NU_ENABLE_PPP */







⌨️ 快捷键说明

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