foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
nxp_mc33775a.c File Reference

Driver for the MC33775A monitoring chip. More...

#include "nxp_mc33775a.h"
#include "nxp_mc33775a-ll.h"
#include "HL_gio.h"
#include "HL_system.h"
#include "MC33775A.h"
#include "afe_dma.h"
#include "database.h"
#include "diag.h"
#include "io.h"
#include "mcu.h"
#include "os.h"
#include "spi.h"
Include dependency graph for nxp_mc33775a.c:

Go to the source code of this file.

Functions

static void N775_SetFirstMeasurementCycleFinished (N775_STATE_s *n775_state)
 sets the measurement initialization status. More...
 
uint16_t n775_CrcAddItem (uint16_t remainder, uint16_t item)
 Called to calculate the CRC of a message. More...
 
uint16_t n775_CalcCrc (const N775_MESSAGE_s *msg)
 Calculate the CRC of a message. More...
 
static void N775_InitializeDatabase (N775_STATE_s *n775_state)
 in the database, initializes the fields related to the N775 driver. More...
 
void N775_ResetStringSequence (N775_STATE_s *n775_state)
 reset index in string sequence. More...
 
void N775_IncrementStringSequence (N775_STATE_s *n775_state)
 updates index in string sequence. More...
 
void N775_ResetMuxIndex (N775_STATE_s *n775_state)
 resets index in mux sequence. More...
 
void N775_IncrementMuxIndex (N775_STATE_s *n775_state)
 updates index in mux sequence. More...
 
void N775_ErrorHandling (N775_STATE_s *n775_state, N775_COMMUNICATION_STATUS_e returnedValue, uint8_t module)
 handles error when doing measurements. More...
 
void N775_Init (N775_STATE_s *n775_state)
 initializes the N775 driver. More...
 
STD_RETURN_TYPE_e N775_Enumerate (N775_STATE_s *n775_state)
 enumerates the N775 slaves. More...
 
void N775_I2cInit (N775_STATE_s *n775_state)
 init I2C for the N775 slaves. More...
 
void N775_StartMeasurement (N775_STATE_s *n775_state)
 starts the measurement. More...
 
void N775_CaptureMeasurement (N775_STATE_s *n775_state)
 captures the measurement. More...
 
STD_RETURN_TYPE_e N775_SetMuxChannel (N775_STATE_s *n775_state)
 sets mux channel. More...
 
void N775_BalanceSetup (N775_STATE_s *n775_state)
 setups balancing. More...
 
void N775_BalanceControl (N775_STATE_s *n775_state)
 manages balancing. More...
 
void N775_waitTime (uint32_t milliseconds)
 waits for a definite amount of time in ms. More...
 
void N775_Meas (N775_STATE_s *n775_state)
 trigger function for the N775 driver state machine. More...
 
bool N775_IsFirstMeasurementCycleFinished (N775_STATE_s *n775_state)
 gets the measurement initialization status. More...
 
void TEST_N775_SetFirstMeasurementCycleFinished (N775_STATE_s *n775_state)
 

Variables

static N775_SUPPLY_CURRENT_s n775_supplyCurrent = {0}
 
static N775_ERRORTABLE_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 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-10-27 (date of last update)
Version
v1.4.1
Prefix
N775

Definition in file nxp_mc33775a.c.

Function Documentation

◆ N775_BalanceControl()

void N775_BalanceControl ( N775_STATE_s n775_state)

manages balancing.

Reads balancing order from database and balances the corresponding cells.

Parameters
n775_statestate of the N775A driver

Definition at line 838 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_BalanceSetup()

void N775_BalanceSetup ( N775_STATE_s n775_state)

setups balancing.

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

Parameters
n775_statestate of the N775A driver

Definition at line 799 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ n775_CalcCrc()

uint16_t n775_CalcCrc ( const N775_MESSAGE_s msg)

Calculate the CRC of a message.

Parameters
msg
Returns
crc

Definition at line 179 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_CaptureMeasurement()

void N775_CaptureMeasurement ( N775_STATE_s n775_state)

captures the measurement.

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

Parameters
n775_statestate of the N775A driver

Definition at line 541 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ n775_CrcAddItem()

uint16_t n775_CrcAddItem ( uint16_t  remainder,
uint16_t  item 
)

Called to calculate the CRC of a message.

Parameters
remainder
item
Returns
remainder

Definition at line 152 of file nxp_mc33775a.c.

◆ N775_Enumerate()

STD_RETURN_TYPE_e N775_Enumerate ( N775_STATE_s n775_state)

enumerates the N775 slaves.

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

Parameters
n775_statestate of the N775A driver

Parse all slaves in the daisy-chain

Definition at line 416 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_ErrorHandling()

void N775_ErrorHandling ( N775_STATE_s n775_state,
N775_COMMUNICATION_STATUS_e  returnedValue,
uint8_t  module 
)

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
n775_statestate of the N775A driver
returnedValuestatus of the low-level communication
modulenumber of module addressed

