foxBMS - Unit Tests
1.3.0
The foxBMS Unit Tests API Documentation
|
Driver for the smart power switches. More...
#include "sps.h"
#include "database.h"
#include "io.h"
#include "mcu.h"
#include "os.h"
#include "pex.h"
#include "spi.h"
Go to the source code of this file.
Macros | |
#define | SPS_RESET_WAIT_TIME_TICKS (5u) |
Functions | |
static void | SPS_SetCommandTxBuffer (const SPS_ACTION_e action) |
Assemble a general command to the SPS ICs. More... | |
static void | SPS_SetContactorsTxBuffer (void) |
Assemble an update to the channel state of the SPS ICs. More... | |
static STD_RETURN_TYPE_e | SPS_Transmit (void) |
Transmit all assembled messages for one timeframe. More... | |
static void | SPS_GlobalReadCurrent (const uint8_t outputAllDevices) |
Read the current measurements for a specific output for all SPS ICs of the daisy-chain. More... | |
static void | SPS_InitializeIo (void) |
static void | SPS_InitializeBuffers (void) |
static void | SPS_GlobalRegisterRead (const uint16_t address, const SPS_READ_TYPE_e controlOrDiagnostic, uint16_t *pSpiTxBuffer) |
Sets the SPI Tx buffer for a register read access for all SPS ICs of the daisy-chain. More... | |
static void | SPS_GlobalRegisterWrite (const uint16_t address, uint8_t writeData, uint16_t *pSpiTxBuffer) |
Sets the SPI Tx buffer for a register write access for all SPS ICs of the daisy-chain. More... | |
static void | SPS_SingleDeviceRegisterWrite (uint8_t device, const uint16_t address, uint8_t writeData, SPS_WRITE_TYPE_e writeType, uint16_t *pSpiTxBuffer) |
Sets the SPI Tx buffer for a register write access for a specific single SPS ICs in the daisy-chain. More... | |
static void | SPS_RequestChannelState (SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction) |
Request the functional state of a channel. More... | |
void | SPS_Ctrl (void) |
Control function for the CONT driver state machine. More... | |
void | SPS_Initialize (void) |
Initialize IOs for the SPS driver. More... | |
void | SPS_RequestContactorState (SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction) |
Request state of a contactor. More... | |
void | SPS_RequestGeneralIoState (SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction) |
Request state of a general IO. More... | |
CONT_ELECTRICAL_STATE_TYPE_e | SPS_GetChannelCurrentFeedback (const SPS_CHANNEL_INDEX channelIndex) |
Get feedback value. More... | |
CONT_ELECTRICAL_STATE_TYPE_e | SPS_GetChannelPexFeedback (const SPS_CHANNEL_INDEX channelIndex, bool normallyOpen) |
Get the feedback state of a channel. More... | |
SPS_CHANNEL_AFFILIATION_e | SPS_GetChannelAffiliation (SPS_CHANNEL_INDEX channelIndex) |
Returns the channel affiliation. More... | |
void | TEST_SPS_RequestChannelState (SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction) |
SPS_STATE_e | TEST_SPS_GetSpsState (void) |
void | TEST_SPS_SetSpsState (const SPS_STATE_e newState) |
uint8_t | TEST_SPS_GetSpsTimer (void) |
void | TEST_SPS_SetSpsTimer (const uint8_t newTimer) |
Variables | |
static SPS_STATE_e | sps_state = SPS_START |
static uint8_t | sps_timer = 0 |
static uint16_t | sps_spiTxRegisterBuffer [SPS_SPI_BUFFERSIZE] = {0} |
static uint16_t | sps_spiRxRegisterBuffer [SPS_SPI_BUFFERSIZE] = {0} |
static uint16_t | sps_spiTxWriteToChannelChannelControlRegister [SPS_SPI_BUFFERSIZE] = {0} |
static uint16_t | sps_spiRxReadAnswerDuringChannelControl [SPS_SPI_BUFFERSIZE] = {0} |
Driver for the smart power switches.
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:
Definition in file sps.c.
#define SPS_RESET_WAIT_TIME_TICKS (5u) |
void SPS_Ctrl | ( | void | ) |
Control function for the CONT driver state machine.
This function contains the sequence of events in the SPS state machine. It must be called time-triggered, every 10ms. It exits without effect, if the function call is a reentrance.
Definition at line 476 of file sps.c.
SPS_CHANNEL_AFFILIATION_e SPS_GetChannelAffiliation | ( | SPS_CHANNEL_INDEX | channelIndex | ) |
CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelCurrentFeedback | ( | const SPS_CHANNEL_INDEX | channelIndex | ) |
Get feedback value.
This function compares the measured current in the contactor channel with a fixed threshold and assumes the contactor feedback to be closed when this threshold is passed on the channel.
[in] | channelIndex | index of the channel (contactor) that should be accessed |
Definition at line 609 of file sps.c.
CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelPexFeedback | ( | const SPS_CHANNEL_INDEX | channelIndex, |
bool | normallyOpen | ||
) |
Get the feedback state of a channel.
Retrieves the feedback state of a sps channel by looking up the appropriate channel in sps_kChannelFeedbackMapping and retrieving the value through the PEX API.
[in] | channelIndex | number of the SPS channel that shall be checked |
[in] | normallyOpen | true if the feedback is normally open, false if not |
Definition at line 625 of file sps.c.
|
static |
Read the current measurements for a specific output for all SPS ICs of the daisy-chain.
A read command must be issued for all SPS ICs in the daisy chain first. There is one register to read for each output. This funcion i used to retrieve the answer on the MISO line after the write command to the contactors output registers was made. The result is written to SPS_CoilCurrent[].
[in] | outputAllDevices | Output (1 to 4) to be read. Value between 1-4 instead of 0-3 to match numbering in data sheet. |
|
static |
Sets the SPI Tx buffer for a register read access for all SPS ICs of the daisy-chain.
The same command is issued for all SPS ICs in the daisy chain. This means that the same register is read to all SPS ICs in the daisy chain.
[in] | address | address of register accessed |
[in] | controlOrDiagnostic | type of read access, SPS_READ_DIAGNOSTIC_REGISTER for diagnostic register, SPS_READ_CONTROL_REGISTER for control register. |
[out] | pSpiTxBuffer | Tx buffer used for the transmission |
|
static |
Sets the SPI Tx buffer for a register write access for all SPS ICs of the daisy-chain.
The same command is issued for all SPS ICs in the daisy chain. This means that the same value is written to all SPS ICs in the daisy chain. The current value in register is overwritten by writeData.
[in] | address | address of register accessed |
[in] | writeData | data to write |
[out] | pSpiTxBuffer | Tx buffer used for the transmission |
void SPS_Initialize | ( | void | ) |
|
static |
|
static |
|
static |
Request the functional state of a channel.
Pass a value of SPS_CHANNEL_FUNCTION_e and a channel index number in order to request this state.
[in] | channelIndex | number of the channel that should be accessed; do not confuse with contactor channel! |
[in] | channelFunction | requested functional state of the channel |
Definition at line 466 of file sps.c.
void SPS_RequestContactorState | ( | SPS_CHANNEL_INDEX | channelIndex, |
SPS_CHANNEL_FUNCTION_e | channelFunction | ||
) |
Request state of a contactor.
This function checks if the requested channel is affiliated to contactors and then passes the arguments on to SPS_RequestChannelState().
[in] | channelIndex | number of the channel that should be accessed; This has to be a SPS channel and it has to be affiliated with SPS_AFF_CONTACTOR |
[in] | channelFunction | requested functional state of the channel |
Definition at line 597 of file sps.c.
void SPS_RequestGeneralIoState | ( | SPS_CHANNEL_INDEX | channelIndex, |
SPS_CHANNEL_FUNCTION_e | channelFunction | ||
) |
Request state of a general IO.
This function checks if the requested channel is affiliated to general IO and then passes the arguments on to SPS_RequestChannelState().
[in] | channelIndex | number of the channel that should be accessed; This has to be a SPS channel and it has to be affiliated with SPS_AFF_GENERAL_IO |
[in] | channelFunction | requested functional state of the channel |
Definition at line 603 of file sps.c.
|
static |
Assemble a general command to the SPS ICs.
For each call of the SPS_Ctrl() function two transactions are sent. For details please read the documentation of SPS_Transmit().
This function has to be called before the transaction in order to update the TX buffer with a general command to the SPS chips in the daisy-chain. The actual command (and with that registers) that shall be accessed and sent is controlled by the parameter that is passed on with this function. *
[in] | action | decides which command should be used |
Definition at line 329 of file sps.c.
|
static |
Assemble an update to the channel state of the SPS ICs.
For each call of the SPS_Ctrl() function two transactions are sent. For details please read the documentation of SPS_Transmit().
This function has to be called before the transaction in order to update the TX buffer with a channel configuration to the SPS chips in the daisy-chain. The actual contactor or channel state is taken from the current state of the array sps_channelStatus.
With this computation, the contactor number is linked to the SPS IC position in the daisy-chain which is driving this contactor. Contactor 0-3: SPS IC 0 Contactor 4-7: SPS IC 1 Contactor 8-11: SPS IC 2 ...
Definition at line 391 of file sps.c.
|
static |
Sets the SPI Tx buffer for a register write access for a specific single SPS ICs in the daisy-chain.
The same command is issued for all SPS ICs in the daisy chain. This means that the same value is written to all SPS ICs in the daisy chain. This function does not set the Tx buffer to 0. This must be done manually.
[in] | device | device number in the daisy-chain to be written to. |
[in] | address | address of register accessed |
[in] | writeData | data to write. In case of read access, this field is ignored and can be set to 0u. |
[in] | writeType | defines whether the value in register should be replaced by writeData, or or-ed with writeType, or and-ed with writeData |
[out] | pSpiTxBuffer | Tx buffer used for the transmission |
|
static |
Transmit all assembled messages for one timeframe.
This function leverages the fact that the SPS are connected in a "daisy-chain". This way the chain acts as a large shift register. When sending a message into the chain it is clocked in until every chip in the chain as its message. Then chip-select is released and the messages parsed. The answer is then assembled by the chip in its register and clocked out and received by the master with the next transmission.
This function sends out a general command to each chip that has been assembled with SPS_SetCommandTxBuffer(). The clocked out information that is received of this transaction is stored in a separate buffer and is the answer from the last transaction of the timeframe before the current one.
After this transaction the answer to the general command is retrieved and the transmission is used to clock in an update of the state of the contactor channels. This update has been assembled before the call of this function with the function SPS_SetContactorsTxBuffer().
Definition at line 431 of file sps.c.
SPS_STATE_e TEST_SPS_GetSpsState | ( | void | ) |
void TEST_SPS_RequestChannelState | ( | SPS_CHANNEL_INDEX | channelIndex, |
SPS_CHANNEL_FUNCTION_e | channelFunction | ||
) |
void TEST_SPS_SetSpsState | ( | const SPS_STATE_e | newState | ) |
|
static |
SPI buffer: Tx part used to write to contactor output control register Rx part used to read answer from former read register command
When a read register command was issued on the MOSI line, the answers comes during the next command (read or write) on the MISO line (data sheet figure 6 page 9 in data sheet Rev. 2 - 11 September 2019)
In the SPS driver, there are always two communications with the SPS IC each time the state machine is triggered:
|
static |
|
static |
|
static |
SPI buffer: Tx part used to write to contactor output control register Rx part used to read answer from former read register command
When a read register command was issued on the MOSI line, the answers comes during the next command (read or write) on the MISO line (data sheet figure 6 page 9 in data sheet Rev. 2 - 11 September 2019)
In the SPS driver, there are always two communications with the SPS IC each time the state machine is triggered:
|
static |