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:
Krzysztof Chruscinski 2019-02-11 15:25:53 +01:00 committed by Anas Nashif
commit 4fac1f4204

View file

@ -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);