foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
mxm_battery_management.h File Reference

Headers for the driver for the MAX17841B ASCI and MAX1785x analog front-end. More...

#include "general.h"
#include "mxm_cfg.h"
#include "fstd_types.h"
#include "mxm_17841b.h"
#include "mxm_basic_defines.h"
#include "mxm_crc8.h"
#include "mxm_register_map.h"
#include <stdint.h>
Include dependency graph for mxm_battery_management.h:
This graph shows which files directly or indirectly include this file:

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 state machine 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...
 

Enumerations

enum  MXM_STATEMACHINE_5X_e {
  MXM_STATEMACH_5X_UNINITIALIZED , MXM_STATEMACH_5X_INIT , MXM_STATEMACH_5X_41B_FMEA_CHECK , MXM_STATEMACH_5X_IDLE ,
  MXM_STATEMACH_5X_WRITEALL , MXM_STATEMACH_5X_WRITE_DEVICE , MXM_STATEMACH_5X_READALL , MXM_STATEMACH_5X_MAXSTATE
}
 States of the Battery Management Protocol state-machine. More...
 
enum  MXM_5X_SUBSTATES_e {
  MXM_5X_INIT_41B_INIT , MXM_5X_INIT_41B_GET_VERSION , MXM_5X_INIT_WAIT_FOR_RESET , MXM_5X_INIT_ENABLE_RX_INTERRUPT_FLAGS ,
  MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_CLEAR_RECEIVE_BUFFER , MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_EN_PREAMBLES , MXM_5X_INIT_ENABLE_KEEP_ALIVE , MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_WAIT_FOR_RX_STATUS_BUSY ,
  MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_DIS_PREAMBLES , MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_WAIT_FOR_RX_STATUS_EMPTY , MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_CLEAR_TRANSMIT_BUFFER , MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_CLEAR_RECEIVE_BUFFER_2 ,
  MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_HELLOALL , MXM_5X_INIT_WAKE_UP_SATELLITE_DEVICES_HELLOALL_VERIFY_MSG_AND_COUNT , MXM_5X_41B_FMEA_REQUEST , MXM_5X_41B_FMEA_CHECK ,
  MXM_5X_WRITE_UART_TRANSACTION , MXM_5X_WRITE_CHECK_CRC , MXM_5X_READALL_UART_TRANSACTION , MXM_5X_READALL_CHECK_CRC ,
  MXM_5X_READALL_GET_DC , MXM_5X_ENTRY_SUBSTATE
}
 Sub-states of the Battery Management Protocol state-machine. More...
 
enum  MXM_5X_STATE_REQUEST_STATUS_e { MXM_5X_STATE_UNSENT = 0x56 , MXM_5X_STATE_UNPROCESSED , MXM_5X_STATE_PROCESSED = 0x9A , MXM_5X_STATE_ERROR = 0xAB }
 Request status of Battery Management Protocol states. 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 GEN_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...
 

Detailed Description

Headers for the driver for the MAX17841B ASCI and MAX1785x analog front-end.

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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2019-01-14 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
MXM

def

Definition in file mxm_battery_management.h.

Macro Definition Documentation

◆ BATTERY_MANAGEMENT_ALERTPACKET

#define BATTERY_MANAGEMENT_ALERTPACKET   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x21u)

ALERTPACKET message.

Definition at line 103 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_DOWNHOST

#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 134 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_HELLOALL

#define BATTERY_MANAGEMENT_HELLOALL   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x57u)

HELLOALL message.

Definition at line 98 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_READALL

#define BATTERY_MANAGEMENT_READALL   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x03u)

READALL message (read single register of all daisy-chain devices)

Definition at line 123 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_READBLOCK

#define BATTERY_MANAGEMENT_READBLOCK   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x06u)

READBLOCK message (read block of registers of a single device)

Definition at line 128 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_READDEVICE

#define BATTERY_MANAGEMENT_READDEVICE   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x05u)

READDEVICE message (read single register of a single device)

Definition at line 118 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_TX_LENGTH_READALL

#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 150 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_UPHOST

#define BATTERY_MANAGEMENT_UPHOST   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x08u)

UPHOST message (make the uphost writing, only useable on uphost line)

Definition at line 139 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_WRITEALL

#define BATTERY_MANAGEMENT_WRITEALL   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x02u)

WRITEALL message (write single register of all daisy-chain devices)

Definition at line 113 of file mxm_battery_management.h.

◆ BATTERY_MANAGEMENT_WRITEDEVICE

#define BATTERY_MANAGEMENT_WRITEDEVICE   ((MXM_BATTERY_MANAGEMENT_COMMAND_t)0x04u)

WRITEDEVICE message (write single register of a single device)

Definition at line 108 of file mxm_battery_management.h.

◆ COMMAND_BUFFER_LENGTH

#define COMMAND_BUFFER_LENGTH   (10u)

length of the command buffer

Definition at line 77 of file mxm_battery_management.h.

