這兩天在整理代碼,看了hal的代碼,效率有待提高。

?? 可以用宏定義來實(shí)現(xiàn),得到高效的代碼。建議用##連接宏。


/*********************************************************************
?* @fn????? USART_GetITStatus
?*
?* @brief?? Checks whether the specified USART interrupt has occurred or not.
?*
?* @param?? USARTx - where x can be 1 to select the USART peripheral.
?*????????? USART_IT - specifies the USART interrupt source to check.
?*??????????? USART_IT_LBD - LIN Break detection interrupt.
?*??????????? USART_IT_TXE - Tansmit Data Register empty interrupt.
?*??????????? USART_IT_TC - Transmission complete interrupt.
?*??????????? USART_IT_RXNE - Receive Data register not empty interrupt.
?*??????????? USART_IT_IDLE - Idle line detection interrupt.
?*??????????? USART_IT_ORE_RX - OverRun Error interrupt if the RXNEIE bit is set.
?*??????????? USART_IT_ORE_ER - OverRun Error interrupt if the EIE bit is set.
?*??????????? USART_IT_NE - Noise Error interrupt.
?*??????????? USART_IT_FE - Framing Error interrupt.
?*??????????? USART_IT_PE - Parity Error interrupt.
?*
?* @return? bitstatus: SET or RESET.
?*/
ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint16_t USART_IT)
{
??? uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
??? ITStatus bitstatus = RESET;

########################################################
??? usartreg = (((uint8_t)USART_IT) >> 0x05);
??? itmask = USART_IT & IT_Mask;
??? itmask = (uint32_t)0x01 << itmask;

??? if(usartreg == 0x01)???
??? {
??????? itmask &= USARTx->CTLR1;

??? }???????????????????????????????????????????????????????
??? else if(usartreg == 0x02)??????????? ?
??? {???????????????????????????????????????????????????????
??????? itmask &= USARTx->CTLR2;????

??? }????????????????????????????????????????????????????????

??? else???????????????????????????????????????????????????
??? {?????????????????????????????????????????????????????????
??????? itmask &= USARTx->CTLR3;
??? }

??? bitpos = USART_IT >> 0x08;
??? bitpos = (uint32_t)0x01 << bitpos;
??? bitpos &= USARTx->STATR;

########################################################

??? if((itmask != (uint16_t)RESET) && (bitpos != (uint16_t)RESET))
??? {
??????? bitstatus = SET;
??? }
??? else
??? {
??????? bitstatus = RESET;
??? }

??? return bitstatus;
}

您好,感謝你的建議,這邊會反饋給相關(guān)同事


我去,我基本上極少用串口中斷,還真沒留意這個函數(shù)里面是這樣處理的啊…這也太浪費(fèi)資源了…感覺還是不用官方的函數(shù),自己直接操作寄存器更節(jié)省資源。


就是三種通信類外設(shè)中斷標(biāo)志位這么寫。完全要以用inline類函數(shù)或宏定義實(shí)現(xiàn)

更高效率。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频