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

📄 uartfax.c

📁 手机底层驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
     * Escape sequence.
     */

    uart->esc_seq_modified        = 0;
    /*
     * Flow control.
     */

     uart->flow_control_mode         = fc_rts;
	 uart->send_xon_xoff             = 0; 
    
     uart->rx_stopped_by_application = 1;
   	 uart->rx_stopped_by_driver      = 0;

   	 uart->tx_stopped_by_application = 1;
     uart->tx_stopped_by_driver      = 0;

    /*
     * Break.
     */

    uart->break_received    = 0;
    uart->break_to_send     = 0;
    uart->break_in_progress = 0;

    /*
     * Callback (UAF_ReadData and UAF_WriteData).
     */

    uart->esc_seq_received  = 0;

    uart->reading_suspended             = 0;
    uart->writing_suspended             = 0;
    uart->rd_call_from_hisr_in_progress = 0;
    uart->wr_call_from_hisr_in_progress = 0;
    uart->rd_call_setup                 = rm_noInstall;
    uart->wr_call_setup                 = rm_noInstall;

    /*
     * State defined in UAF_GetLineState.
     */

    uart->state_1 = 0;
    uart->state_2 = 0;
    uart->state   = &(uart->state_1);

    /*
     * Errors counters.
     */

    uart->framing_error       = 0;
    uart->parity_error        = 0;
    uart->overrun_error       = 0;
    uart->spurious_interrupts = 0;

    uart->max_rx_fifo_level   = 0;

	UAF_Open(uartNo, FD_BAUD_115200);

    /*
     * Read the state of RTS (RTS on RS232, CTS on chipset).
     */
    if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
    	status = dev_Uart_getModemStatusRegister(uartNo);
    else
    	status = 0;

    if (status & MCTS)
        uart->rts_level = 0;
    else
        uart->rts_level = 1;

    if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
	dev_Uart_setInterruptEnableRegister(UAF_UART_1, ERBI|EDSSI);
     
    return (FD_OK);
}


/*******************************************************************************
 *
 *                               UAF_Enable
 * 
 * Purpose  : The functionalities of the UART driver are disabled or enabled.
 *            In the deactivated state, all information about the communication
 *            parameters should be stored and recalled if the driver is again
 *            enabled. When the driver is enabled the RX and TX buffers are
 *            cleared.
 *
 * Arguments: In : uartNo: Used UART.
 *               : enable: 1: enable the driver
 *                         0: disable the driver
 *            Out: none
 *
 * Returns  : FD_OK           : Successful operation.
 *            FD_NOT_SUPPORTED: Wrong UART number.
 *            FD_INTERNAL_ERR : Internal problem with the hardware.
 *
 ******************************************************************************/

T_FDRET
UAF_Enable (T_tr_UartId uartNo,
            SYS_BOOL enable)
{
    t_uart  *uart;

    uartNo += 1; 
    if (uartNo != UAF_UART_1)
        return (FD_NOT_SUPPORTED);

    /*
     * There is no case where FD_INTERNAL_ERR may be returned.
     */
    uart = &uart_parameters;

    if (enable) {
        uart->rx_stopped_by_driver = 0;            
        ENABLE_DRIVER (uart);
    } else {

        DISABLE_DRIVER (uart);

        uart->tx_in = &(uart->tx_buffer[0]);
        uart->rx_in = &(uart->rx_buffer[0]);
        uart->tx_out = uart->tx_in;
        uart->rx_out = uart->rx_in;
    }

    return (FD_OK);
}

