no-OS
Loading...
Searching...
No Matches
ltc2983.c File Reference

Implementation of LTC2983 Driver. More...

#include <errno.h>
#include "ltc2983.h"
#include "no_os_alloc.h"
#include "no_os_delay.h"
#include "no_os_print_log.h"
Include dependency graph for ltc2983.c:

Functions

int ltc2983_init (struct ltc2983_desc **device, struct ltc2983_init_param *init_param)
 Device and comm init function.
 
int ltc2983_remove (struct ltc2983_desc *device)
 Remove resources allocated by the init function.
 
int ltc2983_reg_read (struct ltc2983_desc *device, uint16_t reg_addr, uint8_t *val)
 Read raw register value.
 
int ltc2983_reg_write (struct ltc2983_desc *device, uint16_t reg_addr, uint8_t val)
 Write raw register value.
 
int ltc2983_reg_update_bits (struct ltc2983_desc *device, uint16_t reg_addr, uint8_t mask, uint8_t val)
 Update register value.
 
int ltc2983_setup (struct ltc2983_desc *device)
 Device setup.
 
int ltc2983_chan_read_resistance (struct ltc2983_desc *device, const int chan, uint32_t *val)
 Read raw resistance from the ADT7604 resistance result bank (0x0060)
 
int ltc2983_chan_read (struct ltc2983_desc *device, const int chan, int *val)
 Read channel data / temperature.
 
int ltc2983_chan_read_raw (struct ltc2983_desc *device, const int chan, uint32_t *val)
 Read raw channel data / temperature.
 
int ltc2983_chan_read_scale (struct ltc2983_desc *device, const int chan, uint32_t *val, uint32_t *val2)
 Set scale of raw channel data / temperature.
 
int ltc2983_chan_read_scale_resistance (struct ltc2983_desc *device, const int chan, uint32_t *val, uint32_t *val2)
 Get resistance scale for copper trace or leak detector channels.
 
int ltc2983_thermocouple_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 Channel assignment for thermocouple sensors.
 
int ltc2983_rtd_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 Channel assignment for RTD sensors.
 
int ltc2983_thermistor_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 Channel assignment for thermistor sensors.
 
int ltc2983_diode_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 Channel assignment for diode sensors.
 
int ltc2983_r_sense_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 Channel assignment for rsense.
 
int ltc2983_adc_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 Channel assignment for direct ADC.
 
int ltc2983_temp_assign_chan (struct ltc2983_desc *device, const struct ltc2983_sensor *sensor)
 
int ltc2983_thermocouple_fault_handler (const uint32_t result)
 Fault handling of thermocouple sensors.
 
int ltc2983_common_fault_handler (const uint32_t result)
 Fault handling of sensors other than thermocouple.
 

Detailed Description

Implementation of LTC2983 Driver.

Author
John Erasmus Mari Geronimo (johne.nosp@m.rasm.nosp@m.usmar.nosp@m.i.ge.nosp@m.ronim.nosp@m.o@an.nosp@m.alog..nosp@m.com)

