Module Notes
Main
Keeps a static BmsStorage
prv_setup_can(): initializes CAN
fault_bps(): directly calls relay_process_event() with an OPEN event, takes in a fault bitset and adds it to the current fault bitset, logs over CAN. This will be defined in a fault_bps.h header, included in any module that fault checks, but will be implemented in main.c for access to BmsStorage.fault_bitset.
main(): event loop, processes can
Can_handler
prv_ack_handler(): acks center console during startup
prv_..._tx(): transmits data about …
prv_periodic_tx(): periodically calls all ...tx() functions
can_handler_init(): starts the periodic tx
Bps_heartbeat
prv_handle_ack(): checks the ack from heartbeats are ok
prv_heartbeat_tx(): periodically transmits BPS heartbeat
bps_heartbeat_init(): starts the periodic heartbeat
Fan_control
Needs afe storage for temps
prv_calc_speed(): offset linear fan curve calculation based on aggregate temps
prv_fan_stuck_cb(): broadcasts if the fans get stuck
prv_periodic_set_speed(): periodically calcs speed and sets it with the fan controller driver
fan_control_init(): starts periodic set speed
Relay_control_fsm
State machine is:
Open
Close ground
Close hv
Closed
Must check relay state after each close and open, BPS fault if relays didn’t follow instructions
Wait 100 ms to check relay state, wait 200 ms between closing gnd and closing hv
prv_open(): opens gnd then hv, can do them both nearly the same time without checking state in between, but check state afterwards
relay_control_init(): inits pins
relay_process_event(): opens relays upon relay open event, advances state machine after checks
Note: relay sense pins are hidden behind a GPIO expander and will have to be queried through I2C
Killswitch
Killswitch is basically just a debounced GPIO pin
prv_killswitch_cb(): BPS fault
killswitch_init(): inits pins. Hidden behind gpio expander, will have to go through that driver.
Cell_sense
prv_fault_check(): check fresh data for faults
prv_periodic…(): periodically reads AFEs for data
cell_sense_init(): begins periodic checks, inits SPI
Passive_balance
prv_periodic_balance(): periodically checks which cells are highest and raises event for AFEs to balance those cells
passive_balance_init(): inits periodic balance
Current_sense
prv_fault_check(): checks new data for faults
prv_periodic_read_current(): read current at least 100 times a second
Every 20 readings, update the data in CurrentStorage.
current_sense_init(): inits periodic read
Note: eventually this module will also be responsible for transmitting data to the RPI for state of charge calculations.
Data type notes
RelayStorage
Holds relay states
BpsHbStorage
Holds the number of failed acks
Holds the expected ack devices, initialized by bps_heartbeat_init()
CurrentStorage
Holds the last 20 current readings, all updated at the same time periodically. Stored as int16_t because current can be negative.
AfeStorage
Holds the voltages of 6 modules x3 AFEs
Holds the temps of 30 thermistors (exact number TBD) x3 AFEs
FanStorage
Holds the speeds of 4 fans
Holds the fan status so we can update driver if one is stuck
BmsStorage
Holds one of each of the above. The respective module only has access to their own storage.
Also holds fault_bitset, which is the master fault bitset.
Also holds DebounceStorage, required for killswitch.
Drivers
ADT7470
fan controller, exposes init() and update_speed(). The ‘stuck’ interrupt is in a GPIO pin, can be registered by the module.
ADS1259
Current sense
exposes init(), and read()
MCP23008
May need addition of interrupt configuration