/*******************************************************************************
 *
 *                             UAF_SetFlowCtrl
 * 
 * Purpose  : Changes the flow control mode of the UART driver.
 *            If a flow control is activated, DTR is activated or XOFF is sent
 *            if the RX buffer is not able to store the received characters else
 *            DTR is deactivated or XON is sent.
 *
 * Arguments: In : uartNo: Used UART.
 *                 fcMode: flow control mode (none, DTR/DSR, RTS/CTS, XON/XOFF).
 *                 XON   : ASCII code of the XON character.
 *                 XOFF  : ASCII code of the XOFF character.
 *            Out: none
 *
 * Returns  : FD_OK           : Successful operation.
 *            FD_NOT_SUPPORTED: The flow control mode is not supported or wrong
 *                              UART number.
 *            FD_INTERNAL_ERR : Internal problem with the hardware.
 *
 ******************************************************************************/

T_FDRET
UAF_SetFlowCtrl (T_tr_UartId uartNo,
                 T_flowCtrlMode fcMode,
                 SYS_UWORD8 XON,
                 SYS_UWORD8 XOFF)
{
    T_FDRET result;
    t_uart  *uart;
    unsigned char mcRegister;
    volatile SYS_UWORD8 status;
	
	uartNo += 1;
    if (uartNo != UAF_UART_1)
        return (FD_NOT_SUPPORTED);

    /*
     * There is no case where FD_INTERNAL_ERR may be returned.
     * The DTR/DSR protocol is not supported.
     */

    if (fcMode == fc_dtr)
        result = FD_NOT_SUPPORTED;

    else {

	if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
	{
		bspUsart_modemIntPtr( (BspUsart_Id)UAF_UART_1,check_v24_input_lines);
	}

        uart = &uart_parameters;

        uart->tx_stopped_by_driver = 0;

        
        uart->xon_character = XON;
        uart->xoff_character = XOFF;
        uart->flow_control_mode = fcMode;

	 if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
	 {
		mcRegister = dev_Uart_getModemControlRegister(UAF_UART_1);
		dev_Uart_setModemControlRegister(UAF_UART_1, mcRegister|MRTS);  
		status = dev_Uart_getModemStatusRegister(UAF_UART_1);
	 }

	 UART3_CTSlow_vote_for_PM = bspVote_allocateHandle(
                                 BSP_VOTE_ELECTION_PREVENT_ARM_DEEP_SLEEP,
                                 FALSE,
                                 "UART3_CTSlow_vote_for_PM");
	 
    if (status & MCTS)
	{
        
	 if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
	 {
	    uart->rts_level = 0;
	    bspVote_setVote(UART3_CTSlow_vote_for_PM, TRUE);
	 }
	}

    else
	{
        
	  if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
	  {
	  	uart->rts_level = 1;
	    	bspVote_setVote(UART3_CTSlow_vote_for_PM, FALSE); //deep sleep
	  }
	}
	if(fcMode == RTS)
	{
		if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
	  	{
	          if (uart->rts_level)
	                uart->tx_stopped_by_driver = 1;
	        }
	}

        /*
         * If the high watermark is reached, RTS is activated or XOFF is sent
         * according to the flow control mode. Else, RTS is deactivated or XON
         * is sent.
         */

        if (fcMode != fc_none) {

            if (get_bytes_in_rx_buffer (uart) >= RX_HIGH_WATERMARK (
                                                     uart->buffer_size)) {

                uart->rx_stopped_by_driver = 1;
                stop_receiver (uartNo);

            } else if (!DRIVER_DISABLED (uart)) {

                uart->rx_stopped_by_driver = 0;
                start_receiver (uartNo);
            }
            
        } else {
        
            uart->rx_stopped_by_driver = 0;
            uart->tx_stopped_by_driver = 0;
        }

        result = FD_OK;
    }

    return (result);
}

/*******************************************************************************
 *
 *                            UAF_SetComPar
 * 
 * Purpose  : Sets up the communication parameters: baud rate, bits per
 *            character, number of stop bits, parity.
 *
 * Arguments: In : uartNo  : Used UART.
 *                 baudrate: Used baud rate.
 *                 bpc     : Used bits per character.
 *                 sb      : Used stop bits.
 *                 parity  : Used parity.
 *            Out: none
 *
 * Returns  : FD_OK           : Successful operation.
 *            FD_NOT_SUPPORTED: The specified parameters don't fit to the
 *                              capabilities of the UART or wrong UART number.
 *            FD_INTERNAL_ERR : Internal problem with the hardware.
 *
 ******************************************************************************/