Definition at line 365 of file nxp_mc33775a.c.

◆ N775_I2cInit()

void N775_I2cInit ( N775_STATE_s n775_state)

init I2C for the N775 slaves.

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

Parameters
n775_statestate of the N775A driver

Definition at line 493 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_IncrementMuxIndex()

void N775_IncrementMuxIndex ( N775_STATE_s n775_state)

updates index in mux sequence.

Parameters
n775_statestate of the N775A driver

Definition at line 345 of file nxp_mc33775a.c.

◆ N775_IncrementStringSequence()

void N775_IncrementStringSequence ( N775_STATE_s n775_state)

updates index in string sequence.

Parameters
n775_statestate of the N775A driver

Definition at line 322 of file nxp_mc33775a.c.

◆ N775_Init()

void N775_Init ( N775_STATE_s n775_state)

initializes the N775 driver.

This function enumerates the slaves and starts the measurement.

Parameters
n775_statestate of the N775A driver

Definition at line 394 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_InitializeDatabase()

static void N775_InitializeDatabase ( N775_STATE_s n775_state)
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.

Parameters
n775_statestate of the N775A driver

Definition at line 202 of file nxp_mc33775a.c.

◆ N775_IsFirstMeasurementCycleFinished()

bool N775_IsFirstMeasurementCycleFinished ( N775_STATE_s n775_state)

gets the measurement initialization status.

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

Definition at line 869 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_Meas()

void N775_Meas ( N775_STATE_s n775_state)

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
n775_statestate of the N775A driver

Definition at line 251 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_ResetMuxIndex()

void N775_ResetMuxIndex ( N775_STATE_s n775_state)

resets index in mux sequence.

Parameters
n775_statestate of the N775A driver

Definition at line 334 of file nxp_mc33775a.c.

◆ N775_ResetStringSequence()

void N775_ResetStringSequence ( N775_STATE_s n775_state)

reset index in string sequence.

Parameters
n775_statestate of the N775A driver

Definition at line 310 of file nxp_mc33775a.c.

◆ N775_SetFirstMeasurementCycleFinished()

static void N775_SetFirstMeasurementCycleFinished ( N775_STATE_s n775_state)
static

sets the measurement initialization status.

Parameters
n775_statestate of the N775A driver

Definition at line 885 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_SetMuxChannel()

STD_RETURN_TYPE_e N775_SetMuxChannel ( N775_STATE_s n775_state)

sets mux channel.

This function uses I2C to set the mux channel.

Parameters
n775_statestate of the N775A 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 692 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_StartMeasurement()

void N775_StartMeasurement ( N775_STATE_s n775_state)

starts the measurement.

The MC33775A measures continuously. This function starts the measurement.

Parameters
n775_statestate of the N775A driver

Definition at line 513 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ N775_waitTime()

void N775_waitTime ( uint32_t  milliseconds)

waits for a definite amount of time in ms.

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

Parameters
millisecondstime to wait in ms

Definition at line 904 of file nxp_mc33775a.c.

Here is the call graph for this function:

◆ TEST_N775_SetFirstMeasurementCycleFinished()

void TEST_N775_SetFirstMeasurementCycleFinished ( N775_STATE_s n775_state)

Definition at line 891 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 85 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 84 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:82

local copies of database tables

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

◆ n775_errorTable

N775_ERRORTABLE_s n775_errorTable = {0}
static

Definition at line 92 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 83 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 89 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 88 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:76
static DATA_BLOCK_SLAVE_CONTROL_s n775_slaveControl
Definition: nxp_mc33775a.c:88
static N775_ERRORTABLE_s n775_errorTable
Definition: nxp_mc33775a.c:92
static DATA_BLOCK_ALL_GPIO_VOLTAGES_s n775_allGpioVoltage
Definition: nxp_mc33775a.c:85
static DATA_BLOCK_MIN_MAX_s n775_minMax
Definition: nxp_mc33775a.c:83
static DATA_BLOCK_CELL_TEMPERATURE_s n775_cellTemperature
Definition: nxp_mc33775a.c:82
static DATA_BLOCK_CELL_VOLTAGE_s n775_cellVoltage
Definition: nxp_mc33775a.c:81
static DATA_BLOCK_BALANCING_CONTROL_s n775_balancingControl
Definition: nxp_mc33775a.c:84
static N775_SUPPLY_CURRENT_s n775_supplyCurrent
Definition: nxp_mc33775a.c:91
static DATA_BLOCK_OPEN_WIRE_s n775_openwire
Definition: nxp_mc33775a.c:89
static DATA_BLOCK_BALANCING_FEEDBACK_s n775_balancingFeedback
Definition: nxp_mc33775a.c:86

Variable containing the state machine state for the MC33775A driver.

Definition at line 96 of file nxp_mc33775a.c.

◆ n775_supplyCurrent

N775_SUPPLY_CURRENT_s n775_supplyCurrent = {0}
static

Definition at line 91 of file nxp_mc33775a.c.