openMMC
Open Source Modular MMC for AMCs
Loading...
Searching...
No Matches
ina3221.h
Go to the documentation of this file.
1/*
2 * openMMC -- Open Source modular IPM Controller firmware
3 *
4 * Copyright (C) 2015-2016 Henrique Silva <henrique.silva@lnls.br>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
20 */
21
38#ifndef INA3221_H_
39#define INA3221_H_
40
41#include "FreeRTOS.h"
42#include "port.h"
43
44#define MAX_INA3221_COUNT 6
45#define INA3221_UPDATE_RATE 100
46
47#define INA3221_CHANNEL_1 0
48#define INA3221_CHANNEL_2 1
49#define INA3221_CHANNEL_3 2
50
57#define INA3221_CONFIG 0x00
58#define INA3221_SHUNT_VOLTAGE 0x01
59#define INA3221_BUS_VOLTAGE 0x02
60#define INA3221_CRITICAL_ALERT_LIMIT 0x07
61#define INA3221_WARNING_ALERT_LIMIT 0x08
62#define INA3221_SHUNT_VOLTAGE_SUM 0x0D
63#define INA3221_SHUNT_VOLTAGE_SUM_LIMIT 0x0E
64#define INA3221_MASK_ENABLE 0x0F
65#define INA3221_POWER_UPPER_VALID 0x10
66#define INA3221_POWER_VALID_LOWER_LIMIT 0x11
67#define INA3221_MANUFACTURER_ID 0xFE
68#define INA3221_DIE_ID 0xFF
69
74/* Operating modes */
75#define INA3221_MODE_POWER_DOWN 0x0
76#define INA3221_MODE_SHUNT_TRIG 0x1
77#define INA3221_MODE_BUS_TRIG 0x2
78#define INA3221_MODE_SHUNT_BUS_TRIG 0x3
79#define INA3221_MODE_SHUNT_CONT 0x5
80#define INA3221_MODE_BUS_CONT 0x6
81#define INA3221_MODE_SHUNT_BUS_CONT 0x7
82
86#define INA3221_VOLTAGE_REGISTERS 6
87
88#define INA3221_MAX_DELAY 10 /* worst case delay in ms */
89
90#define INA3221_RSHUNT_DEFAULT 2
91
92typedef union {
93 struct {
94#ifdef BF_MS_FIRST
95 uint16_t mode:3;
96 uint16_t shunt_voltage_conversion_time:3;
97 uint16_t bus_voltage_conversion_time:3;
98 uint16_t averaging_mode:3;
99 uint16_t channel_enable_mode:3;
100 uint16_t reset:1;
101#else
102 uint16_t reset:1;
104 uint16_t averaging_mode:3;
107 uint16_t mode:3;
108#endif
109 } cfg_struct;
110 uint16_t cfg_word;
112
113typedef struct {
114 uint16_t shunt_resistor[3]; /* mOhm */
116
125
126extern TaskHandle_t vTaskINA3221_Handle;
127
128uint8_t ina3221_read_reg( ina3221_data_t * data, uint8_t reg, uint16_t *read );
129uint8_t ina3221_read_voltages( ina3221_data_t * data );
130void ina3221_init( void );
131void vTaskINA3221( void* Parameters );
132
133#endif
uint8_t ina3221_read_reg(ina3221_data_t *data, uint8_t reg, uint16_t *read)
Definition ina3221.c:108
#define INA3221_VOLTAGE_REGISTERS
INA3221 Register Count.
Definition ina3221.h:86
void vTaskINA3221(void *Parameters)
Definition ina3221.c:48
TaskHandle_t vTaskINA3221_Handle
Definition ina3221.c:44
uint8_t ina3221_read_voltages(ina3221_data_t *data)
Definition ina3221.c:126
void ina3221_init(void)
Definition ina3221.c:137
Port layer (includes all portable functions headers)
Definition ina3221.h:113
Definition ina3221.h:117
uint32_t rshunt
Definition ina3221.h:121
const ina3221_config_t * config
Definition ina3221.h:120
uint8_t chipid
Definition ina3221.h:118
ina3221_config_reg_t curr_reg_config
Definition ina3221.h:122
Definition sdr.h:181
Definition ina3221.h:92
uint16_t cfg_word
Definition ina3221.h:110
uint16_t reset
Definition ina3221.h:102
uint16_t bus_voltage_conversion_time
Definition ina3221.h:105
uint16_t mode
Definition ina3221.h:107
uint16_t channel_enable_mode
Definition ina3221.h:103
uint16_t shunt_voltage_conversion_time
Definition ina3221.h:106
uint16_t averaging_mode
Definition ina3221.h:104