serial: merge serial check signo to one place

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2021-12-20 17:44:08 +08:00 committed by Petro Karashchenko
parent 065553e59b
commit 5a0ab205ca
4 changed files with 96 additions and 145 deletions

View file

@ -1675,6 +1675,11 @@ static void uart_launch_worker(void *arg)
#endif
}
}
static void uart_launch(void)
{
work_queue(HPWORK, &g_serial_work, uart_launch_worker, NULL, 0);
}
#endif
/****************************************************************************
@ -1887,17 +1892,71 @@ void uart_reset_sem(FAR uart_dev_t *dev)
}
/****************************************************************************
* Name: uart_launch
* Name: uart_check_special
*
* Description:
* This function is called when user want launch a new program by
* using a special char.
* Check if the SIGINT or SIGTSTP character is in the contiguous Rx DMA
* buffer region. The first signal associated with the first such
* character is returned.
*
* If there multiple such characters in the buffer, only the signal
* associated with the first is returned (this a bug!)
*
* Returned Value:
* 0 if a signal-related character does not appear in the. Otherwise,
* SIGKILL or SIGTSTP may be returned to indicate the appropriate signal
* action.
*
****************************************************************************/
#ifdef CONFIG_TTY_LAUNCH
void uart_launch(void)
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
int uart_check_special(FAR uart_dev_t *dev, const char *buf, size_t size)
{
work_queue(HPWORK, &g_serial_work, uart_launch_worker, NULL, 0);
size_t i;
#ifdef CONFIG_SERIAL_TERMIOS
if ((dev->tc_lflag & ISIG) == 0)
#else
if (!dev->isconsole)
#endif
{
return 0;
}
for (i = 0; i < size; i++)
{
#ifdef CONFIG_TTY_FORCE_PANIC
if (buf[i] == CONFIG_TTY_FORCE_PANIC_CHAR)
{
PANIC();
return 0;
}
#endif
#ifdef CONFIG_TTY_LAUNCH
if (buf[i] == CONFIG_TTY_LAUNCH_CHAR)
{
uart_launch();
return 0;
}
#endif
#ifdef CONFIG_TTY_SIGINT
if (dev->pid > 0 && buf[i] == CONFIG_TTY_SIGINT_CHAR)
{
return SIGINT;
}
#endif
#ifdef CONFIG_TTY_SIGTSTP
if (dev->pid > 0 && buf[i] == CONFIG_TTY_SIGTSTP_CHAR)
{
return SIGTSTP;
}
#endif
}
return 0;
}
#endif

View file

@ -39,68 +39,7 @@
****************************************************************************/
/****************************************************************************
* Name: uart_check_signo
*
* Description:
* Check if the SIGINT or SIGTSTP character is in the contiguous Rx DMA
* buffer region. The first signal associated with the first such
* character is returned.
*
* If there multiple such characters in the buffer, only the signal
* associated with the first is returned (this a bug!)
*
* Returned Value:
* 0 if a signal-related character does not appear in the. Otherwise,
* SIGKILL or SIGTSTP may be returned to indicate the appropriate signal
* action.
*
****************************************************************************/
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
static int uart_check_signo(int pid, const char *buf, size_t size)
{
size_t i;
for (i = 0; i < size; i++)
{
#ifdef CONFIG_TTY_FORCE_PANIC
if (buf[i] == CONFIG_TTY_FORCE_PANIC_CHAR)
{
PANIC();
return 0;
}
#endif
#ifdef CONFIG_TTY_LAUNCH
if (buf[i] == CONFIG_TTY_LAUNCH_CHAR)
{
uart_launch();
return 0;
}
#endif
#ifdef CONFIG_TTY_SIGINT
if (pid > 0 && buf[i] == CONFIG_TTY_SIGINT_CHAR)
{
return SIGINT;
}
#endif
#ifdef CONFIG_TTY_SIGTSTP
if (pid > 0 && buf[i] == CONFIG_TTY_SIGTSTP_CHAR)
{
return SIGTSTP;
}
#endif
}
return 0;
}
#endif
/****************************************************************************
* Name: uart_recvchars_signo
* Name: uart_recvchars_check_special
*
* Description:
* Check if the SIGINT character is anywhere in the newly received DMA
@ -114,7 +53,7 @@ static int uart_check_signo(int pid, const char *buf, size_t size)
#if defined(CONFIG_SERIAL_RXDMA) && \
(defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH))
static int uart_recvchars_signo(FAR uart_dev_t *dev)
static int uart_recvchars_check_special(FAR uart_dev_t *dev)
{
FAR struct uart_dmaxfer_s *xfer = &dev->dmarx;
int signo;
@ -123,20 +62,20 @@ static int uart_recvchars_signo(FAR uart_dev_t *dev)
if (xfer->nbytes <= xfer->length)
{
return uart_check_signo(dev->pid, xfer->buffer, xfer->nbytes);
return uart_check_special(dev, xfer->buffer, xfer->nbytes);
}
else
{
/* REVISIT: Additional signals could be in the second region. */
signo = uart_check_signo(dev->pid, xfer->buffer, xfer->length);
signo = uart_check_special(dev, xfer->buffer, xfer->length);
if (signo != 0)
{
return signo;
}
return uart_check_signo(dev->pid, xfer->nbuffer,
xfer->nbytes - xfer->length);
return uart_check_special(dev, xfer->nbuffer,
xfer->nbytes - xfer->length);
}
}
#endif
@ -384,10 +323,7 @@ void uart_recvchars_done(FAR uart_dev_t *dev)
* buffer.
*/
if ((dev->tc_lflag & ISIG))
{
signo = uart_recvchars_signo(dev);
}
signo = uart_recvchars_check_special(dev);
#endif
/* Move head for nbytes. */
@ -405,7 +341,8 @@ void uart_recvchars_done(FAR uart_dev_t *dev)
uart_datareceived(dev);
}
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
/* Send the signal if necessary */
if (signo != 0)

