foxBMS - Unit Tests  1.3.0
The foxBMS Unit Tests API Documentation
n775.c File Reference

Driver for the MC33775A monitoring chip. More...

#include "n775.h"
#include "HL_system.h"
#include "MC33775A.h"
#include "afe_dma.h"
#include "database.h"
#include "diag.h"
#include "os.h"
Include dependency graph for n775.c:

Go to the source code of this file.

Macros

#define N775_MAX_SUPPORTED_CELLS   (12u)
 
#define N775_SAVELASTSTATES()
 

Functions

static void N775_SetFirstMeasurementCycleFinished (N775_STATE_s *n775_state)
 sets the measurement initialization status. More...
 
static void N775_CopyStructToTxBuffer (N775_MESSAGE_s *message, uint16_t *buffer)
 sends a write command to the daisy-chain. More...
 
static void N775_WakeUp (uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress)
 sends a wake-up command to the daisy-chain. More...
 
static void N775_Write (uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t data)
 sends a write command to the daisy-chain. More...
 
static void N775_Read (uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t totalNumberOfRequestedRegister)
 sends a read command to the daisy-chain. More...
 
static void N775_Initialize_Database (void)
 in the database, initializes the fields related to the N775 driver. More...
 
static void N775_StateTransition (N775_STATEMACH_e state, uint8_t subState, uint16_t timer_ms)
 function for setting N775_Trigger state transitions More...
 
uint16_t n775_CrcAddItem (uint16_t remainder, uint16_t item)
 Called to calculate the CRC of a message. NXP function. More...
 
static N775_RETURN_TYPE_e N775_CheckStateRequest (N775_STATE_REQUEST_e statereq)
 checks the state requests that are made. More...
 
uint16_t n775_CalcCrc (const N775_MESSAGE_s *msg)
 Calculate the CRC of a message. NXP function. More...
 
uint8_t N775_CheckReEntrance (void)
 re-entrance check of N775 state machine trigger function More...
 
uint8_t TEST_N775_CheckReEntrance (void)
 
N775_STATE_REQUEST_e N775_GetStateRequest (void)
 gets the current state request. More...
 
N775_STATEMACH_e N775_GetState (void)
 gets the current state. More...
 
N775_STATE_REQUEST_e N775_TransferStateRequest ()
 transfers the current state request to the state machine. More...
 
N775_RETURN_TYPE_e N775_SetStateRequest (N775_STATE_REQUEST_e statereq)
 sets the current state request of the state variable n775_state. More...
 
void N775_Trigger (void)
 trigger function for the N775 driver state machine. More...
 
bool N775_IsFirstMeasurementCycleFinished (void)
 gets the measurement initialization status. More...
 
void TEST_N775_SetFirstMeasurementCycleFinished (N775_STATE_s *n775_state)
 

Variables

N775_MESSAGE_s n775_sentData = {0}
 
N775_MESSAGE_s n775_receivedData = {0}
 
uint8_t n775_enumerateAddress = 1u
 
N775_STATE_s n775_state
 
uint16_t n775_RXbuffer [N775_MAX_N_BYTES_FOR_DATA_RECEPTION] = {0}
 
uint16_t n775_TXbuffer [N775_TX_MESSAGE_LENGTH] = {0}
 
static DATA_BLOCK_CELL_VOLTAGE_s n775_cellVoltage = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE_BASE}
 
static DATA_BLOCK_CELL_TEMPERATURE_s n775_cellTemperature = {.header.uniqueId = DATA_BLOCK_ID_CELL_TEMPERATURE_BASE}
 
static DATA_BLOCK_MIN_MAX_s n775_minMax = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX}
 
static DATA_BLOCK_BALANCING_CONTROL_s n775_balancingControl = {.header.uniqueId = DATA_BLOCK_ID_BALANCING_CONTROL}
 

Detailed Description

Driver for the MC33775A 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:

  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
2020-05-08 (date of creation)
Updated
2022-05-30 (date of last update)
Version
v1.3.0
Prefix
N775

Definition in file n775.c.

Macro Definition Documentation

◆ N775_MAX_SUPPORTED_CELLS

#define N775_MAX_SUPPORTED_CELLS   (12u)

maximum number of supported cells per slave-module

Definition at line 69 of file n775.c.

◆ N775_SAVELASTSTATES

#define N775_SAVELASTSTATES ( )
Value:
n775_state.lastSubState = n775_state.subState
N775_STATE_s n775_state
Definition: n775.c:116
uint8_t subState
Definition: n775_defs.h:232
N775_STATEMACH_e state
Definition: n775_defs.h:231
N775_STATEMACH_e lastState
Definition: n775_defs.h:233

Saves the last state and the last substate

Definition at line 74 of file n775.c.

Function Documentation

◆ n775_CalcCrc()

uint16_t n775_CalcCrc ( const N775_MESSAGE_s msg)

Calculate the CRC of a message. NXP function.

Parameters
msg
Returns
crc

Definition at line 199 of file n775.c.

Here is the call graph for this function:

◆ N775_CheckReEntrance()

uint8_t N775_CheckReEntrance ( void  )

re-entrance check of N775 state machine trigger function

This function is not re-entrant and should only be called time- or event-triggered. It increments the triggerentry counter from the state variable n775_state. It should never be called by two different processes, so if it is the case, triggerentry should never be higher than 0 when this function is called.

Returns
retval 0 if no further instance of the function is active, 0xff else

Definition at line 282 of file n775.c.

Here is the call graph for this function:

◆ N775_CheckStateRequest()

static N775_RETURN_TYPE_e N775_CheckStateRequest ( N775_STATE_REQUEST_e  statereq)
static

checks the state requests that are made.

This function checks the validity of the state requests. The results of the checked is returned immediately.

Parameters
statereqstate request to be checked
Returns
result of the state request that was made, taken from N775_RETURN_TYPE_e

Definition at line 515 of file n775.c.

◆ N775_CopyStructToTxBuffer()

static void N775_CopyStructToTxBuffer ( N775_MESSAGE_s message,
uint16_t *  buffer 
)
static

sends a write command to the daisy-chain.

Parameters
messagemessage to be sent
bufferbuffer used for SPI

Definition at line 568 of file n775.c.

◆ n775_CrcAddItem()

uint16_t n775_CrcAddItem ( uint16_t  remainder,
uint16_t  item 
)

Called to calculate the CRC of a message. NXP function.

Parameters
remainder
item
Returns
remainder

Definition at line 170 of file n775.c.

◆ N775_GetState()

N775_STATEMACH_e N775_GetState ( void  )

gets the current state.

This function is used in the functioning of the N775 state machine.

Returns
current state, taken from N775_STATEMACH_e

Definition at line 323 of file n775.c.

◆ N775_GetStateRequest()

N775_STATE_REQUEST_e N775_GetStateRequest ( void  )

gets the current state request.

This function is used in the functioning of the N775 state machine.

Returns
retval current state request, taken from N775_STATE_REQUEST_e

Definition at line 306 of file n775.c.

Here is the call graph for this function:

◆ N775_Initialize_Database()

static void N775_Initialize_Database ( void  )
static

in the database, initializes the fields related to the N775 driver.

This function loops through all the N775-related data fields in the database and sets them to 0. It should be called in the initialization or re-initialization routine of the N775 driver.

Definition at line 220 of file n775.c.

◆ N775_IsFirstMeasurementCycleFinished()

bool N775_IsFirstMeasurementCycleFinished ( void  )

gets the measurement initialization status.

Returns
retval true if a first measurement cycle was made, false otherwise

Definition at line 540 of file n775.c.

Here is the call graph for this function:

◆ N775_Read()

static void N775_Read ( uint16_t  daisyChainAddress,
uint16_t  deviceAddress,
uint16_t  registerAddress,
uint16_t  totalNumberOfRequestedRegister 
)
static

sends a read command to the daisy-chain.

Parameters
daisyChainAddressparameter CADD in the message format
deviceAddressparameter DADD in the message format lies between 1 and 62
registerAddressaddress of first consecutive register to be read from
totalNumberOfRequestedRegistertotal number of registers values sent by daisy-chain lies between 1 and 256

Set Head part or WRITE message

Set Data head part or WRITE message

Set Data part or WRITE message

Set CRC part or WRITE message

Definition at line 713 of file n775.c.

Here is the call graph for this function:

◆ N775_SetFirstMeasurementCycleFinished()

static void N775_SetFirstMeasurementCycleFinished ( N775_STATE_s n775_state)
static

sets the measurement initialization status.

Definition at line 553 of file n775.c.

Here is the call graph for this function:

◆ N775_SetStateRequest()

N775_RETURN_TYPE_e N775_SetStateRequest ( N775_STATE_REQUEST_e  statereq)

sets the current state request of the state variable n775_state.

This function is used to make a state request to the state machine,e.g, start voltage measurement, read result of voltage measurement, re-initialization It calls N775_CheckStateRequest() to check if the request is valid. The state request is rejected if is not valid. The result of the check is returned immediately, so that the requester can act in case it made a non-valid state request.

Parameters
statereqstate request to set
Returns
retVal current state request, taken from N775_STATE_REQUEST_e

Definition at line 347 of file n775.c.

Here is the call graph for this function:

◆ N775_StateTransition()

static void N775_StateTransition ( N775_STATEMACH_e  state,
uint8_t  subState,
uint16_t  timer_ms 
)
static

function for setting N775_Trigger state transitions

Parameters
statestate to transition into
subStatesubstate to transition into
timer_mstransition into state, substate after timer elapsed

Definition at line 264 of file n775.c.

◆ N775_TransferStateRequest()

N775_STATE_REQUEST_e N775_TransferStateRequest ( )

transfers the current state request to the state machine.

This function takes the current state request from n775_state and transfers it to the state machine. It resets the value from n775_state to N775_STATE_NO_REQUEST

Returns
retVal current state request, taken from N775_STATE_REQUEST_e

Definition at line 336 of file n775.c.

Here is the call graph for this function:

◆ N775_Trigger()

void N775_Trigger ( void  )

trigger function for the N775 driver state machine.

This function contains the sequence of events in the N775 state machine. It must be called time-triggered, every 1ms.

Definition at line 361 of file n775.c.

Here is the call graph for this function:

◆ N775_WakeUp()

static void N775_WakeUp ( uint16_t  daisyChainAddress,
uint16_t  deviceAddress,
uint16_t  registerAddress 
)
static

sends a wake-up command to the daisy-chain.

Parameters
daisyChainAddressparameter CADD in the message format
deviceAddressparameter DADD in the message format lies between 1 and 62, 63 means all devices
registerAddressaddress of register to be written to

Set Head part or WRITE message

Set Data head part or WRITE message

Set Data part or WRITE message

Set CRC part or WRITE message

Definition at line 592 of file n775.c.

Here is the call graph for this function:

◆ N775_Write()

static void N775_Write ( uint16_t  daisyChainAddress,
uint16_t  deviceAddress,
uint16_t  registerAddress,
uint16_t  data 
)
static

sends a write command to the daisy-chain.

Parameters
daisyChainAddressparameter CADD in the message format
deviceAddressparameter DADD in the message format lies between 1 and 62, 63 means all devices
registerAddressaddress of register to be written to
datadata to be written in the device register

Set Head part or WRITE message

Set Data head part or WRITE message

Set Data part or WRITE message

Set CRC part or WRITE message

Definition at line 651 of file n775.c.

Here is the call graph for this function:

◆ TEST_N775_CheckReEntrance()

uint8_t TEST_N775_CheckReEntrance ( void  )

Definition at line 295 of file n775.c.

Here is the call graph for this function:

◆ TEST_N775_SetFirstMeasurementCycleFinished()

void TEST_N775_SetFirstMeasurementCycleFinished ( N775_STATE_s n775_state)

Definition at line 559 of file n775.c.

Here is the call graph for this function:

Variable Documentation

◆ n775_balancingControl

DATA_BLOCK_BALANCING_CONTROL_s n775_balancingControl = {.header.uniqueId = DATA_BLOCK_ID_BALANCING_CONTROL}
static

local copies of database tables

Definition at line 113 of file n775.c.

◆ n775_cellTemperature

DATA_BLOCK_CELL_TEMPERATURE_s n775_cellTemperature = {.header.uniqueId = DATA_BLOCK_ID_CELL_TEMPERATURE_BASE}
static

local copies of database tables

Definition at line 111 of file n775.c.

◆ n775_cellVoltage

DATA_BLOCK_CELL_VOLTAGE_s n775_cellVoltage = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE_BASE}
static

local copies of database tables

Definition at line 110 of file n775.c.

◆ n775_enumerateAddress

uint8_t n775_enumerateAddress = 1u

Definition at line 96 of file n775.c.

◆ n775_minMax

DATA_BLOCK_MIN_MAX_s n775_minMax = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX}
static

local copies of database tables

Definition at line 112 of file n775.c.

◆ n775_receivedData

N775_MESSAGE_s n775_receivedData = {0}

Struct used for SPI Rx transmissions for the communicaiton with MC33775A.

Definition at line 94 of file n775.c.

◆ n775_RXbuffer

uint16_t n775_RXbuffer[N775_MAX_N_BYTES_FOR_DATA_RECEPTION] = {0}

PEC buffer for RX and TX

Definition at line 87 of file n775.c.

◆ n775_sentData

N775_MESSAGE_s n775_sentData = {0}

Struct used for SPI Tx transmissions for the communicaiton with MC33775A.

Definition at line 93 of file n775.c.

◆ n775_state

N775_STATE_s n775_state
Initial value:
= {
.timer = 0,
.stateReq = N775_STATE_NO_REQUEST,
.subState = 0,
.lastSubState = 0,
.errRequestCounter = 0,
.triggerEntry = 0,
.firstMeasurementMade = STD_NOT_OK,
.checkSpiFlag = STD_NOT_OK,
.balanceControlDone = STD_NOT_OK,
.txTransmitOngoing = false,
.rxTransmitOngoing = false,
.totalMessages = 0u,
.remainingMessages = 0u,
}
@ STD_NOT_OK
Definition: fstd_types.h:83
@ N775_STATE_NO_REQUEST
Definition: n775_defs.h:123
@ N775_STATEMACH_UNINITIALIZED
Definition: n775_defs.h:84

Variable containing the state machine state for the MC33775A driver.

Definition at line 116 of file n775.c.

◆ n775_TXbuffer

uint16_t n775_TXbuffer[N775_TX_MESSAGE_LENGTH] = {0}

Buffer used for SPI Tx transmissions for the communication with MC33775A.

Definition at line 88 of file n775.c.