📄 drvuart.c
字号:
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_Write */
/* */
/* Parameter: */
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 /UART_PORT2 */
/* pu8RxBuf -[in] Specify the buffer to send the data to transmission FIFO. */
/* u32ReadBytes -[in] Specify the byte number of data. */
/* Returns: */
/* E_SUCCESS */
/* */
/* Description: */
/* TThe function is to write data to TX buffer to transmit data by UART */
/* Note: */
/* In IrDA Mode, the BAUD RATE configure MUST to use MODE # 0 */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvUART_Write(E_UART_PORT u32Port,uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
{
uint32_t u32Count, u32delayno;
UART_T * tUART;
tUART = (UART_T *)((uint32_t)UART0 + u32Port);
for (u32Count=0; u32Count<u32WriteBytes; u32Count++)
{
u32delayno = 0;
while (tUART->FSR.TE_FLAG !=1) /* Wait Tx empty and Time-out manner */
{
u32delayno++;
if ( u32delayno >= 0x40000000 )
return E_DRVUART_ERR_TIMEOUT;
}
tUART->DATA = pu8TxBuf[u32Count]; /* Send UART Data from buffer */
}
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_EnablePDMA */
/* */
/* Parameter: */
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 */
/* Returns: */
/* None */
/* */
/* Description: */
/* The function is used to control enable Transmit and Receive PDMA channel */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUART_EnablePDMA(E_UART_PORT u32Port)
{
if(u32Port == UART_PORT0)
{
UART0->IER.DMA_TX_EN = 1;
UART0->IER.DMA_RX_EN = 1;
}
else if(u32Port == UART_PORT1)
{
UART1->IER.DMA_TX_EN = 1;
UART1->IER.DMA_RX_EN = 1;
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_DisablePDMA */
/* */
/* Parameter: */
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 */
/* Returns: */
/* None */
/* */
/* Description: */
/* The function is used to control disable PDMA Transmit/Receive PDMA channel */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUART_DisablePDMA(E_UART_PORT u32Port)
{
if(u32Port == UART_PORT0)
{
UART0->IER.DMA_TX_EN = 0;
UART0->IER.DMA_RX_EN = 0;
}
else if(u32Port == UART_PORT1)
{
UART1->IER.DMA_TX_EN = 0;
UART1->IER.DMA_RX_EN = 0;
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_SetFnIRCR */
/* */
/* Parameter: */
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 /UART_PORT2 */
/* STR_IRCR_T -[in] Ther stucture of IRCR */
/* It includes of */
/* u8cTXSelect: 1: Enable Irda transmit function.(TX mode) */
/* 0: Disable Irda transmit function.(RX mode) */
/* u8cInvTX: Inverse TX signal */
/* u8cInvRX: Inverse RX signal */
/* */
/* Returns: */
/* E_SUCCESS */
/* */
/* Description: */
/* The function is used to configure IRDA relative settings. */
/* It consists of TX or RX mode and Inverse TX or RX signals. */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUART_SetFnIRDA(E_UART_PORT u32Port,STR_IRCR_T *str_IRCR )
{
UART_T * tUART;
tUART = (UART_T *)((uint32_t)UART0 + u32Port);
tUART->FUNSEL.FUN_SEL = FUN_IRCR; /* Enable IrDA function and configure */
tUART->IRCR.TX_SELECT = (str_IRCR->u8cTXSelect) ?1:0;
tUART->IRCR.INV_TX = str_IRCR->u8cInvTX ;
tUART->IRCR.INV_RX = str_IRCR->u8cInvRX ;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_SetFnLIN */
/* */
/* Parameter: */
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 /UART_PORT2 */
/* u16Mode -[in] MODE_TX or MODE_RX */
/* u16BreakLength -[in] Break Count */
/* Returns: */
/* None */
/* */
/* Description: */
/* The function is used to set LIN Control Register */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUART_SetFnLIN(E_UART_PORT u32Port,uint16_t u16Mode,uint16_t u16BreakLength)
{
UART_T * tUART;
tUART = (UART_T *)((uint32_t)UART0 + u32Port);
tUART->FUNSEL.FUN_SEL = FUN_LIN;
tUART->ALTCON.LIN_BKFL = u16BreakLength;
tUART->ALTCON.LIN_TX_EN = (u16Mode & MODE_TX) ?1:0;
tUART->ALTCON.LIN_RX_EN = (u16Mode & MODE_RX) ?1:0;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_SetFnRS485 */
/* */
/* Parameter: */
/* u32Port -[in] UART Channel: UART_PORT0 / UART_PORT1 / UART_PORT2 */
/* STR_RS485_T -[in] Ther stucture of RS485 */
/* It includes of */
/* u8cModeSelect: MODE_RS485_AUD / MODE_RS485_AAD */
/* MODE_RS485_NMM */
/* u8cAddrEnable: Enable or Disable RS-485 Address Detection */
/* u8cAddrValue: Match Address Value */
/* u8cDelayTime: Set transmit delay time value */
/* u8cRxDisable: Enable or Disable receiver function */
/* Returns: */
/* None */
/* */
/* Description: */
/* The function is to Set RS485 Control Register */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUART_SetFnRS485(E_UART_PORT u32Port,STR_RS485_T *str_RS485)
{
UART_T * tUART;
tUART = (UART_T *)((uint32_t)UART0 + u32Port);
tUART->FUNSEL.FUN_SEL = FUN_RS485;
tUART->ALTCON.RS485_ADD_EN = (str_RS485-> u8cAddrEnable) ?1:0;
tUART->ALTCON.ADDR_MATCH = str_RS485-> u8cAddrValue ;
tUART->ALTCON.RS485_NMM = (str_RS485-> u8cModeSelect & MODE_RS485_NMM)?1:0;
tUART->ALTCON.RS485_AAD = (str_RS485-> u8cModeSelect & MODE_RS485_AAD)?1:0;
tUART->ALTCON.RS485_AUD = (str_RS485-> u8cModeSelect & MODE_RS485_AUD)?1:0;
tUART->TOR.DLY = str_RS485-> u8cDelayTime;
tUART->FCR.RX_DIS = (str_RS485-> u8cRxDisable) ?1:0;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUART_GetVersion */
/* */
/* Parameter: */
/* None */
/* Returns: */
/* Version Number */
/* Side effects: */
/* */
/* Description: */
/* The function is used to get DrvUART Version Number */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvUART_GetVersion(void)
{
return DRVUART_VERSION_NUM;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -