foxBMS  1.0.0
The foxBMS Battery Management System API Documentation
mxm_17841b.h File Reference

Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip. More...

#include "mxm_cfg.h"
#include "mxm_bitextract.h"
Include dependency graph for mxm_17841b.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MXM_41B_INSTANCE
 Struct for the state-variable of state-machine. More...
 

Macros

#define MXM_SPI_TX_BUFFER_LENGTH   (8u)
 SPI TX buffer length. More...
 

Typedefs

typedef enum MXM_STATEMACH_41B MXM_STATEMACH_41B_e
 States of the MAX17841B state-machine. More...
 
typedef enum MXM_41B_SUBSTATES MXM_41B_SUBSTATES_e
 Substates of the MAX17841B state-machine. More...
 
typedef enum MXM_41B_STATE_REQUEST_STATUS MXM_41B_STATE_REQUEST_STATUS_e
 Request status of MAX17841B states. More...
 
typedef enum MXM_41B_REG_FUNCTION MXM_41B_REG_FUNCTION_e
 Register functions. More...
 
typedef struct MXM_41B_INSTANCE MXM_41B_INSTANCE_s
 Struct for the state-variable of state-machine. More...
 

Enumerations

enum  MXM_STATEMACH_41B {
  MXM_STATEMACH_41B_UNINITIALIZED, MXM_STATEMACH_41B_INIT, MXM_STATEMACH_41B_IDLE, MXM_STATEMACH_41B_CHECK_FMEA,
  MXM_STATEMACH_41B_GET_VERSION, MXM_STATEMACH_41B_WRITE_CONF_AND_INT_REGISTER, MXM_STATEMACH_41B_READ_STATUS_REGISTER, MXM_STATEMACH_41B_UART_TRANSACTION,
  MXM_STATEMACH_41B_CLEAR_RECEIVE_BUFFER, MXM_STATEMACH_41B_CLEAR_TRANSMIT_BUFFER, MXM_STATEMACH_41B_MAXSTATE
}
 States of the MAX17841B state-machine. More...
 
enum  MXM_41B_SUBSTATES {
  MXM_41B_ENTRY_SUBSTATE, MXM_41B_INIT_WRITE_DEFAULT_VALUES, MXM_41B_INIT_READ_CONFIG_REGISTERS, MXM_41B_INIT_CHECK_INITIALIZATION,
  MXM_41B_FMEA_REQUEST_REGISTER, MXM_41B_FMEA_VERIFY, MXM_41B_VERSION_REQUEST_REGISTER, MXM_41B_VERSION_VERIFY,
  MXM_41B_UART_WRITE_LOAD_QUEUE, MXM_41B_UART_READ_LOAD_QUEUE, MXM_41B_UART_VERIFY_LOAD_QUEUE_AND_TRANSMIT, MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_WRITE,
  MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_READ_AND_READ_BACK_RCV_BUF, MXM_41B_UART_READ_BACK_RECEIVE_BUFFER_SAVE, MXM_41B_READ_STATUS_REGISTER_SEND, MXM_41B_READ_STATUS_REGISTER_PROCESS
}
 Substates of the MAX17841B state-machine. More...
 
enum  MXM_41B_STATE_REQUEST_STATUS { MXM_41B_STATE_UNSENT, MXM_41B_STATE_UNPROCESSED, MXM_41B_STATE_PROCESSED, MXM_41B_STATE_ERROR }
 Request status of MAX17841B states. More...
 
enum  MXM_41B_REG_FUNCTION {
  MXM_41B_REG_FUNCTION_RX_BUSY_STATUS, MXM_41B_REG_FUNCTION_RX_STOP_STATUS, MXM_41B_REG_FUNCTION_RX_EMPTY_STATUS, MXM_41B_REG_FUNCTION_TX_PREAMBLES,
  MXM_41B_REG_FUNCTION_KEEP_ALIVE, MXM_41B_REG_FUNCTION_RX_ERROR_INT, MXM_41B_REG_FUNCTION_RX_OVERFLOW_INT
}
 Register functions. More...
 

Functions

STD_RETURN_TYPE_e MXM_41BWriteRegisterFunction (MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_FUNCTION_e registerFunction, MXM_41B_REG_BIT_VALUE value)
 Write a register function. More...
 
STD_RETURN_TYPE_e MXM_41BReadRegisterFunction (MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_FUNCTION_e registerFunction, MXM_41B_REG_BIT_VALUE *pValue)
 Read the value of a register function. More...
 
void MXM_41BStateMachine (MXM_41B_INSTANCE_s *pInstance)
 Execute state-machine for the MAX17841B. More...
 
STD_RETURN_TYPE_e MXM_41BSetStateRequest (MXM_41B_INSTANCE_s *pInstance, MXM_STATEMACH_41B_e state, uint16_t *pPayload, uint16_t payloadLength, uint8_t extendMessageBytes, uint16_t *pRxBuffer, uint16_t rxBufferLength, MXM_41B_STATE_REQUEST_STATUS_e *processed)
 Set state transition for MAX17841B-state-machine. More...
 

Variables

const uint8_t mxm_kConfig2EnableTransmitPreamblesMode41BRegister
 standard configuration for register config 2 More...
 
const uint8_t mxm_kConfig3KeepAlive160us41BRegister
 standard configuration for register config 3 More...
 
const uint8_t mxm_kRXInterruptEnableRXErrorRXOverflow41BRegister
 standard configuration for register rx interrupt More...
 

Detailed Description

Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.

BSD 3-Clause License 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
2018-12-14 (date of creation)
Updated
2020-06-22 (date of last update)
Prefix
MXM

def

Definition in file mxm_17841b.h.

Macro Definition Documentation

◆ MXM_SPI_TX_BUFFER_LENGTH

#define MXM_SPI_TX_BUFFER_LENGTH   (8u)

SPI TX buffer length.

This define defines the length of the SPI TX buffer. This TX buffer is declared in MXM_41B_INSTANCE_s::spiTXBuffer. The buffer has to be large enough to accommodate every relevant SPI transaction.

Definition at line 75 of file mxm_17841b.h.

Typedef Documentation

◆ MXM_41B_INSTANCE_s

Struct for the state-variable of state-machine.

This struct defines the state-variable of the MXM_41BStateMachine().

◆ MXM_41B_REG_FUNCTION_e

Register functions.

◆ MXM_41B_STATE_REQUEST_STATUS_e

Request status of MAX17841B states.

This enum describes the states that a state in the MXM_41BStateMachine() can have.

◆ MXM_41B_SUBSTATES_e

Substates of the MAX17841B state-machine.

◆ MXM_STATEMACH_41B_e

States of the MAX17841B state-machine.

Enumeration Type Documentation

◆ MXM_41B_REG_FUNCTION

Register functions.

Enumerator
MXM_41B_REG_FUNCTION_RX_BUSY_STATUS 
MXM_41B_REG_FUNCTION_RX_STOP_STATUS 
MXM_41B_REG_FUNCTION_RX_EMPTY_STATUS 
MXM_41B_REG_FUNCTION_TX_PREAMBLES 
MXM_41B_REG_FUNCTION_KEEP_ALIVE 
MXM_41B_REG_FUNCTION_RX_ERROR_INT 
MXM_41B_REG_FUNCTION_RX_OVERFLOW_INT 

Definition at line 133 of file mxm_17841b.h.

◆ MXM_41B_STATE_REQUEST_STATUS

Request status of MAX17841B states.

This enum describes the states that a state in the MXM_41BStateMachine() can have.

Enumerator
MXM_41B_STATE_UNSENT 

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

MXM_41B_STATE_UNPROCESSED 

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

MXM_41B_STATE_PROCESSED 

The request has been process successfully

MXM_41B_STATE_ERROR 

