66 #define MXM_41B_BIT_SHIFT_HALF_BYTE (4u)
69 #define MXM_41B_BIT_MASK_LOW_NIBBLE (0xFu)
72 #define MXM_41B_BIT_MASK_HIGH_NIBBLE (0xF0u)
75 #define MXM_41B_BIT_MASK_ONE_BYTE (0xFFu)
78 #define MXM_41B_WAIT_COUNTER_THRESHOLD (75u)
79 #if MXM_41B_WAIT_COUNTER_THRESHOLD > (UINT8_MAX - 1)
80 #error "invalid wait counter threshold (counter is implemented in uint8_t)"
86 #define MXM_41B_BRIDGE_RESET_TIME_MS (100u)
93 #define MXM_41B_CONFIG_REGISTER_LENGTH (7u)
125 const uint8_t *
const kpkPayload,
126 uint8_t lengthPayload);
193 const uint16_t *
const kpkMessage,
194 uint8_t messageLength,
195 uint8_t extendMessage);
289 const uint8_t *
const kpkPayload,
290 uint8_t lengthPayload) {
299 if ((command % 2u) == 0u) {
303 if ((kpkPayload !=
NULL_PTR) && (lengthPayload != 0u)) {
304 for (uint8_t i = 0u; i < lengthPayload; i++) {
313 }
else if ((kpkPayload ==
NULL_PTR) && (lengthPayload == 0u)) {
337 if ((command % 2u) != 0u) {
360 mxm_spi_temp_buffer[4u] = pInstance->
regConfig1;
361 mxm_spi_temp_buffer[5u] = pInstance->
regConfig2;
362 mxm_spi_temp_buffer[6u] = pInstance->
regConfig3;
372 const uint16_t *
const kpkMessage,
373 uint8_t messageLength,
374 uint8_t extendMessage) {
385 pInstance->
spiTXBuffer[1] = (uint16_t)messageLength + extendMessage;
390 if (i < messageLength) {
444 const bool resetTimeHasPassed =
446 if (resetTimeHasPassed) {
493 if (pInstance->
spiRXBuffer[i + 1u] != mxm_41B_reg_default_values[i]) {
710 if (i < pInstance->rxBufferLength) {
738 if (pInstance->
regFmea == 0u) {
788 uint8_t payloadLength,
789 uint8_t extendMessageBytes,
791 uint16_t rxBufferLength,
806 }
else if ((pPayload ==
NULL_PTR) && (payloadLength != 0u)) {
808 }
else if ((payloadLength == 0u) && (pPayload !=
NULL_PTR)) {
810 }
else if ((pRxBuffer ==
NULL_PTR) && (rxBufferLength != 0u)) {
812 }
else if ((rxBufferLength == 0u) && (pRxBuffer !=
NULL_PTR)) {
818 pInstance->
state = state;
831 pInstance->
state = state;
858 switch (registerFunction) {
902 switch (registerFunction) {
936 switch (pInstance->
state) {
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
#define FAS_STATIC_ASSERT(cond, msg)
#define NULL_PTR
Null pointer.
static void MXM_41BStateHandlerClearTransmitBuffer(MXM_41B_INSTANCE_s *pInstance)
state handler for "clear transmit buffer"
static void MXM_41BStateHandlerIdle(MXM_41B_INSTANCE_s *pInstance)
state handler for "idle"
static void MXM_41BStateHandlerClearReceiveBuffer(MXM_41B_INSTANCE_s *pInstance)
state handler for "clear receive buffer"
static void MXM_41BStateHandlerUartTransaction(MXM_41B_INSTANCE_s *pInstance)
state handler for "uart transaction"
static void MXM_41BStateHandlerWriteConfAndIntRegister(MXM_41B_INSTANCE_s *pInstance)
state handler for "write conf and int register"
static void MXM_41BStateHandlerReadStatusRegister(MXM_41B_INSTANCE_s *pInstance)
state handler for "read status register"
static void MXM_41BStateHandlerGetVersion(MXM_41B_INSTANCE_s *pInstance)
state handler for "get version"
static void MXM_41BStateHandlerCheckFmea(MXM_41B_INSTANCE_s *pInstance)
state handler for "check fmea"
static void MXM_41BStateHandlerInit(MXM_41B_INSTANCE_s *pInstance)
init state handler
STD_RETURN_TYPE_e MXM_41BSetStateRequest(MXM_41B_INSTANCE_s *pInstance, MXM_STATEMACH_41B_e state, uint16_t *pPayload, uint8_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.
void MXM_41BStateMachine(MXM_41B_INSTANCE_s *pInstance)
Execute state-machine for the MAX17841B.
static STD_RETURN_TYPE_e MXM_41BRegisterWrite(MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_ADD_t command, const uint8_t *const kpkPayload, uint8_t lengthPayload)
Write one or multiple registers of MAX17841B.
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.
static STD_RETURN_TYPE_e MXM_41BConfigRegisterWrite(MXM_41B_INSTANCE_s *pInstance)
Write the config register of MAX17841B.
static void MXM_41BTransitionToIdleError(MXM_41B_INSTANCE_s *pInstance)
Transition into idle, mark as an error occurred.
static void MXM_41BInitializeRegisterCopies(MXM_41B_INSTANCE_s *pInstance)
Reset register copies to default.
static STD_RETURN_TYPE_e MXM_41BRegisterRead(MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_ADD_t command, uint16_t *pRxBuffer, uint8_t length)
Read one or multiple registers of MAX17841B.
#define MXM_41B_CONFIG_REGISTER_LENGTH
#define MXM_41B_BIT_MASK_HIGH_NIBBLE
#define MXM_41B_BIT_MASK_ONE_BYTE
void MXM_41BInitializeStateStruct(MXM_41B_INSTANCE_s *pInstance)
Initializes the state struct with default values.
static void MXM_41BTransitionToIdleSuccess(MXM_41B_INSTANCE_s *pInstance)
Transition into idle, mark as successful.
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.
static STD_RETURN_TYPE_e MXM_41BBufferWrite(MXM_41B_INSTANCE_s *pInstance, const uint16_t *const kpkMessage, uint8_t messageLength, uint8_t extendMessage)
Write a buffer transaction to MAX17841B.
#define MXM_41B_BIT_SHIFT_HALF_BYTE
#define MXM_41B_BRIDGE_RESET_TIME_MS
#define MXM_41B_WAIT_COUNTER_THRESHOLD
#define MXM_41B_BIT_MASK_LOW_NIBBLE
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
#define MXM_SPI_TX_BUFFER_LENGTH
SPI TX buffer length.
MXM_STATEMACH_41B_e
States of the MAX17841B state-machine.
@ MXM_STATEMACH_41B_MAXSTATE
@ MXM_STATEMACH_41B_GET_VERSION
@ MXM_STATEMACH_41B_CLEAR_RECEIVE_BUFFER
@ MXM_STATEMACH_41B_CLEAR_TRANSMIT_BUFFER
@ MXM_STATEMACH_41B_UNINITIALIZED
@ MXM_STATEMACH_41B_WRITE_CONF_AND_INT_REGISTER
@ MXM_STATEMACH_41B_CHECK_FMEA
@ MXM_STATEMACH_41B_READ_STATUS_REGISTER
@ MXM_STATEMACH_41B_UART_TRANSACTION
@ MXM_41B_FMEA_REQUEST_REGISTER
@ MXM_41B_INIT_RESET_BRIDGE_IC
@ MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_WRITE
@ MXM_41B_UART_READ_RX_SPACE
@ MXM_41B_INIT_CHECK_INITIALIZATION
@ MXM_41B_UART_READ_BACK_RECEIVE_BUFFER_SAVE
@ MXM_41B_VERSION_REQUEST_REGISTER
@ MXM_41B_UART_WRITE_LOAD_QUEUE
@ MXM_41B_UART_READ_LOAD_QUEUE
@ MXM_41B_INIT_START_BRIDGE_IC
@ MXM_41B_UART_READ_RX_SPACE_PARSE
@ MXM_41B_INIT_READ_CONFIG_REGISTERS
@ MXM_41B_UART_VERIFY_LOAD_QUEUE_AND_TRANSMIT
@ MXM_41B_READ_STATUS_REGISTER_SEND
@ MXM_41B_READ_STATUS_REGISTER_PROCESS
@ MXM_41B_INIT_WRITE_DEFAULT_VALUES
@ MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_READ_AND_READ_BACK_RCV_BUF
#define MXM_SPI_RX_BUFFER_LENGTH
MXM_41B_REG_FUNCTION_e
Register functions.
@ MXM_41B_REG_FUNCTION_RX_BUSY_STATUS
@ MXM_41B_REG_FUNCTION_RX_EMPTY_STATUS
@ MXM_41B_REG_FUNCTION_RX_STOP_STATUS
@ MXM_41B_REG_FUNCTION_RX_OVERFLOW_STATUS
@ MXM_41B_REG_FUNCTION_TX_PREAMBLES
@ MXM_41B_REG_FUNCTION_RX_ERROR_INT
@ MXM_41B_REG_FUNCTION_KEEP_ALIVE
@ MXM_41B_REG_FUNCTION_RX_OVERFLOW_INT
MXM_41B_STATE_REQUEST_STATUS_e
Request status of MAX17841B states.
@ MXM_41B_STATE_UNPROCESSED
@ MXM_41B_STATE_PROCESSED
Register map of the MAX17841 bridge IC.
#define MXM_REG_RX_INTERRUPT_ENABLE_W
RX interrupt enable register write address.
#define MXM_BUF_RD_LD_Q_0
Read load queue starting from location 0.
#define MXM_REG_RX_SPACE_R
RX space register read address.
#define MXM_BUF_CLR_RX_BUF
Reset receive buffer and pointers to default state.
#define MXM_REG_FMEA_R
FMEA register read address.
#define MXM_REG_RX_INTERRUPT_ENABLE_R
RX interrupt enable register read address.
#define MXM_BUF_RD_NXT_MSG
Read receive buffer starting at the oldest unread message.
#define MXM_REG_RX_STATUS_R
RX status register read address.
#define MXM_REG_MODEL_R
Model register read address.
#define MXM_BUF_WR_LD_Q_0
Write load queue starting from location 0.
#define MXM_BUF_CLR_TX_BUF
Reset transmit buffer to default state and clear TX_Q and LD_Q.
#define MXM_BUF_WR_NXT_LD_Q_0
Select next load queue and write starting from location 0.
uint8_t MXM_41B_REG_ADD_t
MAX17841B register addresses.
STD_RETURN_TYPE_e MXM_ReceiveData(uint16_t *txBuffer, uint16_t *rxBuffer, uint16_t length)
Send and Receive data over SPI.
STD_RETURN_TYPE_e MXM_GetSPIStateReady(void)
Return whether SPI interface is ready.
void MXM_ShutDownBridgeIc(void)
Pulls the shutdown of the bridge IC low.
void MXM_EnableBridgeIc(void)
Pulls the shutdown of the bridge IC high.
STD_RETURN_TYPE_e MXM_SendData(uint16_t *txBuffer, uint16_t length)
Transmit data over SPI.
#define MXM_41B_CONFIG_3_DEFAULT_VALUE
#define MXM_41B_CONFIG_1_DEFAULT_VALUE
#define MXM_41B_CONFIG_2_DEFAULT_VALUE
#define MXM_41B_RX_INT_ENABLE_DEFAULT_VALUE
#define MXM_41B_RX_INT_FLAG_DEFAULT_VALUE
#define MXM_41B_TX_INT_ENABLE_DEFAULT_VALUE
#define MXM_41B_TX_INT_FLAG_DEFAULT_VALUE
bool OS_CheckTimeHasPassed(uint32_t oldTimeStamp_ms, uint32_t timeToPass_ms)
This function checks if timeToPass has passed since the last timestamp to now.
Declaration of the OS wrapper interface.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Struct for the state-variable of state-machine.
MXM_41B_STATE_REQUEST_STATUS_e * processed
uint16_t spiRXBuffer[MXM_SPI_RX_BUFFER_LENGTH]
uint16_t spiTXBuffer[MXM_SPI_TX_BUFFER_LENGTH]
uint32_t shutdownTimeStamp
MXM_41B_SUBSTATES_e substate
MXM_STATEMACH_41B_e state
uint8_t extendMessageBytes