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

📄 uart.cu

📁 the uart driver based on NEC V850
💻 CU
📖 第 1 页 / 共 3 页
字号:
    {
         recv_index = BT_Get_Current_Inpx(dev_index);
    }
    else {
	recv_index = size;
    }
   
     for (i =0; i< recv_index; i++)
     {
  	      buffer[i] = BT_Get_Char(dev_index);
      }
   
	
    return recv_index;
}

extern void  UART_Service_Write(Uart_Devices_Enum_T dev_index, uint8_t *buffer, uint16_t size)
{
    uart_chan_t *pChan;
    int i;

    pChan = uart_chan[dev_index];
#if BLUETOOTH_IS
    CXN_RTS_LOW();
#endif
    for (i=0;i<size;i++)
    {
        BT_Put_Char(buffer[i] );
    }
#if BLUETOOTH_IS
    CXN_RTS_HIGH();
#endif

}

/*******************************************************************************
*    Function: Uart_Check_Uart_Char
*
*  Parameters: None
*     Returns: None
* Description: Returns uart byte based on current rx_out index
*******************************************************************************/
extern uint8_t Uart_Check_Uart_Char(Uart_Devices_Enum_T dev_index, uint8_t offset)
{
    uint8_t  data;
    uart_chan_t *pChan;
    if ( ( dev_index < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[dev_index] ) )
   {
      pChan = uart_chan[dev_index];
      offset =  (pChan->rx_out + offset)%pChan->rx_buf_size; 
      data = pChan->rx_buf[offset];
    }
    else
    {
       data =  0;
    }

    return  data;
}
#elif (External_Bluetooth_IS && M12_NAV_MODEL_IS)
/*******************************************************************************
*    Function: BT_Uart_Initilize, compatible interface for sipprot
*
*  Parameters: None
*     Returns: true, initiliizaed; false, initilize failed
* Description: The Bluetooth specific version of initialize a UART channel.
*******************************************************************************/
bool BT_Uart_Initilize (void)
{
   Uart_Devices_Enum_T device;

   device = UART_Initialize( UART_CONF_BT); // initialize UART channel 3
   if ( UART_NUM_HW_DEVICES > device )
   {
      UART_Start( device, UART_ISR_TX_ON ); //open uart interrupt     
      return true;
   }
   else
   {
     /* error */
     return false;
   }
}


/**********************************************************************
 * Description: Send Uart data, compatible interface for sipprot
 *  Parameters: data byte
 *     Returns: written data byte or (-1) on error
 *********************************************************************/
int8_t BT_Put_Char ( uint8_t data )
{    
   bool_fast result; /* = false; */

   result = UART_Put_Char( UART_DEVICE_BT,data);

   if ( true == result )
   {
      return ( ( int8_t ) data );
   }
   else
   {
      return ( -1 );      
   }
}

extern void  UART_Service_Write(Uart_Devices_Enum_T dev_index, uint8_t *buffer, uint16_t size)
{
    uart_chan_t *pChan;
    int i;

    pChan = uart_chan[dev_index];
#if BLUETOOTH_IS
    CXN_RTS_LOW();
#endif
    for (i=0;i<size;i++)
    {
        BT_Put_Char(buffer[i] );
    }
#if BLUETOOTH_IS
    CXN_RTS_HIGH();
#endif
}

#endif
/*******************************************************************************
*    Function: UART_Error_Register
*
*  Parameters: None
*     Returns: None
* Description: Returns any error flags during uart reception.
*******************************************************************************/
UINT8 UART_Error_Register (Uart_Devices_Enum_T device)
{
   if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
   {
      return (uart_chan[device]->ptr_reg->str);  
   }
}

/*******************************************************************************
*    Function: UART_Error_Register
*
*  Parameters: None
*     Returns: None
* Description: Returns uart signal setup like stop bit, # bits, etc.
*******************************************************************************/
UINT8 UART_Signal_Setup_Register( Uart_Devices_Enum_T device)
{
    if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
   {
       return (uart_chan[device]->ptr_reg->ctl0);  
   }
}

/*******************************************************************************
*    Function: UART_Rx_Buf_Input_Index
*
*  Parameters: Channel number
*     Returns: Returns rx buffer iput index if invalid or zero if invalid.
* Description: Returns rx buffer iput index.
*******************************************************************************/
UINT8 UART_Rx_Buf_Input_Index(Uart_Devices_Enum_T device)
{
    if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
    {
       return(uart_chan[device]->rx_in);
    }
   else
   {
      return(0);						 // return 0 if chan is invalid
   }
} 

