foxBMS-UnitTests  1.0.0
The foxBMS Unit Tests API Documentation
interlock.c File Reference

Driver for the interlock. More...

#include "interlock.h"
#include "HL_gio.h"
#include "database.h"
#include "diag.h"
#include "os.h"
Include dependency graph for interlock.c:

Go to the source code of this file.

Macros

#define ILCK_SAVELASTSTATES()
 
#define ILCK_CLOSEINTERLOCK()   ILCK_SwitchInterlockOn()
 
#define ILCK_OPENINTERLOCK()   ILCK_SwitchInterlockOff()
 

Functions

static ILCK_RETURN_TYPE_e ILCK_CheckStateRequest (ILCK_STATE_REQUEST_e statereq)
 checks the state requests that are made. More...
 
static ILCK_STATE_REQUEST_e ILCK_TransferStateRequest (void)
 gets the current state request. More...
 
static uint8_t ILCK_CheckReEntrance (void)
 re-entrance check of ILCK state machine trigger function More...
 
static void ILCK_CheckFeedback (void)
 checks interlock feedback More...
 
static ILCK_ELECTRICAL_STATE_TYPE_e ILCK_GetInterlockSetValue ()
 Gets the latest value (ILCK_SWITCH_ON, ILCK_SWITCH_OFF) the interlock was set to. More...
 
static STD_RETURN_TYPE_e ILCK_SetInterlockState (ILCK_ELECTRICAL_STATE_TYPE_e requestedInterlockState)
 Sets the interlock state to its requested state, if the interlock is at that time not in the requested state. It returns STD_OK if the requested state was successfully set or if the interlock was at the requested state before. More...
 
static STD_RETURN_TYPE_e ILCK_SwitchInterlockOff (void)
 Switches the interlock off and returns STD_NOT_OK on success. More...
 
static STD_RETURN_TYPE_e ILCK_SwitchInterlockOn (void)
 Switches the interlock on and returns STD_OK on success. More...
 
static void ILCK_Init_Pins (void)
 
ILCK_ELECTRICAL_STATE_TYPE_e ILCK_GetInterlockFeedback (void)
 Reads the feedback pin of the interlock and returns its current value (ILCK_SWITCH_OFF/ILCK_SWITCH_ON) More...
 
ILCK_STATEMACH_e ILCK_GetState (void)
 gets the current state. More...
 
ILCK_RETURN_TYPE_e ILCK_SetStateRequest (ILCK_STATE_REQUEST_e statereq)
 sets the current state request of the state variable ilck_state. More...
 
void ILCK_Trigger (void)
 trigger function for the ILCK driver state machine. More...
 
void TEST_ILCK_SetStateStruct (ILCK_STATE_s state)
 

Variables

static ILCK_STATE_s ilck_state
 

Detailed Description

Driver for the interlock.

BSD 3-Clause License 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-02-24 (date of creation)
Updated
2020-02-24 (date of last update)
Prefix
ILCK

Definition in file interlock.c.

Macro Definition Documentation

◆ ILCK_CLOSEINTERLOCK

#define ILCK_CLOSEINTERLOCK ( )    ILCK_SwitchInterlockOn()

provides more clear name for ILCK_SwitchInterlockOn()

Definition at line 72 of file interlock.c.

◆ ILCK_OPENINTERLOCK

#define ILCK_OPENINTERLOCK ( )    ILCK_SwitchInterlockOff()

provides more clear name for ILCK_SwitchInterlockOff()

Definition at line 74 of file interlock.c.

◆ ILCK_SAVELASTSTATES

#define ILCK_SAVELASTSTATES ( )
Value:
ilck_state.lastsubstate = ilck_state.substate

Saves the last state and the last substate

Definition at line 67 of file interlock.c.

Function Documentation

◆ ILCK_CheckFeedback()

static void ILCK_CheckFeedback ( void  )
static

checks interlock feedback

This function is used to check interlock feedback.

Definition at line 206 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_CheckReEntrance()

static uint8_t ILCK_CheckReEntrance ( void  )
static

re-entrance check of ILCK state machine trigger function

This function is not re-entrant and should only be called time- or event-triggered. It increments the triggerentry counter from the state variable ilck_state. It should never be called by two different processes, so if it is the case, triggerentry should never be higher than 0 when this function is called.

Returns
retval 0 if no further instance of the function is active, 0xff else

Definition at line 188 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_CheckStateRequest()

static ILCK_RETURN_TYPE_e ILCK_CheckStateRequest ( ILCK_STATE_REQUEST_e  statereq)
static

checks the state requests that are made.

This function checks the validity of the state requests. The results of the checked is returned immediately.

Parameters
statereqstate request to be checked
Returns
result of the state request that was made, taken from ILCK_RETURN_TYPE_e

Definition at line 117 of file interlock.c.

◆ ILCK_GetInterlockFeedback()

ILCK_ELECTRICAL_STATE_TYPE_e ILCK_GetInterlockFeedback ( void  )

Reads the feedback pin of the interlock and returns its current value (ILCK_SWITCH_OFF/ILCK_SWITCH_ON)

