npcx: shi: Avoid 'unexpected state' console spam

If SHI finds itself in an unexpected state, we may try to print an error
message for each IBF / IBHF interrupt, which is excessively spammy and
may even lead to EC watchdog. Avoid console spam by not duplicating IBF
/ IBHF / IBEOR error prints, if our state doesn't change.

BUG=chrome-os-partner:54502
BRANCH=None
TEST=Manual on gru. Verify only one print is seen when SHI fails due to
missed initialization.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I331c64c24fa3a68d7c17e052240691076d3532cc
Reviewed-on: https://chromium-review.googlesource.com/356239
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
This commit is contained in:
Shawn Nematbakhsh
2016-06-27 12:42:57 -07:00
committed by chrome-bot
parent b9e9f7b863
commit 369fbaf052

View File

@@ -490,7 +490,7 @@ static void shi_bad_received_data(void)
shi_fill_out_status(EC_SPI_RX_BAD_DATA);
state = SHI_STATE_BAD_RECEIVED_DATA;
CPRINTS("BAD-");
CPRINTF("BAD-");
CPRINTF("in_msg=[");
for (i = 0; i < shi_params.sz_received; i++)
CPRINTF("%02x ", in_msg[i]);
@@ -503,6 +503,21 @@ static void shi_bad_received_data(void)
task_enable_irq(NPCX_IRQ_SHI);
}
/*
* Avoid spamming the console with prints every IBF / IBHF interrupt, if
* we find ourselves in an unexpected state.
*/
static int last_error_state = -1;
static void log_unexpected_state(char *isr_name)
{
#if !(DEBUG_SHI)
if (state != last_error_state)
CPRINTS("Unexpected state %d in %s ISR", state, isr_name);
#endif
last_error_state = state;
}
/* This routine handles all interrupts of this module */
void shi_int_handler(void)
{
@@ -542,7 +557,7 @@ void shi_int_handler(void)
/* Error state for checking*/
if (state != SHI_STATE_SENDING)
CPRINTS("Unexpected state %d in IBEOR ISR\n", state);
log_unexpected_state("IBEOR");
/* reset SHI and prepare to next transaction again */
shi_reset_prepare();
@@ -587,7 +602,7 @@ void shi_int_handler(void)
#endif
else
/* Unexpected status */
CPRINTS("Unexpected state %d in IBHF ISR\n", state);
log_unexpected_state("IBHF");
}
/*
@@ -622,7 +637,7 @@ void shi_int_handler(void)
return;
else
/* Unexpected status */
CPRINTS("Unexpected state %d in IBF ISR\n", state);
log_unexpected_state("IBF");
}
}
/*
@@ -657,7 +672,7 @@ void shi_cs_event(enum gpio_signal signal)
/* Chip select is low = asserted */
if (state != SHI_STATE_READY_TO_RECV) {
/* State machine should be reset in EVSTAT_EOR ISR */
CPRINTS("Unexpected state %d in CS ISR\n", state);
CPRINTS("Unexpected state %d in CS ISR", state);
return;
}
@@ -706,6 +721,7 @@ static void shi_reset_prepare(void)
/* Ready to receive */
state = SHI_STATE_READY_TO_RECV;
last_error_state = -1;
DEBUG_CPRINTF("RDY-");
}