| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #ifndef _BMS_STATE_H__
- #define _BMS_STATE_H__
- #include "bsp/shark_bsp.h"
- #include "libs/shark_libs.h"
- #ifndef BIT
- #define BIT(x) ((uint32_t)((uint32_t)0x01U<<(x)))
- #endif
- #ifndef BITS
- #define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
- #endif
- #define BATT_USED_BY_NONE 0
- #define BATT_USED_BY_MOTOR_BIKE 1
- #define BATT_USED_BY_CHARGER_DOCKER 2
- #define HATT_USED_BY_CHARGER_BOX 3
- #define MIN_START_CHARGER_CURRENT 100 //ma, 如果有正向超过 MIN_START_CHARGER_CURRENT的电流,认为在充电
- #define MIN_START_LOADING_CURRENT 2 //ma, 如果有反向小于 MIN_START_LOADING_CURRENT的电流,认为在放电
- #define MAX_DIFF_BETWEEN_MIN_MAX_CELL 150 //0.15v ,压差超过这个值,开始balance
- #define MIN_DIFF_BETWEEN_MIN_MAX_CELL 050 //0.05v, 牙差低于这个数据,停止balance
- #define CELL_FUSION_VOLTAGE 3500 //LFP电池在3.5v的时候,开始发散,需要判断是否要balance
- typedef struct{
- uint16_t discharging :1;
- uint16_t charging: 1;
- uint16_t pack_balancing:1;
- uint16_t pack_voltage; //电池包的总电压
- uint16_t cell_max_vol;
- uint16_t cell_min_vol;
- uint8_t cell_index_of_max_vol;
- int used_by;//where this battery is used for: on motor, on charger docker, on charger box, NONE
- int user_request;
- }bms_state_t;
- #define USER_REQUEST_PENDING BIT(31) //是否有用户请求
- #define USER_REQUEST_CHARGER BIT(0)
- #define USER_REQUEST_DISCHARGER BIT(1)
- #define USER_REQUEST_SMALLCURRENT BIT(2)
- typedef struct {
- shark_timer_t _timer;
- int count;
- int max_count;
- int interval;
- }debounce_timer_t;
- typedef struct {
- int count;
- int max_count;
- }debounce_t;
- /* 充电充满判断OK前,需要经过balance 的判断再决定是否告知充电完成,判断balance前soc会一直在99%
- * balance 的时候,不会停止充电,soc一直99%,推出balance后,soc直接到100%
- */
- typedef enum {
- charger_full_fsm_start = 0,
- charger_full_fsm_check_balance,
- charger_full_fsm_end_balance,
- charger_full_fsm_full
- }charger_full_fsm_t;
- #define debounce_reach_max(dt) (dt.count >= dt.max_count)
- #define debounce_reach_zero(dt) (dt.count == 0)
- #define debounce_reset(dt) {dt.count = 0;}
- #define debounce_inc(dt) {if (dt.count < dt.max_count) dt.count++;}
- #define debounce_dec(dt) {if (dt.count > 0) dt.count--;}
- void bms_state_init(void);
- bms_state_t * bms_state_get(void);
- #endif /* _BMS_STATE_H__ */
|