Skip to content
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

Flusing log uart during fault #6660

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion os/arch/arm/src/amebad/amebad_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void rtl8721d_uart_irq(uint32_t id, SerialIrq event)
}
if (event == TxIrq) {
priv->tx_level = TX_FIFO_MAX;
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
priv->tx_level = 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions os/arch/arm/src/amebalite/amebalite_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ static void rtl8720e_log_up_txint(struct uart_dev_s *dev, bool enable)
priv->txint_enable = enable;

if (enable)
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
//LOGUART_RxCmd(LOGUART_DEV, ENABLE);
//else
//LOGUART_RxCmd(LOGUART_DEV, DISABLE);
Expand Down Expand Up @@ -891,7 +891,7 @@ void rtl8720e_uart_irq(uint32_t id, SerialIrq event)
}
if (event == TxIrq) {
priv->tx_level = TX_FIFO_MAX;
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
priv->tx_level = 0;
}
}
Expand Down
45 changes: 43 additions & 2 deletions os/arch/arm/src/amebasmart/amebasmart_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ static uart_dev_t g_uart4port = {
};
#endif

#ifdef CONFIG_UART4_SERIAL_CONSOLE
static bool g_log_flush_running;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -573,7 +576,7 @@ static int rtl8730e_log_uart_irq(void *Data)

u32 txempty_en = LOGUART_GET_ETPFEI(IrqEn);
if ((txempty_en == 0x4 && (reg_lsr & LOGUART_BIT_TP4F_EMPTY)) || (reg_lsr & LOGUART_BIT_TP4F_NOT_FULL)) {
uart_xmitchars(&CONSOLE_DEV);
(void)uart_xmitchars(&CONSOLE_DEV);
}
return 0;
}
Expand Down Expand Up @@ -921,7 +924,7 @@ void rtl8730e_uart_irq(uint32_t id, SerialIrq event)
}
if (event == TxIrq) {
priv->tx_level = TX_FIFO_MAX;
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
priv->tx_level = 0;
}
}
Expand Down Expand Up @@ -1377,6 +1380,44 @@ int up_getc(void)
return ch;
}

/****************************************************************************
* Name: up_flush_console
*
* Description:
* This function is used to ensure that all characters in the UART buffer
* are transmitted.
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
void up_flush_console(void)
{
#ifdef CONFIG_UART4_SERIAL_CONSOLE
uint16_t nbyte;
irqstate_t flags = enter_critical_section();

/* To avoid duplicated calling up_flush_console(). */
if (g_log_flush_running) {
leave_critical_section(flags);
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have leave_critical_section here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Updated!

}
g_log_flush_running = true;

do {
while (!LOGUART_Ready());
nbyte = uart_xmitchars(&CONSOLE_DEV);
} while (nbyte);
Comment on lines +1410 to +1413
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work? Currently it looks like we still rely on uart interrupts to send data. But interrupts are disabled. Wont it be better to use lldbg path instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IRQ is calling uart_xmitchars()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant uart_xmitchars path is through drivers (will call the drivers send function and it also has some signalling logic to wakeup other threads), but at this point, we are no longer using the driver's path to print logs. Instead we use lldbg, so I asked the above question, why not use up_putc instead of driver send.


g_log_flush_running = false;

leave_critical_section(flags);
#endif
}

#else /* USE_SERIALDRIVER */
/****************************************************************************
* Name: up_putc
Expand Down
17 changes: 17 additions & 0 deletions os/arch/arm/src/armv7-a/arm_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,21 @@ static inline void print_assert_detail(const uint8_t *filename, int lineno, stru

}

/****************************************************************************
* Name: flush_console
****************************************************************************/

static inline void flush_console(void)
{
if (!IS_SECURE_STATE()) {
lldbg_noarg("\n===========================================================\n");
lldbg_noarg("Flush console log\n");
lldbg_noarg("===========================================================\n\n");
up_flush_console();
lldbg_noarg("\n");
}
}

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -612,6 +627,8 @@ void up_assert(const uint8_t *filename, int lineno)
/* Heap corruption check */
check_heap_corrupt(fault_tcb);

flush_console();

/* Closing log line */
lldbg_noarg("##########################################################################################################################################\n");

Expand Down
2 changes: 1 addition & 1 deletion os/arch/arm/src/imx6/imx_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ static int imx_interrupt(int irq, void *context, void *arg)
if (usr1 & UART_USR1_TRDY &&
(imx_serialin(priv, UART_UCR1_OFFSET) & UART_UCR1_TXEMPTYEN) != 0)
{
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
}

