Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hsb-mrts.c
mmi f09eb6034c Fixed some debugging methods that were necessary while no drawer was available
Fixed HV0/1/2present GPIO settings (must be IN instead of OUT)

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@470 05563f52-14a8-4384-a975-3d1654cca0fa
2018-03-14 09:18:06 +00:00

238 lines
5.9 KiB
C

// -----------------------------------------------------------------------------
/// @file hsb-mrts.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 hsb-mrts.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include "hsb-mrts.h"
#include "ADConverter.h"
#include "ADConverters.h"
#include "DAConverter.h"
#include "DAConverters.h"
#include "Display.h"
#include "Error.h"
#include "Warning.h"
#include "platform.h"
#include "CoverSolenoid.h"
#include "HighVoltageDetection.h"
#include "Interlock.h"
#include "Logger.h"
#include "PCBA.h"
#include "TeslaGunSafety.h"
#include "Version.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static bool _hsb_safetyIsEnabled = false;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus hsb_generateStartScreen(struct Display* Display)
{
ErrorStatus returnValue = SUCCESS;
if (returnValue == SUCCESS)
{
Display_setCursorToPosition(mainDisplay, 1, 1);
vTaskDelay(10);
returnValue = Display_write(mainDisplay, PCBA_getInstance()->name, 1, 1);
}
else
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[20];
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "SW V. %d.%d.%d.%d", Version_getInstance()->major,
Version_getInstance()->minor,
Version_getInstance()->branch,
Version_getInstance()->patch);
Display_writeCentered(mainDisplay, buffer, 3);
}
else
{
returnValue = ERROR;
}
return returnValue;
}
ErrorStatus hsb_enableSafetyWithError(void)
{
ErrorStatus returnValue = SUCCESS;
// First, Lock the cover
if (returnValue == SUCCESS)
{
CoverSolenoid_lock();
}
if (returnValue == SUCCESS)
{
// Check for INTERLOCK CLOSE
if (Interlock_isClosed(interlock))
{
// Enable Interrupt for interlock switch
Interlock_setEXTI(interlock, ENABLE);
}
else
{
Error_postError(INTERLOCK_COMMON_FAIL);
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
_hsb_safetyIsEnabled = true;
}
else
{
_hsb_safetyIsEnabled = false;
}
return returnValue;
}
ErrorStatus hsb_enableSafetyWithWarning(void)
{
ErrorStatus returnValue = SUCCESS;
// First, Lock the cover
if (returnValue == SUCCESS)
{
CoverSolenoid_lock();
}
if (returnValue == SUCCESS)
{
// Check for INTERLOCK CLOSE
if (Interlock_isClosed(interlock))
{
// Enable Interrupt for interlock switch
Interlock_setEXTI(interlock, ENABLE);
}
else
{
Warning_postWarning(WARNING_INTERLOCK_COMMON_FAIL);
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
// In case of a TESLA repair, release the teslaGunSafety
if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
TeslaGunSafety_release();
}
}
if (returnValue == SUCCESS)
{
_hsb_safetyIsEnabled = true;
}
else
{
_hsb_safetyIsEnabled = false;
}
return returnValue;
}
ErrorStatus hsb_disableSafety(void)
{
ErrorStatus returnValue = SUCCESS;
if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
TeslaGunSafety_block();
}
// Power-down the DAC outputs
DAConverter_setOutputVoltage(dacRow1, 0);
DAConverter_setOutputVoltage(dacRow2, 0);
DAConverter_setOutputVoltage(dacRow3, 0);
char buffer[mainDisplay->displayDevice->parameters.numberOfColumns];
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "WAITING FOR");
Display_write(mainDisplay, buffer, 3, 5);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "POWER DOWN");
Display_write(mainDisplay, buffer, 4, 6);
while (HighVoltageDetection_isVoltagePresent())
{
vTaskDelay(100);
}
Display_clearLine(mainDisplay, 3);
Display_clearLine(mainDisplay, 4);
Interlock_setEXTI(interlock, DISABLE);
_hsb_safetyIsEnabled = false;
return returnValue;
}
bool hsb_safetyIsEnabled(void)
{
return _hsb_safetyIsEnabled;
}