Copyright 2024(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ltc2983_adc_assign_chan()

int ltc2983_adc_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for direct ADC.

Parameters
device- LTC2983 descriptor
sensor- LTC2983 common sensor descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_chan_read()

int ltc2983_chan_read ( struct ltc2983_desc * device,
const int chan,
int * val )

Read channel data / temperature.

Parameters
device- LTC2983 descriptor
chan- channel number
val- channel data / temperature
Returns
0 in case of success, errno errors otherwise

For copper trace (LTC2983_RTD_CUSTOM) and leak detector (LTC2983_THERMISTOR_CUSTOM) channels, use ltc2983_chan_read_resistance() to read raw resistance from the ADT7604 resistance bank. The IIO resistance scales (1/1024000 Ohm/LSB for copper trace, 1/1024 Ohm/LSB for leak detector) cause precision loss in integer arithmetic.

◆ ltc2983_chan_read_raw()

int ltc2983_chan_read_raw ( struct ltc2983_desc * device,
const int chan,
uint32_t * val )

Read raw channel data / temperature.

Parameters
device- LTC2983 descriptor
chan- channel number
val- raw channel data / temperature
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_chan_read_resistance()

int ltc2983_chan_read_resistance ( struct ltc2983_desc * device,
const int chan,
uint32_t * val )

Read raw resistance from the ADT7604 resistance result bank (0x0060)

Parameters
device- LTC2983 descriptor
chan- channel number (1-indexed)
val- raw resistance value (bits[30:0], unsigned)
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_chan_read_scale()

int ltc2983_chan_read_scale ( struct ltc2983_desc * device,
const int chan,
uint32_t * val,
uint32_t * val2 )

Set scale of raw channel data / temperature.

Parameters
device- LTC2983 descriptor
chan- channel number
val- scale numerator
val2- scale denominator
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_chan_read_scale_resistance()

int ltc2983_chan_read_scale_resistance ( struct ltc2983_desc * device,
const int chan,
uint32_t * val,
uint32_t * val2 )

Get resistance scale for copper trace or leak detector channels.

Parameters
device- LTC2983 descriptor
chan- channel number
val- scale numerator
val2- scale denominator
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_common_fault_handler()

int ltc2983_common_fault_handler ( const uint32_t result)

Fault handling of sensors other than thermocouple.

Parameters
result- result captured that contains the faults
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_diode_assign_chan()

int ltc2983_diode_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for diode sensors.

Parameters
device- LTC2983 descriptor
sensor- LTC2983 common sensor descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_init()

int ltc2983_init ( struct ltc2983_desc ** device,
struct ltc2983_init_param * init_param )

Device and comm init function.

Parameters
device- LTC2983 descriptor to be initialized
init_param- Init parameter for descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_r_sense_assign_chan()

int ltc2983_r_sense_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for rsense.

Parameters
device- LTC2983 descriptor
sensor- LTC2983 common sensor descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_reg_read()

int ltc2983_reg_read ( struct ltc2983_desc * device,
uint16_t reg_addr,
uint8_t * val )

Read raw register value.

Parameters
device- LTC2983 descriptor
reg_addr- register address
val- register value
Returns
0 in case of success, negative error code otherwise

◆ ltc2983_reg_update_bits()

int ltc2983_reg_update_bits ( struct ltc2983_desc * device,
uint16_t reg_addr,
uint8_t mask,
uint8_t val )

Update register value.

Parameters
device- LTC2983 descriptor
reg_addr- register address
mask- Mask for specific register bits to be updated
val- register value to be written
Returns
0 in case of success, negative error code otherwise

◆ ltc2983_reg_write()

int ltc2983_reg_write ( struct ltc2983_desc * device,
uint16_t reg_addr,
uint8_t val )

Write raw register value.

Parameters
device- LTC2983 descriptor
reg_addr- register address
val- register value
Returns
0 in case of success, negative error code otherwise

◆ ltc2983_remove()

int ltc2983_remove ( struct ltc2983_desc * device)

Remove resources allocated by the init function.

Parameters
device- LTC2983 descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_rtd_assign_chan()

int ltc2983_rtd_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for RTD sensors.

Parameters
device- LTC2983 descriptor
sensor- LTC2983 common sensor descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_setup()

int ltc2983_setup ( struct ltc2983_desc * device)

Device setup.

Parameters
device- LTC2983 descriptor
Returns
0 in case of success, errno errors otherwise

make sure the device is up: start bit (7) is 0 and done bit (6) is 1

◆ ltc2983_temp_assign_chan()

int ltc2983_temp_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for analog temp sensor

◆ ltc2983_thermistor_assign_chan()

int ltc2983_thermistor_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for thermistor sensors.

Parameters
device- LTC2983 descriptor
sensor- LTC2983 common sensor descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_thermocouple_assign_chan()

int ltc2983_thermocouple_assign_chan ( struct ltc2983_desc * device,
const struct ltc2983_sensor * sensor )

Channel assignment for thermocouple sensors.

Parameters
device- LTC2983 descriptor
sensor- LTC2983 common sensor descriptor
Returns
0 in case of success, errno errors otherwise

◆ ltc2983_thermocouple_fault_handler()

int ltc2983_thermocouple_fault_handler ( const uint32_t result)

Fault handling of thermocouple sensors.

Parameters
result- result captured that contains the faults
Returns
0 in case of success, errno errors otherwise