| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 |
- /*!
- * @file apm32e10x_usart.c
- *
- * @brief This file provides all the USART firmware functions
- *
- * @version V1.0.2
- *
- * @date 2022-12-31
- *
- * @attention
- *
- * Copyright (C) 2021-2023 Geehy Semiconductor
- *
- * You may not use this file except in compliance with the
- * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
- *
- * The program is only for reference, which is distributed in the hope
- * that it will be useful and instructional for customers to develop
- * their software. Unless required by applicable law or agreed to in
- * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
- * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
- * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
- * and limitations under the License.
- */
- #include "apm32e10x_usart.h"
- #include "apm32e10x_rcm.h"
- /** @addtogroup APM32E10x_StdPeriphDriver
- @{
- */
- /** @addtogroup USART_Driver
- * @brief USART driver modules
- @{
- */
- /** @defgroup USART_Functions Functions
- @{
- */
- /*!
- * @brief Reset usart peripheral registers to their default reset values
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_Reset(USART_T* usart)
- {
- if (USART1 == usart)
- {
- RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_USART1);
- RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_USART1);
- }
- else if (USART2 == usart)
- {
- RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_USART2);
- RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_USART2);
- }
- else if (USART3 == usart)
- {
- RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_USART3);
- RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_USART3);
- }
- else if (UART4 == usart)
- {
- RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_UART4);
- RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_UART4);
- }
- else if (UART5 == usart)
- {
- RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_UART5);
- RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_UART5);
- }
- }
- /*!
- * @brief Config the USART peripheral according to the specified parameters in the usartConfig
- *
- * @param uart: Select the USART or the UART peripheral
- *
- * @param usartConfig: pointer to a USART_Config_T structure
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_Config(USART_T* uart, USART_Config_T* usartConfig)
- {
- uint32_t temp, fCLK, intDiv, fractionalDiv;
- temp = uart->CTRL1;
- temp &= 0xE9F3;
- temp |= (uint32_t)usartConfig->mode | \
- (uint32_t)usartConfig->parity | \
- (uint32_t)usartConfig->wordLength;
- uart->CTRL1 = temp;
- temp = uart->CTRL2;
- temp &= 0xCFFF;
- temp |= usartConfig->stopBits;
- uart->CTRL2 = temp;
- temp = uart->CTRL3;
- temp &= 0xFCFF;
- temp |= (uint32_t)usartConfig->hardwareFlow;
- uart->CTRL3 = temp;
- if (uart == USART1)
- {
- RCM_ReadPCLKFreq(NULL, &fCLK);
- }
- else
- {
- RCM_ReadPCLKFreq(&fCLK, NULL);
- }
- intDiv = ((25 * fCLK) / (4 * (usartConfig->baudRate)));
- temp = (intDiv / 100) << 4;
- fractionalDiv = intDiv - (100 * (temp >> 4));
- temp |= ((((fractionalDiv * 16) + 50) / 100)) & ((uint8_t)0x0F);
- uart->BR = temp;
- }
- /*!
- * @brief Fills each USART_InitStruct member with its default value
- *
- * @param usartConfig: pointer to a USART_Config_T structure which will be initialized
- *
- * @retval None
- */
- void USART_ConfigStructInit(USART_Config_T* usartConfig)
- {
- usartConfig->baudRate = 9600;
- usartConfig->wordLength = USART_WORD_LEN_8B;
- usartConfig->stopBits = USART_STOP_BIT_1;
- usartConfig->parity = USART_PARITY_NONE ;
- usartConfig->mode = USART_MODE_TX_RX;
- usartConfig->hardwareFlow = USART_HARDWARE_FLOW_NONE;
- }
- /*!
- * @brief Configuration communication clock
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param clockConfig: Pointer to a USART_clockConfig_T structure
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3
- */
- void USART_ConfigClock(USART_T* usart, USART_ClockConfig_T* clockConfig)
- {
- usart->CTRL2_B.CLKEN = clockConfig->clock;
- usart->CTRL2_B.CPHA = clockConfig->phase;
- usart->CTRL2_B.CPOL = clockConfig->polarity;
- usart->CTRL2_B.LBCPOEN = clockConfig->lastBit;
- }
- /*!
- * @brief Fills each clockConfig member with its default value
- *
- * @param clockConfig: Pointer to a USART_clockConfig_T structure
- *
- * @retval None
- *
- * @note
- */
- void USART_ConfigClockStructInit(USART_ClockConfig_T* clockConfig)
- {
- clockConfig->clock = USART_CLKEN_DISABLE;
- clockConfig->phase = USART_CLKPHA_1EDGE;
- clockConfig->polarity = USART_CLKPOL_LOW;
- clockConfig->lastBit = USART_LBCP_DISABLE;
- }
- /*!
- * @brief Enables the specified USART peripheral
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_Enable(USART_T* usart)
- {
- usart->CTRL1_B.UEN = BIT_SET;
- }
- /*!
- * @brief Disable the specified USART peripheral
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_Disable(USART_T* usart)
- {
- usart->CTRL1_B.UEN = BIT_RESET;
- }
- /*!
- * @brief Enables the USART DMA interface
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param dmaReq: Specifies the DMA request
- * This parameter can be one of the following values:
- * @arg USART_DMA_TX: USART DMA receive request
- * @arg USART_DMA_RX: USART DMA transmit request
- * @arg USART_DMA_TX_RX: USART DMA transmit/receive request
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableDMA(USART_T* usart, USART_DMA_T dmaReq)
- {
- usart->CTRL3 |= dmaReq;
- }
- /*!
- * @brief Disable the USART DMA interface
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param dmaReq: Specifies the DMA request
- * This parameter can be one of the following values:
- * @arg USART_DMA_TX: USART DMA receive request
- * @arg USART_DMA_RX: USART DMA transmit request
- * @arg USART_DMA_TX_RX: USART DMA transmit/receive request
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableDMA(USART_T* usart, USART_DMA_T dmaReq)
- {
- usart->CTRL3 &= (uint32_t)~dmaReq;
- }
- /*!
- * @brief Configures the address of the USART node
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param address: Indicates the address of the USART node
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_Address(USART_T* usart, uint8_t address)
- {
- usart->CTRL2_B.ADDR = address;
- }
- /*!
- * @brief Selects the USART WakeUp method.
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param wakeup: Specifies the selected USART auto baud rate method
- * This parameter can be one of the following values:
- * @arg USART_WAKEUP_IDLE_LINE: WakeUp by an idle line detection
- * @arg USART_WAKEUP_ADDRESS_MARK: WakeUp by an address mark
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_ConfigWakeUp(USART_T* usart, USART_WAKEUP_T wakeup)
- {
- usart->CTRL1_B.WUPMCFG = wakeup;
- }
- /*!
- * @brief Enable USART Receiver in mute mode
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableMuteMode(USART_T* usart)
- {
- usart->CTRL1_B.RXMUTEEN = BIT_SET;
- }
- /*!
- * @brief Disable USART Receiver in active mode
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableMuteMode(USART_T* usart)
- {
- usart->CTRL1_B.RXMUTEEN = BIT_RESET;
- }
- /*!
- * @brief Sets the USART LIN Break detection length
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param length: Specifies the LIN break detection length
- * This parameter can be one of the following values:
- * @arg USART_LBDL_10B: 10-bit break detection
- * @arg USART_LBDL_10B: 11-bit break detection
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_ConfigLINBreakDetectLength(USART_T* usart, USART_LBDL_T length)
- {
- usart->CTRL2_B.LBDLCFG = length;
- }
- /*!
- * @brief Enables the USART LIN MODE
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableLIN(USART_T* usart)
- {
- usart->CTRL2_B.LINMEN = BIT_SET;
- }
- /*!
- * @brief Disable the USART LIN MODE
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableLIN(USART_T* usart)
- {
- usart->CTRL2_B.LINMEN = BIT_RESET;
- }
- /*!
- * @brief Transmitter Enable
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableTx(USART_T* usart)
- {
- usart->CTRL1_B.TXEN = BIT_SET;
- }
- /*!
- * @brief Transmitter Disable
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableTx(USART_T* usart)
- {
- usart->CTRL1_B.TXEN = BIT_RESET;
- }
- /*!
- * @brief Receiver enable
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableRx(USART_T* usart)
- {
- usart->CTRL1_B.RXEN = BIT_SET;
- }
- /*!
- * @brief Receiver disable
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableRx(USART_T* usart)
- {
- usart->CTRL1_B.RXEN = BIT_RESET;
- }
- /*!
- * @brief Transmits single data
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param data: the data to transmit
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_TxData(USART_T* usart, uint16_t data)
- {
- usart->DATA_B.DATA = data;
- }
- /*!
- * @brief Returns the most recent received data
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- uint16_t USART_RxData(USART_T* usart)
- {
- return (uint16_t)(usart->DATA_B.DATA);
- }
- /*!
- * @brief Transmits break characters
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_TxBreak(USART_T* usart)
- {
- usart->CTRL1_B.TXBF = BIT_SET;
- }
- /*!
- * @brief Sets the specified USART guard time
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param guardTime: Specifies the guard time
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3
- */
- void USART_ConfigGuardTime(USART_T* usart, uint8_t guardTime)
- {
- usart->GTPSC_B.GRDT = guardTime;
- }
- /*!
- * @brief Sets the system clock divider number
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param div: specifies the divider number
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3
- */
- void USART_ConfigPrescaler(USART_T* usart, uint8_t div)
- {
- usart->GTPSC_B.PSC = div;
- }
- /*!
- * @brief Enables the USART Smart Card mode
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The Smart Card mode is not available for UART4 and UART5
- */
- void USART_EnableSmartCard(USART_T* usart)
- {
- usart->CTRL3_B.SCEN = BIT_SET;
- }
- /*!
- * @brief Disable the USART Smart Card mode
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The Smart Card mode is not available for UART4 and UART5
- */
- void USART_DisableSmartCard(USART_T* usart)
- {
- usart->CTRL3_B.SCEN = BIT_RESET;
- }
- /*!
- * @brief Enables NACK transmission
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The Smart Card mode is not available for UART4 and UART5
- */
- void USART_EnableSmartCardNACK(USART_T* usart)
- {
- usart->CTRL3_B.SCNACKEN = BIT_SET;
- }
- /*!
- * @brief Disable NACK transmission
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The Smart Card mode is not available for UART4 and UART5
- */
- void USART_DisableSmartCardNACK(USART_T* usart)
- {
- usart->CTRL3_B.SCNACKEN = BIT_RESET;
- }
- /*!
- * @brief Enables USART Half Duplex communication
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableHalfDuplex(USART_T* usart)
- {
- usart->CTRL3_B.HDEN = BIT_SET;
- }
- /*!
- * @brief Disable USART Half Duplex communication
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableHalfDuplex(USART_T* usart)
- {
- usart->CTRL3_B.HDEN = BIT_RESET;
- }
- /*!
- * @brief Configures the USART's IrDA interface
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param IrDAMode: Specifies the IrDA mode
- * This parameter can be one of the following values:
- * @arg USART_IRDALP_NORMAL: Normal
- * @arg USART_IRDALP_LOWPOWER: Low-Power
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_ConfigIrDA(USART_T* usart, USART_IRDALP_T IrDAMode)
- {
- usart->CTRL3_B.IRLPEN = IrDAMode;
- }
- /*!
- * @brief Enables the USART's IrDA interface
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableIrDA(USART_T* usart)
- {
- usart->CTRL3_B.IREN = BIT_SET;
- }
- /*!
- * @brief Disable the USART's IrDA interface
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableIrDA(USART_T* usart)
- {
- usart->CTRL3_B.IREN = BIT_RESET;
- }
- /*!
- * @brief Enable the specified USART interrupts
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param interrupt: Specifies the USART interrupts sources
- * The parameter can be one of following values:
- * @arg USART_INT_PE: Parity error interrupt
- * @arg USART_INT_TXBE: Tansmit data buffer empty interrupt
- * @arg USART_INT_TXC: Transmission complete interrupt
- * @arg USART_INT_RXBNE: Receive data buffer not empty interrupt
- * @arg USART_INT_IDLE: Idle line detection interrupt
- * @arg USART_INT_LBD: LIN break detection interrupt
- * @arg USART_INT_CTS: CTS change interrupt
- * @arg USART_INT_ERR: Error interrupt(Frame error, noise error, overrun error)
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_EnableInterrupt(USART_T* usart, USART_INT_T interrupt)
- {
- uint32_t temp;
- temp = (uint32_t)(interrupt & 0xffff);
- if (interrupt & 0X10000)
- {
- usart->CTRL1 |= temp;
- }
- if (interrupt & 0X20000)
- {
- usart->CTRL2 |= temp;
- }
- if (interrupt & 0X40000)
- {
- usart->CTRL3 |= temp;
- }
- }
- /*!
- * @brief Disables the specified USART interrupts
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param interrupt: Specifies the USART interrupts sources
- * The parameter can be one of following values:
- * @arg USART_INT_PE: Parity error interrupt
- * @arg USART_INT_TXBE: Tansmit data buffer empty interrupt
- * @arg USART_INT_TXC: Transmission complete interrupt
- * @arg USART_INT_RXBNE: Receive data buffer not empty interrupt
- * @arg USART_INT_IDLE: Idle line detection interrupt
- * @arg USART_INT_LBD: LIN break detection interrupt
- * @arg USART_INT_CTS: CTS change interrupt
- * @arg USART_INT_ERR: Error interrupt(Frame error, noise error, overrun error)
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_DisableInterrupt(USART_T* usart, USART_INT_T interrupt)
- {
- uint32_t temp;
- temp = (uint32_t)~(interrupt & 0xffff);
- if (interrupt & 0X10000)
- {
- usart->CTRL1 &= temp;
- }
- if (interrupt & 0X20000)
- {
- usart->CTRL2 &= temp;
- }
- if (interrupt & 0X40000)
- {
- usart->CTRL3 &= temp;
- }
- }
- /*!
- * @brief Read the specified USART flag
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param flag: Specifies the flag to check
- * The parameter can be one of following values:
- * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
- * @arg USART_FLAG_LBD: LIN Break detection flag
- * @arg USART_FLAG_TXBE: Transmit data buffer empty flag
- * @arg USART_FLAG_TXC: Transmission Complete flag
- * @arg USART_FLAG_RXBNE: Receive data buffer not empty flag
- * @arg USART_FLAG_IDLE: Idle Line detection flag
- * @arg USART_FLAG_OVRE: OverRun Error flag
- * @arg USART_FLAG_NE: Noise Error flag
- * @arg USART_FLAG_FE: Framing Error flag
- * @arg USART_FLAG_PE: Parity Error flag
- *
- * @retval The new state of flag (SET or RESET)
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- uint8_t USART_ReadStatusFlag(USART_T* usart, USART_FLAG_T flag)
- {
- return (usart->STS & flag) ? SET : RESET;
- }
- /*!
- * @brief Clears the USARTx's pending flags
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param flag: Specifies the flag to clear
- * The parameter can be one of following values:
- * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
- * @arg USART_FLAG_LBD: LIN Break detection flag
- * @arg USART_FLAG_TXC: Transmission Complete flag
- * @arg USART_FLAG_RXBNE: Receive data buffer not empty flag
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_ClearStatusFlag(USART_T* usart, USART_FLAG_T flag)
- {
- usart->STS &= (uint32_t)~flag;
- }
- /*!
- * @brief Read the specified USART interrupt flag
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param flag: Specifies the USART interrupt source to check
- * The parameter can be one of following values:
- * @arg USART_INT_TXBE: Tansmit data buffer empty interrupt
- * @arg USART_INT_TXC: Transmission complete interrupt
- * @arg USART_INT_RXBNE: Receive data buffer not empty interrupt
- * @arg USART_INT_IDLE: Idle line detection interrupt
- * @arg USART_INT_LBD: LIN break detection interrupt
- * @arg USART_INT_CTS: CTS change interrupt
- * @arg USART_INT_OVRE: OverRun Error interruptpt
- * @arg USART_INT_NE: Noise Error interrupt
- * @arg USART_INT_FE: Framing Error interrupt
- * @arg USART_INT_PE: Parity error interrupt
- *
- * @retval The new state of flag (SET or RESET)
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- uint8_t USART_ReadIntFlag(USART_T* usart, USART_INT_T flag)
- {
- uint32_t itFlag, srFlag;
- if (flag & 0x10000)
- {
- itFlag = usart->CTRL1 & flag & 0xffff;
- }
- else if (flag & 0x20000)
- {
- itFlag = usart->CTRL2 & flag & 0xffff;
- }
- else
- {
- itFlag = usart->CTRL3 & flag & 0xffff;
- }
- srFlag = flag >> 24;
- srFlag = (uint32_t)(1 << srFlag);
- srFlag = usart->STS & srFlag;
- if (srFlag && itFlag)
- {
- return SET;
- }
- return RESET;
- }
- /*!
- * @brief Clears the USART interrupt pending bits
- *
- * @param usart: Select the USART or the UART peripheral
- *
- * @param flag: Specifies the interrupt pending bit to clear
- * The parameter can be one of following values:
- * @arg USART_INT_RXBNE: Receive data buffer not empty interrupt
- * @arg USART_INT_TXC: Transmission complete interrupt
- * @arg USART_INT_LBD: LIN break detection interrupt
- * @arg USART_INT_CTS: CTS change interrupt
- *
- * @retval None
- *
- * @note The usart can be USART1, USART2, USART3, UART4 and UART5
- */
- void USART_ClearIntFlag(USART_T* usart, USART_INT_T flag)
- {
- uint32_t srFlag;
- srFlag = flag >> 24;
- srFlag = (uint32_t)(1 << srFlag);
- usart->STS &= (uint32_t)~srFlag;
- }
- /**@} end of group USART_Functions */
- /**@} end of group USART_Driver */
- /**@} end of group APM32E10x_StdPeriphDriver */
|