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

📄 uartfax.c

📁 手机底层驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
hisr_start_break (VOID)
{
    t_uart *uart;

    uart = &uart_parameters;

    (void) NU_Control_Timer (&(uart->break_timer_ctrl_block),
                             NU_DISABLE_TIMER);

    (void) NU_Reset_Timer (&(uart->break_timer_ctrl_block),
                           stop_break,
                           uart->time_without_character,
                           0, /* The timer expires once. */
                           NU_DISABLE_TIMER);

    (void) NU_Control_Timer (&(uart->break_timer_ctrl_block),
                             NU_ENABLE_TIMER);
}

void CTShigh_timeout(unsigned short id)
{
   if ( (&uart_parameters)->rts_level )
   {
	  NU_Control_Timer(&CTShigh_Timer, NU_DISABLE_TIMER);	 
      bspVote_setVote(UART3_CTSlow_vote_for_PM, FALSE); //deep sleep 
   }
}

/*******************************************************************************
 *
 *                          hisr_execute_v24_operations
 * 
 * Purpose  : The user's function is called if all conditions to call it are
 *            fulfiled.
 *
 * Arguments: In : none
 *            Out: none
 *
 * Returns  : none
 *
 ******************************************************************************/

static VOID
hisr_execute_v24_operations (VOID)
{
    t_uart *uart;

    uart = &uart_parameters;

/***********************added for powersaving by chendejun 060530***************/
    if (uart->rts_level)
    {
	NU_Control_Timer(&CTShigh_Timer, NU_DISABLE_TIMER);	 
	NU_Reset_Timer(&CTShigh_Timer,	CTShigh_timeout, 500, 0, NU_ENABLE_TIMER);
    }
   else 
	{
	 bspVote_setVote(UART3_CTSlow_vote_for_PM, TRUE); 
	 NU_Control_Timer(&CTShigh_Timer, NU_DISABLE_TIMER);	 
       }
/*****************added for powersaving by chendejun 060530*********************/

    /*
     * If a reading was suspended or if the callback function is installed,
     * it is called.
     */

    if ((!DRIVER_DISABLED (uart)) &&
        (!uart->rd_call_from_hisr_in_progress) &&
        (uart->reading_suspended || (uart->rd_call_setup == rm_reInstall))) {

        uart->rd_call_from_hisr_in_progress = 1;
        update_reading_callback (uart, 1); /* 1: call from HISR. */

        uart->reading_suspended = 0;
        uart->break_received = 0;
        uart->esc_seq_received = 0;
    }
}

/*******************************************************************************
 *
 *                          check_v24_input_lines
 * 
 * Purpose  : Check the V.24 input lines. According to the states of the input
 *            lines and to the flow control mode selected, the transmitter is
 *            enabled or disabled. The reading callback function is called if
 *            it is installed and if all conditions are fulfiled.
 *
 * Arguments: In : uart: Pointer on the UART structure.
 *            Out: none
 *
 * Returns  : none
 *
 ******************************************************************************/

