foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
sps.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file sps.h
44  * @author foxBMS Team
45  * @date 2020-10-14 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.0
48  * @ingroup DRIVERS
49  * @prefix SPS
50  *
51  * @brief Headers for the driver for the smart power switches.
52  *
53  */
54 
55 #ifndef FOXBMS__SPS_H_
56 #define FOXBMS__SPS_H_
57 
58 /*========== Includes =======================================================*/
59 #include "contactor_cfg.h"
60 #include "sps_cfg.h"
61 
62 #include "sps_types.h"
63 
64 #include <stdint.h>
65 
66 /*========== Macros and Definitions =========================================*/
67 
68 /*========== Extern Constant and Variable Declarations ======================*/
69 
70 /*========== Extern Function Prototypes =====================================*/
71 
72 /**
73  * @brief Initialize IOs for the SPS driver.
74  * @details This function sets the necessary register (e.g., configure pins as
75  * input or output).
76  */
77 extern void SPS_Initialize(void);
78 
79 /**
80  * @brief Control function for the CONT driver state machine.
81  * @details This function contains the sequence of events in the SPS state
82  * machine. It must be called time-triggered, every 10ms. It exits
83  * without effect, if the function call is a reentrance.
84  */
85 extern void SPS_Ctrl(void);
86 
87 /**
88  * @brief Request state of a contactor
89  * @details This function checks if the requested channel is affiliated to contactors and
90  * then passes the arguments on to #SPS_RequestChannelState().
91  * @param[in] channelIndex number of the channel that should be accessed; This has to be
92  * a SPS channel and it has to be affiliated with #SPS_AFF_CONTACTOR
93  * @param[in] channelFunction requested functional state of the channel
94  */
95 extern void SPS_RequestContactorState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction);
96 
97 /**
98  * @brief Request state of a general IO
99  * @details This function checks if the requested channel is affiliated to general IO and
100  * then passes the arguments on to #SPS_RequestChannelState().
101  * @param[in] channelIndex number of the channel that should be accessed; This has to be
102  * a SPS channel and it has to be affiliated with #SPS_AFF_GENERAL_IO
103  * @param[in] channelFunction requested functional state of the channel
104  */
105 extern void SPS_RequestGeneralIoState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction);
106 
107 /**
108  * @brief Get feedback value
109  * @details This function compares the measured current in the contactor
110  * channel with a fixed threshold and assumes the contactor feedback
111  * to be closed when this threshold is passed on the channel.
112  * @param[in] channelIndex index of the channel (contactor) that should be accessed
113  * @returns state of the channel's feedback
114  */
116 
117 /**
118  * @brief Get the feedback state of a channel
119  * @details Retrieves the feedback state of a sps channel by looking up the
120  * appropriate channel in #sps_kChannelFeedbackMapping and retrieving
121  * the value through the PEX API.
122  * @param[in] channelIndex number of the SPS channel that shall be checked
123  * @param[in] normallyOpen true if the feedback is normally open, false if not
124  * @return state of the channel as reported by PEX
125  */
126 extern CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelPexFeedback(const SPS_CHANNEL_INDEX channelIndex, bool normallyOpen);
127 
128 /**
129  * @brief Returns the channel affiliation
130  * @param[in] channelIndex index of the channel in question
131  * @returns affiliation of the channel
132  */
134 
135 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
136 #ifdef UNITY_UNIT_TEST
137 extern void TEST_SPS_RequestChannelState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction);
138 extern SPS_STATE_e TEST_SPS_GetSpsState(void);
139 extern void TEST_SPS_SetSpsState(const SPS_STATE_e newState);
140 extern uint8_t TEST_SPS_GetSpsTimer(void);
141 extern void TEST_SPS_SetSpsTimer(const uint8_t newTimer);
142 #endif
143 
144 #endif /* FOXBMS__SPS_H_ */
Header for the configuration for the driver for the contactors.
CONT_ELECTRICAL_STATE_TYPE_e
Definition: contactor_cfg.h:70
CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelPexFeedback(const SPS_CHANNEL_INDEX channelIndex, bool normallyOpen)
Get the feedback state of a channel.
Definition: sps.c:636
SPS_CHANNEL_AFFILIATION_e SPS_GetChannelAffiliation(SPS_CHANNEL_INDEX channelIndex)
Returns the channel affiliation.
Definition: sps.c:659
void SPS_Initialize(void)
Initialize IOs for the SPS driver.
Definition: sps.c:598
void TEST_SPS_RequestChannelState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction)
Definition: sps.c:666
void SPS_Ctrl(void)
Control function for the CONT driver state machine.
Definition: sps.c:481
uint8_t TEST_SPS_GetSpsTimer(void)
Definition: sps.c:675
void TEST_SPS_SetSpsTimer(const uint8_t newTimer)
Definition: sps.c:678
CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelCurrentFeedback(const SPS_CHANNEL_INDEX channelIndex)
Get feedback value.
Definition: sps.c:620
void SPS_RequestContactorState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction)
Request state of a contactor.
Definition: sps.c:602
SPS_STATE_e TEST_SPS_GetSpsState(void)
Definition: sps.c:669
void TEST_SPS_SetSpsState(const SPS_STATE_e newState)
Definition: sps.c:672
void SPS_RequestGeneralIoState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction)
Request state of a general IO.
Definition: sps.c:611
Header for the configuration for the driver for the smart power switches.
SPS_CHANNEL_FUNCTION_e
Definition: sps_cfg.h:186
SPS_STATE_e
Definition: sps_cfg.h:212
Types for the SPS driver.
uint8_t SPS_CHANNEL_INDEX
Definition: sps_types.h:65
SPS_CHANNEL_AFFILIATION_e
affiliation type of a sps channel
Definition: sps_types.h:73