◆ DATA_CHECK_BYTE_SEED

#define DATA_CHECK_BYTE_SEED   0x00u

seed for data check, should be 0x00u

Definition at line 85 of file mxm_battery_management.h.

◆ HELLOALL_START_SEED

#define HELLOALL_START_SEED   0x00u

seed for helloall, should be 0x00u except for special edge cases

Definition at line 83 of file mxm_battery_management.h.

◆ MXM_5X_RX_BUFFER_LEN

#define MXM_5X_RX_BUFFER_LEN   100u

length of the rx buffer

Definition at line 80 of file mxm_battery_management.h.

Typedef Documentation

◆ 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 93 of file mxm_battery_management.h.

Enumeration Type Documentation

◆ MXM_5X_STATE_REQUEST_STATUS_e

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.

Enumerator
MXM_5X_STATE_UNSENT 

The request has not been sent to the state-machine yet.

MXM_5X_STATE_UNPROCESSED 

The request has been received by the state-machine, but not been processed yet.

MXM_5X_STATE_PROCESSED 

The request has been process successfully

MXM_5X_STATE_ERROR 

An error has occurred during processing of the request.

Definition at line 228 of file mxm_battery_management.h.

◆ 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_WRITE_UART_TRANSACTION 

substate for the initiation of a uart transaction for the WRITEALL and WRITEDEVICE command

MXM_5X_WRITE_CHECK_CRC 

substate for checking the received CRC in a WRITEALL/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 169 of file mxm_battery_management.h.

◆ MXM_STATEMACHINE_5X_e

States of the Battery Management Protocol state-machine.

Enumerator
MXM_STATEMACH_5X_UNINITIALIZED 

Uninitialized state that the state-machine starts in

MXM_STATEMACH_5X_INIT 

Initialization state

MXM_STATEMACH_5X_41B_FMEA_CHECK 

Requests a FMEA-check from the 41B-state-machine

MXM_STATEMACH_5X_IDLE 

Idle state, transitions are possible in this state

MXM_STATEMACH_5X_WRITEALL 

WRITEALL state, sends a WRITEALL to the daisy-chain

MXM_STATEMACH_5X_WRITE_DEVICE 

WRITEDEVICE state, sends a WRITEDEVICE to a specific address

MXM_STATEMACH_5X_READALL 

READALL state, sends a READALL to the daisy-chain

MXM_STATEMACH_5X_MAXSTATE 

Highest state

Definition at line 155 of file mxm_battery_management.h.

Function Documentation

◆ MXM_5X_InitializeStateStruct()

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.

Parameters
[out]pInstanceinstance of the state struct that shall be initialized

Definition at line 926 of file mxm_battery_management.c.

◆ MXM_5XGetLastDCByte()

MXM_DC_BYTE_e MXM_5XGetLastDCByte ( const MXM_5X_INSTANCE_s *const  kpkInstance)

Returns the last received DC byte.

Parameters
[in]kpkInstancepointer to the instance struct

Definition at line 977 of file mxm_battery_management.c.

◆ MXM_5XGetNumberOfSatellites()

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).

Parameters
[in]kpkInstancepointer to the state struct
Returns
value of MXM_5X_INSTANCE_s::numberOfSatellites

Definition at line 982 of file mxm_battery_management.c.

◆ MXM_5XGetNumberOfSatellitesGood()

STD_RETURN_TYPE_e MXM_5XGetNumberOfSatellitesGood ( const MXM_5X_INSTANCE_s *const  kpkInstance)

Get the value of MXM_5X_INSTANCE_s::numberOfSatellitesIsGood.

Parameters
[in]kpkInstancepointer to the instance struct
Returns
MXM_5X_INSTANCE_s::numberOfSatellitesIsGood

Definition at line 989 of file mxm_battery_management.c.

◆ MXM_5XGetRXBuffer()

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.

Parameters
[in,out]kpkInstancepointer to the state-struct
[in]rxBufferarray-pointer to a RX buffer that shall be filled
[in]rxBufferLengthlength of the supplied array
Returns
STD_NOT_OK for rxBuffer being a NULL_PTR or rxBufferLength having length 0

Definition at line 954 of file mxm_battery_management.c.

◆ MXM_5XSetStateRequest()

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().

Parameters
[in,out]pInstance5xpointer to the 5x state
[in]stateState that is requested
[in]commandPayloadadditional payload that is handled by the state
[in,out]processedpointer to the status of the request
Returns
STD_OK if the request has been successfully placed, STD_NOT_OK if not

Definition at line 994 of file mxm_battery_management.c.

◆ MXM_5XStateMachine()

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 1031 of file mxm_battery_management.c.

Here is the call graph for this function:

◆ MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck()

STD_RETURN_TYPE_e GEN_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.

Returns
STD_OK if the selfcheck has been successful

Definition at line 1073 of file mxm_battery_management.c.

Here is the call graph for this function: