PX4 Firmware
PX4 Autopilot Software http://px4.io
batt_smbus.h File Reference

Header for a battery monitor connected via SMBus (I2C). More...

#include <ecl/geo/geo.h>
#include <lib/drivers/smbus/SMBus.hpp>
#include <mathlib/mathlib.h>
#include <perf/perf_counter.h>
#include <px4_platform_common/module.h>
#include <px4_platform_common/getopt.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
#include <uORB/topics/battery_status.h>
#include "board_config.h"
Include dependency graph for batt_smbus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  batt_smbus_bus_option
 
class  BATT_SMBUS
 

Macros

#define DATA_BUFFER_SIZE   32
 
#define BATT_CELL_VOLTAGE_THRESHOLD_RTL   0.5f
 Threshold in volts to RTL if cells are imbalanced. More...
 
#define BATT_CELL_VOLTAGE_THRESHOLD_FAILED   1.5f
 Threshold in volts to Land if cells are imbalanced. More...
 
#define BATT_CURRENT_UNDERVOLTAGE_THRESHOLD   5.0f
 Threshold in amps to disable undervoltage protection. More...
 
#define BATT_VOLTAGE_UNDERVOLTAGE_THRESHOLD   3.4f
 Threshold in volts to re-enable undervoltage protection. More...
 
#define BATT_SMBUS_ADDR   0x0B
 Default 7 bit address I2C address. 8 bit = 0x16. More...
 
#define BATT_SMBUS_CURRENT   0x0A
 current register More...
 
#define BATT_SMBUS_AVERAGE_CURRENT   0x0B
 current register More...
 
#define BATT_SMBUS_TEMP   0x08
 temperature register More...
 
#define BATT_SMBUS_VOLTAGE   0x09
 voltage register More...
 
#define BATT_SMBUS_FULL_CHARGE_CAPACITY   0x10
 capacity when fully charged More...
 
#define BATT_SMBUS_RUN_TIME_TO_EMPTY   0x11
 predicted remaining battery capacity based on the present rate of discharge in min More...
 
#define BATT_SMBUS_AVERAGE_TIME_TO_EMPTY   0x12
 predicted remaining battery capacity based on the present rate of discharge in min More...
 
#define BATT_SMBUS_REMAINING_CAPACITY   0x0F
 predicted remaining battery capacity as a percentage More...
 
#define BATT_SMBUS_CYCLE_COUNT   0x17
 number of cycles the battery has experienced More...
 
#define BATT_SMBUS_DESIGN_CAPACITY   0x18
 design capacity register More...
 
#define BATT_SMBUS_DESIGN_VOLTAGE   0x19
 design voltage register More...
 
#define BATT_SMBUS_MANUFACTURER_NAME   0x20
 manufacturer name More...
 
#define BATT_SMBUS_MANUFACTURE_DATE   0x1B
 manufacture date register More...
 
#define BATT_SMBUS_SERIAL_NUMBER   0x1C
 serial number register More...
 
#define BATT_SMBUS_MEASUREMENT_INTERVAL_US   100000
 time in microseconds, measure at 10Hz More...
 
#define BATT_SMBUS_MANUFACTURER_ACCESS   0x00
 
#define BATT_SMBUS_MANUFACTURER_DATA   0x23
 
#define BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS   0x44
 
#define BATT_SMBUS_SECURITY_KEYS   0x0035
 
#define BATT_SMBUS_CELL_1_VOLTAGE   0x3F
 
#define BATT_SMBUS_CELL_2_VOLTAGE   0x3E
 
#define BATT_SMBUS_CELL_3_VOLTAGE   0x3D
 
#define BATT_SMBUS_CELL_4_VOLTAGE   0x3C
 
#define BATT_SMBUS_LIFETIME_FLUSH   0x002E
 
#define BATT_SMBUS_LIFETIME_BLOCK_ONE   0x0060
 
#define BATT_SMBUS_ENABLED_PROTECTIONS_A_ADDRESS   0x4938
 
#define BATT_SMBUS_SEAL   0x0030
 
#define BATT_SMBUS_ENABLED_PROTECTIONS_A_DEFAULT   0xcf
 
#define BATT_SMBUS_ENABLED_PROTECTIONS_A_CUV_DISABLED   0xce
 
#define NUM_BUS_OPTIONS   (sizeof(smbus_bus_options)/sizeof(smbus_bus_options[0]))
 

Enumerations

enum  BATT_SMBUS_BUS {
  BATT_SMBUS_BUS_ALL = 0, BATT_SMBUS_BUS_I2C_INTERNAL, BATT_SMBUS_BUS_I2C_EXTERNAL, BATT_SMBUS_BUS_I2C_EXTERNAL1,
  BATT_SMBUS_BUS_I2C_EXTERNAL2
}
 

Variables

struct batt_smbus_bus_option smbus_bus_options []
 

Detailed Description

Header for a battery monitor connected via SMBus (I2C).

