File dump from Analog
This commit is contained in:
141
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830CmdList.h
Normal file
141
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830CmdList.h
Normal file
@ -0,0 +1,141 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2020 - Analog Devices Inc. All Rights Reserved.
|
||||
This software is proprietary & confidential to Analog Devices, Inc.
|
||||
and its licensor.
|
||||
******************************************************************************
|
||||
* @file: adBms6830CmdList.h
|
||||
* @brief: Command header file
|
||||
* @version: $Revision$
|
||||
* @date: $Date$
|
||||
* Developed by: ADIBMS Software team, Bangalore, India
|
||||
*****************************************************************************/
|
||||
/*! @addtogroup BMS_DRIVER
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/*! @addtogroup BMS_COMMAND BMS COMMAND
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ADBMSCOMMAND_H
|
||||
#define __ADBMSCOMMAND_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/* configuration registers commands */
|
||||
uint8_t WRCFGA[2] = { 0x00, 0x01 };
|
||||
uint8_t WRCFGB[2] = { 0x00, 0x24 };
|
||||
uint8_t RDCFGA[2] = { 0x00, 0x02 };
|
||||
uint8_t RDCFGB[2] = { 0x00, 0x26 };
|
||||
|
||||
/* Read cell voltage result registers commands */
|
||||
uint8_t RDCVA[2] = { 0x00, 0x04 };
|
||||
uint8_t RDCVB[2] = { 0x00, 0x06 };
|
||||
uint8_t RDCVC[2] = { 0x00, 0x08 };
|
||||
uint8_t RDCVD[2] = { 0x00, 0x0A };
|
||||
uint8_t RDCVE[2] = { 0x00, 0x09 };
|
||||
uint8_t RDCVF[2] = { 0x00, 0x0B };
|
||||
uint8_t RDCVALL[2] = { 0x00, 0x0C };
|
||||
|
||||
/* Read average cell voltage result registers commands commands */
|
||||
uint8_t RDACA[2] = { 0x00, 0x44 };
|
||||
uint8_t RDACB[2] = { 0x00, 0x46 };
|
||||
uint8_t RDACC[2] = { 0x00, 0x48 };
|
||||
uint8_t RDACD[2] = { 0x00, 0x4A };
|
||||
uint8_t RDACE[2] = { 0x00, 0x49 };
|
||||
uint8_t RDACF[2] = { 0x00, 0x4B };
|
||||
uint8_t RDACALL[2] = { 0x00, 0x4C };
|
||||
|
||||
/* Read s voltage result registers commands */
|
||||
uint8_t RDSVA[2] = { 0x00, 0x03 };
|
||||
uint8_t RDSVB[2] = { 0x00, 0x05 };
|
||||
uint8_t RDSVC[2] = { 0x00, 0x07 };
|
||||
uint8_t RDSVD[2] = { 0x00, 0x0D };
|
||||
uint8_t RDSVE[2] = { 0x00, 0x0E };
|
||||
uint8_t RDSVF[2] = { 0x00, 0x0F };
|
||||
uint8_t RDSALL[2] = { 0x00, 0x10 };
|
||||
|
||||
/* Read c and s results */
|
||||
uint8_t RDCSALL[2] = { 0x00, 0x11 };
|
||||
uint8_t RDACSALL[2] = { 0x00, 0x51 };
|
||||
|
||||
/* Read all AUX and all Status Registers */
|
||||
uint8_t RDASALL[2] = { 0x00, 0x35 };
|
||||
|
||||
/* Read filtered cell voltage result registers*/
|
||||
uint8_t RDFCA[2] = { 0x00, 0x12 };
|
||||
uint8_t RDFCB[2] = { 0x00, 0x13 };
|
||||
uint8_t RDFCC[2] = { 0x00, 0x14 };
|
||||
uint8_t RDFCD[2] = { 0x00, 0x15 };
|
||||
uint8_t RDFCE[2] = { 0x00, 0x16 };
|
||||
uint8_t RDFCF[2] = { 0x00, 0x17 };
|
||||
uint8_t RDFCALL[2] = { 0x00, 0x18 };
|
||||
|
||||
/* Read aux results */
|
||||
uint8_t RDAUXA[2] = { 0x00, 0x19 };
|
||||
uint8_t RDAUXB[2] = { 0x00, 0x1A };
|
||||
uint8_t RDAUXC[2] = { 0x00, 0x1B };
|
||||
uint8_t RDAUXD[2] = { 0x00, 0x1F };
|
||||
|
||||
/* Read redundant aux results */
|
||||
uint8_t RDRAXA[2] = { 0x00, 0x1C };
|
||||
uint8_t RDRAXB[2] = { 0x00, 0x1D };
|
||||
uint8_t RDRAXC[2] = { 0x00, 0x1E };
|
||||
uint8_t RDRAXD[2] = { 0x00, 0x25 };
|
||||
|
||||
/* Read status registers */
|
||||
uint8_t RDSTATA[2] = { 0x00, 0x30 };
|
||||
uint8_t RDSTATB[2] = { 0x00, 0x31 };
|
||||
uint8_t RDSTATC[2] = { 0x00, 0x32 };
|
||||
uint8_t RDSTATCERR[2] = { 0x00, 0x72 }; /* ERR */
|
||||
uint8_t RDSTATD[2] = { 0x00, 0x33 };
|
||||
uint8_t RDSTATE[2] = { 0x00, 0x34 };
|
||||
|
||||
/* Pwm registers commands */
|
||||
uint8_t WRPWM1[2] = { 0x00, 0x20 };
|
||||
uint8_t RDPWM1[2] = { 0x00, 0x22 };
|
||||
|
||||
uint8_t WRPWM2[2] = { 0x00, 0x21 };
|
||||
uint8_t RDPWM2[2] = { 0x00, 0x23 };
|
||||
|
||||
/* Clear commands */
|
||||
uint8_t CLRCELL[2] = { 0x07, 0x11 };
|
||||
uint8_t CLRAUX [2] = { 0x07, 0x12 };
|
||||
uint8_t CLRSPIN[2] = { 0x07, 0x16 };
|
||||
uint8_t CLRFLAG[2] = { 0x07, 0x17 };
|
||||
uint8_t CLRFC[2] = { 0x07, 0x14 };
|
||||
uint8_t CLOVUV[2] = { 0x07, 0x15 };
|
||||
|
||||
/* Poll adc command */
|
||||
uint8_t PLADC[2] = { 0x07, 0x18 };
|
||||
uint8_t PLAUT[2] = { 0x07, 0x19 };
|
||||
uint8_t PLCADC[2] = { 0x07, 0x1C };
|
||||
uint8_t PLSADC[2] = { 0x07, 0x1D };
|
||||
uint8_t PLAUX1[2] = { 0x07, 0x1E };
|
||||
uint8_t PLAUX2[2] = { 0x07, 0x1F };
|
||||
|
||||
/* Diagn command */
|
||||
uint8_t DIAGN[2] = {0x07 , 0x15};
|
||||
|
||||
/* GPIOs Comm commands */
|
||||
uint8_t WRCOMM[2] = { 0x07, 0x21 };
|
||||
uint8_t RDCOMM[2] = { 0x07, 0x22 };
|
||||
uint8_t STCOMM[13] = { 0x07, 0x23, 0xB9, 0xE4 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00};
|
||||
|
||||
/* Mute and Unmute commands */
|
||||
uint8_t MUTE[2] = { 0x00, 0x28 };
|
||||
uint8_t UNMUTE[2] = { 0x00, 0x29 };
|
||||
|
||||
uint8_t RSTCC[2] = { 0x00, 0x2E };
|
||||
uint8_t SNAP[2] = { 0x00, 0x2D };
|
||||
uint8_t UNSNAP[2] = { 0x00, 0x2F };
|
||||
uint8_t SRST[2] = { 0x00, 0x27 };
|
||||
|
||||
/* Read SID command */
|
||||
uint8_t RDSID[2] = { 0x00, 0x2C };
|
||||
|
||||
#endif /* __BMS_COMMAND_H */
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
620
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830Data.h
Normal file
620
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830Data.h
Normal file
@ -0,0 +1,620 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2020 - Analog Devices Inc. All Rights Reserved.
|
||||
This software is proprietary & confidential to Analog Devices, Inc.
|
||||
and its licensor.
|
||||
******************************************************************************
|
||||
* @file: adBms6830Data.h
|
||||
* @brief: Generic bms data structure header file
|
||||
* @version: $Revision$
|
||||
* @date: $Date$
|
||||
* Developed by: ADIBMS Software team, Bangalore, India
|
||||
*****************************************************************************/
|
||||
|
||||
/*! @addtogroup BMS DRIVER
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/*! @addtogroup BMS_DATA BMS DATA
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ADBMSDATA_H
|
||||
#define __ADBMSDATA_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define CELL 16 /* Bms ic number of cell */
|
||||
#define AUX 12 /* Bms ic number of Aux */
|
||||
#define RAUX 10 /* Bms ic number of RAux */
|
||||
#define PWMA 12 /* Bms ic number of PWMA */
|
||||
#define PWMB 4 /* Bms ic number of PWMB */
|
||||
#define COMM 3 /* GPIO communication comm reg */
|
||||
#define RSID 6 /* Bms ic number of SID byte */
|
||||
#define TX_DATA 6 /* Bms tx data byte */
|
||||
#define RX_DATA 8 /* Bms rx data byte */
|
||||
#define RDCVALL_SIZE 34 /* RDCVALL data byte size */
|
||||
#define RDSALL_SIZE 34 /* RDSALL data byte size */
|
||||
#define RDACALL_SIZE 34 /* RDACALL data byte size */
|
||||
#define RDFCALL_SIZE 34 /* RDFCALL data byte size */
|
||||
#define RDCSALL_SIZE 66 /* RDCSALL data byte size */
|
||||
#define RDASALL_SIZE 70 /* RDASALL data byte size */
|
||||
#define RDACSALL_SIZE 66 /* RDACSALL data byte size */
|
||||
|
||||
/* For ADBMS6830 config register structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t refon :1;
|
||||
uint8_t cth :3;
|
||||
uint8_t flag_d :8;
|
||||
uint8_t soakon :1;
|
||||
uint8_t owrng :1;
|
||||
uint8_t owa :3;
|
||||
uint16_t gpo :10;
|
||||
uint8_t snap :1;
|
||||
uint8_t mute_st :1;
|
||||
uint8_t comm_bk :1;
|
||||
uint8_t fc :3;
|
||||
}cfa_;
|
||||
|
||||
/* For ADBMS6830 config register structure */
|
||||
typedef struct
|
||||
{
|
||||
uint16_t vuv :16;
|
||||
uint16_t vov :16;
|
||||
uint8_t dtmen :1;
|
||||
uint8_t dtrng :1;
|
||||
uint8_t dcto :6;
|
||||
uint16_t dcc :16;
|
||||
}cfb_;
|
||||
|
||||
/* Cell Voltage Data structure */
|
||||
typedef struct
|
||||
{
|
||||
int16_t c_codes[CELL]; /* Cell Voltage Codes */
|
||||
} cv_;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16_t ac_codes[CELL]; /* Average Cell Voltage Codes */
|
||||
} acv_;
|
||||
|
||||
/* S Voltage Data structure */
|
||||
typedef struct
|
||||
{
|
||||
int16_t sc_codes[CELL]; /* S Voltage Codes */
|
||||
} scv_;
|
||||
|
||||
/* Filtered Cell Voltage Data structure */
|
||||
typedef struct
|
||||
{
|
||||
int16_t fc_codes[CELL]; /* filtered Cell Voltage Codes */
|
||||
} fcv_;
|
||||
|
||||
/* Aux Voltage Data Structure*/
|
||||
typedef struct
|
||||
{
|
||||
int16_t a_codes[AUX]; /* Aux Voltage Codes */
|
||||
} ax_;
|
||||
|
||||
/* Redundant Aux Voltage Data Structure*/
|
||||
typedef struct
|
||||
{
|
||||
int16_t ra_codes[RAUX]; /* Aux Voltage Codes */
|
||||
} rax_;
|
||||
|
||||
/* Status A register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t vref2;
|
||||
uint16_t itmp;
|
||||
uint16_t vref3;
|
||||
} sta_;
|
||||
|
||||
/* Status B register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t vd;
|
||||
uint16_t va;
|
||||
uint16_t vr4k;
|
||||
} stb_;
|
||||
|
||||
/* Status C register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t cs_flt;
|
||||
uint8_t va_ov :1;
|
||||
uint8_t va_uv :1;
|
||||
uint8_t vd_ov :1;
|
||||
uint8_t vd_uv :1;
|
||||
uint8_t otp1_ed :1;
|
||||
uint8_t otp1_med:1;
|
||||
uint8_t otp2_ed :1;
|
||||
uint8_t otp2_med:1;
|
||||
uint8_t vde :1;
|
||||
uint8_t vdel :1;
|
||||
uint8_t comp :1;
|
||||
uint8_t spiflt :1;
|
||||
uint8_t sleep :1;
|
||||
uint8_t thsd :1;
|
||||
uint8_t tmodchk :1;
|
||||
uint8_t oscchk :1;
|
||||
} stc_;
|
||||
|
||||
/* ClrFlag register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t cl_csflt;
|
||||
uint8_t cl_smed :1;
|
||||
uint8_t cl_sed :1;
|
||||
uint8_t cl_cmed :1;
|
||||
uint8_t cl_ced :1;
|
||||
uint8_t cl_vduv :1;
|
||||
uint8_t cl_vdov :1;
|
||||
uint8_t cl_vauv :1;
|
||||
uint8_t cl_vaov :1;
|
||||
uint8_t cl_oscchk :1;
|
||||
uint8_t cl_tmode :1;
|
||||
uint8_t cl_thsd :1;
|
||||
uint8_t cl_sleep :1;
|
||||
uint8_t cl_spiflt :1;
|
||||
uint8_t cl_vdel :1;
|
||||
uint8_t cl_vde :1;
|
||||
} clrflag_;
|
||||
|
||||
/* Status D register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t c_ov[CELL];
|
||||
uint8_t c_uv[CELL];
|
||||
uint8_t ct :6;
|
||||
uint8_t cts :2;
|
||||
uint8_t oc_cntr;
|
||||
} std_;
|
||||
|
||||
/* Status E register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t gpi :10;
|
||||
uint8_t rev :4;
|
||||
} ste_;
|
||||
|
||||
/* Pwm register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pwma[PWMA];
|
||||
} pwma_;
|
||||
|
||||
/*PWMB Register Structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pwmb[PWMB];
|
||||
} pwmb_;
|
||||
|
||||
/* COMM register Data structure*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t fcomm[COMM];
|
||||
uint8_t icomm[COMM];
|
||||
uint8_t data[COMM];
|
||||
} com_;
|
||||
|
||||
/*SID Register Structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sid[RSID];
|
||||
} sid_;
|
||||
|
||||
/* Transmit byte and recived byte data structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t tx_data[TX_DATA];
|
||||
uint8_t rx_data[RX_DATA];
|
||||
} ic_register_;
|
||||
|
||||
/* Command counter and pec error data Structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd_cntr;
|
||||
uint8_t cfgr_pec;
|
||||
uint8_t cell_pec;
|
||||
uint8_t acell_pec;
|
||||
uint8_t scell_pec;
|
||||
uint8_t fcell_pec;
|
||||
uint8_t aux_pec;
|
||||
uint8_t raux_pec;
|
||||
uint8_t stat_pec;
|
||||
uint8_t comm_pec;
|
||||
uint8_t pwm_pec;
|
||||
uint8_t sid_pec;
|
||||
} cmdcnt_pec_;
|
||||
|
||||
/* Diagnostic test result data structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t osc_mismatch;
|
||||
uint8_t supply_error;
|
||||
uint8_t supply_ovuv;
|
||||
uint8_t thsd;
|
||||
uint8_t fuse_ed;
|
||||
uint8_t fuse_med;
|
||||
uint8_t tmodchk;
|
||||
uint8_t cell_ow[CELL];
|
||||
uint8_t cellred_ow[CELL];
|
||||
uint8_t aux_ow[(AUX-2)];
|
||||
} diag_test_;
|
||||
|
||||
/* Aux open wire data structure */
|
||||
typedef struct
|
||||
{
|
||||
int cell_ow_even[CELL];
|
||||
int cell_ow_odd[CELL];
|
||||
} cell_ow_;
|
||||
|
||||
/* Aux open wire data structure */
|
||||
typedef struct
|
||||
{
|
||||
int aux_pup_up[(AUX-2)];
|
||||
int aux_pup_down[(AUX-2)];
|
||||
} aux_ow_;
|
||||
|
||||
/* BMS ic main structure */
|
||||
typedef struct
|
||||
{
|
||||
cfa_ tx_cfga;
|
||||
cfa_ rx_cfga;
|
||||
cfb_ tx_cfgb;
|
||||
cfb_ rx_cfgb;
|
||||
clrflag_ clflag;
|
||||
cv_ cell;
|
||||
acv_ acell;
|
||||
scv_ scell;
|
||||
fcv_ fcell;
|
||||
ax_ aux;
|
||||
rax_ raux;
|
||||
sta_ stata;
|
||||
stb_ statb;
|
||||
stc_ statc;
|
||||
std_ statd;
|
||||
ste_ state;
|
||||
com_ comm;
|
||||
pwma_ PwmA;
|
||||
pwmb_ PwmB;
|
||||
sid_ sid;
|
||||
ic_register_ configa;
|
||||
ic_register_ configb;
|
||||
ic_register_ clrflag;
|
||||
ic_register_ stat;
|
||||
ic_register_ com;
|
||||
ic_register_ pwma;
|
||||
ic_register_ pwmb;
|
||||
ic_register_ rsid;
|
||||
cmdcnt_pec_ cccrc;
|
||||
aux_ow_ gpio;
|
||||
cell_ow_ owcell;
|
||||
diag_test_ diag_result;
|
||||
} cell_asic;
|
||||
|
||||
/*!
|
||||
* \enum Loop Measurement ENABLED or DISABLED.
|
||||
*/
|
||||
typedef enum { DISABLED = 0X0, ENABLED = 0X1} LOOP_MEASURMENT;
|
||||
|
||||
/**************************************** CMDEnums *************************************************/
|
||||
/*!
|
||||
* \enum GPIO CHANNEL
|
||||
* CH: GPIO Channels.
|
||||
*/
|
||||
/* Channel selection */
|
||||
typedef enum
|
||||
{
|
||||
AUX_ALL = 0,
|
||||
GPIO1,
|
||||
GPIO2,
|
||||
GPIO3,
|
||||
GPIO4,
|
||||
GPIO5,
|
||||
GPIO6,
|
||||
GPIO7,
|
||||
GPIO8,
|
||||
GPIO9,
|
||||
GPIO10,
|
||||
VREF2,
|
||||
LD03V,
|
||||
LD05V,
|
||||
TEMP,
|
||||
V_POSTIVE_2_NAGATIVE,
|
||||
V_NAGATIVE,
|
||||
VR4K,
|
||||
VREF3
|
||||
}CH;
|
||||
|
||||
/*!
|
||||
* \enum RD
|
||||
* RD: Read Device.
|
||||
*/
|
||||
typedef enum { RD_OFF = 0X0, RD_ON = 0X1} RD;
|
||||
|
||||
/*!
|
||||
* \enum CONT
|
||||
* CONT: Continuous or single measurement.
|
||||
*/
|
||||
/* Continuous or single measurement */
|
||||
typedef enum { SINGLE = 0X0, CONTINUOUS = 0X1} CONT;
|
||||
|
||||
/*!
|
||||
* \enum OW_C_S
|
||||
* OW_C_S: Open wire c/s.
|
||||
*/
|
||||
/* Open wire c/s adcs */
|
||||
typedef enum { OW_OFF_ALL_CH = 0X0, OW_ON_EVEN_CH, OW_ON_ODD_CH, OW_ON_ALL_CH} OW_C_S;
|
||||
|
||||
/*!
|
||||
* \enum OW_AUX
|
||||
* OW_AUX: Open wire Aux.
|
||||
*/
|
||||
/* Open wire AUX */
|
||||
typedef enum { AUX_OW_OFF = 0X0, AUX_OW_ON = 0X1} OW_AUX;
|
||||
|
||||
/*!
|
||||
* \enum PUP
|
||||
* PUP: Pull Down current during aux conversion.
|
||||
*/
|
||||
/* Pull Down current during aux conversion (if OW = 1) */
|
||||
typedef enum { PUP_DOWN = 0X0, PUP_UP = 0X1 } PUP;
|
||||
|
||||
/*!
|
||||
* \enum DCP
|
||||
* DCP: Discharge permitted.
|
||||
*/
|
||||
/* Discharge permitted */
|
||||
typedef enum { DCP_OFF = 0X0, DCP_ON = 0X1} DCP;
|
||||
|
||||
/*!
|
||||
* \enum RSTF
|
||||
* RSTF: Reset Filter.
|
||||
*/
|
||||
/* Reset filter */
|
||||
typedef enum { RSTF_OFF = 0x0, RSTF_ON = 0x1 } RSTF;
|
||||
|
||||
/*!
|
||||
* \enum ERR
|
||||
* ERR: Inject error is spi read out.
|
||||
*/
|
||||
/* Inject error is spi read out */
|
||||
typedef enum { WITHOUT_ERR = 0x0, WITH_ERR = 0x1 } ERR;
|
||||
|
||||
/**************************************** Mem bits *************************************************/
|
||||
/* Configuration Register A */
|
||||
|
||||
/*!
|
||||
* \enum REFON
|
||||
* REFON: Refernece remains power up/down.
|
||||
*/
|
||||
/* Refernece remains power up/down */
|
||||
typedef enum { PWR_DOWN = 0x0, PWR_UP = 0x1 } REFON;
|
||||
|
||||
/*!
|
||||
* \enum CTH
|
||||
* CTH: Comparison voltages threshold C vs S.
|
||||
*/
|
||||
/* Comparison voltages threshold C vs S*/
|
||||
typedef enum
|
||||
{
|
||||
CVT_5_1mV = 0, /* 5.1mV */
|
||||
CVT_8_1mV, /* 8.1mV (Default) */
|
||||
CVT_10_05mV, /* 10.05mV */
|
||||
CVT_15mV, /* 15mV */
|
||||
CVT_22_5mV, /* 22.5mV */
|
||||
CVT_45mV, /* 45mV */
|
||||
CVT_75mV, /* 75mV */
|
||||
CVT_135mV, /* 135mV */
|
||||
}CTH;
|
||||
|
||||
/*!
|
||||
* \enum FLAG_D
|
||||
* FLAG_D: Fault flags.
|
||||
*/
|
||||
/* Fault flags */
|
||||
typedef enum
|
||||
{
|
||||
FLAG_D0 = 0, /* Force oscillator counter fast */
|
||||
FLAG_D1, /* Force oscillator counter slow */
|
||||
FLAG_D2, /* Force Supply Error detection */
|
||||
FLAG_D3, /* FLAG_D[3]: 1--> Select Supply OV and delta detection, 0 --> Selects UV */
|
||||
FLAG_D4, /* Set THSD */
|
||||
FLAG_D5, /* Force Fuse ED */
|
||||
FLAG_D6, /* Force Fuse MED */
|
||||
FLAG_D7, /* Force TMODCHK */
|
||||
} FLAG_D;
|
||||
|
||||
typedef enum { FLAG_CLR = 0x0, FLAG_SET = 0x1 } CFGA_FLAG;
|
||||
|
||||
/*!
|
||||
* \enum CL FLAG
|
||||
* FLAG: Fault Clear.
|
||||
*/
|
||||
typedef enum { CL_FLAG_CLR = 0x0, CL_FLAG_SET = 0x1 } FLAG;
|
||||
|
||||
/*!
|
||||
* \enum SOAKON
|
||||
* SOAKON: Enables or disable soak time for all commands.
|
||||
*/
|
||||
/* Enables or disable soak time for all commands */
|
||||
typedef enum { SOAKON_CLR = 0x0, SOAKON_SET = 0x1 } SOAKON;
|
||||
|
||||
|
||||
/* Open wire sokon time owa */
|
||||
typedef enum {OWA0 = 0x0, OWA1, OWA2, OWA3, OWA4, OWA5, OWA6, OWA7} OWA;
|
||||
|
||||
/*!
|
||||
* \enum OWRNG
|
||||
* OWRNG: Set soak time range Long/Short.
|
||||
*/
|
||||
/* Set soak time range Long/Short */
|
||||
typedef enum { SHORT = 0x0, LONG = 0x1 } OWRNG;
|
||||
|
||||
|
||||
/*!
|
||||
* \enum OW_TIME
|
||||
* OW_TIME:Open Wire Soak times
|
||||
* For Aux commands. If OWRNG=0, Soak time = 2^(6 +OWA[2:0]) Clocks (32 us 4.1 ms)
|
||||
* For Aux commands. If OWRNG=1, Soak time = 2^(13+OWA[2:0]) Clocks (41 ms 524 ms)
|
||||
*/
|
||||
typedef enum { TIME_32US_TO_4_1MS = 0x0, TIME_41MS_TO_524MS = 0x1 } OW_TIME;
|
||||
|
||||
/*!
|
||||
* \enum GPO
|
||||
* GPO: GPO Pins.
|
||||
*/
|
||||
/* GPO Pins */
|
||||
typedef enum
|
||||
{
|
||||
GPO1 = 0,
|
||||
GPO2,
|
||||
GPO3,
|
||||
GPO4,
|
||||
GPO5,
|
||||
GPO6,
|
||||
GPO7,
|
||||
GPO8,
|
||||
GPO9,
|
||||
GPO10,
|
||||
} GPO;
|
||||
|
||||
/*!
|
||||
* \enum GPIO
|
||||
* GPIO: GPIO Pin Control.
|
||||
*/
|
||||
/* GPO Pin Control */
|
||||
typedef enum { GPO_CLR = 0x0, GPO_SET = 0x1 } CFGA_GPO;
|
||||
|
||||
/*!
|
||||
* \enum IIR_FPA
|
||||
* IIR_FPA: IIR Filter Parameter.
|
||||
*/
|
||||
/* IIR Filter Parameter */
|
||||
typedef enum
|
||||
{
|
||||
IIR_FPA_OFF = 0, /* Filter Disabled */
|
||||
IIR_FPA2, /* 110 Hz -3dB Frequency */
|
||||
IIR_FPA4, /* 45 Hz -3dB Frequency */
|
||||
IIR_FPA8, /* 21 Hz -3dB Frequency */
|
||||
IIR_FPA16, /* 10 Hz -3dB Frequency */
|
||||
IIR_FPA32, /* 5 Hz -3dB Frequency */
|
||||
IIR_FPA128, /* 1.25 Hz -3dB Frequency */
|
||||
IIR_FPA256, /* 0.625 Hz -3dB Frequency */
|
||||
}IIR_FPA;
|
||||
|
||||
/*!
|
||||
* \enum COMM_BK
|
||||
* COMM_BK: Communication Break.
|
||||
*/
|
||||
/* Communication Break */
|
||||
typedef enum { COMM_BK_OFF = 0x0, COMM_BK_ON = 0x1 } COMM_BK;
|
||||
|
||||
/*!
|
||||
* \enum SNAPSHOT
|
||||
* SNAPSHOT: Snapshot.
|
||||
*/
|
||||
/* Snapshot */
|
||||
typedef enum { SNAP_OFF = 0x0, SNAP_ON = 0x1 } SNAPSHOT;
|
||||
|
||||
/* Configuration Register B */
|
||||
|
||||
/*!
|
||||
* \enum DTMEN
|
||||
* DTMEN: Enable Dis-charge Timer Monitor.
|
||||
*/
|
||||
/* Enable Dis-charge Timer Monitor */
|
||||
typedef enum { DTMEN_OFF = 0x0, DTMEN_ON = 0x1 } DTMEN;
|
||||
|
||||
/*!
|
||||
* \enum DTRNG
|
||||
* DTRNG: Discharge Timer Range Setting.
|
||||
*/
|
||||
/* Discharge Timer Range Setting */
|
||||
typedef enum { RANG_0_TO_63_MIN = 0x0, RANG_0_TO_16_8_HR = 0x1 } DTRNG;
|
||||
|
||||
/*!
|
||||
* \enum DCTO
|
||||
* DCTO: DCTO timeout values.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
DCTO_TIMEOUT = 0,
|
||||
TIME_1MIN_OR_0_26HR,
|
||||
TIME_2MIN_OR_0_53HR,
|
||||
TIME_3MIN_OR_0_8HR,
|
||||
TIME_4MIN_OR_1_06HR,
|
||||
TIME_5MIN_OR_1_33HR,
|
||||
TIME_6MIN_OR_1_6HR,
|
||||
/* If required more time out value add here */
|
||||
} DCTO;
|
||||
|
||||
/*!
|
||||
* \enum PWM
|
||||
* PWM: PWM Duty cycle.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PWM_0_0_PCT = 0, /* 0.0% (default) */
|
||||
PWM_6_6_PCT, /* 6.6% */
|
||||
PWM_13_2_PCT, /* 13.2% */
|
||||
PWM_19_8_PCT, /* 19.8% */
|
||||
PWM_26_4_PCT, /* 26.4% */
|
||||
PWM_33_0_PCT, /* 33.0% */
|
||||
PWM_39_6_PCT, /* 39.6% */
|
||||
PWM_46_2_PCT, /* 46.2% */
|
||||
PWM_52_8_PCT, /* 52.8% */
|
||||
PWM_59_4_PCT, /* 59.4% */
|
||||
PWM_66_0_PCT, /* 66.0% */
|
||||
PWM_72_6_PCT, /* 72.6% */
|
||||
PWM_79_2_PCT, /* 79.2% */
|
||||
PWM_85_8_PCT, /* 85.8% */
|
||||
PWM_92_4_PCT, /* 92.4% */
|
||||
PWM_100_0_PCT, /* ~100.0% */
|
||||
} PWM_DUTY;
|
||||
|
||||
/*!
|
||||
* \enum DCC
|
||||
* DCC: DCC bits.
|
||||
*/
|
||||
/* DCC bits */
|
||||
typedef enum
|
||||
{
|
||||
DCC1 = 0,
|
||||
DCC2,
|
||||
DCC3,
|
||||
DCC4,
|
||||
DCC5,
|
||||
DCC6,
|
||||
DCC7,
|
||||
DCC8,
|
||||
DCC9,
|
||||
DCC10,
|
||||
DCC11,
|
||||
DCC12,
|
||||
DCC13,
|
||||
DCC14,
|
||||
DCC15,
|
||||
DCC16,
|
||||
} DCC;
|
||||
|
||||
/*!
|
||||
* \enum DCC_BIT
|
||||
* DCC_BIT: Discharge cell set and claer.
|
||||
*/
|
||||
/* Discharge cell set and claer */
|
||||
typedef enum { DCC_BIT_CLR = 0x0, DCC_BIT_SET = 0x1 } DCC_BIT;
|
||||
|
||||
/* General Enums */
|
||||
typedef enum { ALL_GRP = 0x0, A,B, C, D, E, F ,NONE} GRP;
|
||||
typedef enum { Cell = 0x0, Aux, RAux, Status, Pwm, AvgCell, S_volt, F_volt, Config, Comm, Sid, Clrflag, Rdcvall, Rdacall, Rdsall, Rdcsall, Rdacsall, Rdfcall, Rdasall} TYPE;
|
||||
typedef enum { PASS , FAIL } RESULT ;
|
||||
typedef enum { OSC_MISMATCH = 0x0, SUPPLY_ERROR, THSD, FUSE_ED, FUSE_MED, TMODCHK} DIAGNOSTIC_TYPE;
|
||||
#endif /* __BMS_DATA_H */
|
||||
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
85
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830GenericType.h
Normal file
85
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830GenericType.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2020 - Analog Devices Inc. All Rights Reserved.
|
||||
This software is proprietary & confidential to Analog Devices, Inc.
|
||||
and its licensor.
|
||||
******************************************************************************
|
||||
* @file: adBms6830GenericType.h
|
||||
* @brief: Generic Type function header file
|
||||
* @version: $Revision$
|
||||
* @date: $Date$
|
||||
* Developed by: ADIBMS Software team, Bangalore, India
|
||||
*****************************************************************************/
|
||||
/** @addtogroup BMS_DRIVER
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/** @addtogroup GENERIC_TYPE GENERIC TYPE
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
#ifndef __adBmsGenericType_H
|
||||
#define __adBmsGenericType_H
|
||||
|
||||
#include "adbms_main.h"
|
||||
|
||||
/* Calculates and returns the CRC15Table */
|
||||
uint16_t Pec15_Calc
|
||||
(
|
||||
uint8_t len, /* Number of bytes that will be used to calculate a PEC */
|
||||
uint8_t *data /* Array of data that will be used to calculate a PEC */
|
||||
);
|
||||
uint16_t pec10_calc(bool rx_cmd, int len, uint8_t *data);
|
||||
|
||||
void spiSendCmd(uint8_t tx_cmd[2]);
|
||||
|
||||
void spiReadData
|
||||
(
|
||||
uint8_t tIC,
|
||||
uint8_t tx_cmd[2],
|
||||
uint8_t *rx_data,
|
||||
uint8_t *pec_error,
|
||||
uint8_t *cmd_cntr,
|
||||
uint8_t regData_size
|
||||
);
|
||||
void spiWriteData
|
||||
(
|
||||
uint8_t tIC,
|
||||
uint8_t tx_cmd[2],
|
||||
uint8_t *data
|
||||
);
|
||||
void adBmsReadData(uint8_t tIC, cell_asic *ic, uint8_t cmd_arg[2], TYPE type, GRP group);
|
||||
void adBmsWriteData(uint8_t tIC, cell_asic *ic, uint8_t cmd_arg[2], TYPE type, GRP group);
|
||||
uint32_t adBmsPollAdc(uint8_t tx_cmd[2]);
|
||||
|
||||
void adBms6830_Adcv
|
||||
(
|
||||
RD rd,
|
||||
CONT cont,
|
||||
DCP dcp,
|
||||
RSTF rstf,
|
||||
OW_C_S owcs
|
||||
);
|
||||
|
||||
void adBms6830_Adsv
|
||||
(
|
||||
CONT cont,
|
||||
DCP dcp,
|
||||
OW_C_S owcs
|
||||
);
|
||||
|
||||
void adBms6830_Adax
|
||||
(
|
||||
OW_AUX owaux,
|
||||
PUP pup,
|
||||
CH ch
|
||||
);
|
||||
|
||||
void adBms6830_Adax2
|
||||
(
|
||||
CH ch
|
||||
);
|
||||
|
||||
#endif
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
63
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830ParseCreate.h
Normal file
63
Keil_Studio_Cloud/ADBMS6830/inc/adBms6830ParseCreate.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2020 - Analog Devices Inc. All Rights Reserved.
|
||||
This software is proprietary & confidential to Analog Devices, Inc.
|
||||
and its licensor.
|
||||
******************************************************************************
|
||||
* @file: adBms6830ParseCreate.h
|
||||
* @brief: Data parse create helper function header file
|
||||
* @version: $Revision$
|
||||
* @date: $Date$
|
||||
* Developed by: ADIBMS Software team, Bangalore, India
|
||||
*****************************************************************************/
|
||||
/** @addtogroup BMS_DRIVER
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/** @addtogroup PARSE_CREATE PARSE CREATE DATA
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
#ifndef __ADBMSPARSECREATE_H
|
||||
#define __ADBMSPARSECREATE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "adBms6830Data.h"
|
||||
|
||||
uint16_t SetOverVoltageThreshold(float volt);
|
||||
uint16_t SetUnderVoltageThreshold(float voltage);
|
||||
uint8_t ConfigA_Flag(FLAG_D flag_d, CFGA_FLAG flag);
|
||||
uint16_t ConfigA_Gpo(GPO gpo, CFGA_GPO stat);
|
||||
uint16_t ConfigB_DccBit(DCC dcc, DCC_BIT dccbit);
|
||||
void SetConfigB_DischargeTimeOutValue(uint8_t tIC, cell_asic *ic, DTRNG timer_rang, DCTO timeout_value);
|
||||
void SetPwmDutyCycle(uint8_t tIC, cell_asic *ic, PWM_DUTY duty_cycle);
|
||||
void adBms6830ParseConfiga(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseConfigb(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseConfig(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *data);
|
||||
void adBms6830ParseCell(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *cv_data);
|
||||
void adBms6830ParseAverageCell(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *acv_data);
|
||||
void adBms6830ParseSCell(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *scv_data);
|
||||
void adBms6830ParseFCell(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *fcv_data);
|
||||
void adBms6830ParseAux(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *aux_data);
|
||||
void adBms6830ParseRAux(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *raux_data);
|
||||
void adBms6830ParseStatusA(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseStatusB(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseStatusC(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseStatusD(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseStatusE(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParseStatus(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *data);
|
||||
void adBms6830ParseComm(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParsePwma(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParsePwmb(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
void adBms6830ParsePwm(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *data);
|
||||
void adBms6830CreateConfiga(uint8_t tIC, cell_asic *ic);
|
||||
void adBms6830CreateConfigb(uint8_t tIC, cell_asic *ic);
|
||||
void adBms6830CreateClrflagData(uint8_t tIC, cell_asic *ic);
|
||||
void adBms6830CreateComm(uint8_t tIC, cell_asic *ic);
|
||||
void adBms6830CreatePwma(uint8_t tIC, cell_asic *ic);
|
||||
void adBms6830CreatePwmb(uint8_t tIC, cell_asic *ic);
|
||||
void adBms6830ParseSID(uint8_t tIC, cell_asic *ic, uint8_t *data);
|
||||
|
||||
#endif
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
871
Keil_Studio_Cloud/ADBMS6830/src/adBms6830GenericType.cpp
Normal file
871
Keil_Studio_Cloud/ADBMS6830/src/adBms6830GenericType.cpp
Normal file
@ -0,0 +1,871 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2020 - Analog Devices Inc. All Rights Reserved.
|
||||
This software is proprietary & confidential to Analog Devices, Inc.
|
||||
and its licensor.
|
||||
******************************************************************************
|
||||
* @file: Adbms6830GenericType.c
|
||||
* @brief: Generic function driver file
|
||||
* @version: $Revision$
|
||||
* @date: $Date$
|
||||
* Developed by: ADIBMS Software team, Bangalore, India
|
||||
*****************************************************************************/
|
||||
/*! \addtogroup BMS DRIVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @addtogroup GENERIC_TYPE GENERIC TYPE
|
||||
* @{
|
||||
*
|
||||
This documentation provides details about BMS driver APIs and their usage.
|
||||
Using the BMS Driver Application can:
|
||||
- Read/Write the configuration registers of the BMS devices stacked in daisy chaining.
|
||||
- Send commands and Read the Cell Voltages, Aux Voltages and Status registers (Sum of cells, Internal Die temperature etc.)
|
||||
|
||||
*/
|
||||
#include "common.h"
|
||||
#include "adbms_main.h"
|
||||
#ifdef MBED
|
||||
extern Serial pc;
|
||||
#endif
|
||||
/**************************************** BMS Driver APIs definitions ********************************************/
|
||||
/* Precomputed CRC15 Table */
|
||||
const uint16_t Crc15Table[256] =
|
||||
{
|
||||
0x0000,0xc599, 0xceab, 0xb32, 0xd8cf, 0x1d56, 0x1664, 0xd3fd, 0xf407, 0x319e, 0x3aac,
|
||||
0xff35, 0x2cc8, 0xe951, 0xe263, 0x27fa, 0xad97, 0x680e, 0x633c, 0xa6a5, 0x7558, 0xb0c1,
|
||||
0xbbf3, 0x7e6a, 0x5990, 0x9c09, 0x973b, 0x52a2, 0x815f, 0x44c6, 0x4ff4, 0x8a6d, 0x5b2e,
|
||||
0x9eb7, 0x9585, 0x501c, 0x83e1, 0x4678, 0x4d4a, 0x88d3, 0xaf29, 0x6ab0, 0x6182, 0xa41b,
|
||||
0x77e6, 0xb27f, 0xb94d, 0x7cd4, 0xf6b9, 0x3320, 0x3812, 0xfd8b, 0x2e76, 0xebef, 0xe0dd,
|
||||
0x2544, 0x2be, 0xc727, 0xcc15, 0x98c, 0xda71, 0x1fe8, 0x14da, 0xd143, 0xf3c5, 0x365c,
|
||||
0x3d6e, 0xf8f7,0x2b0a, 0xee93, 0xe5a1, 0x2038, 0x7c2, 0xc25b, 0xc969, 0xcf0, 0xdf0d,
|
||||
0x1a94, 0x11a6, 0xd43f, 0x5e52, 0x9bcb, 0x90f9, 0x5560, 0x869d, 0x4304, 0x4836, 0x8daf,
|
||||
0xaa55, 0x6fcc, 0x64fe, 0xa167, 0x729a, 0xb703, 0xbc31, 0x79a8, 0xa8eb, 0x6d72, 0x6640,
|
||||
0xa3d9, 0x7024, 0xb5bd, 0xbe8f, 0x7b16, 0x5cec, 0x9975, 0x9247, 0x57de, 0x8423, 0x41ba,
|
||||
0x4a88, 0x8f11, 0x57c, 0xc0e5, 0xcbd7, 0xe4e, 0xddb3, 0x182a, 0x1318, 0xd681, 0xf17b,
|
||||
0x34e2, 0x3fd0, 0xfa49, 0x29b4, 0xec2d, 0xe71f, 0x2286, 0xa213, 0x678a, 0x6cb8, 0xa921,
|
||||
0x7adc, 0xbf45, 0xb477, 0x71ee, 0x5614, 0x938d, 0x98bf, 0x5d26, 0x8edb, 0x4b42, 0x4070,
|
||||
0x85e9, 0xf84, 0xca1d, 0xc12f, 0x4b6, 0xd74b, 0x12d2, 0x19e0, 0xdc79, 0xfb83, 0x3e1a, 0x3528,
|
||||
0xf0b1, 0x234c, 0xe6d5, 0xede7, 0x287e, 0xf93d, 0x3ca4, 0x3796, 0xf20f, 0x21f2, 0xe46b, 0xef59,
|
||||
0x2ac0, 0xd3a, 0xc8a3, 0xc391, 0x608, 0xd5f5, 0x106c, 0x1b5e, 0xdec7, 0x54aa, 0x9133, 0x9a01,
|
||||
0x5f98, 0x8c65, 0x49fc, 0x42ce, 0x8757, 0xa0ad, 0x6534, 0x6e06, 0xab9f, 0x7862, 0xbdfb, 0xb6c9,
|
||||
0x7350, 0x51d6, 0x944f, 0x9f7d, 0x5ae4, 0x8919, 0x4c80, 0x47b2, 0x822b, 0xa5d1, 0x6048, 0x6b7a,
|
||||
0xaee3, 0x7d1e, 0xb887, 0xb3b5, 0x762c, 0xfc41, 0x39d8, 0x32ea, 0xf773, 0x248e, 0xe117, 0xea25,
|
||||
0x2fbc, 0x846, 0xcddf, 0xc6ed, 0x374, 0xd089, 0x1510, 0x1e22, 0xdbbb, 0xaf8, 0xcf61, 0xc453,
|
||||
0x1ca, 0xd237, 0x17ae, 0x1c9c, 0xd905, 0xfeff, 0x3b66, 0x3054, 0xf5cd, 0x2630, 0xe3a9, 0xe89b,
|
||||
0x2d02, 0xa76f, 0x62f6, 0x69c4, 0xac5d, 0x7fa0, 0xba39, 0xb10b, 0x7492, 0x5368, 0x96f1, 0x9dc3,
|
||||
0x585a, 0x8ba7, 0x4e3e, 0x450c, 0x8095
|
||||
};
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: Pec15_Calc
|
||||
* @brief CRC15 Pec Calculation Function
|
||||
*
|
||||
* @details This function calculates and return the CRC15 value
|
||||
*
|
||||
* Parameters:
|
||||
* @param [in] Len Data length
|
||||
*
|
||||
* @param [in] *data Data pointer
|
||||
*
|
||||
* @return CRC15_Value
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
uint16_t Pec15_Calc
|
||||
(
|
||||
uint8_t len, /* Number of bytes that will be used to calculate a PEC */
|
||||
uint8_t *data /* Array of data that will be used to calculate a PEC */
|
||||
)
|
||||
{
|
||||
uint16_t remainder,addr;
|
||||
remainder = 16; /* initialize the PEC */
|
||||
for (uint8_t i = 0; i<len; i++) /* loops for each byte in data array */
|
||||
{
|
||||
addr = (((remainder>>7)^data[i])&0xff);/* calculate PEC table address */
|
||||
remainder = ((remainder<<8)^Crc15Table[addr]);
|
||||
}
|
||||
return(remainder*2);/* The CRC15 has a 0 in the LSB so the remainder must be multiplied by 2 */
|
||||
}
|
||||
|
||||
uint16_t pec10_calc(bool rx_cmd, int len, uint8_t *data)
|
||||
{
|
||||
uint16_t remainder = 16; /* PEC_SEED; 0000010000 */
|
||||
uint16_t polynom = 0x8F; /* x10 + x7 + x3 + x2 + x + 1 <- the CRC15 polynomial 100 1000 1111 48F */
|
||||
|
||||
/* Perform modulo-2 division, a byte at a time. */
|
||||
for (uint8_t pbyte = 0; pbyte < len; ++pbyte)
|
||||
{
|
||||
/* Bring the next byte into the remainder. */
|
||||
remainder ^= (uint16_t)(data[pbyte] << 2);
|
||||
/* Perform modulo-2 division, a bit at a time.*/
|
||||
for (uint8_t bit_ = 8; bit_ > 0; --bit_)
|
||||
{
|
||||
/* Try to divide the current data bit. */
|
||||
if ((remainder & 0x200) > 0)//equivalent to remainder & 2^14 simply check for MSB
|
||||
{
|
||||
remainder = (uint16_t)((remainder << 1));
|
||||
remainder = (uint16_t)(remainder ^ polynom);
|
||||
}
|
||||
else
|
||||
{
|
||||
remainder = (uint16_t)(remainder << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rx_cmd == true)
|
||||
{
|
||||
remainder ^= (uint16_t)((data[len] & 0xFC) << 2);
|
||||
/* Perform modulo-2 division, a bit at a time */
|
||||
for (uint8_t bit_ = 6; bit_ > 0; --bit_)
|
||||
{
|
||||
/* Try to divide the current data bit */
|
||||
if ((remainder & 0x200) > 0)//equivalent to remainder & 2^14 simply check for MSB
|
||||
{
|
||||
remainder = (uint16_t)((remainder << 1));
|
||||
remainder = (uint16_t)(remainder ^ polynom);
|
||||
}
|
||||
else
|
||||
{
|
||||
remainder = (uint16_t)((remainder << 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ((uint16_t)(remainder & 0x3FF));
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: spiSendCmd
|
||||
* @brief Send command in spi line
|
||||
*
|
||||
* @details This function send bms command in spi line
|
||||
*
|
||||
* Parameters:
|
||||
* @param [in] tx_cmd Tx command bytes
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void spiSendCmd(uint8_t tx_cmd[2])
|
||||
{
|
||||
uint8_t cmd[4];
|
||||
uint16_t cmd_pec;
|
||||
cmd[0] = tx_cmd[0];
|
||||
cmd[1] = tx_cmd[1];
|
||||
cmd_pec = Pec15_Calc(2, cmd);
|
||||
cmd[2] = (uint8_t)(cmd_pec >> 8);
|
||||
cmd[3] = (uint8_t)(cmd_pec);
|
||||
adBmsCsLow();
|
||||
spiWriteBytes(4, &cmd[0]);
|
||||
adBmsCsHigh();
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: spiReadData
|
||||
* @brief Spi Read Bms Data
|
||||
*
|
||||
* @details This function send bms command in spi line and read command corrospond data byte.
|
||||
*
|
||||
* Parameters:
|
||||
* @param [in] tIC Total IC
|
||||
*
|
||||
* @param [in] tx_cmd Tx command bytes
|
||||
*
|
||||
* @param [in] *rx_data Rx data pointer
|
||||
*
|
||||
* @param [in] *pec_error Pec error pointer
|
||||
*
|
||||
* @param [in] *cmd_cntr command counter pointer
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void spiReadData
|
||||
(
|
||||
uint8_t tIC,
|
||||
uint8_t tx_cmd[2],
|
||||
uint8_t *rx_data,
|
||||
uint8_t *pec_error,
|
||||
uint8_t *cmd_cntr,
|
||||
uint8_t regData_size
|
||||
)
|
||||
{
|
||||
uint8_t *data, *copyArray, src_address = 0;
|
||||
uint16_t cmd_pec, received_pec, calculated_pec;
|
||||
uint8_t BYTES_IN_REG = regData_size;
|
||||
uint8_t RX_BUFFER = (regData_size * tIC);
|
||||
|
||||
data = (uint8_t *)calloc(RX_BUFFER, sizeof(uint8_t));
|
||||
copyArray = (uint8_t *)calloc(BYTES_IN_REG, sizeof(uint8_t));
|
||||
if((data == NULL) || (copyArray == NULL))
|
||||
{
|
||||
#ifdef MBED
|
||||
pc.printf(" Failed to allocate spi read data memory \n");
|
||||
#else
|
||||
printf(" Failed to allocate spi read data memory \n");
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t cmd[4];
|
||||
cmd[0] = tx_cmd[0];
|
||||
cmd[1] = tx_cmd[1];
|
||||
cmd_pec = Pec15_Calc(2, cmd);
|
||||
cmd[2] = (uint8_t)(cmd_pec >> 8);
|
||||
cmd[3] = (uint8_t)(cmd_pec);
|
||||
adBmsCsLow();
|
||||
spiWriteReadBytes(&cmd[0], &data[0], RX_BUFFER); /* Read the configuration data of all ICs on the daisy chain into readdata array */
|
||||
adBmsCsHigh();
|
||||
for (uint8_t current_ic = 0; current_ic < tIC; current_ic++) /* executes for each ic in the daisy chain and packs the data */
|
||||
{ /* Into the r_comm array as well as check the received data for any bit errors */
|
||||
for (uint8_t current_byte = 0; current_byte < (BYTES_IN_REG-2); current_byte++)
|
||||
{
|
||||
rx_data[(current_ic*BYTES_IN_REG)+current_byte] = data[current_byte + (current_ic*BYTES_IN_REG)];
|
||||
}
|
||||
/* Get command counter value */
|
||||
cmd_cntr[current_ic] = (data[(current_ic * BYTES_IN_REG) + (BYTES_IN_REG - 2)] >> 2);
|
||||
/* Get received pec value from ic*/
|
||||
received_pec = (uint16_t)(((data[(current_ic * BYTES_IN_REG) + (BYTES_IN_REG - 2)] & 0x03) << 8) | data[(current_ic * BYTES_IN_REG) + (BYTES_IN_REG - 1)]);
|
||||
/* Copy each ic correspond data + pec value for calculate data pec */
|
||||
memcpy(©Array[0], &data[src_address], BYTES_IN_REG);
|
||||
src_address = ((current_ic+1) * (regData_size));
|
||||
/* Calculate data pec */
|
||||
calculated_pec = (uint16_t)pec10_calc(true, (BYTES_IN_REG-2), ©Array[0]);
|
||||
/* Match received pec with calculated pec */
|
||||
if (received_pec == calculated_pec){ pec_error[current_ic] = 0; }/* If no error is there value set to 0 */
|
||||
else{ pec_error[current_ic] = 1; } /* If error is there value set to 1 */
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
free(copyArray);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: spiWriteData
|
||||
* @brief Spi Write Bms Data
|
||||
*
|
||||
* @details This function write the data into bms ic.
|
||||
*
|
||||
* Parameters:
|
||||
* @param [in] tIC Total IC
|
||||
*
|
||||
* @param [in] tx_cmd Tx command bytes
|
||||
*
|
||||
* @param [in] *data Data pointer
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void spiWriteData
|
||||
(
|
||||
uint8_t tIC,
|
||||
uint8_t tx_cmd[2],
|
||||
uint8_t *data
|
||||
)
|
||||
{
|
||||
uint8_t BYTES_IN_REG = TX_DATA;
|
||||
uint8_t CMD_LEN = 4 + (RX_DATA * tIC);
|
||||
uint16_t data_pec, cmd_pec;
|
||||
uint8_t *cmd, copyArray[TX_DATA], src_address = 0;
|
||||
uint8_t cmd_index;
|
||||
cmd = (uint8_t *)calloc(CMD_LEN, sizeof(uint8_t));
|
||||
if(cmd == NULL)
|
||||
{
|
||||
#ifdef MBED
|
||||
pc.printf(" Failed to allocate cmd array memory \n");
|
||||
#else
|
||||
printf(" Failed to allocate cmd array memory \n");
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd[0] = tx_cmd[0];
|
||||
cmd[1] = tx_cmd[1];
|
||||
cmd_pec = Pec15_Calc(2, cmd);
|
||||
cmd[2] = (uint8_t)(cmd_pec >> 8);
|
||||
cmd[3] = (uint8_t)(cmd_pec);
|
||||
cmd_index = 4;
|
||||
/* executes for each LTC68xx, this loops starts with the last IC on the stack */
|
||||
for (uint8_t current_ic = tIC; current_ic > 0; current_ic--)
|
||||
{
|
||||
src_address = ((current_ic-1) * TX_DATA);
|
||||
/* The first configuration written is received by the last IC in the daisy chain */
|
||||
for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
|
||||
{
|
||||
cmd[cmd_index] = data[((current_ic-1)*6)+current_byte];
|
||||
cmd_index = cmd_index + 1;
|
||||
}
|
||||
/* Copy each ic correspond data + pec value for calculate data pec */
|
||||
memcpy(©Array[0], &data[src_address], TX_DATA); /* dst, src, size */
|
||||
/* calculating the PEC for each Ics configuration register data */
|
||||
data_pec = (uint16_t)pec10_calc(true,BYTES_IN_REG, ©Array[0]);
|
||||
cmd[cmd_index] = (uint8_t)(data_pec >> 8);
|
||||
cmd_index = cmd_index + 1;
|
||||
cmd[cmd_index] = (uint8_t)data_pec;
|
||||
cmd_index = cmd_index + 1;
|
||||
}
|
||||
adBmsCsLow();
|
||||
spiWriteBytes(CMD_LEN, &cmd[0]);
|
||||
adBmsCsHigh();
|
||||
}
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBmsReadData
|
||||
* @brief Adbms Read Data From Bms ic.
|
||||
*
|
||||
* @details This function send bms command, read payload data parse into function and check pec error.
|
||||
*
|
||||
* Parameters:
|
||||
* @param [in] tIC Total IC
|
||||
*
|
||||
* @param [in] *ic cell_asic stucture pointer
|
||||
*
|
||||
* @param [in] cmd_arg command bytes
|
||||
*
|
||||
* @param [in] TYPE Enum type of resistor
|
||||
*
|
||||
* @param [in] GRP Enum type of resistor group
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void adBmsReadData(uint8_t tIC, cell_asic *ic, uint8_t cmd_arg[2], TYPE type, GRP group)
|
||||
{
|
||||
uint16_t rBuff_size;
|
||||
uint8_t regData_size;
|
||||
if(group == ALL_GRP)
|
||||
{
|
||||
if(type == Rdcvall){rBuff_size = RDCVALL_SIZE; regData_size = RDCVALL_SIZE;}
|
||||
else if(type == Rdsall){rBuff_size = RDSALL_SIZE; regData_size = RDSALL_SIZE;}
|
||||
else if(type == Rdacall){rBuff_size = RDACALL_SIZE; regData_size = RDACALL_SIZE;}
|
||||
else if(type == Rdfcall){rBuff_size = RDFCALL_SIZE; regData_size = RDFCALL_SIZE;}
|
||||
else if(type == Rdcsall){rBuff_size = RDCSALL_SIZE; regData_size = RDCSALL_SIZE;}
|
||||
else if(type == Rdasall){rBuff_size = RDASALL_SIZE; regData_size = RDASALL_SIZE;}
|
||||
else if(type == Rdacsall){rBuff_size = RDACSALL_SIZE; regData_size = RDACSALL_SIZE;}
|
||||
else{printf("Read All cmd wrong type select \n");}
|
||||
}
|
||||
else{rBuff_size = (tIC * RX_DATA); regData_size = RX_DATA;}
|
||||
uint8_t *read_buffer, *pec_error, *cmd_count;
|
||||
read_buffer = (uint8_t *)calloc(rBuff_size, sizeof(uint8_t));
|
||||
pec_error = (uint8_t *)calloc(tIC, sizeof(uint8_t));
|
||||
cmd_count = (uint8_t *)calloc(tIC, sizeof(uint8_t));
|
||||
if((pec_error == NULL) || (cmd_count == NULL) || (read_buffer == NULL))
|
||||
{
|
||||
#ifdef MBED
|
||||
pc.printf(" Failed to allocate memory \n");
|
||||
#else
|
||||
printf(" Failed to allocate memory \n");
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
spiReadData(tIC, &cmd_arg[0], &read_buffer[0], &pec_error[0], &cmd_count[0], regData_size);
|
||||
switch (type)
|
||||
{
|
||||
case Config:
|
||||
adBms6830ParseConfig(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.cfgr_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Cell:
|
||||
adBms6830ParseCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.cell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case AvgCell:
|
||||
adBms6830ParseAverageCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.acell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case S_volt:
|
||||
adBms6830ParseSCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.scell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case F_volt:
|
||||
adBms6830ParseFCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.fcell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Aux:
|
||||
adBms6830ParseAux(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.aux_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case RAux:
|
||||
adBms6830ParseRAux(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.raux_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Status:
|
||||
adBms6830ParseStatus(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.stat_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Comm:
|
||||
adBms6830ParseComm(tIC, ic, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.comm_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Pwm:
|
||||
adBms6830ParsePwm(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.pwm_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Sid:
|
||||
adBms6830ParseSID(tIC, ic, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.sid_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdcvall:
|
||||
/* 32 byte cell data + 2 byte pec */
|
||||
adBms6830ParseCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.cell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdacall:
|
||||
/* 32 byte avg cell data + 2 byte pec */
|
||||
adBms6830ParseAverageCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.acell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdsall:
|
||||
/* 32 byte scell volt data + 2 byte pec */
|
||||
adBms6830ParseSCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.scell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdfcall:
|
||||
/* 32 byte fcell data + 2 byte pec */
|
||||
adBms6830ParseFCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.fcell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdcsall:
|
||||
/* 64 byte + 2 byte pec = 32 byte cell data + 32 byte scell volt data */
|
||||
adBms6830ParseCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.cell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
adBms6830ParseSCell(tIC, ic, group, &read_buffer[32]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.scell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdacsall:
|
||||
/* 64 byte + 2 byte pec = 32 byte avg cell data + 32 byte scell volt data */
|
||||
adBms6830ParseAverageCell(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.acell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
adBms6830ParseSCell(tIC, ic, group, &read_buffer[32]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.scell_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
case Rdasall:
|
||||
/* 68 byte + 2 byte pec:
|
||||
24 byte gpio data + 20 byte Redundant gpio data +
|
||||
24 byte status A(6 byte), B(6 byte), C(4 byte), D(6 byte) & E(2 byte)
|
||||
*/
|
||||
adBms6830ParseAux(tIC, ic, group, &read_buffer[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.aux_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
adBms6830ParseRAux(tIC, ic, group, &read_buffer[24]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.raux_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
adBms6830ParseStatus(tIC, ic, group, &read_buffer[44]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
ic[cic].cccrc.stat_pec = pec_error[cic];
|
||||
ic[cic].cccrc.cmd_cntr = cmd_count[cic];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(read_buffer);
|
||||
free(pec_error);
|
||||
free(cmd_count);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBmsWriteData
|
||||
* @brief Adbms Write Data into Bms ic.
|
||||
*
|
||||
* @details This function write the data into bms ic.
|
||||
*
|
||||
* Parameters:
|
||||
* @param [in] tIC Total IC
|
||||
*
|
||||
* @param [in] *ic cell_asic stucture pointer
|
||||
*
|
||||
* @param [in] cmd_arg command bytes
|
||||
*
|
||||
* @param [in] TYPE Enum type of resistor
|
||||
*
|
||||
* @param [in] GRP Enum type of resistor group
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void adBmsWriteData(uint8_t tIC, cell_asic *ic, uint8_t cmd_arg[2], TYPE type, GRP group)
|
||||
{
|
||||
uint8_t data_len = TX_DATA, write_size = (TX_DATA * tIC);
|
||||
uint8_t *write_buffer = (uint8_t *)calloc(write_size, sizeof(uint8_t));
|
||||
if(write_buffer == NULL)
|
||||
{
|
||||
#ifdef MBED
|
||||
pc.printf(" Failed to allocate write_buffer array memory \n");
|
||||
#else
|
||||
printf(" Failed to allocate write_buffer array memory \n");
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Config:
|
||||
switch (group)
|
||||
{
|
||||
case A:
|
||||
adBms6830CreateConfiga(tIC, &ic[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
for (uint8_t data = 0; data < data_len; data++)
|
||||
{
|
||||
write_buffer[(cic * data_len) + data] = ic[cic].configa.tx_data[data];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case B:
|
||||
adBms6830CreateConfigb(tIC, &ic[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
for (uint8_t data = 0; data < data_len; data++)
|
||||
{
|
||||
write_buffer[(cic * data_len) + data] = ic[cic].configb.tx_data[data];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Comm:
|
||||
adBms6830CreateComm(tIC, &ic[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
for (uint8_t data = 0; data < data_len; data++)
|
||||
{
|
||||
write_buffer[(cic * data_len) + data] = ic[cic].com.tx_data[data];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Pwm:
|
||||
switch (group)
|
||||
{
|
||||
case A:
|
||||
adBms6830CreatePwma(tIC, &ic[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
for (uint8_t data = 0; data < data_len; data++)
|
||||
{
|
||||
write_buffer[(cic * data_len) + data] = ic[cic].pwma.tx_data[data];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case B:
|
||||
adBms6830CreatePwmb(tIC, &ic[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
for (uint8_t data = 0; data < data_len; data++)
|
||||
{
|
||||
write_buffer[(cic * data_len) + data] = ic[cic].pwmb.tx_data[data];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Clrflag:
|
||||
adBms6830CreateClrflagData(tIC, &ic[0]);
|
||||
for (uint8_t cic = 0; cic < tIC; cic++)
|
||||
{
|
||||
for (uint8_t data = 0; data < data_len; data++)
|
||||
{
|
||||
write_buffer[(cic * data_len) + data] = ic[cic].clrflag.tx_data[data];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
spiWriteData(tIC, cmd_arg, &write_buffer[0]);
|
||||
free(write_buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBmsPollAdc
|
||||
* @brief PLADC Command.
|
||||
*
|
||||
* @details Send poll adc command and retun adc conversion count.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* @param [in] tIC Total IC
|
||||
*
|
||||
* @param [in] tx_cmd Tx command byte
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
uint32_t adBmsPollAdc(uint8_t tx_cmd[2])
|
||||
{
|
||||
uint32_t conv_count = 0;
|
||||
uint8_t cmd[4];
|
||||
uint16_t cmd_pec;
|
||||
uint8_t read_data = 0x00;
|
||||
uint8_t SDO_Line = 0xFF;
|
||||
cmd[0] = tx_cmd[0];
|
||||
cmd[1] = tx_cmd[1];
|
||||
cmd_pec = Pec15_Calc(2, cmd);
|
||||
cmd[2] = (uint8_t)(cmd_pec >> 8);
|
||||
cmd[3] = (uint8_t)(cmd_pec);
|
||||
startTimer();
|
||||
adBmsCsLow();
|
||||
spiWriteBytes(4, &cmd[0]);
|
||||
do{
|
||||
spiReadBytes(1, &read_data);
|
||||
}while(!(read_data == SDO_Line));
|
||||
adBmsCsHigh();
|
||||
conv_count = getTimCount();
|
||||
stopTimer();
|
||||
return(conv_count);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBms6830_Adcv
|
||||
* @brief ADCV Command.
|
||||
*
|
||||
* @details Send adcv command to start cell voltage conversion.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* @param [in] RD Enum type Read bit
|
||||
*
|
||||
* @param [in] CONT Enum type continuous measurement bit
|
||||
*
|
||||
* @param [in] DCP Enum type discharge bit
|
||||
*
|
||||
* @param [in] RSTF Enum type Reset filter
|
||||
*
|
||||
* @param [in] OW_C_S Enum type open wire c/s
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void adBms6830_Adcv
|
||||
(
|
||||
RD rd,
|
||||
CONT cont,
|
||||
DCP dcp,
|
||||
RSTF rstf,
|
||||
OW_C_S owcs
|
||||
)
|
||||
{
|
||||
uint8_t cmd[2];
|
||||
cmd[0] = 0x02 + rd;
|
||||
cmd[1] = (cont<<7)+(dcp<<4)+(rstf<<2)+(owcs & 0x03) + 0x60;
|
||||
spiSendCmd(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBms6830_Adsv
|
||||
* @brief ADSV Command.
|
||||
*
|
||||
* @details Send s_adcv command to start cell voltage conversion.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* @param [in] cont Enum type continuous measurement bit
|
||||
*
|
||||
* @param [in] dcp Enum type discharge bit
|
||||
*
|
||||
* @param [in] owcs Enum type open wire c/s
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void adBms6830_Adsv
|
||||
(
|
||||
CONT cont,
|
||||
DCP dcp,
|
||||
OW_C_S owcs
|
||||
)
|
||||
{
|
||||
uint8_t cmd[2];
|
||||
cmd[0] = 0x01;
|
||||
cmd[1] = (cont<<7)+(dcp<<4)+(owcs &0x03) + 0x68;
|
||||
spiSendCmd(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBms6830_Adax
|
||||
* @brief ADAX Command.
|
||||
*
|
||||
* @details Send Aux command to starts auxiliary conversion.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* @param [in] owcs Enum type open wire c/s
|
||||
*
|
||||
* @param [in] pup Enum type Pull Down current during aux conversion
|
||||
*
|
||||
* @param [in] ch Enum type gpio Channel selection
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void adBms6830_Adax
|
||||
(
|
||||
OW_AUX owaux,
|
||||
PUP pup,
|
||||
CH ch
|
||||
)
|
||||
{
|
||||
uint8_t cmd[2];
|
||||
cmd[0] = 0x04 + owaux;
|
||||
cmd[1] = (pup << 7) + (((ch >>4)&0x01)<<6) + (ch & 0x0F) + 0x10;
|
||||
spiSendCmd(cmd);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Function: adBms6830_Adax2
|
||||
* @brief ADAX2 Command.
|
||||
*
|
||||
* @details Send Aux2 command to starts auxiliary conversion.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* @param [in] ch Enum type gpio Channel selection
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
void adBms6830_Adax2
|
||||
(
|
||||
CH ch
|
||||
)
|
||||
{
|
||||
uint8_t cmd[2];
|
||||
cmd[0] = 0x04;
|
||||
cmd[1] = (ch & 0x0F);
|
||||
spiSendCmd(cmd);
|
||||
}
|
||||
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
1583
Keil_Studio_Cloud/ADBMS6830/src/adBms6830ParseCreate.cpp
Normal file
1583
Keil_Studio_Cloud/ADBMS6830/src/adBms6830ParseCreate.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user