An error has occurred during processing of the request.

Definition at line 123 of file mxm_17841b.h.

◆ MXM_41B_SUBSTATES

Substates of the MAX17841B state-machine.

Enumerator
MXM_41B_ENTRY_SUBSTATE 
MXM_41B_INIT_WRITE_DEFAULT_VALUES 
MXM_41B_INIT_READ_CONFIG_REGISTERS 
MXM_41B_INIT_CHECK_INITIALIZATION 
MXM_41B_FMEA_REQUEST_REGISTER 
MXM_41B_FMEA_VERIFY 
MXM_41B_VERSION_REQUEST_REGISTER 
MXM_41B_VERSION_VERIFY 
MXM_41B_UART_WRITE_LOAD_QUEUE 
MXM_41B_UART_READ_LOAD_QUEUE 
MXM_41B_UART_VERIFY_LOAD_QUEUE_AND_TRANSMIT 
MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_WRITE 
MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_READ_AND_READ_BACK_RCV_BUF 
MXM_41B_UART_READ_BACK_RECEIVE_BUFFER_SAVE 
MXM_41B_READ_STATUS_REGISTER_SEND 
MXM_41B_READ_STATUS_REGISTER_PROCESS 

Definition at line 97 of file mxm_17841b.h.

◆ MXM_STATEMACH_41B

States of the MAX17841B state-machine.

Enumerator
MXM_STATEMACH_41B_UNINITIALIZED 

Uninitialized state that the state-machine starts in

MXM_STATEMACH_41B_INIT 

Initialization sequence, afterwards transitions into idle state

MXM_STATEMACH_41B_IDLE 

Idle state, transition into other states is available here

MXM_STATEMACH_41B_CHECK_FMEA 

Checks the FMEA register of MAX17841B.

MXM_STATEMACH_41B_GET_VERSION 

Retrieves the version of the connected ASCI.

MXM_STATEMACH_41B_WRITE_CONF_AND_INT_REGISTER 

Writes the copy of configuration and interrupt register to the MAX17841B.

MXM_STATEMACH_41B_READ_STATUS_REGISTER 

Reads the status registers of MAX17841B.

MXM_STATEMACH_41B_UART_TRANSACTION 

Sends a complete UART transaction.

MXM_STATEMACH_41B_CLEAR_RECEIVE_BUFFER 

Clears the receive buffer.

MXM_STATEMACH_41B_CLEAR_TRANSMIT_BUFFER 

Clears the transmit buffer

MXM_STATEMACH_41B_MAXSTATE 

Highest state

Definition at line 80 of file mxm_17841b.h.

Function Documentation

◆ MXM_41BReadRegisterFunction()

STD_RETURN_TYPE_e MXM_41BReadRegisterFunction ( MXM_41B_INSTANCE_s pInstance,
MXM_41B_REG_FUNCTION_e  registerFunction,
MXM_41B_REG_BIT_VALUE pValue 
)

Read the value of a register function.

Corresponding read-function to MXM_41BWriteRegisterFunction(). This function reads a value from the register-copy of MAX17841B and writes it into a supplied pointer. The register function is specified by the corresponding MXM_41B_REG_FUNCTION_e value.

This function implements only the needed subset of register functions.

Parameters
[in,out]pInstancepointer to the state of the MAX17841B-state-machine
[in]registerFunctionname of the function that shall be written
[out]pValuepointer to a variable in which the bits shall be written
Returns
STD_NOT_OK for unknown or unimplemented register function, otherwise STD_OK

Definition at line 391 of file mxm_17841b.c.

Here is the call graph for this function:

◆ MXM_41BSetStateRequest()

STD_RETURN_TYPE_e MXM_41BSetStateRequest ( MXM_41B_INSTANCE_s pInstance,
MXM_STATEMACH_41B_e  state,
uint16_t *  pPayload,
uint16_t  payloadLength,
uint8_t  extendMessageBytes,
uint16_t *  pRxBuffer,
uint16_t  rxBufferLength,
MXM_41B_STATE_REQUEST_STATUS_e processed 
)

Set state transition for MAX17841B-state-machine.

This function is used to transition into another state of the state-machine which is handled in MXM_41BStateMachine(). The user sets a state that should be transitioned into. For most states a payload and a payload-length can be supplied. The payload-length has to be consistent with the length in payload. Typically, this supplied payload describes the byte-sequence that should be written into the load-queue.

For the case of a e.g. READALL-command the message-length has to be stretched by the number of connected monitoring ICs times two. This is achieved by passing on extendMessageBytes.

In case that the state generates data that has to be handled in the higher layers, the pointer pRxBuffer will be used. Please make sure that the length of pRxBuffer is also consistent.

In order to determine success or failure of the requested state, the higher layer supplies a pointer into which the current status of the requested state will be written.

Parameters
[in,out]pInstancepointer to the state of the MAX17841B-state-machine
[in]statestate into which the state-machine shall transition
[in]pPayloadpointer to an array with data that will be processed in the requested state
[in]payloadLengthlength of the payload-array
[in]extendMessageBytesnumber of bytes that shall be appended by the ASCI
[out]pRxBufferpointer to an array that will be filled by the requested state with data that has to be processed in higher layers
[in]rxBufferLengthlength of the RX buffer array
[out]processedpointer of the status of the requested state
Returns
STD_NOT_OK for inconsistent input or forbidden state transitions, otherwise STD_OK

Definition at line 291 of file mxm_17841b.c.

◆ MXM_41BStateMachine()

void MXM_41BStateMachine ( MXM_41B_INSTANCE_s pInstance)

Execute state-machine for the MAX17841B.

This function executes the state-machine that communicates with the MAX17841B over SPI.

Definition at line 428 of file mxm_17841b.c.

Here is the call graph for this function:

◆ MXM_41BWriteRegisterFunction()

STD_RETURN_TYPE_e MXM_41BWriteRegisterFunction ( MXM_41B_INSTANCE_s pInstance,
MXM_41B_REG_FUNCTION_e  registerFunction,
MXM_41B_REG_BIT_VALUE  value 
)

Write a register function.

Functions of the ASCI are mapped onto parts of the register. This function is used to write the proper values into the register copy of the ASCI that is inside the driver. In order to use the function, provide the name of the ASCI function that you want to write (MXM_41B_REG_FUNCTION_e) and the value that should be written (MXM_41B_REG_BIT_VALUE). Currently, only a relevant subset of the ASCI features is implemented.

After updating the register copy, it has to be written to the ASCI memory. For the configuration registers this is done with the function MXM_41BConfigRegisterWrite(). This function is for example called in state MXM_STATEMACH_41B_WRITE_CONF_AND_INT_REGISTER.

Parameters
[in,out]pInstancepointer to the state of the MAX17841B-state-machine
[in]registerFunctionname of the function that shall be written
[in]valuevalue of the bits that shall be written
Returns
STD_NOT_OK for unknown or unimplemented register functions, otherwise STD_OK

Definition at line 347 of file mxm_17841b.c.

Here is the call graph for this function:

Variable Documentation

◆ mxm_kConfig2EnableTransmitPreamblesMode41BRegister

const uint8_t mxm_kConfig2EnableTransmitPreamblesMode41BRegister
extern

standard configuration for register config 2

Definition at line 83 of file mxm_17841b.c.

◆ mxm_kConfig3KeepAlive160us41BRegister

const uint8_t mxm_kConfig3KeepAlive160us41BRegister
extern

standard configuration for register config 3

Definition at line 84 of file mxm_17841b.c.

◆ mxm_kRXInterruptEnableRXErrorRXOverflow41BRegister

const uint8_t mxm_kRXInterruptEnableRXErrorRXOverflow41BRegister
extern

standard configuration for register rx interrupt

Definition at line 85 of file mxm_17841b.c.