Designed for BQ40Z50-R1/R2

Author
Jacob Dahl dahl..nosp@m.jake.nosp@m.jacob.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Alex Klimaj alexk.nosp@m.lima.nosp@m.j@gma.nosp@m.il.c.nosp@m.om

Definition in file batt_smbus.h.

Macro Definition Documentation

◆ BATT_CELL_VOLTAGE_THRESHOLD_FAILED

#define BATT_CELL_VOLTAGE_THRESHOLD_FAILED   1.5f

Threshold in volts to Land if cells are imbalanced.

Definition at line 60 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_startup_info(), and BATT_SMBUS::Run().

◆ BATT_CELL_VOLTAGE_THRESHOLD_RTL

#define BATT_CELL_VOLTAGE_THRESHOLD_RTL   0.5f

Threshold in volts to RTL if cells are imbalanced.

Definition at line 59 of file batt_smbus.h.

◆ BATT_CURRENT_UNDERVOLTAGE_THRESHOLD

#define BATT_CURRENT_UNDERVOLTAGE_THRESHOLD   5.0f

Threshold in amps to disable undervoltage protection.

Definition at line 62 of file batt_smbus.h.

Referenced by BATT_SMBUS::set_undervoltage_protection().

◆ BATT_SMBUS_ADDR

#define BATT_SMBUS_ADDR   0x0B

Default 7 bit address I2C address. 8 bit = 0x16.

Definition at line 65 of file batt_smbus.h.

◆ BATT_SMBUS_AVERAGE_CURRENT

#define BATT_SMBUS_AVERAGE_CURRENT   0x0B

current register

Definition at line 68 of file batt_smbus.h.

Referenced by BATT_SMBUS::Run().

◆ BATT_SMBUS_AVERAGE_TIME_TO_EMPTY

#define BATT_SMBUS_AVERAGE_TIME_TO_EMPTY   0x12

predicted remaining battery capacity based on the present rate of discharge in min

Definition at line 73 of file batt_smbus.h.

Referenced by BATT_SMBUS::Run().

◆ BATT_SMBUS_CELL_1_VOLTAGE

#define BATT_SMBUS_CELL_1_VOLTAGE   0x3F

Definition at line 86 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_cell_voltages().

◆ BATT_SMBUS_CELL_2_VOLTAGE

#define BATT_SMBUS_CELL_2_VOLTAGE   0x3E

Definition at line 87 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_cell_voltages().

◆ BATT_SMBUS_CELL_3_VOLTAGE

#define BATT_SMBUS_CELL_3_VOLTAGE   0x3D

Definition at line 88 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_cell_voltages().

◆ BATT_SMBUS_CELL_4_VOLTAGE

#define BATT_SMBUS_CELL_4_VOLTAGE   0x3C

Definition at line 89 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_cell_voltages().

◆ BATT_SMBUS_CURRENT

#define BATT_SMBUS_CURRENT   0x0A

current register

Definition at line 67 of file batt_smbus.h.

Referenced by BATT_SMBUS::Run().

◆ BATT_SMBUS_CYCLE_COUNT

#define BATT_SMBUS_CYCLE_COUNT   0x17

number of cycles the battery has experienced

Definition at line 75 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_startup_info().

◆ BATT_SMBUS_DESIGN_CAPACITY

#define BATT_SMBUS_DESIGN_CAPACITY   0x18

design capacity register

Definition at line 76 of file batt_smbus.h.

◆ BATT_SMBUS_DESIGN_VOLTAGE

#define BATT_SMBUS_DESIGN_VOLTAGE   0x19

design voltage register

Definition at line 77 of file batt_smbus.h.

◆ BATT_SMBUS_ENABLED_PROTECTIONS_A_ADDRESS

#define BATT_SMBUS_ENABLED_PROTECTIONS_A_ADDRESS   0x4938

Definition at line 92 of file batt_smbus.h.

Referenced by BATT_SMBUS::set_undervoltage_protection().

◆ BATT_SMBUS_ENABLED_PROTECTIONS_A_CUV_DISABLED

#define BATT_SMBUS_ENABLED_PROTECTIONS_A_CUV_DISABLED   0xce

Definition at line 96 of file batt_smbus.h.

Referenced by BATT_SMBUS::set_undervoltage_protection().

◆ BATT_SMBUS_ENABLED_PROTECTIONS_A_DEFAULT

#define BATT_SMBUS_ENABLED_PROTECTIONS_A_DEFAULT   0xcf

Definition at line 95 of file batt_smbus.h.

Referenced by BATT_SMBUS::set_undervoltage_protection().

◆ BATT_SMBUS_FULL_CHARGE_CAPACITY

#define BATT_SMBUS_FULL_CHARGE_CAPACITY   0x10

capacity when fully charged

Definition at line 71 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_startup_info().

◆ BATT_SMBUS_LIFETIME_BLOCK_ONE

