Add UART irq input hook to uart_console_isr()
Adds an input hook to be used by the interrupt handler uart_console_isr(). This hook permits the console input to detect a character escape sequence that can be used to override the console's default input behavior. This input hook can be set using the following API: void uart_irq_input_hook_set(struct device *dev, int (*hook)(struct device *, uint8_t)); The hook returns 1 if the handler should stop processing the character, and 0 if it should not stop. Change-Id: I95e7da75e07fb6caaca2d45e80bfc4334a43c0ac Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
parent
b2147178b4
commit
b1c1020732
|
@ -136,6 +136,18 @@ void uart_console_isr(void *unused)
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
int rx;
|
int rx;
|
||||||
|
|
||||||
|
rx = read_uart(UART_CONSOLE_DEV, &byte, 1);
|
||||||
|
if (rx < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uart_irq_input_hook(UART_CONSOLE_DEV, byte) != 0) {
|
||||||
|
/*
|
||||||
|
* The input hook indicates that no further processing
|
||||||
|
* should be done by this handler.
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
cmd = nano_isr_fifo_get(avail_queue);
|
cmd = nano_isr_fifo_get(avail_queue);
|
||||||
|
@ -143,12 +155,6 @@ void uart_console_isr(void *unused)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rx = read_uart(UART_CONSOLE_DEV, &byte, 1);
|
|
||||||
if (rx < 0) {
|
|
||||||
nano_isr_fifo_put(avail_queue, cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Echo back to console */
|
/* Echo back to console */
|
||||||
uart_poll_out(UART_CONSOLE_DEV, byte);
|
uart_poll_out(UART_CONSOLE_DEV, byte);
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ struct uart_driver_api {
|
||||||
int (*irq_is_pending)(struct device *dev);
|
int (*irq_is_pending)(struct device *dev);
|
||||||
int (*irq_update)(struct device *dev);
|
int (*irq_update)(struct device *dev);
|
||||||
unsigned int (*irq_get)(struct device *dev);
|
unsigned int (*irq_get)(struct device *dev);
|
||||||
|
int (*irq_input_hook)(struct device *dev, uint8_t byte);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -416,6 +417,51 @@ static inline unsigned int uart_irq_get(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Invoke the UART input hook routine if installed
|
||||||
|
*
|
||||||
|
* The input hook is a custom handler invoked by the ISR on each received
|
||||||
|
* character. It allows the detection of a character escape sequence that may
|
||||||
|
* be used to override the behavior of the ISR handler.
|
||||||
|
*
|
||||||
|
* @param dev UART device struct (of type struct uart_device_config_t)
|
||||||
|
* @param byte Byte to process
|
||||||
|
*
|
||||||
|
* @return 1 if character processing must stop, 0 or if it is to continue
|
||||||
|
*/
|
||||||
|
static inline int uart_irq_input_hook(struct device *dev, uint8_t byte)
|
||||||
|
{
|
||||||
|
struct uart_driver_api *api;
|
||||||
|
|
||||||
|
api = (struct uart_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
|
if ((api != NULL) && (api->irq_input_hook != NULL)) {
|
||||||
|
return api->irq_input_hook(dev, byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the UART input hook routine
|
||||||
|
*
|
||||||
|
* @param dev UART device struct (of type struct uart_device_config_t)
|
||||||
|
* @param hook Routine to use as UART input hook
|
||||||
|
*
|
||||||
|
* @return N/A
|
||||||
|
*/
|
||||||
|
static inline void uart_irq_input_hook_set(struct device *dev,
|
||||||
|
int (*hook)(struct device *, uint8_t))
|
||||||
|
{
|
||||||
|
struct uart_driver_api *api;
|
||||||
|
|
||||||
|
api = (struct uart_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
|
if (api != NULL) {
|
||||||
|
api->irq_input_hook = hook;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in a new issue