foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
sps.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, 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 2022-10-27 (date of last update)
47  * @version v1.4.1
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 /*========== Macros and Definitions =========================================*/
65 
66 /*========== Extern Constant and Variable Declarations ======================*/
67 
68 /*========== Extern Function Prototypes =====================================*/
69 
70 /**
71  * @brief Initialize IOs for the SPS driver.
72  * @details This function sets the necessary register (e.g., configure pins as
73  * input or output).
74  */
75 extern void SPS_Initialize(void);
76 
77 /**
78  * @brief Control function for the CONT driver state machine.
79  * @details This function contains the sequence of events in the SPS state
80  * machine. It must be called time-triggered, every 10ms. It exits
81  * without effect, if the function call is a reentrance.
82  */
83 extern void SPS_Ctrl(void);
84 
85 /**
86  * @brief Request state of a contactor
87  * @details This function checks if the requested channel is affiliated to contactors and
88  * then passes the arguments on to #SPS_RequestChannelState().
89  * @param[in] channelIndex number of the channel that should be accessed; This has to be
90  * a SPS channel and it has to be affiliated with #SPS_AFF_CONTACTOR
91  * @param[in] channelFunction requested functional state of the channel
92  */
93 extern void SPS_RequestContactorState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction);
94 
95 /**
96  * @brief Request state of a general IO
97  * @details This function checks if the requested channel is affiliated to general IO and
98  * then passes the arguments on to #SPS_RequestChannelState().
99  * @param[in] channelIndex number of the channel that should be accessed; This has to be
100  * a SPS channel and it has to be affiliated with #SPS_AFF_GENERAL_IO
101  * @param[in] channelFunction requested functional state of the channel
102  */
103 extern void SPS_RequestGeneralIoState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction);
104 
105 /**
106  * @brief Get feedback value
107  * @details This function compares the measured current in the contactor
108  * channel with a fixed threshold and assumes the contactor feedback
109  * to be closed when this threshold is passed on the channel.
110  * @param[in] channelIndex index of the channel (contactor) that should be accessed
111  * @returns state of the channel's feedback
112  */
114 
115 /**
116  * @brief Get the feedback state of a channel
117  * @details Retrieves the feedback state of a sps channel by looking up the
118  * appropriate channel in #sps_kChannelFeedbackMapping and retrieving
119  * the value through the PEX API.
120  * @param[in] channelIndex number of the SPS channel that shall be checked
121  * @param[in] normallyOpen true if the feedback is normally open, false if not
122  * @return state of the channel as reported by PEX
123  */
124 extern CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelPexFeedback(const SPS_CHANNEL_INDEX channelIndex, bool normallyOpen);
125 
126 /**
127  * @brief Returns the channel affiliation
128  * @param[in] channelIndex index of the channel in question
129  * @returns affiliation of the channel
130  */
132 
133 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
134 #ifdef UNITY_UNIT_TEST
135 extern void TEST_SPS_RequestChannelState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction);
136 extern SPS_STATE_e TEST_SPS_GetSpsState(void);
137 extern void TEST_SPS_SetSpsState(const SPS_STATE_e newState);
138 extern uint8_t TEST_SPS_GetSpsTimer(void);
139 extern void TEST_SPS_SetSpsTimer(const uint8_t newTimer);
140 #endif /* UNITY_UNIT_TEST */
141 
142 #endif /* FOXBMS__SPS_H_ */
Header for the configuration for the driver for the contactors.
CONT_ELECTRICAL_STATE_TYPE_e
Definition: contactor_cfg.h:69
CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelPexFeedback(const SPS_CHANNEL_INDEX channelIndex, bool normallyOpen)
Get the feedback state of a channel.
Definition: sps.c:631
SPS_CHANNEL_AFFILIATION_e SPS_GetChannelAffiliation(SPS_CHANNEL_INDEX channelIndex)
Returns the channel affiliation.
Definition: sps.c:654
void SPS_Initialize(void)
Initialize IOs for the SPS driver.
Definition: sps.c:593
void TEST_SPS_RequestChannelState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction)
Definition: sps.c:661
void SPS_Ctrl(void)
Control function for the CONT driver state machine.
Definition: sps.c:476
uint8_t TEST_SPS_GetSpsTimer(void)
Definition: sps.c:670
void TEST_SPS_SetSpsTimer(const uint8_t newTimer)
Definition: sps.c:673
CONT_ELECTRICAL_STATE_TYPE_e SPS_GetChannelCurrentFeedback(const SPS_CHANNEL_INDEX channelIndex)
Get feedback value.
Definition: sps.c:615
void SPS_RequestContactorState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction)
Request state of a contactor.
Definition: sps.c:597
SPS_STATE_e TEST_SPS_GetSpsState(void)
Definition: sps.c:664
void TEST_SPS_SetSpsState(const SPS_STATE_e newState)
Definition: sps.c:667
void SPS_RequestGeneralIoState(SPS_CHANNEL_INDEX channelIndex, SPS_CHANNEL_FUNCTION_e channelFunction)
Request state of a general IO.
Definition: sps.c:606
Header for the configuration for the driver for the smart power switches.
SPS_CHANNEL_FUNCTION_e
Definition: sps_cfg.h:184
SPS_STATE_e
Definition: sps_cfg.h:210
Types for the SPS driver.
uint8_t SPS_CHANNEL_INDEX
Definition: sps_types.h:64
SPS_CHANNEL_AFFILIATION_e
affiliation type of a sps channel
Definition: sps_types.h:72