You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
4.9 KiB
C++

/*
* SYSRestart.h
*
* Author: Aleksey Gerasimenko
* gerasimenko.aleksey.n@gmail.com
*/
#include <math.h>
#include <stdint.h>
#include "SYSCTRL/MonitorDigitalInputSignal.h"
#include "SYSCTRL/SystemDefinitions.h"
#include "SYSCTRL/PhaseAlertMonitor.h"
#include "SYSCTRL/SystemEnvironment.h"
#ifndef SYSCTRL_SYSRESTART_H_
#define SYSCTRL_SYSRESTART_H_
namespace SYSCTRL
{
struct SYSRestartEnableBitField
{
uint16_t enable: 1;
};//SYSRestartEnableBitField
union SYSRestartEnableRegister
{
uint16_t all;
struct SYSRestartEnableBitField signal;
SYSRestartEnableRegister():
all((uint16_t)0)
{}
};//SYSRestartEnableRegister
struct SYSRestartStatusBitField
{
uint16_t fault : 1;
uint16_t resetfault : 1;
uint16_t freezefault : 1;
uint16_t startup : 1;
uint16_t turnon_q1 : 1;
uint16_t turnon_km1 : 1;
uint16_t turnon_km3 : 1;
};//SYSRestartStatusBitField
//
union SYSRestartStatusRegister
{
uint16_t all;
struct SYSRestartStatusBitField signal;
SYSRestartStatusRegister():
all((uint16_t)0)
{}
};//SYSRestartStatusRegister
struct SYSRestartRegisters
{
float counter_timer;
float counter_timer_selfclear_attempts;
uint16_t counter_attempts;
SYSCTRL::SystemFaultsRegister status_fault_register;
SYSCTRL::MonitorDigitalInputSignalRegister monitor_fault;
SYSCTRL::MonitorDigitalInputSignalRegister monitor_resetfault;
SYSCTRL::MonitorDigitalInputSignalRegister monitor_startup;
SYSRestartStatusRegister status;
SYSRestartRegisters():
counter_timer(FP_ZERO),
counter_timer_selfclear_attempts(FP_ZERO),
counter_attempts(0),
status_fault_register(),
monitor_fault(),
monitor_resetfault(),
monitor_startup(),
status()
{}
};//SYSRestartRegisters
struct SYSRestartConfiguration
{
SYSRestartEnableRegister restart_enable;
float period_timer_hold_fault;
float period_timer_reset;
float period_timer_hold_stop;
float period_timer_turnon_switch;
float period_timer_startup;
float period_timer_selfclear_attempts;
uint16_t attempts;
SYSCTRL::SystemFaultsRegister enable;
SYSRestartConfiguration():
restart_enable(),
period_timer_hold_fault(-1.0),
period_timer_reset(-1.0),
period_timer_hold_stop(-1.0),
period_timer_turnon_switch(-1.0),
period_timer_startup(-1.0),
period_timer_selfclear_attempts(-1.0),
attempts(0),
enable()
{}
};//SYSRestartConfiguration
struct SYSRestartStateBitField
{
uint16_t free : 1; // bit 0
uint16_t holdfault : 1; // bit 1
uint16_t resetfault : 1; // bit 2
uint16_t holdstop : 1; // bit 3
uint16_t turnonq1 : 1; // bit 4
uint16_t turnonkm1 : 1; // bit 5
uint16_t turnonkm3 : 1; // bit 6
uint16_t startup : 1; // bit 7
uint16_t freezefault: 1; // bit 8
uint16_t empty : 1; // bit 9
//
};//SYSRestartStateBitField
union SYSRestartStateRegister
{
uint16_t all;
SYSRestartStateBitField signal;
SYSRestartStateRegister():
all(0)
{}
};
class SYSRestart
{
public:
enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL};
enum state_t {FREE, HOLDFAULT, RESETFAULT, HOLDSTOP, TURNONQ1, TURNONKM1, TURNONKM3, STARTUP, FREEZEFAULT, EMPTY};
private:
SYSCTRL::SystemEnvironment& m_env;
private:
mode_t m_mode;
state_t m_state;
SYSRestartStateRegister m_state_bit_field;
// Setup parameters
float m_time_sample;
// Configuration parameters
SYSCTRL::SYSRestartConfiguration m_config;
//
SYSCTRL::SYSRestartRegisters m_registers;
public:
SYSRestartStatusRegister status;
public:
SYSRestart(SYSCTRL::SystemEnvironment& m_env);
void setup(float time_sample);
void configure(SYSRestartConfiguration& config);
public:
mode_t get_mode();
state_t get_state();
uint16_t get_state_steps();
uint16_t get_attempts();
bool compare(mode_t mode);
bool compare_state(state_t state);
public:
void execute();
private:
void (SYSRestart::*_execute)();
void _execute_undef();
void _execute_operational();
private:
inline void _set_state_empty();
inline void _set_state_free();
inline void _set_state_holdfault();
inline void _set_state_resetfault();
inline void _set_state_freezefault();
inline void _set_state_holdstop();
inline void _set_state_turnon_q1();
inline void _set_state_turnon_km1();
inline void _set_state_turnon_km3();
inline void _set_state_startup();
private:
void _state_execute();
void (SYSRestart::*_state_run)();
void _state_empty();
void _state_free();
void _state_holdfault();
void _state_resetfault();
void _state_freezefault();
void _state_holdstop();
void _state_turnon_q1();
void _state_turnon_km1();
void _state_turnon_km3();
void _state_startup();
//
};// SYSRestart
} /* namespace SYSCTRL */
#endif /* SYSCTRL_SYSRESTART_H_ */