Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions platform/dev-imxrt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ perf = "deny"
suspicious = "deny"
style = "deny"

[features]
dual-fuel-gauge = ["platform-common/dual-fuel-gauge"]

[dependencies]
cortex-m = { version = "0.7.7", features = [
"inline-asm",
Expand Down
3 changes: 3 additions & 0 deletions platform/dev-mcxa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ perf = "deny"
suspicious = "deny"
style = "deny"

[features]
dual-fuel-gauge = ["platform-common/dual-fuel-gauge"]

[dependencies]
cortex-m = { version = "0.7.7", features = [
"inline-asm",
Expand Down
3 changes: 3 additions & 0 deletions platform/dev-mec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ perf = "deny"
suspicious = "deny"
style = "deny"

[features]
dual-fuel-gauge = ["platform-common/dual-fuel-gauge"]

[dependencies]
cortex-m = { version = "0.7.7", features = [
"inline-asm",
Expand Down
3 changes: 3 additions & 0 deletions platform/dev-npcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ perf = "deny"
suspicious = "deny"
style = "deny"

[features]
dual-fuel-gauge = ["platform-common/dual-fuel-gauge"]

[dependencies]
cortex-m = { version = "0.7.7", features = [
"critical-section-single-core",
Expand Down
1 change: 1 addition & 0 deletions platform/dev-qemu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ style = "deny"
ignored = ["riscv-rt"]

[features]
dual-fuel-gauge = ["platform-common/dual-fuel-gauge"]
time-alarm-wake = ["dep:time-alarm-service-interface"]
time-alarm-power-input = ["time-alarm-wake"]

Expand Down
1 change: 1 addition & 0 deletions platform/platform-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ defmt = "0.3.6"
ignored = ["defmt"]

[features]
dual-fuel-gauge = ["mock"]
mock = [
"battery-service/mock",
"thermal-service/mock",
Expand Down
23 changes: 14 additions & 9 deletions platform/platform-common/src/mock/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use static_cell::StaticCell;

/// The fuel gauge, behind a mutex so the service and the driving task can share it.
type FuelGauge = Mutex<GlobalRawMutex, MockFuelGauge>;
/// Two registered fuel gauges: battery `0` is a 3S pack, battery `1` a 2S pack.
type Reg = bs::ArrayRegistration<'static, FuelGauge, 2>;
const FUEL_GAUGE_COUNT: usize = if cfg!(feature = "dual-fuel-gauge") { 2 } else { 1 };
type Reg = bs::ArrayRegistration<'static, FuelGauge, FUEL_GAUGE_COUNT>;
pub type BatteryService = bs::Service<'static, Reg>;

pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService {
Expand All @@ -18,14 +18,19 @@ pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService {
static FUEL_GAUGE_0: StaticCell<FuelGauge> = StaticCell::new();
let fuel_gauge_0: &'static FuelGauge = FUEL_GAUGE_0.init(Mutex::new(MockFuelGauge::new()));

static FUEL_GAUGE_1: StaticCell<FuelGauge> = StaticCell::new();
let fuel_gauge_1: &'static FuelGauge = FUEL_GAUGE_1.init(Mutex::new(MockFuelGauge::new_2s()));
let fuel_gauges = [
fuel_gauge_0,
#[cfg(feature = "dual-fuel-gauge")]
{
static FUEL_GAUGE_1: StaticCell<FuelGauge> = StaticCell::new();
let fuel_gauge_1: &'static FuelGauge = FUEL_GAUGE_1.init(Mutex::new(MockFuelGauge::new_2s()));
fuel_gauge_1
},
];

let service = bs::Service::new(bs::ArrayRegistration {
fuel_gauges: [fuel_gauge_0, fuel_gauge_1],
});
let service = bs::Service::new(bs::ArrayRegistration { fuel_gauges });

for (battery_id, fuel_gauge) in [fuel_gauge_0, fuel_gauge_1].into_iter().enumerate() {
for (battery_id, fuel_gauge) in fuel_gauges.into_iter().enumerate() {
bs::mock::init_state_machine(fuel_gauge)
.await
.expect("Failed to initialize battery state machine");
Expand All @@ -36,7 +41,7 @@ pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService {
service
}

#[embassy_executor::task(pool_size = 2)]
#[embassy_executor::task(pool_size = FUEL_GAUGE_COUNT)]
pub async fn update_data_task(battery_id: u8, fuel_gauge: &'static FuelGauge) -> ! {
let mut failures: u32 = 0;
let mut count: usize = 0;
Expand Down
Loading