| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #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的电流,认为在放电
- typedef struct{
- uint16_t discharging :1;
- uint16_t charging: 1;
- uint16_t pack_balancing:1;
- uint16_t pack_voltage; //电池包的总电压
- 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_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;
- #define debounce_reach(dt) ((dt)->count >= (dt)->max_count)
- #define debounce_reset(dt) ((dt)->count = 0)
- #define debounce_inc(dt) ((dt)->count++)
- void bms_state_init(void);
- bms_state_t * bms_state_get(void);
- #endif /* _BMS_STATE_H__ */
|