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

📄 sdc.c

📁 已移植到TI OMAP1610处理器的Nucleus操作系统源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                            _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 /* PPP_POLLED_TX */
                }
#endif /* NU_ENABLE_PPP */
            }

            /* Get the interrupt status register value */
            int_status = SD_INBYTE(uart->base_address + IIR_OFFSET);
        }
        
        /**************** End Port Specific Section **************/
    
        /* No port is associated with the vector */
    }
    else 
    {
        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
*
****************************************************************************/
VOID  SDC_Set_Baud_Rate(UINT32 baud_rate, SD_PORT *uart)
{
    UNSIGNED    baud_div;
    UINT32      temp_long;

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

    /* Set this bit to select the 6.5 divisor factor */
    SD_OUTBYTE (uart->base_address + OSC_12M_OFFSET, OSC_12M_SEL);

    /* Write to the divisor latch bit to enable the DLH and DLL registers */
    temp_long = SD_INBYTE(uart->base_address + LCR_OFFSET);
    SD_OUTBYTE (uart->base_address + LCR_OFFSET, LCR_DIV_EN);             

    /* Set the baud rate */
    baud_div = 115200 / uart->baud_rate;

    /* Put LSB in DLL Reg */
    SD_OUTBYTE (uart->base_address + DLL_OFFSET, baud_div);

    /* Put MSB in DLH Reg */    
    SD_OUTBYTE (uart->base_address + DLH_OFFSET, (baud_div >> 8));

    /* Disable the Divisor Latch bit */
    SD_OUTBYTE (uart->base_address + LCR_OFFSET, temp_long & ~LCR_DIV_EN);             
   /**************** 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;

#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 ((UINT8)SD_INBYTE (uart->base_address + RHR_OFFSET));

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

#endif /* NU_ENABLE_PPP */

    /* Execution should never reach this point, this return was added
       in response to the 'implicit return' compiler warning */

    return (ch);
}

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

   /* Grab the semaphore so that strings between threads
       do not get mixed. */
    if (NU_Obtain_Semaphore(uart->sd_semaphore, NU_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);
    }

}


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