no-OS
max22190.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef _MAX22190_H
34 #define _MAX22190_H
35 
36 #include <stdint.h>
37 #include <stdbool.h>
38 #include "no_os_gpio.h"
39 #include "no_os_spi.h"
40 #include "no_os_util.h"
41 
42 #define MAX22190_FRAME_SIZE 2
43 #define MAX22190_CHANNELS 8
44 #define MAX22190_FAULT2_ENABLES 5
45 
46 #define MAX22190_WIRE_BREAK_REG 0x0
47 #define MAX22190_DIGITAL_INPUT_REG 0x2
48 #define MAX22190_FAULT1_REG 0x4
49 #define MAX22190_FILTER_IN_REG(x) (0x6 + (2 * (x)))
50 #define MAX22190_CONFIG_REG 0x18
51 #define MAX22190_INPUT_EN_REG 0x1A
52 #define MAX22190_FAULT2_REG 0x1C
53 #define MAX22190_FAULT2_EN_REG 0x1E
54 #define MAX22190_GPO_REG 0x22
55 #define MAX22190_FAULT1_EN_REG 0x24
56 
57 #define MAX22190_NO_OP_REG 0x26
58 
59 #define MAX22190_CH_STATE_MASK(x) NO_OS_BIT(x)
60 #define MAX22190_DELAY_MASK NO_OS_GENMASK(2, 0)
61 #define MAX22190_FBP_MASK NO_OS_BIT(3)
62 #define MAX22190_WBE_MASK NO_OS_BIT(4)
63 #define MAX22190_RW_MASK NO_OS_BIT(7)
64 #define MAX22190_ADDR_MASK NO_OS_GENMASK(6, 0)
65 #define MAX22190_ALARM_MASK NO_OS_GENMASK(4, 3)
66 #define MAX22190_POR_MASK NO_OS_BIT(6)
67 
68 #define MAX22190_FAULT_MASK(x) NO_OS_BIT(x)
69 #define MAX22190_FAULT2_WBE_MASK NO_OS_BIT(4)
70 
71 #define MAX22190_FAULT2_EN_MASK NO_OS_GENMASK(5, 0)
72 
73 #define MAX22190_CFG_REFDI_MASK NO_OS_BIT(0)
74 #define MAX22190_CFG_CLRF_MASK NO_OS_BIT(3)
75 #define MAX22190_CFG_24VF_MASK NO_OS_BIT(4)
76 
80 };
81 
85  bool crc_en;
86 };
87 
88 struct max22190_desc {
91  uint8_t buff[MAX22190_FRAME_SIZE + 1];
93  uint8_t fault2en;
94  bool crc_en;
95 };
96 
106 };
107 
123 };
124 
126 int max22190_filter_set(struct max22190_desc *, uint32_t, uint32_t,
127  uint32_t, enum max22190_delay);
128 
130 int max22190_filter_get(struct max22190_desc *, uint32_t, uint32_t *,
131  uint32_t *, enum max22190_delay *);
132 
134 int max22190_chan_state(struct max22190_desc *, uint32_t,
135  enum max22190_ch_state);
136 
138 int max22190_wbe_get(struct max22190_desc *, uint32_t, bool *);
139 
141 int max22190_wbe_set(struct max22190_desc *, uint32_t, bool);
142 
145  enum max22190_fault_enable, bool);
146 
149  enum max22190_fault_enable, bool *);
150 
152 int max22190_reg_read(struct max22190_desc *, uint32_t, uint32_t *);
153 
155 int max22190_reg_write(struct max22190_desc *, uint32_t, uint32_t);
156 
158 int max22190_reg_update(struct max22190_desc *, uint32_t, uint32_t, uint32_t);
159 
161 int max22190_init(struct max22190_desc **, struct max22190_init_param *);
162 
164 int max22190_remove(struct max22190_desc *);
165 
166 #endif
max22190_reg_update
int max22190_reg_update(struct max22190_desc *, uint32_t, uint32_t, uint32_t)
Register update function for MAX22190.
Definition: max22190.c:405
MAX22190_FAULT2_RFDIOE
@ MAX22190_FAULT2_RFDIOE
Definition: max22190.h:118
MAX22190_FAULT2_WBE_MASK
#define MAX22190_FAULT2_WBE_MASK
Definition: max22190.h:69
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
MAX22190_CFG_CLRF_MASK
#define MAX22190_CFG_CLRF_MASK
Definition: max22190.h:74
max22190_filter_get
int max22190_filter_get(struct max22190_desc *, uint32_t, uint32_t *, uint32_t *, enum max22190_delay *)
Get filter delay, wite break detection and if the filter is used or bypassed.
Definition: max22190.c:125
MAX22190_FAULT1_24VLE
@ MAX22190_FAULT1_24VLE
Definition: max22190.h:111
MAX22190_CONFIG_REG
#define MAX22190_CONFIG_REG
Definition: max22190.h:50
max22190_init_param::crc_en
bool crc_en
Definition: max22190.h:85
max22190_reg_read
int max22190_reg_read(struct max22190_desc *desc, uint32_t addr, uint32_t *val)
Register read function for MAX22190.
Definition: max22190.c:332
MAX22190_FAULT2_FAULT8CKE
@ MAX22190_FAULT2_FAULT8CKE
Definition: max22190.h:120
max22190_remove
int max22190_remove(struct max22190_desc *)
Free the resources allocated by initialization.
Definition: max22190.c:485
no_os_spi.h
Header file of SPI Interface.
max22190_desc
Definition: max22190.h:88
max22190_init_param::comm_param
struct no_os_spi_init_param * comm_param
Definition: max22190.h:83
MAX22190_FAULT1_WBGE
@ MAX22190_FAULT1_WBGE
Definition: max22190.h:109
MAX22190_DELAY_400US
@ MAX22190_DELAY_400US
Definition: max22190.h:100
max22190_chan_state
int max22190_chan_state(struct max22190_desc *, uint32_t, enum max22190_ch_state)
Switch selected channel's state to disabled or enabled.
Definition: max22190.c:157
max22190_fault_enable_get
int max22190_fault_enable_get(struct max22190_desc *desc, enum max22190_fault_enable fault_enable, bool *enabled)
Get fault enable from the fault registers.
Definition: max22190.c:225
max22190_desc::buff
uint8_t buff[MAX22190_FRAME_SIZE+1]
Definition: max22190.h:91
max22190_fault_enable_set
int max22190_fault_enable_set(struct max22190_desc *desc, enum max22190_fault_enable fault_enable, bool enabled)
Set fault enable in the fault registers.
Definition: max22190.c:273
MAX22190_CFG_24VF_MASK
#define MAX22190_CFG_24VF_MASK
Definition: max22190.h:75
MAX22190_DELAY_1800US
@ MAX22190_DELAY_1800US
Definition: max22190.h:102
no_os_spi_msg
Definition: no_os_spi.h:100
max22190_wbe_get
int max22190_wbe_get(struct max22190_desc *, uint32_t, bool *)
Get Wire Break detection for requested channel.
Definition: max22190.c:183
max22190_desc::crc_en
bool crc_en
Definition: max22190.h:94
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
MAX22190_DELAY_50US
@ MAX22190_DELAY_50US
Definition: max22190.h:98
MAX22190_ADDR_MASK
#define MAX22190_ADDR_MASK
Definition: max22190.h:64
max22190_desc::comm_desc
struct no_os_spi_desc * comm_desc
Definition: max22190.h:89
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:54
MAX22190_RW_MASK
#define MAX22190_RW_MASK
Definition: max22190.h:63
max22190_chan_state
int max22190_chan_state(struct max22190_desc *desc, uint32_t ch, enum max22190_ch_state state)
Switch selected channel's state to disabled or enabled.
Definition: max22190.c:157
MAX22190_FAULT_MASK
#define MAX22190_FAULT_MASK(x)
Definition: max22190.h:68
no_os_spi_msg::tx_buff
uint8_t * tx_buff
Definition: no_os_spi.h:102
MAX22190_DELAY_3200US
@ MAX22190_DELAY_3200US
Definition: max22190.h:103
max22190_wbe_get
int max22190_wbe_get(struct max22190_desc *desc, uint32_t ch, bool *enabled)
Get Wire Break detection for requested channel.
Definition: max22190.c:183
MAX22190_POR_MASK
#define MAX22190_POR_MASK
Definition: max22190.h:66
MAX22190_FAULT1_ALRMT1E
@ MAX22190_FAULT1_ALRMT1E
Definition: max22190.h:112
no_os_field_prep
uint32_t no_os_field_prep(uint32_t mask, uint32_t val)
max22190_init
int max22190_init(struct max22190_desc **, struct max22190_init_param *)
MAX22190 Initialization function.
Definition: max22190.c:427
MAX22190_DELAY_100US
@ MAX22190_DELAY_100US
Definition: max22190.h:99
MAX22190_FAULT2_RFWBSE
@ MAX22190_FAULT2_RFWBSE
Definition: max22190.h:115
max22190_fault_enable
max22190_fault_enable
Definition: max22190.h:108
MAX22190_DELAY_20MS
@ MAX22190_DELAY_20MS
Definition: max22190.h:105
MAX22190_CH_OFF
@ MAX22190_CH_OFF
Definition: max22190.h:78
MAX22190_FRAME_SIZE
#define MAX22190_FRAME_SIZE
Definition: max22190.h:42
MAX22190_INPUT_EN_REG
#define MAX22190_INPUT_EN_REG
Definition: max22190.h:51
max22190_filter_set
int max22190_filter_set(struct max22190_desc *desc, uint32_t ch, uint32_t clrf, uint32_t fbp, enum max22190_delay delay)
Set filter delay, wite break detection and if the filter is used or bypassed.
Definition: max22190.c:93
max22190_reg_update
int max22190_reg_update(struct max22190_desc *desc, uint32_t addr, uint32_t mask, uint32_t val)
Register update function for MAX22190.
Definition: max22190.c:405
MAX22190_CHANNELS
#define MAX22190_CHANNELS
Definition: max22190.h:43
max22190_init
int max22190_init(struct max22190_desc **desc, struct max22190_init_param *param)
MAX22190 Initialization function.
Definition: max22190.c:427
MAX22190_FAULT2_EN_MASK
#define MAX22190_FAULT2_EN_MASK
Definition: max22190.h:71
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:104
max22190_fault_enable_get
int max22190_fault_enable_get(struct max22190_desc *, enum max22190_fault_enable, bool *)
Get fault enable from the fault registers.
Definition: max22190.c:225
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
max22190_desc::en_gpio
struct no_os_gpio_desc * en_gpio
Definition: max22190.h:90
MAX22190_FAULT1_ALRMT2E
@ MAX22190_FAULT1_ALRMT2E
Definition: max22190.h:113
MAX22190_DELAY_MASK
#define MAX22190_DELAY_MASK
Definition: max22190.h:60
max22190_filter_set
int max22190_filter_set(struct max22190_desc *, uint32_t, uint32_t, uint32_t, enum max22190_delay)
Set filter delay, wite break detection and if the filter is used or bypassed.
Definition: max22190.c:93
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
MAX22190_CFG_REFDI_MASK
#define MAX22190_CFG_REFDI_MASK
Definition: max22190.h:73
MAX22190_FAULT2_RFDISE
@ MAX22190_FAULT2_RFDISE
Definition: max22190.h:117
max22190_desc::fault2en
uint8_t fault2en
Definition: max22190.h:93
MAX22190_FAULT1_REG
#define MAX22190_FAULT1_REG
Definition: max22190.h:48
no_os_spi_transfer
int32_t no_os_spi_transfer(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Iterate over head list and send all spi messages.
Definition: no_os_spi.c:185
no_os_spi_msg::bytes_number
uint32_t bytes_number
Definition: no_os_spi.h:106
MAX22190_FAULT1_EN_REG
#define MAX22190_FAULT1_EN_REG
Definition: max22190.h:55
MAX22190_FAULT1_FAULT2E
@ MAX22190_FAULT1_FAULT2E
Definition: max22190.h:114
max22190_wbe_set
int max22190_wbe_set(struct max22190_desc *, uint32_t, bool)
Set Wire Break detection for requested channel.
Definition: max22190.c:207
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
max22190_wbe_set
int max22190_wbe_set(struct max22190_desc *desc, uint32_t ch, bool enabled)
Set Wire Break detection for requested channel.
Definition: max22190.c:207
max22190_reg_write
int max22190_reg_write(struct max22190_desc *desc, uint32_t addr, uint32_t val)
Register write function for MAX22190.
Definition: max22190.c:375
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:69
max22190_fault_enable_set
int max22190_fault_enable_set(struct max22190_desc *, enum max22190_fault_enable, bool)
Set fault enable in the fault registers.
Definition: max22190.c:273
MAX22190_FAULT2_RFWBOE
@ MAX22190_FAULT2_RFWBOE
Definition: max22190.h:116
max22190_init_param
Definition: max22190.h:82
MAX22190_FILTER_IN_REG
#define MAX22190_FILTER_IN_REG(x)
Definition: max22190.h:49
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:197
max22190_ch_state
max22190_ch_state
Definition: max22190.h:77
MAX22190_FBP_MASK
#define MAX22190_FBP_MASK
Definition: max22190.h:61
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:116
max22190_delay
max22190_delay
Definition: max22190.h:97
MAX22190_CH_ON
@ MAX22190_CH_ON
Definition: max22190.h:79
no_os_gpio.h
Header file of GPIO Interface.
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:52
max22190.h
Header file of MAX22190 Driver.
no_os_util.h
Header file of utility functions.
max22190_desc::channels
enum max22190_ch_state channels[MAX22190_CHANNELS]
Definition: max22190.h:92
MAX22190_FAULT2_OTSHDNE
@ MAX22190_FAULT2_OTSHDNE
Definition: max22190.h:119
MAX22190_CFG_REFDI_SH_ENA
@ MAX22190_CFG_REFDI_SH_ENA
Definition: max22190.h:122
MAX22190_FAULT2_EN_REG
#define MAX22190_FAULT2_EN_REG
Definition: max22190.h:53
MAX22190_DELAY_800US
@ MAX22190_DELAY_800US
Definition: max22190.h:101
MAX22190_CFG_24VF
@ MAX22190_CFG_24VF
Definition: max22190.h:121
max22190_init_param::en_gpio_param
struct no_os_gpio_init_param * en_gpio_param
Definition: max22190.h:84
MAX22190_FAULT1_24VME
@ MAX22190_FAULT1_24VME
Definition: max22190.h:110
max22190_reg_write
int max22190_reg_write(struct max22190_desc *, uint32_t, uint32_t)
Register write function for MAX22190.
Definition: max22190.c:375
errno.h
Error macro definition for ARM Compiler.
MAX22190_CH_STATE_MASK
#define MAX22190_CH_STATE_MASK(x)
Definition: max22190.h:59
MAX22190_DELAY_12800US
@ MAX22190_DELAY_12800US
Definition: max22190.h:104
max22190_reg_read
int max22190_reg_read(struct max22190_desc *, uint32_t, uint32_t *)
Register read function for MAX22190.
Definition: max22190.c:332
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
max22190_remove
int max22190_remove(struct max22190_desc *desc)
Free the resources allocated by initialization.
Definition: max22190.c:485
max22190_filter_get
int max22190_filter_get(struct max22190_desc *desc, uint32_t ch, uint32_t *clrf, uint32_t *fbp, enum max22190_delay *delay)
Get filter delay, wite break detection and if the filter is used or bypassed.
Definition: max22190.c:125
no_os_gpio_get_optional
int32_t no_os_gpio_get_optional(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Get the value of an optional GPIO.
Definition: no_os_gpio.c:75