/* Keep track of how many times we do this in case there
Expand Down
2 changes: 1 addition & 1 deletion os/arch/arm/src/s5j/s5j_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static int up_interrupt(int irq, void *context, void *arg)
uint32_t uintp = uart_getreg32(dev->priv, S5J_UART_UINTP_OFFSET);

if (uintp & UART_UINTP_TXD) {
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
}

if (uintp & UART_UINTP_RXD) {
Expand Down
4 changes: 2 additions & 2 deletions os/arch/arm/src/stm32/stm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ static int up_interrupt_common(struct up_dev_s *priv)
if ((priv->sr & USART_SR_TXE) != 0 && (priv->ie & USART_CR1_TXEIE) != 0) {
/* Transmit data register empty ... process outgoing bytes */

uart_xmitchars(&priv->dev);
(void)uart_xmitchars(&priv->dev);
handled = true;
}
}
Expand Down Expand Up @@ -2260,7 +2260,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
* interrupts disabled (note this may recurse).
*/

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
#endif
} else {
/* Disable the TX interrupt */
Expand Down
4 changes: 2 additions & 2 deletions os/arch/arm/src/stm32l4/stm32l4_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ static int up_interrupt(int irq, FAR void *context, FAR void *arg)
{
/* Transmit data register empty ... process outgoing bytes */

uart_xmitchars(&priv->dev);
(void)uart_xmitchars(&priv->dev);
handled = true;
}
}
Expand Down Expand Up @@ -2581,7 +2581,7 @@ static void stm32l4serial_txint(FAR struct uart_dev_s *dev, bool enable)
* interrupts disabled (note this may recurse).
*/

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
#endif
}
else
Expand Down
4 changes: 2 additions & 2 deletions os/arch/arm/src/tiva/tiva_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ static int up_interrupt(int irq, void *context, FAR void *arg)
if ((mis & UART_MIS_TXMIS) != 0) {
/* Tx FIFO not full ... process outgoing bytes */

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
handled = true;
}
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
* the TX interrupt.
*/

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
#endif
} else {
/* Disable the TX interrupt */
Expand Down
4 changes: 2 additions & 2 deletions os/arch/xtensa/src/esp32/esp32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ static int esp32_interrupt(int cpuint, void *context, FAR void *arg)
if (nfifo < 0x7f) {
/* The TXFIFO is not full ... process outgoing bytes */

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
handled = true;
}
}
Expand Down Expand Up @@ -1062,7 +1062,7 @@ static void esp32_txint(struct uart_dev_s *dev, bool enable)
* interrupts disabled (note this may recurse).
*/

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
#endif
} else {
/* Disable the TX interrupt */
Expand Down
4 changes: 3 additions & 1 deletion os/drivers/serial/serialirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
*
************************************************************************************/

void uart_xmitchars(FAR uart_dev_t *dev)
uint16_t uart_xmitchars(FAR uart_dev_t *dev)
{
uint16_t nbytes = 0;

Expand Down Expand Up @@ -146,6 +146,8 @@ void uart_xmitchars(FAR uart_dev_t *dev)
#ifdef CONFIG_SMP
leave_critical_section(flags);
#endif

return nbytes;
}

/************************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions os/drivers/serial/uart_16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ static int u16550_interrupt(int irq, void *context, void *arg)
/* Handle outgoing, transmit bytes */

case UART_IIR_INTID_THRE: {
uart_xmitchars(dev);
(void)uart_xmitchars(dev);
break;
}

Expand Down Expand Up @@ -967,7 +967,7 @@ static void u16550_txint(struct uart_dev_s *dev, bool enable)
* interrupts disabled (note this may recurse).
*/

uart_xmitchars(dev);
(void)uart_xmitchars(dev);
} else {
priv->ier &= ~UART_IER_ETBEI;
u16550_serialout(priv, UART_IER_OFFSET, priv->ier);
Expand Down
10 changes: 10 additions & 0 deletions os/include/tinyara/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,16 @@ int up_getc(void);

void up_puts(FAR const char *str);

/****************************************************************************
* Name: up_flush_console
*
* Description:
* This function is used to ensure that all characters in the UART buffer
* are transmitted.
*
****************************************************************************/
void up_flush_console(void);

#ifdef CONFIG_WATCHDOG_FOR_IRQ
/****************************************************************************
* Name: up_wdog_init
Expand Down
2 changes: 1 addition & 1 deletion os/include/tinyara/serial/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev);
*
************************************************************************************/

void uart_xmitchars(FAR uart_dev_t *dev);
uint16_t uart_xmitchars(FAR uart_dev_t *dev);

/************************************************************************************
* Name: uart_receivechars
Expand Down