Skip to content

*stm32:usart - optimise code use inlinings #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions include/unicore-mx/stm32/common/usart_common_f124.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,119 @@ specific memorymap.h header before including this header file.*/

/* TODO */ /* Note to Uwe: what needs to be done here? */

BEGIN_DECLS
/** @brief USART Send a Data Word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@param[in] data unsigned 16 bit.
*/
static inline
void usart_send(uint32_t usart, uint16_t data)
{
/* Send data. */
USART_DR(usart) = (data & USART_DR_MASK);
}

/*---------------------------------------------------------------------------*/
/** @brief USART Read a Received Data Word.

If parity is enabled the MSB (bit 7 or 8 depending on the word length) is the
parity bit.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@returns unsigned 16 bit data word.
*/
static inline
uint16_t usart_recv(uint32_t usart)
{
/* Receive data. */
return USART_DR(usart) & USART_DR_MASK;
}

/*---------------------------------------------------------------------------*/
/** @brief USART Check if Transmit Data Buffer is empty
*
* Check if transmit data buffer is empty and is ready to accept
* the next data word.
*
* @param[in] usart unsigned 32 bit. USART block register address base @ref
* usart_reg_base
* @returns boolean: transmit data buffer is ready to accept the next data word
*/
static inline
bool usart_is_send_ready(uint32_t usart)
{
return ((USART_SR(usart) & USART_SR_TXE)); /* TXE set, means ready to write byte */
}


/*---------------------------------------------------------------------------*/
/** @brief USART Wait for Transmit Data Buffer Empty

Blocks until the transmit data buffer becomes empty and is ready to accept the
next data word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
*/
static inline
void usart_wait_send_ready(uint32_t usart)
{
/* Wait until the data has been transferred into the shift register. */
while ((USART_SR(usart) & USART_SR_TXE) == 0);
}

/*---------------------------------------------------------------------------*/
/** @brief USART check if Received Data Available

Check if data buffer holds a valid received data word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@returns boolean: data buffer holds a valid received data word.
*/
static inline
bool usart_is_recv_ready(uint32_t usart)
{
return ((USART_SR(usart) & USART_SR_RXNE)); /* RXNE set means there is data to be read */
}


/*---------------------------------------------------------------------------*/
/** @brief USART Wait for Received Data Available

Blocks until the receive data buffer holds a valid received data word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
*/

static inline
void usart_wait_recv_ready(uint32_t usart)
{
/* Wait until the data is ready to be received. */
while ((USART_SR(usart) & USART_SR_RXNE) == 0);
}

/*---------------------------------------------------------------------------*/
/** @brief USART Read a Status Flag.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@param[in] flag Unsigned int32. Status register flag @ref usart_sr_flags.
@returns boolean: flag set.
*/

static inline
bool usart_get_flag(uint32_t usart, uint32_t flag)
{
return ((USART_SR(usart) & flag) != 0);
}

END_DECLS

#endif
/** @cond */
#else
Expand Down
107 changes: 0 additions & 107 deletions lib/stm32/common/usart_common_f124.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,113 +32,6 @@ Devices can have up to 3 USARTs and 2 UARTs.
#include <unicore-mx/stm32/rcc.h>

/*---------------------------------------------------------------------------*/
/** @brief USART Send a Data Word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@param[in] data unsigned 16 bit.
*/

void usart_send(uint32_t usart, uint16_t data)
{
/* Send data. */
USART_DR(usart) = (data & USART_DR_MASK);
}

/*---------------------------------------------------------------------------*/
/** @brief USART Read a Received Data Word.

If parity is enabled the MSB (bit 7 or 8 depending on the word length) is the
parity bit.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@returns unsigned 16 bit data word.
*/

uint16_t usart_recv(uint32_t usart)
{
/* Receive data. */
return USART_DR(usart) & USART_DR_MASK;
}

/*---------------------------------------------------------------------------*/
/** @brief USART Check if Transmit Data Buffer is empty
*
* Check if transmit data buffer is empty and is ready to accept
* the next data word.
*
* @param[in] usart unsigned 32 bit. USART block register address base @ref
* usart_reg_base
* @returns boolean: transmit data buffer is ready to accept the next data word
*/

bool usart_is_send_ready(uint32_t usart)
{
return ((USART_SR(usart) & USART_SR_TXE)); /* TXE set, means ready to write byte */
}


/*---------------------------------------------------------------------------*/
/** @brief USART Wait for Transmit Data Buffer Empty

Blocks until the transmit data buffer becomes empty and is ready to accept the
next data word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
*/

void usart_wait_send_ready(uint32_t usart)
{
/* Wait until the data has been transferred into the shift register. */
while ((USART_SR(usart) & USART_SR_TXE) == 0);
}

/*---------------------------------------------------------------------------*/
/** @brief USART check if Received Data Available

Check if data buffer holds a valid received data word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@returns boolean: data buffer holds a valid received data word.
*/

bool usart_is_recv_ready(uint32_t usart)
{
return ((USART_SR(usart) & USART_SR_RXNE)); /* RXNE set means there is data to be read */
}


/*---------------------------------------------------------------------------*/
/** @brief USART Wait for Received Data Available

Blocks until the receive data buffer holds a valid received data word.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
*/

void usart_wait_recv_ready(uint32_t usart)
{
/* Wait until the data is ready to be received. */
while ((USART_SR(usart) & USART_SR_RXNE) == 0);
}

/*---------------------------------------------------------------------------*/
/** @brief USART Read a Status Flag.

@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@param[in] flag Unsigned int32. Status register flag @ref usart_sr_flags.
@returns boolean: flag set.
*/

bool usart_get_flag(uint32_t usart, uint32_t flag)
{
return ((USART_SR(usart) & flag) != 0);
}

/*---------------------------------------------------------------------------*/
/** @brief USART Return Interrupt Source.
Expand Down