shell: Add support to log_panic in RTT backend
Shell RTT backend was using RTT call which was using lock (mutex). In case of panic, that lead to failure if panic occured in the interrupt context where mutex is not permitted. Implementation changed to use write without log in blocking mode. Additionally, added static assert to check if raw RTT log backend is not enabled on channel 0 which is used by shell RTT backend. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
02670ed2d7
commit
4fac1f4204
1 changed files with 15 additions and 1 deletions
|
@ -9,6 +9,10 @@
|
|||
#include <SEGGER_RTT.h>
|
||||
#include <logging/log.h>
|
||||
|
||||
BUILD_ASSERT_MSG(!(IS_ENABLED(CONFIG_LOG_BACKEND_RTT) &&
|
||||
COND_CODE_0(CONFIG_LOG_BACKEND_RTT_BUFFER, (1), (0))),
|
||||
"Conflicting log RTT backend enabled on the same channel");
|
||||
|
||||
SHELL_RTT_DEFINE(shell_transport_rtt);
|
||||
SHELL_DEFINE(shell_rtt, "rtt:~$ ", &shell_transport_rtt,
|
||||
CONFIG_SHELL_BACKEND_RTT_LOG_MESSAGE_QUEUE_SIZE,
|
||||
|
@ -17,6 +21,8 @@ SHELL_DEFINE(shell_rtt, "rtt:~$ ", &shell_transport_rtt,
|
|||
|
||||
LOG_MODULE_REGISTER(shell_rtt, CONFIG_SHELL_RTT_LOG_LEVEL);
|
||||
|
||||
static bool rtt_blocking;
|
||||
|
||||
static void timer_handler(struct k_timer *timer)
|
||||
{
|
||||
const struct shell_rtt *sh_rtt = k_timer_user_data_get(timer);
|
||||
|
@ -54,6 +60,7 @@ static int enable(const struct shell_transport *transport, bool blocking)
|
|||
struct shell_rtt *sh_rtt = (struct shell_rtt *)transport->ctx;
|
||||
|
||||
if (blocking) {
|
||||
rtt_blocking = true;
|
||||
k_timer_stop(&sh_rtt->timer);
|
||||
}
|
||||
|
||||
|
@ -66,7 +73,14 @@ static int write(const struct shell_transport *transport,
|
|||
struct shell_rtt *sh_rtt = (struct shell_rtt *)transport->ctx;
|
||||
const u8_t *data8 = (const u8_t *)data;
|
||||
|
||||
*cnt = SEGGER_RTT_Write(0, data8, length);
|
||||
if (rtt_blocking) {
|
||||
*cnt = SEGGER_RTT_WriteNoLock(0, data8, length);
|
||||
while (SEGGER_RTT_HasDataUp(0)) {
|
||||
/* empty */
|
||||
}
|
||||
} else {
|
||||
*cnt = SEGGER_RTT_Write(0, data8, length);
|
||||
}
|
||||
|
||||
sh_rtt->handler(SHELL_TRANSPORT_EVT_TX_RDY, sh_rtt->context);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue