Skip to content
Merged
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
35 changes: 24 additions & 11 deletions arch/arm/src/efm32/efm32_leserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct efm32_leuart_s
{
const struct efm32_config_s *config;
uint16_t ien; /* Interrupts enabled */
spinlock_t lock; /* Spinlock */
};

/****************************************************************************
Expand Down Expand Up @@ -212,6 +213,7 @@ static const struct efm32_config_s g_leuart0config =
static struct efm32_leuart_s g_leuart0priv =
{
.config = &g_leuart0config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_leuart0port =
Expand Down Expand Up @@ -247,6 +249,7 @@ static struct efm32_config_s g_leuart1config =
static struct efm32_leuart_s g_leuart1priv =
{
.config = &g_leuart1config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_leuart1port =
Expand Down Expand Up @@ -303,6 +306,17 @@ static inline void efm32_setuartint(struct efm32_leuart_s *priv)
* Name: efm32_restoreuartint
****************************************************************************/

static void efm32_restoreuartint_nolock(struct efm32_leuart_s *priv,
uint32_t ien)
{
/* Re-enable/re-disable interrupts corresponding to the state of
* bits in ien.
*/

priv->ien = ien;
efm32_setuartint(priv);
}

static void efm32_restoreuartint(struct efm32_leuart_s *priv, uint32_t ien)
{
irqstate_t flags;
Expand All @@ -311,10 +325,9 @@ static void efm32_restoreuartint(struct efm32_leuart_s *priv, uint32_t ien)
* bits in ien.
*/

flags = spin_lock_irqsave(NULL);
priv->ien = ien;
efm32_setuartint(priv);
spin_unlock_irqrestore(NULL, flags);
flags = spin_lock_irqsave(&priv->lock);
efm32_restoreuartint_nolock(priv, len);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -325,14 +338,14 @@ static void efm32_disableuartint(struct efm32_leuart_s *priv, uint32_t *ien)
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);
if (ien)
{
*ien = priv->ien;
}

efm32_restoreuartint(priv, 0);
spin_unlock_irqrestore(NULL, flags);
efm32_restoreuartint_nolock(priv, 0);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -607,7 +620,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
struct efm32_leuart_s *priv = (struct efm32_leuart_s *)dev->priv;
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
if (enable)
{
/* Receive an interrupt when there is anything in the Rx data register
Expand All @@ -625,7 +638,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
efm32_setuartint(priv);
}

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -673,7 +686,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
struct efm32_leuart_s *priv = (struct efm32_leuart_s *)dev->priv;
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
if (enable)
{
/* Enable the TX interrupt */
Expand All @@ -697,7 +710,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
efm32_setuartint(priv);
}

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
38 changes: 25 additions & 13 deletions arch/arm/src/efm32/efm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ struct efm32_usart_s
const struct efm32_config_s *config;
#endif
uint16_t ien; /* Interrupts enabled */
spinlock_t lock; /* Spinlock */
};

/****************************************************************************
Expand Down Expand Up @@ -303,7 +304,7 @@ static char g_uart1txbuffer[CONFIG_UART1_TXBUFSIZE];
/* This describes the state of the EFM32 USART0 port. */

