foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
nxp_mc33775a.c File Reference

Driver for the MC33775A analog front-end. More...

#include "nxp_mc33775a.h"
#include "nxp_mc33775a-ll.h"
#include "MC33775A.h"
#include "afe.h"
#include "afe_dma.h"
#include "database.h"
#include "fassert.h"
#include "fstd_types.h"
#include "ftask.h"
#include "mcu.h"
#include "os.h"
#include "spi.h"
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for nxp_mc33775a.c:

Go to the source code of this file.

Functions

static void N775_BalanceControl (N775_STATE_s *pState)
 manages balancing. More...
 
static void N775_BalanceSetup (N775_STATE_s *pState)
 setups balancing. More...
 
static void N775_CaptureMeasurement (N775_STATE_s *pState)
 captures the measurement. More...
 
static STD_RETURN_TYPE_e N775_Enumerate (N775_STATE_s *pState)
 enumerates the N775 slaves. More...
 
static void N775_ErrorHandling (N775_STATE_s *pState, N775_COMMUNICATION_STATUS_e returnedValue, uint8_t module)
 handles error when doing measurements. More...
 
static void N775_IncrementMuxIndex (N775_STATE_s *pState)
 updates index in mux sequence. More...
 
static void N775_IncrementStringSequence (N775_STATE_s *pState)
 increments index in string sequence. More...
 
static void N775_Initialize (N775_STATE_s *pState)
 initializes the N775 driver. More...
 
static void N775_InitializeDatabase (N775_STATE_s *pState)
 in the database, initializes the fields related to the N775 driver. More...
 
static void N775_InitializeI2c (N775_STATE_s *pState)
 init I2C for the N775 slaves. More...
 
static void N775_ResetStringSequence (N775_STATE_s *pState)
 reset index in string sequence. More...
 
static void N775_ResetMuxIndex (N775_STATE_s *pState)
 resets index in mux sequence. More...
 
static void N775_SetFirstMeasurementCycleFinished (N775_STATE_s *pState)
 sets the measurement initialization status. More...
 
static STD_RETURN_TYPE_e N775_SetMuxChannel (N775_STATE_s *pState)
 sets mux channel. More...
 
static void N775_StartMeasurement (N775_STATE_s *pState)
 starts the measurement. More...
 
static STD_RETURN_TYPE_e N775_TransmitI2c (N775_STATE_s *pState)
 transmit over I2C on NXP slave. More...
 
static void N775_Wait (uint32_t milliseconds)
 waits for a definite amount of time in ms. More...
 
STD_RETURN_TYPE_e N775_I2cRead (uint8_t module, uint8_t deviceAddress, uint8_t *pData, uint8_t dataLength)
 trigger a read on the I2C bus of the slave. More...
 
STD_RETURN_TYPE_e N775_I2cWrite (uint8_t module, uint8_t deviceAddress, uint8_t *pData, uint8_t dataLength)
 trigger a write on the I2C bus of the slave. More...
 
STD_RETURN_TYPE_e N775_I2cWriteRead (uint8_t module, uint8_t deviceAddress, uint8_t *pDataWrite, uint8_t writeDataLength, uint8_t *pDataRead, uint8_t readDataLength)
 trigger a read on the I2C bus of the slave, first write address of register to read. More...
 
bool N775_IsFirstMeasurementCycleFinished (N775_STATE_s *pState)
 gets the measurement initialization status. More...
 
void N775_Measure (N775_STATE_s *pState)
 trigger function for the N775 driver state machine. More...
 

Variables

static N775_SUPPLY_CURRENT_s n775_supplyCurrent = {0}
 
static N775_ERROR_TABLE_s n775_errorTable = {0}
 
N775_STATE_s n775_stateBase
 
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}
 
static DATA_BLOCK_ALL_GPIO_VOLTAGES_s n775_allGpioVoltage = {.header.uniqueId = DATA_BLOCK_ID_ALL_GPIO_VOLTAGES_BASE}
 
static DATA_BLOCK_BALANCING_FEEDBACK_s n775_balancingFeedback
 
static DATA_BLOCK_SLAVE_CONTROL_s n775_slaveControl = {.header.uniqueId = DATA_BLOCK_ID_SLAVE_CONTROL}
 
static DATA_BLOCK_OPEN_WIRE_s n775_openWire = {.header.uniqueId = DATA_BLOCK_ID_OPEN_WIRE_BASE}
 

Detailed Description

Driver for the MC33775A analog front-end.

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
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
N775

Definition in file nxp_mc33775a.c.

Function Documentation

◆ N775_BalanceControl()

static void N775_BalanceControl ( N775_STATE_s pState)
static

manages balancing.

Reads balancing order from database and balances the corresponding cells.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 251 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_BalanceSetup()

static void N775_BalanceSetup ( N775_STATE_s pState)
static

setups balancing.

Sets all balancing timer to max to allow for software balancing control.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 274 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_CaptureMeasurement()

static void N775_CaptureMeasurement ( N775_STATE_s pState)
static

