no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
max17851.c File Reference

Source file of the MAX17851 driver. More...

#include "max17851.h"
#include "no_os_alloc.h"
#include "no_os_error.h"
Include dependency graph for max17851.c:

Functions

int max17851_send_command (struct max17851_desc *desc, enum max17851_command command, bool enable)
 Send specific device command over SPI.
 
int max17851_read_msg (struct max17851_desc *desc, uint8_t *data, uint8_t len)
 Read message over UART from the MAX17851.
 
int max17851_write_msg (struct max17851_desc *desc, const uint8_t *data, uint8_t len)
 Write message over UART using MAX17851.
 
int max17851_config_gen2 (struct max17851_desc *desc, enum max17851_config_gen2_sel sel, bool enable)
 Configure general settings for MAX17851.
 
int max17851_sel_alrtpckt_time (struct max17851_desc *desc, enum max17851_alrtpckt_time time)
 Set timing for Alert Packets/Keep-Alive Packets.
 
int max17851_select_queue (struct max17851_desc *desc, enum max17851_queue_sel sel)
 Select queue for transmitting/loading TX buffer for UART.
 
int max17851_clear_buff (struct max17851_desc *desc, bool tx_buf)
 Clear RX/TX buffer inside the MAX17851 memory.
 
int max17851_get_alert (struct max17851_desc *desc, enum max17851_alert alert, bool *enable)
 Read specific alert state.
 
int max17851_set_alert (struct max17851_desc *desc, enum max17851_alert alert, bool enable)
 Enable/Disable specific alert.
 
int max17851_set_alert_debounce (struct max17851_desc *desc, enum max17851_status_debounce dbnc)
 Select the number of unmasked consecutive Alert Packet status alerts, which must happen prior to taking action in either Safe Minotring or Sleep Mode.
 
int max17851_set_safemon_dly (struct max17851_desc *desc, enum max17851_safemon_dly delay)
 Select Safe Monitoring Mode Scan Delay.
 
int max17851_set_safemon_gpio (struct max17851_desc *desc, enum max17851_safemon_gpio gpio, bool enable)
 Select which GPIO pins to be configured as SAFEMON output.
 
int max17851_set_comm (struct max17851_desc *desc, enum max17851_comm_try_count count, enum max17851_comm_timeout_delay delay)
 Set communication retry count and timeout delay.
 
int max17851_reg_read (struct max17851_desc *desc, uint8_t reg, uint8_t *data)
 MAX17851 register read function.
 
int max17851_reg_write (struct max17851_desc *desc, uint8_t reg, uint8_t data)
 MAX17851 register write function.
 
int max17851_reg_update (struct max17851_desc *desc, uint8_t reg, uint8_t mask, uint8_t data)
 MAX17851 register update function.
 
int max17851_init (struct max17851_desc **desc, struct max17851_init_param *init_param)
 MAX17851 device initialization function.
 
int max17851_remove (struct max17851_desc *desc)
 Deallocate any resources used at the initialization function.
 

Variables

const struct no_os_uart_platform_ops max17851_uart_ops
 MAX17851 platform specific UART platform ops structure.
 

Detailed Description

Source file of the MAX17851 driver.

Author
Radu Sabau (radu..nosp@m.saba.nosp@m.u@ana.nosp@m.log..nosp@m.com)

