Skip to content

Commit

Permalink
bq769x2: Fix alert_mask configuration write-back
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
martinjaeger committed Nov 16, 2024
1 parent ad92b6a commit 8f6a949
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions drivers/bms_ic/bq769x2/bq769x2.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,24 +406,23 @@ static int bq769x2_configure_balancing(const struct device *dev, struct bms_ic_c

static int bq769x2_configure_alerts(const struct device *dev, struct bms_ic_conf *ic_conf)
{
uint32_t alert_mask = 0;
int err = 0;

union bq769x2_reg_alarm_sf_alert_mask_a sf_alert_mask_a = { 0 };
union bq769x2_reg_alarm_sf_alert_mask_b sf_alert_mask_b = { 0 };

ic_conf->alert_mask = 0;

sf_alert_mask_a.CUV = !!(ic_conf->alert_mask & BMS_ERR_CELL_UNDERVOLTAGE);
sf_alert_mask_a.COV = !!(ic_conf->alert_mask & BMS_ERR_CELL_OVERVOLTAGE);
sf_alert_mask_a.SCD = !!(ic_conf->alert_mask & BMS_ERR_SHORT_CIRCUIT);
sf_alert_mask_a.OCD1 = !!(ic_conf->alert_mask & BMS_ERR_DIS_OVERCURRENT);
sf_alert_mask_a.OCC = !!(ic_conf->alert_mask & BMS_ERR_CHG_OVERCURRENT);

ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_CELL_UNDERVOLTAGE);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_CELL_OVERVOLTAGE);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_SHORT_CIRCUIT);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_DIS_OVERCURRENT);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_CHG_OVERCURRENT);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_CELL_UNDERVOLTAGE);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_CELL_OVERVOLTAGE);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_SHORT_CIRCUIT);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_DIS_OVERCURRENT);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_CHG_OVERCURRENT);

err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_ALARM_SF_ALERT_MASK_A, sf_alert_mask_a.byte);

Expand All @@ -434,18 +433,20 @@ static int bq769x2_configure_alerts(const struct device *dev, struct bms_ic_conf
sf_alert_mask_b.OTINT = !!(ic_conf->alert_mask & BMS_ERR_INT_OVERTEMP);
sf_alert_mask_b.OTF = !!(ic_conf->alert_mask & BMS_ERR_FET_OVERTEMP);

ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_DIS_UNDERTEMP);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_DIS_OVERTEMP);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_CHG_UNDERTEMP);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_CHG_OVERTEMP);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_INT_OVERTEMP);
ic_conf->alert_mask |= (ic_conf->alert_mask & BMS_ERR_FET_OVERTEMP);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_DIS_UNDERTEMP);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_DIS_OVERTEMP);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_CHG_UNDERTEMP);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_CHG_OVERTEMP);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_INT_OVERTEMP);
alert_mask |= (ic_conf->alert_mask & BMS_ERR_FET_OVERTEMP);

err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_ALARM_SF_ALERT_MASK_B, sf_alert_mask_b.byte);

/* enable alarm (triggering of ALERT pin) for SF alert masks configured above */
err |= bq769x2_datamem_write_u2(dev, BQ769X2_SET_ALARM_DEFAULT_MASK, 0x1000);

ic_conf->alert_mask = alert_mask;

return err == 0 ? 0 : -EIO;
}

Expand Down

0 comments on commit 8f6a949

Please sign in to comment.