foxBMS - Unit Tests
1.2.1
The foxBMS Unit Tests API Documentation
|
Driver for the MAX17841B ASCI and MAX1785x monitoring chip. More...
Go to the source code of this file.
Macros | |
#define | MXM_5X_ERROR_THRESHOLD (3u) |
#define | MXM_5X_SLAVE_SHUTDOWN_TIMEOUT_MS (400u) |
#define | MXM_5X_BIT_MASK_ONE_BYTE (0xFFu) |
#define | MXM_5X_BIT_MASK_WRITE_DEVICE_ADDRESS ((uint16_t)0xF8u) |
bit masks for writing the device address in write device command More... | |
#define | HELLOALL_TX_LENGTH (3u) |
#define | HELLOALL_RX_LENGTH HELLOALL_TX_LENGTH |
Functions | |
static void | MXM_5XClearCommandBuffer (MXM_5X_INSTANCE_s *pInstance) |
Clear the command-buffer. More... | |
static STD_RETURN_TYPE_e | MXM_5XIsUserAccessibleRegister (uint8_t regAddress, MXM_MODEL_ID_e model) |
Check if a register address is user accessible. More... | |
static STD_RETURN_TYPE_e | MXM_52IsUserAccessibleRegister (uint8_t regAddress) |
Check if a register address is user accessible in MAX17852. More... | |
static STD_RETURN_TYPE_e | MXM_53IsUserAccessibleRegister (uint8_t regAddress) |
Check if a register address is user accessible in MAX17853. More... | |
static void | MXM_5XConstructCommandBufferHelloall (MXM_5X_INSTANCE_s *pInstance) |
clears the command buffer and writes HELLOALL into the buffer More... | |
static STD_RETURN_TYPE_e | MXM_5XConstructCommandBufferWriteall (MXM_5X_INSTANCE_s *pInstance) |
clears the command buffer and writes WRITEALL into the buffer More... | |
static STD_RETURN_TYPE_e | MXM_5XConstructCommandBufferWriteDevice (MXM_5X_INSTANCE_s *pInstance) |
clears the command buffer and writes a WRITEDEVICE message More... | |
static STD_RETURN_TYPE_e | MXM_5XConstructCommandBufferReadall (MXM_5X_INSTANCE_s *pInstance) |
clears the command buffer and writes READALL into the buffer More... | |
static void | MXM_5XHandle41BErrorState (MXM_5X_INSTANCE_s *pInstance) |
handles the error of the underlying state-machine (by resetting it and counting the error) More... | |
static void | MXM_5XTransitionToSubstate (MXM_5X_INSTANCE_s *pInstance, MXM_5X_SUBSTATES_e substate) |
sets all internal state variables so that upon next execution the next substate is entered More... | |
static void | MXM_5XRepeatCurrentSubstate (MXM_5X_INSTANCE_s *pInstance) |
repeat the current substate (by resetting to the entry state) More... | |
static void | MXM_5XSignalSuccess (MXM_5X_INSTANCE_s *pInstance) |
Signal that a chain of substates has been successfully handled. More... | |
static void | MXM_5XSignalError (MXM_5X_INSTANCE_s *pInstance) |
Signal that an error has occurred in a chain of substates. More... | |
static void | MXM_5XStateHandler41BFmeaCheck (MXM_5X_INSTANCE_s *pInstance5x, MXM_41B_INSTANCE_s *pInstance41b) |
Handle the state MXM_STATEMACH_5X_41B_FMEA_CHECK. More... | |
static void | MXM_5XStateHandlerInit (MXM_5X_INSTANCE_s *pInstance5x, MXM_41B_INSTANCE_s *pInstance41b) |
Handle the state MXM_STATEMACH_5X_INIT. More... | |
static void | MXM_5XStateHandlerWriteAll (MXM_5X_INSTANCE_s *pInstance5x, MXM_41B_INSTANCE_s *pInstance41b) |
Handle the state MXM_STATEMACH_5X_WRITEALL. More... | |
static void | MXM_5XStateHandlerWriteDevice (MXM_5X_INSTANCE_s *pInstance5x, MXM_41B_INSTANCE_s *pInstance41b) |
Handle the state MXM_STATEMACH_5X_WRITE_DEVICE. More... | |
static void | MXM_5XStateHandlerReadAll (MXM_5X_INSTANCE_s *pInstance5x, MXM_41B_INSTANCE_s *pInstance41b) |
Handle the state MXM_STATEMACH_5X_READALL. More... | |
void | MXM_5X_InitializeStateStruct (MXM_5X_INSTANCE_s *pInstance) |
Initializes the state struct with default values. 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... | |
MXM_DC_BYTE_e | MXM_5XGetLastDCByte (const MXM_5X_INSTANCE_s *const kpkInstance) |
Returns the last received DC byte. More... | |
uint8_t | MXM_5XGetNumberOfSatellites (const MXM_5X_INSTANCE_s *const kpkInstance) |
Get number of satellites. 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_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... | |
void | MXM_5XStateMachine (MXM_41B_INSTANCE_s *pInstance41b, MXM_5X_INSTANCE_s *pInstance5x) |
Execute state-machine for Battery Management Protocol. More... | |
STD_RETURN_TYPE_e must_check_return | MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck (void) |
runs a selfcheck for the address space check 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_battery_management.c.
#define HELLOALL_RX_LENGTH HELLOALL_TX_LENGTH |
length of the helloall command
Definition at line 65 of file mxm_battery_management.c.
#define HELLOALL_TX_LENGTH (3u) |
length of the helloall command
Definition at line 64 of file mxm_battery_management.c.
#define MXM_5X_BIT_MASK_ONE_BYTE (0xFFu) |
(uint8_t) one byte bit mask
Definition at line 75 of file mxm_battery_management.c.
#define MXM_5X_BIT_MASK_WRITE_DEVICE_ADDRESS ((uint16_t)0xF8u) |
bit masks for writing the device address in write device command
Definition at line 80 of file mxm_battery_management.c.
#define MXM_5X_ERROR_THRESHOLD (3u) |
threshold above which an error handling procedure is triggered
Definition at line 69 of file mxm_battery_management.c.
#define MXM_5X_SLAVE_SHUTDOWN_TIMEOUT_MS (400u) |
time in milliseconds that should be waited in order to ensure that the slaves shut off
Definition at line 72 of file mxm_battery_management.c.
|
static |
Check if a register address is user accessible in MAX17852.
Checks if a register address is inside the user accessible memory range. This range is specified in the data sheet of the monitoring IC.
[in] | regAddress | register address to be checked |
Definition at line 284 of file mxm_battery_management.c.
|
static |
Check if a register address is user accessible in MAX17853.
Checks if a register address is inside the user accessible memory range. This range is specified in the data sheet of the monitoring IC as the following:
[in] | regAddress | register address to be checked |
Definition at line 300 of file mxm_battery_management.c.
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.
|
static |
Clear the command-buffer.
Clears MXM_5X_INSTANCE_s::commandBuffer by writing 0x00 to every entry.
[in,out] | pInstance | pointer to the state-struct |
Definition at line 251 of file mxm_battery_management.c.
|
static |
clears the command buffer and writes HELLOALL into the buffer
Fills the command buffer with a HELLOALL message after having it cleaned.
[in,out] | pInstance | pointer to the state-struct |
Definition at line 317 of file mxm_battery_management.c.
|
static |
clears the command buffer and writes READALL into the buffer
Fills the command buffer with a READALL command. This command retrieves the LSB and MSB of exactly one register of every device in the daisy-chain. The data to be written has to be set before calling this function in MXM_5X_INSTANCE_s::commandPayload.
[in,out] | pInstance | pointer to the state-struct |
Definition at line 386 of file mxm_battery_management.c.
|
static |
clears the command buffer and writes WRITEALL into the buffer
Fills the command buffer with a WRITEALL command. This command writes the same lsb and msb to every satellite in the daisy-chain in the same register. The data to be written has to be set before calling this function in MXM_5X_INSTANCE_s::commandPayload.
[in,out] | pInstance | pointer to the state-struct |
Definition at line 326 of file mxm_battery_management.c.
|
static |
clears the command buffer and writes a WRITEDEVICE message
Fills the command buffer with a WRITEDEVICE message. This message is addressed to one specific device in the daisy-chain. Therefore the address of the device has to be supplied together with the register and the data that should be written. The data to be written has to be set before calling this function in MXM_5X_INSTANCE_s::commandPayload.
[in,out] | pInstance | pointer to the state-struct |
Definition at line 352 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.
|
static |
handles the error of the underlying state-machine (by resetting it and counting the error)
[in,out] | pInstance | pointer to the state-struct |
Definition at line 418 of file mxm_battery_management.c.
|
static |
Check if a register address is user accessible.
Checks if a register address is inside the user accessible memory range. This range is specified in the data sheet of the monitoring IC as following:
[in] | regAddress | register address to be checked |
[in] | model | model id of the IC that shall be addressed |
Definition at line 259 of file mxm_battery_management.c.
|
static |
repeat the current substate (by resetting to the entry state)
[out] | pInstance | pointer to the state-struct |
Definition at line 437 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.
|
static |
Signal that an error has occurred in a chain of substates.
[out] | pInstance | pointer to the state-struct |
Definition at line 452 of file mxm_battery_management.c.
|
static |
Signal that a chain of substates has been successfully handled.
[out] | pInstance | pointer to the state-struct |
Definition at line 443 of file mxm_battery_management.c.
|
static |
Handle the state MXM_STATEMACH_5X_41B_FMEA_CHECK.
[in,out] | pInstance5x | pointer to the state-struct of the battery management state machine |
[in,out] | pInstance41b | pointer to the state-struct of the bridge IC |
Definition at line 461 of file mxm_battery_management.c.
|
static |
Handle the state MXM_STATEMACH_5X_INIT.
[in,out] | pInstance5x | pointer to the state-struct of the battery management state machine |
[in,out] | pInstance41b | pointer to the state-struct of the bridge IC |
Definition at line 490 of file mxm_battery_management.c.
|
static |
Handle the state MXM_STATEMACH_5X_READALL.
[in,out] | pInstance5x | pointer to the state-struct of the battery management state machine |
[in,out] | pInstance41b | pointer to the state-struct of the bridge IC |
Definition at line 886 of file mxm_battery_management.c.
|
static |
Handle the state MXM_STATEMACH_5X_WRITEALL.
[in,out] | pInstance5x | pointer to the state-struct of the battery management state machine |
[in,out] | pInstance41b | pointer to the state-struct of the bridge IC |
Definition at line 817 of file mxm_battery_management.c.
|
static |
Handle the state MXM_STATEMACH_5X_WRITE_DEVICE.
[in,out] | pInstance5x | pointer to the state-struct of the battery management state machine |
[in,out] | pInstance41b | pointer to the state-struct of the bridge IC |
Definition at line 852 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.
|
static |
sets all internal state variables so that upon next execution the next substate is entered
[out] | pInstance | pointer to the state-struct |
[in] | substate | identifier of the next substate |
Definition at line 427 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.