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:
parent
4c3bcbafef
commit
eac2f7c763
1 changed files with 18 additions and 12 deletions
|
@ -138,17 +138,6 @@ static int line_out_drop_mode(void)
|
||||||
return 0;
|
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)
|
static void on_failed_write(int retry_cnt)
|
||||||
{
|
{
|
||||||
if (retry_cnt == 0) {
|
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)
|
static int data_out_block_mode(u8_t *data, size_t length, void *ctx)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -178,7 +184,7 @@ static int data_out_block_mode(u8_t *data, size_t length, void *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
on_write();
|
on_write(retry_cnt);
|
||||||
} else {
|
} else {
|
||||||
retry_cnt--;
|
retry_cnt--;
|
||||||
on_failed_write(retry_cnt);
|
on_failed_write(retry_cnt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue