Hardware Abstraction Layer for FreeRTOS
|
Go to the documentation of this file.
26 const uint32_t numberOfSlaves;
30 const uint32_t allSlavesMask;
34 const uint32_t cellUnderVoltage;
38 const uint32_t cellOverVoltage;
58 struct ltc6811_slave **slaves;
62 struct spi_slave *spi;
66 bool (*callback)(
struct ltc6811 *ltc,
void *data);
71 #ifdef CONFIG_LTC6811_I2C
79 #ifdef CONFIG_LTC6811_I2C
82 struct ltc6811_slave {
91 struct ltc6811 *master;
95 struct adc_ltc6811 **adcs;
99 struct adc_ltc6811 **gpioADCS;
100 #ifdef CONFIG_LTC6811_I2C
104 struct i2c_ltc6811 *i2c;
108 #ifdef CONFIG_LTC6811_I2C
114 struct ltc6811_slave *ltc;
122 struct ltc6811_slave *ltc;
143 #define LTC_CMD_WRCFGA (0x1)
148 #define LTC_CMD_WRCFGA_0_GPIO_PULLUP(gpio) ((1 << gpio) << 3)
155 #define LTC_CMD_WRCFGA_0_REFON BIT(2)
161 #define LTC_CMD_WRCFGA_0_DTEN BIT(1)
167 #define LTC_CMD_WRCFGA_0_ADCOPT BIT(0)
172 #define LTC_CMD_WRCFGA_4_DCC(x) BIT(x)
181 #define LTC_CMD_WRCFGA_5_DCTO(DCTO) (DCTO << 4)
186 #define LTC_CMD_RDCFGA (0x2)
190 #define LTC_CMD_RDCVA (0x4)
194 #define LTC_CMD_RDCVB (0x6)
198 #define LTC_CMD_RDCVC (0x8)
202 #define LTC_CMD_RDCVD (0xA)
206 #define LTC_CMD_RDAUXA (0xC)
210 #define LTC_CMD_RDAUXB (0xE)
214 #define LTC_CMD_RDSTATA (0x10)
218 #define LTC_CMD_RDSTATB (0x12)
222 #define LTC_CMD_WRSCTRL (0x14)
226 #define LTC_CMD_WRPWM (0x20)
230 #define LTC_CMD_RDSCTRL (0x16)
234 #define LTC_CMD_RDPWM (0x22)
238 #define LTC_CMD_STSCTRL (0x19)
242 #define LTC_CMD_CLRSCTRL (0x18)
265 #define LTC_CMD_ADCV(CH, DCP, MD) (BIT(5) | BIT(6) | BIT(9) | (((CH) & 0x7) << 0) | (((DCP) & 0x1) << 4) | (((MD) & 0x3) << 7))
266 #define LTC_CMD_ADCV_NORM_DCP_ALL (0x370)
290 #define LTC_CMD_ADOW(CH, DCP, PUP, MD) (BIT(3) | BIT(5) | BIT(9) | (((CH) & 0x7) << 0) |(((PUP) & 0x1) << 6) ((DCP & 0x1) << 4) | (((MD) & 0x3) << 7))
291 #define LTC_CMD_ADOW_NORM_PUP_ALL (0x378)
292 #define LTC_CMD_ADOW_NORM_PDN_ALL (0x338)
309 #define LTC_CMD_CVST(ST, MD) (BIT(0) | BIT(1) | BIT(2) | BIT(9) | (((ST) & 0x3) << 5) | (((MD) & 0x3) << 7))
310 #define LTC_CMD_CVST_NORM_ST1 (0x327)
322 #define LTC_CMD_ADOL(DCP, MD) (BIT(0) | BIT(9) | (((DCP) & 0x1) << 4) | (((MD) & 0x3) << 7))
323 #define LTC_CMD_ADOL_NORM_DCP (0x311)
345 #define LTC_CMD_ADAX(CHG, MD) (BIT(5) | BIT(6) | BIT(10) | (((CHG) & 0x7) << 0) | (((MD & 0x3) << 7)))
346 #define LTC_CMD_ADAX_NORM_GPIO1 (0x561)
347 #define LTC_CMD_ADAX_NORM_GPIO2 (0x562)
369 #define LTC_CMD_ADAXD(CHG, MD) (BIT(10) | (((CHG) & 0x7) << 0) | (((MD & 0x3) << 7)))
370 #define LTC_CMD_ADAXD_NORM_GPIO1 (0x501)
371 #define LTC_CMD_ADAXD_NORM_GPIO2 (0x502)
388 #define LTC_CMD_AXST(ST, MD) (BIT(0) | BIT(1) | BIT(2) | BIT(10) | (((ST) & 0x3) << 5) | (((MD) & 0x3) << 7))
389 #define LTC_CMD_AXST_NORM_ST1 (0x527)
410 #define LTC_CMD_ADSTAT(CHST, MD) (BIT(3) | BIT(5) | BIT(6) | BIT(10) | (((CHST) & 0x7) << 0) | (((MD) & 0x3) << 7))
411 #define LTC_CMD_ADSTAT_NORM_ALL (0x568)
431 #define LTC_CMD_ADSTATD(CHST, MD) (BIT(3) | BIT(10) | (((CHST) & 0x7) << 0) | (((MD) & 0x3) << 7))
432 #define LTC_CMD_ADSTATD_NORM_ALL (0x508)
449 #define LTC_CMD_STATST(ST, MD) (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(10) | (((ST) & 0x3) << 5) | (((MD) & 0x3) << 7))
450 #define LTC_CMD_STATST_NORM_ST1 (0x52F)
462 #define LTC_CMD_ADCVAX(DCP, MD) (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(6) | BIT(10) | (((DCP) & 0x1) << 4) | (((MD) & 0x3) << 7))
463 #define LTC_CMD_ADCVAX_NORM_DCP (0x57F)
475 #define LTC_CMD_ADCVSC(DCP, MD) (BIT(0) | BIT(1) | BIT(2) | BIT(6) | BIT(10) | (((DCP) & 0x1) << 4) | (((MD) & 0x3) << 7))
476 #define LTC_CMD_ADCVSC_NORM_DCP (0x577)
480 #define LTC_CMD_CLRCELL (0x711)
484 #define LTC_CMD_CLRAUX (0x712)
488 #define LTC_CMD_CLRSTAT (0x713)
492 #define LTC_CMD_PLADC (0x714)
496 #define LTC_CMD_DIAGN (0x715)
500 #define LTC_CMD_WRCOMM (0x721)
504 #define LTC_CMD_RDCOMM (0x722)
508 #define LTC_CMD_STCOMM (0x723)
537 int32_t
ltc6811_connect(
struct ltc6811 *ltc,
struct spi *spi, uint8_t cs, uint16_t gpio, uint32_t baudrate);
585 #define LTC6811_ADC_DEV(masterid, id, adcID) \
586 struct adc_ltc6811 ltc6811_adc_##masterid##_##id##_##adcID = { \
587 ADC_INIT_DEV(ltc6811), \
588 .ltc = <c6811_slave_##masterid##_##id, \
590 ADC_ADDDEV(ltc6811, ltc6811_adc_##masterid##_##id##_##adcID)
593 extern const struct adc_ops ltc6811_adc_ops;
595 #define LTC6811_ADDDEV(id, numberofslave, _cellUnderVoltage, _cellOverVoltage) \
596 struct ltc6811_slave *ltc6811_slaves_##id[numberofslave]; \
597 struct ltc6811 ltc6811_dev_##id = { \
598 HAL_NAME("LTC6811 " #id) \
600 .numberOfSlaves = numberofslave, \
601 .allSlavesMask = ((1 << numberofslave) - 1), \
602 .selectSlaves = ((1 << numberofslave) - 1), \
603 .slaves = ltc6811_slaves_##id, \
604 .cellUnderVoltage = (((_cellUnderVoltage) / (16 * 100E-3)) - 1), \
605 .cellOverVoltage = ((_cellOverVoltage) / (16 * 100E-3)), \
607 HAL_ADD(ltc6811, ltc6811_dev_##id);
609 #define LTC6811_SLAVE_ADDDEV(masterid, id) \
610 extern struct adc_ltc6811 *ltc6811_adcs_##id[12]; \
611 struct ltc6811_slave ltc6811_slave_##masterid##_##id = { \
612 HAL_NAME("LTC6811 " #id) \
614 .master = <c6811_dev_##masterid,\
615 .adcs = ltc6811_adcs_##id, \
617 HAL_ADD(ltc6811, ltc6811_slave_##masterid##_##id); \
618 LTC6811_ADC_DEV(masterid, id, 0); \
619 LTC6811_ADC_DEV(masterid, id, 1); \
620 LTC6811_ADC_DEV(masterid, id, 2); \
621 LTC6811_ADC_DEV(masterid, id, 3); \
622 LTC6811_ADC_DEV(masterid, id, 4); \
623 LTC6811_ADC_DEV(masterid, id, 5); \
624 LTC6811_ADC_DEV(masterid, id, 6); \
625 LTC6811_ADC_DEV(masterid, id, 7); \
626 LTC6811_ADC_DEV(masterid, id, 8); \
627 LTC6811_ADC_DEV(masterid, id, 9); \
628 LTC6811_ADC_DEV(masterid, id, 10); \
629 LTC6811_ADC_DEV(masterid, id, 11); \
630 struct adc_ltc6811 *ltc6811_adcs_##id[12] = { \
631 <c6811_adc_##masterid##_##id##_0, \
632 <c6811_adc_##masterid##_##id##_1, \
633 <c6811_adc_##masterid##_##id##_2, \
634 <c6811_adc_##masterid##_##id##_3, \
635 <c6811_adc_##masterid##_##id##_4, \
636 <c6811_adc_##masterid##_##id##_5, \
637 <c6811_adc_##masterid##_##id##_6, \
638 <c6811_adc_##masterid##_##id##_7, \
639 <c6811_adc_##masterid##_##id##_8, \
640 <c6811_adc_##masterid##_##id##_9, \
641 <c6811_adc_##masterid##_##id##_10, \
642 <c6811_adc_##masterid##_##id##_11, \
645 #define LTC6811_ID(id) HAL_GET_ID(hal, ltc6811, ltc6811_dev_##id)
646 #define LTC6811_SLAVE_ID(masterid, id) HAL_GET_ID(hal, ltc6811, ltc6811_slave_##masterid##_##id)
647 #define LTC6811_ADC_ID(masterid, id, adcid) HAL_GET_ID(adc, ltc6811, ltc6811_adc_##masterid##_##id##_##adcid)
648 #define LTC6811_GET_ALL_ADCS(masterid, id, adcs) { \
649 (adcs)[0] = adc_init(LTC6811_ADC_ID(masterid, id, 0), 12,0); \
650 (adcs)[1] = adc_init(LTC6811_ADC_ID(masterid, id, 1), 12,0); \
651 (adcs)[2] = adc_init(LTC6811_ADC_ID(masterid, id, 2), 12,0); \
652 (adcs)[3] = adc_init(LTC6811_ADC_ID(masterid, id, 3), 12,0); \
653 (adcs)[4] = adc_init(LTC6811_ADC_ID(masterid, id, 4), 12,0); \
654 (adcs)[5] = adc_init(LTC6811_ADC_ID(masterid, id, 5), 12,0); \
655 (adcs)[6] = adc_init(LTC6811_ADC_ID(masterid, id, 6), 12,0); \
656 (adcs)[7] = adc_init(LTC6811_ADC_ID(masterid, id, 7), 12,0); \
657 (adcs)[8] = adc_init(LTC6811_ADC_ID(masterid, id, 8), 12,0); \
658 (adcs)[9] = adc_init(LTC6811_ADC_ID(masterid, id, 9), 12,0); \
659 (adcs)[10] = adc_init(LTC6811_ADC_ID(masterid, id, 10), 12,0); \
660 (adcs)[11] = adc_init(LTC6811_ADC_ID(masterid, id, 11), 12,0); \
struct ltc6811_slave * ltc6811_slave_init(uint32_t index)
int32_t ltc6811_startADC(struct ltc6811 *ltc)
int32_t ltc6811_stopADC(struct ltc6811 *ltc)
struct ltc6811 * ltc6811_init(uint32_t index)
int32_t ltc6811_read(struct ltc6811 *ltc, ltc_cmd_t cmd, uint8_t *data, uint32_t len)
#define OS_DEFINE_TASK(name, stackSize)
Definition: os.h:52
int32_t ltc6811_readRegister(struct ltc6811 *ltc, ltc_cmd_t cmd, uint8_t *registerContent)
int32_t ltc6811_writeRegister(struct ltc6811 *ltc, ltc_cmd_t cmd, uint8_t *newData, uint8_t *oldData)
int32_t ltc6811_setADCCallback(struct ltc6811 *ltc, bool(*callback)(struct ltc6811 *ltc, void *data), void *data)
uint16_t ltc6811_calcPEC(uint8_t *data, uint8_t len)
int16_t ltc_cmd_t
Definition: ltc6811.h:513
int32_t ltc6811_connect(struct ltc6811 *ltc, struct spi *spi, uint8_t cs, uint16_t gpio, uint32_t baudrate)
int32_t ltc6811_write(struct ltc6811 *ltc, ltc_cmd_t cmd, uint8_t *data, uint32_t len)