📄 uart.cu
字号:
#endif // Zhao Zhigang added
#endif //#if UART_CONF_USE_GET_ISR_STATE
/******************************************************************************
* Function Definitions
******************************************************************************/
/**********************************************************************
* Description: uP/project specific init
* Parameters: device, init data for registers
* Returns: None
*********************************************************************/
static void uart_initialize_hook ( Uart_Devices_Enum_T device, uart_reg_init_data_t *pInitRegs )
{
uart_chan[device]->ptr_reg = (volatile uart_reg_t*) pInitRegs->base_address;
uart_chan[device]->ptr_reg->ctl0 = pInitRegs->ctl0;
uart_chan[device]->ptr_reg->ctl1 = pInitRegs->ctl1;
uart_chan[device]->ptr_reg->ctl2 = pInitRegs->ctl2;
uart_chan[device]->ptr_reg->str = 0; /* clear Status Register */
if (0 == device)
{
uart0_set_isr_state( UART_ISR_OFF );
uart_initialize_port_0();
}
else if ( 1 == device )
{
uart1_set_isr_state( UART_ISR_OFF );
uart_initialize_port_1();
}
else if ( 2 == device )
{
uart2_set_isr_state( UART_ISR_OFF );
uart_initialize_port_2();
}
#if SJ3_IS // Zhao Zhigang added
else if( 3 == device) /*added by steven_yi for UART3*/
{
uart3_set_isr_state(UART_ISR_OFF);
uart_initialize_port_3();
}
#endif // Zhao Zhigang added
else
{
/* channel not supported */
}
}
#if UART_CONF_USE_GET_ISR_STATE
/**********************************************************************
* Description: Get state of rx/tx interrupts
* Parameters: state (rx/tx ISR on/off)
* Returns: None
*********************************************************************/
static Uart_Isr_State_T uart0_get_isr_state ( void )
{
Uart_Isr_State_T state;
/* check rx interrupt */
state = (UA0RIC != 0x46) ? UART_ISR_RX_ON : UART_ISR_OFF;
/* check tx interrupt and or it to previous */
state |= (UA0TIC != 0x46) ? UART_ISR_TX_ON : UART_ISR_OFF;
return ( state );
}
/**********************************************************************
* Description: Get state of rx/tx interrupts
* Parameters: state (rx/tx ISR on/off)
* Returns: None
*********************************************************************/
static Uart_Isr_State_T uart1_get_isr_state ( void )
{
Uart_Isr_State_T state;
/* check rx interrupt */
state = (UA1RIC != 0x46) ? UART_ISR_RX_ON : UART_ISR_OFF;
/* check tx interrupt and or it to previous */
state |= (UA1TIC != 0x46) ? UART_ISR_TX_ON : UART_ISR_OFF;
return ( state );
}
/**********************************************************************
* Description: Get state of rx/tx interrupts
* Parameters: state (rx/tx ISR on/off)
* Returns: None
*********************************************************************/
static Uart_Isr_State_T uart2_get_isr_state ( void )
{
Uart_Isr_State_T state;
/* check rx interrupt */
state = (UA2RIC != 0x46) ? UART_ISR_RX_ON : UART_ISR_OFF;
/* check tx interrupt and or it to previous */
state |= (UA2TIC != 0x46) ? UART_ISR_TX_ON : UART_ISR_OFF;
return ( state );
}
#if SJ3_IS // Zhao Zhigang
/**********************************************************************
* Description: Get state of rx/tx interrupts
* Parameters: state (rx/tx ISR on/off)
* Returns: None
*********************************************************************/
static Uart_Isr_State_T uart3_get_isr_state ( void )
{
Uart_Isr_State_T state;
/* check rx interrupt */
state = (UA3RIC != 0x46) ? UART_ISR_RX_ON : UART_ISR_OFF;
/* check tx interrupt and or it to previous */
state |= (UA3TIC != 0x46) ? UART_ISR_TX_ON : UART_ISR_OFF;
return ( state );
}
#endif // Zhao Zhigang
/**********************************************************************
* Description: Get state of rx/tx interrupts
* Parameters: ISR rx/tx on/off
* Returns: None
*********************************************************************/
Uart_Isr_State_T UART_Get_Isr_State ( Uart_Devices_Enum_T device )
{
Uart_Isr_State_T state;
if (0 == device)
{
state = uart0_get_isr_state();
}
else if ( 1 == device )
{
state = uart1_get_isr_state();
}
else if ( 2 == device )
{
state = uart2_get_isr_state();
}
else if(3 == device) /*steven_yi added*/
{
state = uart3_get_isr_state();
}
else
{
/* channel not supported */
}
return ( state );
}
#endif //#if UART_CONF_USE_GET_ISR_STATE
/**********************************************************************
* Description: Enable/disable interrupts
* Parameters: None
* Returns: None
*********************************************************************/
void UART_Set_Isr_State ( Uart_Devices_Enum_T device, Uart_Isr_State_T state )
{
if (0 == device)
{
uart0_set_isr_state(state);
}
else if ( 1 == device )
{
uart1_set_isr_state(state);
}
else if ( 2 == device )
{
uart2_set_isr_state(state);
}
#if SJ3_IS // Zhao Zhigang add
else if(3 == device)
{
uart3_set_isr_state(state);
}
#endif // Zhao Zhigang add
}
#if UART_CONF_SET_BAUDRATE_IS
/**********************************************************************
* Description: set baudrate, example: UART_Set_Baudrate( UART_BAUD_115K2 )
* ! UART is stopped after call to this function !
*
* Parameters: device, new baudrate (enum)
* Returns: None
*********************************************************************/
void UART_Set_Baudrate ( Uart_Devices_Enum_T device, UART_Baudrate_T baud )
{
if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
{
/* Stop first the UART */
uart_chan[device]->ptr_reg->ctl0 = 0;
if ( UART_NUM_SUPPORTED_BAUDRATES > baud )
{
uart_chan[device]->ptr_reg->ctl1 = uart_baud_rate_init_table[baud].ctl1;
uart_chan[device]->ptr_reg->ctl2 = uart_baud_rate_init_table[baud].ctl2;
}
else
{
/* baudrate not supported */
}
}
else
{
/* invalid device */
}
}
#endif // #if UART_CONF_SET_BAUDRATE_IS
#if UART_CONF_SET_MODE_IS
/**********************************************************************
* Description: set baudrate, Important -> this stops the UART <--
* Parameters: device, new mode
* Returns: None
*********************************************************************/
void UART_Set_Mode ( Uart_Devices_Enum_T device, uint_fast8_t mode )
{
if ( ( device < UART_NUM_HW_DEVICES) && ( NULL != uart_chan[device] ) )
{
/* Stop first the UART */
uart_chan[device]->ptr_reg->ctl0 &= ~( UART_CLOCK_ENABLE | UART_TX_ENABLE | UART_RX_ENABLE);
uart_chan[device]->ptr_reg->ctl0 = mode;
}
else
{
/* invalid device */
}
}
#endif //#if UART_CONF_SET_MODE_IS
#if UART_CONF_DESIP_OLD_STYLE_IS
/**********************************************************************
* Description: Read Uart data, compatible interface for sipprot
* Parameters: None
* Returns: read data byte or (-1) on error
*********************************************************************/
int16_t Com_Get_Char (void)
{
bool_fast result; /* = false; */
uint8_t data;
result = UART_Get_Char ( UART_DEVICE_HISIP, &data );
if ( true == result )
{
return ( ( int16_t ) data );
}
else
{
return ( -1 );
}
}
/**********************************************************************
* Description: Send Uart data, compatible interface for sipprot
* Parameters: data byte
* Returns: written data byte or (-1) on error
*********************************************************************/
int16_t Com_Put_Char ( uint16_t data )
{
bool_fast result; /* = false; */
result = UART_Put_Char ( UART_DEVICE_HISIP, (uint8_t ) data );
if ( true == result )
{
return ( ( int16_t ) data );
}
else
{
return ( -1 );
}
}
/*******************************************************************************
* Function: Open_Com, compatible interface for sipprot
*
* Parameters: None
* Returns: None
* Description: The SIPPROT specific version of initialize a UART channel.
*******************************************************************************/
void Open_Com (void)
{
Uart_Devices_Enum_T device;
device = UART_Initialize( UART_CONF_HISIP ); // initialize UART channel 0
if ( UART_NUM_HW_DEVICES > device )
{
UART_Start( device, UART_ISR_RX_TX_ON ); //open uart interrupt
}
else
{
/* error */
}
}
#endif //#if UART_CONF_DESIP_OLD_STYLE_IS
#if BLUETOOTH_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_RX_TX_ON ); //open uart interrupt
return true;
}
else
{
/* error */
return false;
}
}
/**********************************************************************
* Description: Read Uart data, compatible interface for sipprot
* Parameters: None
* Returns: read data byte or (-1) on error
*********************************************************************/
int8_t BT_Get_Char (Uart_Devices_Enum_T dev_index)
{
bool_fast result; /* = false; */
uint8_t data;
result = UART_Get_Char ( dev_index, &data );
if ( true == result )
{
return ( ( int8_t ) data );
}
else
{
return ( -1 );
}
}
/**********************************************************************
* 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 bool BT_RecvBuffer_Is_Full()
{
uart_chan_t *pChan;
pChan = uart_chan[UART_DEVICE_BT];
if ((!pChan->rx_count) && (pChan->rx_count < pChan->rx_buf_size)) // Rx buffer empty
{
return false;
}
else {
return true;
}
}
extern bool BT_RecvBuffer_Is_Empty()
{
uart_chan_t *pChan;
pChan = uart_chan[UART_DEVICE_BT];
if ((pChan->rx_count == 0) && (pChan->rx_in == 0) )
{
return true;
}
else {
return false;
}
}
extern bool BT_New_Data()
{
uart_chan_t *pChan;
pChan = uart_chan[UART_DEVICE_BT];
if((pChan->rx_count != 0) && (pChan->rx_in != pChan->rx_out))
{
return true;
}
else {
return false;
}
}
uint8_t BT_Get_Current_Inpx(Uart_Devices_Enum_T dev_index)
{
uart_chan_t *pChan;
pChan = uart_chan[dev_index];
return ((pChan->rx_in+pChan->rx_buf_size -pChan->rx_out) % pChan->rx_buf_size);
}
extern uint16_t UART_Service_Read(Uart_Devices_Enum_T dev_index, uint8_t *buffer, bool_t specific_size,uint16_t size)
{
uart_chan_t *pChan;
uint8_t recv_index,i;
pChan = uart_chan[dev_index];
if (!specific_size)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -