Skip to content

Commit

Permalink
WIP: ISL compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjaeger committed Dec 2, 2023
1 parent eb4db0a commit 7ee308d
Show file tree
Hide file tree
Showing 20 changed files with 1,160 additions and 1,100 deletions.
28 changes: 14 additions & 14 deletions app/src/bms_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,74 +104,74 @@ __weak void bms_state_machine(struct bms_context *bms)
switch (bms->state) {
case BMS_STATE_OFF:
if (bms_dis_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, true);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, true);
bms->state = BMS_STATE_DIS;
LOG_INF("OFF -> DIS (error flags: 0x%08x)", bms->ic_data->error_flags);
}
else if (bms_chg_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, true);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, true);
bms->state = BMS_STATE_CHG;
LOG_INF("OFF -> CHG (error flags: 0x%08x)", bms->ic_data->error_flags);
}
break;
case BMS_STATE_CHG:
if (!bms_chg_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, false);
/* DIS switch may be on on because of ideal diode control */
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, false);
bms->state = BMS_STATE_OFF;
LOG_INF("CHG -> OFF (error flags: 0x%08x)", bms->ic_data->error_flags);
}
else if (bms_dis_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, true);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, true);
bms->state = BMS_STATE_NORMAL;
LOG_INF("CHG -> NORMAL (error flags: 0x%08x)", bms->ic_data->error_flags);
}
#ifndef CONFIG_BMS_IC_BQ769X2 /* bq769x2 has built-in ideal diode control */
else {
/* ideal diode control for discharge MOSFET (with hysteresis) */
if (bms->ic_data->current > 0.5F) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, true);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, true);
}
else if (bms->ic_data->current < 0.1F) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, false);
}
}
#endif
break;
case BMS_STATE_DIS:
if (!bms_dis_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, false);
/* CHG_FET may be on because of ideal diode control */
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, false);
bms->state = BMS_STATE_OFF;
LOG_INF("DIS -> OFF (error flags: 0x%08x)", bms->ic_data->error_flags);
}
else if (bms_chg_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, true);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, true);
bms->state = BMS_STATE_NORMAL;
LOG_INF("DIS -> NORMAL (error flags: 0x%08x)", bms->ic_data->error_flags);
}
#ifndef CONFIG_BMS_IC_BQ769X2 /* bq769x2 has built-in ideal diode control */
else {
/* ideal diode control for charge MOSFET (with hysteresis) */
if (bms->ic_data->current < -0.5F) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, true);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, true);
}
else if (bms->ic_data->current > -0.1F) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, false);
}
}
#endif
break;
case BMS_STATE_NORMAL:
if (!bms_dis_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_DIS, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_DIS, false);
bms->state = BMS_STATE_CHG;
LOG_INF("NORMAL -> CHG (error flags: 0x%08x)", bms->ic_data->error_flags);
}
else if (!bms_chg_allowed(bms)) {
bms_ic_enable_switch(bms_ic, BMS_SWITCH_CHG, false);
bms_ic_set_switches(bms_ic, BMS_SWITCH_CHG, false);
bms->state = BMS_STATE_DIS;
LOG_INF("NORMAL -> DIS (error flags: 0x%08x)", bms->ic_data->error_flags);
}
Expand Down
11 changes: 0 additions & 11 deletions app/src/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@

#include "helper.h"

#ifndef UNIT_TEST
#include <zephyr/kernel.h>
#endif

#include <time.h>

uint32_t uptime()
{
#ifndef UNIT_TEST
return k_uptime_get() / 1000;
#else
return time(NULL);
#endif
}

float interpolate(const float a[], const float b[], size_t size, float value_a)
{
if (a[0] < a[size - 1]) {
Expand Down
3 changes: 3 additions & 0 deletions boards/arm/bms_8s50_ic/bms_8s50_ic.dts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
uart-dbg = &usart1;
uart-uext = &usart2;
i2c-uext = &i2c1;
bms-ic = &isl94202;
};
};

Expand Down Expand Up @@ -132,6 +133,8 @@
reg = <0x28>; /* 0x50 >> 1 */
pull-up-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>;
board-max-current = <50>;
used-cell-channels = <0xFF>;
status = "okay";
};

eeprom0: eeprom@50 {
Expand Down
3 changes: 3 additions & 0 deletions boards/arm/bms_8s50_ic/bms_8s50_ic_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ CONFIG_EEPROM_AT24=y

CONFIG_CAN=y
CONFIG_ISOTP=y

CONFIG_BMS_IC=y
CONFIG_BMS_IC_MAX_THERMISTORS=1
Loading

0 comments on commit 7ee308d

Please sign in to comment.