#define BATT_SMBUS_LIFETIME_BLOCK_ONE   0x0060

Definition at line 91 of file batt_smbus.h.

Referenced by BATT_SMBUS::lifetime_read_block_one().

◆ BATT_SMBUS_LIFETIME_FLUSH

#define BATT_SMBUS_LIFETIME_FLUSH   0x002E

Definition at line 90 of file batt_smbus.h.

Referenced by BATT_SMBUS::lifetime_data_flush().

◆ BATT_SMBUS_MANUFACTURE_DATE

#define BATT_SMBUS_MANUFACTURE_DATE   0x1B

manufacture date register

Definition at line 79 of file batt_smbus.h.

Referenced by BATT_SMBUS::manufacture_date().

◆ BATT_SMBUS_MANUFACTURER_ACCESS

#define BATT_SMBUS_MANUFACTURER_ACCESS   0x00

Definition at line 82 of file batt_smbus.h.

Referenced by BATT_SMBUS::unseal().

◆ BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS

#define BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS   0x44

◆ BATT_SMBUS_MANUFACTURER_DATA

#define BATT_SMBUS_MANUFACTURER_DATA   0x23

Definition at line 83 of file batt_smbus.h.

◆ BATT_SMBUS_MANUFACTURER_NAME

#define BATT_SMBUS_MANUFACTURER_NAME   0x20

manufacturer name

Definition at line 78 of file batt_smbus.h.

Referenced by BATT_SMBUS::manufacturer_name().

◆ BATT_SMBUS_MEASUREMENT_INTERVAL_US

#define BATT_SMBUS_MEASUREMENT_INTERVAL_US   100000

time in microseconds, measure at 10Hz

Definition at line 81 of file batt_smbus.h.

Referenced by BATT_SMBUS::resume(), and BATT_SMBUS::task_spawn().

◆ BATT_SMBUS_REMAINING_CAPACITY

#define BATT_SMBUS_REMAINING_CAPACITY   0x0F

predicted remaining battery capacity as a percentage

Definition at line 74 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_startup_info(), and BATT_SMBUS::Run().

◆ BATT_SMBUS_RUN_TIME_TO_EMPTY

#define BATT_SMBUS_RUN_TIME_TO_EMPTY   0x11

predicted remaining battery capacity based on the present rate of discharge in min

Definition at line 72 of file batt_smbus.h.

Referenced by BATT_SMBUS::Run().

◆ BATT_SMBUS_SEAL

#define BATT_SMBUS_SEAL   0x0030

Definition at line 93 of file batt_smbus.h.

Referenced by BATT_SMBUS::seal().

◆ BATT_SMBUS_SECURITY_KEYS

#define BATT_SMBUS_SECURITY_KEYS   0x0035

Definition at line 85 of file batt_smbus.h.

◆ BATT_SMBUS_SERIAL_NUMBER

#define BATT_SMBUS_SERIAL_NUMBER   0x1C

serial number register

Definition at line 80 of file batt_smbus.h.

Referenced by BATT_SMBUS::get_serial_number(), and BATT_SMBUS::get_startup_info().

◆ BATT_SMBUS_TEMP

#define BATT_SMBUS_TEMP   0x08

temperature register

Definition at line 69 of file batt_smbus.h.

Referenced by BATT_SMBUS::Run().

◆ BATT_SMBUS_VOLTAGE

#define BATT_SMBUS_VOLTAGE   0x09

voltage register

Definition at line 70 of file batt_smbus.h.

Referenced by BATT_SMBUS::Run().

◆ BATT_VOLTAGE_UNDERVOLTAGE_THRESHOLD

#define BATT_VOLTAGE_UNDERVOLTAGE_THRESHOLD   3.4f

Threshold in volts to re-enable undervoltage protection.

Definition at line 63 of file batt_smbus.h.

Referenced by BATT_SMBUS::set_undervoltage_protection().

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   32

◆ NUM_BUS_OPTIONS

#define NUM_BUS_OPTIONS   (sizeof(smbus_bus_options)/sizeof(smbus_bus_options[0]))

Definition at line 98 of file batt_smbus.h.

Enumeration Type Documentation

◆ BATT_SMBUS_BUS

Enumerator
BATT_SMBUS_BUS_ALL 
BATT_SMBUS_BUS_I2C_INTERNAL 
BATT_SMBUS_BUS_I2C_EXTERNAL 
BATT_SMBUS_BUS_I2C_EXTERNAL1 
BATT_SMBUS_BUS_I2C_EXTERNAL2 

Definition at line 100 of file batt_smbus.h.

Variable Documentation

◆ smbus_bus_options

struct batt_smbus_bus_option smbus_bus_options[]
Initial value:
= {
{ BATT_SMBUS_BUS_I2C_EXTERNAL, "/dev/batt_smbus_ext", PX4_I2C_BUS_EXPANSION},
}

Referenced by BATT_SMBUS::task_spawn().