Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c
mmi 97a42de2ea Updated Interlocks (NO and NC inverted)
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@256 05563f52-14a8-4384-a975-3d1654cca0fa
2017-10-18 08:11:09 +00:00

118 lines
3.3 KiB
C

// -----------------------------------------------------------------------------
/// @file Interlock.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file Interlock.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "Interlock.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus Interlock_construct(struct Interlock* self, T_INTERLOCK_ID ID, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
self->ID = ID;
self->NO.io = NO;
self->NO.ioEXTI = NOEXTI;
self->NC.io = NC;
self->NC.ioEXTI = NCEXTI;
self->initialized = true;
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void Interlock_getStatus(struct Interlock* self, FunctionalState* command, int* NO, int* NC)
{
*command = self->NO.ioEXTI.EXTI_LineCmd;
size_t actualLength;
IODevice_read((struct IODevice*)self->NO.io, (char*)NO, 1, &actualLength);
IODevice_read((struct IODevice*)self->NC.io, (char*)NC, 1, &actualLength);
}
bool Interlock_isClosed(struct Interlock* self)
{
bool returnValue;
char no;
char nc;
size_t actualLength;
IODevice_read((struct IODevice*)self->NO.io, &no, 1, &actualLength);
IODevice_read((struct IODevice*)self->NC.io, &nc, 1, &actualLength);
if ((nc != 0) && (no == 0))
{
returnValue = true;
}
else
{
returnValue = false;
}
return returnValue;
}
void Interlock_setEXTI(struct Interlock* self, FunctionalState command)
{
self->NO.ioEXTI.EXTI_LineCmd = command;
EXTI_Init(&self->NO.ioEXTI);
self->NC.ioEXTI.EXTI_LineCmd = command;
EXTI_Init(&self->NC.ioEXTI);
}