captures the measurement.

The MC33775A measures continuously. This function takes a snapshot on all slaves in the daisy-chain.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 302 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_Enumerate()

static STD_RETURN_TYPE_e N775_Enumerate ( N775_STATE_s pState)
static

enumerates the N775 slaves.

This function gives the slaves in the daisy-chain an address.

Parameters
pStatestate of the NXP MC33775A driver

Parse all slaves in the daisy-chain

Definition at line 440 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_ErrorHandling()

static void N775_ErrorHandling ( N775_STATE_s pState,
N775_COMMUNICATION_STATUS_e  returnedValue,
uint8_t  module 
)
static

handles error when doing measurements.

This function is used in the measurement function. It sets the errors flags in the error table according to the value returned by the communication function.

Parameters
pStatestate of the NXP MC33775A driver
returnedValuestatus of the low-level communication
modulenumber of module addressed

Definition at line 509 of file nxp_mc33775a.c.

◆ N775_I2cRead()

STD_RETURN_TYPE_e N775_I2cRead ( uint8_t  module,
uint8_t  deviceAddress,
uint8_t *  pData,
uint8_t  dataLength 
)

trigger a read on the I2C bus of the slave.

Parameters
modulemodule number to address in the daisy-chain
deviceAddressaddress of the I2C device addressed
pDatadata read on I2C bus
dataLengthnumber of bytes to read

Definition at line 1096 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_I2cWrite()

STD_RETURN_TYPE_e N775_I2cWrite ( uint8_t  module,
uint8_t  deviceAddress,
uint8_t *  pData,
uint8_t  dataLength 
)

trigger a write on the I2C bus of the slave.

Parameters
modulemodule number to address in the daisy-chain
deviceAddressaddress of the I2C device addressed
pDatadata to write on I2C bus
dataLengthnumber of bytes to write

Definition at line 1125 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_I2cWriteRead()

STD_RETURN_TYPE_e N775_I2cWriteRead ( uint8_t  module,
uint8_t  deviceAddress,
uint8_t *  pDataWrite,
uint8_t  writeDataLength,
uint8_t *  pDataRead,
uint8_t  readDataLength 
)

trigger a read on the I2C bus of the slave, first write address of register to read.

Parameters
modulemodule number to address in the daisy-chain
deviceAddressaddress of the I2C device addressed
pDataWritedata written on I2C bus
writeDataLengthnumber of bytes to write
pDataReaddata read on I2C bus
readDataLengthnumber of bytes to read

Definition at line 1154 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_IncrementMuxIndex()

static void N775_IncrementMuxIndex ( N775_STATE_s pState)
static

updates index in mux sequence.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 532 of file nxp_mc33775a.c.

◆ N775_IncrementStringSequence()

static void N775_IncrementStringSequence ( N775_STATE_s pState)
static

increments index in string sequence.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 543 of file nxp_mc33775a.c.

◆ N775_Initialize()

static void N775_Initialize ( N775_STATE_s pState)
static

initializes the N775 driver.

This function enumerates the slaves and starts the measurement.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 551 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_InitializeDatabase()

static void N775_InitializeDatabase ( N775_STATE_s pState)
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 shall be called in the initialization or re-initialization routine of the N775 driver.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 565 of file nxp_mc33775a.c.

◆ N775_InitializeI2c()

static void N775_InitializeI2c ( N775_STATE_s pState)
static

init I2C for the N775 slaves.

This function makes slaves ready for I2C transactions with on-slave devices.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 620 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_IsFirstMeasurementCycleFinished()

bool N775_IsFirstMeasurementCycleFinished ( N775_STATE_s pState)

gets the measurement initialization status.

Parameters
pStatestate of the N775A driver
Returns
true if a first measurement cycle was made, false otherwise

Definition at line 1196 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_Measure()

void N775_Measure ( N775_STATE_s pState)

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.

Parameters
pStatestate of the N775A driver

Definition at line 1207 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_ResetMuxIndex()

static void N775_ResetMuxIndex ( N775_STATE_s pState)
static

resets index in mux sequence.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 640 of file nxp_mc33775a.c.

◆ N775_ResetStringSequence()

static void N775_ResetStringSequence ( N775_STATE_s pState)
static

reset index in string sequence.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 632 of file nxp_mc33775a.c.

◆ N775_SetFirstMeasurementCycleFinished()

static void N775_SetFirstMeasurementCycleFinished ( N775_STATE_s pState)
static

sets the measurement initialization status.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 647 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_SetMuxChannel()

static STD_RETURN_TYPE_e N775_SetMuxChannel ( N775_STATE_s pState)
static

sets mux channel.

This function uses I2C to set the mux channel.

Parameters
pStatestate of the NXP MC33775A driver

Set data to send, contains channel bit (8 channels) 1 means channel active, 0 means channel inactive

Wait util transaction ends, test on last device in daisy-chain So device address = number of modules

Get I2C read data, on last device in daisy-chain Use result to set error state for all slaves to avoid reading all slaves in daisy-chain.

Definition at line 655 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_StartMeasurement()

static void N775_StartMeasurement ( N775_STATE_s pState)
static

starts the measurement.

The MC33775A measures continuously. This function starts the measurement.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 755 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_TransmitI2c()

static STD_RETURN_TYPE_e N775_TransmitI2c ( N775_STATE_s pState)
static

transmit over I2C on NXP slave.

Parameters
pStatestate of the NXP MC33775A driver

Definition at line 774 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_Wait()

static void N775_Wait ( uint32_t  milliseconds)
static

waits for a definite amount of time in ms.

This function uses FreeRTOS. It blocks the tasks for the given amount of milliseconds.

Parameters
millisecondstime to wait in ms

Definition at line 1088 of file nxp_mc33775a.c.

Here is the call graph for this function:

Variable Documentation

◆ n775_allGpioVoltage

DATA_BLOCK_ALL_GPIO_VOLTAGES_s n775_allGpioVoltage = {.header.uniqueId = DATA_BLOCK_ID_ALL_GPIO_VOLTAGES_BASE}
static

local copies of database tables

Definition at line 89 of file nxp_mc33775a.c.

◆ 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 88 of file nxp_mc33775a.c.

◆ n775_balancingFeedback

DATA_BLOCK_BALANCING_FEEDBACK_s n775_balancingFeedback
static
Initial value:
= {
@ DATA_BLOCK_ID_BALANCING_FEEDBACK_BASE
Definition: database_cfg.h:84

local copies of database tables

Definition at line 90 of file nxp_mc33775a.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 86 of file nxp_mc33775a.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 85 of file nxp_mc33775a.c.

◆ n775_errorTable

N775_ERROR_TABLE_s n775_errorTable = {0}
static

Definition at line 96 of file nxp_mc33775a.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 87 of file nxp_mc33775a.c.

◆ n775_openWire

DATA_BLOCK_OPEN_WIRE_s n775_openWire = {.header.uniqueId = DATA_BLOCK_ID_OPEN_WIRE_BASE}
static

local copies of database tables

Definition at line 93 of file nxp_mc33775a.c.

◆ n775_slaveControl

DATA_BLOCK_SLAVE_CONTROL_s n775_slaveControl = {.header.uniqueId = DATA_BLOCK_ID_SLAVE_CONTROL}
static

local copies of database tables

Definition at line 92 of file nxp_mc33775a.c.

◆ n775_stateBase

N775_STATE_s n775_stateBase
Initial value:
= {
.firstMeasurementMade = false,
.currentString = 0u,
.pSpiTxSequenceStart = NULL_PTR,
.pSpiTxSequence = NULL_PTR,
.pSpiRxSequenceStart = NULL_PTR,
.pSpiRxSequence = NULL_PTR,
.currentMux = {0},
.pMuxSequenceStart = {0},
.pMuxSequence = {0},
.n775Data.cellVoltage = &n775_cellVoltage,
.n775Data.cellTemperature = &n775_cellTemperature,
.n775Data.allGpioVoltage = &n775_allGpioVoltage,
.n775Data.minMax = &n775_minMax,
.n775Data.balancingFeedback = &n775_balancingFeedback,
.n775Data.balancingControl = &n775_balancingControl,
.n775Data.slaveControl = &n775_slaveControl,
.n775Data.openWire = &n775_openWire,
.n775Data.supplyCurrent = &n775_supplyCurrent,
.n775Data.errorTable = &n775_errorTable,
}
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
static DATA_BLOCK_SLAVE_CONTROL_s n775_slaveControl
Definition: nxp_mc33775a.c:92
static N775_ERROR_TABLE_s n775_errorTable
Definition: nxp_mc33775a.c:96
static DATA_BLOCK_ALL_GPIO_VOLTAGES_s n775_allGpioVoltage
Definition: nxp_mc33775a.c:89
static DATA_BLOCK_MIN_MAX_s n775_minMax
Definition: nxp_mc33775a.c:87
static DATA_BLOCK_CELL_TEMPERATURE_s n775_cellTemperature
Definition: nxp_mc33775a.c:86
static DATA_BLOCK_CELL_VOLTAGE_s n775_cellVoltage
Definition: nxp_mc33775a.c:85
static DATA_BLOCK_BALANCING_CONTROL_s n775_balancingControl
Definition: nxp_mc33775a.c:88
static DATA_BLOCK_OPEN_WIRE_s n775_openWire
Definition: nxp_mc33775a.c:93
static N775_SUPPLY_CURRENT_s n775_supplyCurrent
Definition: nxp_mc33775a.c:95
static DATA_BLOCK_BALANCING_FEEDBACK_s n775_balancingFeedback
Definition: nxp_mc33775a.c:90

state of the state machine for the MC33775A driver

Definition at line 100 of file nxp_mc33775a.c.

◆ n775_supplyCurrent

N775_SUPPLY_CURRENT_s n775_supplyCurrent = {0}
static

Definition at line 95 of file nxp_mc33775a.c.