Returns
measuredInterlockState (type: ILCK_ELECTRICAL_STATE_TYPE_e)

Definition at line 287 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_GetInterlockSetValue()

static ILCK_ELECTRICAL_STATE_TYPE_e ILCK_GetInterlockSetValue ( void  )
static

Gets the latest value (ILCK_SWITCH_ON, ILCK_SWITCH_OFF) the interlock was set to.

Meaning of the return value:

Returns
setInformation (type: ILCK_ELECTRICAL_STATE_TYPE_e)

Definition at line 230 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_GetState()

ILCK_STATEMACH_e ILCK_GetState ( void  )

gets the current state.

This function is used in the functioning of the ILCK state machine.

Returns
current state, taken from ILCK_STATEMACH_e

Definition at line 302 of file interlock.c.

◆ ILCK_Init_Pins()

static void ILCK_Init_Pins ( void  )
static

initializes the pins of the interlock to default state

Definition at line 281 of file interlock.c.

◆ ILCK_SetInterlockState()

static STD_RETURN_TYPE_e ILCK_SetInterlockState ( ILCK_ELECTRICAL_STATE_TYPE_e  requestedInterlockState)
static

Sets the interlock state to its requested state, if the interlock is at that time not in the requested state. It returns STD_OK if the requested state was successfully set or if the interlock was at the requested state before.

Parameters
requestedInterlockStateopen or close interlock
Returns
retVal STD_OK if no error, STD_NOT_OK otherwise

Definition at line 244 of file interlock.c.

◆ ILCK_SetStateRequest()

ILCK_RETURN_TYPE_e ILCK_SetStateRequest ( ILCK_STATE_REQUEST_e  statereq)

sets the current state request of the state variable ilck_state.

This function is used to make a state request to the state machine,e.g, start voltage measurement, read result of voltage measurement, re-initialization It calls ILCK_CheckStateRequest() to check if the request is valid. The state request is rejected if is not valid. The result of the check is returned immediately, so that the requester can act in case it made a non-valid state request.

Parameters
statereqstate request to set
Returns
retVal current state request, taken from ILCK_STATE_REQUEST_e

Definition at line 306 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_SwitchInterlockOff()

static STD_RETURN_TYPE_e ILCK_SwitchInterlockOff ( void  )
static

Switches the interlock off and returns STD_NOT_OK on success.

Returns
retVal (type: STD_RETURN_TYPE_e)

Definition at line 264 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_SwitchInterlockOn()

static STD_RETURN_TYPE_e ILCK_SwitchInterlockOn ( void  )
static

Switches the interlock on and returns STD_OK on success.

Returns
retVal (type: STD_RETURN_TYPE_e)

Definition at line 274 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_TransferStateRequest()

static ILCK_STATE_REQUEST_e ILCK_TransferStateRequest ( void  )
static

gets the current state request.

This function is used in the functioning of the ILCK state machine. It is kept as comment for compatibility.

Returns
retval current state request, taken from ILCK_STATE_REQUEST_e

transfers the current state request to the state machine.

This function takes the current state request from ilck_state and transfers it to the state machine. It resets the value from ilck_state to ILCK_STATE_NO_REQUEST

Returns
retVal current state request, taken from ILCK_STATE_REQUEST_e

Definition at line 167 of file interlock.c.

Here is the call graph for this function:

◆ ILCK_Trigger()

void ILCK_Trigger ( void  )

trigger function for the ILCK driver state machine.

This function contains the sequence of events in the ILCK state machine. It must be called time-triggered, every 1ms.

Definition at line 320 of file interlock.c.

Here is the call graph for this function:

◆ TEST_ILCK_SetStateStruct()

void TEST_ILCK_SetStateStruct ( ILCK_STATE_s  state)

Definition at line 432 of file interlock.c.

Variable Documentation

◆ ilck_state

ILCK_STATE_s ilck_state
static
Initial value:
= {
.timer = 0,
.statereq = ILCK_STATE_NO_REQUEST,
.substate = ILCK_ENTRY,
.lastsubstate = ILCK_ENTRY,
.triggerentry = 0,
.ErrRequestCounter = 0,
.counter = 0,
}

contains the state of the contactor state machine

Definition at line 80 of file interlock.c.

ILCK_STATE_s::substate
ILCK_STATEMACH_SUB_e substate
Definition: interlock.h:120
ILCK_STATEMACH_UNINITIALIZED
@ ILCK_STATEMACH_UNINITIALIZED
Definition: interlock.h:67
ILCK_STATE_s::state
ILCK_STATEMACH_e state
Definition: interlock.h:118
ILCK_ENTRY
@ ILCK_ENTRY
Definition: interlock.h:81
ILCK_STATE_s::laststate
ILCK_STATEMACH_e laststate
Definition: interlock.h:122
ilck_state
static ILCK_STATE_s ilck_state
Definition: interlock.c:80
ILCK_STATE_NO_REQUEST
@ ILCK_STATE_NO_REQUEST
Definition: interlock.h:92