logging: log_backend_rtt: Fix panic behavior when no host

RTT log backend was locking in panic if host absense was not yet
detected (early panic). It is fixed by adding detection of host
absense while pending on data being read by the host.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-01-30 08:26:24 +01:00 committed by Anas Nashif
commit eac2f7c763

View file

@ -138,17 +138,6 @@ static int line_out_drop_mode(void)
return 0;
}
static void on_write(void)
{
host_present = true;
if (panic_mode) {
while (SEGGER_RTT_HasDataUp(CONFIG_LOG_BACKEND_RTT_BUFFER)) {
/* Pend until data is fetched by the host. */
}
}
}
static void on_failed_write(int retry_cnt)
{
if (retry_cnt == 0) {
@ -160,6 +149,23 @@ static void on_failed_write(int retry_cnt)
}
}
static void on_write(int retry_cnt)
{
host_present = true;
if (panic_mode) {
/* In panic mode block on each write until host reads it. This
* way it is ensured that if system resets all messages are read
* by the host. While pending on data being read by the host we
* must also detect situation where host is disconnected.
*/
while (SEGGER_RTT_HasDataUp(CONFIG_LOG_BACKEND_RTT_BUFFER) &&
host_present) {
on_failed_write(retry_cnt--);
}
}
}
static int data_out_block_mode(u8_t *data, size_t length, void *ctx)
{
int ret;
@ -178,7 +184,7 @@ static int data_out_block_mode(u8_t *data, size_t length, void *ctx)
}
if (ret) {
on_write();
on_write(retry_cnt);
} else {
retry_cnt--;
on_failed_write(retry_cnt);