#ifdef CONFIG_EFM32_USART0_ISUART
static const struct efm32_usart_s g_usart0config =
static const struct efm32_config_s g_usart0config =
{
.uartbase = EFM32_USART0_BASE,
.baud = CONFIG_USART0_BAUD,
Expand All @@ -317,6 +318,7 @@ static const struct efm32_usart_s g_usart0config =
static struct efm32_usart_s g_usart0priv =
{
.config = &g_usart0config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_usart0port =
Expand Down Expand Up @@ -353,6 +355,7 @@ static struct efm32_config_s g_usart1config =
static struct efm32_usart_s g_usart1priv =
{
.config = &g_usart1config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_usart1port =
Expand Down Expand Up @@ -389,6 +392,7 @@ static struct efm32_config_s g_usart2config =
static struct efm32_usart_s g_usart2priv =
{
.config = &g_usart2config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_usart2port =
Expand Down Expand Up @@ -425,6 +429,7 @@ static struct efm32_config_s g_uart0config =
static struct efm32_usart_s g_uart0priv =
{
.config = &g_uart0config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_uart0port =
Expand All @@ -447,7 +452,7 @@ static struct uart_dev_s g_uart0port =
/* This describes the state of the EFM32 UART1 port. */

#ifdef CONFIG_EFM32_UART1
static struct efm32_usart_s g_uart1config =
static struct efm32_config_s g_uart1config =
{
.uartbase = EFM32_UART1_BASE,
.baud = CONFIG_UART1_BAUD,
Expand All @@ -461,6 +466,7 @@ static struct efm32_usart_s g_uart1config =
static struct efm32_usart_s g_uart1priv =
{
.config = &g_uart1config,
.lock = SP_UNLOCKED
};

static struct uart_dev_s g_uart1port =
Expand Down Expand Up @@ -516,6 +522,13 @@ static inline void efm32_setuartint(struct efm32_usart_s *priv)
* Name: efm32_restoreuartint
****************************************************************************/

static void efm32_restoreuartint_nolock(struct efm32_usart_s *priv,
uint32_t ien)
{
priv->ien = ien;
efm32_setuartint(priv);
}

static void efm32_restoreuartint(struct efm32_usart_s *priv, uint32_t ien)
{
irqstate_t flags;
Expand All @@ -524,10 +537,9 @@ static void efm32_restoreuartint(struct efm32_usart_s *priv, uint32_t ien)
* ien
*/

flags = spin_lock_irqsave(NULL);
priv->ien = ien;
efm32_setuartint(priv);
spin_unlock_irqrestore(NULL, flags);
flags = spin_lock_irqsave(&priv->lock);
efm32_restoreuartint_nolock(priv, len);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -539,14 +551,14 @@ static void efm32_disableuartint(struct efm32_usart_s *priv, uint32_t *ien)
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);
if (ien)
{
*ien = priv->ien;
}

efm32_restoreuartint(priv, 0);
spin_unlock_irqrestore(NULL, flags);
efm32_restoreuartint_nolock(priv, 0);
spin_unlock_irqrestore(&priv->lock, flags);
}
#endif

Expand Down Expand Up @@ -966,7 +978,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
struct efm32_usart_s *priv = (struct efm32_usart_s *)dev->priv;
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
if (enable)
{
/* Receive an interrupt when their is anything in the Rx data register
Expand All @@ -984,7 +996,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
efm32_setuartint(priv);
}

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -1032,7 +1044,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
struct efm32_usart_s *priv = (struct efm32_usart_s *)dev->priv;
irqstate_t flags;

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
if (enable)
{
/* Enable the TX interrupt */
Expand All @@ -1056,7 +1068,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
efm32_setuartint(priv);
}

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
17 changes: 13 additions & 4 deletions arch/arm/src/gd32f4/gd32f4xx_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct up_dev_s
uint8_t stop_2bits; /* True: Configure with 2 stop bits instead of 1 */
uint32_t tx_gpio; /* USART TX GPIO pin configuration */
uint32_t rx_gpio; /* USART RX GPIO pin configuration */
spinlock_t lock; /* Spinlock */

# ifdef CONFIG_SERIAL_IFLOWCONTROL
uint32_t rts_gpio; /* UART RTS GPIO pin configuration */
Expand Down Expand Up @@ -437,6 +438,7 @@ static struct up_dev_s g_usart0priv =

.tx_gpio = GPIO_USART0_TX,
.rx_gpio = GPIO_USART0_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART0_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART0_RTS,
Expand Down Expand Up @@ -509,6 +511,7 @@ static struct up_dev_s g_usart1priv =

.tx_gpio = GPIO_USART1_TX,
.rx_gpio = GPIO_USART1_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART1_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART1_RTS,
Expand Down Expand Up @@ -581,6 +584,7 @@ static struct up_dev_s g_usart2priv =

.tx_gpio = GPIO_USART2_TX,
.rx_gpio = GPIO_USART2_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART2_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART2_RTS,
Expand Down Expand Up @@ -653,6 +657,7 @@ static struct up_dev_s g_usart5priv =

.tx_gpio = GPIO_USART5_TX,
.rx_gpio = GPIO_USART5_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART5_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART5_RTS,
Expand Down Expand Up @@ -725,6 +730,7 @@ static struct up_dev_s g_uart3priv =

.tx_gpio = GPIO_UART3_TX,
.rx_gpio = GPIO_UART3_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART3_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_UART3_RTS,
Expand Down Expand Up @@ -797,6 +803,7 @@ static struct up_dev_s g_uart4priv =

.tx_gpio = GPIO_UART4_TX,
.rx_gpio = GPIO_UART4_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART4_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_UART4_RTS,
Expand Down Expand Up @@ -869,6 +876,7 @@ static struct up_dev_s g_uart6priv =

.tx_gpio = GPIO_UART6_TX,
.rx_gpio = GPIO_UART6_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART6_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_UART6_RTS,
Expand Down Expand Up @@ -941,6 +949,7 @@ static struct up_dev_s g_uart7priv =

.tx_gpio = GPIO_UART7_TX,
.rx_gpio = GPIO_UART7_RX,
.lock = SP_UNLOCKED,
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART7_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_UART7_RTS,
Expand Down Expand Up @@ -1127,7 +1136,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint32_t *ie)
irqstate_t flags;
uint32_t ctl_ie;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

if (ie)
{
Expand Down Expand Up @@ -1161,7 +1170,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint32_t *ie)
ctl_ie = (USART_CFG_CTL_MASK << USART_CFG_SHIFT);
up_setusartint(priv, ctl_ie);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -1172,11 +1181,11 @@ static void up_restoreusartint(struct up_dev_s *priv, uint32_t ie)
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

up_setusartint(priv, ie);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
Loading