From cd2b5c999ed50843c2235af1b6d11b078fdd1679 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 3 Dec 2019 14:52:51 +0100 Subject: i2c: Introduce PANIC state When processing an event for an I2C device, if an unrecoverable error occurs, the I2C HAL internal state of the I2C device is set to the PANIC state. The possible type of unrecoverable errors are: unexpected event, invalid event, call to framework returned in error. Driver errors are not considered as unrecoverable. It is not possible to exit the PANIC state. Once in PANIC state, all requests returns with the FWK_E_PANIC error code. Change-Id: I8d1a6b62cc1ab413e8a43e6641604133bb5dfbd8 Signed-off-by: Ronald Cron --- module/i2c/src/mod_i2c.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'module/i2c') diff --git a/module/i2c/src/mod_i2c.c b/module/i2c/src/mod_i2c.c index b310c008..27b30b55 100644 --- a/module/i2c/src/mod_i2c.c +++ b/module/i2c/src/mod_i2c.c @@ -20,6 +20,7 @@ enum mod_i2c_dev_state { MOD_I2C_DEV_TX, MOD_I2C_DEV_RX, MOD_I2C_DEV_TX_RX, + MOD_I2C_DEV_PANIC, }; struct mod_i2c_dev_ctx { @@ -67,8 +68,10 @@ static int create_i2c_request(fwk_id_t dev_id, return FWK_E_PARAM; /* Check whether an I2C request is already on-going */ - if (ctx->state != MOD_I2C_DEV_IDLE) - return FWK_E_BUSY; + if (ctx->state != MOD_I2C_DEV_IDLE) { + return (ctx->state == MOD_I2C_DEV_PANIC) ? + FWK_E_PANIC : FWK_E_BUSY; + } /* Create the request */ event = (struct fwk_event) { @@ -353,6 +356,13 @@ static int mod_i2c_process_event(const struct fwk_event *event, is_request = fwk_id_get_event_idx(event->id) < MOD_I2C_EVENT_IDX_COUNT; if (is_request) { + if (ctx->state == MOD_I2C_DEV_PANIC) { + event_param = (struct mod_i2c_event_param *)resp_event->params; + event_param->status = FWK_E_PANIC; + + return FWK_SUCCESS; + } + request = (struct mod_i2c_request *)event->params; ctx->request = *request; @@ -407,6 +417,9 @@ static int mod_i2c_process_event(const struct fwk_event *event, break; } + if (status != FWK_SUCCESS) + ctx->state = MOD_I2C_DEV_PANIC; + return status; } -- cgit v1.2.3