From 2ebb8217f43b69f491620423ea4d5d5944d1f91d Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期六, 05 七月 2025 22:43:58 +0800 Subject: [PATCH] 格式化部分代码 --- keil/include/components/hal/UART.c | 87 +++++++++++++++++++++++++++---------------- 1 files changed, 55 insertions(+), 32 deletions(-) diff --git a/keil/include/components/hal/UART.c b/keil/include/components/hal/UART.c index 4839aaf..795a75d 100644 --- a/keil/include/components/hal/UART.c +++ b/keil/include/components/hal/UART.c @@ -69,7 +69,7 @@ { enum UART_BAUD_T baud; HIDO_UINT32 u32Baud; -} baud_map[] = +} baud_map[] = { {BAUD_1200, 1200}, {BAUD_2400, 2400}, @@ -99,7 +99,7 @@ return baud_map[i].baud; } } - + return BAUD_115200; } @@ -108,11 +108,11 @@ *******************************************************************************/ /******************************************************************************* - * Function Name : - * Description : - * Input : - * Output : - * Return : + * Function Name : + * Description : + * Input : + * Output : + * Return : * Author : 杜键 * Modified Date: : 2018年4月24日 *******************************************************************************/ @@ -120,7 +120,7 @@ { /* 初始化参数 */ HIDO_UtilBzero(&l_astUartInfo[_eUartID], sizeof(ST_UartInfo)); - + l_astUartInfo[_eUartID].m_eUartPort = _ePort; return HIDO_OK; @@ -145,7 +145,7 @@ #ifdef _USE_OS_ l_astUartInfo[_eUartID].m_mutexLock = osMutexCreate(HIDO_NULL); #endif - + struct UART_CFG_T uart_cfg = { .parity = UART_PARITY_NONE, @@ -168,32 +168,36 @@ l_astUartInfo[_eUartID].m_u32RxBufSize = _pstInit->m_u32RxBufSize; if(UART_RX_MODE_DMA == _pstInit->m_eRxMode) { - l_astUartInfo[_eUartID].m_pu8RxLastPos= l_astUartInfo[_eUartID].m_pu8RxBuf; - l_astUartInfo[_eUartID].m_pu8RxBufEnd = l_astUartInfo[_eUartID].m_pu8RxBuf + l_astUartInfo[_eUartID].m_u32RxBufSize - 1; + HIDO_ArraryQueueInit( + &l_astUartInfo[_eUartID].m_stRxArraryQueue, + _pstInit->m_pu8RxBuf, + _pstInit->m_u32RxBufSize, + sizeof(HIDO_UINT8)); + return HIDO_OK; } else if(UART_RX_MODE_INT == _pstInit->m_eRxMode) { HIDO_ArraryQueueInit( - &l_astUartInfo[_eUartID].m_stRxArraryQueue, - _pstInit->m_pu8RxBuf, - _pstInit->m_u32RxBufSize, - sizeof(HIDO_UINT8)); + &l_astUartInfo[_eUartID].m_stRxArraryQueue, + _pstInit->m_pu8RxBuf, + _pstInit->m_u32RxBufSize, + sizeof(HIDO_UINT8)); } l_astUartInfo[_eUartID].m_pu8TxBuf = _pstInit->m_pu8TxBuf; l_astUartInfo[_eUartID].m_u32TxBufSize = _pstInit->m_u32TxBufSize; l_astUartInfo[_eUartID].m_fnRxISR = _pstInit->m_fnRxISR; l_astUartInfo[_eUartID].m_u32TxQueueMemberCnt = _pstInit->m_u32TxQueueMemberCnt; - + uart_open(l_astUartInfo[_eUartID].m_eUartPort, &uart_cfg); if((UART_TX_MODE_DMA == _pstInit->m_eTxMode) || (UART_TX_MODE_INT == _pstInit->m_eTxMode)) { HIDO_VLQInit( - &(l_astUartInfo[_eUartID].m_stTxVLQueue), - _pstInit->m_pu8TxBuf, - _pstInit->m_u32TxBufSize, - _pstInit->m_u32TxQueueMemberCnt); + &(l_astUartInfo[_eUartID].m_stTxVLQueue), + _pstInit->m_pu8TxBuf, + _pstInit->m_u32TxBufSize, + _pstInit->m_u32TxQueueMemberCnt); } if (UART_RX_MODE_INT == _pstInit->m_eRxMode) @@ -224,19 +228,19 @@ else if(UART_RX_MODE_INT == l_astUartInfo[_eUartID].m_eRxMode) { HIDO_ArraryQueueInit( - &l_astUartInfo[_eUartID].m_stRxArraryQueue, - l_astUartInfo[_eUartID].m_pu8RxBuf, - l_astUartInfo[_eUartID].m_u32RxBufSize, - sizeof(HIDO_UINT8)); + &l_astUartInfo[_eUartID].m_stRxArraryQueue, + l_astUartInfo[_eUartID].m_pu8RxBuf, + l_astUartInfo[_eUartID].m_u32RxBufSize, + sizeof(HIDO_UINT8)); } if((UART_TX_MODE_DMA == l_astUartInfo[_eUartID].m_eTxMode) || (UART_TX_MODE_INT == l_astUartInfo[_eUartID].m_eTxMode)) { HIDO_VLQInit( - &(l_astUartInfo[_eUartID].m_stTxVLQueue), - l_astUartInfo[_eUartID].m_pu8TxBuf, - l_astUartInfo[_eUartID].m_u32TxBufSize, - l_astUartInfo[_eUartID].m_u32TxQueueMemberCnt); + &(l_astUartInfo[_eUartID].m_stTxVLQueue), + l_astUartInfo[_eUartID].m_pu8TxBuf, + l_astUartInfo[_eUartID].m_u32TxBufSize, + l_astUartInfo[_eUartID].m_u32TxQueueMemberCnt); } uart_receive(l_astUartInfo[_eUartID].m_eUartPort, &l_astUartInfo[_eUartID].m_u8RxValue, 1, uart_receive_callback); @@ -270,7 +274,7 @@ .int_rx = true, .int_tx = false, }; - + uart_open(l_astUartInfo[_eUartID].m_eUartPort, &uart_cfg); return HIDO_OK; @@ -338,7 +342,7 @@ static void uart_receive_callback(void *dev, uint32_t err_code) { E_UartID eUartID = UART_ID_4G; - + HIDO_UINT8 u8RecvByte = l_astUartInfo[eUartID].m_u8RxValue; HIDO_ArraryQueueIn(&l_astUartInfo[eUartID].m_stRxArraryQueue, &u8RecvByte); @@ -369,12 +373,17 @@ osMutexWait(l_astUartInfo[_eUartID].m_mutexLock, osWaitForever); #endif - if (UART_RX_MODE_INT == l_astUartInfo[_eUartID].m_eRxMode) + switch(l_astUartInfo[_eUartID].m_eRxMode) + { + case UART_RX_MODE_INT: + case UART_RX_MODE_DMA: { if (HIDO_ArraryQueueOut(&l_astUartInfo[_eUartID].m_stRxArraryQueue, _pu8Char) == HIDO_OK) { i32Result = HIDO_OK; } + break; + } } #ifdef _USE_OS_ @@ -382,6 +391,20 @@ #endif return i32Result; +} + +/******************************************************************************* + * Function Name : Uart_SetChar + * Description : + * Input : + * Output : + * Return : + * Author : 杜键 + * Modified Date: : 2018年4月24日 + *******************************************************************************/ +HIDO_VOID Uart_SetChar(E_UartID _eUartID, HIDO_UINT8 _u8Data) +{ + HIDO_ArraryQueueIn(&l_astUartInfo[_eUartID].m_stRxArraryQueue, &_u8Data); } /******************************************************************************* @@ -424,7 +447,7 @@ memcpy(pstMember->m_pDataAddr, _pu8Data, _u32Len); pstMember = HIDO_VLQGetDequeueMember(&(l_astUartInfo[_eUartID].m_stTxVLQueue)); HIDO_UnLock(); - + uart_send(l_astUartInfo[_eUartID].m_eUartPort, pstMember->m_pDataAddr, pstMember->m_u32DataLen, uart_send_callback); } } -- Gitblit v1.9.3