/*******************************************************************************
*    Function: UART_Get_Char_Offset
*
*  Parameters: Channel number, offset
*     Returns: Returns a char at offset from rx buffer input index or zero.
* Description: Returns char at offset from rx buffer input index.
*******************************************************************************/
UINT8 UART_Get_Char_Offset(Uart_Devices_Enum_T device, UINT16 offset )
{
    uint16_t   rx_size;
    if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
    {
       rx_size = uart_chan[device]->rx_buf_size;
       if ((offset >= 0) && (offset <rx_size))
      {
	  offset = ((uart_chan[device]->rx_in-1) - offset + rx_size ) % rx_size;
         return(uart_chan[device]->rx_buf[offset]);
      }
    }
    else
      return(0);						 // return 0 if offset or chan is invalid
} 



/*******************************************************************************
*    Function: UART_Reset_Rx_Buf
*
*  Parameters: Channel number
*     Returns: Returns true if channel is valid or false if channel is invalid.
* Description: Reset the Rx buffer of the desired channel.
*******************************************************************************/
bool UART_Reset_Rx_Buf(Uart_Devices_Enum_T device)
{
   bool ret = false;     

    if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
    {
         uart_chan[device]->rx_count = 0;	   // Clear rx byte counter
         uart_chan[device]->rx_in = 0;	   // Rx buf write index
	  uart_chan[device]->rx_out = 0;	   // Rx buf read out index
	  ret = true;
   }

   return(ret);
}


/*******************************************************************************
*    Function: Configure_UART_For_Idle
*
*  Parameters: Channel
*     Returns: None
* Description: Configure UART SIP TX as input in idle to avoid damage to NAV board.
*              NAV is powered down, and outputting high can damage NAV uP port. 
*******************************************************************************/
extern void Configure_UART_For_Idle(Uart_Devices_Enum_T device)
{
   if (UART_DEVICE_0 == device) // DVDX (Hardware UART2)
   {
      // Make transmit pin as input
      PMC3L.0   = 0;   // Disable alternate function   TX
      PMC3L.1   = 0;  //disable alternate function for RX
      PF3L.0      = 0;  //CMOS output 
      P3L.0       = 0;     // Output value
      PM3L.0    = 1;    // Configure as input 
      PM3L.1    = 1; 
      uart0_set_isr_state( UART_ISR_OFF );

   }
   else if (UART_DEVICE_1 == device)  // SIP Channel  (Hardware UART0)
   {
      // Make transmit pin as input
      PMC9L.0  = 0;  // Disable alternate function for TX
      PMC9L.1  = 0; //Disable alternate function for RX
      PF9L.0      = 0;
      PF9L.1      = 0;
      PM9L.0    = 1;  //config as input
      PM9L.1    =  1;  //config as input
      P9L.0    = 0;  // Output value
      P9L.1    = 0;  // output value  
      uart1_set_isr_state( UART_ISR_OFF );
   }
   else if(UART_DEVICE_2 == device)
   {
      PMC3H.0   = 0;   // Disable alternate function   TX
      PMC3H.1   = 0;  //disable alternate function for RX
      PF3H.0      = 0;  //CMOS output 
      PF3H.1     = 0;  //CMOS output
      P3H.0       = 0;     // Output value
      P3H.1       =  0;   //opuput value
      PM3H.0    = 1;    // Configure as input   
      PM3H.1    = 1;    //configure as input
      uart2_set_isr_state( UART_ISR_OFF );
   }
   #if SJ3_IS	// Zhao Zhigang add
   else if(UART_DEVICE_3 == device)
   {
       PMC8.0 = 0; //disable alternate function Tx
	PMC8.1 = 0; //disable alternate function RX
	PM8.0   = 1; //configure as input;
	PM8.1   = 1; //configure as input;
	P8.0     = 0;
       P8.1     = 0; 
      uart3_set_isr_state( UART_ISR_OFF );
   }
   #endif		// Zhao Zhigang add
   else
   {
   
   }

}

/**********************************************************************
 * Description: Read Uart data, compatible interface for sipprot
 *  Parameters: None
 *     Returns: read data byte or (-1) on error
 *********************************************************************/
extern int8_t TSI_Get_Char (uint8_t data)
{
    bool_fast result; /* = false; */
    result = UART_Get_Char ( UART_DEVICE_TSI, &data );
   
    if ( true == result )
    {
        return ( ( int8_t ) data );
    }
    else
    {
        return ( -1 );      
    }
}

/*===========================================================================*\
 * FUNCTION: Set_New_Msg_From_SBX
 *===========================================================================
 * PARAMETERS:	none
 * RETURN VALUE:	none
 * --------------------------------------------------------------------------
 * ABSTRACT:
 * --------------------------------------------------------------------------
 * Set the flag indecating the next message comes from Silver Box, called in UART TSI module and
 * TSI module
\*===========================================================================*/
extern void Set_New_Msg_From_SBX(void)
{
    New_Msg_From_SBX = 1;
}

/*===========================================================================*\
 * FUNCTION: TSI_UART_RX_ISR
 *===========================================================================
 * PARAMETERS:	none
 * RETURN VALUE:	none
 * --------------------------------------------------------------------------
 * ABSTRACT:
 * --------------------------------------------------------------------------
 * Handle the msg, the msg comes both from SBX and TSI mouduel, if the length of one frame more than
 * 15, consider is as a invalid frame, and get it out from UART buffer, reinitial UART 2(TSI channel)
 * UART 2 Interrutp Service Roution called in applvect.s
\*===========================================================================*/
void TSI_UART_RX_ISR (void)
{
    unsigned char a[20];
    int i;
    if (1 == New_Msg_From_SBX)		// new msg from SBX?
    {
        New_Msg_From_SBX = 0;
        TSI_Enable_ISRs_For_Msg();	//start 2ms timer, the msg will be handled in the timer ISR--
    }
    UART0_RX_ISR();	// store msg, count bytes received
    Received_Msg_Length_Inc();		// count received bytes
    
    if (Is_Msg_From_FTD())		// msg from FTD?
    {
        if (Received_Msg_Length() == Sent_Msg_Length())	// last byte of a msg?
        {
            Move_TSI_Msg_2_Comp_Buf();	//move msg to Comp buffer
            Sent_Msg_Length_Rst();		// clear the length of msg from FTD for next recieption
            Clr_Msg_From_FTD();			// clear flag whitch were set when FTD start to send msg in timer ISR
            Received_Msg_Length_Rst();
            New_Msg_From_SBX = 1;		// set the flat indecating the next msg will come from SBX after FTD finish sending a msg
        }
        else
        {
            // do nothing
        }
    }
	
    if (Received_Msg_Length() > 15)	// length more than 15, consider as invalid frame
    {
        Disable_Interrupts();
        Timer_Disable();
//		
        for (i=0; i<Received_Msg_Length(); i++)
        {
            UART_Get_Char(UART_DEVICE_TSI, &a[i]);
        }
//		
        Sent_Msg_Length_Rst();
        Clr_Msg_From_FTD();
        Received_Msg_Length_Rst();
        New_Msg_From_SBX = 1;
        UART_TSI_Initialize();
		
        Enable_Interrupts();
    }

}

/**********************************************************************
 * Description: Send Uart data, compatible interface for sipprot
 *  Parameters: data byte
 *     Returns: written data byte or (-1) on error
 *********************************************************************/
extern int8_t TSI_Put_Char ( uint8_t data )
{    
   bool_fast result; /* = false; */

   result = UART_Put_Char( UART_DEVICE_TSI,data);

   if ( true == result )
   {
      return ( ( int8_t ) data );
   }
   else
   {
      return ( -1 );      
   }
}


/*******************************************************************************
* REVISION RECORDS                                                             *
*******************************************************************************/
/******************************************************************************/
/* $Log:   O:\pvcs\ibs_software\06_opel\src\uart.cuv  $
 * 
 *    Rev 1.0   steven_yi
 *    initial version for Chery Project  
 
 *    Rev 1.5   May 18 2005 16:29:18   Stryj_Michael
 * bugfix again
 * 
 *    Rev 1.4   May 11 2005 16:58:42   Stryj_Michael
 * bugfix in  "uart_init_data_table"
 * 
 *    Rev 1.3   Apr 26 2005 17:55:26   Stryj_Michael
 * add compile switch KW82_USED_IS to KW82_Recv_handler
 * 
 *    Rev 1.2   Mar 09 2005 18:49:48   Brunken_Guido
 * + reworked module
 * + added configuration switches for code size optimization
 * 
 *    Rev 1.1   Oct 11 2004 11:09:12   Brunken_Guido
 * + reconfigured: HiSIP --> UART0
 * 
 *    Rev 1.0   Sep 30 2004 21:09:14   Brunken_Guido
 * Initial revision.
 * 
 *    Rev 0.9   Sep 30 2004  12:00:00  Brunken_Guido 
 * First revision will use UART2 for HiSIP (testing). THIS WILL CHANGE TO UART0.
 *
 *    Rev 0.8   Sep 16 2004  12:00:00  Brunken_Guido 
 * Initial revision for V850-ES-Sx2 based on previous uart.cu from Lee_Long
 * 
 ******************************************************************************/

⌨️ 快捷键说明

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