Linking Zephyr logging to UART powerdown

During the testing phase of my device I use the Zephyr (uart) logging module and the Zephyr shell module(CONFIG_SHELL_LOG_BACKEND=y). Shell is mostly disabled, and is enabled by placing a jumper. Because the device is battery powered the UART needs to be disabled when there is nothing to log. Now I'm trying to link the Zephyr log system to UART powerdown. When the log module receives a log message it should disable powerdown of the UART. When the log module has processed the last log message, and the UART is done sending it, the UART powerdown should be enabled.

My first attempt was to link LTE_LC_EVT_MODEM_SLEEP_EXIT and LTE_LC_EVT_MODEM_SLEEP_ENTER to UART powerdown with pm_device_action_run. This works but leads to missing logs, as the modem sleep is not synced to the log module.

Second attempt was to write my own log processing thread (CONFIG_LOG_PROCESS_THREAD=y). I copied the one in log_core.c and added my UART powerdown code. This worked, but only polling, which is not good for the low power requirement. The semaphore that is supposed to release when a new log message is received is only usable when the processing thread from log_core.c is used. When using a custom thread the required timer is never initialized(log_process_thread_timer).

Third attempt was to add a custom log backend(LOG_BACKEND_DEFINE). Idea was to disable powerdown on the first call to the process function, and re-enable upon receiving the LOG_BACKEND_EVT_PROCESS_THREAD_DONE event. This did not work because it seems that my custom backend seems to override the shell log backend, although Zephyr should support multiple backends.

Any Zephyr experts here that could help with this? Is there maybe another way to achieve this?

Parents Reply Children
Related