console: uart_console: handle runtime PM
Allow the uart_console console_out implementation to integrate with 'Device Runtime Power Management'. Without using runtime PM, it is impossible for the application to manage the power state of a UART instance, given that any module in the application could theoretically LOG_* or printk at any point in time. This removes the need to manually call `pm_device_state_set` when the lowest power states must be reached, while still allowing console and printk messages to be output. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
e0fbd35fc0
commit
0561d0dd59
1 changed files with 15 additions and 0 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <zephyr/linker/sections.h>
|
||||
#include <zephyr/sys/atomic.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
#ifdef CONFIG_UART_CONSOLE_MCUMGR
|
||||
#include <zephyr/mgmt/mcumgr/transport/serial.h>
|
||||
#endif
|
||||
|
|
@ -86,11 +87,25 @@ static int console_out(int c)
|
|||
|
||||
#endif /* CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS */
|
||||
|
||||
if (pm_device_runtime_is_enabled(uart_console_dev)) {
|
||||
if (pm_device_runtime_get(uart_console_dev) < 0) {
|
||||
/* Enabling the UART instance has failed but this
|
||||
* function MUST return the byte output.
|
||||
*/
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
if ('\n' == c) {
|
||||
uart_poll_out(uart_console_dev, '\r');
|
||||
}
|
||||
uart_poll_out(uart_console_dev, c);
|
||||
|
||||
if (pm_device_runtime_is_enabled(uart_console_dev)) {
|
||||
/* As errors cannot be returned, ignore the return value */
|
||||
(void)pm_device_runtime_put(uart_console_dev);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue