no-OS
Classes | Functions
ltc3337.c File Reference

Implementation file for the LTC3337 Driver. More...

#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include "ltc3337.h"
#include "no_os_alloc.h"
Include dependency graph for ltc3337.c:

Classes

struct  ipeak_entry_t
 

Functions

int ltc3337_init (struct ltc3337_dev **device, struct ltc3337_init_param *init_param)
 
int ltc3337_remove (struct ltc3337_dev *dev)
 
int ltc3337_get_voltage_mv (struct ltc3337_dev *dev, enum ltc3337_voltage_src_t source, uint32_t *value)
 
int ltc3337_get_temperature_c (struct ltc3337_dev *dev, int16_t *value)
 
int ltc3337_get_accumulated_charge (struct ltc3337_dev *dev, struct charge_count_t *value, uint16_t *raw_value)
 
int ltc3337_set_prescaler (struct ltc3337_dev *dev, uint8_t prescale)
 
int ltc3337_set_temperature_alarms_c (struct ltc3337_dev *dev, int16_t hot_alarm, int16_t cold_alarm)
 
int ltc3337_set_counter_shutdown (struct ltc3337_dev *dev, uint8_t shutdown_en)
 
int ltc3337_set_counter_alarm (struct ltc3337_dev *dev, uint16_t counter_reg_val, uint8_t round_up)
 
int ltc3337_set_accumulated_charge (struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
 
int ltc3337_get_and_clear_interrupts (struct ltc3337_dev *dev, uint16_t *int_field, int16_t *temp_c)
 
int ltc3337_calculate_charge_register (struct ltc3337_dev *dev, struct charge_count_t *charge_a, uint16_t *reg_value)
 

Detailed Description

Implementation file for the LTC3337 Driver.

Author
Brent Kowal (brent.nosp@m..kow.nosp@m.al@an.nosp@m.alog.nosp@m..com)

Copyright 2023(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ ltc3337_calculate_charge_register()

int ltc3337_calculate_charge_register ( struct ltc3337_dev dev,
struct charge_count_t charge_a,
uint16_t *  reg_value 
)

Gets a register value equivalent of the provided charge in A/nA-hrs to be used in configuring the charge alarms, and resetting the charge register. This function does not access the device over the bus, but utilizes the latched prescaled and IPK values to perform the calculation

Parameters
dev- Device to utilize configuration from
charge_a- Pointer to the charge values in A/nA-hrs
reg_value- Pointer to store the output register value
Returns
0 on success, Non-0 on error

◆ ltc3337_get_accumulated_charge()

int ltc3337_get_accumulated_charge ( struct ltc3337_dev dev,
struct charge_count_t value,
uint16_t *  raw_value 
)

Gets the current value of the accumulated charge register. This function can return the raw value and/or the calculated value based on the prescaler and IPK settings of dev.

Parameters
dev- Device to read from
value- Pointer to calculated storage location, or NULL
raw_value- Pointer to raw storage location, or NULL
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_get_and_clear_interrupts()

int ltc3337_get_and_clear_interrupts ( struct ltc3337_dev dev,
uint16_t *  int_field,
int16_t *  temp_c 
)

Reads and clears the interrupt status of the chip. Since the die temp is also provided in the interrupt register, temperature is optionally provided as well. This allows a user to poll interrupt status and not accidentally clear interrupts by reading temperature inbetween interrupt polls. Use the LTC3337_RC_ macros to determine status of each interrupt in int_field

Parameters
dev- Device to read from
int_field- Interrupt status bits
temp_c- Location to store temperature (or NULL)
Returns
0 on success, Non-0 on error

◆ ltc3337_get_temperature_c()

int ltc3337_get_temperature_c ( struct ltc3337_dev dev,
int16_t *  value 
)

Gets the current die temperature

Parameters
dev- Device to read from
value- Location to store calculated value, in Deg C
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_get_voltage_mv()

int ltc3337_get_voltage_mv ( struct ltc3337_dev dev,
enum ltc3337_voltage_src_t  source,
uint32_t *  value 
)

Gets the current value of the requested voltage monitor in mV.

Parameters
dev- Device to read from
source- Which voltage source to read
value- Location to store calcualted value, in mV
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_init()

int ltc3337_init ( struct ltc3337_dev **  device,
struct ltc3337_init_param init_param 
)

Initializes the driver instance. Assigns the I2C bus and reads the IPK pins. The prescaler is set to the user value, and the accumulated charge alarm is defaulted to maximum 0xFF

Parameters
device- Pointer to the device instance
init_param- Initialization parameters
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_remove()

int ltc3337_remove ( struct ltc3337_dev dev)

Uninitializes the device instance and frees up any allocated memory

Parameters
dev- Device to remove
Returns
0 on success, non-0 on error
Here is the caller graph for this function:

◆ ltc3337_set_accumulated_charge()

int ltc3337_set_accumulated_charge ( struct ltc3337_dev dev,
uint16_t  reg_value,
uint8_t  round_up 
)

Sets the level for the coulomb counter accumulated charge register. The input value is the raw register value, and can be calculated using LTC3337_CalculateChargeRegister or manually by hand. IMPORTANT: Only the upper 8-bits of the value are utilized. Use the roundUp flag to have the driver optionally round up to the next valid bit

Parameters
dev- Device to configure
reg_value- Register value, as if all 16-bits were utilized
round_up- 1 -Have the driver round up to next usable alarm bit
Returns
0 on success, Non-0 on error

◆ ltc3337_set_counter_alarm()

int ltc3337_set_counter_alarm ( struct ltc3337_dev dev,
uint16_t  counter_reg_val,
uint8_t  round_up 
)

Sets the alarm level for the coulomb counter alarm. The input value is the raw register value, and can be calculated using LTC3337_CalculateChargeRegister or manually by hand. IMPORTANT: Only the upper 8-bits of the value are utilized. Use the roundUp flag to have the driver optionally round up to the next valid bit

Parameters
dev- Device to configure
counter_reg_val- Register value, as if all 16-bits were utilized
round_up- 1 -Have the driver round up to next usable alarm bit
Returns
0 on success, Non-0 on error

◆ ltc3337_set_counter_shutdown()

int ltc3337_set_counter_shutdown ( struct ltc3337_dev dev,
uint8_t  shutdown_en 
)

Sets the state of the coulomb counter shutdown function

Parameters
dev- Device to configure
shutdown_en- 1 - Enable shutdown, 0 - Coulomb counter running
Returns
0 on success, Non-0 on error

◆ ltc3337_set_prescaler()

int ltc3337_set_prescaler ( struct ltc3337_dev dev,
uint8_t  prescale 
)

Sets the prescaler value of the device. IMPORTANT: Changing the prescaler does not affect the value of the accumulated charge register. If the prescaler is set sometime following the initial runtime setup, after charge has been accumulated, the acccumulated charge register should be set according to the current value shifted by the difference in original and current prescaler. This driver does not automatically perform that action. IMPORTANT: Changing the prescaler does not alter the configuration of alarm. That may need to be changed if configured prior to the prescaler

Parameters
dev- Pointer to the device instance
prescale- Prescaler value
Returns
0 on success, Non-0 on error

◆ ltc3337_set_temperature_alarms_c()

int ltc3337_set_temperature_alarms_c ( struct ltc3337_dev dev,
int16_t  hot_alarm,
int16_t  cold_alarm 
)

Set the alarm thresholds for hot and cold temperatures

Parameters
dev- Device to configure
hot_alarm- Hot alarm threshold, in Degrees C
cold_alarm- Cold alarm threshold, in Degrees C
Returns
0 on success, Non-0 on error