ams-slave-22/Core/Inc/BQ_Abstraction_Layer.h

71 lines
1.5 KiB
C
Raw Normal View History

/*
* BQ_Abstraction_Layer.h
*
* Created on: 29.01.2022
* Author: max
*/
#ifndef INC_BQ_ABSTRACTION_LAYER_H_
#define INC_BQ_ABSTRACTION_LAYER_H_
#include "common_defs.h"
#include "main.h"
#include "stm32f4xx_hal.h"
#define WAKEUP_PIN BQ_Wakeup_Pin
#define WAKEUP_PORT BQ_Wakeup_GPIO_Port
#define CELL_OV_THRESHOLD 55100 // 4.2V
#define CELL_UV_THRESHOLD 34100 // 2.6V
extern uint16_t cell_voltages[N_CELLS];
2022-06-12 14:44:37 +02:00
typedef enum { BQ_OFF, BQ_RDY, BQ_STDBY, BQ_INIT_PHASE, BQ_ERROR } BQ_Status;
extern BQ_Status bq_status;
#define BQ_ERROR_KIND_HAL (1 << 0)
#define BQ_ERROR_KIND_CRC (1 << 1)
#define BQ_ERROR_KIND_FAULT (1 << 2)
#define BQ_ERROR_LOC_MEASURE (1 << 0)
typedef struct {
uint8_t kind;
uint8_t hal_loc;
uint8_t crc_loc;
uint16_t fault_uv;
uint16_t fault_ov;
uint8_t fault_aux_uv;
uint8_t fault_aux_ov;
uint16_t fault_cmp_uv;
uint16_t fault_cmp_ov;
uint16_t fault_comm;
uint8_t fault_sys;
uint16_t fault_dev;
uint8_t fault_gpi;
} BQ_Error_Description;
extern BQ_Error_Description bq_error;
extern uint32_t lastmeasurementtime;
void afe_init(UART_HandleTypeDef* uarthandle);
void afe_shutdown();
void afe_measure();
void afe_selftest();
void afe_wakeup();
void afe_init_fault_thresholds();
void afe_clear_all_faults();
void afe_check_faults();
void afe_update_Checksum();
void afe_config_measurement_channels();
void afe_config_communication();
void afe_config_balancing();
void afe_balance_channels(uint16_t channelstobalance);
void afe_config_gpios();
void afe_activate_LED();
#endif /* INC_BQ_ABSTRACTION_LAYER_H_ */