emul: emul_sbs_gauge read/write returns ret code
To facilitate testing improper reads and writes on various registers, enable the emul_sbs_gauge reg_read/write handlers to return custom exit codes. Signed-off-by: Aaron Massey <aaronmassey@google.com>
This commit is contained in:
parent
df42cf366e
commit
1cff6099f7
|
@ -31,7 +31,7 @@ struct sbs_gauge_emul_cfg {
|
||||||
uint16_t addr;
|
uint16_t addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void reg_write(const struct emul *target, int reg, int val)
|
static int reg_write(const struct emul *target, int reg, int val)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(target);
|
ARG_UNUSED(target);
|
||||||
|
|
||||||
|
@ -39,13 +39,14 @@ static void reg_write(const struct emul *target, int reg, int val)
|
||||||
switch (reg) {
|
switch (reg) {
|
||||||
default:
|
default:
|
||||||
LOG_INF("Unknown write %x", reg);
|
LOG_INF("Unknown write %x", reg);
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reg_read(const struct emul *target, int reg)
|
static int reg_read(const struct emul *target, int reg, int *val)
|
||||||
{
|
{
|
||||||
int val;
|
|
||||||
|
|
||||||
ARG_UNUSED(target);
|
ARG_UNUSED(target);
|
||||||
|
|
||||||
switch (reg) {
|
switch (reg) {
|
||||||
|
@ -61,15 +62,15 @@ static int reg_read(const struct emul *target, int reg)
|
||||||
case SBS_GAUGE_CMD_CYCLE_COUNT:
|
case SBS_GAUGE_CMD_CYCLE_COUNT:
|
||||||
case SBS_GAUGE_CMD_DESIGN_VOLTAGE:
|
case SBS_GAUGE_CMD_DESIGN_VOLTAGE:
|
||||||
/* Arbitrary stub value. */
|
/* Arbitrary stub value. */
|
||||||
val = 1;
|
*val = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERR("Unknown register 0x%x read", reg);
|
LOG_ERR("Unknown register 0x%x read", reg);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
LOG_INF("read 0x%x = 0x%x", reg, val);
|
LOG_INF("read 0x%x = 0x%x", reg, *val);
|
||||||
|
|
||||||
return val;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg *msgs,
|
static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg *msgs,
|
||||||
|
@ -79,6 +80,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
||||||
struct sbs_gauge_emul_data *data;
|
struct sbs_gauge_emul_data *data;
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
int reg;
|
int reg;
|
||||||
|
int rc;
|
||||||
|
|
||||||
data = target->data;
|
data = target->data;
|
||||||
|
|
||||||
|
@ -102,7 +104,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
||||||
if (msgs->flags & I2C_MSG_READ) {
|
if (msgs->flags & I2C_MSG_READ) {
|
||||||
switch (msgs->len - 1) {
|
switch (msgs->len - 1) {
|
||||||
case 1:
|
case 1:
|
||||||
val = reg_read(target, reg);
|
rc = reg_read(target, reg, &val);
|
||||||
msgs->buf[0] = val;
|
msgs->buf[0] = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -113,7 +115,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
||||||
if (msgs->len != 1) {
|
if (msgs->len != 1) {
|
||||||
LOG_ERR("Unexpected msg1 length %d", msgs->len);
|
LOG_ERR("Unexpected msg1 length %d", msgs->len);
|
||||||
}
|
}
|
||||||
reg_write(target, reg, msgs->buf[0]);
|
rc = reg_write(target, reg, msgs->buf[0]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -121,7 +123,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct i2c_emul_api sbs_gauge_emul_api_i2c = {
|
static const struct i2c_emul_api sbs_gauge_emul_api_i2c = {
|
||||||
|
|
Loading…
Reference in a new issue