ina3221_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef INA3221_INTERNAL_H
21 #define INA3221_INTERNAL_H
22 
23 #include <assert.h>
24 #include "ina3221_defines.h"
25 #include "ina3221.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
40 static inline int32_t reg_val_to_shunt_voltage_uv(int16_t reg_val)
41 {
43 
44  return reg_val / 8 * INA3221_SHUNT_VOLTAGE_PRECISION_UV;
45 }
46 
56 static inline int16_t shunt_voltage_uv_to_reg_val(int32_t s_uv)
57 {
59 
60  return s_uv / INA3221_SHUNT_VOLTAGE_PRECISION_UV * 8;
61 }
62 
72 static inline int16_t reg_val_to_bus_voltage_mv(int16_t reg_val)
73 {
74  assert(reg_val <= INA3221_MAX_BUS_REG_VAL);
75 
76  return reg_val / 8 * INA3221_BUS_VOLTAGE_PRECISION_MV;
77 }
78 
88 static inline int16_t bus_voltage_mv_to_reg_val(int16_t b_mv)
89 {
90  assert(b_mv >= INA3221_MIN_BUS_MV);
91  assert(b_mv <= INA3221_MAX_BUS_MV);
92 
93  return b_mv / INA3221_BUS_VOLTAGE_PRECISION_MV * 8;
94 }
95 
105 static inline int32_t sum_reg_val_to_shunt_voltage_uv(int16_t sum_reg_val)
106 {
107  assert(sum_reg_val <= INA3221_MAX_SHUNT_SUM_REG_VAL);
108 
109  return sum_reg_val / 2 * INA3221_SHUNT_VOLTAGE_PRECISION_UV;
110 }
111 
121 static inline int16_t sum_shunt_voltage_uv_to_reg_val(int32_t sum_suv)
122 {
123  assert(sum_suv <= INA3221_MAX_SHUNT_SUM_UV);
124 
125  return sum_suv / INA3221_SHUNT_VOLTAGE_PRECISION_UV * 2;
126 }
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* INA3221_INTERNAL_H */
133 
bus_voltage_mv_to_reg_val
static int16_t bus_voltage_mv_to_reg_val(int16_t b_mv)
Convert bus voltage in mV to register value.
Definition: ina3221_internal.h:88
sum_shunt_voltage_uv_to_reg_val
static int16_t sum_shunt_voltage_uv_to_reg_val(int32_t sum_suv)
Convert shunt voltage sum value in uV to register value.
Definition: ina3221_internal.h:121
INA3221_MAX_SHUNT_UV
#define INA3221_MAX_SHUNT_UV
Max.
Definition: ina3221_defines.h:47
assert
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
INA3221_MAX_BUS_MV
#define INA3221_MAX_BUS_MV
Max.
Definition: ina3221_defines.h:49
INA3221_MAX_SHUNT_SUM_UV
#define INA3221_MAX_SHUNT_SUM_UV
Max.
Definition: ina3221_defines.h:51
assert.h
POSIX.1-2008 compliant version of the assert macro.
INA3221_MAX_SHUNT_REG_VAL
#define INA3221_MAX_SHUNT_REG_VAL
0111 1111 1111 1000
Definition: ina3221_defines.h:41
INA3221_MAX_BUS_REG_VAL
#define INA3221_MAX_BUS_REG_VAL
0111 1111 1111 1000
Definition: ina3221_defines.h:43
sum_reg_val_to_shunt_voltage_uv
static int32_t sum_reg_val_to_shunt_voltage_uv(int16_t sum_reg_val)
Convert register value to shunt voltage sum value in mV.
Definition: ina3221_internal.h:105
ina3221.h
Device driver interface for Texas Instruments INA3221 three-channel ,high-side current and bus voltag...
ina3221_defines.h
Internal definitions for Texas Instruments INA3221 three-channel, high-side current and bus voltage m...
INA3221_MAX_SHUNT_SUM_REG_VAL
#define INA3221_MAX_SHUNT_SUM_REG_VAL
0111 1111 1111 1110
Definition: ina3221_defines.h:45
reg_val_to_shunt_voltage_uv
static int32_t reg_val_to_shunt_voltage_uv(int16_t reg_val)
Convert register value to shunt voltage in uV.
Definition: ina3221_internal.h:40
INA3221_MIN_BUS_MV
#define INA3221_MIN_BUS_MV
Min.
Definition: ina3221_defines.h:50
INA3221_SHUNT_VOLTAGE_PRECISION_UV
#define INA3221_SHUNT_VOLTAGE_PRECISION_UV
Shunt voltage measurement precision.
Definition: ina3221_defines.h:31
INA3221_BUS_VOLTAGE_PRECISION_MV
#define INA3221_BUS_VOLTAGE_PRECISION_MV
Bus voltage measurement precision.
Definition: ina3221_defines.h:32
shunt_voltage_uv_to_reg_val
static int16_t shunt_voltage_uv_to_reg_val(int32_t s_uv)
Convert shunt voltage in uV to register value.
Definition: ina3221_internal.h:56
reg_val_to_bus_voltage_mv
static int16_t reg_val_to_bus_voltage_mv(int16_t reg_val)
Convert register value to bus voltage in mV.
Definition: ina3221_internal.h:72