no-OS
ltc3337.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef __LTC3337_H__
40 #define __LTC3337_H__
41 
42 #include <stdint.h>
43 #include "no_os_util.h"
44 #include "no_os_i2c.h"
45 
46 #define LTC3337_I2C_ADDR 0x64 // b1100100[r/w] 0xC8, 0xC9
47 
48 #define LTC3337_MAX_TEMP_C 159 //Maximum temperature for alarms
49 #define LTC3337_MIN_TEMP_C -41 //Minimum temperature for alarms
50 #define LTC3337_MAX_PRESCALE 15 //Maximum prescaler value
51 
52 #define LTC3337_OVERFLOW_ALARM_MAX 0xFF //Max value for overflow alarm
53 
54 #define LTC3337_REG_A 0x01 //Prescaler Select, IRQ Clear, Shutdown, Alarm Thresh
55 
56 #define LTC3337_RA_PRESCALE_MSK NO_OS_GENMASK(3, 0)
57 #define LTC3337_RA_CLEAR_INT NO_OS_BIT(4)
58 #define LTC3337_RA_CNT_CHK NO_OS_BIT(5)
59 #define LTC3337_RA_SHTDN NO_OS_BIT(6)
60 #define LTC3337_RA_ADC_CONV NO_OS_BIT(7)
61 #define LTC3337_RA_ALARM_LVL_MSK NO_OS_GENMASK(15, 8)
62 
63 #define LTC3337_REG_B 0x02 //Accumulated Charge
64 
65 #define LTC3337_REG_C 0x03 //Status, Temperature
66 //Use the following definitions for derterming interrupt status
67 #define LTC3337_RC_OVERFLOW NO_OS_BIT(0)
68 #define LTC3337_RC_ALARM_TRIP NO_OS_BIT(1)
69 #define LTC3337_RC_ALARM_MIN NO_OS_BIT(2)
70 #define LTC3337_RC_ALARM_MAX NO_OS_BIT(3)
71 #define LTC3337_RC_ADC_READY NO_OS_BIT(4)
72 #define LTC3337_RC_IPK_PIN_MSK NO_OS_GENMASK(7, 5)
73 #define LTC3337_RC_DIE_TEMP_MSK NO_OS_GENMASK(15, 8)
74 
75 #define LTC3337_REG_D 0x04 //BAT_IN V, Ipeak On
76 #define LTC3337_REG_E 0x05 //BAT_IN V, Ipeak Off
77 #define LTC3337_REG_F 0x06 //BAT_OUT V, Ipeak On
78 #define LTC3337_REG_G 0x07 //BAT_OUT V, Ipeak Off
79 #define LTC3337_BATV_MSK NO_OS_GENMASK(11, 0)
80 
81 #define LTC3337_REG_H 0x08 //Temp Alarm Config
82 #define LTC3337_RH_HOT_ALARM_MSK NO_OS_GENMASK(15, 8)
83 #define LTC3337_RH_COLD_ALARM_MSK NO_OS_GENMASK(7, 0)
84 
85 #define LTC3337_VLSB_UV 1465 //1.465 mV = 1465 uV
86 #define LTC3337_TLSB_MC 784 //0.784 Deg C = 784 mC
87 #define LTC3337_TEMP_MIN_C -41
88 
89 #define LTC3337_NUM_IPEAKS 8 //3-bit iPeak Input
90 
91 //Scale values used in integer match to calulate A/nA-hrs from counters
92 #define LTC3337_NANO_AMP 1000000000
93 #define LTC3337_CALC_SCALE 10000
94 #define LTC3337_CALC_TO_WHOLE (LTC3337_NANO_AMP / LTC3337_CALC_SCALE)
95 
96 //Scale value for converting uV to mV
97 #define LTC3337_UV_TO_MV_SCALE 1000
98 
99 //Scale Value for converting mC to Deg C
100 #define LTC3337_MC_TO_C_SCALE 1000
101 
107 struct ltc3337_dev {
108  struct no_os_i2c_desc *i2c_desc; //I2C device
109  uint8_t ipeak_latched; //iPeak value read at init
110  uint16_t latched_reg_a; //Latched Register A value
111 };
112 
117  struct no_os_i2c_init_param i2c_init; //I2C Configuration
118  uint8_t prescale; //Initial device prescaler value
119 };
120 
125  uint32_t a_hr; //A-hrs
126  uint32_t na_hr; //nA-hrs
127 };
128 
137 };
138 
139 /* Initializes the device instance */
140 int ltc3337_init(struct ltc3337_dev** dev,
142 
143 /* Removes the device instance */
144 int ltc3337_remove( struct ltc3337_dev* dev);
145 
146 /* Sets the device prescaler value */
147 int ltc3337_set_prescaler(struct ltc3337_dev* dev, uint8_t prescale);
148 
149 /* Sets the temperature alarms, in Deg C */
150 int ltc3337_set_temperature_alarms_c(struct ltc3337_dev* dev, int16_t hot_alarm,
151  int16_t cold_alarm);
152 
153 /* Enabled / Disables the Coulomb counter shutdown */
154 int ltc3337_set_counter_shutdown(struct ltc3337_dev* dev, uint8_t shutdown_en);
155 
156 /* Sets the couloumb counter alarm threshold */
157 int ltc3337_set_counter_alarm(struct ltc3337_dev* dev, uint16_t reg_value,
158  uint8_t round_up);
159 
160 /* Manually sets the accumulated charge register */
161 int ltc3337_set_accumulated_charge(struct ltc3337_dev* dev, uint16_t reg_value,
162  uint8_t round_up);
163 
164 /* Gets the current value of the accumulated charge register */
166  struct charge_count_t* value,
167  uint16_t* raw_value);
168 
169 /* Reads the specified voltage source, in millivolts */
170 int ltc3337_get_voltage_mv(struct ltc3337_dev* dev,
171  enum ltc3337_voltage_src_t source,
172  uint32_t* value);
173 
174 /* Gets the current die temperature, in Deg C */
175 int ltc3337_get_temperature_c(struct ltc3337_dev* dev, int16_t* value);
176 
177 /* Gets the device interrupt status, and clears interrupts */
179  uint16_t* int_field,
180  int16_t* temp_c);
181 
182 /* Calculates a charge register value based on A-Hr units */
184  struct charge_count_t* charge_a,
185  uint16_t* reg_value);
186 
187 #endif
ltc3337_get_and_clear_interrupts
int ltc3337_get_and_clear_interrupts(struct ltc3337_dev *dev, uint16_t *int_field, int16_t *temp_c)
Definition: ltc3337.c:447
no_os_alloc.h
ltc3337_set_prescaler
int ltc3337_set_prescaler(struct ltc3337_dev *dev, uint8_t prescale)
Definition: ltc3337.c:277
LTC3337_RA_ALARM_LVL_MSK
#define LTC3337_RA_ALARM_LVL_MSK
Definition: ltc3337.h:61
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:165
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:58
ltc3337_voltage_src_t
ltc3337_voltage_src_t
Definition: ltc3337.h:132
ltc3337_init
int ltc3337_init(struct ltc3337_dev **device, struct ltc3337_init_param *init_param)
Definition: ltc3337.c:92
ipeak_entry_t::qlsb_na_hr
uint32_t qlsb_na_hr
Definition: ltc3337.c:51
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:119
LTC3337_NANO_AMP
#define LTC3337_NANO_AMP
Definition: ltc3337.h:92
LTC3337_BATV_MSK
#define LTC3337_BATV_MSK
Definition: ltc3337.h:79
ltc3337_get_temperature_c
int ltc3337_get_temperature_c(struct ltc3337_dev *dev, int16_t *value)
Definition: ltc3337.c:205
ltc3337_set_temperature_alarms_c
int ltc3337_set_temperature_alarms_c(struct ltc3337_dev *dev, int16_t hot_alarm, int16_t cold_alarm)
Definition: ltc3337.c:305
LTC3337_REG_B
#define LTC3337_REG_B
Definition: ltc3337.h:63
ltc3337_dev::ipeak_latched
uint8_t ipeak_latched
Definition: ltc3337.h:109
ltc3337_set_counter_alarm
int ltc3337_set_counter_alarm(struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
Definition: ltc3337.c:369
LTC3337_NUM_IPEAKS
#define LTC3337_NUM_IPEAKS
Definition: ltc3337.h:89
BAT_OUT_IPEAK_OFF
@ BAT_OUT_IPEAK_OFF
Definition: ltc3337.h:136
LTC3337_RH_COLD_ALARM_MSK
#define LTC3337_RH_COLD_ALARM_MSK
Definition: ltc3337.h:83
LTC3337_REG_H
#define LTC3337_REG_H
Definition: ltc3337.h:81
LTC3337_REG_E
#define LTC3337_REG_E
Definition: ltc3337.h:76
LTC3337_REG_G
#define LTC3337_REG_G
Definition: ltc3337.h:78
device
Definition: ad9361_util.h:75
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:60
LTC3337_RC_IPK_PIN_MSK
#define LTC3337_RC_IPK_PIN_MSK
Definition: ltc3337.h:72
ltc3337_init
int ltc3337_init(struct ltc3337_dev **dev, struct ltc3337_init_param *init_param)
Definition: ltc3337.c:92
LTC3337_OVERFLOW_ALARM_MAX
#define LTC3337_OVERFLOW_ALARM_MAX
Definition: ltc3337.h:52
ltc3337_set_counter_shutdown
int ltc3337_set_counter_shutdown(struct ltc3337_dev *dev, uint8_t shutdown_en)
Definition: ltc3337.c:333
LTC3337_REG_C
#define LTC3337_REG_C
Definition: ltc3337.h:65
LTC3337_VLSB_UV
#define LTC3337_VLSB_UV
Definition: ltc3337.h:85
no_os_field_prep
uint32_t no_os_field_prep(uint32_t mask, uint32_t val)
ltc3337_init_param
Definition: ltc3337.h:116
LTC3337_UV_TO_MV_SCALE
#define LTC3337_UV_TO_MV_SCALE
Definition: ltc3337.h:97
LTC3337_MC_TO_C_SCALE
#define LTC3337_MC_TO_C_SCALE
Definition: ltc3337.h:100
ltc3337_dev
Definition: ltc3337.h:107
ltc3337_set_accumulated_charge
int ltc3337_set_accumulated_charge(struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
Definition: ltc3337.c:413
ltc3337_get_accumulated_charge
int ltc3337_get_accumulated_charge(struct ltc3337_dev *dev, struct charge_count_t *value, uint16_t *raw_value)
Definition: ltc3337.c:233
ltc3337_set_counter_alarm
int ltc3337_set_counter_alarm(struct ltc3337_dev *dev, uint16_t counter_reg_val, uint8_t round_up)
Definition: ltc3337.c:369
LTC3337_REG_A
#define LTC3337_REG_A
Definition: ltc3337.h:54
LTC3337_TLSB_MC
#define LTC3337_TLSB_MC
Definition: ltc3337.h:86
ltc3337_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: ltc3337.h:108
LTC3337_MAX_TEMP_C
#define LTC3337_MAX_TEMP_C
Definition: ltc3337.h:48
ltc3337_set_counter_shutdown
int ltc3337_set_counter_shutdown(struct ltc3337_dev *dev, uint8_t shutdown_en)
Definition: ltc3337.c:333
LTC3337_RC_DIE_TEMP_MSK
#define LTC3337_RC_DIE_TEMP_MSK
Definition: ltc3337.h:73
charge_count_t
Definition: ltc3337.h:124
ltc3337_set_temperature_alarms_c
int ltc3337_set_temperature_alarms_c(struct ltc3337_dev *dev, int16_t hot_alarm, int16_t cold_alarm)
Definition: ltc3337.c:305
BAT_IN_IPEAK_OFF
@ BAT_IN_IPEAK_OFF
Definition: ltc3337.h:134
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:107
ltc3337_get_voltage_mv
int ltc3337_get_voltage_mv(struct ltc3337_dev *dev, enum ltc3337_voltage_src_t source, uint32_t *value)
Definition: ltc3337.c:159
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:196
ltc3337_set_accumulated_charge
int ltc3337_set_accumulated_charge(struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
Definition: ltc3337.c:413
ltc3337_get_accumulated_charge
int ltc3337_get_accumulated_charge(struct ltc3337_dev *dev, struct charge_count_t *value, uint16_t *raw_value)
Definition: ltc3337.c:233
ltc3337_remove
int ltc3337_remove(struct ltc3337_dev *dev)
Definition: ltc3337.c:138
no_os_i2c.h
Header file of I2C Interface.
LTC3337_MIN_TEMP_C
#define LTC3337_MIN_TEMP_C
Definition: ltc3337.h:49
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
LTC3337_RH_HOT_ALARM_MSK
#define LTC3337_RH_HOT_ALARM_MSK
Definition: ltc3337.h:82
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:75
no_os_get_unaligned_le16
uint16_t no_os_get_unaligned_le16(uint8_t *buf)
ltc3337_calculate_charge_register
int ltc3337_calculate_charge_register(struct ltc3337_dev *dev, struct charge_count_t *charge_a, uint16_t *reg_value)
Definition: ltc3337.c:485
BAT_OUT_IPEAK_ON
@ BAT_OUT_IPEAK_ON
Definition: ltc3337.h:135
charge_count_t::na_hr
uint32_t na_hr
Definition: ltc3337.h:126
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:70
ltc3337_get_temperature_c
int ltc3337_get_temperature_c(struct ltc3337_dev *dev, int16_t *value)
Definition: ltc3337.c:205
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:119
charge_count_t::a_hr
uint32_t a_hr
Definition: ltc3337.h:125
ltc3337_get_and_clear_interrupts
int ltc3337_get_and_clear_interrupts(struct ltc3337_dev *dev, uint16_t *int_field, int16_t *temp_c)
Definition: ltc3337.c:447
LTC3337_CALC_SCALE
#define LTC3337_CALC_SCALE
Definition: ltc3337.h:93
ltc3337_set_prescaler
int ltc3337_set_prescaler(struct ltc3337_dev *dev, uint8_t prescale)
Definition: ltc3337.c:277
LTC3337_RA_SHTDN
#define LTC3337_RA_SHTDN
Definition: ltc3337.h:59
ltc3337_init_param::i2c_init
struct no_os_i2c_init_param i2c_init
Definition: ltc3337.h:117
ltc3337.h
Header file for the LTC3337 Driver.
ipeak_entry_t
Definition: ltc3337.c:49
ipeak_entry_t::ipeak_ma
uint8_t ipeak_ma
Definition: ltc3337.c:50
ltc3337_get_voltage_mv
int ltc3337_get_voltage_mv(struct ltc3337_dev *dev, enum ltc3337_voltage_src_t source, uint32_t *value)
Definition: ltc3337.c:159
ltc3337_init_param::prescale
uint8_t prescale
Definition: ltc3337.h:118
ltc3337_remove
int ltc3337_remove(struct ltc3337_dev *dev)
Definition: ltc3337.c:138
ltc3337_dev::latched_reg_a
uint16_t latched_reg_a
Definition: ltc3337.h:110
no_os_util.h
Header file of utility functions.
LTC3337_RA_PRESCALE_MSK
#define LTC3337_RA_PRESCALE_MSK
Definition: ltc3337.h:56
LTC3337_REG_F
#define LTC3337_REG_F
Definition: ltc3337.h:77
LTC3337_REG_D
#define LTC3337_REG_D
Definition: ltc3337.h:75
ltc3337_calculate_charge_register
int ltc3337_calculate_charge_register(struct ltc3337_dev *dev, struct charge_count_t *charge_a, uint16_t *reg_value)
Definition: ltc3337.c:485
BAT_IN_IPEAK_ON
@ BAT_IN_IPEAK_ON
Definition: ltc3337.h:133
LTC3337_TEMP_MIN_C
#define LTC3337_TEMP_MIN_C
Definition: ltc3337.h:87
errno.h
Error macro definition for ARM Compiler.
NO_OS_DIV_ROUND_CLOSEST
#define NO_OS_DIV_ROUND_CLOSEST(x, y)
Definition: no_os_util.h:60
LTC3337_CALC_TO_WHOLE
#define LTC3337_CALC_TO_WHOLE
Definition: ltc3337.h:94
LTC3337_RA_CLEAR_INT
#define LTC3337_RA_CLEAR_INT
Definition: ltc3337.h:57