View file

@ -124,7 +124,8 @@ void uart_recvchars(FAR uart_dev_t *dev)
#endif
unsigned int status;
int nexthead = rxbuf->head + 1;
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
int signo = 0;
#endif
uint16_t nbytes = 0;
@ -202,66 +203,9 @@ void uart_recvchars(FAR uart_dev_t *dev)
ch = uart_receive(dev, &status);
#ifdef CONFIG_TTY_SIGINT
/* Is this the special character that will generate the SIGINT
* signal?
*/
if (dev->pid >= 0 && (dev->tc_lflag & ISIG) &&
ch == CONFIG_TTY_SIGINT_CHAR)
{
/* Yes.. note that the kill is needed and do not put the character
* into the Rx buffer. It should not be read as normal data.
*/
signo = SIGINT;
}
else
#endif
#ifdef CONFIG_TTY_SIGTSTP
/* Is this the special character that will generate the SIGTSTP
* signal?
*/
if (dev->pid >= 0 && (dev->tc_lflag & ISIG) &&
ch == CONFIG_TTY_SIGTSTP_CHAR)
{
#ifdef CONFIG_TTY_SIGINT
/* Give precedence to SIGINT */
if (signo == 0)
#endif
{
/* Note that the kill is needed and do not put the character
* into the Rx buffer. It should not be read as normal data.
*/
signo = SIGTSTP;
}
}
else
#endif
#ifdef CONFIG_TTY_FORCE_PANIC
/* Is this the special character that will generate the SIGTSTP
* signal?
*/
if ((dev->tc_lflag & ISIG) && ch == CONFIG_TTY_FORCE_PANIC_CHAR)
{
PANIC();
}
else
#endif
#ifdef CONFIG_TTY_LAUNCH
/* Is this the special character that will generate the SIGTSTP
* signal?
*/
if ((dev->tc_lflag & ISIG) && ch == CONFIG_TTY_LAUNCH_CHAR)
{
uart_launch();
}
else
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
signo = uart_check_special(dev, &ch, 1);
#endif
/* If the RX buffer becomes full, then the serial data is discarded.
@ -299,7 +243,8 @@ void uart_recvchars(FAR uart_dev_t *dev)
uart_datareceived(dev);
}
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
/* Send the signal if necessary */
if (signo != 0)

View file

@ -496,16 +496,26 @@ void uart_recvchars_done(FAR uart_dev_t *dev);
void uart_reset_sem(FAR uart_dev_t *dev);
/****************************************************************************
* Name: uart_lanch
* Name: uart_check_special
*
* Description:
* This function is called when user want lanch a new program by
* using a special char.
* Check if the SIGINT or SIGTSTP character is in the contiguous Rx DMA
* buffer region. The first signal associated with the first such
* character is returned.
*
* If there multiple such characters in the buffer, only the signal
* associated with the first is returned (this a bug!)
*
* Returned Value:
* 0 if a signal-related character does not appear in the. Otherwise,
* SIGKILL or SIGTSTP may be returned to indicate the appropriate signal
* action.
*
****************************************************************************/
#ifdef CONFIG_TTY_LAUNCH
void uart_launch(void);
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC) || defined(CONFIG_TTY_LAUNCH)
int uart_check_special(FAR uart_dev_t *dev, const char *buf, size_t size);
#endif
#undef EXTERN