static void
check_v24_input_lines (BspUsart_Id uartNo)
{
    SYS_BOOL v24_input_line_changed;
    volatile SYS_UWORD8 modem_status;
    t_uart *uart;

    uart = &uart_parameters;

    modem_status = dev_Uart_getModemStatusRegister(UAF_UART_1);
    v24_input_line_changed = 0;

    if (modem_status & DELTA_CTS) {

        v24_input_line_changed = 1;

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

    /*
     * When the hardware flow control is selected, if the RS 232 input signal is
     * deactivated (low), the transmitter is stopped.
     */

    if (uart->flow_control_mode == fc_rts) {
        
        if (uart->rts_level)
		{
            uart->tx_stopped_by_driver = 1;
		}

        else {
            
            uart->tx_stopped_by_driver = 0;
            /*
             * Unmask Tx interrupt.
             */

		       bspUsart_enableTxInterrupt(UAF_UART_1);
        }
    }

    if (v24_input_line_changed)
        (void) NU_Activate_HISR (&(uart->v24_hisr_ctrl_block));
}

/*******************************************************************************
 *
 *                          hisr_execute_tx_operations
 * 
 * Purpose  : Writes bytes from the TX buffer to the TX FIFO.
 *            The user's function is called if all conditions to call it are
 *            fulfiled.
 *
 * Arguments: In : none
 *            Out: none
 *
 * Returns  : none
 *
 ******************************************************************************/

static VOID
hisr_execute_tx_operations (VOID)
{

    SYS_UWORD16 bytes_in_tx_buffer;
    SYS_UWORD16 bytes_in_tx_fifo;
    SYS_UWORD16 wrap_around_counter;
    SYS_UWORD16 bytes_to_write;
    unsigned char lsRegister;
    t_uart *uart;
    int counter;


    uart = &uart_parameters;

    bytes_in_tx_fifo = 0;
	lsRegister = dev_Uart_getLineStatusRegister(UAF_UART_1);
	    
        if ((!uart->tx_stopped_by_application) &&
            (!uart->tx_stopped_by_driver)) {

            bytes_in_tx_buffer = get_bytes_in_tx_buffer (uart);
            wrap_around_counter =
                uart->buffer_size + 1 - (SYS_UWORD16) (uart->tx_out -
                                                  &(uart->tx_buffer[0]));


            bytes_to_write =
                Min3 (bytes_in_tx_buffer, wrap_around_counter,
                      /*FIFO_SIZE-18*/NumBytesFree-1);

         	send_counter1 += bytes_to_write;
            for (counter = 0; counter < bytes_to_write; counter++)
	        {
	            bspUtil_CircBuf_enqueueUint8( Scb, *(uart->tx_out++) );
	        }       
	        

            bytes_in_tx_buffer -= bytes_to_write;
            bytes_in_tx_fifo += bytes_to_write;

            wrap_around_counter -= bytes_to_write;
            if (!wrap_around_counter)
                uart->tx_out = &(uart->tx_buffer[0]);

            if (bytes_in_tx_buffer && /*FIFO_SIZE-18*/NumBytesFree-1>bytes_in_tx_fifo) {

               bytes_to_write =  Min (bytes_in_tx_buffer, /*FIFO_SIZE-18*/NumBytesFree-1-bytes_in_tx_fifo);

	         	send_counter1 += bytes_to_write;
	            for (counter = 0; counter < bytes_to_write; counter++)
		        {  
		            bspUtil_CircBuf_enqueueUint8( Scb, *(uart->tx_out++) );

		        }

                bytes_in_tx_buffer -= bytes_to_write;
                bytes_in_tx_fifo += bytes_to_write;
            }
		    if ((!DRIVER_DISABLED (uart)) &&
		        (!uart->wr_call_from_hisr_in_progress) &&
		        ((uart->wr_call_setup == rm_reInstall) ||
		         uart->writing_suspended)) {

		             uart->writing_suspended = 0;
		             uart->wr_call_from_hisr_in_progress = 1;
				     update_writing_callback (uart, 1); 
		 	}
        }

		if(bytes_in_tx_fifo > 0)
		{
		       bspUsart_enableTxInterrupt(UAF_UART_1);
		}
	    else
		{
	     if ((!bytes_in_tx_fifo) && (uart->break_to_send))
	         bytes_in_tx_fifo = send_break (uart);			
	    }      
}

/****************************************************************************************************************       
 *      FUNCTION : bsp_Usart_txCallback8
 *      ARGUMENTS : 
                 irq                    :  if irq set to TRUE otherwise FALSE 
                 reinstallPtr   :  Reinstall pointer for reinstall after each thresh-hold 
                 cb                     :  Circular buffer for data manupulation.  
                 numBytesAvailable  :  Number of byte availabe in circular buffer. 
                 state              :  which state the UART is. 
                 CommPort           :  which UART. 

 *      GLOBAL VARIABLES : rxBuf      :  Circular buffer for Transmitt. 
 *      RETURN VALUE :  numRetrieved   : Number of bytes retrieved from the buffer. 
 *      DESCRIPTION :  The TX callback, called from TX interrupt, which can't be interrupted by read thread.
 *                         Copies data from BSP_USART to TX buffer
 ****************************************************************************************************************/ 

static BspUsart_ResultCode
bsp_Usart_txCallback(  Uint16                   irq,
                                    BspUsart_ReInstallMode *reInstallPtr,
                                    BspUtil_CircBuf_Handle cb,
                                    Uint16                 numBytesFree, 
                                    BspUsart_Id            usartId )
{

   		t_uart *uart;

    	uart = &uart_parameters;
		NumBytesFree = numBytesFree;
		Scb = cb;
    	*reInstallPtr = BSP_USART_REINSTALL_MODE_REINSTALL;  
       (void) NU_Activate_HISR (&(uart->tx_hisr_ctrl_block));
    	
    	return 0;		

}

/*******************************************************************************
 *
 *                          hisr_execute_rx_operations
 * 
 * Purpose  : If an escape sequence is detected or if a break in the detection
 *            has occured RX FIFO bytes are written in the RX buffer. 
 *            If the software flow control is used bytes are analyzed to know
 *            if a XON or a XOFF character is received to stop or start the
 *            transmitter. 
 *            If a flow control is used and if the high watermark of the RX
 *            buffer is reached the receiver is stopped.
 *            If the RX threshold level is reached the callback mechanism is
 *            activated.
 *
 * Arguments: In : none
 *            Out: none
 *
 * Returns  : none
 *
 ******************************************************************************/
static VOID
hisr_execute_rx_operations (VOID)
{
    SYS_UWORD16 bytes_free_in_rx_buffer;
    SYS_UWORD16 wrap_around_counter;
    SYS_UWORD16 bytes_in_rx_buffer;
    SYS_UWORD16 bytes_read;
    SYS_UWORD16 bytes_to_copy;
    SYS_UWORD8  *current_byte;
    SYS_UWORD8  xon_xoff_detected;
    t_uart *uart;


    uart = &uart_parameters;
    
    xon_xoff_detected = 0;
     
    current_byte = uart->rx_buffer_used_by_rx_hisr;
    if (current_byte == &(uart->rx_fifo_byte_1[0])) {
    
        current_byte = &(uart->rx_fifo_byte_2[0]);
        bytes_read = uart->bytes_in_rx_buffer_2;
    
    } else {
    
        current_byte = &(uart->rx_fifo_byte_1[0]);
        bytes_read = uart->bytes_in_rx_buffer_1;
    }

    uart->rx_buffer_used_by_rx_hisr = current_byte;

	receive_counter2 += bytes_read;

    if (1) {

        if (uart->rx_out > uart->rx_in)
            bytes_free_in_rx_buffer = (SYS_UWORD16) (uart->rx_out - uart->rx_in - 1);
        else
            bytes_free_in_rx_buffer =
                (SYS_UWORD16) (uart->buffer_size + uart->rx_out - uart->rx_in);

        wrap_around_counter = uart->buffer_size + 1 -
                              (SYS_UWORD16) (uart->rx_in - &(uart->rx_buffer[0]));
        
        if (uart->flow_control_mode == fc_xoff) {
        

        
            while (bytes_read && bytes_free_in_rx_buffer) {


                if (*current_byte == uart->xoff_character) {

                    uart->tx_stopped_by_driver = 1;
                    xon_xoff_detected = 1;

                } else if (*current_byte == uart->xon_character) {

                    uart->tx_stopped_by_driver = 0;
                    xon_xoff_detected = 1;

                } else {
    
                    *(uart->rx_in++) = *current_byte;

                    wrap_around_counter--;
                    if (!wrap_around_counter) {
                    
                        uart->rx_in = &(uart->rx_buffer[0]);
                        wrap_around_counter = uart->buffer_size + 1;
                    }
                    
                    bytes_free_in_rx_buffer--;
                }

                current_byte++;
                bytes_read--;
            }
        } else { 
                

            bytes_to_copy =
                Min3 (bytes_free_in_rx_buffer, wrap_around_counter, bytes_read);
                          

        
            memcpy (uart->rx_in, current_byte, bytes_to_copy);

                
            bytes_free_in_rx_buffer	-= bytes_to_copy;
            bytes_read -= bytes_to_copy;
                
            wrap_around_counter -= bytes_to_copy;
            if (!wrap_around_counter)
                    uart->rx_in = &(uart->rx_buffer[0]);
            else
                uart->rx_in += bytes_to_copy;

            if (bytes_read && bytes_free_in_rx_buffer) {

                current_byte += bytes_to_copy;
                bytes_to_copy = Min (bytes_read, bytes_free_in_rx_buffer);

                memcpy (uart->rx_in, current_byte, bytes_to_copy);

                uart->rx_in += bytes_to_copy;
                
            }
        } 


        bytes_in_rx_buffer = get_bytes_in_rx_buffer (uart);

        if ((uart->flow_control_mode != fc_none) &&
            (bytes_in_rx_buffer >= RX_HIGH_WATERMARK (uart->buffer_size))) {



            if (!uart->rx_stopped_by_driver) {

                uart->rx_stopped_by_driver = 1;
                if (!uart->rx_stopped_by_application)
                    stop_receiver (UAF_UART_1);
            }
        }

        if ((!uart->rd_call_from_hisr_in_progress) &&
            (uart->reading_suspended ||

⌨️ 快捷键说明

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