no-OS
Functions
max14001.c File Reference

Implementation of max14001.c. More...

#include <stdlib.h>
#include "max14001.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
Include dependency graph for max14001.c:

Functions

int max14001_read (struct max14001_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
 Read from device. More...
 
int max14001_write (struct max14001_dev *dev, uint8_t reg_addr, uint16_t reg_data)
 Write to device. More...
 
int max14001_reg_update (struct max14001_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data)
 SPI write to device using a mask. More...
 
int max14001_write_config_verify (struct max14001_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data)
 Write to config registers then to corresponding verification register. More...
 
int max14001_init (struct max14001_dev **device, struct max14001_init_param init_param)
 Initialize the device. More...
 
int max14001_init_config (struct max14001_dev *dev)
 Initialize the configurations of device. More...
 
int max14001_wen (struct max14001_dev *dev, bool enable)
 Enable write to registers. More...
 
int max14001_full_reset (struct max14001_dev *dev)
 Full reset, same effect as power on reset. More...
 
int max14001_reg_reset (struct max14001_dev *dev)
 Software reset. Restores all registers to their POR value. More...
 
int max14001_inpls_reset (struct max14001_dev *dev)
 Trigger an inrush current pulse. More...
 
int max14001_emv_config (struct max14001_dev *dev, bool mode)
 Enable MV fault. More...
 
int max14001_efet_config (struct max14001_dev *dev, bool mode)
 Enable FET fault. More...
 
int max14001_ecrcf_config (struct max14001_dev *dev, bool mode)
 Enable CRCF fault. More...
 
int max14001_ecrcl_config (struct max14001_dev *dev, bool mode)
 Enable CRCL fault. More...
 
int max14001_ecom_config (struct max14001_dev *dev, bool mode)
 Enable COM fault. More...
 
int max14001_espi_config (struct max14001_dev *dev, bool mode)
 Enable SPI fault. More...
 
int max14001_einrd_config (struct max14001_dev *dev, bool mode)
 Enable INRD fault. More...
 
int max14001_eadc_config (struct max14001_dev *dev, bool mode)
 Enable ADC fault. More...
 
int max14001_dyen_config (struct max14001_dev *dev, bool mode)
 Enable dynamic FAULT signal. More...
 
int max14001_fast_config (struct max14001_dev *dev, bool fast)
 Enable/Disable fast inrush mode. More...
 
int max14001_iraw_config (struct max14001_dev *dev, bool raw_data)
 Selects Inrush comparator input multiplexer. More...
 
int max14001_ena_config (struct max14001_dev *dev, bool enable)
 Enable/Disable field-side current sink. More...
 
int max14001_exrf_config (struct max14001_dev *dev, bool mode)
 Selects the voltage reference source for the ADC. More...
 
int max14001_exti_config (struct max14001_dev *dev, bool mode)
 Current source connection. More...
 
int max14001_tinr_config (struct max14001_dev *dev, int mode)
 Configure 4-bit inrush time. More...
 
int max14001_iinr_config (struct max14001_dev *dev, int mode)
 Configure 4-bit inrush current. More...
 
int max14001_du_config (struct max14001_dev *dev, enum max14001_du mode)
 Set maximum duty cycle for inrush current over the last 10 seconds. More...
 
int max14001_ibias_config (struct max14001_dev *dev, float mode)
 Configure 4-bit bias current. More...
 
int max14001_ft_config (struct max14001_dev *dev, enum max14001_ft mode)
 Set number of readings averaged in the ADC filter. More...
 
int max14001_get_data_raw (struct max14001_dev *dev, uint16_t *data)
 Get adc data. More...
 
int max14001_get_data_filtered (struct max14001_dev *dev, uint16_t *data)
 Get filtered adc data. More...
 
int max14001_remove (struct max14001_dev *dev)
 Free the resources allocated by max14001_init(). More...
 

Detailed Description

Implementation of max14001.c.

Author
NAlteza (natha.nosp@m.niel.nosp@m..alte.nosp@m.za@a.nosp@m.nalog.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

◆ max14001_du_config()

int max14001_du_config ( struct max14001_dev dev,
enum max14001_du  mode 
)

Set maximum duty cycle for inrush current over the last 10 seconds.

Parameters
dev- The device structure.
mode- Duty Cycle Accepted values: DUTY_OFF DUTY_1P6 DUTY_3P1 DUTY_6P3
Returns
0 in case of success, fail otherwise.

◆ max14001_dyen_config()

int max14001_dyen_config ( struct max14001_dev dev,
bool  mode 
)

Enable dynamic FAULT signal.

Parameters
dev- The device structure.
mode- true for dynamic FAULT signal false for latched FAULT signal (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_eadc_config()

int max14001_eadc_config ( struct max14001_dev dev,
bool  mode 
)

Enable ADC fault.

Parameters
dev- The device structure.
mode- true to allow ADC error to assert FAULT false to prevent ADC error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_ecom_config()

int max14001_ecom_config ( struct max14001_dev dev,
bool  mode 
)

Enable COM fault.

Parameters
dev- The device structure.
mode- true to allow COM error to assert FAULT false to prevent COM error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_ecrcf_config()

int max14001_ecrcf_config ( struct max14001_dev dev,
bool  mode 
)

Enable CRCF fault.

Parameters
dev- The device structure.
mode- true to allow CRCF error to assert FAULT false to prevent CRCF error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_ecrcl_config()

int max14001_ecrcl_config ( struct max14001_dev dev,
bool  mode 
)

Enable CRCL fault.

Parameters
dev- The device structure.
mode- true to allow CRCL error to assert FAULT false to prevent CRCL error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_efet_config()

int max14001_efet_config ( struct max14001_dev dev,
bool  mode 
)

Enable FET fault.

Parameters
dev- The device structure.
mode- true to allow FET error to assert FAULT false to prevent FET error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_einrd_config()

int max14001_einrd_config ( struct max14001_dev dev,
bool  mode 
)

Enable INRD fault.

Parameters
dev- The device structure.
mode- true to allow INRD error to assert FAULT false to prevent INRD error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_emv_config()

int max14001_emv_config ( struct max14001_dev dev,
bool  mode 
)

Enable MV fault.

Parameters
dev- The device structure.
mode- true to allow MV error to assert FAULT false to prevent MV error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function:

◆ max14001_ena_config()

int max14001_ena_config ( struct max14001_dev dev,
bool  enable 
)

Enable/Disable field-side current sink.

Parameters
dev- The device structure.
enable- true to enable field-side current sink false to prevent field-side current sink (default)
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function:

◆ max14001_espi_config()

int max14001_espi_config ( struct max14001_dev dev,
bool  mode 
)

Enable SPI fault.

Parameters
dev- The device structure.
mode- true to allow SPI error to assert FAULT false to prevent SPI error to assert FAULT (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_exrf_config()

int max14001_exrf_config ( struct max14001_dev dev,
bool  mode 
)

Selects the voltage reference source for the ADC.

Parameters
dev- The device structure.
mode- 0 for external voltage reference enabled 1 for internal voltage reference enabled (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_exti_config()

int max14001_exti_config ( struct max14001_dev dev,
bool  mode 
)

Current source connection.

Parameters
dev- The device structure.
mode- 0 for current source on and connected to the REFIN pin 1 for current source off (default)
Returns
0 in case of success, fail otherwise.

◆ max14001_fast_config()

int max14001_fast_config ( struct max14001_dev dev,
bool  fast 
)

Enable/Disable fast inrush mode.

Parameters
dev- The device structure.
fast- true for FAST inrush mode (default) false for ADC controlled
Returns
0 in case of success, fail otherwise.

◆ max14001_ft_config()

int max14001_ft_config ( struct max14001_dev dev,
enum max14001_ft  mode 
)

Set number of readings averaged in the ADC filter.

Parameters
dev- The device structure.
mode- Average readings Accepted values: FILTER_OFF AVERAGE_2_READINGS AVERAGE_4_READINGS AVERAGE_8_READINGS
Returns
0 in case of success, fail otherwise.

◆ max14001_full_reset()

int max14001_full_reset ( struct max14001_dev dev)

Full reset, same effect as power on reset.

Parameters
dev- The device structure.
Returns
0 in case of success, fail otherwise.

◆ max14001_get_data_filtered()

int max14001_get_data_filtered ( struct max14001_dev dev,
uint16_t *  data 
)

Get filtered adc data.

Parameters
dev- Device handler.
data- Pointer to filtered adc value.
Returns
0 in case of success, negative error code otherwise.

◆ max14001_get_data_raw()

int max14001_get_data_raw ( struct max14001_dev dev,
uint16_t *  data 
)

Get adc data.

Parameters
dev- Device handler.
data- Pointer to raw adc value.
Returns
0 in case of success, negative error code otherwise.

◆ max14001_ibias_config()

int max14001_ibias_config ( struct max14001_dev dev,
float  mode 
)

Configure 4-bit bias current.

Parameters
dev- The device structure.
mode- 50uA to 3.75mA in 0.25mA increments. Inputs are clamped and rounded within limits.
Returns
0 in case of success, fail otherwise.

◆ max14001_iinr_config()

int max14001_iinr_config ( struct max14001_dev dev,
int  mode 
)

Configure 4-bit inrush current.

Parameters
dev- The device structure.
mode- 50uA to 105mA in 7mA increments. Inputs are clamped and rounded within limits.
Returns
0 in case of success, fail otherwise.

◆ max14001_init()

int max14001_init ( struct max14001_dev **  device,
struct max14001_init_param  init_param 
)

Initialize the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, fail otherwise.

◆ max14001_init_config()

int max14001_init_config ( struct max14001_dev dev)

Initialize the configurations of device.

Parameters
dev- The device structure.
Returns
0 in case of success, fail otherwise.

◆ max14001_inpls_reset()

int max14001_inpls_reset ( struct max14001_dev dev)

Trigger an inrush current pulse.

Parameters
dev- The device structure.
Returns
0 in case of success, fail otherwise.

◆ max14001_iraw_config()

int max14001_iraw_config ( struct max14001_dev dev,
bool  raw_data 
)

Selects Inrush comparator input multiplexer.

Parameters
dev- The device structure.
raw_data- 0 to connect comparator to ADC register(default) 1 to connect comparator to FADC register
Returns
0 in case of success, fail otherwise.

◆ max14001_read()

int max14001_read ( struct max14001_dev dev,
uint8_t  reg_addr,
uint16_t *  reg_data 
)

Read from device.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function:

◆ max14001_reg_reset()

int max14001_reg_reset ( struct max14001_dev dev)

Software reset. Restores all registers to their POR value.

Parameters
dev- The device structure.
Returns
0 in case of success, fail otherwise.

◆ max14001_reg_update()

int max14001_reg_update ( struct max14001_dev dev,
uint8_t  reg_addr,
uint16_t  mask,
uint16_t  data 
)

SPI write to device using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The register data.
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function:

◆ max14001_remove()

int max14001_remove ( struct max14001_dev dev)

Free the resources allocated by max14001_init().

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ max14001_tinr_config()

int max14001_tinr_config ( struct max14001_dev dev,
int  mode 
)

Configure 4-bit inrush time.

Parameters
dev- The device structure.
mode- 0 to 120ms in 8ms increments. Inputs are clamped and rounded within limits.
Returns
0 in case of success, fail otherwise.

◆ max14001_wen()

int max14001_wen ( struct max14001_dev dev,
bool  enable 
)

Enable write to registers.

Parameters
dev- The device structure.
enable- true to write enable false to write disable
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function:

◆ max14001_write()

int max14001_write ( struct max14001_dev dev,
uint8_t  reg_addr,
uint16_t  reg_data 
)

Write to device.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function:

◆ max14001_write_config_verify()

int max14001_write_config_verify ( struct max14001_dev dev,
uint8_t  reg_addr,
uint16_t  mask,
uint16_t  data 
)

Write to config registers then to corresponding verification register.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The register data.
Returns
0 in case of success, fail otherwise.
Here is the caller graph for this function: