foxBMS
1.1.0
The foxBMS Battery Management System API Documentation
|
Driver for the MAX17841B ASCI and MAX1785x monitoring chip. More...
Go to the source code of this file.
Functions | |
static STD_RETURN_TYPE_e | MXM_41BRegisterWrite (MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_ADD_t command, const uint8_t *const kpkPayload, uint16_t lengthPayload) |
Write one or multiple registers of MAX17841B. More... | |
static STD_RETURN_TYPE_e | MXM_41BRegisterRead (MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_ADD_t command, uint16_t *pRxBuffer, uint16_t length) |
Read one or multiple registers of MAX17841B. More... | |
static STD_RETURN_TYPE_e | MXM_41BConfigRegisterWrite (MXM_41B_INSTANCE_s *pInstance) |
Write the config register of MAX17841B. More... | |
static STD_RETURN_TYPE_e | MXM_41BBufferWrite (MXM_41B_INSTANCE_s *pInstance, const uint16_t *const kpkMessage, uint16_t message_length, uint8_t extend_message) |
Write a buffer transaction to 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... | |
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 (const MXM_41B_INSTANCE_s *const kpkInstance, 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... | |
Variables | |
static const uint8_t | mxm_41B_reg_default_values [7] = {0, 0, 0, 0x80, 0x60, 0x10, 0x0F} |
Default values for the configuration and interrupt registers. More... | |
const uint8_t | mxm_kConfig2EnableTransmitPreamblesMode41BRegister = 0x30 |
standard configuration for register config 2 More... | |
const uint8_t | mxm_kConfig3KeepAlive160us41BRegister = 0x05 |
standard configuration for register config 3 More... | |
const uint8_t | mxm_kRXInterruptEnableRXErrorRXOverflow41BRegister = 0x88 |
standard configuration for register rx interrupt More... | |
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_17841b.c.
|
static |
Write a buffer transaction to MAX17841B.
Writes into the load-queue-buffer. The supplied-message-length marks the length of the Battery Management Protocol message without any stuffing-bytes for read-commands. The extend_message parameter describes with how much bytes the command shall be stretched. This number will be added to the length of the command and written into the length field of the buffer. After this action the user has to select the next load queue with the appropriate command in order to mark the load queue as sendable.
[in,out] | pInstance | pointer to the state of the MAX17841B-state-machine |
[in] | kpkMessage | pointer to an array containing the message |
[in] | message_length | length of the supplied array |
[in] | extend_message | stretch the message by number of bytes |
Definition at line 260 of file mxm_17841b.c.
|
static |
Write the config register of MAX17841B.
This functions writes the config registers with the values from the local register copies. It puts together a buffer from these register values and calls MXM_41BRegisterWrite() with this data.
[in,out] | pInstance | state pointer |
Definition at line 244 of file mxm_17841b.c.
STD_RETURN_TYPE_e MXM_41BReadRegisterFunction | ( | const MXM_41B_INSTANCE_s *const | kpkInstance, |
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.
[in,out] | kpkInstance | pointer to the state of the MAX17841B-state-machine |
[in] | registerFunction | name of the function that shall be written |
[out] | pValue | pointer to a variable in which the bits shall be written |
Definition at line 391 of file mxm_17841b.c.
|
static |
Read one or multiple registers of MAX17841B.
This function puts together a SPI message consisting of command and bit-stuffing and writes it to the assigned SPI-interface.
The command should be one of the MXM_41B_REG_ADD_t commands. The function checks whether the chosen command is a read command.
The RX buffer length has to be consistent with the RX buffer. RX buffer lengths of one will read one register only. Longer RX buffers will read also from adjacent registers. Please see the MAX17841B-datasheet for reference.
[in,out] | pInstance | pointer to the state of the MAX17841B-state-machine |
[in] | command | register command of MXM_41B_REG_ADD_t |
[out] | pRxBuffer | pointer to an array into which read data will be written |
[in] | length | length of the RX buffer array |
Definition at line 219 of file mxm_17841b.c.
|
static |
Write one or multiple registers of MAX17841B.
This function puts together a SPI message consisting of command and payload and writes it to the assigned SPI interface.
The command should be one of the MXM_41B_REG_ADD_t commands. The function checks whether the chosen command is a write command.
The payload-length has to be consistent with the payload. Payload-lengths of one will write to one register only. Longer payloads will write to adjacent registers. Please see the MAX17841B-datasheet for reference.
[in,out] | pInstance | pointer to the state of the MAX17841B-state-machine |
[in] | command | register command of MXM_41B_REG_ADD_t |
[in] | kpkPayload | pointer to an array of data to be written |
[in] | lengthPayload | length of the payload array |
Definition at line 183 of file mxm_17841b.c.
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.
[in,out] | pInstance | pointer to the state of the MAX17841B-state-machine |
[in] | state | state into which the state-machine shall transition |
[in] | pPayload | pointer to an array with data that will be processed in the requested state |
[in] | payloadLength | length of the payload-array |
[in] | extendMessageBytes | number of bytes that shall be appended by the ASCI |
[out] | pRxBuffer | pointer to an array that will be filled by the requested state with data that has to be processed in higher layers |
[in] | rxBufferLength | length of the RX buffer array |
[out] | processed | pointer of the status of the requested state |
Definition at line 291 of file mxm_17841b.c.
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 429 of file mxm_17841b.c.
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.
[in,out] | pInstance | pointer to the state of the MAX17841B-state-machine |
[in] | registerFunction | name of the function that shall be written |
[in] | value | value of the bits that shall be written |
Definition at line 347 of file mxm_17841b.c.
|
static |
Default values for the configuration and interrupt registers.
This constant array contains the default values to which the configuration is compared when resetting it. The array is 7 entries long in order to fit onto the following registers which are placed in succession in the memory of MAX17841B:
Definition at line 80 of file mxm_17841b.c.
const uint8_t mxm_kConfig2EnableTransmitPreamblesMode41BRegister = 0x30 |
standard configuration for register config 2
Definition at line 83 of file mxm_17841b.c.
const uint8_t mxm_kConfig3KeepAlive160us41BRegister = 0x05 |
standard configuration for register config 3
Definition at line 84 of file mxm_17841b.c.
const uint8_t mxm_kRXInterruptEnableRXErrorRXOverflow41BRegister = 0x88 |
standard configuration for register rx interrupt
Definition at line 85 of file mxm_17841b.c.