foxBMS
1.2.1
The foxBMS Battery Management System API Documentation
|
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip. More...
#include "mxm_cfg.h"
#include "mxm_17841b.h"
#include "mxm_basic_defines.h"
#include "mxm_crc8.h"
#include "mxm_register_map.h"
Go to the source code of this file.
Data Structures | |
struct | MXM_5X_COMMAND_PAYLOAD_s |
Payload command. More... | |
struct | MXM_5X_INSTANCE_s |
5x statemachine structure More... | |
Macros | |
#define | COMMAND_BUFFER_LENGTH (10u) |
#define | MXM_5X_RX_BUFFER_LEN 100u |
#define | HELLOALL_START_SEED 0x00u |
#define | DATA_CHECK_BYTE_SEED 0x00u |
#define | BATTERY_MANAGEMENT_HELLOALL ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x57u) |
HELLOALL message. More... | |
#define | BATTERY_MANAGEMENT_ALERTPACKET ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x21u) |
ALERTPACKET message. More... | |
#define | BATTERY_MANAGEMENT_WRITEDEVICE ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x04u) |
WRITEDEVICE message (write single register of a single device) More... | |
#define | BATTERY_MANAGEMENT_WRITEALL ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x02u) |
WRITEALL message (write single register of all daisy-chain devices) More... | |
#define | BATTERY_MANAGEMENT_READDEVICE ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x05u) |
READDEVICE message (read single register of a single device) More... | |
#define | BATTERY_MANAGEMENT_READALL ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x03u) |
READALL message (read single register of all daisy-chain devices) More... | |
#define | BATTERY_MANAGEMENT_READBLOCK ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x06u) |
READBLOCK message (read block of registers of a single device) More... | |
#define | BATTERY_MANAGEMENT_DOWNHOST ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x09u) |
DOWNHOST message (make the downhost writing) More... | |
#define | BATTERY_MANAGEMENT_UPHOST ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x08u) |
UPHOST message (make the uphost writing, only useable on uphost line) More... | |
#define | BATTERY_MANAGEMENT_TX_LENGTH_READALL ((uint8_t)4u) |
Battery Management Protocol lengths of TX buffer. More... | |
Typedefs | |
typedef uint8_t | MXM_BATTERY_MANAGEMENT_COMMAND_t |
Type for Battery Management Protocol commands. More... | |
Functions | |
void | MXM_5XStateMachine (MXM_41B_INSTANCE_s *pInstance41b, MXM_5X_INSTANCE_s *pInstance5x) |
Execute state-machine for Battery Management Protocol. More... | |
MXM_DC_BYTE_e | MXM_5XGetLastDCByte (const MXM_5X_INSTANCE_s *const kpkInstance) |
Returns the last received DC byte. More... | |
STD_RETURN_TYPE_e | MXM_5XGetNumberOfSatellitesGood (const MXM_5X_INSTANCE_s *const kpkInstance) |
Get the value of MXM_5X_INSTANCE_s::numberOfSatellitesIsGood. More... | |
STD_RETURN_TYPE_e | MXM_5XGetRXBuffer (const MXM_5X_INSTANCE_s *const kpkInstance, uint8_t *rxBuffer, uint16_t rxBufferLength) |
Copy RX buffer into variable. More... | |
uint8_t | MXM_5XGetNumberOfSatellites (const MXM_5X_INSTANCE_s *const kpkInstance) |
Get number of satellites. More... | |
STD_RETURN_TYPE_e | MXM_5XSetStateRequest (MXM_5X_INSTANCE_s *pInstance5x, MXM_STATEMACHINE_5X_e state, MXM_5X_COMMAND_PAYLOAD_s commandPayload, MXM_5X_STATE_REQUEST_STATUS_e *processed) |
Set state request for the Battery Management Statemachine. More... | |
STD_RETURN_TYPE_e must_check_return | MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck (void) |
runs a selfcheck for the address space check More... | |
void | MXM_5X_InitializeStateStruct (MXM_5X_INSTANCE_s *pInstance) |
Initializes the state struct with default values. More... | |
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
def
Definition in file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_ALERTPACKET ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x21u) |
ALERTPACKET message.
Definition at line 97 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_DOWNHOST ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x09u) |
DOWNHOST message (make the downhost writing)
This feature is only useable on downhost line.
Definition at line 128 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_HELLOALL ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x57u) |
HELLOALL message.
Definition at line 92 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_READALL ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x03u) |
READALL message (read single register of all daisy-chain devices)
Definition at line 117 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_READBLOCK ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x06u) |
READBLOCK message (read block of registers of a single device)
Definition at line 122 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_READDEVICE ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x05u) |
READDEVICE message (read single register of a single device)
Definition at line 112 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_TX_LENGTH_READALL ((uint8_t)4u) |
Battery Management Protocol lengths of TX buffer.
Reference values for the lengths of the respective TX buffers for Battery Management Protocol messages.
length of a READALL command without stuffing bytes
Definition at line 144 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_UPHOST ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x08u) |
UPHOST message (make the uphost writing, only useable on uphost line)
Definition at line 133 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_WRITEALL ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x02u) |
WRITEALL message (write single register of all daisy-chain devices)
Definition at line 107 of file mxm_battery_management.h.
#define BATTERY_MANAGEMENT_WRITEDEVICE ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x04u) |
WRITEDEVICE message (write single register of a single device)
Definition at line 102 of file mxm_battery_management.h.
#define COMMAND_BUFFER_LENGTH (10u) |
length of the command buffer
Definition at line 71 of file mxm_battery_management.h.
#define DATA_CHECK_BYTE_SEED 0x00u |
seed for data check, should be 0x00u
Definition at line 79 of file mxm_battery_management.h.
#define HELLOALL_START_SEED 0x00u |
seed for helloall, should be 0x00u except for special edge cases
Definition at line 77 of file mxm_battery_management.h.
#define MXM_5X_RX_BUFFER_LEN 100u |
length of the rx buffer
Definition at line 74 of file mxm_battery_management.h.
typedef uint8_t MXM_BATTERY_MANAGEMENT_COMMAND_t |
Type for Battery Management Protocol commands.
This type describes the hex-numbers of all Maxim Battery Management Protocol commands. For details see the data sheet of MAX1785x devices.
Definition at line 87 of file mxm_battery_management.h.
Request status of Battery Management Protocol states.
This enum describes the states that a state in the MXM_5XStateMachine() can have.
Alternating bit patterns are used for better distinction and to make sure that there is no accidental overlap.
Definition at line 227 of file mxm_battery_management.h.
enum MXM_5X_SUBSTATES_e |
Sub-states of the Battery Management Protocol state-machine.
Enumerator | |
---|---|
MXM_5X_INIT_41B_INIT | initialization of the MAX17841 bridge IC |
MXM_5X_INIT_41B_GET_VERSION | retrieves the version of the bridge IC |
MXM_5X_INIT_WAIT_FOR_RESET | waits for the slave devices to be reset (due to disabled preambles) |
MXM_5X_INIT_ENABLE_RX_INTERRUPT_FLAGS | substate for the initialization, enable RX interrupt flags |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_CLEAR_RECEIVE_BUFFER | substate for the wake-up routine, clear the receive buffer in the bridge IC |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_EN_PREAMBLES | substate for the wake-up routine, enable the sending of preambles in order to wake up the daisy-chain devices |
MXM_5X_INIT_ENABLE_KEEP_ALIVE | enables keep alive mode (which will take over after en preambles is off) |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_WAIT_FOR_RX_STATUS_BUSY | substate for the wake-up routine, wait for the daisy-chain devices to return an answer, resulting in status RX busy of the bridge IC |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_DIS_PREAMBLES | substate for the wake-up routine, disable the sending of preambles |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_WAIT_FOR_RX_STATUS_EMPTY | substate for the wake-up routine, wait for the RX transmission to finish |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_CLEAR_TRANSMIT_BUFFER | substate for the wake-up routine, clear the transmit buffer |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_CLEAR_RECEIVE_BUFFER_2 | substate for the wake-up routine, clear the receive buffer |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_HELLOALL | substate for the wake-up routine, sending helloall to the daisy-chain |
MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_HELLOALL_VERIFY_MSG_AND_COUNT | substate for the wake-up routine, verifying the result of helloall |
MXM_5X_41B_FMEA_REQUEST | substate for requesting an FMEA check on the bridge IC |
MXM_5X_41B_FMEA_CHECK | substate for the verification of the FMEA check done in MXM_5X_41B_FMEA_REQUEST |
MXM_5X_WRITEALL_UART_TRANSACTION | substate for the initiation of a uart transaction for the WRITEALL command |
MXM_5X_WRITEALL_UART_VERIFY_BUFFER | substate for the verifying the buffer of a WRITEALL transaction |
MXM_5X_WRITE_DEVICE_UART_TRANSACTION | substate for the initiation of a uart transaction for the WRITEALL command |
MXM_5X_WRITE_DEVICE_CHECK_CRC | substate for checking the received CRC in a WRITEDEVICE transaction |
MXM_5X_READALL_UART_TRANSACTION | substate for the initiation of a uart transaction for the READALL command |
MXM_5X_READALL_CHECK_CRC | substate for checking the received CRC in a READALL transaction |
MXM_5X_READALL_GET_DC | substate for retrieving the data check byte from a READALL transaction |
MXM_5X_ENTRY_SUBSTATE | default value indicating no selected substate; has to be last substate in enum |
Definition at line 163 of file mxm_battery_management.h.
States of the Battery Management Protocol state-machine.
Definition at line 149 of file mxm_battery_management.h.
void MXM_5X_InitializeStateStruct | ( | MXM_5X_INSTANCE_s * | pInstance | ) |
Initializes the state struct with default values.
This function is called through the startup of the driver in order to ensure proper default values.
[out] | pInstance | instance of the state struct that shall be initialized |
Definition at line 945 of file mxm_battery_management.c.
MXM_DC_BYTE_e MXM_5XGetLastDCByte | ( | const MXM_5X_INSTANCE_s *const | kpkInstance | ) |
Returns the last received DC byte.
[in] | kpkInstance | pointer to the instance struct |
Definition at line 994 of file mxm_battery_management.c.
uint8_t MXM_5XGetNumberOfSatellites | ( | const MXM_5X_INSTANCE_s *const | kpkInstance | ) |
Get number of satellites.
Getter-function for the number of satellites (variable MXM_5X_INSTANCE_s::numberOfSatellites).
[in] | kpkInstance | pointer to the state struct |
Definition at line 999 of file mxm_battery_management.c.
STD_RETURN_TYPE_e MXM_5XGetNumberOfSatellitesGood | ( | const MXM_5X_INSTANCE_s *const | kpkInstance | ) |
Get the value of MXM_5X_INSTANCE_s::numberOfSatellitesIsGood.
[in] | kpkInstance | pointer to the instance struct |
Definition at line 1006 of file mxm_battery_management.c.
STD_RETURN_TYPE_e MXM_5XGetRXBuffer | ( | const MXM_5X_INSTANCE_s *const | kpkInstance, |
uint8_t * | rxBuffer, | ||
uint16_t | rxBufferLength | ||
) |
Copy RX buffer into variable.
This function copies the RX buffer which is locally available in the MXM_5XStateMachine() into a supplied array pointer. It will make sure that both the length of the local as also the supplied length of the RX buffer are not violated. In case of the supplied RX buffer being longer than the locally available one, the remaining entries of the buffer will be filled with 0.
[in,out] | kpkInstance | pointer to the state-struct |
[in] | rxBuffer | array-pointer to a RX buffer that shall be filled |
[in] | rxBufferLength | length of the supplied array |
Definition at line 973 of file mxm_battery_management.c.
STD_RETURN_TYPE_e MXM_5XSetStateRequest | ( | MXM_5X_INSTANCE_s * | pInstance5x, |
MXM_STATEMACHINE_5X_e | state, | ||
MXM_5X_COMMAND_PAYLOAD_s | commandPayload, | ||
MXM_5X_STATE_REQUEST_STATUS_e * | processed | ||
) |
Set state request for the Battery Management Statemachine.
This function sets the state requests for the MXM_5XStateMachine().
[in,out] | pInstance5x | pointer to the 5x state |
[in] | state | State that is requested |
[in] | commandPayload | additional payload that is handled by the state |
[in,out] | processed | pointer to the status of the request |
Definition at line 1011 of file mxm_battery_management.c.
void MXM_5XStateMachine | ( | MXM_41B_INSTANCE_s * | pInstance41b, |
MXM_5X_INSTANCE_s * | pInstance5x | ||
) |
Execute state-machine for Battery Management Protocol.
This function executes the state-machine that exposes an interface for the Maxim Battery Management Protocol for monitoring ICs of the MAX1785x family.
Definition at line 1044 of file mxm_battery_management.c.
STD_RETURN_TYPE_e must_check_return MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck | ( | void | ) |
runs a selfcheck for the address space check
Runs a selfcheck for the function which is checking if a register address is inside the user accessible address space of the monitoring IC.
Definition at line 1086 of file mxm_battery_management.c.