Skip to content

Commit

Permalink
imxrt_serial: use small lock in arch/arm/src/imxrt/imxrt_serial.c
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Nov 29, 2024
1 parent fcd8236 commit eb2b984
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions arch/arm/src/imxrt/imxrt_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,8 @@ static struct pm_callback_s g_serial_pmcb =
};
#endif

static spinlock_t g_imxrt_serial_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -1973,7 +1975,7 @@ static inline void imxrt_disableuartint(struct imxrt_uart_s *priv,
irqstate_t flags;
uint32_t regval;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);

/* Return the current Rx and Tx interrupt state */
Expand All @@ -1985,7 +1987,7 @@ static inline void imxrt_disableuartint(struct imxrt_uart_s *priv,

regval &= ~LPUART_ALL_INTS;
imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
#endif

Expand All @@ -2004,12 +2006,12 @@ static inline void imxrt_restoreuartint(struct imxrt_uart_s *priv,
* enabled/disabled.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
regval &= ~LPUART_ALL_INTS;
regval |= ie;
imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
#endif

Expand Down Expand Up @@ -2631,15 +2633,15 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)
* implement TCSADRAIN / TCSAFLUSH
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
imxrt_disableuartint(priv, &ie);
ret = dev->ops->setup(dev);

/* Restore the interrupt state */

imxrt_restoreuartint(priv, ie);
priv->ie = ie;
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
}
break;
Expand All @@ -2652,7 +2654,7 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)
irqstate_t flags;
struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);

if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
Expand Down Expand Up @@ -2686,7 +2688,7 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)

imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
break;
#endif
Expand All @@ -2700,7 +2702,7 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)
irqstate_t flags;
struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
ctrl = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
stat = imxrt_serialin(priv, IMXRT_LPUART_STAT_OFFSET);
regval = ctrl;
Expand Down Expand Up @@ -2736,7 +2738,7 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)
imxrt_serialout(priv, IMXRT_LPUART_STAT_OFFSET, stat);
imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, ctrl);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
break;
#endif
Expand Down Expand Up @@ -2790,7 +2792,7 @@ static void imxrt_rxint(struct uart_dev_s *dev, bool enable)

/* Enable interrupts for data available at Rx */

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
if (enable)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
Expand All @@ -2806,7 +2808,7 @@ static void imxrt_rxint(struct uart_dev_s *dev, bool enable)
regval &= ~LPUART_ALL_INTS;
regval |= priv->ie;
imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
#endif

Expand Down Expand Up @@ -3258,12 +3260,12 @@ static void imxrt_singlewire_send(struct uart_dev_s *dev, int ch)
uint32_t regval;
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
regval &= ~(LPUART_CTRL_RSRC);
regval |= (LPUART_CTRL_TXDIR);
imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);

imxrt_serialout(priv, IMXRT_LPUART_DATA_OFFSET, (uint32_t)ch);
}
Expand Down Expand Up @@ -3323,7 +3325,7 @@ static void imxrt_txint(struct uart_dev_s *dev, bool enable)

/* Enable interrupt for TX complete */

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
if (enable)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
Expand All @@ -3339,7 +3341,7 @@ static void imxrt_txint(struct uart_dev_s *dev, bool enable)
regval &= ~LPUART_ALL_INTS;
regval |= priv->ie;
imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
#endif

Expand All @@ -3360,7 +3362,7 @@ static void imxrt_singlewire_txint(struct uart_dev_s *dev, bool enable)

/* Enable interrupt for TX complete */

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_imxrt_serial_lock);
regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
if (enable)
{
Expand All @@ -3384,7 +3386,7 @@ static void imxrt_singlewire_txint(struct uart_dev_s *dev, bool enable)
regval |= priv->ie;

imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_imxrt_serial_lock, flags);
}
#endif

Expand Down

0 comments on commit eb2b984

Please sign in to comment.