use small lock in following files:
arch/arm/src/tiva/common/tiva_hciuart.c arch/arm/src/tms570/tms570_lowputc.c arch/arm/src/xmc4/xmc4_serial.c arch/arm64/src/a64/a64_serial.c arch/mips/src/pic32mx/pic32mx_serial.c arch/mips/src/pic32mz/pic32mz_serial.c arch/risc-v/src/c906/c906_serial.c arch/risc-v/src/fe310/fe310_serial.c arch/risc-v/src/hpm6750/hpm6750_serial.c arch/risc-v/src/k210/k210_serial.c arch/sparc/src/bm3803/bm3803-serial.c arch/sparc/src/bm3823/bm3823-serial.c Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
4d7be17d40
commit
798695a4f7
12 changed files with 164 additions and 95 deletions
|
@ -103,6 +103,7 @@ struct hciuart_config_s
|
|||
{
|
||||
struct btuart_lowerhalf_s lower; /* Generic HCI-UART lower half */
|
||||
struct hciuart_state_s *state; /* Reference to variable state */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
uint8_t *rxbuffer; /* Rx buffer start */
|
||||
uint8_t *txbuffer; /* Tx buffer start */
|
||||
uint16_t rxbufsize; /* Size of the Rx buffer */
|
||||
|
@ -205,6 +206,7 @@ static const struct hciuart_config_s g_hciuart0_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart0_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart0_rxbuffer,
|
||||
.txbuffer = g_uart0_txbuffer,
|
||||
|
@ -255,6 +257,7 @@ static const struct hciuart_config_s g_hciuart1_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart1_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart1_rxbuffer,
|
||||
.txbuffer = g_uart1_txbuffer,
|
||||
|
@ -305,6 +308,7 @@ static const struct hciuart_config_s g_hciuart2_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart2_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart2_rxbuffer,
|
||||
.txbuffer = g_uart2_txbuffer,
|
||||
|
@ -355,6 +359,7 @@ static const struct hciuart_config_s g_hciuart3_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart3_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart3_rxbuffer,
|
||||
.txbuffer = g_uart3_txbuffer,
|
||||
|
@ -405,6 +410,7 @@ static const struct hciuart_config_s g_hciuart4_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart4_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart4_rxbuffer,
|
||||
.txbuffer = g_uart4_txbuffer,
|
||||
|
@ -455,6 +461,7 @@ static const struct hciuart_config_s g_hciuart5_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart5_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart5_rxbuffer,
|
||||
.txbuffer = g_uart5_txbuffer,
|
||||
|
@ -505,6 +512,7 @@ static const struct hciuart_config_s g_hciuart6_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart6_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart6_rxbuffer,
|
||||
.txbuffer = g_uart6_txbuffer,
|
||||
|
@ -555,6 +563,7 @@ static const struct hciuart_config_s g_hciuart7_config =
|
|||
},
|
||||
|
||||
.state = &g_hciuart7_state,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
.rxbuffer = g_uart7_rxbuffer,
|
||||
.txbuffer = g_uart7_txbuffer,
|
||||
|
@ -1272,7 +1281,7 @@ static void hciuart_rxattach(const struct btuart_lowerhalf_s *lower,
|
|||
|
||||
/* If the callback is NULL, then we are detaching */
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&config->lock);
|
||||
if (callback == NULL)
|
||||
{
|
||||
uint32_t intset;
|
||||
|
@ -1294,7 +1303,7 @@ static void hciuart_rxattach(const struct btuart_lowerhalf_s *lower,
|
|||
state->callback = callback;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&config->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -1322,7 +1331,7 @@ static void hciuart_rxenable(const struct btuart_lowerhalf_s *lower,
|
|||
uint32_t intset;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&config->lock);
|
||||
if (enable)
|
||||
{
|
||||
/* Receive an interrupt when their is anything in the Rx data
|
||||
|
@ -1338,7 +1347,7 @@ static void hciuart_rxenable(const struct btuart_lowerhalf_s *lower,
|
|||
hciuart_disableints(config, intset);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&config->lock, flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1524,9 +1533,9 @@ static ssize_t hciuart_write(const struct btuart_lowerhalf_s *lower,
|
|||
|
||||
/* Make sure that the Tx Interrupts are disabled. */
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&config->lock);
|
||||
hciuart_disableints(config, UART_IM_TXIM);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&config->lock, flags);
|
||||
|
||||
/* Loop until all of the user data have been moved to the Tx buffer */
|
||||
|
||||
|
@ -1621,9 +1630,9 @@ static ssize_t hciuart_write(const struct btuart_lowerhalf_s *lower,
|
|||
|
||||
if (state->txhead != state->txtail)
|
||||
{
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&config->lock);
|
||||
hciuart_enableints(config, UART_IM_TXIM);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&config->lock, flags);
|
||||
}
|
||||
|
||||
return ntotal;
|
||||
|
|
|
@ -82,6 +82,12 @@
|
|||
# undef HAVE_SERIAL_CONSOLE
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static spinlock_t g_tms570_lowputc_lock = SP_UNLOCKED;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
@ -187,30 +193,18 @@ void arm_lowputc(char ch)
|
|||
#ifdef HAVE_SERIAL_CONSOLE
|
||||
irqstate_t flags;
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
/* Wait for the transmitter to be available */
|
||||
/* Wait for the transmitter to be available */
|
||||
|
||||
while ((getreg32(TMS570_CONSOLE_BASE + TMS570_SCI_FLR_OFFSET) &
|
||||
SCI_FLR_TXRDY) == 0);
|
||||
flags = spin_lock_irqsave(&g_tms570_lowputc_lock);
|
||||
|
||||
/* Disable interrupts so that the test and the transmission are
|
||||
* atomic.
|
||||
*/
|
||||
while ((getreg32(TMS570_CONSOLE_BASE + TMS570_SCI_FLR_OFFSET) &
|
||||
SCI_FLR_TXRDY) == 0);
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
if ((getreg32(TMS570_CONSOLE_BASE + TMS570_SCI_FLR_OFFSET) &
|
||||
SCI_FLR_TXRDY) != 0)
|
||||
{
|
||||
/* Send the character */
|
||||
/* Send the character */
|
||||
|
||||
putreg32((uint32_t)ch, TMS570_CONSOLE_BASE + TMS570_SCI_TD_OFFSET);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
return;
|
||||
}
|
||||
putreg32((uint32_t)ch, TMS570_CONSOLE_BASE + TMS570_SCI_TD_OFFSET);
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
}
|
||||
spin_unlock_irqrestore(&g_tms570_lowputc_lock, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -238,6 +238,7 @@ struct xmc4_dev_s
|
|||
/* UART configuration */
|
||||
|
||||
struct uart_config_s config;
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -326,7 +327,8 @@ static struct xmc4_dev_s g_uart0priv =
|
|||
.startbufferptr = 0,
|
||||
.txbuffersize = CONFIG_XMC4_USIC0_CHAN0_TX_BUFFER_SIZE,
|
||||
.rxbuffersize = CONFIG_XMC4_USIC0_CHAN0_RX_BUFFER_SIZE,
|
||||
}
|
||||
},
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart0port =
|
||||
|
@ -365,7 +367,8 @@ static struct xmc4_dev_s g_uart1priv =
|
|||
+ CONFIG_XMC4_USIC0_CHAN0_RX_BUFFER_SIZE,
|
||||
.txbuffersize = CONFIG_XMC4_USIC0_CHAN1_TX_BUFFER_SIZE,
|
||||
.rxbuffersize = CONFIG_XMC4_USIC0_CHAN1_RX_BUFFER_SIZE,
|
||||
}
|
||||
},
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart1port =
|
||||
|
@ -403,7 +406,8 @@ static struct xmc4_dev_s g_uart2priv =
|
|||
.startbufferptr = 0,
|
||||
.txbuffersize = CONFIG_XMC4_USIC1_CHAN0_TX_BUFFER_SIZE,
|
||||
.rxbuffersize = CONFIG_XMC4_USIC1_CHAN0_RX_BUFFER_SIZE,
|
||||
}
|
||||
},
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart2port =
|
||||
|
@ -442,7 +446,8 @@ static struct xmc4_dev_s g_uart3priv =
|
|||
+ CONFIG_XMC4_USIC1_CHAN0_RX_BUFFER_SIZE,
|
||||
.txbuffersize = CONFIG_XMC4_USIC1_CHAN1_TX_BUFFER_SIZE,
|
||||
.rxbuffersize = CONFIG_XMC4_USIC1_CHAN1_RX_BUFFER_SIZE,
|
||||
}
|
||||
},
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart3port =
|
||||
|
@ -480,7 +485,8 @@ static struct xmc4_dev_s g_uart4priv =
|
|||
.startbufferptr = 0,
|
||||
.txbuffersize = CONFIG_XMC4_USIC2_CHAN0_TX_BUFFER_SIZE,
|
||||
.rxbuffersize = CONFIG_XMC4_USIC2_CHAN0_RX_BUFFER_SIZE,
|
||||
}
|
||||
},
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart4port =
|
||||
|
@ -519,7 +525,8 @@ static struct xmc4_dev_s g_uart5priv =
|
|||
+ CONFIG_XMC4_USIC2_CHAN0_RX_BUFFER_SIZE,
|
||||
.txbuffersize = CONFIG_XMC4_USIC2_CHAN1_TX_BUFFER_SIZE,
|
||||
.rxbuffersize = CONFIG_XMC4_USIC2_CHAN1_RX_BUFFER_SIZE,
|
||||
}
|
||||
},
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart5port =
|
||||
|
@ -567,22 +574,28 @@ static inline void xmc4_serialout(struct xmc4_dev_s *priv,
|
|||
* Name: xmc4_modifyreg
|
||||
****************************************************************************/
|
||||
|
||||
static inline void xmc4_modifyreg(struct xmc4_dev_s *priv, unsigned
|
||||
static inline void xmc4_modifyreg_nolock(struct xmc4_dev_s *priv, unsigned
|
||||
int offset, uint32_t setbits,
|
||||
uint32_t clrbits)
|
||||
{
|
||||
irqstate_t flags;
|
||||
uintptr_t regaddr = priv->uartbase + offset;
|
||||
uint32_t regval;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
|
||||
regval = getreg32(regaddr);
|
||||
regval &= ~clrbits;
|
||||
regval |= setbits;
|
||||
putreg32(regval, regaddr);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
static inline void xmc4_modifyreg(struct xmc4_dev_s *priv, unsigned
|
||||
int offset, uint32_t setbits,
|
||||
uint32_t clrbits)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
xmc4_modifyreg_nolock(priv, offset, setbits, clrbits);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -591,15 +604,11 @@ static inline void xmc4_modifyreg(struct xmc4_dev_s *priv, unsigned
|
|||
|
||||
static void xmc4_setuartint(struct xmc4_dev_s *priv)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
/* Re-enable/re-disable event interrupts corresponding to the state of
|
||||
* bits in priv->ccr.
|
||||
*/
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
xmc4_modifyreg(priv, XMC4_USIC_CCR_OFFSET, CCR_ALL_EVENTS, priv->ccr);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -614,10 +623,11 @@ static void xmc4_restoreuartint(struct xmc4_dev_s *priv, uint32_t ccr)
|
|||
* in the ccr argument.
|
||||
*/
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
priv->ccr = ccr;
|
||||
xmc4_setuartint(priv);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
xmc4_modifyreg_nolock(priv, XMC4_USIC_CCR_OFFSET, CCR_ALL_EVENTS,
|
||||
priv->ccr);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -626,16 +636,12 @@ static void xmc4_restoreuartint(struct xmc4_dev_s *priv, uint32_t ccr)
|
|||
|
||||
static void xmc4_disableuartint(struct xmc4_dev_s *priv, uint32_t *ccr)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
if (ccr)
|
||||
{
|
||||
*ccr = priv->ccr;
|
||||
}
|
||||
|
||||
xmc4_restoreuartint(priv, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -269,6 +269,12 @@ struct a64_uart_port_s
|
|||
bool is_console; /* 1 if this UART is console */
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
* Private Data
|
||||
***************************************************************************/
|
||||
|
||||
static spinlock_t g_a64_serial_lock = SP_UNLOCKED;
|
||||
|
||||
/***************************************************************************
|
||||
* Private Function Prototypes
|
||||
***************************************************************************/
|
||||
|
@ -967,7 +973,7 @@ static int a64_uart_init(uint32_t gating, uint32_t rst, pio_pinset_t tx,
|
|||
irqstate_t flags;
|
||||
int ret = OK;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&g_a64_serial_lock);
|
||||
|
||||
/* Enable clocking to UART */
|
||||
|
||||
|
@ -993,7 +999,7 @@ static int a64_uart_init(uint32_t gating, uint32_t rst, pio_pinset_t tx,
|
|||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&g_a64_serial_lock, flags);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ struct up_dev_s
|
|||
uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||
uint8_t bits; /* Number of bits (5, 6, 7 or 8) */
|
||||
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -152,7 +153,9 @@ struct up_dev_s
|
|||
static inline uint32_t up_serialin(struct up_dev_s *priv, int offset);
|
||||
static inline void up_serialout(struct up_dev_s *priv, int offset,
|
||||
uint32_t value);
|
||||
#ifdef HAVE_SERIAL_CONSOLE
|
||||
static void up_restoreuartint(struct uart_dev_s *dev, uint8_t im);
|
||||
#endif
|
||||
static void up_disableuartint(struct uart_dev_s *dev, uint8_t *im);
|
||||
|
||||
/* Serial driver methods */
|
||||
|
@ -220,6 +223,7 @@ static struct up_dev_s g_uart1priv =
|
|||
.parity = CONFIG_UART1_PARITY,
|
||||
.bits = CONFIG_UART1_BITS,
|
||||
.stopbits2 = CONFIG_UART1_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart1port =
|
||||
|
@ -254,6 +258,7 @@ static struct up_dev_s g_uart2priv =
|
|||
.parity = CONFIG_UART2_PARITY,
|
||||
.bits = CONFIG_UART2_BITS,
|
||||
.stopbits2 = CONFIG_UART2_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart2port =
|
||||
|
@ -300,19 +305,27 @@ static inline void up_serialout(struct up_dev_s *priv, int offset,
|
|||
* Name: up_restoreuartint
|
||||
****************************************************************************/
|
||||
|
||||
static void up_restoreuartint_nolock(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
}
|
||||
|
||||
#ifdef HAVE_SERIAL_CONSOLE
|
||||
static void up_restoreuartint(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Re-enable/re-disable interrupts corresponding to the state
|
||||
* of bits in im.
|
||||
*/
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
up_restoreuartint_nolock(dev, im);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_disableuartint
|
||||
|
@ -323,14 +336,14 @@ static void up_disableuartint(struct uart_dev_s *dev, uint8_t *im)
|
|||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
if (im)
|
||||
{
|
||||
*im = priv->im;
|
||||
}
|
||||
|
||||
up_restoreuartint(dev, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
up_restoreuartint_nolock(dev, 0);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -249,6 +249,7 @@ struct up_dev_s
|
|||
uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||
uint8_t bits; /* Number of bits (5, 6, 7 or 8) */
|
||||
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
bool brk; /* true: Line break in progress */
|
||||
|
@ -351,6 +352,7 @@ static struct up_dev_s g_uart1priv =
|
|||
.parity = CONFIG_UART1_PARITY,
|
||||
.bits = CONFIG_UART1_BITS,
|
||||
.stopbits2 = CONFIG_UART1_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
.brk = false,
|
||||
|
@ -393,6 +395,7 @@ static struct up_dev_s g_uart2priv =
|
|||
.parity = CONFIG_UART2_PARITY,
|
||||
.bits = CONFIG_UART2_BITS,
|
||||
.stopbits2 = CONFIG_UART2_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
.brk = false,
|
||||
|
@ -435,6 +438,7 @@ static struct up_dev_s g_uart3priv =
|
|||
.parity = CONFIG_UART3_PARITY,
|
||||
.bits = CONFIG_UART3_BITS,
|
||||
.stopbits2 = CONFIG_UART3_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
.brk = false,
|
||||
|
@ -477,6 +481,7 @@ static struct up_dev_s g_uart4priv =
|
|||
.parity = CONFIG_UART4_PARITY,
|
||||
.bits = CONFIG_UART4_BITS,
|
||||
.stopbits2 = CONFIG_UART4_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
.brk = false,
|
||||
|
@ -519,6 +524,7 @@ static struct up_dev_s g_uart5priv =
|
|||
.parity = CONFIG_UART5_PARITY,
|
||||
.bits = CONFIG_UART5_BITS,
|
||||
.stopbits2 = CONFIG_UART5_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
.brk = false,
|
||||
|
@ -561,6 +567,7 @@ static struct up_dev_s g_uart6priv =
|
|||
.parity = CONFIG_UART6_PARITY,
|
||||
.bits = CONFIG_UART6_BITS,
|
||||
.stopbits2 = CONFIG_UART6_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
|
||||
#ifdef CONFIG_PIC32MZ_UART_BREAKS
|
||||
.brk = false,
|
||||
|
@ -617,18 +624,24 @@ static inline void up_serialout(struct up_dev_s *priv, int offset,
|
|||
* Name: up_restoreuartint
|
||||
****************************************************************************/
|
||||
|
||||
static void up_restoreuartint_nolock(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
}
|
||||
|
||||
static void up_restoreuartint(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Re-enable/re-disable interrupts corresponding to the state of bits
|
||||
* in im
|
||||
*/
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
up_restoreuartint_nolock(dev, im);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -640,14 +653,14 @@ static void up_disableuartint(struct uart_dev_s *dev, uint8_t *im)
|
|||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
if (im)
|
||||
{
|
||||
*im = priv->im;
|
||||
}
|
||||
|
||||
up_restoreuartint(dev, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
up_restoreuartint_nolock(dev, 0);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -101,6 +101,7 @@ struct up_dev_s
|
|||
uint32_t baud; /* Configured baud */
|
||||
uint8_t irq; /* IRQ associated with this UART */
|
||||
uint8_t im; /* Interrupt mask state */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -167,6 +168,7 @@ static struct up_dev_s g_uart0priv =
|
|||
.uartbase = C906_UART0_BASE,
|
||||
.baud = CONFIG_UART0_BAUD,
|
||||
.irq = C906_IRQ_UART0,
|
||||
.lock = SP_UNLOCKED
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart0port =
|
||||
|
@ -217,12 +219,12 @@ static void up_serialout(struct up_dev_s *priv, int offset, uint32_t value)
|
|||
|
||||
static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
priv->im = im;
|
||||
up_serialout(priv, UART_IE_OFFSET, im);
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -231,7 +233,7 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
|||
|
||||
static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
/* Return the current interrupt mask value */
|
||||
|
||||
|
@ -244,7 +246,7 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
|||
|
||||
priv->im = 0;
|
||||
up_serialout(priv, UART_IE_OFFSET, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -101,6 +101,7 @@ struct up_dev_s
|
|||
uint32_t baud; /* Configured baud */
|
||||
uint8_t irq; /* IRQ associated with this UART */
|
||||
uint8_t im; /* Interrupt mask state */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -167,6 +168,7 @@ static struct up_dev_s g_uart0priv =
|
|||
.uartbase = FE310_UART0_BASE,
|
||||
.baud = CONFIG_UART0_BAUD,
|
||||
.irq = FE310_IRQ_UART0,
|
||||
.lock = SP_UNLOCKED
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart0port =
|
||||
|
@ -217,12 +219,12 @@ static void up_serialout(struct up_dev_s *priv, int offset, uint32_t value)
|
|||
|
||||
static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
priv->im = im;
|
||||
up_serialout(priv, UART_IE_OFFSET, im);
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -231,7 +233,7 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
|||
|
||||
static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
/* Return the current interrupt mask value */
|
||||
|
||||
|
@ -244,7 +246,7 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
|||
|
||||
priv->im = 0;
|
||||
up_serialout(priv, UART_IE_OFFSET, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -101,6 +101,7 @@ struct up_dev_s
|
|||
uint32_t uartbase; /* Base address of UART registers */
|
||||
uint32_t irq; /* IRQ associated with this UART */
|
||||
uint32_t im; /* Interrupt mask state */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
uart_config_t config; /* Uart config */
|
||||
};
|
||||
|
||||
|
@ -158,6 +159,7 @@ static struct up_dev_s g_uart0priv =
|
|||
.uartbase = HPM6750_UART0_BASE,
|
||||
.irq = HPM6750_IRQ_UART0,
|
||||
.im = 0,
|
||||
.lock = SP_UNLOCKED,
|
||||
.config =
|
||||
{
|
||||
.src_freq_in_hz = 24000000,
|
||||
|
@ -236,12 +238,12 @@ static void up_serialmodfiy(struct up_dev_s *priv, int offset,
|
|||
|
||||
static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
priv->im = im;
|
||||
up_serialout(priv, UART_IER_OFFSET, im);
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -250,7 +252,7 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
|||
|
||||
static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
/* Return the current interrupt mask value */
|
||||
|
||||
|
@ -263,7 +265,7 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
|||
|
||||
priv->im = 0;
|
||||
up_serialout(priv, UART_IER_OFFSET, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -101,6 +101,7 @@ struct up_dev_s
|
|||
uint32_t baud; /* Configured baud */
|
||||
uint8_t irq; /* IRQ associated with this UART */
|
||||
uint8_t im; /* Interrupt mask state */
|
||||
spinlock_t lock; /* Spinllock */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -167,6 +168,7 @@ static struct up_dev_s g_uart0priv =
|
|||
.uartbase = K210_UART0_BASE,
|
||||
.baud = CONFIG_UART0_BAUD,
|
||||
.irq = K210_IRQ_UART0,
|
||||
.lock = SP_UNLOCKED
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart0port =
|
||||
|
@ -217,12 +219,12 @@ static void up_serialout(struct up_dev_s *priv, int offset, uint32_t value)
|
|||
|
||||
static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
priv->im = im;
|
||||
up_serialout(priv, UART_IE_OFFSET, im);
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -231,7 +233,7 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t im)
|
|||
|
||||
static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
||||
{
|
||||
irqstate_t flags = spin_lock_irqsave(NULL);
|
||||
irqstate_t flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
/* Return the current interrupt mask value */
|
||||
|
||||
|
@ -244,7 +246,7 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *im)
|
|||
|
||||
priv->im = 0;
|
||||
up_serialout(priv, UART_IE_OFFSET, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -156,6 +156,7 @@ struct up_dev_s
|
|||
uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||
uint8_t bits; /* Number of bits (5, 6, 7 or 8) */
|
||||
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -235,6 +236,7 @@ static struct up_dev_s g_uart1priv =
|
|||
.parity = CONFIG_UART1_PARITY,
|
||||
.bits = CONFIG_UART1_BITS,
|
||||
.stopbits2 = CONFIG_UART1_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart1port =
|
||||
|
@ -265,6 +267,7 @@ static struct up_dev_s g_uart2priv =
|
|||
.parity = CONFIG_UART2_PARITY,
|
||||
.bits = CONFIG_UART2_BITS,
|
||||
.stopbits2 = CONFIG_UART2_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart2port =
|
||||
|
@ -295,6 +298,7 @@ static struct up_dev_s g_uart3priv =
|
|||
.parity = CONFIG_UART3_PARITY,
|
||||
.bits = CONFIG_UART3_BITS,
|
||||
.stopbits2 = CONFIG_UART3_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart3port =
|
||||
|
@ -354,18 +358,24 @@ static inline void up_setuartint(struct up_dev_s *priv)
|
|||
* Name: up_restoreuartint
|
||||
****************************************************************************/
|
||||
|
||||
static void up_restoreuartint_nolock(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
}
|
||||
|
||||
static void up_restoreuartint(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Re-enable/re-disable interrupts corresponding to the state of bits
|
||||
* in im
|
||||
*/
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
up_restoreuartint_nolock(dev, im);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -377,14 +387,14 @@ static void up_disableuartint(struct uart_dev_s *dev, uint8_t *im)
|
|||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
if (im)
|
||||
{
|
||||
*im = priv->im;
|
||||
}
|
||||
|
||||
up_restoreuartint(dev, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
up_restoreuartint_nolock(dev, 0);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -154,6 +154,7 @@ struct up_dev_s
|
|||
uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||
uint8_t bits; /* Number of bits (5, 6, 7 or 8) */
|
||||
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
|
||||
spinlock_t lock; /* Spinlock */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -232,6 +233,7 @@ static struct up_dev_s g_uart1priv =
|
|||
.parity = CONFIG_UART1_PARITY,
|
||||
.bits = CONFIG_UART1_BITS,
|
||||
.stopbits2 = CONFIG_UART1_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart1port =
|
||||
|
@ -262,6 +264,7 @@ static struct up_dev_s g_uart2priv =
|
|||
.parity = CONFIG_UART2_PARITY,
|
||||
.bits = CONFIG_UART2_BITS,
|
||||
.stopbits2 = CONFIG_UART2_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart2port =
|
||||
|
@ -292,6 +295,7 @@ static struct up_dev_s g_uart3priv =
|
|||
.parity = CONFIG_UART3_PARITY,
|
||||
.bits = CONFIG_UART3_BITS,
|
||||
.stopbits2 = CONFIG_UART3_2STOP,
|
||||
.lock = SP_UNLOCKED,
|
||||
};
|
||||
|
||||
static uart_dev_t g_uart3port =
|
||||
|
@ -355,18 +359,24 @@ static inline void up_setuartint(struct up_dev_s *priv)
|
|||
* Name: up_restoreuartint
|
||||
****************************************************************************/
|
||||
|
||||
static void up_restoreuartint_nolock(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
}
|
||||
|
||||
static void up_restoreuartint(struct uart_dev_s *dev, uint8_t im)
|
||||
{
|
||||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Re-enable/re-disable interrupts corresponding to the state of bits in
|
||||
* im
|
||||
*/
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
up_rxint(dev, RX_ENABLED(im));
|
||||
up_txint(dev, TX_ENABLED(im));
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
up_restoreuartint_nolock(dev, im);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -378,14 +388,14 @@ static void up_disableuartint(struct uart_dev_s *dev, uint8_t *im)
|
|||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
if (im)
|
||||
{
|
||||
*im = priv->im;
|
||||
}
|
||||
|
||||
up_restoreuartint(dev, 0);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
up_restoreuartint_nolock(dev, 0);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
Loading…
Reference in a new issue