Copyright 2025(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

◆ max17851_clear_buff()

int max17851_clear_buff ( struct max17851_desc * desc,
bool tx_buf )

Clear RX/TX buffer inside the MAX17851 memory.

Parameters
desc- MAX17851 device descriptor.
tx_buf- True - Clear TX buffer. False - Clear RX buffer.
Returns
0 incase of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_config_gen2()

int max17851_config_gen2 ( struct max17851_desc * desc,
enum max17851_config_gen2_sel sel,
bool enable )

Configure general settings for MAX17851.

Parameters
desc- MAX17851 device descriptor.
sel- Specific setting to be changed.
enable- Disable/Enable specific setting.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_get_alert()

int max17851_get_alert ( struct max17851_desc * desc,
enum max17851_alert alert,
bool * enable )

Read specific alert state.

Parameters
desc- MAX17851 device descriptor.
alert- Specific alert state to be read.
enable- Pointer to alert state value to be read.
Returns
0 in case of success, negative error code otherwise.

◆ max17851_init()

int max17851_init ( struct max17851_desc ** desc,
struct max17851_init_param * init_param )

MAX17851 device initialization function.

Parameters
desc- MAX17851 device descriptor to be intialized.
init_param- MAX17851 initialization parameter.
Returns
0 in case of success, negative error code otherwise.

◆ max17851_read_msg()

int max17851_read_msg ( struct max17851_desc * desc,
uint8_t * data,
uint8_t len )

Read message over UART from the MAX17851.

Parameters
desc- MAX17851 device descriptor.
data- Pointer to data containing buffer.
len- Length of the message in bytes.
Returns
0 in case of success, negative error code otherwise.

◆ max17851_reg_read()

int max17851_reg_read ( struct max17851_desc * desc,
uint8_t reg,
uint8_t * data )

MAX17851 register read function.

Parameters
desc- MAX17851 device descriptor.
reg- Register Address.
data- Data byte to be read.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_reg_update()

int max17851_reg_update ( struct max17851_desc * desc,
uint8_t reg,
uint8_t mask,
uint8_t data )

MAX17851 register update function.

Parameters
desc- MAX17851 device descriptor.
reg- Register Address.
mask- Field mask to be udated inside the register.
data- Data byte to be updated.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_reg_write()

int max17851_reg_write ( struct max17851_desc * desc,
uint8_t reg,
uint8_t data )

MAX17851 register write function.

Parameters
desc- MAX17851 device descriptor.
reg- Register Address.
data- Data byte to be written.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_remove()

int max17851_remove ( struct max17851_desc * desc)

Deallocate any resources used at the initialization function.

Parameters
desc- MAX17851 device descriptor.
Returns
0 in case of success, negative error code otherwise.

◆ max17851_sel_alrtpckt_time()

int max17851_sel_alrtpckt_time ( struct max17851_desc * desc,
enum max17851_alrtpckt_time time )

Set timing for Alert Packets/Keep-Alive Packets.

Parameters
desc- MAX17851 device descriptor.
time- Specific pre-defined time value to be set.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_select_queue()

int max17851_select_queue ( struct max17851_desc * desc,
enum max17851_queue_sel sel )

Select queue for transmitting/loading TX buffer for UART.

Parameters
desc- MAX17851 device descriptor.
sel- Specific pre-defined value for either TX or LD queue selection.
Returns
0 in case of success, negative error code otherwise.

◆ max17851_send_command()

int max17851_send_command ( struct max17851_desc * desc,
enum max17851_command command,
bool enable )

Send specific device command over SPI.

Parameters
desc- MAX17851 device descriptor.
command- Specific command from the command list.
enable- Enable/Disable function in case of some commands. Appropiated value needed only for SWPORT or SLEEP_EN commands, ohterwise can be left either true or false.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_set_alert()

int max17851_set_alert ( struct max17851_desc * desc,
enum max17851_alert alert,
bool enable )

Enable/Disable specific alert.

Parameters
desc- MAX17851 device descriptor.
alert- Specific alert to be enabled/disabled.
enable- true - Enable specific alert. false - Disable specific alert.
Returns
0 in case of success, negative erro code otherwise.

◆ max17851_set_alert_debounce()

int max17851_set_alert_debounce ( struct max17851_desc * desc,
enum max17851_status_debounce dbnc )

Select the number of unmasked consecutive Alert Packet status alerts, which must happen prior to taking action in either Safe Minotring or Sleep Mode.

Parameters
desc- MAX17851 device descriptor.
dbnc- Specific pre-defined value for number of debounces.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_set_comm()

int max17851_set_comm ( struct max17851_desc * desc,
enum max17851_comm_try_count count,
enum max17851_comm_timeout_delay delay )

Set communication retry count and timeout delay.

Parameters
desc- MAX17851 device descriptor.
count- Specific pre-defined value for communication retry count.
delay- Specific pre-defined value for communication timeout delay.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_set_safemon_dly()

int max17851_set_safemon_dly ( struct max17851_desc * desc,
enum max17851_safemon_dly delay )

Select Safe Monitoring Mode Scan Delay.

Parameters
desc- MAX17851 device descriptor.
delay- Specific pre-defined time delay.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ max17851_set_safemon_gpio()

int max17851_set_safemon_gpio ( struct max17851_desc * desc,
enum max17851_safemon_gpio gpio,
bool enable )

Select which GPIO pins to be configured as SAFEMON output.

Parameters
desc- MAX17851 device descriptor.
gpio- Selected GPIO.
enable- Enable/Disable the SAFEMON output function of the GPIO.
Returns
0 in case of success, negative error code otherwise.

◆ max17851_write_msg()

int max17851_write_msg ( struct max17851_desc * desc,
const uint8_t * data,
uint8_t len )

Write message over UART using MAX17851.

Parameters
desc- MAX17851 device descriptor.
data- Pointer to data containing buffer.
len- Length of the message in bytes.
Returns
0 in case of success, negative error code otherwise.

Variable Documentation

◆ max17851_uart_ops

const struct no_os_uart_platform_ops max17851_uart_ops
Initial value:
= {
.init = &max17851_uart_init,
.read = &max17851_uart_read,
.write = &max17851_uart_write,
.get_errors = &max17851_uart_get_errors,
.remove = &max17851_uart_remove
}

MAX17851 platform specific UART platform ops structure.