T_FDRET
UAF_SetComPar (T_tr_UartId uartNo,
               T_baudrate baudrate,
               T_bitsPerCharacter bpc,
               T_stopBits sb,
               T_parity parity)
{
    t_uart *uart;
    volatile SYS_UWORD8 status;

	uartNo += 1;
    /*
     * Check UART number.
     * A return is used to simplify the code.
     * UART IrDA (UAF_UART_0) can't be used for F&D on Ulysse because hardware
     * flow control is not supported.
     * DCD and DTR are not supported on UART Irda on C & D-Sample.
     * DCD and DTR are not supported on UART Irda & Modem2 on E-Sample.
     */
    if (uartNo != UAF_UART_1)
        return (FD_NOT_SUPPORTED);

		baudrate = FD_BAUD_115200;
    /*
     * There is no case where FD_INTERNAL_ERR may be returned.
     * pa_space is not supported. Some baudrates are not supported too.
     * A return is used to simplify the code.
     */

    if ((!baudrate_value[baudrate]) ||
        (parity == pa_space))

        return (FD_NOT_SUPPORTED);

    if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
    {
    /*
     * Mask all interrupts causes and disable sleep mode and low power mode.
     */
		dev_Uart_setInterruptEnableRegister(UAF_UART_1,0x00);
     }
	
    uart = &uart_parameters;

    /*
     * Select the word length, the number of stop bits , the parity and set
     * LCR[7] (DLAB) to allow to program FCR, DLL and DLM.
     */

    uart->baudrate = baudrate_value[baudrate];
    uart->bits_per_char = 1; /* Start bit. */

    if (bpc == bpc_7) {
    
        uart->bits_per_char += 7;

    } else {

        uart->bits_per_char += 8;
    }

    if (sb == sb_2) {

        uart->bits_per_char += 2;

    } else
        uart->bits_per_char += 1;

    switch (parity) {

    case pa_even:

        uart->bits_per_char += 1;

        break;

    case pa_odd:

        uart->bits_per_char += 1;

        break;

    default:

        /*
         * There is nothing to do.
         */

        break;
    }

   if(UAF_GetPortType(uartNo) == UA_TYPE_UART)
   {
    /*
     * Reset UART mode configuration.
     */
    if (uartNo == UAF_UART_1)
	{
		bspUsart_unreserve( UAF_UART_1 );
		bspUsart_reserve( UAF_UART_1 );
		bspUsart_enable( UAF_UART_1, (Uint16)FALSE);
		bspUsart_setComPar( UAF_UART_1,
		                    baudrate,
		                    bpc,
		                    sb,
		                    parity );   
	     	bspUsart_enable( UAF_UART_1, TRUE );

	    /*
	     * Read the state of RTS (RTS on RS232, CTS on chipset).
	     */

	    
		dev_Uart_setInterruptEnableRegister(UAF_UART_1,ERBI | ETBEI | EDSSI | ELSI);
	  }
   	}
    return (FD_OK);
}


/*******************************************************************************
 *
 *                            UAF_SetLineState
 * 
 * Purpose  : Sets the states of the V.24 status lines according to the bit
 *            field of the parameter state.
 *
 * Arguments: In : uartNo: Used UART.
 *                 state : Bit field. Only the signals which are marked with
 *                         the 'set' access can be used to change the state of
 *                         the signal.
 *                 mask  : Bit field with the same structure as state. Each bit
 *                         in state corresponds to a bit in mask. Settabled
 *                         bits marked by a 1 are manipulated by the driver.
 *            Out: none
 *
 * Returns  : FD_OK           : Successful operation.
 *            FD_NOT_SUPPORTED: Wrong UART number.
 *            FD_INTERNAL_ERR : Internal problem with the hardw

⌨️ 快捷键说明

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