commit a1981564a3fe3e1d4cf9912ab08695087533748d Author: Oleg Date: Mon Apr 15 14:59:23 2024 +0300 0822 Does not work diff --git a/.ccsproject b/.ccsproject new file mode 100644 index 0000000..6ffb037 --- /dev/null +++ b/.ccsproject @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..31819a2 --- /dev/null +++ b/.cproject @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3fd553 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ + +# Created by https://www.gitignore.io/api/codecomposerstudio +# Edit at https://www.gitignore.io/?templates=codecomposerstudio + +### CodeComposerStudio ### + +tmp/ +*.tmp +*.bak +# Generated build artifact directories +Debug/ +Release/ +Flash/ +RAM/ +# Generated build artifacts +makefile +*.map +*.mk +*.opt +*.pp +*.xml +# Generated directories +.config/ +.launches/ +# Generated file used to help display error messages in the problems view +.xdchelp +# Uniflash session files +*.uniflashsession +.settings/ +targetConfigs/ + +# End of https://www.gitignore.io/api/codecomposerstudio diff --git a/.project b/.project new file mode 100644 index 0000000..8ad43ef --- /dev/null +++ b/.project @@ -0,0 +1,152 @@ + + + DVR500Framework + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + app_main.c + 1 + PARENT-2-ORIGINAL_PROJECT_ROOT/source/app_main.c + + + Debug/framework.out + 1 + EXTERNAL_BUILD_ARTIFACT + + + F28335/DSP2833x_ADC_cal.asm + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_ADC_cal.asm + + + F28335/DSP2833x_CodeStartBranch.asm + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_CodeStartBranch.asm + + + F28335/DSP2833x_CpuTimers.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_CpuTimers.c + + + F28335/DSP2833x_ECan.c + 1 + PARENT-2-ORIGINAL_PROJECT_ROOT/source/DSP2833x_ECan.c + + + F28335/DSP2833x_ECap.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_ECap.c + + + F28335/DSP2833x_EPwm.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_EPwm.c + + + F28335/DSP2833x_EQep.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_EQep.c + + + F28335/DSP2833x_GlobalVariableDefs.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_headers/source/DSP2833x_GlobalVariableDefs.c + + + F28335/DSP2833x_MemCopy.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_MemCopy.c + + + F28335/DSP2833x_PieCtrl.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_PieCtrl.c + + + F28335/DSP2833x_PieVect.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_PieVect.c + + + F28335/DSP2833x_SWPrioritizedDefaultIsr.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_SWPrioritizedDefaultIsr.c + + + F28335/DSP2833x_Sci.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_Sci.c + + + F28335/DSP2833x_SysCtrl.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_SysCtrl.c + + + F28335/DSP2833x_Xintf.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_Xintf.c + + + F28335/DSP2833x_usDelay.asm + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/DSP2833x_usDelay.asm + + + F28335/Date_ComBoard.c + 1 + PARENT-2-ORIGINAL_PROJECT_ROOT/source/Date_ComBoard.c + + + F28335/Ecap2.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/Ecap2.c + + + F28335/Gpio.c + 1 + PARENT-3-ORIGINAL_PROJECT_ROOT/DSP2833x_common/source/Gpio.c + + + + + FAST_FPU32_SUPPLEMENT + file:/C:/ti/controlSUITE/libs/math/FPUfastRTS/V100 + + + ORIGINAL_PROJECT_ROOT + file:/C:/CCSWorkSpaces/Framework_500_Hz/sys/build/framework + + + SRC_ROOT + $%7BPARENT-3-ORIGINAL_PROJECT_ROOT%7D + + + UTILITIES + file:/C:/ti/controlSUITE/libs/utilities + + + diff --git a/Alert/AlertBase.cpp b/Alert/AlertBase.cpp new file mode 100644 index 0000000..836b8fc --- /dev/null +++ b/Alert/AlertBase.cpp @@ -0,0 +1,37 @@ +/* + * AlertBase.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/AlertBase.h" + +namespace ALERT +{ +//CONSTRUCTOR +AlertBase::AlertBase(): + //m_mode(ALERT::AlertBase::UNDEFINED), + m_time_sample(-1.0), + m_level(FP_ZERO), + m_period(FP_ZERO), + m_timer(FP_ZERO) +// +{}//CONSTRUCTOR + +/* +AlertBase::mode_t AlertBase::get_mode() const +{ + return m_mode; + // +}//get_mode() +// + +bool AlertBase::compare(mode_t mode) const +{ + return m_mode == mode; + // +}//compare() +// +*/ +} /* namespace ALERT */ diff --git a/Alert/AlertBase.h b/Alert/AlertBase.h new file mode 100644 index 0000000..fd602a6 --- /dev/null +++ b/Alert/AlertBase.h @@ -0,0 +1,62 @@ +/* + * AlertBase.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef ALERT_ALARMBASE_H_ +#define ALERT_ALARMBASE_H_ + +namespace ALERT +{ + +struct AlertBaseConfiguration +{ + float level; + float period; + AlertBaseConfiguration(): + level(-1.0), + period(-1.0) + {} +};//AlertBaseConfiguration + + +class AlertBase +{ +//public: +// enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; +//protected: +// mode_t m_mode; +protected: + float m_time_sample; +protected: + float m_level; + +protected: + float m_period; + float m_timer; +//public: +// mode_t mode; +public: + AlertBase(); + virtual void setup(float time_sample) = 0; + virtual void configure(const AlertBaseConfiguration& config) = 0; +//public: + //mode_t get_mode() const; + //bool compare(mode_t mode) const; +public: + virtual void reset() = 0; + virtual void execute(float reference) = 0; +protected: + virtual void _execute_undef(float reference) = 0; + virtual void _execute_operational(float reference) = 0; +// +};//AlertBase +// +} /* namespace ALERT */ +// +#endif /* ALERT_ALARMBASE_H_ */ diff --git a/Alert/FaultDecrease.cpp b/Alert/FaultDecrease.cpp new file mode 100644 index 0000000..addeb3b --- /dev/null +++ b/Alert/FaultDecrease.cpp @@ -0,0 +1,96 @@ +/* + * FaultDecrease.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/FaultDecrease.h" + +namespace ALERT +{ + +//CONSTRUCTOR +FaultDecrease::FaultDecrease(): + ALERT::AlertBase(), +// m_state(ALERT::FaultDecrease::UNKNOWN), + m_fault(false), + fault(false), + _execute(&ALERT::FaultDecrease::_execute_undef) +// +{}//CONSTRUCTOR +// +void FaultDecrease::setup(float time_sample) +{ + m_time_sample = time_sample; + // +}//setup() +// +void FaultDecrease::configure(const ALERT::AlertBaseConfiguration& config) +{ + m_level = config.level; + m_period = config.period; + m_timer = FP_ZERO; + // + m_fault = false; + fault = false; + // + if((m_time_sample > FP_ZERO) && (m_period > m_time_sample) && (m_level >= FP_ZERO)) + { + _execute = &ALERT::FaultDecrease::_execute_operational; + } + // +}//configure() +// +// +#pragma CODE_SECTION("ramfuncs"); +void FaultDecrease::reset() +{ + m_fault = false; + fault = false; + m_timer = FP_ZERO; + // +}//reset() +// +#pragma CODE_SECTION("ramfuncs"); +void FaultDecrease::execute(float reference) +{ + (this->*_execute)(reference); + // +}//execute() +// +void FaultDecrease::_execute_undef(float reference) +{ + // +}//_execute_undef() +// +#pragma CODE_SECTION("ramfuncs"); +void FaultDecrease::_execute_operational(float reference) +{ + if(reference <= m_level) + { + if(m_timer >= m_period) + { + m_fault = true; + fault = true; + } + else + { + m_timer += m_time_sample; + m_fault = false; + fault = false; + // + }// + // + } + else + { + m_timer = FP_ZERO; + m_fault = false; + fault = false; + // + }// + // +}//_execute_operational_warning() +// +} /* namespace ALERT */ diff --git a/Alert/FaultDecrease.h b/Alert/FaultDecrease.h new file mode 100644 index 0000000..8711442 --- /dev/null +++ b/Alert/FaultDecrease.h @@ -0,0 +1,46 @@ +/* + * FaultDecrease.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/AlertBase.h" + +#ifndef ALERT_FAULTDECREASE_H_ +#define ALERT_FAULTDECREASE_H_ + +namespace ALERT +{ + +class FaultDecrease: public ALERT::AlertBase +{ +public: +// enum state_t {UNKNOWN, NORMAL, FAULT}; +private: +// state_t m_state; + bool m_fault; +public: + bool fault; +public: + FaultDecrease(); + void setup(float time_sample); + void configure(const ALERT::AlertBaseConfiguration& config); +public: +// state_t get_state() const; +// bool compare_state(state_t state) const; +// bool is_fault(); +public: + void reset(); +public: + void execute(float reference); +private: + void (FaultDecrease::*_execute)(float reference); + void _execute_undef(float reference); + void _execute_operational(float reference); + // +};//FaultDecrease() + +} /* namespace ALERT */ + +#endif /* ALERT_FAULTDECREASE_H_ */ diff --git a/Alert/FaultExceed.cpp b/Alert/FaultExceed.cpp new file mode 100644 index 0000000..fd2f16d --- /dev/null +++ b/Alert/FaultExceed.cpp @@ -0,0 +1,92 @@ +/* + * FaultExceed.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/FaultExceed.h" + +namespace ALERT +{ +//CONSTRUCTOR +FaultExceed::FaultExceed(): + ALERT::AlertBase(), + m_fault(false), + fault(false), + _execute(&ALERT::FaultExceed::_execute_undef) +// +{}//CONSTRUCTOR +// +void FaultExceed::setup(float time_sample) +{ + m_time_sample = time_sample; + // +}//setup() +// +void FaultExceed::configure(const AlertBaseConfiguration& config) +{ + + m_level = config.level; + m_period = config.period; + // + m_fault = false; + fault = false; + + // + if((m_time_sample > FP_ZERO) && (m_period >= m_time_sample)&&(m_level > FP_ZERO)) + { + _execute = &ALERT::FaultExceed::_execute_operational; + // + }//if + // +}//configure() +// +#pragma CODE_SECTION("ramfuncs"); +void FaultExceed::reset() +{ + m_fault = false; + fault = false; + m_timer = FP_ZERO; + // +}//reset() +// +void FaultExceed::execute(float reference) +{ + (this->*_execute)(reference); + // +}//execute() +// +void FaultExceed::_execute_undef(float reference) +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void FaultExceed::_execute_operational(float reference) +{ + if(reference >= m_level) + { + if(m_timer >= m_period) + { + m_fault = true; + fault = true; + } + else + { + m_timer += m_time_sample; + m_fault = false; + fault = false; + // + }//if else + // + } + else + { + m_timer = FP_ZERO; + m_fault = false; + fault = false; + // + }//if else + // +}// +// +} /* namespace ALERT */ diff --git a/Alert/FaultExceed.h b/Alert/FaultExceed.h new file mode 100644 index 0000000..f01c3af --- /dev/null +++ b/Alert/FaultExceed.h @@ -0,0 +1,39 @@ +/* + * FaultExceed.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/AlertBase.h" + +#ifndef ALERT_FAULTEXCEED_H_ +#define ALERT_FAULTEXCEED_H_ + +namespace ALERT +{ + +class FaultExceed: public ALERT::AlertBase +{ +private: + bool m_fault; +public: + bool fault; +public: + FaultExceed(); + void setup(float time_sample); + void configure(const AlertBaseConfiguration& config); +public: + void reset(); +public: + void execute(float reference); +private: + void (FaultExceed::*_execute)(float reference); + void _execute_undef(float reference); + void _execute_operational(float reference); + // +};//FaultExceed() + +} /* namespace ALERT */ + +#endif /* ALERT_FAULTEXCEED_H_ */ diff --git a/Alert/WarningDecrease.cpp b/Alert/WarningDecrease.cpp new file mode 100644 index 0000000..7e5e017 --- /dev/null +++ b/Alert/WarningDecrease.cpp @@ -0,0 +1,88 @@ +/* + * WarningDecrease.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/WarningDecrease.h" + +namespace ALERT +{ +//CONSTRUCTOR +WarningDecrease::WarningDecrease(): + ALERT::AlertBase(), + m_warning(false), + warning(false), + _execute(&ALERT::WarningDecrease::_execute_undef) +{}//CONSTRUCTOR +// +void WarningDecrease::setup(float time_sample) +{ + m_time_sample = time_sample; + // +}//setup() +// +void WarningDecrease::configure(const AlertBaseConfiguration& config) +{ + m_level = config.level; + m_period = config.period; + // + m_warning = false; + // + if((m_time_sample > FP_ZERO) && (m_period >= m_time_sample) && (m_level > FP_ZERO)) + { + _execute = &ALERT::WarningDecrease::_execute_operational; + // + }//if + // +}//configure() +// +#pragma CODE_SECTION("ramfuncs"); +void WarningDecrease::reset() +{ + m_warning = false; + warning = false; + m_timer = FP_ZERO; + // +}//reset() +// +void WarningDecrease::execute(float reference) +{ + (this->*_execute)(reference); + // +}//execute() +// +void WarningDecrease::_execute_undef(float reference) +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void WarningDecrease::_execute_operational(float reference) +{ + // + if(reference <= m_level) + { + if(m_timer >= m_period) + { + m_warning = true; + warning = true; + } + else + { + m_timer += m_time_sample; + m_warning = false; + warning = false; + // + }//if else + } + else + { + m_warning = false; + warning = false; + m_timer = FP_ZERO; + // + }//else if + // +}//_execute_operational() +// +} /* namespace ALERT */ diff --git a/Alert/WarningDecrease.h b/Alert/WarningDecrease.h new file mode 100644 index 0000000..999ad7b --- /dev/null +++ b/Alert/WarningDecrease.h @@ -0,0 +1,39 @@ +/* + * WarningDecrease.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/AlertBase.h" + +#ifndef ALERT_WARNINGDECREASE_H_ +#define ALERT_WARNINGDECREASE_H_ + +namespace ALERT +{ + +class WarningDecrease: public ALERT::AlertBase +{ +private: + bool m_warning; +public: + bool warning; +public: + WarningDecrease(); + void setup(float time_sample); + void configure(const AlertBaseConfiguration& config); +public: + void reset(); +public: + void execute(float reference); +private: + void (WarningDecrease::*_execute)(float reference); + void _execute_undef(float reference); + void _execute_operational(float reference); +// +};// + +} /* namespace ALERT */ + +#endif /* ALERT_WARNINGDECREASE_H_ */ diff --git a/Alert/WarningExceed.cpp b/Alert/WarningExceed.cpp new file mode 100644 index 0000000..6c3619b --- /dev/null +++ b/Alert/WarningExceed.cpp @@ -0,0 +1,96 @@ +/* + * WarningExceed.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/WarningExceed.h" + +namespace ALERT +{ + +//CONSTRUCTOR +WarningExceed::WarningExceed(): + ALERT::AlertBase(), + m_warning(false), + warning(false), + _execute(&ALERT::WarningExceed::_execute_undef) +{}//CONSTRUCTOR +// +void WarningExceed::setup(float time_sample) +{ + m_time_sample = time_sample; + // +}//setup() +// +void WarningExceed::configure(const AlertBaseConfiguration& config) +{ + + m_level = config.level; + m_period = config.period; + // + m_warning = false; + // + if((m_time_sample > FP_ZERO)&&(m_period > m_time_sample)&&(m_level >= FP_ZERO)) + { + _execute = &ALERT::WarningExceed::_execute_operational; + // + }//if + // +}//configure() +// +// + +// + +// +#pragma CODE_SECTION("ramfuncs"); +void WarningExceed::reset() +{ + m_warning = false; + warning = false; + m_timer = FP_ZERO; + // +}//reset() +// +void WarningExceed::execute(float reference) +{ + (this->*_execute)(reference); + // +}//execute() +// + +void WarningExceed::_execute_undef(float reference) +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void WarningExceed::_execute_operational(float reference) +{ + // + if(reference >= m_level) + { + if(m_timer >= m_period) + { + m_warning = true; + warning = true; + } + else + { + m_timer += m_time_sample; + m_warning = false; + warning = false; + // + }//if else + } + else + { + m_warning = false; + warning = false; + m_timer = FP_ZERO; + // + }//else if + // +}//_execute_operational() +// +} /* namespace ALERT */ diff --git a/Alert/WarningExceed.h b/Alert/WarningExceed.h new file mode 100644 index 0000000..791a5f4 --- /dev/null +++ b/Alert/WarningExceed.h @@ -0,0 +1,38 @@ +/* + * WarningExceed.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "Alert/AlertBase.h" + +#ifndef ALERT_WARNINGEXCEED_H_ +#define ALERT_WARNINGEXCEED_H_ + +namespace ALERT +{ + +class WarningExceed: public ALERT::AlertBase +{ +private: + bool m_warning; +public: + bool warning; +public: + WarningExceed(); + void setup(float time_sample); + void configure(const AlertBaseConfiguration& config); +public: + void reset(); +public: + void execute(float reference); +private: + void (WarningExceed::*_execute)(float reference); + void _execute_undef(float reference); + void _execute_operational(float reference); +}; + +} /* namespace ALERT */ + +#endif /* ALERT_WARNINGEXCEED_H_ */ diff --git a/F28335/DSP28x_Project.h b/F28335/DSP28x_Project.h new file mode 100644 index 0000000..27dddcf --- /dev/null +++ b/F28335/DSP28x_Project.h @@ -0,0 +1,22 @@ + +//########################################################################### +// +// FILE: DSP28x_Project.h +// +// TITLE: DSP28x Project Headerfile and Examples Include File +// +//########################################################################### +// $TI Release: F2833x/F2823x Header Files and Peripheral Examples V142 $ +// $Release Date: November 1, 2016 $ +// $Copyright: Copyright (C) 2007-2016 Texas Instruments Incorporated - +// http://www.ti.com/ ALL RIGHTS RESERVED $ +//########################################################################### + +#ifndef DSP28x_PROJECT_H +#define DSP28x_PROJECT_H + +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" // DSP2833x Examples Include File + +#endif // end of DSP28x_PROJECT_H definition + diff --git a/F28335/Flash2833x_API_Config.h b/F28335/Flash2833x_API_Config.h new file mode 100644 index 0000000..5cfc9de --- /dev/null +++ b/F28335/Flash2833x_API_Config.h @@ -0,0 +1,80 @@ +// TI File $Revision: /main/2 $ +// Checkin $Date: June 22, 2007 13:11:24 $ +//########################################################################### +// +// FILE: Flash2833x_API_Config.h +// +// TITLE: F2833x Flash Algo's - User Settings +// +// NOTE: This file contains user defined settings that +// are used by the F2833x Flash APIs. +// +//########################################################################### +// $TI Release:$ +// $Release Date:$ +//########################################################################### + +#ifndef FLASH2833X_API_CONFIG_H +#define FLASH2833X_API_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +// Variables that can be configured by the user. + +/*----------------------------------------------------------------------------- + 1. Specify the device. + Define the device to be programmed as "1" (no quotes). + Define all other devices as "0" (no quotes). +-----------------------------------------------------------------------------*/ + +#define FLASH_F28335 1 +#define FLASH_F28334 0 +#define FLASH_F28332 0 + +/*----------------------------------------------------------------------------- + 2. Specify the clock rate of the CPU (SYSCLKOUT) in nS. + + Take into account the input clock frequency and the PLL multiplier + that your application will use. + + Use one of the values provided, or define your own. + The trailing L is required tells the compiler to treat + the number as a 64-bit value. + + Only one statement should be uncommented. + + Example: CLKIN is a 30MHz crystal. + + If the application will set PLLCR = 0xA then the CPU clock + will be 150Mhz (SYSCLKOUT = 150MHz). + + In this case, the CPU_RATE will be 6.667L + Uncomment the line: #define CPU_RATE 6.667L +-----------------------------------------------------------------------------*/ + +#define CPU_RATE 6.667L // for a 150MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 10.000L // for a 100MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 13.330L // for a 75MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 20.000L // for a 50MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 33.333L // for a 30MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 41.667L // for a 24MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 50.000L // for a 20MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 66.667L // for a 15MHz CPU clock speed (SYSCLKOUT) +//#define CPU_RATE 100.000L // for a 10MHz CPU clock speed (SYSCLKOUT) + +//---------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// **** DO NOT modify the code below this line **** +//----------------------------------------------------------------------------- +#define SCALE_FACTOR 1048576.0L*( (200L/CPU_RATE) ) // IQ20 + + +#ifdef __cplusplus +} +#endif /* extern "C" */ + +#endif // -- end FLASH2833X_API_CONFIG_H diff --git a/F28335/Flash2833x_API_Library.h b/F28335/Flash2833x_API_Library.h new file mode 100644 index 0000000..0f518b0 --- /dev/null +++ b/F28335/Flash2833x_API_Library.h @@ -0,0 +1,272 @@ +// TI File $Revision: /main/3 $ +// Checkin $Date: February 5, 2008 11:10:02 $ +//########################################################################### +// +// FILE: Flash2833x_API_Library.h +// +// TITLE: F2833x Flash Algo's main include file +// +// DESCRIPTION: +// +// This file should be included in any project that uses any of the +// the F2833x flash APIs. +// +//########################################################################### +// $TI Release:$ +// $Release Date:$ +//########################################################################### + +#ifndef FLASH2833X_API_LIBRARY_H +#define FLASH2833X_API_LIBRARY_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + + +/*--------------------------------------------------------------------------- + 28x Datatypes + + For Portability, User Is Recommended To Use Following Data Type Size + Definitions For 16/32/64-Bit Signed/Unsigned Integers and floating point + variables: +---------------------------------------------------------------------------*/ + +#ifndef DSP28_DATA_TYPES +#define DSP28_DATA_TYPES +typedef int int16; +typedef long int32; +typedef long long int64; +typedef unsigned int Uint16; +typedef unsigned long Uint32; +typedef unsigned long long Uint64; +typedef float float32; +typedef long double float64; +#endif + +/*--------------------------------------------------------------------------- + API Status Messages + + The following status values are returned from the API to the calling + program. These can be used to determine if the API function passed + or failed. +---------------------------------------------------------------------------*/ + // Operation passed, no errors were flagged +#define STATUS_SUCCESS 0 + +// The CSM is preventing the function from performing its operation +#define STATUS_FAIL_CSM_LOCKED 10 + +// Device REVID does not match that required by the API +#define STATUS_FAIL_REVID_INVALID 11 + +// Invalid address passed to the API +#define STATUS_FAIL_ADDR_INVALID 12 + +// Incorrect PARTID +// For example the F2806 API was used on a F2808 device. +#define STATUS_FAIL_INCORRECT_PARTID 13 + +// API/Silicon missmatch. An old version of the +// API is being used on silicon it is not valid for +// Please update to the latest API. +#define STATUS_FAIL_API_SILICON_MISMATCH 14 + +// ---- Erase Specific errors ---- +#define STATUS_FAIL_NO_SECTOR_SPECIFIED 20 +#define STATUS_FAIL_PRECONDITION 21 +#define STATUS_FAIL_ERASE 22 +#define STATUS_FAIL_COMPACT 23 +#define STATUS_FAIL_PRECOMPACT 24 + +// ---- Program Specific errors ---- +#define STATUS_FAIL_PROGRAM 30 +#define STATUS_FAIL_ZERO_BIT_ERROR 31 + +// ---- Verify Specific errors ---- +#define STATUS_FAIL_VERIFY 40 + +// Busy is set by each API function before it determines +// a pass or fail condition for that operation. +// The calling function will will not receive this +// status condition back from the API +#define STATUS_BUSY 999 + +/*--------------------------------------------------------------------------- + Flash sector mask definitions + + The following macros can be used to form a mask specifying which sectors + will be erased by the erase API function. + + Bit0 = Sector A + Bit1 = Sector B + Bit2 = Sector C + Bit3 = Sector D + Bit4 = Sector E + Bit5 = Sector F + Bit6 = Sector G + Bit7 = Sector H +---------------------------------------------------------------------------*/ + +#define SECTORA (Uint16)0x0001 +#define SECTORB (Uint16)0x0002 +#define SECTORC (Uint16)0x0004 +#define SECTORD (Uint16)0x0008 +#define SECTORE (Uint16)0x0010 +#define SECTORF (Uint16)0x0020 +#define SECTORG (Uint16)0x0040 +#define SECTORH (Uint16)0x0080 + + +#if FLASH_F28335 +// All sectors on an F28335 - Sectors A - H +#define SECTOR_F28335 (SECTORA|SECTORB|SECTORC|\ + SECTORD|SECTORE|SECTORF|\ + SECTORG|SECTORH) +#endif // -- end FLASH_F28335 + +#if FLASH_F28334 +// All sectors on an F28334 - Sectors A - H +#define SECTOR_F28334 (SECTORA|SECTORB|SECTORC|\ + SECTORD|SECTORE|SECTORF|\ + SECTORG|SECTORH) +#endif // -- end FLASH_F28334 + +#if FLASH_F28332 +// All sectors on an F28332 - Sectors A - D +#define SECTOR_F28332 (SECTORA|SECTORB|SECTORC|\ + SECTORD) +#endif // -- end FLASH_F28332 + + +/*--------------------------------------------------------------------------- + API Status Structure + + This structure is used to pass debug data back to the calling routine. + Note that the Erase API function has 3 parts: precondition, erase and + and compaction. Erase and compaction failures will not populate + the expected and actual data fields. +---------------------------------------------------------------------------*/ + +typedef struct { + Uint32 FirstFailAddr; + Uint16 ExpectedData; + Uint16 ActualData; +}FLASH_ST; + +/*--------------------------------------------------------------------------- + Interface Function prototypes + + For each 28x Flash API library, the function names are of the form: + Flash_() + + Where is the device: ie 2808, 2806, 2801 + is the operation such as Erase, Program... + + For portability for users who may move between the F2808, F2806 and + F2801, the following macro definitions are supplied. + + Using these macro definitions, the user can use instead make a generic + call: Flash_ and the macro will map the call to the proper + device function + + Note except for the toggle test function, all of the function prototypes + are compatible with F281x devices as well. +---------------------------------------------------------------------------*/ + +#if FLASH_F28335 +#define Flash_Erase(a,b) Flash28335_Erase(a,b) +#define Flash_Program(a,b,c,d) Flash28335_Program(a,b,c,d) +#define Flash_Verify(a,b,c,d) Flash28335_Verify(a,b,c,d) +#define Flash_ToggleTest(a,b) Flash28335_ToggleTest(a,b) +#define Flash_DepRecover() Flash28335_DepRecover() +#define Flash_APIVersionHex() Flash28335_APIVersionHex() +#define Flash_APIVersion() Flash28335_APIVersion() +#endif + +#if FLASH_F28334 +#define Flash_Erase(a,b) Flash28334_Erase(a,b) +#define Flash_Program(a,b,c,d) Flash28334_Program(a,b,c,d) +#define Flash_Verify(a,b,c,d) Flash28334_Verify(a,b,c,d) +#define Flash_ToggleTest(a,b) Flash28334_ToggleTest(a,b) +#define Flash_DepRecover() Flash28334_DepRecover() +#define Flash_APIVersionHex() Flash28334_APIVersionHex() +#define Flash_APIVersion() Flash28334_APIVersion() +#endif + +#if FLASH_F28332 +#define Flash_Erase(a,b) Flash28332_Erase(a,b) +#define Flash_Program(a,b,c,d) Flash28332_Program(a,b,c,d) +#define Flash_Verify(a,b,c,d) Flash28332_Verify(a,b,c,d) +#define Flash_ToggleTest(a,b) Flash28332_ToggleTest(a,b) +#define Flash_DepRecover() Flash28332_DepRecover() +#define Flash_APIVersionHex() Flash28332_APIVersionHex() +#define Flash_APIVersion() Flash28332_APIVersion() +#endif + +extern Uint16 Flash_Erase(Uint16 SectorMask, FLASH_ST *FEraseStat); +extern Uint16 Flash_Program(Uint16 *FlashAddr, Uint16 *BufAddr, Uint32 Length, FLASH_ST *FProgStatus); +extern Uint16 Flash_Verify(Uint16 *StartAddr, Uint16 *BufAddr, Uint32 Length, FLASH_ST *FVerifyStat); +extern void Flash_ToggleTest(volatile Uint32 *ToggleReg, Uint32 Mask); +extern Uint16 Flash_DepRecover(); +extern float32 Flash_APIVersion(); +extern Uint16 Flash_APIVersionHex(); + +/*--------------------------------------------------------------------------- + Frequency Scale factor: + The calling program must provide this global parameter used + for frequency scaling the algo's. +----------------------------------------------------------------------------*/ + +extern Uint32 Flash_CPUScaleFactor; + +/*--------------------------------------------------------------------------- + Callback Function Pointer: + A callback function can be specified. This function will be called + at safe times during erase, program and verify. This function can + then be used to service an external watchdog or send a communications + packet. + + Note: + THE FLASH AND OTP ARE NOT AVAILABLE DURING THIS FUNCTION CALL. + THE FLASH/OTP CANNOT BE READ NOR CAN CODE EXECUTE FROM IT DURING THIS CALL + DO NOT CALL ANY OF THE THE FLASH API FUNCTIONS DURING THIS CALL +----------------------------------------------------------------------------*/ +extern void (*Flash_CallbackPtr) (void); + +/*--------------------------------------------------------------------------- + API load/run symbols: + These symbols are defined by the linker during the link. Refer to the + Flash28_API section in the example .cmd file: + + Flash28_API: + { + Flash28335_API_Library.lib(.econst) + Flash28335_API_Library.lib(.text) + } LOAD = FLASH, + RUN = SARAM, + LOAD_START(_Flash28_API_LoadStart), + LOAD_END(_Flash28_API_LoadEnd), + RUN_START(_Flash28_API_RunStart), + PAGE = 0 + + These are used to copy the flash API from flash to SARAM + +----------------------------------------------------------------------------*/ + +extern Uint16 Flash28_API_LoadStart; +extern Uint16 Flash28_API_LoadEnd; +extern Uint16 Flash28_API_RunStart; + +#ifdef __cplusplus +} +#endif /* extern "C" */ + + +#endif // -- end FLASH2833x_API_LIBRARY_H + +// --------- END OF FILE ---------------------------------- + diff --git a/FRAM/FRAMBuffer.cpp b/FRAM/FRAMBuffer.cpp new file mode 100644 index 0000000..7c3ab0f --- /dev/null +++ b/FRAM/FRAMBuffer.cpp @@ -0,0 +1,118 @@ +/* + * FRAMBuffer.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "FRAM/FRAMBuffer.h" + +namespace FRAM +{ +//CONSTRUCTOR +FRAMBuffer::FRAMBuffer(): + m_header(), + m_config(), + m_footer() +// +{}//CONSTRUCTOR + + + +void FRAMBuffer::update(const FRAM::FRAMHeader& header, const SYSCTRL::SystemControlConfiguration& config, const FRAM::FRAMFooter& footer) +{ + m_header = header; + m_config = config; + m_footer = footer; + // +}// +// + +bool FRAMBuffer::verify_header_and_footer(const FRAM::FRAMHeader& header, const FRAM::FRAMFooter& footer) +{ + if((m_header.class_id == 0xFFFF) + && (m_header.part_id == 0xFFFF) + && (m_header.software_version == 0xFFFF) + && (m_header.size_of_fram_data == 0xFFFF) + && (m_footer.foot == 0xFFFF)) + { + return false; + // + }else{ + if(m_header.class_id != header.class_id) + { + return false; + // + }else{ + if(m_header.part_id != header.part_id) + { + return false; + // + }else{ + if(m_header.software_version != header.software_version) + { + return false; + // + }else{ + if(m_header.size_of_fram_data != header.size_of_fram_data) + { + return false; + // + }else{ + if(m_footer.foot != footer.foot) + { + return false; + // + }else{ + return true; + // + } + } + } + } + } + } +}// +// + + +void FRAMBuffer::extract(FRAM::FRAMHeader& header, SYSCTRL::SystemControlConfiguration& config, FRAM::FRAMFooter& footer) +{ + header = m_header; + footer = m_footer; + config = m_config; + // +}// +// +void FRAMBuffer::extract_header(FRAMHeader& header) +{ + header = m_header; + // +}// +// +FRAM::FRAMHeader FRAMBuffer::get_header() +{ + return m_header; + // +}// +// +void FRAMBuffer::extract_footer(FRAMFooter& footer) +{ + footer = m_footer; + // +}// +// +FRAM::FRAMFooter FRAMBuffer::get_footer() +{ + return m_footer; + // +}// +// +void FRAMBuffer::extract_system_configuration(SYSCTRL::SystemControlConfiguration& config) +{ + config = m_config; + // +}// +// + +} /* namespace FRAM */ diff --git a/FRAM/FRAMBuffer.h b/FRAM/FRAMBuffer.h new file mode 100644 index 0000000..ba88345 --- /dev/null +++ b/FRAM/FRAMBuffer.h @@ -0,0 +1,65 @@ +/* + * FRAMBuffer.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include + + +#include "SYSCTRL/TypeControl.h" +#include "SYSCTRL/SystemConfigurator.h" + +#ifndef FRAM_FRAMBUFFER_H_ +#define FRAM_FRAMBUFFER_H_ + +namespace FRAM +{ + + +struct FRAMHeader +{ + int16_t class_id; + int16_t part_id; + int16_t software_version; + int16_t size_of_fram_data; + FRAMHeader(): + class_id(0x0FFFF), + part_id(0x0FFFF), + software_version(0x0FFFF), + size_of_fram_data(0x0FFFF) + {} +};//FRAMHeader + +struct FRAMFooter +{ + int16_t foot; + FRAMFooter(): + foot(0x0FFFF) + {} +};//FRAMFooter + + +class FRAMBuffer +{ +private: + FRAMHeader m_header; + SYSCTRL::SystemControlConfiguration m_config; + FRAMFooter m_footer; +public: + FRAMBuffer(); +public: + void update(const FRAM::FRAMHeader& header, const SYSCTRL::SystemControlConfiguration& config, const FRAM::FRAMFooter& footer); + bool verify_header_and_footer(const FRAM::FRAMHeader& header, const FRAM::FRAMFooter& footer); + void extract(FRAM::FRAMHeader& header, SYSCTRL::SystemControlConfiguration& config, FRAM::FRAMFooter& footer); + void extract_header(FRAMHeader& header); + FRAM::FRAMHeader get_header(); + void extract_footer(FRAMFooter& footer); + FRAM::FRAMFooter get_footer(); + void extract_system_configuration(SYSCTRL::SystemControlConfiguration& config); +}; + +} /* namespace FRAM */ + +#endif /* FRAM_FRAMBUFFER_H_ */ diff --git a/FRAM/FRAMConfigurationParameters.cpp b/FRAM/FRAMConfigurationParameters.cpp new file mode 100644 index 0000000..b3f7e8d --- /dev/null +++ b/FRAM/FRAMConfigurationParameters.cpp @@ -0,0 +1,446 @@ +/* + * FRAMConfigurationParameters.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "FRAM/FRAMDATABASE.h" + +namespace FRAM +{ + +void FRAMDATABASE::register_configuration_parameters(SYSCTRL::SystemControlConfiguration *sys_config) +{ + + m_fram_object_index = 0; + m_fram_object_address = 0; + m_fram_object_last_address = 0; + + //add_register_float(uint8_t readonly, float* pParam, float default_value); + //add_register_int(uint8_t readonly, int16_t* pParam, int16_t default_value); + // + + // + // References + // + add_float( 0, &sys_config->reference_current_limit_rms, CURRENT_LIMIT_RMS); + add_float( 0, &sys_config->reference_current_pfc_rms, CURRENT_PFC_RMS); + add_float( 0, &sys_config->reference_voltage_rms, GRID_VOLTAGE_REFERENCE); + add_float( 0, &sys_config->reference_voltage_high_limit_rms, GRID_VOLTAGE_HIGH_LIMIT); + add_float( 0, &sys_config->reference_voltage_dc, CELL_DC_VOLTAGE_REFERENCE); + //<> + + // + // Algorithm Control Register + add_uint16(0, &sys_config->algorithm_control.all, ENABLE_CONTROL_BIT); + //<> + + + // + // High Voltage Cell + // + add_uint16(0, &sys_config->hardware.cell_level, 4); + add_uint16(0, &sys_config->hardware.version.pwm, 210); + add_uint16(0, &sys_config->hardware.version.cell, 211); + add_uint32(0, &sys_config->hardware.version.cpu_cpld, 202); + //<> + + + add_float( 0, &sys_config->minimal_input_voltage_level, 10.0); + //<> + + // + // Scale Analog Signals + // + add_float( 0, &sys_config->scale_voltage_input_a, 0.166324854);//0.0227386411//0.0233486816; + add_float( 0, &sys_config->scale_voltage_input_b, 0.166955084);//0.0227597337//0.0234651081; + add_float( 0, &sys_config->scale_voltage_input_c, 0.170290515);//0.02278281//0.0236082859; + // + add_float( 0, &sys_config->scale_current_input_a, 0.0057266783); + add_float( 0, &sys_config->scale_current_input_b, 0.00571648451); + add_float( 0, &sys_config->scale_current_input_c, 0.00571565609); + // + add_float( 0, &sys_config->scale_current_cell_a, 0.0095403092);//0.00665648002; + add_float( 0, &sys_config->scale_current_cell_b, 0.00967073813);//0.00667640707; + add_float( 0, &sys_config->scale_current_cell_c, 0.00962774921);//0.00666095456; + // + add_float( 0, &sys_config->scale_voltage_load_a, 0.168764219);//0.0227408651//0.0232194811; + add_float( 0, &sys_config->scale_voltage_load_b, 0.167528242);//0.0227707103//0.0233941432; + add_float( 0, &sys_config->scale_voltage_load_c, 0.171417475);//0.0229060184//0.0234934501; + // + add_float( 0, &sys_config->scale_current_load_a, 0.00949461199);//0.00668919506; + add_float( 0, &sys_config->scale_current_load_b, 0.00953965727);//0.00669770781; + add_float( 0, &sys_config->scale_current_load_c, 0.00959520414);//0.00670575583; + // + add_float( 0, &sys_config->scale_current_bypass_a, 0.00953388773); + add_float( 0, &sys_config->scale_current_bypass_b, 0.00956917088); + add_float( 0, &sys_config->scale_current_bypass_c, 0.00956158526); + //<> + + + + // + // Amplitude Filter Parameters + // + add_float( 0, &sys_config->ampl_filter_current.time, 20.0e-3); + add_float( 0, &sys_config->ampl_filter_current.a3, 2.61313); + add_float( 0, &sys_config->ampl_filter_current.a2, 3.41422); + add_float( 0, &sys_config->ampl_filter_current.a1, 2.61313); + //<> + + // + // RMS Filter Parameters + // + add_float( 0, &sys_config->rms_filter_analog_signal.time, 10.0e-3); + add_float( 0, &sys_config->rms_filter_analog_signal.a3, 2.61313); + add_float( 0, &sys_config->rms_filter_analog_signal.a2, 3.41422); + add_float( 0, &sys_config->rms_filter_analog_signal.a1, 2.61313); + //<> + + + // + // Zero Drift Current Input + // + add_float( 0, &sys_config->zero_filter.time, 1.333); + //<> + + + // + // Cell DC Voltage Filter + // + add_float( 0, &sys_config->cell_dc_voltage_filter.time, 3.0e-3); + add_float( 0, &sys_config->cell_dc_voltage_filter.a3, 2.61313); + add_float( 0, &sys_config->cell_dc_voltage_filter.a2, 3.41422); + add_float( 0, &sys_config->cell_dc_voltage_filter.a1, 2.61313); + //<> + + + // + // Signal Decompose + // + add_float( 0, &sys_config->signal_decompose.projection_filter.time, 10.0e-3); + add_float( 0, &sys_config->signal_decompose.projection_filter.a3, 2.61313); + add_float( 0, &sys_config->signal_decompose.projection_filter.a2, 3.41422); + add_float( 0, &sys_config->signal_decompose.projection_filter.a1, 2.61313); + //<> + + + // + // Relative + // + add_float( 0, &sys_config->relative_voltage_input.minimal_amplitude_level, 0.1); + add_float( 0, &sys_config->relative_voltage_input.limit_relative_high, 1.1); + add_float( 0, &sys_config->relative_voltage_input.limit_relative_low, -1.1); + add_float( 0, &sys_config->relative_voltage_input.amplitude_filter.time, (float)(1.0/2.0/FP_PI/10.0)); + add_float( 0, &sys_config->relative_voltage_input.amplitude_filter.a3, 2.61313); + add_float( 0, &sys_config->relative_voltage_input.amplitude_filter.a2, 3.41422); + add_float( 0, &sys_config->relative_voltage_input.amplitude_filter.a1, 2.61313); + //<> + + + + + // + // Voltage PLL-ABC Parameters + // + add_float( 0, &sys_config->pll_abc_input_voltage.frequency_nominal, PLLABC_FREQUENCY_NOMINAL); + add_float( 0, &sys_config->pll_abc_input_voltage.filter.time, 1.0/PLLABC_FREQUENCY_CUT); + add_float( 0, &sys_config->pll_abc_input_voltage.controller.gain, PLLABC_FREQUENCY_CUT/2.0); + add_float( 0, &sys_config->pll_abc_input_voltage.controller.time, 4.0/PLLABC_FREQUENCY_CUT); + add_float( 0, &sys_config->pll_abc_input_voltage.controller.low_saturation, PLLABC_FREQUENCY_LIMIT_LOW); + add_float( 0, &sys_config->pll_abc_input_voltage.controller.high_saturation, PLLABC_FREQUENCY_LIMIT_HI); + add_float( 0, &sys_config->pll_abc_input_voltage.position.time, 1.0); + add_float( 0, &sys_config->pll_abc_input_voltage.position.low_saturation, FP_ZERO); + add_float( 0, &sys_config->pll_abc_input_voltage.position.high_saturation, 2.0 * FP_PI); + //<> + + + + // + // System Alarm + // + // exceed voltage level 1 + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_1.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 + (PROTECTION_EXCEED_VOLTAGE_LEVEL_1_PERCENT / (float)100.0)));//253.0; + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_1.period, 10.0); + // + // exceed voltage level 2 + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_2.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 + (PROTECTION_EXCEED_VOLTAGE_LEVEL_2_PERCENT / (float)100.0)));//264.5; + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_2.period, 5.0); + // + // exceed voltage level 3 + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_3.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 + (PROTECTION_EXCEED_VOLTAGE_LEVEL_3_PERCENT / (float)100.0)));//276.0; + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_3.period, 2.0); + // + // exceed voltage level 4 + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_4.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 + (PROTECTION_EXCEED_VOLTAGE_LEVEL_4_PERCENT / (float)100.0))); + add_float( 0, &sys_config->phase_alert_monitor.voltage_exceed_level_4.period, 0.004);//1.0; + // + // decrease voltage level 1 + add_float( 0, &sys_config->phase_alert_monitor.voltage_decrease_level_1.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 - (PROTECTION_DECREASE_VOLTAGE_LEVEL_1_PERCENT / (float)100.0)));//218.5;//195.5; + add_float( 0, &sys_config->phase_alert_monitor.voltage_decrease_level_1.period, 10.0); + // + // decrease voltage level 2 + add_float( 0, &sys_config->phase_alert_monitor.voltage_decrease_level_2.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 - (PROTECTION_DECREASE_VOLTAGE_LEVEL_2_PERCENT / (float)100.0)));//207.0;//172.5; + add_float( 0, &sys_config->phase_alert_monitor.voltage_decrease_level_2.period, 5.0); + // + // decrease voltage level 3 + add_float( 0, &sys_config->phase_alert_monitor.voltage_decrease_level_3.level, NOMINAL_GRID_VOLTAGE * ((float)1.0 - (PROTECTION_DECREASE_VOLTAGE_LEVEL_3_PERCENT / (float)100.0))); + add_float( 0, &sys_config->phase_alert_monitor.voltage_decrease_level_3.period, 2.0); + // + // current overload level 1 120% 60s + add_float( 0, &sys_config->phase_alert_monitor.current_overload_level_1.level, 30.0 * 14.4); + add_float( 0, &sys_config->phase_alert_monitor.current_overload_level_1.period, 60.0); + // + // current overload level 2 130% 10s + add_float( 0, &sys_config->phase_alert_monitor.current_overload_level_2.level, 30.0 * 15.6);//30.0*15.6 + add_float( 0, &sys_config->phase_alert_monitor.current_overload_level_2.period, 10.0); + // + // current overload level 3 150% 1ms + add_float( 0, &sys_config->phase_alert_monitor.current_overload_level_3.level, 30.0 * 18.0); + add_float( 0, &sys_config->phase_alert_monitor.current_overload_level_3.period, 0.004); + // + // current invertor overload level 1 110% 60s + add_float( 0, &sys_config->phase_alert_monitor.current_invertor_overload_level_1.level, 13.2); + add_float( 0, &sys_config->phase_alert_monitor.current_invertor_overload_level_1.period, 60.0); + // + // current invertor overload level 2 130% 10s + add_float( 0, &sys_config->phase_alert_monitor.current_invertor_overload_level_2.level, 15.6); + add_float( 0, &sys_config->phase_alert_monitor.current_invertor_overload_level_2.period, 10.0); + // + // current invertor overload level 3 150% 1ms + add_float( 0, &sys_config->phase_alert_monitor.current_invertor_overload_level_3.level, 18.0); + add_float( 0, &sys_config->phase_alert_monitor.current_invertor_overload_level_3.period, 0.004); + // + // current input overload level 1 110% 60s + add_float( 0, &sys_config->phase_alert_monitor.current_input_overload_level_1.level, 99.0); + add_float( 0, &sys_config->phase_alert_monitor.current_input_overload_level_1.period, 60.0); + // + // current input overload level 2 130% 10s + add_float( 0, &sys_config->phase_alert_monitor.current_input_overload_level_2.level, 117.0); + add_float( 0, &sys_config->phase_alert_monitor.current_input_overload_level_2.period, 10.0); + // + // current input overload level 3 150% 1ms + add_float( 0, &sys_config->phase_alert_monitor.current_input_overload_level_3.level, 135.0); + add_float( 0, &sys_config->phase_alert_monitor.current_input_overload_level_3.period, 0.004); + //<> + + + // + // DIGITAL INPUTS + // + add_float( 0, &sys_config->digital_input_config.period, 50.0e-3); //3001 - 3020 + //<> + + + // + // FAN CONTROL + // + add_float( 0, &sys_config->fan_control.timer_period, 5.0*60.0); + //<> + + + // + // Generator ABC + // + add_float( 0, &sys_config->generator_abc.amplitude, 1.0); + add_float( 0, &sys_config->generator_abc.frequency, 2.0*FP_PI*50.0); + add_float( 0, &sys_config->generator_abc.phase_shift, 0.0); + //<> + + + // + // Reference PWM-Generator + // + //add_float( 0, &sys_config->generator_pwm.frequency, 2.0*FP_PI*1.0); + //add_float( 0, &sys_config->generator_abc.phase_shift, 0.0); + + //add_float( 0, &sys_config->gen_inp_volt.amplitude.direct.d, 220.0); + // + //add_float( 0, &sys_config->gen_out_volt.amplitude.direct.d, 220.0); + //add_float( 0, &sys_config->gen_out_volt.phase.direct.phase, 0.122756);//FP_PI/4.0); + // + //add_float( 0, &sys_config->gen_out_current.amplitude.direct.d, 50.0); + //add_float( 0, &sys_config->gen_out_current.phase.direct.phase, 0.122756);//FP_PI/3.0; + //<> + + // + // AlgorithmGeneratorReferences + // + add_float( 0, &sys_config->algorithm_source_references.voltage, 0.0); + add_float( 0, &sys_config->algorithm_source_references.phase_shift, 0.0); + + // + // Harmonica Analyzer + // + add_float( 0, &sys_config->ph_harmonica_5.time, 50.0e-3); + add_float( 0, &sys_config->ph_harmonica_5.a3, 2.61313); + add_float( 0, &sys_config->ph_harmonica_5.a2, 3.41422); + add_float( 0, &sys_config->ph_harmonica_5.a1, 2.61313); + //<> + + + + // + // Reference Intensity Idref Iqref in Start Mode + // + add_float( 0, &sys_config->intensity_id_iq_references.damp_factor, 0.7071); + add_float( 0, &sys_config->intensity_id_iq_references.time, 20.0e-3); + //<> + + + // + // Regulators + // + +#if TYPECONTROL == VECTORCONTROL + // +#if TYPE_VOLTAGE_CONTROLLER == VOLTAGE_CONTROLLER_PII + add_float( 0, &sys_config->regulator_voltage_load_dq.gain, 1.0); + add_float( 0, &sys_config->regulator_voltage_load_dq.time, 1.6e-3); + add_float( 0, &sys_config->regulator_voltage_load_dq.high_saturation, 4500.0); + add_float( 0, &sys_config->regulator_voltage_load_dq.low_saturation, -4500.0); + // + add_float( 0, &sys_config->integrator_voltage_dq.time, 2.0e-3); + add_float( 0, &sys_config->integrator_voltage_dq.high_saturation, 4500.0); + add_float( 0, &sys_config->integrator_voltage_dq.low_saturation, -4500.0); + // + add_float( 0, &sys_config->reference_voltage_dq_intensity.time, 200.0e-3); + // +#endif +#if TYPE_VOLTAGE_CONTROLLER == VOLTAGE_CONTROLLER_I + + add_float( 0, &sys_config->regulator_voltage_load_dq.gain, 0.4); + add_float( 0, &sys_config->regulator_voltage_load_dq.time, 1600.0e-6); + add_float( 0, &sys_config->regulator_voltage_load_dq.high_saturation, 4500.0); + add_float( 0, &sys_config->regulator_voltage_load_dq.low_saturation, -4500.0); + + // + add_float( 0, &sys_config->integrator_voltage_dq.time, 4.0e-3); // 4.0e-3 for single winding; 2.0e-3 for double winding + add_float( 0, &sys_config->integrator_voltage_dq.high_saturation, 4500.0); + add_float( 0, &sys_config->integrator_voltage_dq.low_saturation, -4500.0); + // + add_float( 0, &sys_config->reference_voltage_dq_intensity.time, 200.0e-3); + // +#endif + // + //add_float( 0, &sys_config->regulator_current_limit.gain, 1.0); + add_float( 0, &sys_config->regulator_current_limit.time, 140.0e-3); + add_float( 0, &sys_config->regulator_current_limit.high_saturation, REGULATOR_CURRENT_LIMIT_HIGH_SATURATION); + add_float( 0, &sys_config->regulator_current_limit.low_saturation, REGULATOR_CURRENT_LIMIT_LOW_SATURATION); + // + add_float( 0, &sys_config->regulator_current_pfc.gain, 0.25); + add_float( 0, &sys_config->regulator_current_pfc.time, 800.0e-3); + add_float( 0, &sys_config->regulator_current_pfc.high_saturation, REGULATOR_CURRENT_PFC_HIGH_SATURATION); + add_float( 0, &sys_config->regulator_current_pfc.low_saturation, REGULATOR_CURRENT_PFC_LOW_SATURATION); + // +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_PI + add_float( 0, &sys_config->regulator_current_load_dq.gain, 8.0); // 4.0 for single winding; 8.0 for double winding + add_float( 0, &sys_config->regulator_current_load_dq.time, 6.4e-3); + add_float( 0, &sys_config->regulator_current_load_dq.high_saturation, 500.0); + add_float( 0, &sys_config->regulator_current_load_dq.low_saturation, -500.0); +#endif +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_P + add_float( 0, &sys_config->regulator_current_load_dq.gain, 8.0); + add_float( 0, &sys_config->regulator_current_load_dq.high_saturation, 500.0); + add_float( 0, &sys_config->regulator_current_load_dq.low_saturation, -500.0); +#endif + // + add_float( 0, &sys_config->referencer_current_bypass_dq.time, 25.6e-3); + add_float( 0, &sys_config->referencer_current_bypass_dq.high_saturation, 240.0); + add_float( 0, &sys_config->referencer_current_bypass_dq.low_saturation, -240.0); + // +#endif + + +#if TYPECONTROL == SCALARCONTROL + add_float( 0, &sys_config->regulator_voltage_load_active_reactive.gain, 0.04); + add_float( 0, &sys_config->regulator_voltage_load_active_reactive.time, 10.0e-3); + add_float( 0, &sys_config->regulator_voltage_load_active_reactive.high_saturation, 4500.0); + add_float( 0, &sys_config->regulator_voltage_load_active_reactive.low_saturation, -4500.0); + // + add_float( 0, &sys_config->regulator_current_limit.gain, 1.0); + add_float( 0, &sys_config->regulator_current_limit.time, 5.0); + add_float( 0, &sys_config->regulator_current_limit.high_saturation, GRID_VOLTAGE_REFERENCE * 0.57735); + add_float( 0, &sys_config->regulator_current_limit.low_saturation, FP_ZERO); + // + add_float( 0, &sys_config->regulator_current_pfc.gain, 0.25); + add_float( 0, &sys_config->regulator_current_pfc.time, 800.0e-3); + add_float( 0, &sys_config->regulator_current_pfc.high_saturation, GRID_VOLTAGE_REFERENCE * 0.57735); + add_float( 0, &sys_config->regulator_current_pfc.low_saturation, -GRID_VOLTAGE_REFERENCE * 0.57735); + // + add_float( 0, &sys_config->current_regulator_active.gain, 0.17); // 0.34 for single winding + add_float( 0, &sys_config->current_regulator_active.time, 0.04); + add_float( 0, &sys_config->current_regulator_active.high_saturation, 500.0); + add_float( 0, &sys_config->current_regulator_active.low_saturation, -500.0); + // + add_float( 0, &sys_config->current_regulator_reactive.gain, 0.17); // 0.34 for single winding + add_float( 0, &sys_config->current_regulator_reactive.time, 0.04); + add_float( 0, &sys_config->current_regulator_reactive.high_saturation, 500.0); + add_float( 0, &sys_config->current_regulator_reactive.low_saturation, -500.0); + // + add_float( 0, &sys_config->current_referencer.gain, 1.0); + add_float( 0, &sys_config->current_referencer.time, 0.160); + add_float( 0, &sys_config->current_referencer.high_saturation, 20.0); + add_float( 0, &sys_config->current_referencer.low_saturation, -20.0); + // + add_float( 0, &sys_config->regulator_dc_voltage.gain, 0.05); + add_float( 0, &sys_config->regulator_dc_voltage.time, 800.0e-3); + add_float( 0, &sys_config->regulator_dc_voltage.high_saturation, FP_ZERO); + add_float( 0, &sys_config->regulator_dc_voltage.low_saturation, -GRID_VOLTAGE_REFERENCE * 0.57735); +#endif + //<> + + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + add_float( 0, &sys_config->drc_voltage_decomposer.filter.time, 31.83e-3); //31.83e-3//6.366e-3//3.183e-3 + // + add_float( 0, &sys_config->drc_voltage_controller.gain, 0.4); //0.4 - for single winding; 0.7958 - for double winding. //7.958//1.592//0.7958 + add_float( 0, &sys_config->drc_voltage_controller.time, 3.2e-3); //31.83e-3//6.366e-3//3.183e-3 + add_float( 0, &sys_config->drc_voltage_controller.high_saturation, 4500.0); + add_float( 0, &sys_config->drc_voltage_controller.low_saturation, -4500.0); + // + add_float( 0, &sys_config->drc_reference_voltage_direct_intensity.time, 333.0e-3); + add_float( 0, &sys_config->drc_reference_voltage_direct_intensity.damp_factor, 0.9); + // + add_float( 0, &sys_config->drc_regulator_current_load.gain, 4.0);// 4.0 - for single winding; 8.0 - for double winding + add_float( 0, &sys_config->drc_regulator_current_load.time, 6.4e-3); + add_float( 0, &sys_config->drc_regulator_current_load.high_saturation, 500.0); + add_float( 0, &sys_config->drc_regulator_current_load.low_saturation, -500.0); + // + add_float( 0, &sys_config->drc_referencer_current_bypass.time, 25.6e-3); + add_float( 0, &sys_config->drc_referencer_current_bypass.high_saturation, 240.0); + add_float( 0, &sys_config->drc_referencer_current_bypass.low_saturation, -240.0); + // + add_float( 0, &sys_config->drc_regulator_current_limit.time, 140.0e-3); + add_float( 0, &sys_config->drc_regulator_current_limit.high_saturation, REGULATOR_CURRENT_LIMIT_HIGH_SATURATION); + add_float( 0, &sys_config->drc_regulator_current_limit.low_saturation, REGULATOR_CURRENT_LIMIT_LOW_SATURATION); + // + add_float( 0, &sys_config->drc_regulator_current_pfc.gain, 0.25); + add_float( 0, &sys_config->drc_regulator_current_pfc.time, 800.0e-3); + add_float( 0, &sys_config->drc_regulator_current_pfc.high_saturation, REGULATOR_CURRENT_PFC_HIGH_SATURATION); + add_float( 0, &sys_config->drc_regulator_current_pfc.low_saturation, REGULATOR_CURRENT_PFC_LOW_SATURATION); + // +#endif + //<> + + + + // + // Timers + // + add_float( 0, &sys_config->timer_start.period, 5.0); + add_float( 0, &sys_config->timer_stop.period, 5.0); + //<> + + + // + // Contactor Control Fault + // + add_float( 0, &sys_config->contactor.period, 0.4); + + +}// + +} /* namespace FRAM */ diff --git a/FRAM/FRAMDATABASE.cpp b/FRAM/FRAMDATABASE.cpp new file mode 100644 index 0000000..27bee4e --- /dev/null +++ b/FRAM/FRAMDATABASE.cpp @@ -0,0 +1,439 @@ +/* + * FRAMDATABASE.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "FRAM/FRAMDATABASE.h" + +namespace FRAM +{ + + +FRAMDATABASE::FRAMDATABASE(): + m_mode(), + m_state(), + m_fram_data_buffer(), + m_buffer_pointer((uint16_t*)&m_fram_data_buffer), + m_fram_object(), + m_fram_size(FRAM_FRAM_SIZE), + m_fram_object_index(0), + m_fram_object_address(0), + m_fram_object_last_address(0), + m_fram_rw_index(0), + m_header(), + m_footer(), + m_verify(false) +{ + m_header.class_id = HEADER_CLASS_ID; + m_header.part_id = HEADER_PART_ID; + m_header.software_version = HEADER_SOFTWARE_VERSION; + m_header.size_of_fram_data = sizeof(m_fram_data_buffer); + m_footer.foot = FOOTER_FOOT; +} +// + + + + + + + + +FRAM::FRAMDATABASE::mode_t FRAMDATABASE::get_mode() +{ + return m_mode; + // +}// +// +bool FRAMDATABASE::compare_mode(FRAM::FRAMDATABASE::mode_t mode) +{ + return mode == m_mode; + // +}// +// +FRAM::FRAMDATABASE::state_t FRAMDATABASE::get_state() +{ + return m_state; + // +}// +// +bool FRAMDATABASE::compare_state(FRAM::FRAMDATABASE::state_t state) +{ + return state == m_state; + // +}// +// +bool FRAMDATABASE::is_free() +{ + return m_state == FRAM::FRAMDATABASE::FREE; +}// +// +bool FRAMDATABASE::is_busy() +{ + return m_state == FRAM::FRAMDATABASE::BUSY; +}// +// +bool FRAMDATABASE::is_read() +{ + return m_mode == FRAM::FRAMDATABASE::READ; +}// +// +bool FRAMDATABASE::is_burn() +{ + return m_mode == FRAM::FRAMDATABASE::BURN; +}// +// +bool FRAMDATABASE::is_erase() +{ + return m_mode == FRAM::FRAMDATABASE::ERASE; +}// +// +bool FRAMDATABASE::is_restore() +{ + return m_mode == FRAM::FRAMDATABASE::RESTORE; +}// +// +bool FRAMDATABASE::is_verify() +{ + return m_mode == FRAM::FRAMDATABASE::VERIFY; +}// +// +void FRAMDATABASE::set_read() +{ + m_state = FRAM::FRAMDATABASE::BUSY; + m_mode = FRAM::FRAMDATABASE::READ; + m_fram_rw_index = 0; + // +}// +// +void FRAMDATABASE::set_burn() +{ + m_state = FRAM::FRAMDATABASE::BUSY; + m_mode = FRAM::FRAMDATABASE::BURN; + m_fram_rw_index = 0; + // +}// +// +void FRAMDATABASE::set_erase() +{ + m_state = FRAM::FRAMDATABASE::BUSY; + m_mode = FRAM::FRAMDATABASE::ERASE; + m_fram_rw_index = 0; + // +}// +// +void FRAMDATABASE::set_verify() +{ + m_state = FRAM::FRAMDATABASE::BUSY; + m_mode = FRAM::FRAMDATABASE::VERIFY; + m_fram_rw_index = 0; + // +}// +// +void FRAMDATABASE::set_restore() +{ + m_state = FRAM::FRAMDATABASE::BUSY; + m_mode = FRAM::FRAMDATABASE::RESTORE; + m_fram_rw_index = 0; + // +}// +// +void FRAMDATABASE::set_break() +{ + m_state = FRAM::FRAMDATABASE::FREE; + m_mode = FRAM::FRAMDATABASE::WAIT; + m_fram_rw_index = 0; + // +}// +// +FRAM::FRAMHeader FRAMDATABASE::get_header() +{ + return m_header; + // +}// +// +FRAM::FRAMFooter FRAMDATABASE::get_footer() +{ + return m_footer; + // +}// +// +void FRAMDATABASE::extract_system_configuration(SYSCTRL::SystemControlConfiguration *sys_config) +{ + m_fram_data_buffer.extract_system_configuration(*sys_config); + // +}// +// +void FRAMDATABASE::implement_dafault_configuration() +{ + for(uint16_t i = 0; i < m_fram_object_index; i++) + { + FRAM::FRAMDataObjects& o = m_fram_object[i]; + o.restore_default_value(); + // + }//for + // +}// +// + +void FRAMDATABASE::upload_configuration(SYSCTRL::SystemControlConfiguration *sys_config) +{ + register_configuration_parameters(sys_config); + + //implement_dafault_configuration(); + + read_from_fram_to_buffer(); + + m_verify = m_fram_data_buffer.verify_header_and_footer(m_header, m_footer); + //m_verify = false; + if(m_verify) + { + extract_system_configuration(sys_config); + } + else + { + erase_fram_buffer(); + + implement_dafault_configuration(); + + m_fram_data_buffer.update(m_header, *sys_config, m_footer); + + write_to_fram_from_buffer(); + // + }//if else +}// +// + +void FRAMDATABASE::update_buffer(const SYSCTRL::SystemControlConfiguration *sys_config) +{ + m_fram_data_buffer.update(m_header, *sys_config, m_footer); + // +}// +// +void FRAMDATABASE::erase_fram_index() +{ + if(m_mode == FRAM::FRAMDATABASE::ERASE) + { + if(m_fram_rw_index < sizeof(m_fram_data_buffer)) + { + writeint(0xFFFF, m_fram_rw_index << 1); + m_fram_rw_index++; + } + else + { + set_break(); + // + }//if else + }//if + // +}// +// +void FRAMDATABASE::verify_fram_index() +{ + if(m_mode == FRAM::FRAMDATABASE::VERIFY) + { + if(m_fram_rw_index < sizeof(m_fram_data_buffer)) + { + m_fram_rw_index++; + } + else + { + set_break(); + // + }//if else + }//if + // +}// +// +void FRAMDATABASE::write_fram_index() +{ + if(m_mode == FRAM::FRAMDATABASE::BURN) + { + if(m_fram_rw_index < sizeof(m_fram_data_buffer)) + { + writeint((*(m_buffer_pointer + m_fram_rw_index)), m_fram_rw_index << 1); + m_fram_rw_index++; + } + else + { + set_break(); + // + }//if else + }//if + // +}// +// +void FRAMDATABASE::read_fram_index() +{ + if(m_mode == FRAM::FRAMDATABASE::READ) + { + if(m_fram_rw_index < sizeof(m_fram_data_buffer)) + { + *(m_buffer_pointer + m_fram_rw_index) = readint(m_fram_rw_index << 1); + m_fram_rw_index++; + } + else + { + set_break(); + // + }//if else + }//if + // +}// +// +void FRAMDATABASE::restore_fram_index() +{ + if(m_mode == FRAM::FRAMDATABASE::RESTORE) + { + if(m_fram_rw_index < sizeof(m_fram_data_buffer)) + { + writeint((*(m_buffer_pointer + m_fram_rw_index)), m_fram_rw_index << 1); + m_fram_rw_index++; + } + else + { + set_break(); + // + }//if else + }//if + // +}// +// +void FRAMDATABASE::read_from_fram_to_buffer() +{ + set_read(); + for(m_fram_rw_index = 0; m_fram_rw_index < sizeof(m_fram_data_buffer); m_fram_rw_index++) + { + *(m_buffer_pointer + m_fram_rw_index) = readint(m_fram_rw_index << 1); + // + }//for + // + m_mode = FRAM::FRAMDATABASE::READ; + m_state = FRAMDATABASE::BUSY; + set_break(); + // +}// +// +void FRAMDATABASE::write_to_fram_from_buffer() +{ + set_burn(); + for(m_fram_rw_index = 0; m_fram_rw_index < sizeof(m_fram_data_buffer); m_fram_rw_index++) + { + writeint((*(m_buffer_pointer + m_fram_rw_index)), m_fram_rw_index << 1); + // + }//for + // + set_break(); + // +}// +// +void FRAMDATABASE::erase_fram_buffer() +{ + set_verify(); + for(m_fram_rw_index = 0; m_fram_rw_index < sizeof(m_fram_data_buffer); m_fram_rw_index++) + { + writeint(0xFFFF, m_fram_rw_index << 1); + *(m_buffer_pointer + m_fram_rw_index) = readint(m_fram_rw_index << 1); + // + }//for + // + set_break(); + // +}// +// + + +void FRAMDATABASE::add_float(uint8_t readonly, float* pParam, float default_value) +{ + if((m_fram_object_index < NUMBER_FRAM_PARAMETERS)&& + (((m_fram_object_address + (sizeof(float)<<1)) < m_fram_size))) + { + FRAM::FRAMDataObjects& object = m_fram_object[m_fram_object_index]; + object.add_register_float(m_fram_object_address, readonly, pParam, default_value); + m_fram_object_index++; + m_fram_object_address += (sizeof(float) << 1); + m_fram_object_last_address = m_fram_object_address; + // + }//if + // +}// +// +void FRAMDATABASE::add_int16(uint8_t readonly, int16_t* pParam, int16_t default_value) +{ + if((m_fram_object_index < NUMBER_FRAM_PARAMETERS)&& + (((m_fram_object_address + (sizeof(uint16_t)<<1)) < m_fram_size))) + { + FRAM::FRAMDataObjects& object = m_fram_object[m_fram_object_index]; + object.add_register_int16(m_fram_object_address, readonly, pParam, default_value); + m_fram_object_index++; + m_fram_object_address += sizeof(int16_t) << 1; + m_fram_object_last_address = m_fram_object_address; + // + }//if + // +}// +// +void FRAMDATABASE::add_int32(uint8_t readonly, int32_t* pParam, int32_t default_value) +{ + if((m_fram_object_index < NUMBER_FRAM_PARAMETERS)&& + (((m_fram_object_address + (sizeof(int32_t)<<1)) < m_fram_size))) + { + FRAM::FRAMDataObjects& object = m_fram_object[m_fram_object_index]; + object.add_register_int32(m_fram_object_address, readonly, pParam, default_value); + m_fram_object_index++; + m_fram_object_address += (sizeof(int32_t) << 1); + m_fram_object_last_address = m_fram_object_address; + // + }//if +}// +// +void FRAMDATABASE::add_uint16(uint8_t readonly, uint16_t* pParam, uint16_t default_value) +{ + if((m_fram_object_index < NUMBER_FRAM_PARAMETERS)&& + (((m_fram_object_address + (sizeof(uint16_t)<<1)) < m_fram_size))) + { + FRAM::FRAMDataObjects& object = m_fram_object[m_fram_object_index]; + object.add_register_uint16(m_fram_object_address, readonly, pParam, default_value); + m_fram_object_index++; + m_fram_object_address += sizeof(uint16_t) << 1; + m_fram_object_last_address = m_fram_object_address; + // + }//if + // +}// +// +void FRAMDATABASE::add_uint32(uint8_t readonly, uint32_t* pParam, uint32_t default_value) +{ + if((m_fram_object_index < NUMBER_FRAM_PARAMETERS)&& + (((m_fram_object_address + (sizeof(uint32_t)<<1)) < m_fram_size))) + { + FRAM::FRAMDataObjects& object = m_fram_object[m_fram_object_index]; + object.add_register_uint32(m_fram_object_address, readonly, pParam, default_value); + m_fram_object_index++; + m_fram_object_address += (sizeof(uint32_t) << 1); + m_fram_object_last_address = m_fram_object_address; + // + }//if +}// +// +void FRAMDATABASE::add_bool(uint8_t readonly, bool* pParam, bool default_value) +{ + if((m_fram_object_index < NUMBER_FRAM_PARAMETERS)&& + (((m_fram_object_address + (sizeof(uint16_t)<<1)) < m_fram_size))) + { + FRAM::FRAMDataObjects& object = m_fram_object[m_fram_object_index]; + object.add_register_bool(m_fram_object_address, readonly, pParam, default_value); + m_fram_object_index++; + m_fram_object_address += sizeof(int16_t) << 1; + m_fram_object_last_address = m_fram_object_address; + // + }//if + // +}// +// + + + +} /* namespace FRAM */ diff --git a/FRAM/FRAMDATABASE.h b/FRAM/FRAMDATABASE.h new file mode 100644 index 0000000..eb6e250 --- /dev/null +++ b/FRAM/FRAMDATABASE.h @@ -0,0 +1,101 @@ +/* + * FRAMDATABASE.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + + +#include +#include + +#include "framework.h" +#include "FRAM/FRAMDefinitions.h" +#include "FRAM/FRAMBuffer.h" +#include "FRAM/FRAMDataObjects.h" +#include "FRAM/FRAMVariant.h" +#include "SYSCTRL/SystemConfigurator.h" +#include "SYSCTRL/SystemDefinitions.h" + +#ifndef FRAM_FRAMDATABASE_H_ +#define FRAM_FRAMDATABASE_H_ + +namespace FRAM +{ + + +class FRAMDATABASE +{ +public: + enum mode_t {WAIT, READ, BURN, ERASE, VERIFY, RESTORE}; + enum state_t {BUSY, FREE}; +private: + mode_t m_mode; + state_t m_state; +private: + FRAM::FRAMBuffer m_fram_data_buffer; + uint16_t *m_buffer_pointer; + FRAM::FRAMDataObjects m_fram_object[NUMBER_FRAM_PARAMETERS]; + uint16_t m_fram_size; + uint16_t m_fram_object_index; + uint16_t m_fram_object_address; + uint16_t m_fram_object_last_address; + uint16_t m_fram_rw_index; + FRAM::FRAMHeader m_header; + FRAM::FRAMFooter m_footer; + bool m_verify; +public: + FRAMDATABASE(); +public: + mode_t get_mode(); + bool compare_mode(mode_t mode); + state_t get_state(); + bool compare_state(state_t state); +public: + bool is_free(); + bool is_busy(); + bool is_read(); + bool is_burn(); + bool is_erase(); + bool is_restore(); + bool is_verify(); +public: + void set_read(); + void set_burn(); + void set_erase(); + void set_verify(); + void set_restore(); + void set_break(); +public: + void upload_configuration(SYSCTRL::SystemControlConfiguration *sys_config); + void update_buffer(const SYSCTRL::SystemControlConfiguration *sys_config); + void erase_fram_index(); + void verify_fram_index(); + void write_fram_index(); + void read_fram_index(); + void restore_fram_index(); + void read_from_fram_to_buffer(); + void write_to_fram_from_buffer(); + void erase_fram_buffer(); +public: + FRAM::FRAMHeader get_header(); + FRAM::FRAMFooter get_footer(); + void extract_system_configuration(SYSCTRL::SystemControlConfiguration *sys_config); + void implement_dafault_configuration(); + // + // +private: + void add_float(uint8_t readonly, float* pParam, float default_value); + void add_int16(uint8_t readonly, int16_t* pParam, int16_t default_value); + void add_int32(uint8_t readonly, int32_t* pParam, int32_t default_value); + void add_uint16(uint8_t readonly, uint16_t* pParam, uint16_t default_value); + void add_uint32(uint8_t readonly, uint32_t* pParam, uint32_t default_value); + void add_bool(uint8_t readonly, bool* pParam, bool default_value); +public: + void register_configuration_parameters(SYSCTRL::SystemControlConfiguration *sys_config); + +};//class FRAMDATABASE + +} /* namespace FRAM */ + +#endif /* FRAM_FRAMDATABASE_H_ */ diff --git a/FRAM/FRAMDataObjects.cpp b/FRAM/FRAMDataObjects.cpp new file mode 100644 index 0000000..d939536 --- /dev/null +++ b/FRAM/FRAMDataObjects.cpp @@ -0,0 +1,201 @@ +/* + * FRAMDataObjects.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "FRAM/FRAMDataObjects.h" + +namespace FRAM +{ + +FRAMDataObjects::FRAMDataObjects(): + m_address(0), + m_is_read_only(false), + m_pParam(0), + m_default_value() +// +{}//CONSTRUCTOR +// +void FRAMDataObjects::restore_default_value() +{ + if(m_pParam != 0) + { + switch(m_default_value.get_type()) + { + case FRAM::FRAM_VARIANT_FLOAT: { *((float*) m_pParam) = m_default_value.get_float(); break;} + case FRAM::FRAM_VARIANT_INT16: { *((int16_t*) m_pParam) = m_default_value.get_int16(); break;} + case FRAM::FRAM_VARIANT_INT32: { *((int32_t*) m_pParam) = m_default_value.get_int32(); break;} + case FRAM::FRAM_VARIANT_UINT16: { *((uint16_t*) m_pParam) = m_default_value.get_uint16(); break;} + case FRAM::FRAM_VARIANT_UINT32: { *((uint32_t*) m_pParam) = m_default_value.get_uint32(); break;} + case FRAM::FRAM_VARIANT_BOOL: { *((bool*) m_pParam) = m_default_value.get_bool(); break;} + default: {break;} + }//switch + }//if +}// +// +void FRAMDataObjects::add_register_float(uint16_t address, uint8_t readonly, float* pParam, float default_value) +{ + m_address = address; + m_is_read_only = 0 != readonly ? true : false; + m_pParam = pParam; + m_default_value.set_float(default_value); + // +}// +// +void FRAMDataObjects::add_register_int16(uint16_t address, uint8_t readonly, int16_t* pParam, int16_t default_value) +{ + m_address = address; + m_is_read_only = 0 != readonly ? true : false; + m_pParam = pParam; + m_default_value.set_int16(default_value); + // +}// +// +void FRAMDataObjects::add_register_int32(uint16_t address, uint8_t readonly, int32_t* pParam, int32_t default_value) +{ + m_address = address; + m_is_read_only = 0 != readonly ? true : false; + m_pParam = pParam; + m_default_value.set_int32(default_value); + // +}// +// +void FRAMDataObjects::add_register_uint16(uint16_t address, uint8_t readonly, uint16_t* pParam, uint16_t default_value) +{ + m_address = address; + m_is_read_only = 0 != readonly ? true : false; + m_pParam = pParam; + m_default_value.set_uint16(default_value); + // +}// +// +void FRAMDataObjects::add_register_uint32(uint16_t address, uint8_t readonly, uint32_t* pParam, uint32_t default_value) +{ + m_address = address; + m_is_read_only = 0 != readonly ? true : false; + m_pParam = pParam; + m_default_value.set_uint32(default_value); + // +}// +// +void FRAMDataObjects::add_register_bool(uint16_t address, uint8_t readonly, bool* pParam, bool default_value) +{ + m_address = address; + m_is_read_only = 0 != readonly ? true : false; + m_pParam = pParam; + m_default_value.set_bool(default_value); + // +}// +// +uint16_t FRAMDataObjects::get_address() const +{ + return m_address; + // +}// +// +void FRAMDataObjects::write_parameter(const void *pBuffer, uint8_t buffer_size) +{ + if((m_pParam != 0)&& + (pBuffer != 0) && + (buffer_size > 0) && + (m_is_read_only != true)) + { + switch(m_default_value.get_type()) + { + case FRAM::FRAM_VARIANT_FLOAT: { if(4 == buffer_size) *((float*) m_pParam) = *((float*) pBuffer); break;} + case FRAM::FRAM_VARIANT_INT16: { if(2 == buffer_size) *((int16_t*) m_pParam) = *((int16_t*) pBuffer); break;} + default: {break;} + }//switch + // + }//if + // +}// +// +void FRAMDataObjects::read_parameter(void *pBuffer, uint8_t buffer_size) const +{ + if((m_pParam != 0) && + (pBuffer != 0) && + (buffer_size > 0)) + { + switch(m_default_value.get_type()) + { + case FRAM::FRAM_VARIANT_FLOAT: {if(4 == buffer_size) *((float*) pBuffer) = *((float*) m_pParam); break;} + case FRAM::FRAM_VARIANT_INT16: {if(2 == buffer_size) *((int16_t*) pBuffer) = *((int16_t*) m_pParam); break;} + default: {break;} + }//switch + // + }//if +}// + +void FRAMDataObjects::fram_write_parameter() +{ + if(m_pParam != 0) + { + switch(m_default_value.get_type()) + { + case FRAM::FRAM_VARIANT_FLOAT: + { + writefloat(*((float*) m_pParam), m_address); + break; + } + case FRAM::FRAM_VARIANT_INT16: + { + writeint(*((int16_t*) m_pParam), m_address); + break; + } + default: {break;} + }//switch + // + }//if +}// +// +void FRAMDataObjects::fram_read_parameter() +{ + if(m_pParam != 0) + { + switch(m_default_value.get_type()) + { + case FRAM::FRAM_VARIANT_FLOAT: + { + *((float*) m_pParam) = readfloat(m_address); + break; + } + case FRAM::FRAM_VARIANT_INT16: + { + *((int16_t*) m_pParam) = readint(m_address); + break; + } + default: {break;} + }//switch + // + }//if + // +}// +// +void FRAMDataObjects::write_to_fram_data(Uint16 *Dest, Uint32 Length) +{ + for(Uint16 i = 0; i < Length; i++) + { + writeint((*Dest++),i); + // + }//for + // +}// +// +void FRAMDataObjects::read_from_fram_data(Uint16 *BuffAddr, Uint32 Length) +{ + for(Uint16 i = 0; i < Length; i++) + { + (*BuffAddr++) = readint(i); + // + }//for + // +}// +// + + + +// +} /* namespace FRAM */ diff --git a/FRAM/FRAMDataObjects.h b/FRAM/FRAMDataObjects.h new file mode 100644 index 0000000..43cf6f0 --- /dev/null +++ b/FRAM/FRAMDataObjects.h @@ -0,0 +1,49 @@ +/* + * FRAMACCESS.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include + +#include "framework.h" +#include "FRAM/FRAMVariant.h" + +#ifndef FRAM_FRAMDATAOBJECTS_H_ +#define FRAM_FRAMDATAOBJECTS_H_ + +namespace FRAM +{ + +class FRAMDataObjects +{ +private: + uint16_t m_address; + bool m_is_read_only; + void* m_pParam; + FRAM::FRAMVariant m_default_value; +public: + FRAMDataObjects(); + void restore_default_value(); + void add_register_float(uint16_t address, uint8_t readonly, float* pParam, float default_value); + void add_register_int16(uint16_t address, uint8_t readonly, int16_t* pParam, int16_t default_value); + void add_register_int32(uint16_t address, uint8_t readonly, int32_t* pParam, int32_t default_value); + void add_register_uint16(uint16_t address, uint8_t readonly, uint16_t* pParam, uint16_t default_value); + void add_register_uint32(uint16_t address, uint8_t readonly, uint32_t* pParam, uint32_t default_value); + void add_register_bool(uint16_t address, uint8_t readonly, bool* pParam, bool default_value); +public: + uint16_t get_address() const; + void write_parameter(const void *pBuffer, uint8_t buffer_size); + void read_parameter(void *pBuffer, uint8_t buffer_size) const; +public: + void fram_write_parameter(); + void fram_read_parameter(); +public: + void write_to_fram_data(Uint16 *Dest, Uint32 Length); + void read_from_fram_data(Uint16 *BufAddr, Uint32 Length); +}; + +} /* namespace FRAM */ + +#endif /* FRAM_FRAMDATAOBJECTS_H_ */ diff --git a/FRAM/FRAMDefinitions.h b/FRAM/FRAMDefinitions.h new file mode 100644 index 0000000..2ca766a --- /dev/null +++ b/FRAM/FRAMDefinitions.h @@ -0,0 +1,19 @@ +/* + * FRAMDefinitions.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef FRAM_FRAMDEFINITIONS_H_ +#define FRAM_FRAMDEFINITIONS_H_ + + +namespace FRAM +{ +// +// +#define FRAM_FRAM_SIZE ((uint16_t)(8192)) +// +} /* namespace FRAM */ +#endif /* FRAM_FRAMDEFINITIONS_H_ */ diff --git a/FRAM/FRAMVariant.cpp b/FRAM/FRAMVariant.cpp new file mode 100644 index 0000000..c3cd948 --- /dev/null +++ b/FRAM/FRAMVariant.cpp @@ -0,0 +1,112 @@ +/* + * FRAMVariant.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "FRAM/FRAMVariant.h" + +namespace FRAM +{ +//CONSTRUCTOR +FRAMVariant::FRAMVariant(): + t(FRAM::FRAM_VARIANT_UNDEFINED), + f(0) +// +{}//CONSTRUCTOR +// + +FRAM::fram_variant_type_t FRAMVariant::get_type() const +{ + return t; + // +}// +// + +void FRAMVariant::set_float(float v) +{ + f = v; + t = FRAM::FRAM_VARIANT_FLOAT; + // +}// +// + +void FRAMVariant::set_int16(int16_t v) +{ + i16 = v; + t = FRAM::FRAM_VARIANT_INT16; + // +}// +// +void FRAMVariant::set_int32(int32_t v) +{ + i32 = v; + t = FRAM::FRAM_VARIANT_INT32; + // +}// +// +void FRAMVariant::set_uint16(uint16_t v) +{ + u16 = v; + t = FRAM::FRAM_VARIANT_UINT16; + // +}// +// +void FRAMVariant::set_uint32(uint32_t v) +{ + u32 = v; + t = FRAM::FRAM_VARIANT_UINT32; + // +}// +// + + + +void FRAMVariant::set_bool(bool v) +{ + b = v; + t = FRAM::FRAM_VARIANT_BOOL; + // +}// +// +float FRAMVariant::get_float() const +{ + return f; + // +}// +// + +int16_t FRAMVariant::get_int16() const +{ + return i16; + // +}// +// +int32_t FRAMVariant::get_int32() const +{ + return i32; + // +}// +// +uint16_t FRAMVariant::get_uint16() const +{ + return u16; + // +}// +// +uint32_t FRAMVariant::get_uint32() const +{ + return u32; + // +}// +// + + +bool FRAMVariant::get_bool() const +{ + return b; +}// +// + +}/* namespace FRAM */ diff --git a/FRAM/FRAMVariant.h b/FRAM/FRAMVariant.h new file mode 100644 index 0000000..a13bd76 --- /dev/null +++ b/FRAM/FRAMVariant.h @@ -0,0 +1,60 @@ +/* + * FRAMVariant.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include "SYSCTRL/SystemDefinitions.h" + + +#ifndef FRAM_FRAMVARIANT_H_ +#define FRAM_FRAMVARIANT_H_ + +namespace FRAM +{ + +typedef unsigned char uint8_t; + +enum fram_variant_type_t {FRAM_VARIANT_UNDEFINED, FRAM_VARIANT_FLOAT, FRAM_VARIANT_INT16, FRAM_VARIANT_INT32, FRAM_VARIANT_UINT16, FRAM_VARIANT_UINT32, FRAM_VARIANT_BOOL}; + +class FRAMVariant +{ +private: + union + { + float f; + int16_t i16; + int32_t i32; + uint16_t u16; + uint32_t u32; + bool b; + SYSCTRL::Register16 r16; + SYSCTRL::Register32 r32; + }; +private: + fram_variant_type_t t; +public: + FRAMVariant(); + fram_variant_type_t get_type() const; + //setters + void set_float(float v); + void set_int16(int16_t v); + void set_int32(int32_t v); + void set_uint16(uint16_t v); + void set_uint32(uint32_t v); + void set_bool(bool v); + //getters + float get_float() const; + int16_t get_int16() const; + int32_t get_int32() const; + uint16_t get_uint16() const; + uint32_t get_uint32() const; + bool get_bool() const; + // +};//class fram_variant_t +// +}/* namespace FRAM */ + +#endif /* FRAM_FRAMVARIANT_H_ */ diff --git a/FRAM/FRAMheaders.h b/FRAM/FRAMheaders.h new file mode 100644 index 0000000..165ad18 --- /dev/null +++ b/FRAM/FRAMheaders.h @@ -0,0 +1,18 @@ +/* + * FRAMheaders.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef FRAM_FRAMHEADERS_H_ +#define FRAM_FRAMHEADERS_H_ + +#include "FRAM/FRAMBuffer.h" +#include "FRAM/FRAMDATABASE.h" +#include "FRAM/FRAMDataObjects.h" +#include "FRAM/FRAMVariant.h" + + + +#endif /* FRAM_FRAMHEADERS_H_ */ diff --git a/FRAM/ROM.cpp b/FRAM/ROM.cpp new file mode 100644 index 0000000..19ab7bd --- /dev/null +++ b/FRAM/ROM.cpp @@ -0,0 +1,132 @@ +/* + * ROM.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "FRAM/ROM.h" + +namespace FRAM +{ +//CONSTRUCTOR +ROM::ROM(): + m_mode(FRAM::ROM::UNDEFINED), + m_header(), + m_footer(), + m_int_last_address(0), + m_flt_last_address(0), + _write_float(&FRAM::ROM::_write_float_undef), + _read_float(&FRAM::ROM::_read_float_undef), + _write_int(&FRAM::ROM::_write_int_undef), + _read_int(&FRAM::ROM::_read_int_undef) +{} +//CONSTRUCTOR +// +void ROM::setup(const ROMSetup setup) +{ + static bool _status = true; + if(m_mode == FRAM::ROM::UNDEFINED) + { + m_header = setup.header; + m_footer = setup.footer; + // + _status &= m_header.class_id != 0 ? true : false; + _status &= m_header.part_id != 0 ? true : false; + _status &= m_header.rom_size != 0 ? true : false; + _status &= m_header.software_version != 0 ? true : false; + _status &= m_footer.magic != 0 ? true : false; + // + if(_status) + { + m_mode = FRAM::ROM::OPERATIONAL; + // + _write_float = &FRAM::ROM::_write_float_undef; + _read_float = &FRAM::ROM::_read_float_undef; + _write_int = &FRAM::ROM::_write_int_undef; + _read_int = &FRAM::ROM::_read_int_undef; + // + }//if + // + }//if + // +}// +// +FRAM::ROM::mode_t ROM::get_mode() +{ + return m_mode; + // +}// +// +bool ROM::compare(FRAM::ROM::mode_t mode) +{ + return m_mode == mode; + // +}// +// +void ROM::write_float(float data, int16_t addr) +{ + (this->*_write_float)(data, addr); + + // +}// +// +float ROM::read_float(int16_t addr) +{ + return (this->*_read_float)(addr); + // +}// +// +void ROM::write_int(int16_t data, int16_t addr) +{ + (this->*_write_int)(data, addr); + // +}// +// +int16_t ROM::read_int(int16_t addr) +{ + return (this->*_read_int)(addr); + // +}// +// +void ROM::_write_float_undef(float data, int16_t addr) +{}// +// +void ROM::_write_float_operate(float data, int16_t addr) +{ + writefloat(data, addr); + // +}// +// +float ROM::_read_float_undef(int16_t addr) +{ + return (float)0.0; +}// +// +float ROM::_read_float_operate(int16_t addr) +{ + return readfloat(addr); + // +}// +// +void ROM::_write_int_undef(int16_t data, int16_t addr) +{}// +// +void ROM::_write_int_operate(int16_t data, int16_t addr) +{ + writeint(data, addr); + // +}// +// +int16_t ROM::_read_int_undef(int16_t addr) +{ + return 0; +}// +// +int16_t ROM::_read_int_operate(int16_t addr) +{ + return readint(addr); + // +}// +// +} /* namespace FRAM */ diff --git a/FRAM/ROM.h b/FRAM/ROM.h new file mode 100644 index 0000000..c58f062 --- /dev/null +++ b/FRAM/ROM.h @@ -0,0 +1,97 @@ +/* + * ROM.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "framework.h" + +#ifndef FRAM_ROM_H_ +#define FRAM_ROM_H_ + +namespace FRAM +{ + + +struct ROMHeader +{ + uint16_t class_id; + uint16_t part_id; + uint16_t software_version; + uint16_t rom_size; + ROMHeader(): + class_id(0), + part_id(0), + software_version(0), + rom_size(0) + {} +};//ROMHeader + +struct ROMFooter +{ + uint16_t magic; + ROMFooter(): + magic(0) + {} +};//ROMFooter + +struct ROMSetup +{ + ROMHeader header; + ROMFooter footer; + ROMSetup(): + header(), + footer() + {} +};//ROMSetup + +class ROM +{ +public: + enum mode_t {UNDEFINED, OPERATIONAL}; +private: + mode_t m_mode; +private: + ROMHeader m_header; + ROMFooter m_footer; + uint16_t m_int_last_address; + uint16_t m_flt_last_address; +public: + ROM(); + void setup(const ROMSetup setup); +public: + mode_t get_mode(); + bool compare(mode_t mode); +public: + void write_float(float data, int16_t addr); + float read_float(int16_t addr); + void write_int(int16_t data, int16_t addr); + int16_t read_int(int16_t addr); +private: + void (ROM::*_write_float)(float data, int16_t addr); + void _write_float_undef(float data, int16_t addr); + void _write_float_operate(float data, int16_t addr); +private: + float (ROM::*_read_float)(int16_t addr); + float _read_float_undef(int16_t addr); + float _read_float_operate(int16_t addr); +private: + void (ROM::*_write_int)(int16_t data, int16_t addr); + void _write_int_undef(int16_t data, int16_t addr); + void _write_int_operate(int16_t data, int16_t addr); +private: + int16_t (ROM::*_read_int)(int16_t addr); + int16_t _read_int_undef(int16_t addr); + int16_t _read_int_operate(int16_t addr); + + + // +};// class ROM + +} /* namespace FRAM */ + +#endif /* FRAM_ROM_H_ */ diff --git a/Framework/Framework_Lib.lib b/Framework/Framework_Lib.lib new file mode 100644 index 0000000..7e79b63 Binary files /dev/null and b/Framework/Framework_Lib.lib differ diff --git a/Framework/framework.c b/Framework/framework.c new file mode 100644 index 0000000..7efdfe2 --- /dev/null +++ b/Framework/framework.c @@ -0,0 +1,209 @@ +/***************************************************************************** + * File Name:framework.c + * Author:Zhangdi + * Brief: + * Note: + * Last Updated for Version: + * Date of the Last Update: + *****************************************************************************/ +#include"framework.h" +/***************************************************************************** + ** Constants + *****************************************************************************/ + +/***************************************************************************** + ** Maco Define + *****************************************************************************/ + +/***************************************************************************** + ** Data Type Define + *****************************************************************************/ + +/***************************************************************************** + ** Global Variable Declare + *****************************************************************************/ +BaudRate comModbusBaudRateSet; +Uint16 comModbusADDRSet; +ParityMode comModbusParitySet; + +Uint16 cpuCpldVersion; +/***************************************************************************** + * Brief: Analog input + * Note: + *****************************************************************************/ +AnalogInput analogInput = { 0 }; + +/***************************************************************************** + * Brief: Analog output + * Note: + *****************************************************************************/ +Uint16 a2001_2005 = 0; +Uint16 a2002_2006 = 0; +Uint16 a2003_2007 = 0; +Uint16 a2004_2008 = 0; + +/***************************************************************************** + * Brief: Digital input interface + * Note: + *****************************************************************************/ +DigitalInput digitalInput = { 0 }; + +/***************************************************************************** + * Brief: Digital output interface + * Note: + *****************************************************************************/ +DigitalOuput digitalOutput = { 0xffff }; + +/***************************************************************************** + * Brief: modbus output coils buffer + * Note: + *****************************************************************************/ +Uint16 readCoils[300] = { 0 }; + +/***************************************************************************** + * Brief: modbus input coils buffer + * Note: + *****************************************************************************/ +Uint16 writeCoils[300] = { 0 }; + +/***************************************************************************** + * Brief: modbus output registers buffer + * Note: + *****************************************************************************/ +Uint16 readRegisters[300] = { 0 }; + +/***************************************************************************** + * Brief: modbus input registers buffer + * Note: + *****************************************************************************/ +Uint16 writeRegisters[300] = { 0 }; + +/***************************************************************************** + * Brief: Event for modbus state machine + * Note: + *****************************************************************************/ +hsmEvent etmp; + +/***************************************************************************** + * Brief: modbus object + * Note: + *****************************************************************************/ +MODBUS_RTU_SLAVE modbusHMI; + +/***************************************************************************** + * Brief: modbus event list + * Note: + *****************************************************************************/ +hsmEvent eBufferHMI[50]; + +/***************************************************************************** + * Brief: modbus port object + * Note: + *****************************************************************************/ +MODBUS_RTU_PORT_INFOR modbusHMIPort = { 5, B9600, NO_PARITY, + &(ScibRegs.SCIRXBUF.all), &(ScibRegs.SCITXBUF), 21, &(ScibRegs) }; + +/***************************************************************************** + * Brief: Ecan data buffer. These data transport from cpu to communication + * board. + * Note: These data used for communication board modbus output coils. + *****************************************************************************/ +Uint16 canData_cpu2com_coils[16] = { 0 }; + +/***************************************************************************** + * Brief: Ecan data buffer. These data transport from cpu to communication + * board. + * Note: These data used for communication board modbus output registers. + *****************************************************************************/ + Uint16 canData_cpu2com_registers[50] = { 0 }; + +/***************************************************************************** + * Brief: Ecan data buffer. These data transport from communication board to + * cpu board. + * Note: These data are input coils data received by communication board modbus. + *****************************************************************************/ + Uint16 canData_com2cpu_coils[16] = { 0 }; + +/***************************************************************************** + * Brief: Ecan data buffer. These data transport from communication board to + * cpu board. + * Note: These data are input registers data received by communication board + * modbus. + *****************************************************************************/ + Uint16 canData_com2cpu_registers[50] = { 0 }; + +/***************************************************************************** + ** Global Function Declare + *****************************************************************************/ +void frameworkDataInit(void) +{ + Uint32 i; + int16 *p; + + p = (int16 *)&analogInput; + for(i = 0; i < sizeof(analogInput) / sizeof(int16); i++) + { + p[i] = 0; + } + + a2001_2005 = 0; + a2002_2006 = 0; + a2003_2007 = 0; + a2004_2008 = 0; + + digitalInput.all = 0xffffffff; + digitalOutput.all = 0xffffffff; + + p = (int16 *)readCoils; + for(i = 0; i < sizeof(readCoils) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + p = (int16 *)writeCoils; + for(i = 0; i < sizeof(writeCoils) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + p = (int16 *)readRegisters; + for(i = 0; i < sizeof(readRegisters) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + p = (int16 *)writeRegisters; + for(i = 0; i < sizeof(writeRegisters) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + etmp.signal = 0; + + p = (int16 *)canData_cpu2com_coils; + for(i = 0; i < sizeof(canData_cpu2com_coils) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + p = (int16 *)canData_cpu2com_registers; + for(i = 0; i < sizeof(canData_cpu2com_registers) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + p = (int16 *)canData_com2cpu_coils; + for(i = 0; i < sizeof(canData_com2cpu_coils) / sizeof(Uint16); i++) + { + p[i] = 0; + } + + p = (int16 *)canData_com2cpu_registers; + for(i = 0; i < sizeof(canData_com2cpu_registers) / sizeof(Uint16); i++) + { + p[i] = 0; + } +} +/***************************************************************************** + ** Local Function Declare + *****************************************************************************/ diff --git a/HAL/HALBase.cpp b/HAL/HALBase.cpp new file mode 100644 index 0000000..5ac4e0f --- /dev/null +++ b/HAL/HALBase.cpp @@ -0,0 +1,33 @@ +/* + * HALBase.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "HAL/HALBase.h" + +namespace HAL +{ + +//CONSTRUCTOR +HALBase::HALBase(): + m_mode(HAL::HALBase::UNDEFINED), + m_status(false) +// +{}//end CONSTRUCTOR +// +HAL::HALBase::mode_t HAL::HALBase::get_mode() const +{ + + return m_mode; + // +}//end +// +bool HAL::HALBase::compare(HAL::HALBase::mode_t mode) const +{ + return m_mode == mode; + // +}//end +// +} /* namespace HAL */ diff --git a/HAL/HALBase.h b/HAL/HALBase.h new file mode 100644 index 0000000..b6400a5 --- /dev/null +++ b/HAL/HALBase.h @@ -0,0 +1,48 @@ +/* + * HALBase.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include +// +#include "F28335/DSP28x_Project.h" + +#ifndef HAL_HALVIRTUAL_H_ +#define HAL_HALVIRTUAL_H_ + +namespace HAL +{ + +typedef void (*pGPIO_FUNCTION)(); + + +struct HALSetup +{ + pGPIO_FUNCTION gpio_setup; + HALSetup(): + gpio_setup(0) + {} +};//HALSetup + + +class HALBase +{ +public: + enum mode_t {UNDEFINED=0, OPERATIONAL=1}; +protected: + mode_t m_mode; + bool m_status; +public: + HALBase(); +public: + mode_t get_mode() const; + bool compare(mode_t mode) const; + // +};//end class HALVirtual + +} /* namespace HAL */ + +#endif /* HAL_HALVIRTUAL_H_ */ diff --git a/MODBUSRTU/RUBUS.cpp b/MODBUSRTU/RUBUS.cpp new file mode 100644 index 0000000..f3c08d6 --- /dev/null +++ b/MODBUSRTU/RUBUS.cpp @@ -0,0 +1,28 @@ +/* + * RUBUS.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "MODBUSRTU/RUBUS.h" + +namespace MODBUSRTU +{ + +//CONSTRUCTOR +RUBUS::RUBUS(uint16_t len): + mode(MODBUSRTU::RUBUS::RUBUS_RESET), + size(len), + accepted(), + response_shadow(), + response(), + mask(), + m_cell(), + cell_data(0) +// +{}//CONSTRUCTOR +// +// +// +} /* namespace MODBUSRTU */ diff --git a/MODBUSRTU/RUBUS.h b/MODBUSRTU/RUBUS.h new file mode 100644 index 0000000..af1ddab --- /dev/null +++ b/MODBUSRTU/RUBUS.h @@ -0,0 +1,103 @@ +/* + * RUBUS.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef MODBUSRTU_RUBUS_H_ +#define MODBUSRTU_RUBUS_H_ + + +#include +#include + +#include "framework.h" +#include "SYSCTRL/SystemEnvironment.h" +#include "MODBUSRTU/RUBUSRegister.h" +#include "MODBUSRTU/RUBUSTypes.h" + + +namespace MODBUSRTU +{ + + + + +struct RUBUS_ACCEPTED_DATA +{ + RUBUS_REGISTER_16 command_start; + RUBUS_REGISTER_16 command_end; + uint16_t index; + RUBUS_REGISTER_16 id; + RUBUS_REGISTER_16 com; + RUBUS_REGISTER_32 data; + RUBUS_ACCEPTED_DATA(): + command_start(0), + command_end(0), + index(0), + id(0), + com(0), + data(0) + {} +};//RUBUS_ACCEPTED_DATA + + +struct RUBUS_MASK +{ + RUBUS_REGISTER_16 error_response; + RUBUS_REGISTER_16 rubus_bool; + RUBUS_REGISTER_16 rubus_float; + RUBUS_REGISTER_16 rubus_uint8; + RUBUS_REGISTER_16 rubus_uint16; + RUBUS_REGISTER_16 rubus_uint32; + RUBUS_REGISTER_16 rubus_int8; + RUBUS_REGISTER_16 rubus_int16; + RUBUS_REGISTER_16 rubus_int32; + RUBUS_MASK(): + error_response(0x80), + rubus_bool(0x0000), + rubus_float(0x0002), + rubus_uint8(0x0004), + rubus_uint16(0x0006), + rubus_uint32(0x0008), + rubus_int8(0x000A), + rubus_int16(0x00C), + rubus_int32(0x000E) + {} +};//RUBUS_MASK + + + +struct RUBUS_RESPONSE +{ + RUBUS_REGISTER_16 command; + uint16_t index; + RUBUS_REGISTER_32 data; + RUBUS_RESPONSE(): + command(0), + index(0), + data(0) + {} +};//RUBUS_RESPONSE + + + + +struct RUBUS +{ + enum mode_rubus_t {RUBUS_RESET, RUBUS_READ, RUBUS_WRITE, RUBUS_ERROR}; + mode_rubus_t mode; + uint16_t size; + RUBUS_ACCEPTED_DATA accepted; + RUBUS_RESPONSE response_shadow; + RUBUS_RESPONSE response; + const RUBUS_MASK mask; + MODBUSRTU::RUBUSRegister m_cell; + RUBUS_REGISTER_32 cell_data; + RUBUS(uint16_t size); +}; + +} /* namespace MODBUSRTU */ + +#endif /* MODBUSRTU_RUBUS_H_ */ diff --git a/MODBUSRTU/RUBUSCOPE.cpp b/MODBUSRTU/RUBUSCOPE.cpp new file mode 100644 index 0000000..805d56e --- /dev/null +++ b/MODBUSRTU/RUBUSCOPE.cpp @@ -0,0 +1,19 @@ +/* + * RUBUSCOPE.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "MODBUSRTU/RUBUSCOPE.h" + +namespace MODBUSRTU +{ +//CONSTRUCTOR +RUBUSCOPE::RUBUSCOPE(SYSCTRL::SystemEnvironment& env): + m_env(env), + m_len(RUBUSCOPEARRAYLEN), + m_channels() +{}//CONSTRUCTOR + +} /* namespace MODBUSRTU */ diff --git a/MODBUSRTU/RUBUSCOPE.h b/MODBUSRTU/RUBUSCOPE.h new file mode 100644 index 0000000..faccb6f --- /dev/null +++ b/MODBUSRTU/RUBUSCOPE.h @@ -0,0 +1,49 @@ +/* + * RUBUSCOPE.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef MODBUSRTU_RUBUSCOPE_H_ +#define MODBUSRTU_RUBUSCOPE_H_ + +#include +#include + +#include "framework.h" +#include "SYSCTRL/SystemEnvironment.h" +#include "MODBUSRTU/RUBUSRegister.h" +#include "MODBUSRTU/RUBUSTypes.h" + + +namespace MODBUSRTU +{ + +#define RUBUSCOPEARRAYLEN 100 + +struct RUBUSCOPEVariables +{ + uint16_t command; + uint16_t response; + uint16_t channel; + uint16_t pointer; + float data; + RUBUSCOPEVariables(){} +};//RUBUSCOPEVariables + + + +class RUBUSCOPE +{ +private: + SYSCTRL::SystemEnvironment& m_env; + uint16_t m_len; + float m_channels[9][RUBUSCOPEARRAYLEN]; +public: + RUBUSCOPE(SYSCTRL::SystemEnvironment& env); +}; + +} /* namespace MODBUSRTU */ + +#endif /* MODBUSRTU_RUBUSCOPE_H_ */ diff --git a/MODBUSRTU/RUBUSDataBase.cpp b/MODBUSRTU/RUBUSDataBase.cpp new file mode 100644 index 0000000..2ca047c --- /dev/null +++ b/MODBUSRTU/RUBUSDataBase.cpp @@ -0,0 +1,565 @@ +/* + * RUBUSDataBase.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "MODBUSRTU/RUBUSDataBase.h" + +namespace MODBUSRTU +{ + +RUBUSDataBase::RUBUSDataBase(): + m_cell(), + m_current_index_cell(0), + m_index_cell(0), + m_counter_cell(0), + m_size_cell(NUMBER_RUBUSCELLS) +{}// + + +void RUBUSDataBase::add_register_bool (uint16_t index, uint16_t readonly, bool* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bool(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_float (uint16_t index, uint16_t readonly, float* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_float(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_uint8 (uint16_t index, uint16_t readonly, uint8_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_uint8(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_uint16(uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_uint16(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_uint32(uint16_t index, uint16_t readonly, uint32_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_uint32(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_int8 (uint16_t index, uint16_t readonly, int8_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_int8(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_int16 (uint16_t index, uint16_t readonly, int16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_int16(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_int32 (uint16_t index, uint16_t readonly, int32_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_int32(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// + + + +void RUBUSDataBase::add_register_bit0 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit0(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit1 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit1(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit2 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit2(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit3 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit3(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit4 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit4(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit5 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit5(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit6 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit6(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit7 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit7(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit8 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit8(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit9 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit9(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit10 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit10(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit11 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit11(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit12 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit12(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit13 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit13(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit14 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit14(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit15 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit15(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit16 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit16(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit17 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit17(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit18 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit18(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit19 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit19(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit20 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit20(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit21 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit21(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit22 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit22(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit23 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit23(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit24 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit24(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit25 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit25(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit26 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit26(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit27 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit27(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit28 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit28(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit29 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit29(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit30 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit30(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +void RUBUSDataBase::add_register_bit31 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + if(m_counter_cell < m_size_cell) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_counter_cell]; + cell.register_bit31(index, readonly, param); + m_counter_cell++; + // + }//if + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +MODBUSRTU::RUBUSRegister& RUBUSDataBase::get_register(uint16_t index) +{ + m_current_index_cell = 0; + for(m_index_cell = 0; m_index_cell < m_counter_cell; m_index_cell++) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_index_cell]; + if(cell.get_index() == index) + { + m_current_index_cell = m_index_cell; + break; + // + }//if + // + }//for + // + return m_cell[m_current_index_cell]; + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +void RUBUSDataBase::read_register(uint16_t index, RUBUS_REGISTER_32& data) +{ + m_current_index_cell = 0; + for(m_index_cell = 0; m_index_cell < m_counter_cell; m_index_cell++) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_index_cell]; + if(cell.get_index() == index) + { + m_current_index_cell = m_index_cell; + break; + // + }//if + // + }//for + // + data.all = m_cell[m_current_index_cell].read_register().all; + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +uint16_t RUBUSDataBase::write_register(uint16_t index, RUBUS_REGISTER_32 data) +{ + m_current_index_cell = 0; + for(m_index_cell = 0; m_index_cell < m_counter_cell; m_index_cell++) + { + MODBUSRTU::RUBUSRegister& cell = m_cell[m_index_cell]; + if(cell.get_index() == index) + { + m_current_index_cell = m_index_cell; + break; + // + }//if + // + }//for + // + return m_cell[m_current_index_cell].write_register(data.all); + // +}// +// + +} /* namespace MODBUSRTU */ diff --git a/MODBUSRTU/RUBUSDataBase.h b/MODBUSRTU/RUBUSDataBase.h new file mode 100644 index 0000000..75f0c01 --- /dev/null +++ b/MODBUSRTU/RUBUSDataBase.h @@ -0,0 +1,88 @@ +/* + * RUBUSDataBase.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef MODBUSRTU_RUBUSDATABASE_H_ +#define MODBUSRTU_RUBUSDATABASE_H_ + +#include +#include + +#include "framework.h" +#include "SYSCTRL/SystemEnvironment.h" + +#include "MODBUSRTU/RUBUSTypes.h" +#include "MODBUSRTU/RUBUSRegister.h" + + + +namespace MODBUSRTU +{ + +#define NUMBER_RUBUSCELLS ((uint16_t)(420)) + +class RUBUSDataBase +{ +private: + MODBUSRTU::RUBUSRegister m_cell[NUMBER_RUBUSCELLS]; + uint16_t m_current_index_cell; + uint16_t m_index_cell; + uint16_t m_counter_cell; + uint16_t m_size_cell; +public: + RUBUSDataBase(); +public: + void configurate(); +public: + void add_register_bool (uint16_t index, uint16_t readonly, bool* param); + void add_register_float (uint16_t index, uint16_t readonly, float* param); + void add_register_uint8 (uint16_t index, uint16_t readonly, uint8_t* param); + void add_register_uint16(uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_uint32(uint16_t index, uint16_t readonly, uint32_t* param); + void add_register_int8 (uint16_t index, uint16_t readonly, int8_t* param); + void add_register_int16 (uint16_t index, uint16_t readonly, int16_t* param); + void add_register_int32 (uint16_t index, uint16_t readonly, int32_t* param); + void add_register_bit0 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit1 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit2 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit3 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit4 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit5 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit6 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit7 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit8 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit9 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit10 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit11 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit12 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit13 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit14 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit15 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit16 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit17 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit18 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit19 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit20 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit21 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit22 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit23 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit24 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit25 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit26 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit27 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit28 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit29 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit30 (uint16_t index, uint16_t readonly, uint16_t* param); + void add_register_bit31 (uint16_t index, uint16_t readonly, uint16_t* param); +public: + MODBUSRTU::RUBUSRegister& get_register(uint16_t index); + void read_register(uint16_t index, RUBUS_REGISTER_32& data); + uint16_t write_register(uint16_t index, RUBUS_REGISTER_32 data); +}; + +} /* namespace MODBUSRTU */ + +#endif /* MODBUSRTU_RUBUSDATABASE_H_ */ diff --git a/MODBUSRTU/RUBUSRegister.cpp b/MODBUSRTU/RUBUSRegister.cpp new file mode 100644 index 0000000..cae2e18 --- /dev/null +++ b/MODBUSRTU/RUBUSRegister.cpp @@ -0,0 +1,862 @@ +/* + * RUBUSCell.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "MODBUSRTU/RUBUSRegister.h" + +namespace MODBUSRTU +{ +//CONSTRUCTOR +RUBUSRegister::RUBUSRegister(): + m_index(0), + m_is_read_only(true), + m_param(0), + m_type(MODBUSRTU::RUBUS_UNDEFINED) +{}//CONSTRUCTOR + +RUBUSRegister::RUBUSRegister(const RUBUSRegister& copyregister): + m_index(copyregister.m_index), + m_is_read_only(copyregister.m_is_read_only), + m_param(copyregister.m_param), + m_type(copyregister.m_type) +{} + + +void RUBUSRegister::register_bool (uint16_t index, uint16_t readonly, bool* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BOOL; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_float (uint16_t index, uint16_t readonly, float* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_FLOAT; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_uint8 (uint16_t index, uint16_t readonly, uint8_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_UINT8; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_uint16(uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_UINT16; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_uint32(uint16_t index, uint16_t readonly, uint32_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_UINT32; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_int8 (uint16_t index, uint16_t readonly, int8_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_INT8; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_int16 (uint16_t index, uint16_t readonly, int16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_INT16; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_int32 (uint16_t index, uint16_t readonly, int32_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_INT32; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit0 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT0; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit1 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT1; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit2 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT2; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit3 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT3; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit4 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT4; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit5 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT5; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit6 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT6; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit7 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT7; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit8 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT8; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit9 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT9; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit10 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT10; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit11 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT11; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit12 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT12; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit13 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT13; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit14 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT14; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit15 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT15; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit16 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT16; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit17 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT17; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit18 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT18; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit19 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT19; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit20 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT20; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit21 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT21; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit22 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT22; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit23 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT23; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit24 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT24; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit25 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT25; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit26 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT26; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit27 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT27; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit28 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT28; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit29 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT29; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit30 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT30; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// +void RUBUSRegister::register_bit31 (uint16_t index, uint16_t readonly, uint16_t* param) +{ + m_index = index; + m_param = param; + m_type = MODBUSRTU::RUBUS_BIT31; + m_is_read_only = readonly == 0 ? false : true; + // +}// +// + +uint16_t RUBUSRegister::get_index() +{ + return m_index; + // +}// +// + +bool RUBUSRegister::is_read_only() +{ + return m_is_read_only; +}// +// + +MODBUSRTU::rubus_variant_type_t RUBUSRegister::get_type() +{ + return m_type; + // +}// +// + +MODBUSRTU::RUBUS_REGISTER_32 RUBUSRegister::read_register() +{ + + MODBUSRTU::RUBUS_REGISTER_32 _temp = MODBUSRTU::RUBUS_REGISTER_32(0); + _temp.word.wL.all = 0x0000; + _temp.word.wH.all = 0x0000; + + + switch(m_type) + { + case MODBUSRTU::RUBUS_BOOL: { _temp.b = *((bool*) m_param); break;} + case MODBUSRTU::RUBUS_FLOAT: { _temp.f = *((float*) m_param); break;} + case MODBUSRTU::RUBUS_UINT8: { _temp.u8 = *((uint8_t*) m_param); break;} + case MODBUSRTU::RUBUS_UINT16: { _temp.u16 = *((uint16_t*) m_param); break;} + case MODBUSRTU::RUBUS_UINT32: { _temp.u32 = *((uint32_t*) m_param); break;} + case MODBUSRTU::RUBUS_INT8: { _temp.i8 = *((int8_t*) m_param); break;} + case MODBUSRTU::RUBUS_INT16: { _temp.i16 = *((int16_t*) m_param); break;} + case MODBUSRTU::RUBUS_INT32: { _temp.i32 = *((int32_t*) m_param); break;} + case MODBUSRTU::RUBUS_BIT0: + { + _read_bit(_temp.word.wL.all, 0x0001); + break; + } + case MODBUSRTU::RUBUS_BIT1: + { + _read_bit(_temp.word.wL.all, 0x0002); + break; + } + case MODBUSRTU::RUBUS_BIT2: + { + _read_bit(_temp.word.wL.all, 0x0004); + break; + } + case MODBUSRTU::RUBUS_BIT3: + { + _read_bit(_temp.word.wL.all, 0x0008); + break; + } + case MODBUSRTU::RUBUS_BIT4: + { + _read_bit(_temp.word.wL.all, 0x0010); + break; + } + case MODBUSRTU::RUBUS_BIT5: + { + _read_bit(_temp.word.wL.all, 0x0020); + break; + } + case MODBUSRTU::RUBUS_BIT6: + { + _read_bit(_temp.word.wL.all, 0x0040); + break; + } + case MODBUSRTU::RUBUS_BIT7: + { + _read_bit(_temp.word.wL.all, 0x0080); + break; + } + case MODBUSRTU::RUBUS_BIT8: + { + _read_bit(_temp.word.wL.all, 0x0100); + break; + } + case MODBUSRTU::RUBUS_BIT9: + { + _read_bit(_temp.word.wL.all, 0x0200); + break; + } + case MODBUSRTU::RUBUS_BIT10: + { + _read_bit(_temp.word.wL.all, 0x0400); + break; + } + case MODBUSRTU::RUBUS_BIT11: + { + _read_bit(_temp.word.wL.all, 0x0800); + break; + } + case MODBUSRTU::RUBUS_BIT12: + { + _read_bit(_temp.word.wL.all, 0x1000); + break; + } + case MODBUSRTU::RUBUS_BIT13: + { + _read_bit(_temp.word.wL.all, 0x2000); + break; + } + case MODBUSRTU::RUBUS_BIT14: + { + _read_bit(_temp.word.wL.all, 0x4000); + break; + } + case MODBUSRTU::RUBUS_BIT15: + { + _read_bit(_temp.word.wL.all, 0x8000); + break; + } + case MODBUSRTU::RUBUS_BIT16: + { + _read_bit(_temp.word.wH.all, 0x0001); + break; + } + case MODBUSRTU::RUBUS_BIT17: + { + _read_bit(_temp.word.wH.all, 0x0002); + break; + } + case MODBUSRTU::RUBUS_BIT18: + { + _read_bit(_temp.word.wH.all, 0x0004); + break; + } + case MODBUSRTU::RUBUS_BIT19: + { + _read_bit(_temp.word.wH.all, 0x0008); + break; + } + case MODBUSRTU::RUBUS_BIT20: + { + _read_bit(_temp.word.wH.all, 0x0010); + break; + } + case MODBUSRTU::RUBUS_BIT21: + { + _read_bit(_temp.word.wH.all, 0x0020); + break; + } + case MODBUSRTU::RUBUS_BIT22: + { + _read_bit(_temp.word.wH.all, 0x0040); + break; + } + case MODBUSRTU::RUBUS_BIT23: + { + _read_bit(_temp.word.wH.all, 0x0080); + break; + } + case MODBUSRTU::RUBUS_BIT24: + { + _read_bit(_temp.word.wH.all, 0x0100); + break; + } + case MODBUSRTU::RUBUS_BIT25: + { + _read_bit(_temp.word.wH.all, 0x0200); + break; + } + case MODBUSRTU::RUBUS_BIT26: + { + _read_bit(_temp.word.wH.all, 0x0400); + break; + } + case MODBUSRTU::RUBUS_BIT27: + { + _read_bit(_temp.word.wH.all, 0x0800); + break; + } + case MODBUSRTU::RUBUS_BIT28: + { + _read_bit(_temp.word.wH.all, 0x1000); + break; + } + case MODBUSRTU::RUBUS_BIT29: + { + _read_bit(_temp.word.wH.all, 0x2000); + break; + } + case MODBUSRTU::RUBUS_BIT30: + { + _read_bit(_temp.word.wH.all, 0x4000); + break; + } + case MODBUSRTU::RUBUS_BIT31: + { + _read_bit(_temp.word.wH.all, 0x8000); + break; + } + }//switch + // + return _temp.all; + // +}// +// + +uint16_t RUBUSRegister::write_register(MODBUSRTU::RUBUS_REGISTER_32 data) +{ + + MODBUSRTU::RUBUS_REGISTER_32 _temp = MODBUSRTU::RUBUS_REGISTER_32(0); + _temp.word.wL.all = 0x0000; + _temp.word.wH.all = 0x0000; + + if(m_is_read_only) + { + // register is read only + // write operation is not allowed + return 0x0040; + } + else + { + // writeable register + switch(m_type) + { + case MODBUSRTU::RUBUS_BOOL: { *((bool*) m_param) = data.b; break;} + case MODBUSRTU::RUBUS_FLOAT: { *((float*) m_param) = data.f; break;} + case MODBUSRTU::RUBUS_UINT8: { *((uint8_t*) m_param) = data.u8; break;} + case MODBUSRTU::RUBUS_UINT16: { *((uint16_t*) m_param) = data.u16; break;} + case MODBUSRTU::RUBUS_UINT32: { *((uint32_t*) m_param) = data.u32; break;} + case MODBUSRTU::RUBUS_INT8: { *((int8_t*) m_param) = data.i8; break;} + case MODBUSRTU::RUBUS_INT16: { *((int16_t*) m_param) = data.i16; break;} + case MODBUSRTU::RUBUS_INT32: { *((int32_t*) m_param) = data.i32; break;} + case MODBUSRTU::RUBUS_BIT0: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b00 = data.bit16.b00; + *((uint16_t*) m_param) = data.u16; + break; + } + case MODBUSRTU::RUBUS_BIT1: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b01 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT2: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b02 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT3: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b03 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT4: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b04 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT5: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b05 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT6: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b06 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT7: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b07 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT8: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b08 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT9: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b09 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT10: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b10 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT11: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b11 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT12: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b12 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT13: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b13 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT14: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b14 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT15: + { + _temp.u16 = *((uint16_t*) m_param); + _temp.bit16.b15 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.u16; + break; + } + case MODBUSRTU::RUBUS_BIT16: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b16 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT17: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b17 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT18: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b18 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT19: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b19 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT20: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b20 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT21: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b21 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT22: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b22 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT23: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b23 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT24: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b24 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT25: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b25 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT26: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b26 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT27: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b27 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT28: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b28 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT29: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b29 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT30: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b30 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + case MODBUSRTU::RUBUS_BIT31: + { + _temp.word.wH.all = *((uint16_t*) m_param); + _temp.bit32.b31 = data.bit16.b00; + *((uint16_t*) m_param) = _temp.word.wH.all; + break; + } + }//switch + // + return 0; + // + }//if else + // +}// +// + +inline void RUBUSRegister::_read_bit(uint16_t& auxreg, uint16_t mask) +{ + auxreg = *((uint16_t*) m_param); + auxreg &= mask; + auxreg = auxreg == 0 ? 0 : 1; + // +}// +// +// +} /* namespace MODBUSRTU */ diff --git a/MODBUSRTU/RUBUSRegister.h b/MODBUSRTU/RUBUSRegister.h new file mode 100644 index 0000000..416a1d0 --- /dev/null +++ b/MODBUSRTU/RUBUSRegister.h @@ -0,0 +1,89 @@ +/* + * RUBUSCell.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef MODBUSRTU_RUBUSREGISTER_H_ +#define MODBUSRTU_RUBUSREGISTER_H_ + +#include +#include + +#include "framework.h" + +#include "SYSCTRL/SystemEnvironment.h" +#include "MODBUSRTU/RUBUSTypes.h" + + +namespace MODBUSRTU +{ + +class RUBUSRegister +{ +private: + uint16_t m_index; + bool m_is_read_only; + void* m_param; + rubus_variant_type_t m_type; +public: + RUBUSRegister(); + RUBUSRegister(const RUBUSRegister& cell); +public: + void register_bool (uint16_t index, uint16_t readonly, bool* param); + void register_float (uint16_t index, uint16_t readonly, float* param); + void register_uint8 (uint16_t index, uint16_t readonly, uint8_t* param); + void register_uint16(uint16_t index, uint16_t readonly, uint16_t* param); + void register_uint32(uint16_t index, uint16_t readonly, uint32_t* param); + void register_int8 (uint16_t index, uint16_t readonly, int8_t* param); + void register_int16 (uint16_t index, uint16_t readonly, int16_t* param); + void register_int32 (uint16_t index, uint16_t readonly, int32_t* param); + void register_bit0 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit1 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit2 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit3 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit4 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit5 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit6 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit7 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit8 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit9 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit10 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit11 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit12 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit13 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit14 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit15 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit16 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit17 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit18 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit19 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit20 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit21 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit22 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit23 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit24 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit25 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit26 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit27 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit28 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit29 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit30 (uint16_t index, uint16_t readonly, uint16_t* param); + void register_bit31 (uint16_t index, uint16_t readonly, uint16_t* param); +public: + uint16_t get_index(); + bool is_read_only(); + MODBUSRTU::rubus_variant_type_t get_type(); +public: + MODBUSRTU::RUBUS_REGISTER_32 read_register(); + uint16_t write_register(MODBUSRTU::RUBUS_REGISTER_32 data); +private: + inline void _read_bit(uint16_t& auxreg, uint16_t mask); +// +};// + +} /* namespace MODBUSRTU */ + +#endif /* MODBUSRTU_RUBUSREGISTER_H_ */ + diff --git a/MODBUSRTU/RUBUSTypes.h b/MODBUSRTU/RUBUSTypes.h new file mode 100644 index 0000000..3bf264d --- /dev/null +++ b/MODBUSRTU/RUBUSTypes.h @@ -0,0 +1,197 @@ +/* + * RUBUSTypes.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef MODBUSRTU_RUBUSTYPES_H_ +#define MODBUSRTU_RUBUSTYPES_H_ + +#include +#include + +#include "framework.h" + + +namespace MODBUSRTU +{ + +typedef unsigned char uint8_t; +typedef signed char int8_t; + + +enum rubus_variant_type_t { RUBUS_UNDEFINED, + RUBUS_BOOL, + RUBUS_FLOAT, + RUBUS_UINT8, + RUBUS_UINT16, + RUBUS_UINT32, + RUBUS_INT8, + RUBUS_INT16, + RUBUS_INT32, + RUBUS_BIT0, + RUBUS_BIT1, + RUBUS_BIT2, + RUBUS_BIT3, + RUBUS_BIT4, + RUBUS_BIT5, + RUBUS_BIT6, + RUBUS_BIT7, + RUBUS_BIT8, + RUBUS_BIT9, + RUBUS_BIT10, + RUBUS_BIT11, + RUBUS_BIT12, + RUBUS_BIT13, + RUBUS_BIT14, + RUBUS_BIT15, + RUBUS_BIT16, + RUBUS_BIT17, + RUBUS_BIT18, + RUBUS_BIT19, + RUBUS_BIT20, + RUBUS_BIT21, + RUBUS_BIT22, + RUBUS_BIT23, + RUBUS_BIT24, + RUBUS_BIT25, + RUBUS_BIT26, + RUBUS_BIT27, + RUBUS_BIT28, + RUBUS_BIT29, + RUBUS_BIT30, + RUBUS_BIT31}; + + +struct RUBUS_REGISTER_16_BIT_FIELD +{ + uint16_t b00: 1; + uint16_t b01: 1; + uint16_t b02: 1; + uint16_t b03: 1; + uint16_t b04: 1; + uint16_t b05: 1; + uint16_t b06: 1; + uint16_t b07: 1; + uint16_t b08: 1; + uint16_t b09: 1; + uint16_t b10: 1; + uint16_t b11: 1; + uint16_t b12: 1; + uint16_t b13: 1; + uint16_t b14: 1; + uint16_t b15: 1; +};//RUBUS_REGISTER_16_BIT_FIELD + +struct RUBUS_REGISTER_32_BIT_FIELD +{ + uint32_t b00: 1; + uint32_t b01: 1; + uint32_t b02: 1; + uint32_t b03: 1; + uint32_t b04: 1; + uint32_t b05: 1; + uint32_t b06: 1; + uint32_t b07: 1; + uint32_t b08: 1; + uint32_t b09: 1; + uint32_t b10: 1; + uint32_t b11: 1; + uint32_t b12: 1; + uint32_t b13: 1; + uint32_t b14: 1; + uint32_t b15: 1; + uint32_t b16: 1; + uint32_t b17: 1; + uint32_t b18: 1; + uint32_t b19: 1; + uint32_t b20: 1; + uint32_t b21: 1; + uint32_t b22: 1; + uint32_t b23: 1; + uint32_t b24: 1; + uint32_t b25: 1; + uint32_t b26: 1; + uint32_t b27: 1; + uint32_t b28: 1; + uint32_t b29: 1; + uint32_t b30: 1; + uint32_t b31: 1; +};//RUBUS_REGISTER_32_BIT_FIELD + + +struct RUBUS_REGISTER_16_BYTE_FIELD +{ + uint16_t bt0 :8; + uint16_t bt1 :8; +};//RUBUS_REGISTER_16_BYTE_FIELD + +union RUBUS_REGISTER_16 +{ + uint16_t all; + RUBUS_REGISTER_16_BIT_FIELD bit; + RUBUS_REGISTER_16_BYTE_FIELD byte; + RUBUS_REGISTER_16(uint16_t val): + all(val) + {} +};//RUBUS_REGISTER_16 + + +struct RUBUS_REGISTER_32_BYTE_FIELD +{ + uint16_t bt0 :8; + uint16_t bt1 :8; + uint16_t bt2 :8; + uint16_t bt3 :8; +};//RUBUS_REGISTER_32_BYTE_FIELD + + +union RUBUS_REGISTER_16_WORD +{ + uint16_t all; + RUBUS_REGISTER_16_BIT_FIELD bit; + RUBUS_REGISTER_16_BYTE_FIELD byte; +};//RUBUS_REGISTER_16_WORD + + + + +struct RUBUS_REGISTER_32_WORD_FIELD +{ + RUBUS_REGISTER_16_WORD wL; + RUBUS_REGISTER_16_WORD wH; +};//RUBUS_REGISTER_32_WORD_FIELD + +union RUBUS_REGISTER_32 +{ + uint32_t all; + bool b; + float f; + uint8_t u8; + uint16_t u16; + uint32_t u32; + int8_t i8; + int16_t i16; + int32_t i32; + RUBUS_REGISTER_16_BIT_FIELD bit16; + RUBUS_REGISTER_32_BIT_FIELD bit32; + RUBUS_REGISTER_32_WORD_FIELD word; + RUBUS_REGISTER_32_BYTE_FIELD byte; + RUBUS_REGISTER_32(): + all((uint32_t)0) + {}; + RUBUS_REGISTER_32(uint32_t val): + all(val) + {} +};//RUBUS_REGISTER_32 + + + + + + + +} /* namespace MODBUSRTU */ + +#endif /* MODBUSRTU_RUBUSTYPES_H_ */ diff --git a/SYSCTRL/ALERTHeaders.h b/SYSCTRL/ALERTHeaders.h new file mode 100644 index 0000000..7ff6f34 --- /dev/null +++ b/SYSCTRL/ALERTHeaders.h @@ -0,0 +1,18 @@ +/* + * ALERTHeaders.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef ALERT_ALERTHEADERS_H_ +#define ALERT_ALERTHEADERS_H_ + +#include "Alert/AlertBase.h" +#include "Alert/FaultDecrease.h" +#include "Alert/FaultExceed.h" +#include "Alert/WarningDecrease.h" +#include "Alert/WarningExceed.h" + + +#endif /* ALERT_ALERTHEADERS_H_ */ diff --git a/SYSCTRL/AlgorithmBase.cpp b/SYSCTRL/AlgorithmBase.cpp new file mode 100644 index 0000000..f8deaa6 --- /dev/null +++ b/SYSCTRL/AlgorithmBase.cpp @@ -0,0 +1,32 @@ +/* + * AlgorithmBase.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmBase.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmBase::AlgorithmBase(): + m_voltage_a(FP_ZERO), + m_voltage_b(FP_ZERO), + m_voltage_c(FP_ZERO) +// +{}//CONSTRUCTOR +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmBase::get_ref_invertor_voltage(float& volt_a, float& volt_b, float& volt_c) +{ + volt_a = m_voltage_a; + volt_b = m_voltage_b; + volt_c = m_voltage_c; + // +}//end +// +void AlgorithmBase::_execute_undef(){} +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmBase.h b/SYSCTRL/AlgorithmBase.h new file mode 100644 index 0000000..5855dd6 --- /dev/null +++ b/SYSCTRL/AlgorithmBase.h @@ -0,0 +1,43 @@ +/* + * AlgorithmBase.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/SystemEnvironment.h" + +#ifndef SYSCTRL_ALGORITHMBASE_H_ +#define SYSCTRL_ALGORITHMBASE_H_ + +namespace SYSCTRL +{ + +class AlgorithmBase +{ +protected: + float m_voltage_a; + float m_voltage_b; + float m_voltage_c; +public: + AlgorithmBase(); +public: + virtual void setup() = 0; +public: + virtual void reset() = 0; +public: + void get_ref_invertor_voltage(float& volt_a, float& volt_b, float& volt_c); +public: + virtual void execute() = 0; +protected: + void _execute_undef(); + virtual void _execute_run() = 0; + // +};//AlgorithmBase + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMBASE_H_ */ diff --git a/SYSCTRL/AlgorithmContext.cpp b/SYSCTRL/AlgorithmContext.cpp new file mode 100644 index 0000000..476b173 --- /dev/null +++ b/SYSCTRL/AlgorithmContext.cpp @@ -0,0 +1,701 @@ +/* + * AlgorithmContext.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmContext.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmContext::AlgorithmContext(SYSCTRL::SystemEnvironment& env): + m_mode(SYSCTRL::AlgorithmContext::UNDEFINED), + m_algorithm(SYSCTRL::AlgorithmContext::UNKNOWN), + m_algorithm_previous(SYSCTRL::AlgorithmContext::UNKNOWN), + m_env(env), + m_algorithm_pointer(&m_off), + m_fault(env), + m_work(env), + m_stop(env), + m_start(env), + m_off(env), + m_source(env), + _strategy(&SYSCTRL::AlgorithmContext::_strategy_undef), + _set_fault(&SYSCTRL::AlgorithmContext::_set_empty_exe), + _set_work(&SYSCTRL::AlgorithmContext::_set_empty_exe), + _set_stop(&SYSCTRL::AlgorithmContext::_set_empty_exe), + _set_start(&SYSCTRL::AlgorithmContext::_set_empty_exe), + _set_off(&SYSCTRL::AlgorithmContext::_set_empty_exe), + _set_source(&SYSCTRL::AlgorithmContext::_set_empty_exe) +// +{}//CONSTRUCTOR + + +void AlgorithmContext::setup() +{ + static bool status = true; + if(m_mode == SYSCTRL::AlgorithmContext::UNDEFINED) + { + + m_algorithm = SYSCTRL::AlgorithmContext::UNKNOWN; + m_algorithm_previous = SYSCTRL::AlgorithmContext::UNKNOWN; + + m_fault.setup(); + m_work.setup(); + m_stop.setup(); + m_start.setup(); + m_off.setup(); + m_source.setup(); + + _strategy = &SYSCTRL::AlgorithmContext::_strategy_undef; + _set_fault = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_empty_exe; + + if(status) + { + m_mode = SYSCTRL::AlgorithmContext::CONFIGURATE; + // + }//if + // + }//if + // +}// +// +void AlgorithmContext::configure() +{ + static bool status = true; + if(m_mode == SYSCTRL::AlgorithmContext::CONFIGURATE) + { + + _strategy = &SYSCTRL::AlgorithmContext::_strategy_off; + _set_fault = &SYSCTRL::AlgorithmContext::_set_fault_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_work_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_stop_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_start_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_off_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_source_exe; + + if(status) + { + m_algorithm = SYSCTRL::AlgorithmContext::OFF; + m_algorithm_previous = SYSCTRL::AlgorithmContext::OFF; + + m_mode = SYSCTRL::AlgorithmContext::OPERATIONAL; + set_strategy_off(); + set_off(); + // + }//if + // + }//if + // +}// +// +SYSCTRL::AlgorithmContext::mode_t AlgorithmContext::get_mode() +{ + return m_mode; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +SYSCTRL::AlgorithmContext::algorithm_t AlgorithmContext::get_algorithm() +{ + return m_algorithm; +}// +// +bool AlgorithmContext::compare(const SYSCTRL::AlgorithmContext::mode_t mode) +{ + return mode == m_mode; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool AlgorithmContext::compare_algorithm(const SYSCTRL::AlgorithmContext::algorithm_t algorithm) +{ + return algorithm == m_algorithm; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::get_ref_invertor_voltage(float& volt_a, float& volt_b, float& volt_c) +{ + m_algorithm_pointer->get_ref_invertor_voltage(volt_a, volt_b, volt_c); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::strategy() +{ + (this->*_strategy)(); + // +}// +// +void AlgorithmContext::_strategy_undef() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_strategy_fault() +{ + if((!m_env.system_fault.boolbit.b0)&&(m_env.system_reset.boolbit.b0)) + { + set_strategy_off(); + set_off(); + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_strategy_work() +{ + if(m_env.system_fault.boolbit.b0) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_fault(); + set_fault(); + } + else + { + // + if(!m_env.enable_work.boolbit.b0) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_off(); + set_off(); + // + }else{ + + if((m_env.local_remote.state.signal.is_off & m_env.remote_stop.state.signal.is_switched_on) | + ((m_env.local_remote.state.signal.is_on & m_env.external_stop.signal.is_on))) + { + //m_env.reference_intensity_voltage_load_direct.set_output(m_env.voltage_load_active); + //m_env.reference_intensity_voltage_load_quadrature.set_output(m_env.voltage_load_reactive); + + set_strategy_stop(); + set_stop(); + // + }//if + } + // + }//if else + // +}// +// + +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_strategy_stop() +{ + if(m_env.system_fault.boolbit.b0) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_fault(); + set_fault(); + } + else + { + if(!m_env.enable_work.boolbit.b0 | + //(m_env.local_remote.state.signal.is_off & m_env.remote_stop.state.signal.is_switched_on) | + //(m_env.local_remote.state.signal.is_on & m_env.external_stop.signal.is_on) + m_env.auxiliary_km2.state.signal.is_on + ) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_off(); + set_off(); + // + } + // + }//if else + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_strategy_start() +{ + if(m_env.system_fault.boolbit.b0) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_fault(); + set_fault(); + } + else + { + if(!m_env.enable_work.boolbit.b0) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_off(); + set_off(); + // + } + else + { + + if((m_env.local_remote.state.signal.is_off & m_env.remote_stop.state.signal.is_switched_on) | + ((m_env.local_remote.state.signal.is_on & m_env.external_stop.signal.is_on)) + ) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_off(); + set_off(); + // + }//if + + + + if(m_env.auxiliary_km2.state.signal.is_off) + { + //m_env.regulator_voltage_load_a.set_output(m_env.reference.start.voltage_a); + //m_env.regulator_voltage_load_b.set_output(m_env.reference.start.voltage_b); + //m_env.regulator_voltage_load_c.set_output(m_env.reference.start.voltage_c); + // + //m_env.current_regulator_active.reset(); + //m_env.current_regulator_reactive.reset(); + // + set_strategy_work(); + set_work(); + // + //set_strategy_stop(); + //set_stop(); + // + }//if + + // + }//if else + // + }//if else + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_strategy_off() +{ + if(m_env.system_fault.boolbit.b0) + { + set_strategy_fault(); + set_fault(); + } + else + { + if(m_env.enable_work_is_on.boolbit.b0) + { + set_strategy_start(); + set_start(); + // + //set_strategy_source(); + //set_source(); + // + //set_strategy_stop(); + //set_stop(); + // + }//if + // + }//if else + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_strategy_source() +{ + if(m_env.system_fault.boolbit.b0) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_fault(); + set_fault(); + } + else + { + // + if((!m_env.enable_work.boolbit.b0) | + (m_env.local_remote.state.signal.is_off & m_env.remote_stop.state.signal.is_switched_on) | + ((m_env.local_remote.state.signal.is_on & m_env.external_stop.signal.is_on)) + ) + { + m_env.enable_work_reset.boolbit.b0 = true; + set_strategy_off(); + set_off(); + // + }//if + // + }//if else + // + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_strategy_fault() +{ + _strategy = &SYSCTRL::AlgorithmContext::_strategy_fault; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_strategy_work() +{ + _strategy = &SYSCTRL::AlgorithmContext::_strategy_work; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_strategy_stop() +{ + _strategy = &SYSCTRL::AlgorithmContext::_strategy_stop; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_strategy_start() +{ + _strategy = &SYSCTRL::AlgorithmContext::_strategy_start; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_strategy_off() +{ + _strategy = &SYSCTRL::AlgorithmContext::_strategy_off; +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_strategy_source() +{ + _strategy = &SYSCTRL::AlgorithmContext::_strategy_source; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_fault() +{ + (this->*_set_fault)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_work() +{ + (this->*_set_work)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_stop() +{ + (this->*_set_stop)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_start() +{ + (this->*_set_start)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_off() +{ + (this->*_set_off)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::set_source() +{ + (this->*_set_source)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::execute() +{ + m_algorithm_pointer->execute(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_set_fault_exe() +{ + // + m_algorithm_previous = m_algorithm; + m_algorithm = SYSCTRL::AlgorithmContext::FAULT; + // + _set_fault = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_work_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_stop_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_start_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_off_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_source_exe; + // + m_env.timer_start.reset(); + m_env.timer_stop.reset(); + // + m_algorithm_pointer = &m_fault; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_set_work_exe() +{ + // + m_algorithm_previous = m_algorithm; + m_algorithm = SYSCTRL::AlgorithmContext::WORK; + // + _set_fault = &SYSCTRL::AlgorithmContext::_set_fault_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_stop_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_start_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_off_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_source_exe; + // + // +#if TYPECONTROL == VECTORCONTROL + // + m_env.regulator_voltage_load_direct.reset(); + m_env.regulator_voltage_load_quadrature.reset(); + // + m_env.integrator_direct.reset(); + m_env.integrator_quadrature.reset(); + // + m_env.regulator_current_limit.set_to_low_saturation(); + m_env.regulator_current_pfc.reset(); + // +#endif + +#if TYPECONTROL == SCALARCONTROL + // + m_env.regulator_dc_a.reset(); + m_env.regulator_dc_b.reset(); + m_env.regulator_dc_c.reset(); + // + m_env.regulator_current_limit_a.set_to_high_saturation(); + m_env.regulator_current_pfc_a.reset(); + + m_env.regulator_current_limit_b.set_to_high_saturation(); + m_env.regulator_current_pfc_b.reset(); + + m_env.regulator_current_limit_c.set_to_high_saturation(); + m_env.regulator_current_pfc_c.reset(); + + m_env.regulator_voltage_load_a_active.reset(); + m_env.regulator_voltage_load_a_reactive.reset(); + + m_env.regulator_voltage_load_b_active.reset(); + m_env.regulator_voltage_load_b_reactive.reset(); + + m_env.regulator_voltage_load_c_active.reset(); + m_env.regulator_voltage_load_c_reactive.reset(); + // +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + + m_env.drc_positive_voltage_controller_direct.reset(); + m_env.drc_positive_voltage_controller_quadrature.reset(); + m_env.drc_negative_voltage_controller_direct.reset(); + m_env.drc_negative_voltage_controller_quadrature.reset(); + // + m_env.drc_regulator_current_limit.set_to_low_saturation(); + m_env.drc_regulator_current_pfc.reset(); + + m_env.drc_reference_voltage_direct_intensity.set_output(m_env.drc_voltage_grid_direct); + m_work.reset_switcher(); + // +#endif + + // + m_env.timer_start.reset(); + m_env.timer_stop.reset(); + // + m_algorithm_pointer = &m_work; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_set_stop_exe() +{ + // + m_algorithm_previous = m_algorithm; + m_algorithm = SYSCTRL::AlgorithmContext::STOP; + // + _set_fault = &SYSCTRL::AlgorithmContext::_set_fault_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_work_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_start_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_off_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_source_exe; + // +#if TYPECONTROL == VECTORCONTROL + m_env.reference_voltage_direct_intensity.set_output(m_env.regulator_current_limit.get_output()); +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + //m_env.drc_reference_voltage_direct_intensity.set_output(m_env.drc_voltage_grid_direct); + m_env.drc_reference_voltage_direct_intensity.set_output(m_env.drc_regulator_current_limit.get_output()); +#endif + + // + // + /* FOR DEBUG ONLY!!!! */ + /* + m_env.regulator_voltage_load_a_active.reset(); + m_env.regulator_voltage_load_a_reactive.reset(); + + m_env.regulator_voltage_load_b_active.reset(); + m_env.regulator_voltage_load_b_reactive.reset(); + + m_env.regulator_voltage_load_c_active.reset(); + m_env.regulator_voltage_load_c_reactive.reset(); + */ + + /* FOR DEBUG ONLY!!!! */ + /* VECTOR CONTROL */ + /* + m_env.regulator_voltage_load_direct.reset(); + m_env.regulator_voltage_load_quadrature.reset(); + // + m_env.integrator_direct.reset(); + m_env.integrator_quadrature.reset(); + */ + // + m_env.timer_start.reset(); + m_env.timer_stop.start(); + // + m_algorithm_pointer = &m_stop; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_set_start_exe() +{ + // + m_algorithm_previous = m_algorithm; + m_algorithm = SYSCTRL::AlgorithmContext::START; + // + _set_fault = &SYSCTRL::AlgorithmContext::_set_fault_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_work_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_stop_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_off_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_source_exe; + // +#if TYPECONTROL == VECTORCONTROL + // + m_env.regulator_current_load_direct.reset(); + m_env.regulator_current_load_quadrature.reset(); + // + m_env.referencer_current_bypass_direct.reset(); + m_env.referencer_current_bypass_quadrature.reset(); + // +#endif + // +#if TYPECONTROL == SCALARCONTROL + // + m_env.current_referencer_a_active.reset(); + m_env.current_referencer_a_reactive.reset(); + m_env.current_referencer_b_active.reset(); + m_env.current_referencer_b_reactive.reset(); + m_env.current_referencer_c_active.reset(); + m_env.current_referencer_c_reactive.reset(); + // + m_env.current_regulator_a_active.reset(); + m_env.current_regulator_a_reactive.reset(); + m_env.current_regulator_b_active.reset(); + m_env.current_regulator_b_reactive.reset(); + m_env.current_regulator_c_active.reset(); + m_env.current_regulator_c_reactive.reset(); + // +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + m_env.drc_regulator_current_load_direct.reset(); + m_env.drc_regulator_current_load_quadrature.reset(); + // + m_env.drc_referencer_current_bypass_direct.reset(); + m_env.drc_referencer_current_bypass_quadrature.reset(); + // + m_env.drc_positive_voltage_cell_direct = FP_ZERO; + m_env.drc_positive_voltage_cell_quadrature = FP_ZERO; + m_env.drc_negative_voltage_cell_direct = FP_ZERO; + m_env.drc_negative_voltage_cell_quadrature = FP_ZERO; + // + m_env.drc_positive_voltage_cell_alpha = FP_ZERO; + m_env.drc_positive_voltage_cell_beta = FP_ZERO; + m_env.drc_negative_voltage_cell_alpha = FP_ZERO; + m_env.drc_negative_voltage_cell_beta = FP_ZERO; + // + m_env.drc_positive_voltage_cell_a = FP_ZERO; + m_env.drc_positive_voltage_cell_b = FP_ZERO; + m_env.drc_positive_voltage_cell_c = FP_ZERO; + // + m_env.drc_negative_voltage_cell_a = FP_ZERO; + m_env.drc_negative_voltage_cell_b = FP_ZERO; + m_env.drc_negative_voltage_cell_c = FP_ZERO; + // +#endif + + + // + m_env.timer_start.start(); + m_env.timer_stop.reset(); + // + m_algorithm_pointer = &m_start; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_set_off_exe() +{ + // + m_algorithm_previous = m_algorithm; + m_algorithm = SYSCTRL::AlgorithmContext::OFF; + // + _set_fault = &SYSCTRL::AlgorithmContext::_set_fault_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_work_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_stop_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_start_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_empty_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_source_exe; + // + m_env.timer_start.reset(); + m_env.timer_stop.reset(); + // + m_algorithm_pointer = &m_off; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmContext::_set_source_exe() +{ + // + m_algorithm_previous = m_algorithm; + m_algorithm = SYSCTRL::AlgorithmContext::SOURCE; + // + _set_fault = &SYSCTRL::AlgorithmContext::_set_fault_exe; + _set_work = &SYSCTRL::AlgorithmContext::_set_work_exe; + _set_stop = &SYSCTRL::AlgorithmContext::_set_stop_exe; + _set_start = &SYSCTRL::AlgorithmContext::_set_start_exe; + _set_off = &SYSCTRL::AlgorithmContext::_set_off_exe; + _set_source = &SYSCTRL::AlgorithmContext::_set_empty_exe; + // + m_env.timer_start.reset(); + m_env.timer_stop.reset(); + // + m_algorithm_pointer = &m_source; + // +}// +// +void AlgorithmContext::_set_empty_exe() +{ + // +}// +// +// +} /* namespace SYSCTRL */ + diff --git a/SYSCTRL/AlgorithmContext.h b/SYSCTRL/AlgorithmContext.h new file mode 100644 index 0000000..7d90bc5 --- /dev/null +++ b/SYSCTRL/AlgorithmContext.h @@ -0,0 +1,114 @@ +/* + * AlgorithmContext.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/AlgorithmFault.h" +#include "SYSCTRL/AlgorithmOff.h" +#include "SYSCTRL/AlgorithmSource.h" +#include "SYSCTRL/AlgorithmStart.h" +#include "SYSCTRL/AlgorithmStop.h" +#include "SYSCTRL/AlgorithmWork.h" +#include "SYSCTRL/AlgorithmZero.h" +#include "SYSCTRL/SystemEnvironment.h" + + +#ifndef SYSCTRL_ALGORITHMCONTEXT_H_ +#define SYSCTRL_ALGORITHMCONTEXT_H_ + +namespace SYSCTRL +{ + +class AlgorithmContext +{ +private: + friend class SYSCTRL::AlgorithmBase; + friend class SYSCTRL::AlgorithmFault; + friend class SYSCTRL::AlgorithmWork; + friend class SYSCTRL::AlgorithmStop; + friend class SYSCTRL::AlgorithmStart; + friend class SYSCTRL::AlgorithmOff; + friend class SYSCTRL::AlgorithmSource; +public: + enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; + enum algorithm_t {UNKNOWN, OFF, START, ENTRY, WORK, STOP, FAULT, SOURCE}; +private: + mode_t m_mode; + algorithm_t m_algorithm; + algorithm_t m_algorithm_previous; +private: + SYSCTRL::SystemEnvironment& m_env; +private: + SYSCTRL::AlgorithmBase* m_algorithm_pointer; + SYSCTRL::AlgorithmFault m_fault; + SYSCTRL::AlgorithmWork m_work; + SYSCTRL::AlgorithmStop m_stop; + SYSCTRL::AlgorithmStart m_start; + SYSCTRL::AlgorithmOff m_off; + SYSCTRL::AlgorithmSource m_source; +public: + AlgorithmContext(SYSCTRL::SystemEnvironment& env); + void setup(); + void configure(); +public: + mode_t get_mode(); + algorithm_t get_algorithm(); + bool compare(const mode_t mode); + bool compare_algorithm(const algorithm_t algorithm); +public: + void get_ref_invertor_voltage(float& volt_a, float& volt_b, float& volt_c); +public: + void strategy(); +private: + void (AlgorithmContext::*_strategy)(); + void _strategy_undef(); + void _strategy_fault(); + void _strategy_work(); + void _strategy_stop(); + void _strategy_start(); + void _strategy_off(); + void _strategy_source(); +public: + void set_strategy_fault(); + void set_strategy_work(); + void set_strategy_stop(); + void set_strategy_start(); + void set_strategy_off(); + void set_strategy_source(); +public: + void execute(); +public: + void set_fault(); + void set_work(); + void set_stop(); + void set_start(); + void set_off(); + void set_source(); +private: + void (AlgorithmContext::*_set_fault)(); + void (AlgorithmContext::*_set_work)(); + void (AlgorithmContext::*_set_stop)(); + void (AlgorithmContext::*_set_start)(); + void (AlgorithmContext::*_set_off)(); + void (AlgorithmContext::*_set_source)(); + void _set_fault_exe(); + void _set_work_exe(); + void _set_stop_exe(); + void _set_start_exe(); + void _set_off_exe(); + void _set_source_exe(); + void _set_empty_exe(); + // +};//class AlgorithmContext + + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMCONTEXT_H_ */ diff --git a/SYSCTRL/AlgorithmFault.cpp b/SYSCTRL/AlgorithmFault.cpp new file mode 100644 index 0000000..2853219 --- /dev/null +++ b/SYSCTRL/AlgorithmFault.cpp @@ -0,0 +1,49 @@ +/* + * AlgorithmFault.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmFault.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmFault::AlgorithmFault(SYSCTRL::SystemEnvironment& env): + SYSCTRL::AlgorithmBase(), + m_env(env), + _execute(&SYSCTRL::AlgorithmFault::_execute_undef) +// +{}//CONSTRUCTOR +// +void AlgorithmFault::setup() +{ + _execute = &SYSCTRL::AlgorithmFault::_execute_run; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmFault::reset() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmFault::execute() +{ + (this->*_execute)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmFault::_execute_run() +{ + // + m_env.hardware.ref_control_order = ORDER_START; + // + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmFault.h b/SYSCTRL/AlgorithmFault.h new file mode 100644 index 0000000..d78136e --- /dev/null +++ b/SYSCTRL/AlgorithmFault.h @@ -0,0 +1,40 @@ +/* + * AlgorithmFault.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_ALGORITHMFAULT_H_ +#define SYSCTRL_ALGORITHMFAULT_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + +namespace SYSCTRL +{ + + +class AlgorithmFault: public AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +public: + AlgorithmFault(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmFault::*_execute)(); + void _execute_run(); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMFAULT_H_ */ diff --git a/SYSCTRL/AlgorithmOff.cpp b/SYSCTRL/AlgorithmOff.cpp new file mode 100644 index 0000000..a252b9e --- /dev/null +++ b/SYSCTRL/AlgorithmOff.cpp @@ -0,0 +1,78 @@ +/* + * AlgoritmOff.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmOff.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmOff::AlgorithmOff(SYSCTRL::SystemEnvironment& env): + SYSCTRL::AlgorithmBase(), + m_env(env), + _execute(&SYSCTRL::AlgorithmOff::_execute_undef) +// +{}//CONSTRUCTOR +// +void AlgorithmOff::setup() +{ + _execute = &SYSCTRL::AlgorithmOff::_execute_run; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmOff::reset() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmOff::execute() +{ + (this->*_execute)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmOff::_execute_run() +{ + static bool _high_level = true; + _high_level = true; + + if(m_env.system_reset.boolbit.b0) + { + m_env.hardware.ref_control_order = ORDER_RESET; + // + } + else + { + + for(Uint16 cellnum = 0; cellnum < m_env.hardware.level; cellnum++) + { + _high_level &= m_env.hardware.hvcell.dc_voltage[0][cellnum] > m_env.hardware.dc_voltage_low_level ? true : false; + _high_level &= m_env.hardware.hvcell.dc_voltage[1][cellnum] > m_env.hardware.dc_voltage_low_level ? true : false; + _high_level &= m_env.hardware.hvcell.dc_voltage[2][cellnum] > m_env.hardware.dc_voltage_low_level ? true : false; + // + }//for + // + if(!_high_level & m_env.hardware.low_level()) + { + m_env.hardware.ref_control_order = ORDER_RESET; + m_env.hardware.fault_low_level = false; + } + else + { + m_env.hardware.ref_control_order = ORDER_START; + } + // + }//if else + // + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // +}// +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmOff.h b/SYSCTRL/AlgorithmOff.h new file mode 100644 index 0000000..dfcee8a --- /dev/null +++ b/SYSCTRL/AlgorithmOff.h @@ -0,0 +1,41 @@ +/* + * AlgoritmOff.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_ALGORITMSTOPPED_H_ +#define SYSCTRL_ALGORITMSTOPPED_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + + +namespace SYSCTRL +{ + + +class AlgorithmOff: public AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +public: + AlgorithmOff(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmOff::*_execute)(); + void _execute_run(); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITMSTOPPED_H_ */ diff --git a/SYSCTRL/AlgorithmSource.cpp b/SYSCTRL/AlgorithmSource.cpp new file mode 100644 index 0000000..10372a8 --- /dev/null +++ b/SYSCTRL/AlgorithmSource.cpp @@ -0,0 +1,73 @@ +/* + * AlgorithmSource.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmSource.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmSource::AlgorithmSource(SYSCTRL::SystemEnvironment& env): + AlgorithmBase(), + m_env(env), + m_voltage_direct(FP_ZERO), + m_voltage_quadrature(FP_ZERO), + m_voltage_alpha(FP_ZERO), + m_voltage_beta(FP_ZERO), + m_voltage_a_gen(FP_ZERO), + m_voltage_b_gen(FP_ZERO), + m_voltage_c_gen(FP_ZERO), + m_voltage_a_relative(FP_ZERO), + m_voltage_b_relative(FP_ZERO), + m_voltage_c_relative(FP_ZERO), + m_ort_alpha(FP_ZERO), + m_ort_beta(FP_ZERO), + _execute(&SYSCTRL::AlgorithmSource::_execute_undef) +// +{}//CONSTRUCTOR +// +void AlgorithmSource::setup() +{ + _execute = &SYSCTRL::AlgorithmSource::_execute_run; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmSource::reset() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmSource::execute() +{ + (this->*_execute)(); +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmSource::_execute_run() +{ + + m_env.hardware.ref_control_order = ORDER_START; + + m_voltage_direct = m_env.algorithm_source_references.voltage * cosf(m_env.algorithm_source_references.phase_shift); + m_voltage_quadrature = m_env.algorithm_source_references.voltage * sinf(m_env.algorithm_source_references.phase_shift); + // + m_ort_alpha = m_env.main_ab_orts.active; + m_ort_beta = m_env.main_ab_orts.reactive; + // + FLTSYSLIB::Transformation::park_inverse(m_ort_alpha, m_ort_beta, m_voltage_direct, m_voltage_quadrature, m_voltage_alpha, m_voltage_beta); + FLTSYSLIB::Transformation::clarke_inverse(m_voltage_alpha, m_voltage_beta, m_voltage_a_gen, m_voltage_b_gen, m_voltage_c_gen); + // + m_voltage_a_relative = m_voltage_a_gen * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b_relative = m_voltage_b_gen * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c_relative = m_voltage_c_gen * m_env.cell_dc_voltage_c_reciprocal; + // + m_voltage_a = m_voltage_a_relative; + m_voltage_b = m_voltage_b_relative; + m_voltage_c = m_voltage_c_relative; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmSource.h b/SYSCTRL/AlgorithmSource.h new file mode 100644 index 0000000..0325c3d --- /dev/null +++ b/SYSCTRL/AlgorithmSource.h @@ -0,0 +1,54 @@ +/* + * AlgorithmSource.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#ifndef SYSCTRL_ALGIRITHMSOURCE_H_ +#define SYSCTRL_ALGIRITHMSOURCE_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + +namespace SYSCTRL +{ + +class AlgorithmSource: public AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +private: + float m_voltage_direct; + float m_voltage_quadrature; + float m_voltage_alpha; + float m_voltage_beta; + float m_voltage_a_gen; + float m_voltage_b_gen; + float m_voltage_c_gen; + float m_voltage_a_relative; + float m_voltage_b_relative; + float m_voltage_c_relative; + float m_ort_alpha; + float m_ort_beta; +public: + AlgorithmSource(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmSource::*_execute)(); + void _execute_run(); + // +};//class AlgirithmSource + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGIRITHMSOURCE_H_ */ diff --git a/SYSCTRL/AlgorithmStart.cpp b/SYSCTRL/AlgorithmStart.cpp new file mode 100644 index 0000000..99d4490 --- /dev/null +++ b/SYSCTRL/AlgorithmStart.cpp @@ -0,0 +1,291 @@ +/* + * AlgoritmStart.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmStart.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmStart::AlgorithmStart(SYSCTRL::SystemEnvironment& env): + SYSCTRL::AlgorithmBase(), + m_env(env), +#if TYPECONTROL == VECTORCONTROL + m_reference_zero(FP_ZERO), + m_reference_current_cell_direct(FP_ZERO), + m_reference_current_cell_quadrature(FP_ZERO), +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + m_reference_zero(FP_ZERO), + m_reference_current_cell_direct(FP_ZERO), + m_reference_current_cell_quadrature(FP_ZERO), +#endif + _execute(&SYSCTRL::AlgorithmStart::_execute_undef) +{}//CONSTRUCTOR +// +void AlgorithmStart::setup() +{ + _execute = &SYSCTRL::AlgorithmStart::_execute_run; + // +}// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStart::reset() +{ + +#if TYPECONTROL == VECTORCONTROL + // + m_env.regulator_current_load_direct.reset(); + m_env.regulator_current_load_quadrature.reset(); + // + m_env.referencer_current_bypass_direct.reset(); + m_env.referencer_current_bypass_quadrature.reset(); + // +#endif +#if TYPECONTROL == SCALARCONTROL + m_env.current_referencer_a_active.reset(); + m_env.current_referencer_a_reactive.reset(); + m_env.current_referencer_b_active.reset(); + m_env.current_referencer_b_reactive.reset(); + m_env.current_referencer_c_active.reset(); + m_env.current_referencer_c_reactive.reset(); + + m_env.current_regulator_a_active.reset(); + m_env.current_regulator_a_reactive.reset(); + m_env.current_regulator_b_active.reset(); + m_env.current_regulator_b_reactive.reset(); + m_env.current_regulator_c_active.reset(); + m_env.current_regulator_c_reactive.reset(); +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + m_env.drc_regulator_current_load_direct.reset(); + m_env.drc_regulator_current_load_quadrature.reset(); + // + m_env.drc_referencer_current_bypass_direct.reset(); + m_env.drc_referencer_current_bypass_quadrature.reset(); + // +#endif + + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStart::execute() +{ + (this->*_execute)(); + // +}// +// +#if TYPECONTROL == VECTORCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStart::_execute_run() +{ + // + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_start.execute(); + // + m_reference_current_cell_direct = m_env.referencer_current_bypass_direct.execute(m_reference_zero, m_env.current_bypass_direct); + m_reference_current_cell_quadrature = m_env.referencer_current_bypass_quadrature.execute(m_reference_zero, m_env.current_bypass_quadrature); + // + m_env.voltage_cell_direct = m_env.regulator_current_load_direct.execute(m_env.current_cell_direct, m_reference_current_cell_direct); + m_env.voltage_cell_quadrature = m_env.regulator_current_load_quadrature.execute(m_env.current_cell_quadrature, m_reference_current_cell_quadrature); + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.voltage_cell_direct, + m_env.voltage_cell_quadrature, + m_env.voltage_cell_alpha, + m_env.voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.voltage_cell_alpha, + m_env.voltage_cell_beta, + m_env.voltage_cell_a, + m_env.voltage_cell_b, + m_env.voltage_cell_c); + // + m_voltage_a = m_env.voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // +}// +#endif + + +#if TYPECONTROL == SCALARCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStart::_execute_run() +{ + // + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_start.execute(); + + //**** Phase A *** + //-reference constructor + //m_env.start_control.phase_a.reference.current_bypass_active = FP_ZERO; + //m_env.start_control.phase_a.reference.current_bypass_reactive = FP_ZERO; + // + m_env.start_control.phase_a.reference.current_bypass_active = m_env.start_control.common_ref.active; + m_env.start_control.phase_a.reference.current_bypass_reactive = m_env.start_control.common_ref.reactive; + // + //m_env.start_control.phase_a.test_ref = m_env.start_control.common_ref; + + //-feedback constructor + m_env.start_control.phase_a.feedback.current_bypass_active = m_env.projection_current_bypass_a.active; + m_env.start_control.phase_a.feedback.current_bypass_reactive = m_env.projection_current_bypass_a.reactive; + // + m_env.start_control.phase_a.feedback.current_cell_active = m_env.projection_current_cell_a.active; + m_env.start_control.phase_a.feedback.current_cell_reactive = m_env.projection_current_cell_a.reactive; + // + //-control + _execute_single_phase(m_env.start_control.phase_a, + m_env.main_abc_orts.phase_a, + m_env.cell_dc_voltage_a_reciprocal, + m_env.current_referencer_a_active, + m_env.current_referencer_a_reactive, + m_env.current_regulator_a_active, + m_env.current_regulator_a_reactive); + //<> + + //**** Phase B *** + //-reference constructor + //m_env.start_control.phase_b.reference.current_bypass_active = FP_ZERO; + //m_env.start_control.phase_b.reference.current_bypass_reactive = FP_ZERO; + // + m_env.start_control.phase_b.reference.current_bypass_active = m_env.start_control.common_ref.active; + m_env.start_control.phase_b.reference.current_bypass_reactive = m_env.start_control.common_ref.reactive; + // + //m_env.start_control.phase_b.test_ref = m_env.start_control.common_ref; + + //-feedback constructor + m_env.start_control.phase_b.feedback.current_bypass_active = m_env.projection_current_bypass_b.active; + m_env.start_control.phase_b.feedback.current_bypass_reactive = m_env.projection_current_bypass_b.reactive; + // + m_env.start_control.phase_b.feedback.current_cell_active = m_env.projection_current_cell_b.active; + m_env.start_control.phase_b.feedback.current_cell_reactive = m_env.projection_current_cell_b.reactive; + // + //-control + _execute_single_phase(m_env.start_control.phase_b, + m_env.main_abc_orts.phase_b, + m_env.cell_dc_voltage_b_reciprocal, + m_env.current_referencer_b_active, + m_env.current_referencer_b_reactive, + m_env.current_regulator_b_active, + m_env.current_regulator_b_reactive); + //<> + + + //**** Phase C *** + //-reference constructor + //m_env.start_control.phase_c.reference.current_bypass_active = FP_ZERO; + //m_env.start_control.phase_c.reference.current_bypass_reactive = FP_ZERO; + // + m_env.start_control.phase_c.reference.current_bypass_active = m_env.start_control.common_ref.active; + m_env.start_control.phase_c.reference.current_bypass_reactive = m_env.start_control.common_ref.reactive; + // + //m_env.start_control.phase_c.test_ref = m_env.start_control.common_ref; + + //-feedback constructor + m_env.start_control.phase_c.feedback.current_bypass_active = m_env.projection_current_bypass_c.active; + m_env.start_control.phase_c.feedback.current_bypass_reactive = m_env.projection_current_bypass_c.reactive; + // + m_env.start_control.phase_c.feedback.current_cell_active = m_env.projection_current_cell_c.active; + m_env.start_control.phase_c.feedback.current_cell_reactive = m_env.projection_current_cell_c.reactive; + // + //-control + _execute_single_phase(m_env.start_control.phase_c, + m_env.main_abc_orts.phase_c, + m_env.cell_dc_voltage_c_reciprocal, + m_env.current_referencer_c_active, + m_env.current_referencer_c_reactive, + m_env.current_regulator_c_active, + m_env.current_regulator_c_reactive); + //<> + + m_voltage_a = m_env.start_control.phase_a.reference.voltage_cell_relative; + m_voltage_b = m_env.start_control.phase_b.reference.voltage_cell_relative; + m_voltage_c = m_env.start_control.phase_c.reference.voltage_cell_relative; + // +}// +#endif +// +#if TYPECONTROL == SCALARCONTROL +#pragma CODE_SECTION("ramfuncs"); +inline void AlgorithmStart::_execute_single_phase(SYSCTRL::AlgorithmStartSinglePhaseControl& phase, + SYSCTRL::VectorOrthogonalProjection& orts, + float dc_voltage_reciprocal, + FLTSYSLIB::PIController& referencer_active, + FLTSYSLIB::PIController& referencer_reactive, + FLTSYSLIB::PIController& regulator_active, + FLTSYSLIB::PIController& regulator_reactive) +{ + // + phase.reference.current_cell_active = referencer_active.execute(phase.reference.current_bypass_active, phase.feedback.current_bypass_active); + phase.reference.current_cell_reactive = referencer_reactive.execute(phase.reference.current_bypass_reactive, phase.feedback.current_bypass_reactive); + // + phase.reference.voltage_cell_ampl_active = regulator_active.execute(phase.feedback.current_cell_active, phase.reference.current_cell_active); + phase.reference.voltage_cell_ampl_reactive = regulator_reactive.execute(phase.feedback.current_cell_reactive, phase.reference.current_cell_reactive); + // + //phase.reference.voltage_cell_ampl_active = regulator_active.execute(phase.feedback.current_cell_active, phase.test_ref.active); + //phase.reference.voltage_cell_ampl_reactive = regulator_reactive.execute(phase.feedback.current_cell_reactive, phase.test_ref.reactive); + // + phase.reference.voltage_cell_active = phase.reference.voltage_cell_ampl_active * orts.active; + phase.reference.voltage_cell_reactive = phase.reference.voltage_cell_ampl_reactive * orts.reactive; + // + phase.reference.voltage_cell = phase.reference.voltage_cell_active - phase.reference.voltage_cell_reactive; + phase.reference.voltage_cell_relative = phase.reference.voltage_cell * dc_voltage_reciprocal; + // +}// +#endif +// +#if TYPECONTROL == DIRECTREVERSECONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStart::_execute_run() +{ + // + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_start.execute(); + // + m_reference_current_cell_direct = m_env.drc_referencer_current_bypass_direct.execute(m_reference_zero, m_env.drc_current_bypass_direct); + m_reference_current_cell_quadrature = m_env.drc_referencer_current_bypass_quadrature.execute(m_reference_zero, m_env.drc_current_bypass_quadrature); + // + m_env.drc_positive_voltage_cell_direct = m_env.drc_regulator_current_load_direct.execute(m_env.drc_current_cell_direct, m_reference_current_cell_direct); + m_env.drc_positive_voltage_cell_quadrature = m_env.drc_regulator_current_load_quadrature.execute(m_env.drc_current_cell_quadrature, m_reference_current_cell_quadrature); + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.drc_positive_voltage_cell_direct, + m_env.drc_positive_voltage_cell_quadrature, + m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta, + m_env.drc_positive_voltage_cell_a, + m_env.drc_positive_voltage_cell_b, + m_env.drc_positive_voltage_cell_c); + // + m_env.drc_voltage_cell_a = m_env.drc_positive_voltage_cell_a; + m_env.drc_voltage_cell_b = m_env.drc_positive_voltage_cell_b; + m_env.drc_voltage_cell_c = m_env.drc_positive_voltage_cell_c; + // + m_voltage_a = m_env.drc_voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.drc_voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.drc_voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // +}// +// +#endif + + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmStart.h b/SYSCTRL/AlgorithmStart.h new file mode 100644 index 0000000..0363e2a --- /dev/null +++ b/SYSCTRL/AlgorithmStart.h @@ -0,0 +1,66 @@ +/* + * AlgoritmStart.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_ALGORITMPRESTART_H_ +#define SYSCTRL_ALGORITMPRESTART_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + + +namespace SYSCTRL +{ + + +class AlgorithmStart: public SYSCTRL::AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +#if TYPECONTROL == VECTORCONTROL +private: + float m_reference_zero; + float m_reference_current_cell_direct; + float m_reference_current_cell_quadrature; +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + float m_reference_zero; + float m_reference_current_cell_direct; + float m_reference_current_cell_quadrature; +#endif + +public: + AlgorithmStart(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmStart::*_execute)(); + void _execute_run(); +#if TYPECONTROL == SCALARCONTROL +private: + + inline void _execute_single_phase(SYSCTRL::AlgorithmStartSinglePhaseControl& phase, + SYSCTRL::VectorOrthogonalProjection& orts, + float dc_voltage_reciprocal, + FLTSYSLIB::PIController& referencer_active, + FLTSYSLIB::PIController& referencer_reactive, + FLTSYSLIB::PIController& regulator_active, + FLTSYSLIB::PIController& regulator_reactive); +#endif + // +};//AlgoritmPrestart + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITMPRESTART_H_ */ diff --git a/SYSCTRL/AlgorithmStop.cpp b/SYSCTRL/AlgorithmStop.cpp new file mode 100644 index 0000000..7f76cfd --- /dev/null +++ b/SYSCTRL/AlgorithmStop.cpp @@ -0,0 +1,247 @@ +/* + * AlgorithmStop.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmStop.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmStop::AlgorithmStop(SYSCTRL::SystemEnvironment& env): + SYSCTRL::AlgorithmBase(), + m_env(env), + _execute(&SYSCTRL::AlgorithmStop::_execute_undef) +// +{}//CONSTRUCTOR +// +void AlgorithmStop::setup() +{ + _execute = &SYSCTRL::AlgorithmStop::_execute_run; + // +}// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStop::reset() +{ + +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStop::execute() +{ + (this->*_execute)(); + // +}// +// + +#if TYPECONTROL == VECTORCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStop::_execute_run() +{ + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_stop.execute(); + // + if(m_env.timer_stop.is_finished()){ + // + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // + }else{ + // +#if TYPE_VOLTAGE_CONTROLLER == VOLTAGE_CONTROLLER_PII + + m_env.voltage_reference_load_direct = m_env.reference_voltage_direct_intensity.execute(m_env.voltage_grid_direct); + //m_env.voltage_reference_load_direct = 0.33333*(m_env.rms_voltage_input_a + m_env.rms_voltage_input_b + m_env.rms_voltage_input_c); + //m_env.voltage_reference_load_quadrature = m_env.voltage_grid_quadrature; + m_env.voltage_reference_load_quadrature = FP_ZERO; + m_env.voltage_pi_reg_out_direct = m_env.regulator_voltage_load_direct.execute(m_env.voltage_reference_load_direct, m_env.voltage_load_direct); + //m_env.voltage_pi_reg_out_quadrature = m_env.regulator_voltage_load_quadrature.execute(m_env.voltage_reference_load_quadrature, m_env.voltage_load_quadrature); + m_env.voltage_pi_reg_out_quadrature = FP_ZERO; + // + m_env.voltage_cell_direct = m_env.integrator_direct.execute(m_env.voltage_pi_reg_out_direct); + //m_env.voltage_cell_quadrature = m_env.integrator_quadrature.execute(m_env.voltage_pi_reg_out_quadrature); + m_env.voltage_cell_quadrature = FP_ZERO; +#endif + +#if TYPE_VOLTAGE_CONTROLLER == VOLTAGE_CONTROLLER_I + m_env.voltage_reference_load_direct = m_env.reference_voltage_direct_intensity.execute(m_env.voltage_grid_direct); + m_env.voltage_reference_load_quadrature = FP_ZERO; + m_env.voltage_cell_direct = m_env.integrator_direct.execute(m_env.voltage_reference_load_direct - m_env.voltage_load_direct); + m_env.voltage_cell_quadrature = FP_ZERO; + +#endif + + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.voltage_cell_direct, + m_env.voltage_cell_quadrature, + m_env.voltage_cell_alpha, + m_env.voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.voltage_cell_alpha, + m_env.voltage_cell_beta, + m_env.voltage_cell_a, + m_env.voltage_cell_b, + m_env.voltage_cell_c); + // + m_voltage_a = m_env.voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // + }//if else + // + // +}// +#endif +// +#if TYPECONTROL == SCALARCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStop::_execute_run() +{ + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_stop.execute(); + // + // + //reference constructor +// m_env.phase_control.common_ref.voltage_rms_real = m_env.phase_control.common_ref.voltage_module_rms; + //m_env.phase_control.common_ref.voltage_rms_jm = FP_ZERO; +// m_env.phase_control.phase_a.reference.voltage_ampl_real_const = m_env.phase_control.common_ref.voltage_rms_real; + //m_env.phase_control.phase_a.reference.voltage_ampl_jm_const = m_env.phase_control.common_ref.voltage_rms_jm; +// m_env.phase_control.phase_a.reference.voltage_ampl_jm_const = m_env.projection_voltage_input_a.reactive; +// m_env.phase_control.phase_b.reference.voltage_ampl_real_const = m_env.phase_control.common_ref.voltage_rms_real; + //m_env.phase_control.phase_b.reference.voltage_ampl_jm_const = m_env.phase_control.common_ref.voltage_rms_jm; +// m_env.phase_control.phase_b.reference.voltage_ampl_jm_const = m_env.projection_voltage_input_b.reactive; +// m_env.phase_control.phase_c.reference.voltage_ampl_real_const = m_env.phase_control.common_ref.voltage_rms_real; + //m_env.phase_control.phase_c.reference.voltage_ampl_jm_const = m_env.phase_control.common_ref.voltage_rms_jm; +// m_env.phase_control.phase_c.reference.voltage_ampl_jm_const = m_env.projection_voltage_input_c.reactive; + // + //m_env.phase_control.phase_a.reference.voltage_ampl_real = m_env.phase_control.phase_a.reference.voltage_ampl_real_const; + //m_env.phase_control.phase_a.reference.voltage_ampl_jm = m_env.phase_control.phase_a.reference.voltage_ampl_jm_const; + //m_env.phase_control.phase_b.reference.voltage_ampl_real = m_env.phase_control.phase_b.reference.voltage_ampl_real_const; + //m_env.phase_control.phase_b.reference.voltage_ampl_jm = m_env.phase_control.phase_b.reference.voltage_ampl_jm_const; + //m_env.phase_control.phase_c.reference.voltage_ampl_real = m_env.phase_control.phase_c.reference.voltage_ampl_real_const; + //m_env.phase_control.phase_c.reference.voltage_ampl_jm = m_env.phase_control.phase_c.reference.voltage_ampl_jm_const; + + m_env.phase_control.phase_a.reference.voltage_ampl_real = m_env.projection_voltage_input_a.active; + m_env.phase_control.phase_a.reference.voltage_ampl_jm = m_env.projection_voltage_input_a.reactive; + m_env.phase_control.phase_b.reference.voltage_ampl_real = m_env.projection_voltage_input_b.active; + m_env.phase_control.phase_b.reference.voltage_ampl_jm = m_env.projection_voltage_input_b.reactive; + m_env.phase_control.phase_c.reference.voltage_ampl_real = m_env.projection_voltage_input_c.active; + m_env.phase_control.phase_c.reference.voltage_ampl_jm = m_env.projection_voltage_input_c.reactive; + + // + //control execute + _execute_single_phase(m_env.phase_control.phase_a, + m_env.main_abc_orts.phase_a, + m_env.regulator_voltage_load_a_active, + m_env.regulator_voltage_load_a_reactive); + // + _execute_single_phase(m_env.phase_control.phase_b, + m_env.main_abc_orts.phase_b, + m_env.regulator_voltage_load_b_active, + m_env.regulator_voltage_load_b_reactive); + // + _execute_single_phase(m_env.phase_control.phase_c, + m_env.main_abc_orts.phase_c, + m_env.regulator_voltage_load_c_active, + m_env.regulator_voltage_load_c_reactive); + // + + + if(m_env.timer_stop.is_finished()){ + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + }else{ + m_voltage_a = m_env.phase_control.phase_a.reference.voltage_cell_relative; + m_voltage_b = m_env.phase_control.phase_b.reference.voltage_cell_relative; + m_voltage_c = m_env.phase_control.phase_c.reference.voltage_cell_relative; + } + // +}// +#endif +// +// +#if TYPECONTROL == SCALARCONTROL +#pragma CODE_SECTION("ramfuncs"); +inline void AlgorithmStop::_execute_single_phase(SYSCTRL::AlgorithmSinglePhaseControl& phase, + SYSCTRL::VectorOrthogonalProjection& orts, + FLTSYSLIB::PIController& regulator_active, + FLTSYSLIB::PIController& regulator_reactive) +{ + phase.reference.voltage_cell_ampl_real = regulator_active.execute(phase.reference.voltage_ampl_real, phase.feedback.voltage_ampl_real); + phase.reference.voltage_cell_ampl_jm = regulator_reactive.execute(phase.reference.voltage_ampl_jm, phase.feedback.voltage_ampl_jm); + // + phase.reference.voltage_cell_real = phase.reference.voltage_cell_ampl_real * orts.active; + phase.reference.voltage_cell_jm = phase.reference.voltage_cell_ampl_jm * orts.reactive; + phase.reference.voltage_cell = phase.reference.voltage_cell_real - phase.reference.voltage_cell_jm; + // + phase.reference.voltage_cell_relative = phase.reference.voltage_cell * phase.feedback.voltage_cell_dc_reciprocal; + // +}// +#endif +// + +#if TYPECONTROL == DIRECTREVERSECONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmStop::_execute_run() +{ + + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_stop.execute(); + // + if(m_env.timer_stop.is_finished()){ + // + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // + }else{ + // + + m_env.drc_voltage_reference_load_direct = m_env.drc_reference_voltage_direct_intensity.execute(m_env.drc_voltage_grid_direct); + m_env.drc_voltage_reference_load_quadrature = FP_ZERO; + // + m_env.drc_positive_voltage_cell_direct = m_env.drc_positive_voltage_controller_direct.execute(m_env.drc_voltage_reference_load_direct, m_env.drc_positive_voltage_load_direct); + m_env.drc_positive_voltage_cell_quadrature = FP_ZERO; + m_env.drc_negative_voltage_cell_direct = FP_ZERO; + m_env.drc_negative_voltage_cell_quadrature = FP_ZERO; + m_env.drc_negative_voltage_cell_alpha = FP_ZERO; + m_env.drc_negative_voltage_cell_beta = FP_ZERO; + m_env.drc_negative_voltage_cell_a = FP_ZERO; + m_env.drc_negative_voltage_cell_b = FP_ZERO; + m_env.drc_negative_voltage_cell_c = FP_ZERO; + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.drc_positive_voltage_cell_direct, + m_env.drc_positive_voltage_cell_quadrature, + m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta, + m_env.drc_positive_voltage_cell_a, + m_env.drc_positive_voltage_cell_b, + m_env.drc_positive_voltage_cell_c); + // + m_env.drc_voltage_cell_a = m_env.drc_positive_voltage_cell_a; + m_env.drc_voltage_cell_b = m_env.drc_positive_voltage_cell_b; + m_env.drc_voltage_cell_c = m_env.drc_positive_voltage_cell_c; + // + m_voltage_a = m_env.drc_voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.drc_voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.drc_voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // + }//if else + // +}// +#endif +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmStop.h b/SYSCTRL/AlgorithmStop.h new file mode 100644 index 0000000..6fa43e2 --- /dev/null +++ b/SYSCTRL/AlgorithmStop.h @@ -0,0 +1,48 @@ +/* + * AlgorithmStop.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#ifndef SYSCTRL_ALGORITHMSTOP_H_ +#define SYSCTRL_ALGORITHMSTOP_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + +namespace SYSCTRL +{ + +class AlgorithmStop: public SYSCTRL::AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +public: + AlgorithmStop(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmStop::*_execute)(); + void _execute_run(); +#if TYPECONTROL == SCALARCONTROL +private: + inline void _execute_single_phase(SYSCTRL::AlgorithmSinglePhaseControl& phase, + SYSCTRL::VectorOrthogonalProjection& orts, + FLTSYSLIB::PIController& regulator_active, + FLTSYSLIB::PIController& regulator_reactive); +#endif + // +};//AlgorithmPrestop + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMSTOP_H_ */ diff --git a/SYSCTRL/AlgorithmWork.cpp b/SYSCTRL/AlgorithmWork.cpp new file mode 100644 index 0000000..b4a5d70 --- /dev/null +++ b/SYSCTRL/AlgorithmWork.cpp @@ -0,0 +1,407 @@ +/* + * AlgorithmWork.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmWork.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmWork::AlgorithmWork(SYSCTRL::SystemEnvironment& env): + AlgorithmBase(), + m_env(env), + m_reference_switcher(false), + _execute(&SYSCTRL::AlgorithmWork::_execute_undef) +// +{}//CONSTRUCTOR +// + +void AlgorithmWork::setup() +{ + _execute = &SYSCTRL::AlgorithmWork::_execute_run; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::reset() +{ +#if TYPECONTROL == VECTORCONTROL + // + m_env.regulator_voltage_load_direct.reset(); + m_env.regulator_voltage_load_quadrature.reset(); + // + m_env.integrator_direct.reset(); + m_env.integrator_quadrature.reset(); + // + m_env.regulator_current_limit.set_to_high_saturation(); + m_env.regulator_current_pfc.reset(); + // +#endif + +#if TYPECONTROL == SCALARCONTROL + // + m_env.regulator_current_limit_a.set_to_high_saturation(); + m_env.regulator_current_pfc_a.reset(); + + m_env.regulator_current_limit_b.set_to_high_saturation(); + m_env.regulator_current_pfc_b.reset(); + + m_env.regulator_current_limit_c.set_to_high_saturation(); + m_env.regulator_current_pfc_c.reset(); + + m_env.regulator_voltage_load_a_active.reset(); + m_env.regulator_voltage_load_a_reactive.reset(); + + m_env.regulator_voltage_load_b_active.reset(); + m_env.regulator_voltage_load_b_reactive.reset(); + + m_env.regulator_voltage_load_c_active.reset(); + m_env.regulator_voltage_load_c_reactive.reset(); + // +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + + m_env.drc_positive_voltage_controller_direct.reset(); + m_env.drc_positive_voltage_controller_quadrature.reset(); + m_env.drc_negative_voltage_controller_direct.reset(); + m_env.drc_negative_voltage_controller_quadrature.reset(); + // + m_env.drc_reference_voltage_direct_intensity.reset(); + // + m_env.drc_regulator_current_load_direct.reset(); + m_env.drc_regulator_current_load_quadrature.reset(); + // + m_env.drc_referencer_current_bypass_direct.reset(); + m_env.drc_referencer_current_bypass_quadrature.reset(); + // + m_env.drc_regulator_current_limit.set_to_low_saturation(); + m_env.drc_regulator_current_pfc.reset(); + // + m_reference_switcher = false; + // +#endif + + + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::reset_switcher() +{ + m_reference_switcher = false; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::execute() +{ + (this->*_execute)(); + // +}// +// + + +#if TYPECONTROL == VECTORCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::_execute_run() +{ + // + m_env.hardware.ref_control_order = ORDER_START; + // + //if(m_env.algorithm_control.signal.enable_current_limit) + if(false) + { + m_env.voltage_reference_load_direct = m_env.regulator_current_limit.execute(m_env.rms_current_load_module, m_env.current_reference_limit); + } + else + { + m_env.regulator_current_limit.set_to_low_saturation(); + m_env.voltage_reference_load_direct = m_env.regulator_current_limit.get_output(); + } + // + //if(m_env.algorithm_control.signal.enable_pfc) + if(false) + { + m_env.regulator_current_pfc.reset(); + m_env.voltage_reference_load_quadrature = m_env.regulator_current_pfc.get_output(); + } + else + { + m_env.regulator_current_pfc.reset(); + m_env.voltage_reference_load_quadrature = m_env.regulator_current_pfc.get_output(); + } + // + + // for PII-Controller +#if TYPE_VOLTAGE_CONTROLLER == VOLTAGE_CONTROLLER_PII + m_env.voltage_pi_reg_out_direct = m_env.regulator_voltage_load_direct.execute(m_env.voltage_reference_load_direct, m_env.voltage_load_direct); + //m_env.voltage_pi_reg_out_quadrature = m_env.regulator_voltage_load_quadrature.execute(m_env.voltage_reference_load_quadrature, m_env.voltage_load_quadrature); + m_env.voltage_pi_reg_out_quadrature = FP_ZERO; + m_env.voltage_cell_direct = m_env.integrator_direct.execute(m_env.voltage_pi_reg_out_direct); + //m_env.voltage_cell_quadrature = m_env.integrator_quadrature.execute(m_env.voltage_pi_reg_out_quadrature); + m_env.voltage_cell_quadrature = FP_ZERO; +#endif + + // for I-Controller +#if TYPE_VOLTAGE_CONTROLLER == VOLTAGE_CONTROLLER_I + m_env.voltage_cell_direct = m_env.integrator_direct.execute(m_env.voltage_reference_load_direct - m_env.voltage_load_direct); + m_env.voltage_cell_quadrature = FP_ZERO; +#endif + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.voltage_cell_direct, + m_env.voltage_cell_quadrature, + m_env.voltage_cell_alpha, + m_env.voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.voltage_cell_alpha, + m_env.voltage_cell_beta, + m_env.voltage_cell_a, + m_env.voltage_cell_b, + m_env.voltage_cell_c); + // + m_voltage_a = m_env.voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // +}// +// +#endif + + + +#if TYPECONTROL == SCALARCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::_execute_run() +{ + + m_env.hardware.ref_control_order = ORDER_START; + + m_env.phase_control.phase_a.reference.voltage_dc = m_env.phase_control.common_ref.voltage_dc; + m_env.phase_control.phase_b.reference.voltage_dc = m_env.phase_control.common_ref.voltage_dc; + m_env.phase_control.phase_c.reference.voltage_dc = m_env.phase_control.common_ref.voltage_dc; + + m_env.phase_control.phase_a.reference.current_ampl_limit_const = m_env.phase_control.common_ref.current_limit_rms; + m_env.phase_control.phase_b.reference.current_ampl_limit_const = m_env.phase_control.common_ref.current_limit_rms; + m_env.phase_control.phase_c.reference.current_ampl_limit_const = m_env.phase_control.common_ref.current_limit_rms; + + m_env.phase_control.phase_a.reference.current_ampl_pfc_const = m_env.phase_control.common_ref.current_pfc_rms; + m_env.phase_control.phase_b.reference.current_ampl_pfc_const = m_env.phase_control.common_ref.current_pfc_rms; + m_env.phase_control.phase_c.reference.current_ampl_pfc_const = m_env.phase_control.common_ref.current_pfc_rms; + + + + _execute_single_phase(m_env.phase_control.phase_a, + m_env.projection_voltage_input_a, + m_env.main_abc_orts.phase_a, + m_env.regulator_current_limit_a, + m_env.regulator_current_pfc_a, + m_env.regulator_dc_a, + m_env.cell_dc_voltage_a, + m_env.regulator_voltage_load_a_active, + m_env.regulator_voltage_load_a_reactive); + + _execute_single_phase(m_env.phase_control.phase_b, + m_env.projection_voltage_input_b, + m_env.main_abc_orts.phase_b, + m_env.regulator_current_limit_b, + m_env.regulator_current_pfc_b, + m_env.regulator_dc_b, + m_env.cell_dc_voltage_b, + m_env.regulator_voltage_load_b_active, + m_env.regulator_voltage_load_b_reactive); + + _execute_single_phase(m_env.phase_control.phase_c, + m_env.projection_voltage_input_c, + m_env.main_abc_orts.phase_c, + m_env.regulator_current_limit_c, + m_env.regulator_current_pfc_c, + m_env.regulator_dc_c, + m_env.cell_dc_voltage_c, + m_env.regulator_voltage_load_c_active, + m_env.regulator_voltage_load_c_reactive); + + m_voltage_a = m_env.phase_control.phase_a.reference.voltage_cell_relative; + m_voltage_b = m_env.phase_control.phase_b.reference.voltage_cell_relative; + m_voltage_c = m_env.phase_control.phase_c.reference.voltage_cell_relative; + // +}// +#endif +// +#if TYPECONTROL == SCALARCONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::_execute_single_phase(SYSCTRL::AlgorithmSinglePhaseControl& phase, + SYSCTRL::ProjectionAnalogSignalStructure& projection, + SYSCTRL::VectorOrthogonalProjection& orts, + FLTSYSLIB::PIController& regulator_limit, + FLTSYSLIB::PIController& regulator_pfc, + FLTSYSLIB::PIController& regulator_dc, + float& dc_volatage, + FLTSYSLIB::PIController& regulator_active, + FLTSYSLIB::PIController& regulator_reactive) +{ + + + if(phase.control_bit.signal.enable_current_limit) + { + + phase.reference.voltage_limit = regulator_limit.execute(phase.reference.current_ampl_limit_const, phase.feedback.current_ampl_real); + + if(phase.control_bit.signal.enable_pfc) + { + phase.reference.voltage_pfc = regulator_pfc.execute(phase.reference.current_ampl_pfc_const, phase.feedback.current_ampl_jm) + + regulator_dc.execute(phase.reference.voltage_dc, dc_volatage); + } + else + { + regulator_pfc.reset(); + phase.reference.voltage_pfc = projection.reactive; + // + }//if else + } + else + { + regulator_limit.set_to_high_saturation(); + phase.reference.voltage_limit = regulator_limit.get_output(); + // + regulator_pfc.reset(); + phase.reference.voltage_pfc = projection.reactive; + // + }//if else + + + if(phase.control_bit.signal.enable_pfc) + { + phase.reference.voltage_ampl_real = sqrtf(phase.reference.voltage_limit * phase.reference.voltage_limit - phase.reference.voltage_pfc * phase.reference.voltage_pfc); + phase.reference.voltage_ampl_jm = phase.reference.voltage_pfc; + // + } + else + { + phase.reference.voltage_ampl_real = phase.reference.voltage_limit; + phase.reference.voltage_ampl_jm = phase.reference.voltage_pfc; + // + }//if else + // + phase.reference.voltage_cell_ampl_real = regulator_active.execute(phase.reference.voltage_ampl_real, phase.feedback.voltage_ampl_real); + // + if(phase.control_bit.signal.enable_pfc) + { + phase.reference.voltage_cell_ampl_jm = regulator_reactive.execute(phase.reference.voltage_ampl_jm, phase.feedback.voltage_ampl_jm); + // + } + else + { + phase.reference.voltage_cell_ampl_jm = FP_ZERO; + // + }//if + // + phase.reference.voltage_cell_real = phase.reference.voltage_cell_ampl_real * orts.active; + phase.reference.voltage_cell_jm = phase.reference.voltage_cell_ampl_jm * orts.reactive; + phase.reference.voltage_cell = phase.reference.voltage_cell_real - phase.reference.voltage_cell_jm; + // + phase.reference.voltage_cell_relative = phase.reference.voltage_cell * phase.feedback.voltage_cell_dc_reciprocal; + // +}// +#endif +// + + +#if TYPECONTROL == DIRECTREVERSECONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWork::_execute_run() +{ + + // + m_env.hardware.ref_control_order = ORDER_START; + // + + if(m_reference_switcher) + { + //if(m_env.algorithm_control.signal.enable_current_limit) + if(false) + { + m_env.drc_voltage_reference_load_direct = m_env.drc_regulator_current_limit.execute(m_env.rms_current_load_module, m_env.drc_current_reference_limit); + } + else + { + m_env.drc_regulator_current_limit.set_to_low_saturation(); + m_env.drc_voltage_reference_load_direct = m_env.drc_regulator_current_limit.get_output(); + } + } + else + { + m_env.drc_voltage_reference_load_direct = m_env.drc_reference_voltage_direct_intensity.execute(m_env.drc_regulator_current_limit.get_output()); + // + if(m_env.drc_voltage_reference_load_direct >= m_env.drc_regulator_current_limit.get_output()) + { + m_reference_switcher = true; + } + } + + // + //if(m_env.algorithm_control.signal.enable_pfc) + if(false) + { + m_env.drc_regulator_current_pfc.reset(); + m_env.drc_voltage_reference_load_quadrature = m_env.drc_regulator_current_pfc.get_output(); + } + else + { + m_env.drc_regulator_current_pfc.reset(); + m_env.drc_voltage_reference_load_quadrature = m_env.drc_regulator_current_pfc.get_output(); + } + // + m_env.drc_positive_voltage_cell_direct = m_env.drc_positive_voltage_controller_direct.execute(m_env.drc_voltage_reference_load_direct, m_env.drc_positive_voltage_load_direct); + //m_env.drc_positive_voltage_cell_quadrature = m_env.drc_positive_voltage_controller_quadrature.execute(m_env.drc_voltage_reference_load_quadrature, m_env.drc_positive_voltage_load_quadrature); + m_env.drc_positive_voltage_cell_quadrature = FP_ZERO; + m_env.drc_negative_voltage_cell_direct = m_env.drc_negative_voltage_controller_direct.execute(m_env.drc_voltage_reference_zero, m_env.drc_negaative_voltage_load_direct); + m_env.drc_negative_voltage_cell_quadrature = m_env.drc_negative_voltage_controller_quadrature.execute(m_env.drc_voltage_reference_zero, m_env.drc_negative_voltage_load_quadrature); + //m_env.drc_negative_voltage_cell_direct = FP_ZERO; + //m_env.drc_negative_voltage_cell_quadrature = FP_ZERO; + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.drc_positive_voltage_cell_direct, + m_env.drc_positive_voltage_cell_quadrature, + m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta); + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.drc_negative_voltage_cell_direct, + m_env.drc_negative_voltage_cell_quadrature, + m_env.drc_negative_voltage_cell_alpha, + m_env.drc_negative_voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta, + m_env.drc_positive_voltage_cell_a, + m_env.drc_positive_voltage_cell_b, + m_env.drc_positive_voltage_cell_c); + // + FLTSYSLIB::Transformation::clarke_inverse_back_order(m_env.drc_negative_voltage_cell_alpha, + m_env.drc_negative_voltage_cell_beta, + m_env.drc_negative_voltage_cell_a, + m_env.drc_negative_voltage_cell_b, + m_env.drc_negative_voltage_cell_c); + // + m_env.drc_voltage_cell_a = m_env.drc_positive_voltage_cell_a + m_env.drc_negative_voltage_cell_a; + m_env.drc_voltage_cell_b = m_env.drc_positive_voltage_cell_b + m_env.drc_negative_voltage_cell_b; + m_env.drc_voltage_cell_c = m_env.drc_positive_voltage_cell_c + m_env.drc_negative_voltage_cell_c; + // + m_voltage_a = m_env.drc_voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.drc_voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.drc_voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // +}// +#endif + + +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmWork.h b/SYSCTRL/AlgorithmWork.h new file mode 100644 index 0000000..3e0e9df --- /dev/null +++ b/SYSCTRL/AlgorithmWork.h @@ -0,0 +1,55 @@ +/* + * AlgorithmWork.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_ALGORITHMNORMAL_H_ +#define SYSCTRL_ALGORITHMNORMAL_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + +namespace SYSCTRL +{ + +class AlgorithmWork: public SYSCTRL::AlgorithmBase +{ +private: + bool m_reference_switcher; + +private: + SYSCTRL::SystemEnvironment& m_env; +public: + AlgorithmWork(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); + void reset_switcher(); +public: + void execute(); +private: + void (AlgorithmWork::*_execute)(); + void _execute_run(); +#if TYPECONTROL == SCALARCONTROL +private: + void _execute_single_phase(SYSCTRL::AlgorithmSinglePhaseControl& phase, + SYSCTRL::ProjectionAnalogSignalStructure& projection, + SYSCTRL::VectorOrthogonalProjection& orts, + FLTSYSLIB::PIController& regulator_limit, + FLTSYSLIB::PIController& regulator_pfc, + FLTSYSLIB::PIController& regulator_dc, + float& dc_volatage, + FLTSYSLIB::PIController& regulator_active, + FLTSYSLIB::PIController& regulator_reactive); +#endif +};//AlgorithmNormal + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMNORMAL_H_ */ diff --git a/SYSCTRL/AlgorithmWorkEntry.cpp b/SYSCTRL/AlgorithmWorkEntry.cpp new file mode 100644 index 0000000..a30b77d --- /dev/null +++ b/SYSCTRL/AlgorithmWorkEntry.cpp @@ -0,0 +1,112 @@ +/* + * AlgorithmWorkEntry.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/AlgorithmWorkEntry.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +AlgorithmWorkEntry::AlgorithmWorkEntry(SYSCTRL::SystemEnvironment& env): + SYSCTRL::AlgorithmBase(), + m_env(env), + _execute(&SYSCTRL::AlgorithmWorkEntry::_execute_undef) +{}//CONSTRUCTOR + + +void AlgorithmWorkEntry::setup() +{ + _execute = &SYSCTRL::AlgorithmWorkEntry::_execute_run; + // +}// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWorkEntry::reset() +{ + +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWorkEntry::execute() +{ + (this->*_execute)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool AlgorithmWorkEntry::compare_mode(mode_t mode) +{ + return m_mode == mode; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWorkEntry::set_mode(mode_t mode) +{ + m_mode = mode; + // +}// +// + +#if TYPECONTROL == DIRECTREVERSECONTROL +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmWorkEntry::_execute_run() +{ + + m_env.hardware.ref_control_order = ORDER_START; + // + m_env.timer_stop.execute(); + // + if(m_env.timer_stop.is_finished()){ + // + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // + }else{ + // + + m_env.drc_voltage_reference_load_direct = m_env.drc_reference_voltage_direct_intensity.execute(m_env.drc_voltage_grid_direct); + m_env.drc_voltage_reference_load_quadrature = FP_ZERO; + // + m_env.drc_positive_voltage_cell_direct = m_env.drc_positive_voltage_controller_direct.execute(m_env.drc_voltage_reference_load_direct, m_env.drc_positive_voltage_load_direct); + m_env.drc_positive_voltage_cell_quadrature = FP_ZERO; + m_env.drc_negative_voltage_cell_direct = FP_ZERO; + m_env.drc_negative_voltage_cell_quadrature = FP_ZERO; + m_env.drc_negative_voltage_cell_alpha = FP_ZERO; + m_env.drc_negative_voltage_cell_beta = FP_ZERO; + m_env.drc_negative_voltage_cell_a = FP_ZERO; + m_env.drc_negative_voltage_cell_b = FP_ZERO; + m_env.drc_negative_voltage_cell_c = FP_ZERO; + // + FLTSYSLIB::Transformation::park_inverse(m_env.main_ab_orts.active, + m_env.main_ab_orts.reactive, + m_env.drc_positive_voltage_cell_direct, + m_env.drc_positive_voltage_cell_quadrature, + m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta); + // + FLTSYSLIB::Transformation::clarke_inverse(m_env.drc_positive_voltage_cell_alpha, + m_env.drc_positive_voltage_cell_beta, + m_env.drc_positive_voltage_cell_a, + m_env.drc_positive_voltage_cell_b, + m_env.drc_positive_voltage_cell_c); + // + m_env.drc_voltage_cell_a = m_env.drc_positive_voltage_cell_a; + m_env.drc_voltage_cell_b = m_env.drc_positive_voltage_cell_b; + m_env.drc_voltage_cell_c = m_env.drc_positive_voltage_cell_c; + // + m_voltage_a = m_env.drc_voltage_cell_a * m_env.cell_dc_voltage_a_reciprocal; + m_voltage_b = m_env.drc_voltage_cell_b * m_env.cell_dc_voltage_b_reciprocal; + m_voltage_c = m_env.drc_voltage_cell_c * m_env.cell_dc_voltage_c_reciprocal; + // + }//if else + // +}// +#endif + + + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmWorkEntry.h b/SYSCTRL/AlgorithmWorkEntry.h new file mode 100644 index 0000000..e310724 --- /dev/null +++ b/SYSCTRL/AlgorithmWorkEntry.h @@ -0,0 +1,41 @@ +/* + * AlgorithmWorkEntry.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#ifndef SYSCTRL_ALGORITHMWORKENTRY_H_ +#define SYSCTRL_ALGORITHMWORKENTRY_H_ + +#include "SYSCTRL/AlgorithmBase.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + +namespace SYSCTRL +{ + +class AlgorithmWorkEntry: public AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +public: + AlgorithmWorkEntry(SYSCTRL::SystemEnvironment& env); + +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmWorkEntry::*_execute)(); + void _execute_run(); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMWORKENTRY_H_ */ diff --git a/SYSCTRL/AlgorithmZero.cpp b/SYSCTRL/AlgorithmZero.cpp new file mode 100644 index 0000000..0de7300 --- /dev/null +++ b/SYSCTRL/AlgorithmZero.cpp @@ -0,0 +1,50 @@ +/* + * AlgorithmZero.cpp + * + * Created on: 20 ìàÿ 2022 ã. + * Author: geras + */ + +#include "SYSCTRL/AlgorithmZero.h" + +namespace SYSCTRL +{ + +//CONSTRUCTOR +AlgorithmZero::AlgorithmZero(SYSCTRL::SystemEnvironment& env): + SYSCTRL::AlgorithmBase(), + m_env(env), + _execute(&SYSCTRL::AlgorithmZero::_execute_undef) +{}//CONSTRUCTOR + +void AlgorithmZero::setup() +{ + _execute = &SYSCTRL::AlgorithmZero::_execute_run; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmZero::reset() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmZero::execute() +{ + (this->*_execute)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void AlgorithmZero::_execute_run() +{ + // + m_env.hardware.ref_control_order = ORDER_START; + // + m_voltage_a = FP_ZERO; + m_voltage_b = FP_ZERO; + m_voltage_c = FP_ZERO; + // +}// +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/AlgorithmZero.h b/SYSCTRL/AlgorithmZero.h new file mode 100644 index 0000000..948b44f --- /dev/null +++ b/SYSCTRL/AlgorithmZero.h @@ -0,0 +1,38 @@ +/* + * AlgorithmZero.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_ALGORITHMZERO_H_ +#define SYSCTRL_ALGORITHMZERO_H_ + +#include "SYSCTRL/AlgorithmBase.h" + +namespace SYSCTRL +{ + +class AlgorithmZero: public AlgorithmBase +{ +private: + SYSCTRL::SystemEnvironment& m_env; +public: + AlgorithmZero(SYSCTRL::SystemEnvironment& env); +public: + void setup(); +public: + void reset(); +public: + void execute(); +private: + void (AlgorithmZero::*_execute)(); + void _execute_run(); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ALGORITHMZERO_H_ */ diff --git a/SYSCTRL/BaseComponent.cpp b/SYSCTRL/BaseComponent.cpp new file mode 100644 index 0000000..8467bfa --- /dev/null +++ b/SYSCTRL/BaseComponent.cpp @@ -0,0 +1,33 @@ +/* + * BaseComponent.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/BaseComponent.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +BaseComponent::BaseComponent(): + m_mode(SYSCTRL::BaseComponent::UNDEFINED), + m_time_sample(-1.0) +// +{}//CONSTRUCTOR +// +#pragma CODE_SECTION("ramfuncs"); +SYSCTRL::BaseComponent::mode_t BaseComponent::get_mode() +{ + return m_mode; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool BaseComponent::compare(SYSCTRL::BaseComponent::mode_t mode) +{ + return m_mode == mode; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/BaseComponent.h b/SYSCTRL/BaseComponent.h new file mode 100644 index 0000000..2300abe --- /dev/null +++ b/SYSCTRL/BaseComponent.h @@ -0,0 +1,34 @@ +/* + * BaseComponent.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_BASECOMPONENT_H_ +#define SYSCTRL_BASECOMPONENT_H_ + +namespace SYSCTRL +{ + +class BaseComponent +{ +public: + enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; +protected: + mode_t m_mode; +protected: + float m_time_sample; +public: + BaseComponent(); +public: + mode_t get_mode(); + bool compare(mode_t mode); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_BASECOMPONENT_H_ */ diff --git a/SYSCTRL/ContactorFault.cpp b/SYSCTRL/ContactorFault.cpp new file mode 100644 index 0000000..bfc3b02 --- /dev/null +++ b/SYSCTRL/ContactorFault.cpp @@ -0,0 +1,89 @@ +/* + * ContactorFault.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ +#include "SYSCTRL/ContactorFault.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +ContactorFault::ContactorFault(): + m_time_sample(-1.0), + m_period(-1.0), + m_counter(FP_ZERO), + m_status(), + status(), + _execute(&SYSCTRL::ContactorFault::_execute_undef) +{} +//end CONSTRUCTOR + +void ContactorFault::setup(float time_sample) +{ + + m_time_sample = time_sample; + _execute = &SYSCTRL::ContactorFault::_execute_undef; + // +}// +// +void ContactorFault::configure(ContactorFaultConfiguration& config) +{ + m_period = config.period; + + if((m_time_sample > FP_ZERO) && (m_period > m_time_sample)) + { + _execute = &SYSCTRL::ContactorFault::_execute_operational; + } + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +void ContactorFault::reset(bool ref) +{ + m_status.signal.fault &= !ref; + status.all = m_status.all; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void ContactorFault::execute(bool ref, bool current) +{ + (this->*_execute)(ref, current); + // +}// +// + +void ContactorFault::_execute_undef(bool ref, bool current) +{ + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void ContactorFault::_execute_operational(bool ref, bool current) +{ + if(!m_status.signal.fault) + { + if(ref == current) + { + m_counter = FP_ZERO; + + }else{ + + if(m_counter >= m_period) + { + m_status.signal.fault = 1; + m_counter = FP_ZERO; + + }else{ + + m_counter += m_time_sample; + } + } + } + status.all = m_status.all; + // +}// +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/ContactorFault.h b/SYSCTRL/ContactorFault.h new file mode 100644 index 0000000..af90d63 --- /dev/null +++ b/SYSCTRL/ContactorFault.h @@ -0,0 +1,69 @@ +/* + * ContactorFault.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/BaseComponent.h" + +#ifndef SYSCTRL_CONTACTORFAULT_H_ +#define SYSCTRL_CONTACTORFAULT_H_ + +namespace SYSCTRL +{ + +struct ContactorFaultConfiguration +{ + float period; + ContactorFaultConfiguration(): + period(-1.0) + {} +}; + + +struct ContactorFaultBitField +{ + uint16_t fault: 1; +}; + +union ContactorFaultRegister +{ + uint16_t all; + ContactorFaultBitField signal; + ContactorFaultRegister(): + all((uint16_t)0) + {} +}; + + + +class ContactorFault +{ +private: + float m_time_sample; + float m_period; + float m_counter; + ContactorFaultRegister m_status; +public: + ContactorFaultRegister status; +public: + ContactorFault(); + void setup(float time_sample); + void configure(ContactorFaultConfiguration& config); +public: + void reset(bool ref); +public: + void execute(bool ref, bool current); +private: + void (ContactorFault::*_execute)(bool ref, bool current); + void _execute_undef(bool ref, bool current); + void _execute_operational(bool ref, bool current); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_CONTACTORFAULT_H_ */ diff --git a/SYSCTRL/DRCDecomposer.cpp b/SYSCTRL/DRCDecomposer.cpp new file mode 100644 index 0000000..b5b02dd --- /dev/null +++ b/SYSCTRL/DRCDecomposer.cpp @@ -0,0 +1,101 @@ +/* + * DRCDecomposer.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/DRCDecomposer.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +DRCDecomposer::DRCDecomposer(): + m_time_sample(-1.0), + m_filter_direct(), + m_filter_quadrature(), + _aux_reg(FP_ZERO), + direct(FP_ZERO), + quadrature(FP_ZERO), + _execute(&SYSCTRL::DRCDecomposer::_execute_undef) +{}//CONSTRUCTOR + +void DRCDecomposer::setup(float time_sample) +{ + if(time_sample > FP_ZERO) + { + m_time_sample = time_sample; + m_filter_direct.setup(m_time_sample); + m_filter_quadrature.setup(m_time_sample); + } + // +}// +// +void DRCDecomposer::configure(const DRCDecomposerConfiguration& config) +{ + if(m_time_sample > FP_ZERO) + { + m_filter_direct.configure(config.filter); + m_filter_quadrature.configure(config.filter); + + if(m_filter_direct.compare(FLTSYSLIB::Filter::OPERATIONAL) && m_filter_quadrature.compare(FLTSYSLIB::Filter::OPERATIONAL)) + //if(m_filter_direct.compare(FLTSYSLIB::FilterSecond::OPERATIONAL) && m_filter_quadrature.compare(FLTSYSLIB::FilterSecond::OPERATIONAL)) + { + _execute = &SYSCTRL::DRCDecomposer::_execute_operational; + // + }//if + // + }//if + // +}// +// +void DRCDecomposer::reset() +{ + m_filter_direct.reset(); + m_filter_quadrature.reset(); + this->direct = FP_ZERO; + this->quadrature = FP_ZERO; + // +}// +// +void DRCDecomposer::get_outputs(float& outd, float& outq) +{ + this->direct = m_filter_direct.get_output(); + this->quadrature = m_filter_quadrature.get_output(); + outd = this->direct; + outq = this->quadrature; + // +}// +// +void DRCDecomposer::execute(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c) +{ + (this->*_execute)(in_a, in_b, in_c, + ort_direct_a, ort_direct_b, ort_direct_c, + ort_orthogonal_a, ort_orthogonal_b, ort_orthogonal_c); + // +}// +// +void DRCDecomposer::_execute_undef(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c) +{ + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void DRCDecomposer::_execute_operational(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c) +{ + _aux_reg = (0.4714045)*(in_a * ort_direct_a + in_b * ort_direct_b + in_c * ort_direct_c); + direct = m_filter_direct.execute(_aux_reg); + _aux_reg = (-0.4714045)*(in_a * ort_orthogonal_a + in_b * ort_orthogonal_b + in_c * ort_orthogonal_c); + quadrature = m_filter_quadrature.execute(_aux_reg); + // +}// +// + + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/DRCDecomposer.h b/SYSCTRL/DRCDecomposer.h new file mode 100644 index 0000000..db70a76 --- /dev/null +++ b/SYSCTRL/DRCDecomposer.h @@ -0,0 +1,85 @@ +/* + * DRCDecomposer.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/BaseComponent.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + + +#ifndef SYSCTRL_DRCDECOMPOSER_H_ +#define SYSCTRL_DRCDECOMPOSER_H_ + +namespace SYSCTRL +{ + + +struct DRCDecomposerStructure +{ + float direct; + float quadrature; + void reset() + { + direct = FP_ZERO; + quadrature = FP_ZERO; + } + DRCDecomposerStructure(): + direct(FP_ZERO), + quadrature(FP_ZERO) + {} +};//DRCDecomposerStructure + +struct DRCDecomposerConfiguration +{ + FLTSYSLIB::FilterConfiguration filter; + //FLTSYSLIB::FilterSecondConfiguration filter; + DRCDecomposerConfiguration(): + filter() + {} +};//DRCDecomposerConfiguration + +class DRCDecomposer +{ +private: + float m_time_sample; +private: + FLTSYSLIB::Filter m_filter_direct; + FLTSYSLIB::Filter m_filter_quadrature; + //FLTSYSLIB::FilterSecond m_filter_direct; + //FLTSYSLIB::FilterSecond m_filter_quadrature; +private: + float _aux_reg; +public: + float direct; + float quadrature; +public: + DRCDecomposer(); + void setup(float time_sample); + void configure(const DRCDecomposerConfiguration& config); +public: + void reset(); + void get_outputs(float& d, float& q); +public: + void execute(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c); +private: + void (DRCDecomposer::*_execute)(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c); + void _execute_undef(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c); + void _execute_operational(float in_a, float in_b, float in_c, + float ort_direct_a, float ort_direct_b, float ort_direct_c, + float ort_orthogonal_a, float ort_orthogonal_b, float ort_orthogonal_c); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_DRCDECOMPOSER_H_ */ diff --git a/SYSCTRL/FanControl.cpp b/SYSCTRL/FanControl.cpp new file mode 100644 index 0000000..1e8867e --- /dev/null +++ b/SYSCTRL/FanControl.cpp @@ -0,0 +1,199 @@ +/* + * FanControl.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/FanControl.h" + + +#define KM11_TURN_OFF (Uint16)0 +#define KM11_TURN_ON (Uint16)1 + +namespace SYSCTRL +{ +//CONSTRUCTOR +FanControl::FanControl(): + m_mode(SYSCTRL::FanControl::UNDEFINED), + m_time_sample(-1.0), + m_contact_bounce_period(FP_ZERO), + m_voltage_level_on(FP_ZERO), + m_voltage_level_off(FP_ZERO), + m_km11_control(0), + m_km11t_control(0), + m_fan_state(false), + m_fault(false), + m_voltage_relay(), + m_delay_off_timer(), + m_control_state_timer(), + _execute(&SYSCTRL::FanControl::_execute_undef) +// +{}//CONSTRUCTOR + + + +void FanControl::setup(float time_sample) +{ + static bool status = true; + if(m_mode == SYSCTRL::FanControl::UNDEFINED) + { + m_time_sample = time_sample; + + m_delay_off_timer.setup(m_time_sample); + m_control_state_timer.setup(m_time_sample); + + status &= m_time_sample > FP_ZERO ? true : false; + status &= m_delay_off_timer.compare(FLTSYSLIB::FTimer::CONFIGURATE); + status &= m_control_state_timer.compare(FLTSYSLIB::FTimer::CONFIGURATE); + + if(status) + { + m_mode = SYSCTRL::FanControl::CONFIGURATE; + // + }//if + // + }//if + // +}//setup() +// +void FanControl::configure(const FanControlConfiguration& config) +{ + static bool status = true; + if(m_mode == SYSCTRL::FanControl::CONFIGURATE) + { + m_voltage_level_on = config.voltage_level_on; + m_voltage_level_off = config.voltage_level_off; + + FLTSYSLIB::HysteresisConfiguration hyst_config; + hyst_config.level_high = 1.0; + hyst_config.level_low = FP_ZERO; + hyst_config.off = m_voltage_level_off; + hyst_config.on = m_voltage_level_on; + m_voltage_relay.configure(hyst_config); + + FLTSYSLIB::FTimerConfiguration tm_config; + tm_config.period = config.delay_off_timer; + m_delay_off_timer.configure(tm_config); + tm_config.period = config.control_state_timer; + m_control_state_timer.configure(tm_config); + + status &= m_voltage_relay.compare(FLTSYSLIB::Hysteresis::OPERATIONAL); + status &= m_delay_off_timer.compare(FLTSYSLIB::FTimer::OPERATIONAL); + status &= m_control_state_timer.compare(FLTSYSLIB::FTimer::OPERATIONAL); + + if(status) + { + m_mode = SYSCTRL::FanControl::OPERATIONAL; + _execute = &SYSCTRL::FanControl::_execute_undef; + // + }//if + // + }//if + // +}//configure() +// +#pragma CODE_SECTION("ramfuncs"); +SYSCTRL::FanControl::mode_t FanControl::get_mode() +{ + return m_mode; + // +}//get_mode() +// +#pragma CODE_SECTION("ramfuncs"); +bool FanControl::compare(SYSCTRL::FanControl::mode_t mode) +{ + return m_mode == mode; + // +}//compare() +// +#pragma CODE_SECTION("ramfuncs"); +Uint16 FanControl::get_km11_control() +{ + return m_km11_control; + // +}//get_km11_control() +// +#pragma CODE_SECTION("ramfuncs"); +Uint16 FanControl::get_km11t_control() +{ + return m_km11t_control; + // +}//get_km11t_control() +// +#pragma CODE_SECTION("ramfuncs"); +bool FanControl::is_on() +{ + return m_fan_state; + // +}//is_on() +// +#pragma CODE_SECTION("ramfuncs"); +bool FanControl::is_off() +{ + return !m_fan_state; + // +}//is_off() +// +#pragma CODE_SECTION("ramfuncs"); +bool FanControl::is_fault() +{ + return m_fault; + // +}//get_fault() +// +#pragma CODE_SECTION("ramfuncs"); +void FanControl::execute(float voltage, FLTSYSLIB::DigitalInput& aux_km) +{ + (this->*_execute)(voltage, aux_km); + // +}//execute() +// +#pragma CODE_SECTION("ramfuncs"); +void FanControl::_execute_undef(float voltage, FLTSYSLIB::DigitalInput& aux_km) +{ + // +}//_execute_undef() +// +#pragma CODE_SECTION("ramfuncs"); +void FanControl::_execute_operational(float voltage, FLTSYSLIB::DigitalInput& aux_km) +{ + + m_fan_state = aux_km.is_on(); + m_voltage_relay.execute(voltage); + m_delay_off_timer.execute(); + m_control_state_timer.execute(); + + + if(m_voltage_relay.is_on()) + { + m_km11_control = KM11_TURN_ON; + m_km11t_control = KM11_TURN_OFF; + m_delay_off_timer.reset(); + } + else + { + if((m_delay_off_timer.is_running()) || (m_voltage_relay.is_switched_to_off())) + { + m_km11_control = KM11_TURN_OFF; + m_km11t_control = KM11_TURN_ON; + // + }//if + // + if(m_voltage_relay.is_switched_to_off()) + { + m_delay_off_timer.start(); + }//if + + if(m_delay_off_timer.is_finished()) + { + m_km11_control = KM11_TURN_OFF; + m_km11t_control = KM11_TURN_OFF; + // + }//if + // + }//if else + // +}//_execute_operational() +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/FanControl.h b/SYSCTRL/FanControl.h new file mode 100644 index 0000000..b5a1f81 --- /dev/null +++ b/SYSCTRL/FanControl.h @@ -0,0 +1,85 @@ +/* + * FanControl.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include +#include "DSP2833x_Device.h" + +#include "FLTSYSLIB/Hysteresis.h" +#include "FLTSYSLIB/DigitalInput.h" +#include "FLTSYSLIB/FTimer.h" +#include "FLTSYSLIB/Relay.h" + + +#ifndef SYSCTRL_FANCONTROL_H_ +#define SYSCTRL_FANCONTROL_H_ + +namespace SYSCTRL +{ + + +struct FanControlConfiguration +{ + float delay_off_timer; + float control_state_timer; + float voltage_level_on; + float voltage_level_off; + FanControlConfiguration(): + delay_off_timer(FP_ZERO), + control_state_timer(FP_ZERO), + voltage_level_on(FP_ZERO), + voltage_level_off(FP_ZERO) + {} + // +};//FanControlConfiguration + + + +class FanControl +{ +public: + enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; +private: + mode_t m_mode; +private: + float m_time_sample; + float m_contact_bounce_period; + float m_voltage_level_on; + float m_voltage_level_off; +private: + Uint16 m_km11_control; + Uint16 m_km11t_control; + bool m_fan_state;// false - is off, true - is on + bool m_fault; + FLTSYSLIB::Hysteresis m_voltage_relay; + FLTSYSLIB::FTimer m_delay_off_timer; + FLTSYSLIB::FTimer m_control_state_timer; +public: + FanControl(); + void setup(float time_sample); + void configure(const FanControlConfiguration& config); +public: + mode_t get_mode(); + bool compare(mode_t mode); +public: + Uint16 get_km11_control(); + Uint16 get_km11t_control(); + bool is_on(); + bool is_off(); + bool is_fault(); +public: + void execute(float voltage, FLTSYSLIB::DigitalInput& aux_km); +private: + void (FanControl::*_execute)(float voltage, FLTSYSLIB::DigitalInput& aux_km); + void _execute_undef(float voltage, FLTSYSLIB::DigitalInput& aux_km); + void _execute_operational(float voltage, FLTSYSLIB::DigitalInput& aux_km); + // +};//FanControl + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_FANCONTROL_H_ */ diff --git a/SYSCTRL/FanTimerControl.cpp b/SYSCTRL/FanTimerControl.cpp new file mode 100644 index 0000000..4155ad0 --- /dev/null +++ b/SYSCTRL/FanTimerControl.cpp @@ -0,0 +1,135 @@ +/* + * FanTimerControl.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/FanTimerControl.h" + +namespace SYSCTRL +{ + +FanTimerControl::FanTimerControl(): + m_mode(SYSCTRL::FanTimerControl::UNDEFINED), + m_time_sample(-1.0), + m_timer_counter(FP_ZERO), + m_timer_period(FP_ZERO), + m_state(false), + _execute(&SYSCTRL::FanTimerControl::_execute_undef) +{}// + + +void FanTimerControl::setup(float time_sample) +{ + if(m_mode == SYSCTRL::FanTimerControl::UNDEFINED) + { + if(time_sample >= FP_ZERO) + { + m_time_sample = time_sample; + m_mode = SYSCTRL::FanTimerControl::CONFIGURATE; + // + }//if + // + }//if + // +}// +// +void FanTimerControl::configure(const FanTimerControlConfiguration& config) +{ + if(compare(SYSCTRL::FanTimerControl::CONFIGURATE)) + { + if(config.timer_period > m_time_sample) + { + m_timer_period = config.timer_period; + m_timer_counter = config.timer_period; + m_mode = SYSCTRL::FanTimerControl::OPERATIONAL; + _execute = &SYSCTRL::FanTimerControl::_execute_operational; + // + }//if + // + }//if + // + // +}// +// +FanTimerControl::mode_t FanTimerControl::get_mode() +{ + return m_mode; + // +}// +// +bool FanTimerControl::compare(mode_t mode) +{ + return m_mode == mode; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool FanTimerControl::is_on() +{ + return m_state; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool FanTimerControl::is_off() +{ + return !m_state; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void FanTimerControl::execute(bool is_switched_on, bool is_switched_off) +{ + (this->*_execute)(is_switched_on, is_switched_off); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void FanTimerControl::_execute_undef(bool is_switched_on, bool is_switched_off) +{ + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void FanTimerControl::_execute_operational(bool is_switched_on, bool is_switched_off) +{ + if(m_state) + { + // is on + if(m_timer_counter >= FP_ZERO) + { + m_timer_counter -= m_time_sample; + } + else + { + m_state = false; + m_timer_counter = m_timer_period; + } + + } + else + { + // is off + if(is_switched_off) + { + m_state = true; + } + else + { + m_timer_counter = m_timer_period; + } + + } + // + if(is_switched_on) + { + m_state = false; + m_timer_counter = m_timer_period; + } + // +}// +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/FanTimerControl.h b/SYSCTRL/FanTimerControl.h new file mode 100644 index 0000000..19d602b --- /dev/null +++ b/SYSCTRL/FanTimerControl.h @@ -0,0 +1,62 @@ +/* + * FanTimerControl.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#ifndef SYSCTRL_FANTIMERCONTROL_H_ +#define SYSCTRL_FANTIMERCONTROL_H_ + +namespace SYSCTRL +{ + + +struct FanTimerControlConfiguration +{ + float timer_period; + FanTimerControlConfiguration(): + timer_period(-1.0) + {} + // +};//FanTimerControlConfiguration + + + +class FanTimerControl +{ +public: + enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; +private: + mode_t m_mode; +private: + float m_time_sample; +private: + float m_timer_counter; + float m_timer_period; + bool m_state; +public: + FanTimerControl(); + void setup(float time_sample); + void configure(const FanTimerControlConfiguration& config); +public: + mode_t get_mode(); + bool compare(mode_t mode); +public: + bool is_on(); + bool is_off(); +public: + void execute(bool is_switched_on, bool is_switched_off); +private: + void (FanTimerControl::*_execute)(bool is_switched_on, bool is_switched_off); + void _execute_undef(bool is_switched_on, bool is_switched_off); + void _execute_operational(bool is_switched_on, bool is_switched_off); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_FANTIMERCONTROL_H_ */ diff --git a/SYSCTRL/GeneratorSymmetricalComponents.cpp b/SYSCTRL/GeneratorSymmetricalComponents.cpp new file mode 100644 index 0000000..caef0f7 --- /dev/null +++ b/SYSCTRL/GeneratorSymmetricalComponents.cpp @@ -0,0 +1,81 @@ +/* + * GeneratorSymmetricalComponents.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/GeneratorSymmetricalComponents.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +GeneratorSymmetricalComponents::GeneratorSymmetricalComponents(): + m_amplitude(), + m_phase(), + m_ort_direct_alpha(FP_ZERO), + m_ort_direct_beta(FP_ZERO), + m_ort_inverse_alpha(FP_ZERO), + m_ort_inverse_beta(FP_ZERO), + m_direct_alpha(FP_ZERO), + m_direct_beta(FP_ZERO), + m_inverse_alpha(FP_ZERO), + m_inverse_beta(FP_ZERO), + m_direct_a(FP_ZERO), + m_direct_b(FP_ZERO), + m_direct_c(FP_ZERO), + m_inverse_a(FP_ZERO), + m_inverse_b(FP_ZERO), + m_inverse_c(FP_ZERO), + m_out_a(FP_ZERO), + m_out_b(FP_ZERO), + m_out_c(FP_ZERO) +// +{}//CONSTRUCTOR + + +#pragma CODE_SECTION("ramfuncs"); +void GeneratorSymmetricalComponents::configure(GeneratorSymmetricalComponentsConfiguration& config) +{ + m_amplitude = config.amplitude; + m_phase = config.phase; + // +}// + + +#pragma CODE_SECTION("ramfuncs"); +void GeneratorSymmetricalComponents::execute(float ort_alpha, float ort_beta) +{ + m_phase.direct.cos_phase = cosf(m_phase.direct.phase); + m_phase.direct.sin_phase = sinf(m_phase.direct.phase); + m_phase.inverse.cos_phase = cosf(m_phase.inverse.phase); + m_phase.inverse.sin_phase = sinf(m_phase.inverse.phase); + // + m_ort_direct_alpha = ort_alpha * m_phase.direct.cos_phase - ort_beta * m_phase.direct.sin_phase; + m_ort_direct_beta = ort_alpha * m_phase.direct.sin_phase + ort_beta * m_phase.direct.cos_phase; + // + m_ort_inverse_alpha = ort_alpha * m_phase.inverse.cos_phase + ort_beta * m_phase.inverse.sin_phase; + m_ort_inverse_beta = ort_alpha * m_phase.inverse.sin_phase - ort_beta * m_phase.inverse.cos_phase; + // + FLTSYSLIB::Transformation::park_inverse(m_ort_direct_alpha, m_ort_direct_beta, m_amplitude.direct.d, m_amplitude.direct.q, m_direct_alpha, m_direct_beta); + FLTSYSLIB::Transformation::park_inverse(m_ort_inverse_alpha, m_ort_inverse_beta, m_amplitude.inverse.d, m_amplitude.inverse.q, m_inverse_alpha, m_inverse_beta); + FLTSYSLIB::Transformation::clarke_inverse(m_direct_alpha, m_direct_beta, m_direct_a, m_direct_b, m_direct_c); + FLTSYSLIB::Transformation::clarke_inverse(m_inverse_alpha, m_inverse_beta, m_inverse_a, m_inverse_b, m_inverse_c); + // + m_out_a = m_direct_a + m_inverse_a + m_amplitude.zero_a; + m_out_b = m_direct_b + m_inverse_b + m_amplitude.zero_b; + m_out_c = m_direct_c + m_inverse_c + m_amplitude.zero_c; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void GeneratorSymmetricalComponents::get_output(float& out_a, float& out_b, float& out_c) +{ + out_a = m_out_a; + out_b = m_out_b; + out_c = m_out_c; + // +}// +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/GeneratorSymmetricalComponents.h b/SYSCTRL/GeneratorSymmetricalComponents.h new file mode 100644 index 0000000..d38fbe1 --- /dev/null +++ b/SYSCTRL/GeneratorSymmetricalComponents.h @@ -0,0 +1,123 @@ +/* + * GeneratorSymmetricalComponents.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef SYSCTRL_GENERATORSYMMETRICALCOMPONENTS_H_ +#define SYSCTRL_GENERATORSYMMETRICALCOMPONENTS_H_ + + +#include +#include + + +//#include "SYSCTRL/HeadersFLTSYSLIB.h" +#include "FLTSYSLIB/Transformation.h" + +namespace SYSCTRL +{ + + + +struct GeneratorPhase +{ + float phase; + float cos_phase; + float sin_phase; + GeneratorPhase(): + phase(FP_ZERO), + cos_phase(FP_ZERO), + sin_phase(FP_ZERO) + {} +};//GeneratorPhase + +struct GeneratorSymmetricalComponentsPhase +{ + GeneratorPhase direct; + GeneratorPhase inverse; + GeneratorSymmetricalComponentsPhase(): + direct(), + inverse() + {} +};//GeneratorSymmetricalComponentsPhase + + +struct GeneratorAmplitude +{ + float d; + float q; + GeneratorAmplitude(): + d(FP_ZERO), + q(FP_ZERO) + {} +};//GeneratorAmplitude + + +struct GeneratorSymmetricalComponentsAmplitude +{ + GeneratorAmplitude direct; + GeneratorAmplitude inverse; + float zero_a; + float zero_b; + float zero_c; + GeneratorSymmetricalComponentsAmplitude(): + direct(), + inverse(), + zero_a(FP_ZERO), + zero_b(FP_ZERO), + zero_c(FP_ZERO) + {} +};//GeneratorSymmetricalComponentsAmplitude + + +struct GeneratorSymmetricalComponentsConfiguration +{ + GeneratorSymmetricalComponentsAmplitude amplitude; + GeneratorSymmetricalComponentsPhase phase; + GeneratorSymmetricalComponentsConfiguration(): + amplitude(), + phase() + {} +};//GeneratorSymmetricalComponentsConfiguration + + +class GeneratorSymmetricalComponents +{ +private: + GeneratorSymmetricalComponentsAmplitude m_amplitude; + GeneratorSymmetricalComponentsPhase m_phase; +private: + float m_ort_direct_alpha; + float m_ort_direct_beta; + float m_ort_inverse_alpha; + float m_ort_inverse_beta; +private: + float m_direct_alpha; + float m_direct_beta; + float m_inverse_alpha; + float m_inverse_beta; +private: + float m_direct_a; + float m_direct_b; + float m_direct_c; + float m_inverse_a; + float m_inverse_b; + float m_inverse_c; +private: + float m_out_a; + float m_out_b; + float m_out_c; +public: + GeneratorSymmetricalComponents(); +public: + void configure(GeneratorSymmetricalComponentsConfiguration& config); +public: + void execute(float ort_alpha, float ort_beta); + void get_output(float& out_a, float& out_b, float& out_c); +};//GeneratorSymmetricalComponents + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_GENERATORSYMMETRICALCOMPONENTS_H_ */ diff --git a/SYSCTRL/HVCELL.cpp b/SYSCTRL/HVCELL.cpp new file mode 100644 index 0000000..d2ee67c --- /dev/null +++ b/SYSCTRL/HVCELL.cpp @@ -0,0 +1,243 @@ +/* + * CELL.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/HVCELL.h" + +namespace SYSCTRL +{ + +HVCELL::HVCELL(): + m_mode(SYSCTRL::HVCELL::UNDEFINED), + m_control_order(ORDER_STOP), + //m_switching_freq(SWITCHING_FREQ_2500), + m_cell_level(0), + m_cell_error(0), + m_pwm_version(), + m_cell_state(), + m_cell_dc_voltage(), + m_cell_version(), + m_cpu_cpld_version(0), + m_data_u(FP_ZERO), + m_data_v(FP_ZERO), + m_data_w(FP_ZERO), + // + m_dc_voltage_a(FP_ZERO), + m_dc_voltage_b(FP_ZERO), + m_dc_voltage_c(FP_ZERO), + // + m_fault_cell(false), + m_cell_error_fault(0), + m_cell_state_fault(), + // + p_send_syn_signal(&SYSCTRL::HVCELL::_empty), + p_send_control_order(&SYSCTRL::HVCELL::_empty), + p_set_cell_level(&SYSCTRL::HVCELL::_empty), + p_get_pwm_version(&SYSCTRL::HVCELL::_empty), + p_get_cell_state(&SYSCTRL::HVCELL::_empty), + p_get_cell_dc_voltage(&SYSCTRL::HVCELL::_empty), + p_get_cell_version(&SYSCTRL::HVCELL::_empty), + p_send_modulate_data(&SYSCTRL::HVCELL::_empty), + p_get_cpu_cpld_version(&SYSCTRL::HVCELL::_empty) +{} + + +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::configure(HVCELLConfiguration& config) +{ + static bool status = true; + if(m_mode == SYSCTRL::HVCELL::UNDEFINED) + { + + m_cell_level = config.cell_level; + //m_switching_freq = config.switching_freq; + + status &= (m_cell_level >= 1)&&(m_cell_level <= 8) ? true : false; + + if(status) + { + m_mode = SYSCTRL::HVCELL::OPERATIONAL; + // + p_send_syn_signal = &SYSCTRL::HVCELL::_send_syn_signal; + p_send_control_order = &SYSCTRL::HVCELL::_send_control_order; + p_set_cell_level = &SYSCTRL::HVCELL::_set_cell_level; + p_get_pwm_version = &SYSCTRL::HVCELL::_get_pwm_version; + p_get_cell_state = &SYSCTRL::HVCELL::_get_cell_state; + p_get_cell_dc_voltage = &SYSCTRL::HVCELL::_get_cell_dc_voltage; + p_get_cell_version = &SYSCTRL::HVCELL::_get_cell_version; + p_send_modulate_data = &SYSCTRL::HVCELL::_send_modulate_data; + p_get_cpu_cpld_version = &SYSCTRL::HVCELL::_get_cpu_cpld_version; + // + }//if + // + }//if + // +}//configure() +// +#pragma CODE_SECTION("ramfuncs"); +SYSCTRL::HVCELL::mode_t HVCELL::get_mode() +{ + return m_mode; + // +}//get_mode() +// +#pragma CODE_SECTION("ramfuncs"); +bool HVCELL::compare(SYSCTRL::HVCELL::mode_t mode) +{ + return m_mode == mode; + // +}//compare() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::send_syn_signal() +{ + (this->*p_send_syn_signal)(); + // +}//send_syn_signal() +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_send_syn_signal() +{ + sendSynSignal(); + // +}//_send_syn_signal() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::send_control_order() +{ + (this->*p_send_control_order)(); + // +}//send_control_order_start() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_send_control_order() +{ + sendControlOrder(m_control_order); + // +}//_send_control_order() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::set_cell_level() +{ + (this->*p_set_cell_level)(); + // +}//set_cell_level() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_set_cell_level() +{ + //m_cell_error = setCellLevel(m_cell_level, m_switching_freq); + m_cell_error = setCellLevel(m_cell_level); + // +}//_set_cell_level() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::get_pwm_version() +{ + (this->*p_get_pwm_version)(); + // +}//get_pwm_version() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_get_pwm_version() +{ + getPwmVersion(m_pwm_version); + // +}//_get_pwm_version() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::get_cell_state() +{ + (this->*p_get_cell_state)(); + // +}//get_cell_state() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_get_cell_state() +{ + getCellState(m_cell_level, m_cell_state); + // +}//_get_cell_state() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::get_cell_dc_voltage() +{ + (this->*p_get_cell_dc_voltage)(); + // +}//get_cell_dc_voltage() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_get_cell_dc_voltage() +{ + static float aux_a, aux_b, aux_c; + + getCellDCVoltage(m_cell_level, m_cell_dc_voltage); + + aux_a = FP_ZERO; + aux_b = FP_ZERO; + aux_c = FP_ZERO; + // + for(Uint16 cellnum = 0; cellnum < m_cell_level; cellnum++) + { + aux_a += m_cell_dc_voltage[0][cellnum]; + aux_b += m_cell_dc_voltage[1][cellnum]; + aux_c += m_cell_dc_voltage[2][cellnum]; + // + }//for + // + m_dc_voltage_a = aux_a; + m_dc_voltage_b = aux_b; + m_dc_voltage_c = aux_c; + // +}//_get_cell_dc_voltage() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::get_cell_version() +{ + (this->*p_get_cell_version)(); + // +}//get_cell_version() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_get_cell_version() +{ + getCellVersion(m_cell_level, m_cell_version); + // +}//get_cell_version() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::send_modulate_data() +{ + (this->*p_send_modulate_data)(); + // +}//send_modulate_data() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_send_modulate_data() +{ + //sendModulateData(m_data_u, m_data_v, m_data_w, m_switching_freq); + sendModulateData(m_data_u, m_data_v, m_data_w); + // +}//_send_modulate_data() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::get_cpu_cpld_version() +{ + (this->*p_get_cpu_cpld_version)(); + // +}//get_cpu_cpld_version() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_get_cpu_cpld_version() +{ + m_cpu_cpld_version = getCpuCpldVersion(); + // +}//_get_cpu_cpld_version() +// +#pragma CODE_SECTION("ramfuncs"); +void HVCELL::_empty() +{}//_empty() +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/HVCELL.h b/SYSCTRL/HVCELL.h new file mode 100644 index 0000000..ae3b0a7 --- /dev/null +++ b/SYSCTRL/HVCELL.h @@ -0,0 +1,100 @@ +/* + * HVCELL.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "framework.h" +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" + + +#ifndef SYSCTRL_HVCELL_H_ +#define SYSCTRL_HVCELL_H_ + +namespace SYSCTRL +{ + +struct HVCELLConfiguration +{ + Uint16 cell_level; + //UnitSwitchingFreq switching_freq; + HVCELLConfiguration(): + cell_level(0) + //switching_freq(SWITCHING_FREQ_2500) + {} +};//HVCELLConfiguration + + +class HVCELL +{ +public: + enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; +private: + mode_t m_mode; +private: + ControlOrder m_control_order; + //UnitSwitchingFreq m_switching_freq; + Uint16 m_cell_level; + Uint16 m_cell_error; + Uint16 m_pwm_version[3]; + CellState m_cell_state[3][13]; + float m_cell_dc_voltage[3][13]; + Uint16 m_cell_version[3][13]; + Uint32 m_cpu_cpld_version; + float m_data_u; + float m_data_v; + float m_data_w; +private: + float m_dc_voltage_a; + float m_dc_voltage_b; + float m_dc_voltage_c; + bool m_fault_cell; + Uint16 m_cell_error_fault; + CellState m_cell_state_fault[3][13]; + +public: + HVCELL(); + void configure(HVCELLConfiguration& config); + mode_t get_mode(); + bool compare(mode_t mode); +public: + void send_syn_signal(); + void send_control_order(); + void set_cell_level(); + void get_pwm_version(); + void get_cell_state(); + void get_cell_dc_voltage(); + void get_cell_version(); + void send_modulate_data(); + void get_cpu_cpld_version(); +private: + void (HVCELL::*p_send_syn_signal)(); + void _send_syn_signal(); + void (HVCELL::*p_send_control_order)(); + void _send_control_order(); + void (HVCELL::*p_set_cell_level)(); + void _set_cell_level(); + void (HVCELL::*p_get_pwm_version)(); + void _get_pwm_version(); + void (HVCELL::*p_get_cell_state)(); + void _get_cell_state(); + void (HVCELL::*p_get_cell_dc_voltage)(); + void _get_cell_dc_voltage(); + void (HVCELL::*p_get_cell_version)(); + void _get_cell_version(); + void (HVCELL::*p_send_modulate_data)(); + void _send_modulate_data(); + void (HVCELL::*p_get_cpu_cpld_version)(); + void _get_cpu_cpld_version(); + void _empty(); + // +};//class HVCELL + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_HVCELL_H_ */ diff --git a/SYSCTRL/HardWare.cpp b/SYSCTRL/HardWare.cpp new file mode 100644 index 0000000..4923e61 --- /dev/null +++ b/SYSCTRL/HardWare.cpp @@ -0,0 +1,238 @@ +/* + * HardWare.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/HardWare.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +HardWare::HardWare(): + enable(true), + fault(false), + fault_low_level(false), + level((Uint16)0), + error((Uint16)0), + //switching_freq(SWITCHING_FREQ_2500), + dc_voltage_low_level(500.0), + control_order_cell(ORDER_STOP), + ref_control_order(ORDER_STOP), + pwm_version(), + cpu_cpld_version((Uint32)0), + hvcell(), + disable_hw(), + disable_a_cells(), + disable_b_cells(), + disable_c_cells(), + version_default() +{ + + for(Uint16 phase = 0; phase < 3; phase++) + { + for(Uint16 cellnum = 0; cellnum < 13; cellnum++) + { + hvcell.dc_voltage[phase][cellnum] = FP_ZERO; + hvcell.state[phase][cellnum].all = 0; + hvcell.version[phase][cellnum] = 0; + // + }//for + // + }//for + // +}//CONSTRUCTOR + + +void HardWare::configure(const HardWareConfiguration config) +{ + //switching_freq = config.switching_freq; + level = config.cell_level; + version_default = config.version; + disable_hw.all = (uint16_t)0; + disable_a_cells.all = (uint32_t)0; + disable_b_cells.all = (uint32_t)0; + disable_c_cells.all = (uint32_t)0; + // +}// + +#pragma CODE_SECTION("ramfuncs"); +void HardWare::check_status() +{ + if(cpu_cpld_version != version_default.cpu_cpld) + { + disable_hw.bits.cpu_cpld = 1; + } + else + { + disable_hw.bits.cpu_cpld = 0; + // + }//if else + // + if(pwm_version[0] != version_default.pwm) + { + disable_hw.bits.pwm_a = 1; + } + else + { + disable_hw.bits.pwm_a = 0; + // + }//if else + // + if(pwm_version[1] != version_default.pwm) + { + disable_hw.bits.pwm_b = 1; + } + else + { + disable_hw.bits.pwm_b = 0; + // + }//if else + // + if(pwm_version[2] != version_default.pwm) + { + disable_hw.bits.pwm_c = 1; + } + else + { + disable_hw.bits.pwm_c = 0; + // + }//if else + + static uint32_t mask = (uint32_t)0; + static uint32_t auxreg_0 = (uint32_t)0; + static uint32_t auxreg_1 = (uint32_t)0; + static uint32_t auxreg_2 = (uint32_t)0; + auxreg_0 = (uint32_t)0; + auxreg_1 = (uint32_t)0; + auxreg_2 = (uint32_t)0; + for(Uint16 cellnum = 0; cellnum < level; cellnum++) + { + mask = (uint32_t)0; + if(hvcell.version[0][cellnum] != version_default.cell) + { + mask = (uint32_t)0; + mask = 1 << (cellnum); + auxreg_0 |= mask; + } + else + { + mask = (uint32_t)0; + mask = 1 << (cellnum); + mask = (uint32_t)((uint32_t)0xFFFFFFFF ^ (uint32_t)mask); + auxreg_0 &= mask; + // + }//if + // + mask = (uint32_t)0; + if(hvcell.version[1][cellnum] != version_default.cell) + { + mask = 1 << (cellnum); + auxreg_1 |= mask; + } + else + { + mask = 1 << (cellnum); + mask = (uint32_t)((uint32_t)0xFFFFFFFF ^ (uint32_t)mask); + auxreg_1 &= mask; + // + }//if + // + mask = (uint32_t)0; + if(hvcell.version[2][cellnum] != version_default.cell) + { + mask = 1 << (cellnum); + auxreg_2 |= mask; + } + else + { + mask = 1 << (cellnum); + mask = (uint32_t)((uint32_t)0xFFFFFFFF ^ (uint32_t)mask); + auxreg_2 &= mask; + // + }//if + // + }//for + // + disable_a_cells.all = (uint32_t)auxreg_0; + disable_c_cells.all = (uint32_t)auxreg_1; + disable_b_cells.all = (uint32_t)auxreg_2; + // + static bool tmp_enable = true; + tmp_enable = true; +// tmp_enable &= disable_hw.all == 0 ? true : false; +// tmp_enable &= disable_a_cells.all == 0 ? true : false; +// tmp_enable &= disable_b_cells.all == 0 ? true : false; +// tmp_enable &= disable_c_cells.all == 0 ? true : false; + enable = tmp_enable; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool HardWare::is_enable() +{ + // + return enable; + // +}// +#pragma CODE_SECTION("ramfuncs"); +void HardWare::check_faults(mode_fault_t fmode) +{ + + for(Uint16 cellnum = 0; cellnum < level; cellnum++) + { + for(Uint16 phasenum = 0; phasenum < 3; phasenum++) + { + + if(SYSCTRL::HardWare::COMPLETE == fmode) + { + if(((Uint16)(MASK_CELL_STATE_FAULTS & hvcell.state[phasenum][cellnum].all)) != (Uint16)0) + { + fault = true; + // + }// + } + else + { + if(((Uint16)(MASK_CELL_STATE_FAULTS_SHORT & hvcell.state[phasenum][cellnum].all)) != (Uint16)0) + { + fault = true; + // + }// + } + + if(((Uint16)(MASK_CELL_LOW_LEVEL & hvcell.state[phasenum][cellnum].all)) != (Uint16)0) + { + fault_low_level = true; + } + + // + };//for + // + }//for + // +}// +#pragma CODE_SECTION("ramfuncs"); +bool HardWare::is_fault() +{ + return fault; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool HardWare::low_level() +{ + return fault_low_level; + // +}// + +#pragma CODE_SECTION("ramfuncs"); +void HardWare::reset() +{ + fault = false; + fault_low_level = false; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/HardWare.h b/SYSCTRL/HardWare.h new file mode 100644 index 0000000..493c640 --- /dev/null +++ b/SYSCTRL/HardWare.h @@ -0,0 +1,194 @@ +/* + * HardWare.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "framework.h" +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" + + +#ifndef SYSCTRL_HARDWARE_H_ +#define SYSCTRL_HARDWARE_H_ + + +namespace SYSCTRL +{ + + +#define MASK_CELL_STATE_DOWN_COMM (Uint16)0x0001 +#define MASK_CELL_STATE_UP_COMM (Uint16)0x0002 +#define MASK_CELL_STATE_RESERVED_1 (Uint16)0x0004 +#define MASK_CELL_STATE_RUNNING (Uint16)0x0008 +// +#define MASK_CELL_STATE_IGBT4_FAULT (Uint16)0x0010 +#define MASK_CELL_STATE_IGBT3_FAULT (Uint16)0x0020 +#define MASK_CELL_STATE_IGBT2_FAULT (Uint16)0x0040 +#define MASK_CELL_STATE_IGBT1_FAULT (Uint16)0x0080 +// +#define MASK_CELL_STATE_RESERVED_2 (Uint16)0x0100 +#define MASK_CELL_STATE_TEMP_OVER (Uint16)0x0200 +#define MASK_CELL_STATE_UNDER_VOLTAGE (Uint16)0x0400 +#define MASK_CELL_STATE_OVER_VOLTAGE (Uint16)0x0800 +// +#define MASK_CELL_STATE_RESERVED_3 (Uint16)0x0F800 + +#define MASK_CELL_STATE_FAULTS (Uint16)(MASK_CELL_STATE_DOWN_COMM |\ + MASK_CELL_STATE_UP_COMM |\ + MASK_CELL_STATE_IGBT4_FAULT |\ + MASK_CELL_STATE_IGBT3_FAULT |\ + MASK_CELL_STATE_IGBT2_FAULT |\ + MASK_CELL_STATE_IGBT1_FAULT |\ + MASK_CELL_STATE_TEMP_OVER |\ + MASK_CELL_STATE_UNDER_VOLTAGE |\ + MASK_CELL_STATE_OVER_VOLTAGE) + +#define MASK_CELL_STATE_FAULTS_SHORT (Uint16)(MASK_CELL_STATE_IGBT4_FAULT |\ + MASK_CELL_STATE_IGBT3_FAULT |\ + MASK_CELL_STATE_IGBT2_FAULT |\ + MASK_CELL_STATE_IGBT1_FAULT |\ + MASK_CELL_STATE_TEMP_OVER |\ + MASK_CELL_STATE_OVER_VOLTAGE) + +#define MASK_CELL_LOW_LEVEL (Uint16)(MASK_CELL_STATE_DOWN_COMM |\ + MASK_CELL_STATE_UP_COMM |\ + MASK_CELL_STATE_UNDER_VOLTAGE) + + +struct HardWareVersion +{ + uint16_t pwm; + uint16_t cell; + uint32_t cpu_cpld; + HardWareVersion(): + pwm(uint16_t(0)), + cell(uint16_t(0)), + cpu_cpld(uint32_t(0)) + {} +};//HardWareVersion + + +struct HardWareConfiguration +{ + uint16_t cell_level; + //UnitSwitchingFreq switching_freq; + SYSCTRL::HardWareVersion version; + HardWareConfiguration(): + cell_level(0), + //switching_freq(SWITCHING_FREQ_2500), + version() + {} +};//HardWareConfiguration + + +struct Cell +{ + CellState state[3][13]; + float dc_voltage[3][13]; + uint16_t version[3][13]; + float data_u; + float data_v; + float data_w; + Cell(): + state(), + dc_voltage(), + version(), + data_u(FP_ZERO), + data_v(FP_ZERO), + data_w(FP_ZERO) + {} +};//Cell + + +struct HVCellDisableBit +{ + uint32_t cell_1: 1; + uint32_t cell_2: 1; + uint32_t cell_3: 1; + uint32_t cell_4: 1; + uint32_t cell_5: 1; + uint32_t cell_6: 1; + uint32_t cell_7: 1; + uint32_t cell_8: 1; + uint32_t cell_9: 1; + uint32_t cell_10: 1; + uint32_t cell_11: 1; + uint32_t cell_12: 1; + uint32_t cell_13: 1; + uint32_t cell_14: 1; + uint32_t cell_15: 1; + uint32_t cell_16: 1; + uint32_t cell_17: 1; + uint32_t cell_18: 1; +};//HVCellDisableBit + +union HVCellDisableRegister +{ + uint32_t all; + HVCellDisableBit bits; + HVCellDisableRegister(): + all((uint32_t)0) + {} +};//HVCellDisableRegister + +struct HardWareDisableBit +{ + uint16_t cpu_cpld: 1; + uint16_t pwm_a: 1; + uint16_t pwm_b: 1; + uint16_t pwm_c: 1; +};//HardWareDisableBit + +union HardWareDisableRegister +{ + uint16_t all; + HardWareDisableBit bits; + HardWareDisableRegister(): + all((uint16_t)0) + {} +};//HardWareDisable + + +class HardWare +{ +public: + enum mode_fault_t {SHORT, COMPLETE}; +public: + bool enable; + bool fault; + bool fault_low_level; + //UnitSwitchingFreq switching_freq; + float dc_voltage_low_level; + uint16_t level; + uint16_t error; + ControlOrder control_order_cell; + ControlOrder ref_control_order; + uint16_t pwm_version[3]; + uint32_t cpu_cpld_version; + Cell hvcell; + HardWareDisableRegister disable_hw; + HVCellDisableRegister disable_a_cells; + HVCellDisableRegister disable_b_cells; + HVCellDisableRegister disable_c_cells; + HardWareVersion version_default; +public: + HardWare(); + void configure(const HardWareConfiguration config); + void check_status(); + void check_faults(mode_fault_t fmode); + bool is_enable(); + bool is_fault(); + bool low_level(); + void reset(); + // +};//class HardWare + + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_HARDWARE_H_ */ diff --git a/SYSCTRL/Hardcode.cpp b/SYSCTRL/Hardcode.cpp new file mode 100644 index 0000000..c973d42 --- /dev/null +++ b/SYSCTRL/Hardcode.cpp @@ -0,0 +1,358 @@ +/* + * Hardcode.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SystemControl.h" + +namespace SYSCTRL +{ + +void SystemControl::get_hard_code_setup() +{ + m_system_setup.time_sample_control = 400.0e-6; + m_system_setup.time_prescale_slow = 5; + m_system_setup.time_prescale_additional = 1; + + + // + // Relative + // + m_system_setup.relative_voltage_input.time_sample = m_system_setup.time_sample_control; + + // +}//hard_code_setup() +// +void SystemControl::upload_configuration() +{ + m_fram_db.upload_configuration(&m_system_configuration); + //m_system_configuration.selfupdata(); + // +}// +// +void SystemControl::get_hard_code_configuration() +{ + + // + // References + // + m_system_configuration.reference_current_limit_rms = 100.0; + m_system_configuration.reference_current_pfc_rms = 0.0; + m_system_configuration.reference_voltage_rms = 240.0; + m_system_configuration.reference_voltage_dc = 900.0; + + m_system_configuration.algorithm_control.signal.enable_current_limit = true; + m_system_configuration.algorithm_control.signal.enable_pfc = false; + m_system_configuration.algorithm_control.signal.enable_harmonica = false; + m_system_configuration.algorithm_control.signal.enable_auto_offset = true; + + + // + // High Voltage Cell + // + //m_system_configuration.hardware.switching_freq = SWITCHING_FREQ_2500; + m_system_configuration.hardware.cell_level = 1; + m_system_configuration.hardware.version.pwm = 210; + m_system_configuration.hardware.version.cell = 211; + m_system_configuration.hardware.version.cpu_cpld = 202; + // + + m_system_configuration.minimal_input_voltage_level = 10.0; + + // + // Scale Analog Signals + // + m_system_configuration.scale_voltage_input_a = 0.0227386411;//0.0233486816; + m_system_configuration.scale_voltage_input_b = 0.0227597337;//0.0234651081; + m_system_configuration.scale_voltage_input_c = 0.02278281;//0.0236082859; + // + m_system_configuration.scale_current_input_a = 0.00666328007; + m_system_configuration.scale_current_input_b = 0.00667025521; + m_system_configuration.scale_current_input_c = 0.00665952405; + // + m_system_configuration.scale_current_cell_a = 0.0123311505;//0.00665648002; + m_system_configuration.scale_current_cell_b = 0.0123670474;//0.00667640707; + m_system_configuration.scale_current_cell_c = 0.0124070868;//0.00666095456; + // + m_system_configuration.scale_voltage_load_a = 0.0227408651;//0.0232194811; + m_system_configuration.scale_voltage_load_b = 0.0227707103;//0.0233941432; + m_system_configuration.scale_voltage_load_c = 0.0229060184;//0.0234934501; + // + m_system_configuration.scale_current_load_a = 0.00622544903;//0.00668919506; + m_system_configuration.scale_current_load_b = 0.00623486936;//0.00669770781; + m_system_configuration.scale_current_load_c = 0.00624710508;//0.00670575583; + // + m_system_configuration.scale_current_bypass_a = 0.0063; + m_system_configuration.scale_current_bypass_b = 0.0063; + m_system_configuration.scale_current_bypass_c = 0.0063; + + + // + // Amplitude Filter Parameters + // + m_system_configuration.ampl_filter_current.time = 20.0e-3; + m_system_configuration.ampl_filter_current.a3 = 3.0; + m_system_configuration.ampl_filter_current.a2 = 4.25; + m_system_configuration.ampl_filter_current.a1 = 3.0; + + // + // RMS Filter Parameters + // + m_system_configuration.rms_filter_analog_signal.time = 10.0e-3; + m_system_configuration.rms_filter_analog_signal.a3 = 3.0; + m_system_configuration.rms_filter_analog_signal.a2 = 4.25; + m_system_configuration.rms_filter_analog_signal.a1 = 3.0; + + + // + // Zero Drift Current Input + // + m_system_configuration.zero_filter.time = 1333.0e-3; + + + // + // Cell DC Voltage Filter + // + m_system_configuration.cell_dc_voltage_filter.time = 3.0e-3; + m_system_configuration.cell_dc_voltage_filter.a3 = 3.0; + m_system_configuration.cell_dc_voltage_filter.a2 = 4.25; + m_system_configuration.cell_dc_voltage_filter.a1 = 3.0; + + + // + // Signal Decompose + // + m_system_configuration.signal_decompose.projection_filter.time = 10.0e-3; + m_system_configuration.signal_decompose.projection_filter.a3 = 2.61313;//3.0; + m_system_configuration.signal_decompose.projection_filter.a2 = 3.41422;//4.25; + m_system_configuration.signal_decompose.projection_filter.a1 = 2.61313;//3.0; + + + // + // Relative + // + m_system_configuration.relative_voltage_input.minimal_amplitude_level = 0.1; + m_system_configuration.relative_voltage_input.limit_relative_high = 1.1; + m_system_configuration.relative_voltage_input.limit_relative_low = -1.1; + m_system_configuration.relative_voltage_input.amplitude_filter.time = (float)(1.0/2.0/FP_PI/10.0); + m_system_configuration.relative_voltage_input.amplitude_filter.a3 = 3.0; + m_system_configuration.relative_voltage_input.amplitude_filter.a2 = 4.25; + m_system_configuration.relative_voltage_input.amplitude_filter.a1 = 3.0; + + + + + // + // Voltage PLL-ABC Parameters + // +#define PLLABC_FREQUENCY_NOMINAL (float)(2.0*FP_PI*50.0) +#define PLLABC_FREQUENCY_CUT (float)(2.0*FP_PI*10.0) +#define PLLABC_FREQUENCY_LIMIT_HI PLLABC_FREQUENCY_CUT +#define PLLABC_FREQUENCY_LIMIT_LOW -PLLABC_FREQUENCY_CUT + m_system_configuration.pll_abc_input_voltage.frequency_nominal = PLLABC_FREQUENCY_NOMINAL; + m_system_configuration.pll_abc_input_voltage.filter.time = 1.0/PLLABC_FREQUENCY_CUT; + m_system_configuration.pll_abc_input_voltage.controller.gain = PLLABC_FREQUENCY_CUT/2.0; + m_system_configuration.pll_abc_input_voltage.controller.time = 4.0/PLLABC_FREQUENCY_CUT; + m_system_configuration.pll_abc_input_voltage.controller.low_saturation = PLLABC_FREQUENCY_LIMIT_LOW; + m_system_configuration.pll_abc_input_voltage.controller.high_saturation = PLLABC_FREQUENCY_LIMIT_HI; + m_system_configuration.pll_abc_input_voltage.position.time = 1.0; + m_system_configuration.pll_abc_input_voltage.position.low_saturation = FP_ZERO; + m_system_configuration.pll_abc_input_voltage.position.high_saturation = 2.0 * FP_PI; + + + + // + // System Alarm + // + // exceed voltage level 1 + m_system_configuration.phase_alert_monitor.voltage_exceed_level_1.level = 264.5;//253.0; + m_system_configuration.phase_alert_monitor.voltage_exceed_level_1.period = 10.0; + // + // exceed voltage level 2 + m_system_configuration.phase_alert_monitor.voltage_exceed_level_2.level = 276.0;//264.5; + m_system_configuration.phase_alert_monitor.voltage_exceed_level_2.period = 5.0; + // + // exceed voltage level 3 + m_system_configuration.phase_alert_monitor.voltage_exceed_level_3.level = 290.0;//276.0; + m_system_configuration.phase_alert_monitor.voltage_exceed_level_3.period = 2.0; + // + // exceed voltage level 4 + m_system_configuration.phase_alert_monitor.voltage_exceed_level_4.level = 345.0; + m_system_configuration.phase_alert_monitor.voltage_exceed_level_4.period = 0.001;//1.0; + // + // decrease voltage level 1 + m_system_configuration.phase_alert_monitor.voltage_decrease_level_1.level = 200.0;//218.5;//195.5; + m_system_configuration.phase_alert_monitor.voltage_decrease_level_1.period = 10.0; + // + // decrease voltage level 2 + m_system_configuration.phase_alert_monitor.voltage_decrease_level_2.level = 170.0;//207.0;//172.5; + m_system_configuration.phase_alert_monitor.voltage_decrease_level_2.period = 5.0; + // + // decrease voltage level 3 + m_system_configuration.phase_alert_monitor.voltage_decrease_level_3.level = 149.5; + m_system_configuration.phase_alert_monitor.voltage_decrease_level_3.period = 2.0; + // + // current overload level 1 120% 60s + m_system_configuration.phase_alert_monitor.current_overload_level_1.level = 3.0 * 14.4; + m_system_configuration.phase_alert_monitor.current_overload_level_1.period = 60.0; + // + // current overload level 2 130% 10s + m_system_configuration.phase_alert_monitor.current_overload_level_2.level = 3.0 * 15.6; + m_system_configuration.phase_alert_monitor.current_overload_level_2.period = 10.0; + // + // current overload level 3 150% 1ms + m_system_configuration.phase_alert_monitor.current_overload_level_3.level = 3.0 * 18.0; + m_system_configuration.phase_alert_monitor.current_overload_level_3.period = 0.001; + // + // current invertor overload level 1 110% 60s + m_system_configuration.phase_alert_monitor.current_invertor_overload_level_1.level = 13.2; + m_system_configuration.phase_alert_monitor.current_invertor_overload_level_1.period = 60.0; + // + // current invertor overload level 2 130% 10s + m_system_configuration.phase_alert_monitor.current_invertor_overload_level_2.level = 15.6; + m_system_configuration.phase_alert_monitor.current_invertor_overload_level_2.period = 10.0; + // + // current invertor overload level 3 150% 1ms + m_system_configuration.phase_alert_monitor.current_invertor_overload_level_3.level = 18.0; + m_system_configuration.phase_alert_monitor.current_invertor_overload_level_3.period = 0.001; + + + // + //DIGITAL INPUTS + // + m_system_configuration.digital_input_config.period = 200.0e-3; //3001 - 3020 + + // + // FAN CONTROL + // + m_system_configuration.fan_control.timer_period = 5.0*60.0; + + + // + // Generator ABC + // + m_system_configuration.generator_abc.amplitude = 1.0; + m_system_configuration.generator_abc.frequency = 2.0*FP_PI*50.0; + m_system_configuration.generator_abc.phase_shift = 0.0; + + + // + // Reference PWM-Generator + // + //m_system_configuration.generator_pwm.frequency = 2.0*FP_PI*1.0; + //m_system_configuration.generator_abc.phase_shift = 0.0; + + //m_system_configuration.gen_inp_volt.amplitude.direct.d = 220.0; + // + //m_system_configuration.gen_out_volt.amplitude.direct.d = 220.0; + //m_system_configuration.gen_out_volt.phase.direct.phase = 0.122756;//FP_PI/4.0; + // + //m_system_configuration.gen_out_current.amplitude.direct.d = 50.0; + //m_system_configuration.gen_out_current.phase.direct.phase = 0.122756;//FP_PI/3.0; + + + // + // Harmonica Analyzer + // + m_system_configuration.ph_harmonica_5.time = 50.0e-3; + m_system_configuration.ph_harmonica_5.a3 = 3.0; + m_system_configuration.ph_harmonica_5.a2 = 4.25; + m_system_configuration.ph_harmonica_5.a1 = 3.0; + + + + // + // Reference Intensity Idref Iqref in Start Mode + // + m_system_configuration.intensity_id_iq_references.damp_factor = 0.7071; + m_system_configuration.intensity_id_iq_references.time = 20.0e-3; + + + // + // Regulators + // +#if TYPECONTROL == VECTORCONTROL + // + m_system_configuration.regulator_voltage_load_dq.gain = 0.25; + m_system_configuration.regulator_voltage_load_dq.time = 40.0e-3; + m_system_configuration.regulator_voltage_load_dq.high_saturation = 950.0; + m_system_configuration.regulator_voltage_load_dq.low_saturation = -950.0; + // + //m_system_configuration. = 1.0; + m_system_configuration.integrator_voltage_dq.time = 1.0; + m_system_configuration.integrator_voltage_dq.high_saturation = 1.0;; + m_system_configuration.integrator_voltage_dq.low_saturation = -1.0; + // + //m_system_configuration. = 1.0; + //m_system_configuration. = 1.0; + //m_system_configuration. = 1.0; + //m_system_configuration. = -1.0; + // + m_system_configuration.regulator_current_load_dq.gain = 1.0; +// m_system_configuration.regulator_current_load_dq.time = 0.016; + m_system_configuration.regulator_current_load_dq.high_saturation = 200.0; + m_system_configuration.regulator_current_load_dq.low_saturation = -200.0; + // + //m_system_configuration. = 1.0; + //m_system_configuration. = 0.016; + //m_system_configuration. = 200.0; + //m_system_configuration. = -200.0; + // + //m_system_configuration. = 1.0; + m_system_configuration.referencer_current_bypass_dq.time = 0.016; + m_system_configuration.referencer_current_bypass_dq.high_saturation = 200.0; + m_system_configuration.referencer_current_bypass_dq.low_saturation = -200.0; + // +#endif + +#if TYPECONTROL == SCALARCONTROL + // + m_system_configuration.regulator_voltage_load_active_reactive.gain = 0.25; + m_system_configuration.regulator_voltage_load_active_reactive.time = 40.0e-3; + m_system_configuration.regulator_voltage_load_active_reactive.high_saturation = 950.0; + m_system_configuration.regulator_voltage_load_active_reactive.low_saturation = -950.0; + // + m_system_configuration.regulator_current_limit.gain = 1.0; + m_system_configuration.regulator_current_limit.time = 1.0; + m_system_configuration.regulator_current_limit.high_saturation = 1.0;; + m_system_configuration.regulator_current_limit.low_saturation = -1.0; + // + m_system_configuration.regulator_current_pfc.gain = 1.0; + m_system_configuration.regulator_current_pfc.time = 1.0; + m_system_configuration.regulator_current_pfc.high_saturation = 1.0; + m_system_configuration.regulator_current_pfc.low_saturation = -1.0; + // + m_system_configuration.current_regulator_active.gain = 1.0; + m_system_configuration.current_regulator_active.time = 0.016; + m_system_configuration.current_regulator_active.high_saturation = 200.0; + m_system_configuration.current_regulator_active.low_saturation = -200.0; + // + m_system_configuration.current_regulator_reactive.gain = 1.0; + m_system_configuration.current_regulator_reactive.time = 0.016; + m_system_configuration.current_regulator_reactive.high_saturation = 200.0; + m_system_configuration.current_regulator_reactive.low_saturation = -200.0; + // + m_system_configuration.current_referencer.gain = 1.0; + m_system_configuration.current_referencer.time = 0.016; + m_system_configuration.current_referencer.high_saturation = 200.0; + m_system_configuration.current_referencer.low_saturation = -200.0; + // +#endif + //<> + + + // + // Timers + // + m_system_configuration.timer_start.period = 2.0; + m_system_configuration.timer_stop.period = 2.0; + + + + // +}//hard_code_configuration() +// +} /* namespace SYSCTRL */ + diff --git a/SYSCTRL/HeadersFLTSYSLIB.h b/SYSCTRL/HeadersFLTSYSLIB.h new file mode 100644 index 0000000..e2cff68 --- /dev/null +++ b/SYSCTRL/HeadersFLTSYSLIB.h @@ -0,0 +1,48 @@ +/* + * FLTSYSLIBheaders.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef FLTSYSLIB_FLTSYSLIBHEADERS_H_ +#define FLTSYSLIB_FLTSYSLIBHEADERS_H_ + +#include "FLTSYSLIB/AMPL.h" +#include "FLTSYSLIB/AMPLFSO.h" +#include "FLTSYSLIB/AMPLF4O.h" +#include "FLTSYSLIB/Contactor.h" +#include "FLTSYSLIB/DigitalInput.h" +#include "FLTSYSLIB/DigitalInputAntiNoise.h" +#include "FLTSYSLIB/DiscreteInput.h" +#include "FLTSYSLIB/DiscreteOutput.h" +#include "FLTSYSLIB/Filter.h" +#include "FLTSYSLIB/FilterSecond.h" +#include "FLTSYSLIB/FilterForth.h" +#include "FLTSYSLIB/FilterThird.h" +#include "FLTSYSLIB/FTimer.h" +#include "FLTSYSLIB/GeneratorABC.h" +#include "FLTSYSLIB/HarmonicaFilter4Order.h" +#include "FLTSYSLIB/HarmonicaFilterBase.h" +#include "FLTSYSLIB/Hysteresis.h" +#include "FLTSYSLIB/IController.h" +#include "FLTSYSLIB/Integrator.h" +#include "FLTSYSLIB/PController.h" +#include "FLTSYSLIB/PIController.h" +#include "FLTSYSLIB/PLLABC.h" +#include "FLTSYSLIB/PLLABCDVR.h" +#include "FLTSYSLIB/PLLABCreduced.h" +#include "FLTSYSLIB/PLLEQEP.h" +#include "FLTSYSLIB/Position.h" +#include "FLTSYSLIB/Relay.h" +#include "FLTSYSLIB/RMS.h" +#include "FLTSYSLIB/RMSF4O.h" +#include "FLTSYSLIB/RMSFFO.h" +#include "FLTSYSLIB/RMSFSO.h" +#include "FLTSYSLIB/Transformation.h" +#include "FLTSYSLIB/UNIPWM.h" +#include "FLTSYSLIB/ZeroDriftSecond.h" + + + +#endif /* FLTSYSLIB_FLTSYSLIBHEADERS_H_ */ diff --git a/SYSCTRL/HeadersMODBUSRTU.h b/SYSCTRL/HeadersMODBUSRTU.h new file mode 100644 index 0000000..c964261 --- /dev/null +++ b/SYSCTRL/HeadersMODBUSRTU.h @@ -0,0 +1,18 @@ +/* + * HeadersMODBUSRTU.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef SYSCTRL_HEADERSMODBUSRTU_H_ +#define SYSCTRL_HEADERSMODBUSRTU_H_ + +#include "MODBUSRTU/RUBUS.h" +#include "MODBUSRTU/RUBUSCOPE.h" +#include "MODBUSRTU/RUBUSDataBase.h" +#include "MODBUSRTU/RUBUSRegister.h" +#include "MODBUSRTU/RUBUSTypes.h" + + +#endif /* SYSCTRL_HEADERSMODBUSRTU_H_ */ diff --git a/SYSCTRL/MeasureTimeInterval.cpp b/SYSCTRL/MeasureTimeInterval.cpp new file mode 100644 index 0000000..ac3ebc8 --- /dev/null +++ b/SYSCTRL/MeasureTimeInterval.cpp @@ -0,0 +1,59 @@ +/* + * TimeStartStop.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/MeasureTimeInterval.h" + +namespace SYSCTRL +{ + +//Constructor +MeasureTimeInterval::MeasureTimeInterval(CPUTIMER_VARS& CPUTimer, Uint32 magic): + m_CPUTimer(CPUTimer), + m_timer_result((Uint32)0), + m_timer_result_previous((Uint32)0), + m_magic_number((Uint32)magic), + m_period((Uint32)0), + m_tim((Uint32)0), + m_counter((Uint32)0) +{}//end Constructor + +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimeInterval::start(void) +{ + m_CPUTimer.RegsAddr->TCR.bit.TSS = 1; // Stop CPU Timer + m_CPUTimer.RegsAddr->TCR.bit.TRB = 1; // Reload CPU Timer + m_CPUTimer.RegsAddr->TCR.bit.TSS = 0; // Start CPU Timer + // +}//end + +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimeInterval::stop(void) +{ + m_CPUTimer.RegsAddr->TCR.bit.TSS = 1; // Stop CPU Timer + // + m_timer_result_previous = m_timer_result; + m_period = (Uint32)m_CPUTimer.RegsAddr->PRD.all; + m_tim = (Uint32)m_CPUTimer.RegsAddr->TIM.all; + //m_timer_result = m_CPUTimer.RegsAddr->PRD.all - m_CPUTimer.RegsAddr->TIM.all - m_magic_number; + m_timer_result = (Uint32)((Uint32)m_period - (Uint32)m_tim - (Uint32)m_magic_number); + m_counter++; + // +}//end + +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimeInterval::reset(void) +{ + m_CPUTimer.RegsAddr->TCR.bit.TSS = 1; // Stop CPU Timer + m_CPUTimer.RegsAddr->PRD.all = 0xFFFFFFFF; + m_CPUTimer.RegsAddr->TCR.bit.TRB = 1; // Reload CPU Timer + // +}//end + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/MeasureTimeInterval.h b/SYSCTRL/MeasureTimeInterval.h new file mode 100644 index 0000000..5990a25 --- /dev/null +++ b/SYSCTRL/MeasureTimeInterval.h @@ -0,0 +1,38 @@ +/* + * TimeStartStop.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" + +#ifndef SYSCTRL_TIMEINTERVAL_H_ +#define SYSCTRL_TIMEINTERVAL_H_ + +namespace SYSCTRL +{ + +class MeasureTimeInterval +{ +private: + CPUTIMER_VARS& m_CPUTimer; + Uint32 m_timer_result; + Uint32 m_timer_result_previous; + Uint32 m_magic_number; + Uint32 m_period; + Uint32 m_tim; + Uint32 m_counter; +public: + MeasureTimeInterval(CPUTIMER_VARS& CPUTimer, Uint32 magic); +public: + void start(void); + void stop(void); + void reset(void); + // +};//end class MeasureTimeStartStop + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_TIMEINTERVAL_H_ */ diff --git a/SYSCTRL/MeasureTimePeriod.cpp b/SYSCTRL/MeasureTimePeriod.cpp new file mode 100644 index 0000000..a883516 --- /dev/null +++ b/SYSCTRL/MeasureTimePeriod.cpp @@ -0,0 +1,79 @@ +/* + * MeasureTimePeriod.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/MeasureTimePeriod.h" + +namespace SYSCTRL +{ + +//Constructor +MeasureTimePeriod::MeasureTimePeriod(CPUTIMER_REGS& CPUTimer, Uint32 magic): + m_CPUTimer(CPUTimer), + m_timer_result((Uint32)0), + m_timer_result_previous((Uint32)0), + m_magic_number((Uint32)magic), + m_period((Uint32)0), + m_tim((Uint32)0), + m_counter((Uint32)0), + _execute(&SYSCTRL::MeasureTimePeriod::_execute_start) +// +{}//end Constructor + +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimePeriod::execute(void) +{ + (this->*_execute)(); + // +}//end +// +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimePeriod::reset(void) +{ + m_CPUTimer.TCR.bit.TSS = 1; // Stop CPU Timer + m_CPUTimer.PRD.all = (Uint32)0xFFFFFFFF; + m_CPUTimer.TCR.bit.TRB = 1; // Reload CPU Timer + // + _execute = &SYSCTRL::MeasureTimePeriod::_execute_start; + // +}//end +// +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimePeriod::_execute_start(void) +{ + _execute = &SYSCTRL::MeasureTimePeriod::_execute_scan; + // + m_CPUTimer.TCR.bit.TSS = 1; // Stop CPU Timer + m_CPUTimer.TCR.bit.TRB = 1; // Reload CPU Timer + m_CPUTimer.TCR.bit.TSS = 0; // Start CPU Timer + // + + // +}//end +// +//#pragma CODE_SECTION(".TI.ramfunc"); +#pragma CODE_SECTION("ramfuncs"); +void MeasureTimePeriod::_execute_scan(void) +{ + m_CPUTimer.TCR.bit.TSS = 1; // Stop CPU Timer + // + m_timer_result_previous = (Uint32)m_timer_result; + m_period = (Uint32)m_CPUTimer.PRD.all; + m_tim = (Uint32)m_CPUTimer.TIM.all; + m_timer_result = (Uint32)((Uint32)m_CPUTimer.PRD.all - (Uint32)m_CPUTimer.TIM.all - (Uint32)m_magic_number); + // + m_CPUTimer.TCR.bit.TRB = 1; // Reload CPU Timer + m_CPUTimer.TCR.bit.TSS = 0; // Start CPU Timer + // + m_counter++; + // +}//end +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/MeasureTimePeriod.h b/SYSCTRL/MeasureTimePeriod.h new file mode 100644 index 0000000..84056ba --- /dev/null +++ b/SYSCTRL/MeasureTimePeriod.h @@ -0,0 +1,41 @@ +/* + * MeasureTimePeriod.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" + +#ifndef SYSCTRL_MEASURETIMEPERIOD_H_ +#define SYSCTRL_MEASURETIMEPERIOD_H_ + +namespace SYSCTRL +{ + +class MeasureTimePeriod +{ +private: + CPUTIMER_REGS& m_CPUTimer; + //CPUTIMER_VARS& m_CPUTimer; + Uint32 m_timer_result; + Uint32 m_timer_result_previous; + Uint32 m_magic_number; + Uint32 m_period; + Uint32 m_tim; + Uint32 m_counter; +public: + MeasureTimePeriod(CPUTIMER_REGS& pCPUTimer, Uint32 magic); + void execute(void); + void reset(void); +private: + void (MeasureTimePeriod::*_execute)(void); + void _execute_start(void); + void _execute_scan(void); + // +};//end class MeasureTimePeriod + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_MEASURETIMEPERIOD_H_ */ diff --git a/SYSCTRL/MonitorDigitalInputSignal.cpp b/SYSCTRL/MonitorDigitalInputSignal.cpp new file mode 100644 index 0000000..be8e5ee --- /dev/null +++ b/SYSCTRL/MonitorDigitalInputSignal.cpp @@ -0,0 +1,49 @@ +/* + * MonitorDigitalInputSignal.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/MonitorDigitalInputSignal.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +MonitorDigitalInputSignal::MonitorDigitalInputSignal() +{}//CONSTRUCTOR + +// +#pragma CODE_SECTION("ramfuncs"); +void MonitorDigitalInputSignal::implement(bool input, MonitorDigitalInputSignalRegister& state) +{ + state.signal.privious = state.signal.state; + state.signal.state = input; + state.signal.is_on = state.signal.state; + state.signal.is_off = !state.signal.state; + state.signal.is_switched_on = state.signal.state & !state.signal.privious; + state.signal.is_switched_off = !state.signal.state & state.signal.privious; + // +}// + + +#pragma CODE_SECTION("ramfuncs"); +void MonitorDigitalInputSignal::preset(bool input, MonitorDigitalInputSignalRegister& state) +{ + state.signal.privious = input; + state.signal.state = input; + state.signal.is_on = input; + state.signal.is_off = !input; + state.signal.is_switched_on = !state.signal.state & state.signal.privious; + state.signal.is_switched_off = state.signal.state & !state.signal.privious; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void MonitorDigitalInputSignal::reset(MonitorDigitalInputSignalRegister& state) +{ + state.all = 0x0008; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/MonitorDigitalInputSignal.h b/SYSCTRL/MonitorDigitalInputSignal.h new file mode 100644 index 0000000..9e3777b --- /dev/null +++ b/SYSCTRL/MonitorDigitalInputSignal.h @@ -0,0 +1,57 @@ +/* + * MonitorDigitalInputSignal.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/SystemDefinitions.h" + +#ifndef SYSCTRL_MONITORDIGITALINPUTSIGNAL_H_ +#define SYSCTRL_MONITORDIGITALINPUTSIGNAL_H_ + +namespace SYSCTRL +{ + + +struct MonitorDigitalInputSignalBitFiled +{ + uint16_t state:1; + uint16_t privious:1; + uint16_t is_on:1; + uint16_t is_off:1; + uint16_t is_switched_on:1; + uint16_t is_switched_off:1; + // +};// + +union MonitorDigitalInputSignalRegister +{ + uint16_t all; + Register16BitField bit; + MonitorDigitalInputSignalBitFiled signal; + MonitorDigitalInputSignalRegister(): + all(uint16_t(0)) + {} + MonitorDigitalInputSignalRegister(uint16_t val): + all(val) + {} +};//MonitorDigitalInputSignalRegister + +class MonitorDigitalInputSignal +{ +public: + MonitorDigitalInputSignal(); +public: + static void implement(bool input, MonitorDigitalInputSignalRegister& state); + static void preset(bool input, MonitorDigitalInputSignalRegister& state); + static void reset(MonitorDigitalInputSignalRegister& state); + // +};//MonitorDigitalInputSignal + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_MONITORDIGITALINPUTSIGNAL_H_ */ diff --git a/SYSCTRL/PhaseAlertMonitor.cpp b/SYSCTRL/PhaseAlertMonitor.cpp new file mode 100644 index 0000000..e06c050 --- /dev/null +++ b/SYSCTRL/PhaseAlertMonitor.cpp @@ -0,0 +1,430 @@ +/* + * PhaseAlertMonitor.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/PhaseAlertMonitor.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +PhaseAlertMonitor::PhaseAlertMonitor(): + m_time_sample(-1.0), + m_fault(false), + m_warning(false), + m_monitor(), + status(), + fault(false), + warning(false), + m_voltage_ab_exceed_level_1(), + m_voltage_bc_exceed_level_1(), + m_voltage_ca_exceed_level_1(), + m_voltage_ab_exceed_level_2(), + m_voltage_bc_exceed_level_2(), + m_voltage_ca_exceed_level_2(), + m_voltage_ab_exceed_level_3(), + m_voltage_bc_exceed_level_3(), + m_voltage_ca_exceed_level_3(), + m_voltage_ab_exceed_level_4(), + m_voltage_bc_exceed_level_4(), + m_voltage_ca_exceed_level_4(), + m_voltage_ab_decrease_level_1(), + m_voltage_bc_decrease_level_1(), + m_voltage_ca_decrease_level_1(), + m_voltage_ab_decrease_level_2(), + m_voltage_bc_decrease_level_2(), + m_voltage_ca_decrease_level_2(), + m_voltage_ab_decrease_level_3(), + m_voltage_bc_decrease_level_3(), + m_voltage_ca_decrease_level_3(), + m_current_a_overload_level_1(), + m_current_b_overload_level_1(), + m_current_c_overload_level_1(), + m_current_a_overload_level_2(), + m_current_b_overload_level_2(), + m_current_c_overload_level_2(), + m_current_a_overload_level_3(), + m_current_b_overload_level_3(), + m_current_c_overload_level_3(), + // + m_current_invertor_a_overload_level_1(), + m_current_invertor_b_overload_level_1(), + m_current_invertor_c_overload_level_1(), + m_current_invertor_a_overload_level_2(), + m_current_invertor_b_overload_level_2(), + m_current_invertor_c_overload_level_2(), + m_current_invertor_a_overload_level_3(), + m_current_invertor_b_overload_level_3(), + m_current_invertor_c_overload_level_3(), + // + m_current_input_a_overload_level_1(), + m_current_input_b_overload_level_1(), + m_current_input_c_overload_level_1(), + m_current_input_a_overload_level_2(), + m_current_input_b_overload_level_2(), + m_current_input_c_overload_level_2(), + m_current_input_a_overload_level_3(), + m_current_input_b_overload_level_3(), + m_current_input_c_overload_level_3(), + // + _execute(&SYSCTRL::PhaseAlertMonitor::_execute_undef) +// +{}//CONSTRUCTOR + + +void PhaseAlertMonitor::setup(float time_sample) +{ + m_time_sample = time_sample; + + m_voltage_ab_exceed_level_1.setup(m_time_sample); + m_voltage_bc_exceed_level_1.setup(m_time_sample); + m_voltage_ca_exceed_level_1.setup(m_time_sample); + m_voltage_ab_exceed_level_2.setup(m_time_sample); + m_voltage_bc_exceed_level_2.setup(m_time_sample); + m_voltage_ca_exceed_level_2.setup(m_time_sample); + m_voltage_ab_exceed_level_3.setup(m_time_sample); + m_voltage_bc_exceed_level_3.setup(m_time_sample); + m_voltage_ca_exceed_level_3.setup(m_time_sample); + m_voltage_ab_exceed_level_4.setup(m_time_sample); + m_voltage_bc_exceed_level_4.setup(m_time_sample); + m_voltage_ca_exceed_level_4.setup(m_time_sample); + m_voltage_ab_decrease_level_1.setup(m_time_sample); + m_voltage_bc_decrease_level_1.setup(m_time_sample); + m_voltage_ca_decrease_level_1.setup(m_time_sample); + m_voltage_ab_decrease_level_2.setup(m_time_sample); + m_voltage_bc_decrease_level_2.setup(m_time_sample); + m_voltage_ca_decrease_level_2.setup(m_time_sample); + m_voltage_ab_decrease_level_3.setup(m_time_sample); + m_voltage_bc_decrease_level_3.setup(m_time_sample); + m_voltage_ca_decrease_level_3.setup(m_time_sample); + m_current_a_overload_level_1.setup(m_time_sample); + m_current_b_overload_level_1.setup(m_time_sample); + m_current_c_overload_level_1.setup(m_time_sample); + m_current_a_overload_level_2.setup(m_time_sample); + m_current_b_overload_level_2.setup(m_time_sample); + m_current_c_overload_level_2.setup(m_time_sample); + m_current_a_overload_level_3.setup(m_time_sample); + m_current_b_overload_level_3.setup(m_time_sample); + m_current_c_overload_level_3.setup(m_time_sample); + m_current_invertor_a_overload_level_1.setup(m_time_sample); + m_current_invertor_b_overload_level_1.setup(m_time_sample); + m_current_invertor_c_overload_level_1.setup(m_time_sample); + m_current_invertor_a_overload_level_2.setup(m_time_sample); + m_current_invertor_b_overload_level_2.setup(m_time_sample); + m_current_invertor_c_overload_level_2.setup(m_time_sample); + m_current_invertor_a_overload_level_3.setup(m_time_sample); + m_current_invertor_b_overload_level_3.setup(m_time_sample); + m_current_invertor_c_overload_level_3.setup(m_time_sample); + + m_current_input_a_overload_level_1.setup(m_time_sample); + m_current_input_b_overload_level_1.setup(m_time_sample); + m_current_input_c_overload_level_1.setup(m_time_sample); + m_current_input_a_overload_level_2.setup(m_time_sample); + m_current_input_b_overload_level_2.setup(m_time_sample); + m_current_input_c_overload_level_2.setup(m_time_sample); + m_current_input_a_overload_level_3.setup(m_time_sample); + m_current_input_b_overload_level_3.setup(m_time_sample); + m_current_input_c_overload_level_3.setup(m_time_sample); + // +}//setup() +// +void PhaseAlertMonitor::configure(const PhaseAlertConfiguration& config) +{ + m_voltage_ab_exceed_level_1.configure(config.voltage_exceed_level_1); + m_voltage_bc_exceed_level_1.configure(config.voltage_exceed_level_1); + m_voltage_ca_exceed_level_1.configure(config.voltage_exceed_level_1); + m_voltage_ab_exceed_level_2.configure(config.voltage_exceed_level_2); + m_voltage_bc_exceed_level_2.configure(config.voltage_exceed_level_2); + m_voltage_ca_exceed_level_2.configure(config.voltage_exceed_level_2); + m_voltage_ab_exceed_level_3.configure(config.voltage_exceed_level_3); + m_voltage_bc_exceed_level_3.configure(config.voltage_exceed_level_3); + m_voltage_ca_exceed_level_3.configure(config.voltage_exceed_level_3); + m_voltage_ab_exceed_level_4.configure(config.voltage_exceed_level_4); + m_voltage_bc_exceed_level_4.configure(config.voltage_exceed_level_4); + m_voltage_ca_exceed_level_4.configure(config.voltage_exceed_level_4); + m_voltage_ab_decrease_level_1.configure(config.voltage_decrease_level_1); + m_voltage_bc_decrease_level_1.configure(config.voltage_decrease_level_1); + m_voltage_ca_decrease_level_1.configure(config.voltage_decrease_level_1); + m_voltage_ab_decrease_level_2.configure(config.voltage_decrease_level_2); + m_voltage_bc_decrease_level_2.configure(config.voltage_decrease_level_2); + m_voltage_ca_decrease_level_2.configure(config.voltage_decrease_level_2); + m_voltage_ab_decrease_level_3.configure(config.voltage_decrease_level_3); + m_voltage_bc_decrease_level_3.configure(config.voltage_decrease_level_3); + m_voltage_ca_decrease_level_3.configure(config.voltage_decrease_level_3); + m_current_a_overload_level_1.configure(config.current_overload_level_1); + m_current_b_overload_level_1.configure(config.current_overload_level_1); + m_current_c_overload_level_1.configure(config.current_overload_level_1); + m_current_a_overload_level_2.configure(config.current_overload_level_2); + m_current_b_overload_level_2.configure(config.current_overload_level_2); + m_current_c_overload_level_2.configure(config.current_overload_level_2); + m_current_a_overload_level_3.configure(config.current_overload_level_3); + m_current_b_overload_level_3.configure(config.current_overload_level_3); + m_current_c_overload_level_3.configure(config.current_overload_level_3); + // + m_current_invertor_a_overload_level_1.configure(config.current_invertor_overload_level_1); + m_current_invertor_b_overload_level_1.configure(config.current_invertor_overload_level_1); + m_current_invertor_c_overload_level_1.configure(config.current_invertor_overload_level_1); + m_current_invertor_a_overload_level_2.configure(config.current_invertor_overload_level_2); + m_current_invertor_b_overload_level_2.configure(config.current_invertor_overload_level_2); + m_current_invertor_c_overload_level_2.configure(config.current_invertor_overload_level_2); + m_current_invertor_a_overload_level_3.configure(config.current_invertor_overload_level_3); + m_current_invertor_b_overload_level_3.configure(config.current_invertor_overload_level_3); + m_current_invertor_c_overload_level_3.configure(config.current_invertor_overload_level_3); + // + m_current_input_a_overload_level_1.configure(config.current_input_overload_level_1); + m_current_input_b_overload_level_1.configure(config.current_input_overload_level_1); + m_current_input_c_overload_level_1.configure(config.current_input_overload_level_1); + m_current_input_a_overload_level_2.configure(config.current_input_overload_level_2); + m_current_input_b_overload_level_2.configure(config.current_input_overload_level_2); + m_current_input_c_overload_level_2.configure(config.current_input_overload_level_2); + m_current_input_a_overload_level_3.configure(config.current_input_overload_level_3); + m_current_input_b_overload_level_3.configure(config.current_input_overload_level_3); + m_current_input_c_overload_level_3.configure(config.current_input_overload_level_3); + + + if((m_time_sample > FP_ZERO)) + { + _execute = &SYSCTRL::PhaseAlertMonitor::_execute_operational; + // + }//if + // +}//configure() +// +#pragma CODE_SECTION("ramfuncs"); +void PhaseAlertMonitor::get_faults(PhaseFaultRegister& ph_a, PhaseFaultRegister& ph_b, PhaseFaultRegister& ph_c) +{ + ph_a.all = m_monitor.phase_a.fault.all; + ph_b.all = m_monitor.phase_b.fault.all; + ph_c.all = m_monitor.phase_c.fault.all; + // +}// +// +// +#pragma CODE_SECTION("ramfuncs"); +void PhaseAlertMonitor::reset() +{ + m_monitor.phase_a.warning.all = (uint16_t)0; + m_monitor.phase_a.fault.all = (uint16_t)0; + m_monitor.phase_b.warning.all = (uint16_t)0; + m_monitor.phase_b.fault.all = (uint16_t)0; + m_monitor.phase_c.warning.all = (uint16_t)0; + m_monitor.phase_c.fault.all = (uint16_t)0; + // + m_monitor.phase_a.warning.all = (uint16_t)0; + m_monitor.phase_a.fault.all = (uint16_t)0; + m_monitor.phase_b.warning.all = (uint16_t)0; + m_monitor.phase_b.fault.all = (uint16_t)0; + m_monitor.phase_c.warning.all = (uint16_t)0; + m_monitor.phase_c.fault.all = (uint16_t)0; + // + m_voltage_ab_exceed_level_1.reset(); + m_voltage_bc_exceed_level_1.reset(); + m_voltage_ca_exceed_level_1.reset(); + m_voltage_ab_exceed_level_2.reset(); + m_voltage_bc_exceed_level_2.reset(); + m_voltage_ca_exceed_level_2.reset(); + m_voltage_ab_exceed_level_3.reset(); + m_voltage_bc_exceed_level_3.reset(); + m_voltage_ca_exceed_level_3.reset(); + m_voltage_ab_exceed_level_4.reset(); + m_voltage_bc_exceed_level_4.reset(); + m_voltage_ca_exceed_level_4.reset(); + m_voltage_ab_decrease_level_1.reset(); + m_voltage_bc_decrease_level_1.reset(); + m_voltage_ca_decrease_level_1.reset(); + m_voltage_ab_decrease_level_2.reset(); + m_voltage_bc_decrease_level_2.reset(); + m_voltage_ca_decrease_level_2.reset(); + m_voltage_ab_decrease_level_3.reset(); + m_voltage_bc_decrease_level_3.reset(); + m_voltage_ca_decrease_level_3.reset(); + m_current_a_overload_level_1.reset(); + m_current_b_overload_level_1.reset(); + m_current_c_overload_level_1.reset(); + m_current_a_overload_level_2.reset(); + m_current_b_overload_level_2.reset(); + m_current_c_overload_level_2.reset(); + m_current_a_overload_level_3.reset(); + m_current_b_overload_level_3.reset(); + m_current_c_overload_level_3.reset(); + m_current_invertor_a_overload_level_1.reset(); + m_current_invertor_b_overload_level_1.reset(); + m_current_invertor_c_overload_level_1.reset(); + m_current_invertor_a_overload_level_2.reset(); + m_current_invertor_b_overload_level_2.reset(); + m_current_invertor_c_overload_level_2.reset(); + m_current_invertor_a_overload_level_3.reset(); + m_current_invertor_b_overload_level_3.reset(); + m_current_invertor_c_overload_level_3.reset(); + // + m_fault = false; + m_warning = false; + warning = m_warning; + fault = m_fault; + status = m_monitor; + // +}//reset() +// +#pragma CODE_SECTION("ramfuncs"); +void PhaseAlertMonitor::execute(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inprmsb, float inprmsc) +{ + (this->*_execute)(urmsa, urmsb, urmsc, irmsa, irmsb, irmsc, invrmsa, invrmsb, invrmsc, inprmsa, inprmsb, inprmsc); + // +}//execute() +// +#pragma CODE_SECTION("ramfuncs"); +void PhaseAlertMonitor::_execute_undef(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inprmsb, float inprmsc) +{ + // +}//_execute_undef() +// +#pragma CODE_SECTION("ramfuncs"); +void PhaseAlertMonitor::_execute_operational(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inprmsb, float inprmsc) +{ + static bool _warning = false; + _warning = false; + + m_monitor.phase_a.warning.all = (uint16_t)0; + m_monitor.phase_a.fault.all = (uint16_t)0; + m_monitor.phase_b.warning.all = (uint16_t)0; + m_monitor.phase_b.fault.all = (uint16_t)0; + m_monitor.phase_c.warning.all = (uint16_t)0; + m_monitor.phase_c.fault.all = (uint16_t)0; + // + m_voltage_ab_exceed_level_1.execute(urmsa); + m_voltage_bc_exceed_level_1.execute(urmsb); + m_voltage_ca_exceed_level_1.execute(urmsc); + + m_voltage_ab_exceed_level_2.execute(urmsa); + m_voltage_bc_exceed_level_2.execute(urmsb); + m_voltage_ca_exceed_level_2.execute(urmsc); + + m_voltage_ab_exceed_level_3.execute(urmsa); + m_voltage_bc_exceed_level_3.execute(urmsb); + m_voltage_ca_exceed_level_3.execute(urmsc); + + m_voltage_ab_exceed_level_4.execute(urmsa); + m_voltage_bc_exceed_level_4.execute(urmsb); + m_voltage_ca_exceed_level_4.execute(urmsc); +/* + m_voltage_a_decrease_level_1.execute(urmsa); + m_voltage_b_decrease_level_1.execute(urmsb); + m_voltage_c_decrease_level_1.execute(urmsc); + + m_voltage_a_decrease_level_2.execute(urmsa); + m_voltage_b_decrease_level_2.execute(urmsb); + m_voltage_c_decrease_level_2.execute(urmsc); + + m_voltage_a_decrease_level_3.execute(urmsa); + m_voltage_b_decrease_level_3.execute(urmsb); + m_voltage_c_decrease_level_3.execute(urmsc); +*/ + m_current_a_overload_level_1.execute(irmsa); + m_current_b_overload_level_1.execute(irmsb); + m_current_c_overload_level_1.execute(irmsc); + m_current_a_overload_level_2.execute(irmsa); + m_current_b_overload_level_2.execute(irmsb); + m_current_c_overload_level_2.execute(irmsc); + m_current_a_overload_level_3.execute(irmsa); + m_current_b_overload_level_3.execute(irmsb); + m_current_c_overload_level_3.execute(irmsc); + m_current_invertor_a_overload_level_1.execute(invrmsa); + m_current_invertor_b_overload_level_1.execute(invrmsb); + m_current_invertor_c_overload_level_1.execute(invrmsc); + m_current_invertor_a_overload_level_2.execute(invrmsa); + m_current_invertor_b_overload_level_2.execute(invrmsb); + m_current_invertor_c_overload_level_2.execute(invrmsc); + m_current_invertor_a_overload_level_3.execute(invrmsa); + m_current_invertor_b_overload_level_3.execute(invrmsb); + m_current_invertor_c_overload_level_3.execute(invrmsc); + // + m_current_input_a_overload_level_1.execute(inprmsa); + m_current_input_b_overload_level_1.execute(inprmsb); + m_current_input_c_overload_level_1.execute(inprmsc); + m_current_input_a_overload_level_2.execute(inprmsa); + m_current_input_b_overload_level_2.execute(inprmsb); + m_current_input_c_overload_level_2.execute(inprmsc); + m_current_input_a_overload_level_3.execute(inprmsa); + m_current_input_b_overload_level_3.execute(inprmsb); + m_current_input_c_overload_level_3.execute(inprmsc); + // + // set flags + m_monitor.phase_a.warning.bit.exceed_voltage_level_1 = m_voltage_ab_exceed_level_1.warning; + m_monitor.phase_a.warning.bit.exceed_voltage_level_2 = m_voltage_ab_exceed_level_2.warning; + m_monitor.phase_a.fault.bit.exceed_voltage_level_3 = m_voltage_ab_exceed_level_3.fault; + m_monitor.phase_a.fault.bit.exceed_voltage_level_4 = m_voltage_ab_exceed_level_4.fault; + m_monitor.phase_a.warning.bit.decrease_voltage_level_1 = m_voltage_ab_decrease_level_1.warning; + m_monitor.phase_a.warning.bit.decrease_voltage_level_2 = m_voltage_ab_decrease_level_2.warning; + m_monitor.phase_a.fault.bit.decrease_voltage_level_3 = m_voltage_ab_decrease_level_3.fault; + m_monitor.phase_a.fault.bit.overload_current_level_1 = m_current_a_overload_level_1.fault; + m_monitor.phase_a.fault.bit.overload_current_level_2 = m_current_a_overload_level_2.fault; + m_monitor.phase_a.fault.bit.overload_current_level_3 = m_current_a_overload_level_3.fault; + m_monitor.phase_a.fault.bit.overload_invertor_current_level_1 = m_current_invertor_a_overload_level_1.fault; + m_monitor.phase_a.fault.bit.overload_invertor_current_level_2 = m_current_invertor_a_overload_level_2.fault; + m_monitor.phase_a.fault.bit.overload_invertor_current_level_3 = m_current_invertor_a_overload_level_3.fault; + m_monitor.phase_a.fault.bit.overload_input_current_level_1 = m_current_input_a_overload_level_1.fault; + m_monitor.phase_a.fault.bit.overload_input_current_level_2 = m_current_input_a_overload_level_2.fault; + m_monitor.phase_a.fault.bit.overload_input_current_level_3 = m_current_input_a_overload_level_3.fault; + // + m_monitor.phase_b.warning.bit.exceed_voltage_level_1 = m_voltage_bc_exceed_level_1.warning; + m_monitor.phase_b.warning.bit.exceed_voltage_level_2 = m_voltage_bc_exceed_level_2.warning; + m_monitor.phase_b.fault.bit.exceed_voltage_level_3 = m_voltage_bc_exceed_level_3.fault; + m_monitor.phase_b.fault.bit.exceed_voltage_level_4 = m_voltage_bc_exceed_level_4.fault; + m_monitor.phase_b.warning.bit.decrease_voltage_level_1 = m_voltage_bc_decrease_level_1.warning; + m_monitor.phase_b.warning.bit.decrease_voltage_level_2 = m_voltage_bc_decrease_level_2.warning; + m_monitor.phase_b.fault.bit.decrease_voltage_level_3 = m_voltage_bc_decrease_level_3.fault; + m_monitor.phase_b.fault.bit.overload_current_level_1 = m_current_b_overload_level_1.fault; + m_monitor.phase_b.fault.bit.overload_current_level_2 = m_current_b_overload_level_2.fault; + m_monitor.phase_b.fault.bit.overload_current_level_3 = m_current_b_overload_level_3.fault; + m_monitor.phase_b.fault.bit.overload_invertor_current_level_1 = m_current_invertor_b_overload_level_1.fault; + m_monitor.phase_b.fault.bit.overload_invertor_current_level_2 = m_current_invertor_b_overload_level_2.fault; + m_monitor.phase_b.fault.bit.overload_invertor_current_level_3 = m_current_invertor_b_overload_level_3.fault; + m_monitor.phase_b.fault.bit.overload_input_current_level_1 = m_current_input_b_overload_level_1.fault; + m_monitor.phase_b.fault.bit.overload_input_current_level_2 = m_current_input_b_overload_level_2.fault; + m_monitor.phase_b.fault.bit.overload_input_current_level_3 = m_current_input_b_overload_level_3.fault; + // + m_monitor.phase_c.warning.bit.exceed_voltage_level_1 = m_voltage_ca_exceed_level_1.warning; + m_monitor.phase_c.warning.bit.exceed_voltage_level_2 = m_voltage_ca_exceed_level_2.warning; + m_monitor.phase_c.fault.bit.exceed_voltage_level_3 = m_voltage_ca_exceed_level_3.fault; + m_monitor.phase_c.fault.bit.exceed_voltage_level_4 = m_voltage_ca_exceed_level_4.fault; + m_monitor.phase_c.warning.bit.decrease_voltage_level_1 = m_voltage_ca_decrease_level_1.warning; + m_monitor.phase_c.warning.bit.decrease_voltage_level_2 = m_voltage_ca_decrease_level_2.warning; + m_monitor.phase_c.fault.bit.decrease_voltage_level_3 = m_voltage_ca_decrease_level_3.fault; + m_monitor.phase_c.fault.bit.overload_current_level_1 = m_current_c_overload_level_1.fault; + m_monitor.phase_c.fault.bit.overload_current_level_2 = m_current_c_overload_level_2.fault; + m_monitor.phase_c.fault.bit.overload_current_level_3 = m_current_c_overload_level_3.fault; + m_monitor.phase_c.fault.bit.overload_invertor_current_level_1 = m_current_invertor_c_overload_level_1.fault; + m_monitor.phase_c.fault.bit.overload_invertor_current_level_2 = m_current_invertor_c_overload_level_2.fault; + m_monitor.phase_c.fault.bit.overload_invertor_current_level_3 = m_current_invertor_c_overload_level_3.fault; + m_monitor.phase_c.fault.bit.overload_input_current_level_1 = m_current_input_c_overload_level_1.fault; + m_monitor.phase_c.fault.bit.overload_input_current_level_2 = m_current_input_c_overload_level_2.fault; + m_monitor.phase_c.fault.bit.overload_input_current_level_3 = m_current_input_c_overload_level_3.fault; + // + status = m_monitor; + // + if(m_monitor.phase_a.fault.all != (uint16_t)0){ m_fault = true;} + if(m_monitor.phase_b.fault.all != (uint16_t)0){ m_fault = true;} + if(m_monitor.phase_c.fault.all != (uint16_t)0){ m_fault = true;} + // + if(m_monitor.phase_a.warning.all != (uint16_t)0){ _warning = true;} + if(m_monitor.phase_b.warning.all != (uint16_t)0){ _warning = true;} + if(m_monitor.phase_c.warning.all != (uint16_t)0){ _warning = true;} + + m_warning = _warning; + warning = m_warning; + fault = m_fault; + // +}//_execute_operational() + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/PhaseAlertMonitor.h b/SYSCTRL/PhaseAlertMonitor.h new file mode 100644 index 0000000..1166086 --- /dev/null +++ b/SYSCTRL/PhaseAlertMonitor.h @@ -0,0 +1,242 @@ +/* + * PhaseAlertMonitor.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/ALERTHeaders.h" + +#ifndef SYSCTRL_PHASEALERTMONITOR_H_ +#define SYSCTRL_PHASEALERTMONITOR_H_ + +namespace SYSCTRL +{ + +struct PhaseAlertConfiguration +{ + ALERT::AlertBaseConfiguration voltage_exceed_level_1; + ALERT::AlertBaseConfiguration voltage_exceed_level_2; + ALERT::AlertBaseConfiguration voltage_exceed_level_3; + ALERT::AlertBaseConfiguration voltage_exceed_level_4; + ALERT::AlertBaseConfiguration voltage_decrease_level_1; + ALERT::AlertBaseConfiguration voltage_decrease_level_2; + ALERT::AlertBaseConfiguration voltage_decrease_level_3; + ALERT::AlertBaseConfiguration current_overload_level_1; + ALERT::AlertBaseConfiguration current_overload_level_2; + ALERT::AlertBaseConfiguration current_overload_level_3; + ALERT::AlertBaseConfiguration current_invertor_overload_level_1; + ALERT::AlertBaseConfiguration current_invertor_overload_level_2; + ALERT::AlertBaseConfiguration current_invertor_overload_level_3; + ALERT::AlertBaseConfiguration current_input_overload_level_1; + ALERT::AlertBaseConfiguration current_input_overload_level_2; + ALERT::AlertBaseConfiguration current_input_overload_level_3; + PhaseAlertConfiguration(): + voltage_exceed_level_1(), + voltage_exceed_level_2(), + voltage_exceed_level_3(), + voltage_exceed_level_4(), + voltage_decrease_level_1(), + voltage_decrease_level_2(), + voltage_decrease_level_3(), + current_overload_level_1(), + current_overload_level_2(), + current_overload_level_3(), + current_invertor_overload_level_1(), + current_invertor_overload_level_2(), + current_invertor_overload_level_3(), + current_input_overload_level_1(), + current_input_overload_level_2(), + current_input_overload_level_3() + {} + // +};//SystemAlertConfiguration + + +struct PhaseWarningBit +{ + uint16_t exceed_voltage_level_1 :1; + uint16_t exceed_voltage_level_2 :1; + uint16_t decrease_voltage_level_1 :1; + uint16_t decrease_voltage_level_2 :1; + // +};//PhaseWarningBit + +struct PhaseFaultBit +{ + uint16_t exceed_voltage_level_3 :1; // 0 + uint16_t exceed_voltage_level_4 :1; // 1 + uint16_t decrease_voltage_level_3 :1; // 2 + uint16_t phase_lost :1; // 3 + // + uint16_t short_circuit :1; // 4 + uint16_t high_current :1; // 5 + uint16_t overload_current_level_1 :1; // 6 + uint16_t overload_current_level_2 :1; // 7 + // + uint16_t overload_current_level_3 :1; // 8 + uint16_t overload_invertor_current_level_1 :1; // 9 + uint16_t overload_invertor_current_level_2 :1; // 10 + uint16_t overload_invertor_current_level_3 :1; // 11 + // + uint16_t overload_input_current_level_1 :1; // 12 + uint16_t overload_input_current_level_2 :1; // 13 + uint16_t overload_input_current_level_3 :1; // 14 + uint16_t reserved_15 :1; // 15 +};//PhaseFaultBit + +union PhaseWarningRegister +{ + uint16_t all; + struct PhaseWarningBit bit; + PhaseWarningRegister(): + all(uint16_t(0)) + {} + // +};//PhaseWarningRegister + +union PhaseFaultRegister +{ + uint16_t all; + struct PhaseFaultBit bit; + PhaseFaultRegister(): + all(uint16_t(0)) + {} +};//PhaseFaultRegister + +struct PhaseAlertStatusRegister +{ + union PhaseWarningRegister warning; + union PhaseFaultRegister fault; + PhaseAlertStatusRegister(): + warning(), + fault() + {} +};//PhaseAlertStatusRegister + + +struct PhaseAlertRegister +{ + struct PhaseAlertStatusRegister phase_a; + struct PhaseAlertStatusRegister phase_b; + struct PhaseAlertStatusRegister phase_c; + PhaseAlertRegister(): + phase_a(), + phase_b(), + phase_c() + {} + // +};//PhaseAlertRegister + + +class PhaseAlertMonitor +{ +private: + float m_time_sample; + bool m_fault; + bool m_warning; +private: + PhaseAlertRegister m_monitor; +public: + PhaseAlertRegister status; + bool fault; + bool warning; +private: + ALERT::WarningExceed m_voltage_ab_exceed_level_1; + ALERT::WarningExceed m_voltage_bc_exceed_level_1; + ALERT::WarningExceed m_voltage_ca_exceed_level_1; + // + ALERT::WarningExceed m_voltage_ab_exceed_level_2; + ALERT::WarningExceed m_voltage_bc_exceed_level_2; + ALERT::WarningExceed m_voltage_ca_exceed_level_2; + // + ALERT::FaultExceed m_voltage_ab_exceed_level_3; + ALERT::FaultExceed m_voltage_bc_exceed_level_3; + ALERT::FaultExceed m_voltage_ca_exceed_level_3; + // + ALERT::FaultExceed m_voltage_ab_exceed_level_4; + ALERT::FaultExceed m_voltage_bc_exceed_level_4; + ALERT::FaultExceed m_voltage_ca_exceed_level_4; + // + ALERT::WarningDecrease m_voltage_ab_decrease_level_1; + ALERT::WarningDecrease m_voltage_bc_decrease_level_1; + ALERT::WarningDecrease m_voltage_ca_decrease_level_1; + // + ALERT::WarningDecrease m_voltage_ab_decrease_level_2; + ALERT::WarningDecrease m_voltage_bc_decrease_level_2; + ALERT::WarningDecrease m_voltage_ca_decrease_level_2; + // + ALERT::FaultDecrease m_voltage_ab_decrease_level_3; + ALERT::FaultDecrease m_voltage_bc_decrease_level_3; + ALERT::FaultDecrease m_voltage_ca_decrease_level_3; + // + ALERT::FaultExceed m_current_a_overload_level_1; + ALERT::FaultExceed m_current_b_overload_level_1; + ALERT::FaultExceed m_current_c_overload_level_1; + // + ALERT::FaultExceed m_current_a_overload_level_2; + ALERT::FaultExceed m_current_b_overload_level_2; + ALERT::FaultExceed m_current_c_overload_level_2; + // + ALERT::FaultExceed m_current_a_overload_level_3; + ALERT::FaultExceed m_current_b_overload_level_3; + ALERT::FaultExceed m_current_c_overload_level_3; + // + ALERT::FaultExceed m_current_invertor_a_overload_level_1; + ALERT::FaultExceed m_current_invertor_b_overload_level_1; + ALERT::FaultExceed m_current_invertor_c_overload_level_1; + // + ALERT::FaultExceed m_current_invertor_a_overload_level_2; + ALERT::FaultExceed m_current_invertor_b_overload_level_2; + ALERT::FaultExceed m_current_invertor_c_overload_level_2; + // + ALERT::FaultExceed m_current_invertor_a_overload_level_3; + ALERT::FaultExceed m_current_invertor_b_overload_level_3; + ALERT::FaultExceed m_current_invertor_c_overload_level_3; + + ALERT::FaultExceed m_current_input_a_overload_level_1; + ALERT::FaultExceed m_current_input_b_overload_level_1; + ALERT::FaultExceed m_current_input_c_overload_level_1; + // + ALERT::FaultExceed m_current_input_a_overload_level_2; + ALERT::FaultExceed m_current_input_b_overload_level_2; + ALERT::FaultExceed m_current_input_c_overload_level_2; + // + ALERT::FaultExceed m_current_input_a_overload_level_3; + ALERT::FaultExceed m_current_input_b_overload_level_3; + ALERT::FaultExceed m_current_input_c_overload_level_3; +public: + PhaseAlertMonitor(); + void setup(float time_sample); + void configure(const PhaseAlertConfiguration& config); +public: + void get_faults(PhaseFaultRegister& ph_a, PhaseFaultRegister& ph_b, PhaseFaultRegister& ph_c); + void reset(); +public: + void execute(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inmrmsb, float inmrmsc); +private: + void (PhaseAlertMonitor::*_execute)(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inmrmsb, float inmrmsc); + void _execute_undef(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inmrmsb, float inmrmsc); + void _execute_operational(float urmsa, float urmsb, float urmsc, + float irmsa, float irmsb, float irmsc, + float invrmsa, float invrmsb, float invrmsc, + float inprmsa, float inmrmsb, float inmrmsc); +// +};//PhaseAlertMonitor + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_PHASEALERTMONITOR_H_ */ + diff --git a/SYSCTRL/RelativeAnalogSignalStructure.h b/SYSCTRL/RelativeAnalogSignalStructure.h new file mode 100644 index 0000000..29ab51b --- /dev/null +++ b/SYSCTRL/RelativeAnalogSignalStructure.h @@ -0,0 +1,49 @@ +/* + * AnalogSignalStructure.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#ifndef SYSCTRL_ANALOGSIGNALSTRUCTURE_H_ +#define SYSCTRL_ANALOGSIGNALSTRUCTURE_H_ + +namespace SYSCTRL +{ + + + +struct ProjectionAnalogSignalStructure +{ + float active; + float reactive; + ProjectionAnalogSignalStructure(): + active(FP_ZERO), + reactive(FP_ZERO) + {} +};//ProjectionAnalogSignalStructure + + +struct RelativeAnalogSignalStructure +{ + float amplitude; + float relative; + void reset() + { + amplitude = FP_ZERO; + relative = FP_ZERO; + } + RelativeAnalogSignalStructure(): + amplitude(FP_ZERO), + relative(FP_ZERO) + {} +};//AnalogSignalStructure + + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_ANALOGSIGNALSTRUCTURE_H_ */ diff --git a/SYSCTRL/SYSRestart.cpp b/SYSCTRL/SYSRestart.cpp new file mode 100644 index 0000000..1faed08 --- /dev/null +++ b/SYSCTRL/SYSRestart.cpp @@ -0,0 +1,663 @@ +/* + * SYSRestart.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SYSRestart.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +SYSRestart::SYSRestart(SYSCTRL::SystemEnvironment& env): + m_env(env), + m_mode(SYSCTRL::SYSRestart::UNDEFINED), + m_state(SYSCTRL::SYSRestart::EMPTY), + m_state_bit_field(), + m_time_sample(-1.0), + m_config(), + m_registers(), + status(), + _execute(&SYSCTRL::SYSRestart::_execute_undef), + _state_run(&SYSCTRL::SYSRestart::_state_empty) +// +{}//CONSTRUCTOR + +void SYSRestart::setup(float time_sample) +{ + if(m_mode == SYSCTRL::SYSRestart::UNDEFINED) + { + if(time_sample > FP_ZERO) + { + m_time_sample = time_sample; + m_mode = SYSCTRL::SYSRestart::CONFIGURATE; + // + }//if + // + }//if + // +}// +// +void SYSRestart::configure(SYSRestartConfiguration& config) +{ + bool _status = true; + + if(m_mode == SYSCTRL::SYSRestart::CONFIGURATE) + { + m_config = config; + + if((m_config.enable.equipment.all != (uint16_t)0)|| + (m_config.enable.phase_a.all != (uint16_t)0)|| + (m_config.enable.phase_b.all != (uint16_t)0)|| + (m_config.enable.phase_c.all != (uint16_t)0)) + { + _status &= m_config.period_timer_hold_fault > m_time_sample ? true : false; + _status &= m_config.period_timer_selfclear_attempts > m_time_sample ? true : false; + _status &= m_config.period_timer_turnon_switch > m_time_sample ? true : false; + _status &= m_config.attempts > 0 ? true : false; + }//if + // + m_registers.counter_attempts = 0; + m_registers.counter_timer = FP_ZERO; + m_registers.counter_timer_selfclear_attempts = FP_ZERO; + m_registers.status.all = 0; + // + if(_status) + { + m_mode = SYSCTRL::SYSRestart::OPERATIONAL; + _execute = &SYSCTRL::SYSRestart::_execute_operational; + + if((m_config.restart_enable.signal.enable)&& + ((m_config.enable.equipment.all != (uint16_t)0)|| + (m_config.enable.phase_a.all != (uint16_t)0)|| + (m_config.enable.phase_b.all != (uint16_t)0)|| + (m_config.enable.phase_c.all != (uint16_t)0))) + { + _state_run = &SYSCTRL::SYSRestart::_state_free; + m_state = SYSCTRL::SYSRestart::FREE; + } + else + { + _state_run = &SYSCTRL::SYSRestart::_state_empty; + m_state = SYSCTRL::SYSRestart::EMPTY; + // + }// if else + // + }//if + // + }//if + // +}// +// +SYSRestart::mode_t SYSRestart::get_mode() +{ + return m_mode; + // +}// +// +SYSRestart::state_t SYSRestart::get_state() +{ + return m_state; +}// +// +#pragma CODE_SECTION("ramfuncs"); +uint16_t SYSRestart::get_state_steps() +{ + return m_state_bit_field.all; + // +}// +// +uint16_t SYSRestart::get_attempts() +{ + return m_registers.counter_attempts; + // +}// +// +bool SYSRestart::compare(SYSCTRL::SYSRestart::mode_t mode) +{ + return mode == m_mode; + // +}// +// +bool SYSRestart::compare_state(SYSRestart::SYSRestart::state_t state) +{ + return state == m_state; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::execute() +{ + (this->*_execute)(); +}// +// +void SYSRestart::_execute_undef() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_execute_operational() +{ + + + if(m_config.restart_enable.signal.enable) + { + m_registers.status_fault_register.equipment.all = m_config.enable.equipment.all & m_env.system_faults_register.equipment.all; + m_registers.status_fault_register.phase_a.all = m_config.enable.phase_a.all & m_env.system_faults_register.phase_a.all; + m_registers.status_fault_register.phase_b.all = m_config.enable.phase_b.all & m_env.system_faults_register.phase_b.all; + m_registers.status_fault_register.phase_c.all = m_config.enable.phase_c.all & m_env.system_faults_register.phase_c.all; + // + m_registers.status.signal.fault = m_registers.status_fault_register.equipment.all == (uint16_t)0 ? false : true; + m_registers.status.signal.fault |= m_registers.status_fault_register.phase_a.all == (uint16_t)0 ? false : true; + m_registers.status.signal.fault |= m_registers.status_fault_register.phase_b.all == (uint16_t)0 ? false : true; + m_registers.status.signal.fault |= m_registers.status_fault_register.phase_c.all == (uint16_t)0 ? false : true; + // + if(m_registers.counter_attempts != 0) + { + if(m_registers.counter_timer_selfclear_attempts < m_config.period_timer_selfclear_attempts) + { + m_registers.counter_timer_selfclear_attempts += m_time_sample; + } + else + { + m_registers.counter_attempts = 0; + m_registers.counter_timer_selfclear_attempts = FP_ZERO; + } + } + // + SYSCTRL::MonitorDigitalInputSignal::implement(m_registers.status.signal.fault, m_registers.monitor_fault); + // + _state_execute(); + // + } + else + { + _set_state_free(); + // + }//if else + // +}// +// + + + +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_empty() +{ + m_state = SYSCTRL::SYSRestart::EMPTY; + m_state_bit_field.all = 0; + m_state_bit_field.signal.empty = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + + status.all = m_registers.status.all; + // + SYSCTRL::MonitorDigitalInputSignal::preset(false, m_registers.monitor_fault); + // + _state_run = &SYSCTRL::SYSRestart::_state_empty; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_free() +{ + m_state = SYSCTRL::SYSRestart::FREE; + m_state_bit_field.all = 0; + m_state_bit_field.signal.free = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_free; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_holdfault() +{ + m_state = SYSCTRL::SYSRestart::HOLDFAULT; + m_state_bit_field.signal.free = 0; + m_state_bit_field.signal.holdfault = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_holdfault; + // +}// +// + +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_resetfault() +{ + m_state = SYSCTRL::SYSRestart::RESETFAULT; + m_state_bit_field.signal.resetfault = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 1; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_resetfault; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_freezefault() +{ + m_state = SYSCTRL::SYSRestart::FREEZEFAULT; + m_state_bit_field.all = 0; + m_state_bit_field.signal.freezefault = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 1; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_freezefault; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_holdstop() +{ + m_state = SYSCTRL::SYSRestart::HOLDSTOP; + m_state_bit_field.signal.holdstop = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_holdstop; + // +}// +// + +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_turnon_q1() +{ + m_state = SYSCTRL::SYSRestart::TURNONQ1; + m_state_bit_field.signal.turnonq1 = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 1; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_turnon_q1; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_turnon_km1() +{ + m_state = SYSCTRL::SYSRestart::TURNONKM1; + m_state_bit_field.signal.turnonkm1 = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 1; + m_registers.status.signal.turnon_km3 = 0; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_turnon_km1; + // + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_turnon_km3() +{ + m_state = SYSCTRL::SYSRestart::TURNONKM3; + m_state_bit_field.signal.turnonkm3 = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 0; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 1; + // + status.all = m_registers.status.all; + // + _state_run = &SYSCTRL::SYSRestart::_state_turnon_km3; + // + // +}// +// + + + + +#pragma CODE_SECTION("ramfuncs"); +inline void SYSRestart::_set_state_startup() +{ + m_state = SYSCTRL::SYSRestart::STARTUP; + m_state_bit_field.signal.turnonq1 = 1; + m_state_bit_field.signal.turnonkm1 = 1; + m_state_bit_field.signal.turnonkm3 = 1; + m_state_bit_field.signal.startup = 1; + // + m_registers.counter_timer = FP_ZERO; + // + m_registers.status.signal.resetfault = 0; + m_registers.status.signal.freezefault = 0; + m_registers.status.signal.startup = 1; + m_registers.status.signal.turnon_q1 = 0; + m_registers.status.signal.turnon_km1 = 0; + m_registers.status.signal.turnon_km3 = 0; + + status.all = m_registers.status.all; + // + m_registers.counter_attempts++; + // + _state_run = &SYSCTRL::SYSRestart::_state_startup; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_execute() +{ + (this->*_state_run)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_empty() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_free() +{ + // Change State if appropriate conditions was happened + if(m_registers.monitor_fault.signal.is_on) + { + _set_state_holdfault(); + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_holdfault() +{ + // Change State if appropriate conditions was happened + + if(m_registers.counter_timer < m_config.period_timer_hold_fault) + { + m_registers.counter_timer += m_time_sample; + // + }//if + + + if(!m_env.system_fault.boolbit.b0) + { + _set_state_free(); + // + }//if + + + if(m_registers.counter_attempts >= m_config.attempts) + { + _set_state_freezefault(); + // + }//if + + + if(m_env.system_fault.boolbit.b0 & (m_registers.counter_timer >= m_config.period_timer_hold_fault)) + { + _set_state_resetfault(); + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_resetfault() +{ + // Change State if appropriate conditions was happened + + if(m_registers.counter_timer < m_config.period_timer_reset) + { + m_registers.counter_timer += m_time_sample; + // + }//if + + + if(!m_env.system_fault.boolbit.b0) + { + _set_state_holdstop(); + // + }//if + + + if(m_env.system_fault.boolbit.b0 & (m_registers.counter_timer >= m_config.period_timer_reset)) + { + _set_state_freezefault(); + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_freezefault() +{ + // Change State if appropriate conditions was happened + if(!m_env.system_fault.boolbit.b0) + { + _set_state_free(); + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_holdstop() +{ + // Change State if appropriate conditions was happened + + if(m_registers.counter_timer < m_config.period_timer_hold_stop) + { + m_registers.counter_timer += m_time_sample; + // + }//if + + + if(m_env.system_fault.boolbit.b0 | + (!m_env.system_fault.boolbit.b0 & m_env.remote_stop.state.signal.is_on) + ) + { + _set_state_free(); + // + }//if + + + if(!m_env.system_fault.boolbit.b0 & + !m_env.system_ready.boolbit.b0 & + (m_registers.counter_timer >= m_config.period_timer_hold_stop) + ) + { + _set_state_turnon_q1(); + // + }//if + + + if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0) + { + _set_state_startup(); + // + }//if + + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_turnon_q1() +{ + if(m_registers.counter_timer < m_config.period_timer_turnon_switch) + { + m_registers.counter_timer += m_time_sample; + // + }//if + // + if(m_env.system_fault.boolbit.b0 | + (m_registers.counter_timer >= m_config.period_timer_turnon_switch) + ) + { + _set_state_free(); + // + }//if + // + + if(!m_env.system_fault.boolbit.b0 & m_env.input_discrete.signal.auxiliary_q1) + { + _set_state_turnon_km1(); + // + }//if + + + if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0) + { + _set_state_startup(); + // + }//if + +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_turnon_km1() +{ + if(m_registers.counter_timer < m_config.period_timer_turnon_switch) + { + m_registers.counter_timer += m_time_sample; + // + }//if + + if(m_env.system_fault.boolbit.b0 | + (m_registers.counter_timer >= m_config.period_timer_turnon_switch) + ) + { + _set_state_free(); + // + }//if + // + + // + if(!m_env.system_fault.boolbit.b0 & m_env.input_discrete.signal.auxiliary_km1) + { + _set_state_turnon_km3(); + // + }//if + + if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0) + { + _set_state_startup(); + // + }//if +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_turnon_km3() +{ + if(m_registers.counter_timer < m_config.period_timer_turnon_switch) + { + m_registers.counter_timer += m_time_sample; + // + }//if + + if(m_env.system_fault.boolbit.b0 | + (m_registers.counter_timer >= m_config.period_timer_turnon_switch) + ) + { + _set_state_free(); + // + }//if + // + + if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0) + { + _set_state_startup(); + // + }//if +}// + +#pragma CODE_SECTION("ramfuncs"); +void SYSRestart::_state_startup() +{ + // Change State if appropriate conditions was happened + + if(m_registers.counter_timer < m_config.period_timer_startup) + { + m_registers.counter_timer += m_time_sample; + // + }//if + + + if(m_env.system_fault.boolbit.b0 | + (m_registers.counter_timer >= m_config.period_timer_startup) | + (m_env.enable_work.boolbit.b0) | + (m_env.remote_stop.state.signal.is_on) + ) + { + _set_state_free(); + // + }//if + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SYSRestart.h b/SYSCTRL/SYSRestart.h new file mode 100644 index 0000000..3a0bbc2 --- /dev/null +++ b/SYSCTRL/SYSRestart.h @@ -0,0 +1,200 @@ +/* + * SYSRestart.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + + +#include +#include + +#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_ */ diff --git a/SYSCTRL/ScaleCompute.cpp b/SYSCTRL/ScaleCompute.cpp new file mode 100644 index 0000000..c83b970 --- /dev/null +++ b/SYSCTRL/ScaleCompute.cpp @@ -0,0 +1,94 @@ +/* + * ScaleCompute.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/ScaleCompute.h" + +namespace SYSCTRL +{ + +//CONSTRUCTOR +ScaleCompute::ScaleCompute(float& phase_a, float& phase_b, float& phase_c, float& scale_a, float& scale_b, float& scale_c): + m_command(), + m_enable(), + // + m_reference_value(FP_ZERO), + // + m_p_phase_a(phase_a), + m_p_phase_b(phase_b), + m_p_phase_c(phase_c), + // + m_p_scale_a(scale_a), + m_p_scale_b(scale_b), + m_p_scale_c(scale_c), + // + m_value_phase_a(FP_ZERO), + m_value_phase_b(FP_ZERO), + m_value_phase_c(FP_ZERO), + // + m_scale_phase_a(FP_ZERO), + m_scale_phase_b(FP_ZERO), + m_scale_phase_c(FP_ZERO) +{}//CONSTRUCTOR + +#pragma CODE_SECTION("ramfuncs"); +void ScaleCompute::set_reference(float reference) +{ + m_reference_value = reference; + // +}// + +#pragma CODE_SECTION("ramfuncs"); +void ScaleCompute::set_enable() +{ + m_enable.bit.enable = 1; + // +}// +#pragma CODE_SECTION("ramfuncs"); +void ScaleCompute::clear_enable() +{ + m_enable.bit.enable = 0; + // +}// + +#pragma CODE_SECTION("ramfuncs"); +void ScaleCompute::fix() +{ + if(m_enable.bit.enable == 1) + { + m_value_phase_a = m_p_phase_a; + m_value_phase_b = m_p_phase_b; + m_value_phase_c = m_p_phase_c; + // + m_scale_phase_a = new_scale_compute(m_reference_value, m_value_phase_a, m_p_scale_a); + m_scale_phase_b = new_scale_compute(m_reference_value, m_value_phase_b, m_p_scale_b); + m_scale_phase_c = new_scale_compute(m_reference_value, m_value_phase_c, m_p_scale_c); + // + m_p_scale_a = m_scale_phase_a; + m_p_scale_b = m_scale_phase_b; + m_p_scale_c = m_scale_phase_c; + // + }//if +}// + +#pragma CODE_SECTION("ramfuncs"); +inline float ScaleCompute::new_scale_compute(float ref, float value, float scale) +{ + // + if((value != FP_ZERO) && (ref != FP_ZERO)) + { + return ref * scale / value; + // + } + else + { + return scale; + // + }//if else + // +}// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/ScaleCompute.h b/SYSCTRL/ScaleCompute.h new file mode 100644 index 0000000..a2bd462 --- /dev/null +++ b/SYSCTRL/ScaleCompute.h @@ -0,0 +1,79 @@ +/* + * ScaleCompute.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#ifndef SYSCTRL_SCALECOMPUTE_H_ +#define SYSCTRL_SCALECOMPUTE_H_ + +namespace SYSCTRL +{ + +struct ScaleComputeEnableBit +{ + uint16_t enable: 1; +};//ScaleComputeEnableBit + + +union ScaleComputeEnableRegister +{ + uint16_t all; + ScaleComputeEnableBit bit; +};//ScaleComputeEnableRegister + + +struct ScaleComputeCommandBit +{ + uint16_t start: 1; +};//ScaleComputeCommandBit + +union ScaleComputeCommandRegister +{ + uint16_t all; + ScaleComputeCommandBit bit; +};//ScaleComputeCommandRegister + + + +class ScaleCompute +{ +private: + ScaleComputeCommandRegister m_command; + ScaleComputeEnableRegister m_enable; + float m_reference_value; + // + float& m_p_phase_a; + float& m_p_phase_b; + float& m_p_phase_c; + // + float& m_p_scale_a; + float& m_p_scale_b; + float& m_p_scale_c; + // + float m_value_phase_a; + float m_value_phase_b; + float m_value_phase_c; + // + float m_scale_phase_a; + float m_scale_phase_b; + float m_scale_phase_c; +public: + ScaleCompute(float& phase_a, float& phase_b, float& phase_c, float& scale_a, float& scale_b, float& scale_c); + void set_reference(float reference); + void set_enable(); + void clear_enable(); + void fix(); +private: + inline float new_scale_compute(float ref, float value, float scale); + // +};//class ScaleCompute + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_SCALECOMPUTE_H_ */ diff --git a/SYSCTRL/SignalDecompose.cpp b/SYSCTRL/SignalDecompose.cpp new file mode 100644 index 0000000..4b7a0d8 --- /dev/null +++ b/SYSCTRL/SignalDecompose.cpp @@ -0,0 +1,86 @@ +/* + * SignalDecompose.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SignalDecompose.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +SignalDecompose::SignalDecompose(): + m_time_sample(-1.0), + m_projection_active(), + m_projection_reactive(), + m_projection_filter_active(), + m_projection_filter_reactive(), + _execute(&SYSCTRL::SignalDecompose::_execute_undef) +// +{}//CONSTRUCTOR + +void SignalDecompose::setup(float time_sample) +{ + + m_time_sample = time_sample; + m_projection_filter_active.setup(m_time_sample); + m_projection_filter_reactive.setup(m_time_sample); + // +}// +// +void SignalDecompose::configure(const SignalDecomposeConfiguration& config) +{ + + m_projection_filter_active.configure(config.projection_filter); + m_projection_filter_reactive.configure(config.projection_filter); + // + if((m_time_sample > FP_ZERO) && (config.projection_filter.time > m_time_sample)) + { + _execute = &SYSCTRL::SignalDecompose::_execute_operational; + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalDecompose::reset() +{ + m_projection_active = FP_ZERO; + m_projection_reactive = FP_ZERO; + m_projection_filter_active.reset(); + m_projection_filter_reactive.reset(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalDecompose::get_outputs(float& projection_active, float& projection_reactive) +{ + projection_active = m_projection_active; + projection_reactive = m_projection_reactive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalDecompose::execute(float reference, float ort_cos, float ort_sin) +{ + (this->*_execute)(reference, ort_cos, ort_sin); + // +}// +// +void SignalDecompose::_execute_undef(float reference, float ort_cos, float ort_sin) +{ + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalDecompose::_execute_operational(float reference, float ort_cos, float ort_sin) +{ + // + m_projection_active = m_projection_filter_active.execute(1.4142 * reference * ort_cos); + // + m_projection_reactive = m_projection_filter_reactive.execute(-(1.4142 * reference * ort_sin)); + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SignalDecompose.h b/SYSCTRL/SignalDecompose.h new file mode 100644 index 0000000..2b913e7 --- /dev/null +++ b/SYSCTRL/SignalDecompose.h @@ -0,0 +1,74 @@ +/* + * SignalDecompose.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/BaseComponent.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + +#ifndef SYSCTRL_SIGNALDECOMPOSE_H_ +#define SYSCTRL_SIGNALDECOMPOSE_H_ + + +namespace SYSCTRL +{ + + +struct SignalDecomposeStructure +{ + float projection_active; + float projection_reactive; + void reset() + { + projection_active = FP_ZERO; + projection_reactive = FP_ZERO; + } + SignalDecomposeStructure(): + projection_active(FP_ZERO), + projection_reactive(FP_ZERO) + {} +};// + +struct SignalDecomposeConfiguration +{ + FLTSYSLIB::FilterForthConfiguration projection_filter; + SignalDecomposeConfiguration(): + projection_filter() + {} +};//SignalDecomposeConfiguration + + + +class SignalDecompose +{ +private: + float m_time_sample; +private: + float m_projection_active; + float m_projection_reactive; + FLTSYSLIB::FilterForth m_projection_filter_active; + FLTSYSLIB::FilterForth m_projection_filter_reactive; +public: + SignalDecompose(); + void setup(float time_sample); + void configure(const SignalDecomposeConfiguration& config); +public: + void reset(); + void get_outputs(float& projection_active, float& projection_reactive); +public: + void execute(float reference, float ort_cos, float ort_sin); +private: + void (SignalDecompose::*_execute)(float reference, float ort_cos, float ort_sin); + void _execute_undef(float reference, float ort_cos, float ort_sin); + void _execute_operational(float reference, float ort_cos, float ort_sin); + // +};//SignalDecompose + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_SIGNALDECOMPOSE_H_ */ diff --git a/SYSCTRL/SignalRelative.cpp b/SYSCTRL/SignalRelative.cpp new file mode 100644 index 0000000..95a5936 --- /dev/null +++ b/SYSCTRL/SignalRelative.cpp @@ -0,0 +1,134 @@ +/* + * RelativeSignal.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SignalRelative.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +SignalRelative::SignalRelative(): + BaseComponent(), + m_amplitude(FP_ZERO), + m_relative(FP_ZERO), + m_limit_relative_high(FP_ZERO), + m_limit_relative_low(FP_ZERO), + m_minimal_amplitude_level(FP_ZERO), + m_ampl_filter(), + _execute(&SYSCTRL::SignalRelative::_execute_undef) +{}//CONSTRUCTOR +// +void SignalRelative::setup(const SignalRelativeSetup& setup) +{ + static bool status = true; + + if(m_mode == SYSCTRL::SignalRelative::UNDEFINED) + { + m_time_sample = setup.time_sample; + m_ampl_filter.setup(m_time_sample); + + status &= m_time_sample > FP_ZERO ? true : false; + status &= m_ampl_filter.compare(FLTSYSLIB::AMPL::CONFIGURATE); + + if(status) + { + m_mode = SYSCTRL::SignalRelative::CONFIGURATE; + // + }//if + // + }//if + // +}// +// +void SignalRelative::configure(const SignalRelativeConfiguration& config) +{ + static bool status = true; + + if(m_mode == SYSCTRL::SignalRelative::CONFIGURATE) + { + m_limit_relative_high = config.limit_relative_high; + m_limit_relative_low = config.limit_relative_low; + m_minimal_amplitude_level = config.minimal_amplitude_level; + m_ampl_filter.configure(config.amplitude_filter); + + status &= m_limit_relative_high > m_limit_relative_low ? true : false; + status &= m_minimal_amplitude_level > FP_ZERO ? true : false; + status &= m_ampl_filter.compare(FLTSYSLIB::AMPL::OPERATIONAL); + + if(status) + { + m_mode = SYSCTRL::SignalRelative::OPERATIONAL; + _execute = &SYSCTRL::SignalRelative::_execute_operational; + // + }//if + // + }//if + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalRelative::reset() +{ + m_amplitude = FP_ZERO; + m_relative = FP_ZERO; + m_ampl_filter.reset(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalRelative::get_outputs(float& amplitude, float& relative) +{ + amplitude = m_amplitude; + relative = m_relative; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalRelative::execute(float reference) +{ + (this->*_execute)(reference); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalRelative::_execute_undef(float reference) +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void SignalRelative::_execute_operational(float reference) +{ + static float _relative = FP_ZERO; + m_amplitude = m_ampl_filter.execute(reference); + + if(m_amplitude > m_minimal_amplitude_level) + { + // + _relative = reference / m_amplitude; + // + if(_relative > m_limit_relative_high) + { + _relative = m_limit_relative_high; + // + }//if + // + if(_relative < m_limit_relative_low) + { + _relative = m_limit_relative_low; + // + }//if + // + } + else + { + _relative = FP_ZERO; + // + }// if else + // + m_relative = _relative; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SignalRelative.h b/SYSCTRL/SignalRelative.h new file mode 100644 index 0000000..50469d1 --- /dev/null +++ b/SYSCTRL/SignalRelative.h @@ -0,0 +1,74 @@ +/* + * RelativeSignal.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + + +#include "SYSCTRL/BaseComponent.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" + + +#ifndef SYSCTRL_RELATIVESIGNAL_H_ +#define SYSCTRL_RELATIVESIGNAL_H_ + +namespace SYSCTRL +{ + +struct SignalRelativeSetup +{ + float time_sample; + SignalRelativeSetup(): + time_sample(-1.0) + {} +};//SignalRelativeSetup + + +struct SignalRelativeConfiguration +{ + float limit_relative_high; + float limit_relative_low; + float minimal_amplitude_level; + FLTSYSLIB::AMPLF4OConfiguration amplitude_filter; + SignalRelativeConfiguration(): + limit_relative_high(1.0), + limit_relative_low(-1.0), + minimal_amplitude_level(0.1), + amplitude_filter() + {} +};//SignalRelativeConfiguration + +class SignalRelative: public BaseComponent +{ +private: + float m_amplitude; + float m_relative; +private: + float m_limit_relative_high; + float m_limit_relative_low; + float m_minimal_amplitude_level; +private: + FLTSYSLIB::AMPLF4O m_ampl_filter; +public: + SignalRelative(); + void setup(const SignalRelativeSetup& setup); + void configure(const SignalRelativeConfiguration& config); +public: + void reset(); + void get_outputs(float& amplitude, float& relative); +public: + void execute(float reference); +private: + void (SignalRelative::*_execute)(float reference); + void _execute_undef(float reference); + void _execute_operational(float reference); + // +};//RelativeSignal + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_RELATIVESIGNAL_H_ */ diff --git a/SYSCTRL/SymmetricalComponents.cpp b/SYSCTRL/SymmetricalComponents.cpp new file mode 100644 index 0000000..96a00a3 --- /dev/null +++ b/SYSCTRL/SymmetricalComponents.cpp @@ -0,0 +1,180 @@ +/* + * SymmetricalComponents.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SymmetricalComponents.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +SymmetricalComponents::SymmetricalComponents() +{}//CONSTRUCTOR +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsStructure& out) +{ + SYSCTRL::SymmetricalComponents::compute_direct_symmetrical_components_axis_common(in_ph_a, in_ph_b, in_ph_c, out.direct); + SYSCTRL::SymmetricalComponents::compute_inverse_symmetrical_components_axis_common(in_ph_a, in_ph_b, in_ph_c, out.inverse); + SYSCTRL::SymmetricalComponents::compute_zero_symmetrical_components_axis_common(in_ph_a, in_ph_b, in_ph_c, out.zero); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_direct_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + SYSCTRL::SymmetricalComponents::_direct_common_inverse_own(in_ph_a, in_ph_b, in_ph_c, out); + + out.b.active = -m_coefficient_a * out.a.active + m_coefficient_b * out.a.reactive; + out.b.reactive = -m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + + out.c.active = -m_coefficient_a * out.a.active - m_coefficient_b * out.a.reactive; + out.c.reactive = m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_inverse_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + SYSCTRL::SymmetricalComponents::_inverse_common_zero_own(in_ph_a, in_ph_b, in_ph_c, out); + + out.b.active = -m_coefficient_a * out.a.active - m_coefficient_b * out.a.reactive; + out.b.reactive = m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + + out.c.active = -m_coefficient_a * out.a.active + m_coefficient_b * out.a.reactive; + out.c.reactive = -m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_zero_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + SYSCTRL::SymmetricalComponents::_zero_common_direct_own(in_ph_a, in_ph_b, in_ph_c, out); + + out.b.active = out.a.active; + out.b.reactive = out.a.reactive; + + out.c.active = out.a.active; + out.c.reactive = out.a.reactive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsStructure& out) +{ + SYSCTRL::SymmetricalComponents::compute_direct_symmetrical_components_axis_own(in_ph_a, in_ph_b, in_ph_c, out.direct); + SYSCTRL::SymmetricalComponents::compute_inverse_symmetrical_components_axis_own(in_ph_a, in_ph_b, in_ph_c, out.inverse); + SYSCTRL::SymmetricalComponents::compute_zero_symmetrical_components_axis_own(in_ph_a, in_ph_b, in_ph_c, out.zero); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_direct_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + SYSCTRL::SymmetricalComponents::_zero_common_direct_own(in_ph_a, in_ph_b, in_ph_c, out); + + //out.b.active = -m_coefficient_a * out.a.active + m_coefficient_b * out.a.reactive; + //out.b.reactive = -m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + out.b.active = 0.8660254 * (out.a.reactive - 0.577350269 * out.a.active); + out.b.reactive = -0.8660254 * (out.a.active + 0.577350269 * out.a.reactive); + + //out.c.active = -m_coefficient_a * out.a.active - m_coefficient_b * out.a.reactive; + //out.c.reactive = m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + out.c.active = -0.8660254 * (0.577350269 * out.a.active + out.a.reactive); + out.c.reactive = 0.8660254 * (out.a.active - 0.577350269 * out.a.reactive); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_inverse_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + SYSCTRL::SymmetricalComponents::_direct_common_inverse_own(in_ph_a, in_ph_b, in_ph_c, out); + + //out.b.active = -m_coefficient_a * out.a.active - m_coefficient_b * out.a.reactive; + //out.b.reactive = m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + out.b.active = -0.8660254 * (0.577350269 * out.a.active + out.a.reactive); + out.b.reactive = 0.8660254 * (out.a.active - 0.577350269 * out.a.reactive); + + //out.c.active = -m_coefficient_a * out.a.active + m_coefficient_b * out.a.reactive; + //out.c.reactive = -m_coefficient_b * out.a.active - m_coefficient_a * out.a.reactive; + out.c.active = 0.8660254 * (out.a.reactive - 0.577350269 * out.a.active); + out.c.reactive = -0.8660254 * (out.a.active + 0.577350269 * out.a.reactive); + // +}// +// + +#pragma CODE_SECTION("ramfuncs"); +void SymmetricalComponents::compute_zero_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + SYSCTRL::SymmetricalComponents::_inverse_common_zero_own(in_ph_a, in_ph_b, in_ph_c, out); + + out.b.active = out.a.active; + out.b.reactive = out.a.reactive; + + out.c.active = out.a.active; + out.c.reactive = out.a.reactive; + // +}// +// + +#pragma CODE_SECTION("ramfuncs"); +inline void SymmetricalComponents::_direct_common_inverse_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + out.a.active = m_three_recipcoral * (in_ph_a.active - m_coefficient_a * (in_ph_b.active + in_ph_c.active) - m_coefficient_b * (in_ph_b.reactive - in_ph_c.reactive)); + out.a.reactive = m_three_recipcoral * (in_ph_a.reactive - m_coefficient_a * (in_ph_b.reactive + in_ph_c.reactive) + m_coefficient_b * (in_ph_b.active - in_ph_c.active)); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SymmetricalComponents::_inverse_common_zero_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + out.a.active = m_three_recipcoral * (in_ph_a.active - m_coefficient_a * (in_ph_b.active + in_ph_c.active) + m_coefficient_b * (in_ph_b.reactive - in_ph_c.reactive)); + out.a.reactive = m_three_recipcoral * (in_ph_a.reactive - m_coefficient_a * (in_ph_b.reactive + in_ph_c.reactive) - m_coefficient_b * (in_ph_b.active - in_ph_c.active)); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SymmetricalComponents::_zero_common_direct_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out) +{ + out.a.active = m_three_recipcoral * (in_ph_a.active + in_ph_b.active + in_ph_c.active); + out.a.reactive = m_three_recipcoral * (in_ph_a.reactive + in_ph_b.reactive + in_ph_c.reactive); + // +}// +// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SymmetricalComponents.h b/SYSCTRL/SymmetricalComponents.h new file mode 100644 index 0000000..9e33005 --- /dev/null +++ b/SYSCTRL/SymmetricalComponents.h @@ -0,0 +1,125 @@ +/* + * SymmetricalComponents.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/RelativeAnalogSignalStructure.h" + +#ifndef SYSCTRL_SYMMETRICALCOMPONENTS_H_ +#define SYSCTRL_SYMMETRICALCOMPONENTS_H_ + +namespace SYSCTRL +{ + +struct SymmetricalComponentsPhaseProjection +{ + float active; + float reactive; + SymmetricalComponentsPhaseProjection(): + active(FP_ZERO), + reactive(FP_ZERO) + {} +};//SymmetricalComponentsPhaseProjection + + +struct SymmetricalComponentsPhase +{ + SymmetricalComponentsPhaseProjection a; + SymmetricalComponentsPhaseProjection b; + SymmetricalComponentsPhaseProjection c; + SymmetricalComponentsPhase(): + a(), + b(), + c() + {} + // +};//SymmetricalComponentsPhase + +struct SymmetricalComponentsStructure +{ + SymmetricalComponentsPhase direct; + SymmetricalComponentsPhase inverse; + SymmetricalComponentsPhase zero; + SymmetricalComponentsStructure(): + direct(), + inverse(), + zero() + {} + // +};//SymmetricalComponentsStructure + + + +class SymmetricalComponents +{ +private: + static const float m_coefficient_a = 0.5; + static const float m_coefficient_b = 0.8660254; + static const float m_three_recipcoral = 0.33333333; +public: + SymmetricalComponents(); +public: + static void compute_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsStructure& out); + + static void compute_direct_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + + static void compute_inverse_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + + static void compute_zero_symmetrical_components_axis_common(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + + static void compute_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsStructure& out); + + static void compute_direct_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + + static void compute_inverse_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + + static void compute_zero_symmetrical_components_axis_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); +private: + inline static void _direct_common_inverse_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + inline static void _inverse_common_zero_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + + inline static void _zero_common_direct_own(const SYSCTRL::ProjectionAnalogSignalStructure in_ph_a, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_b, + const SYSCTRL::ProjectionAnalogSignalStructure in_ph_c, + SYSCTRL::SymmetricalComponentsPhase& out); + // +};//SymmetricalComponents + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_SYMMETRICALCOMPONENTS_H_ */ diff --git a/SYSCTRL/SystemConfigurator.h b/SYSCTRL/SystemConfigurator.h new file mode 100644 index 0000000..68e82cd --- /dev/null +++ b/SYSCTRL/SystemConfigurator.h @@ -0,0 +1,441 @@ +/* + * SystemConfigurator.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ +#include +#include + + +#include "framework.h" +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" + + +#include "SYSCTRL/AlgorithmContext.h" +//#include "SYSCTRL/FanControl.h" +#include "SYSCTRL/ContactorFault.h" +#include "SYSCTRL/FanTimerControl.h" +#include "SYSCTRL/GeneratorSymmetricalComponents.h" +#include "SYSCTRL/HardWare.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" +#include "SYSCTRL/PhaseAlertMonitor.h" +#include "SYSCTRL/RelativeAnalogSignalStructure.h" +#include "SYSCTRL/SignalDecompose.h" +#include "SYSCTRL/SignalRelative.h" +#include "SYSCTRL/TriggerRS.h" + + +#ifndef SYSCTRL_SYSTEMCONFIGURATOR_H_ +#define SYSCTRL_SYSTEMCONFIGURATOR_H_ + +namespace SYSCTRL +{ + +#define NUMBER_FRAM_PARAMETERS ((uint16_t)(200)) +#define NUMBER_FLASH_PARAMETERS ((uint16_t)(10)) + + +#if TYPECONTROL == SCALARCONTROL +#define HEADER_CLASS_ID ((int16_t)(0x0001)) +#define HEADER_PART_ID ((int16_t)(0x0010)) +#define HEADER_SOFTWARE_VERSION ((int16_t)(0x0796)) +#define FOOTER_FOOT ((int16_t)(0xA5A5)) +#endif + +#if TYPECONTROL == VECTORCONTROL +#define HEADER_CLASS_ID ((int16_t)(0x0002)) +#define HEADER_PART_ID ((int16_t)(0x0059)) +#define HEADER_SOFTWARE_VERSION ((int16_t)(0x3C3C)) +#define FOOTER_FOOT ((int16_t)(0xC7C7)) +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL +#define HEADER_CLASS_ID ((int16_t)(0x0010)) +#define HEADER_PART_ID ((int16_t)(0x0010)) +#define HEADER_SOFTWARE_VERSION ((int16_t)(0x0010)) +#define FOOTER_FOOT ((int16_t)(0x0010)) +#endif + + +struct SystemControlSetup +{ + float time_sample_control; + int16 time_prescale_slow; + int16 time_prescale_additional; + // + // Decompose Current Load + // + SYSCTRL::SignalRelativeSetup relative_voltage_input; + // + SystemControlSetup(): + time_sample_control(-1.0), + time_prescale_slow(0), + time_prescale_additional(0), + relative_voltage_input() + {} +};//end SystemControlSetup + + +struct TestConfiguration +{ + // + // RMS Filter + // + FLTSYSLIB::RMSF4OConfiguration rms_filter; + + // + // Regulators + // + FLTSYSLIB::PIControllerConfiguration regulator_voltage; + + // + // PLL-ABC Voltage + // + FLTSYSLIB::PLLABCDVRConfiguration pll_abc; + + TestConfiguration(): + rms_filter(), + regulator_voltage(), + pll_abc() + {} +};// + + + +struct SystemControlConfiguration +{ + + // + // References + // + float reference_current_limit_rms; + float reference_current_pfc_rms; + float reference_voltage_rms; + float reference_voltage_high_limit_rms; + float reference_voltage_dc; + + SYSCTRL::AlgorithmControlRegister algorithm_control; + + // + // High Voltage Cell + // + SYSCTRL::HardWareConfiguration hardware; + + float minimal_input_voltage_level; + + float scale_voltage_input_a; + float scale_voltage_input_b; + float scale_voltage_input_c; + // + float scale_current_input_a; + float scale_current_input_b; + float scale_current_input_c; + // + float scale_current_cell_a; + float scale_current_cell_b; + float scale_current_cell_c; + // + float scale_voltage_load_a; + float scale_voltage_load_b; + float scale_voltage_load_c; + // + float scale_current_load_a; + float scale_current_load_b; + float scale_current_load_c; + // + float scale_current_bypass_a; + float scale_current_bypass_b; + float scale_current_bypass_c; + + + + + // + // System Alarm + // + SYSCTRL::PhaseAlertConfiguration phase_alert_monitor; + + + // + // DIGITAL INPUTS + // + FLTSYSLIB::DigitalInputAntiNoiseConfiguration digital_input_config; //3001-3020 + + + // + // FAN CONTROL + // + SYSCTRL::FanTimerControlConfiguration fan_control; + + + // + // Amplitude Filter + // +// FLTSYSLIB::AMPLF4OConfiguration ampl_filter_voltage; + FLTSYSLIB::AMPLF4OConfiguration ampl_filter_current; + + + // + // RMS Filter + // + FLTSYSLIB::RMSF4OConfiguration rms_filter_analog_signal; + + // + //Zero Drift Filter + // + FLTSYSLIB::FilterForthConfiguration zero_filter; + + // + //Cell DC Voltage Filter + // + FLTSYSLIB::FilterForthConfiguration cell_dc_voltage_filter; + + + // + // Decompose Current Load + // + SYSCTRL::SignalDecomposeConfiguration signal_decompose; + + + // + // Relative + // + SYSCTRL::SignalRelativeConfiguration relative_voltage_input; + + + // + // PLL-ABC Voltage + // + FLTSYSLIB::PLLABCDVRConfiguration pll_abc_input_voltage; + + + // + // ABC-Generator + // + FLTSYSLIB::GeneratorABCConfiguration generator_abc; + //SYSCTRL::GeneratorSymmetricalComponentsConfiguration gen_inp_volt; + //SYSCTRL::GeneratorSymmetricalComponentsConfiguration gen_out_volt; + //SYSCTRL::GeneratorSymmetricalComponentsConfiguration gen_out_current; + //SYSCTRL::GeneratorSymmetricalComponentsConfiguration gen_input_current; + //SYSCTRL::GeneratorSymmetricalComponentsConfiguration gen_bypass_current; + //SYSCTRL::GeneratorSymmetricalComponentsConfiguration gen_cell_current; + + + // + // Reference PWM-Generator + // + //FLTSYSLIB::GeneratorABCConfiguration generator_pwm; + + // + //AlgorithmGenerator + // + SYSCTRL::AlgorithmSourceReference algorithm_source_references; + + + // + // Harmonica Analyzer + // + FLTSYSLIB::HarmonicaFilter4OrderConfiguration ph_harmonica_5; + + + // + // Reference Intensity Idref Iqref in Start Mode + // + FLTSYSLIB::FilterSecondConfiguration intensity_id_iq_references; + + + // + // Regulators + // +#if TYPECONTROL == VECTORCONTROL + FLTSYSLIB::PIControllerConfiguration regulator_voltage_load_dq; + FLTSYSLIB::IntegratorConfiguration integrator_voltage_dq; + FLTSYSLIB::FilterConfiguration reference_voltage_dq_intensity; + FLTSYSLIB::IControllerConfiguration regulator_current_limit; + FLTSYSLIB::PIControllerConfiguration regulator_current_pfc; +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_PI + FLTSYSLIB::PIControllerConfiguration regulator_current_load_dq; +#endif +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_P + FLTSYSLIB::PControllerConfiguration regulator_current_load_dq; +#endif + FLTSYSLIB::IControllerConfiguration referencer_current_bypass_dq; +#endif + + +#if TYPECONTROL == SCALARCONTROL + FLTSYSLIB::PIControllerConfiguration regulator_voltage_load_active_reactive; + FLTSYSLIB::PIControllerConfiguration regulator_current_limit; + FLTSYSLIB::PIControllerConfiguration regulator_current_pfc; + FLTSYSLIB::PIControllerConfiguration current_regulator_active; + FLTSYSLIB::PIControllerConfiguration current_regulator_reactive; + FLTSYSLIB::PIControllerConfiguration current_referencer; + FLTSYSLIB::PIControllerConfiguration regulator_dc_voltage; +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + FLTSYSLIB::PIControllerConfiguration drc_voltage_controller; + // + FLTSYSLIB::FilterSecondConfiguration drc_reference_voltage_direct_intensity; + // + FLTSYSLIB::PIControllerConfiguration drc_regulator_current_load; + // + FLTSYSLIB::IControllerConfiguration drc_referencer_current_bypass; + // + FLTSYSLIB::IControllerConfiguration drc_regulator_current_limit; + FLTSYSLIB::PIControllerConfiguration drc_regulator_current_pfc; + // + SYSCTRL::DRCDecomposerConfiguration drc_voltage_decomposer; +#endif + + + // + // Timers + // + FLTSYSLIB::FTimerConfiguration timer_start; + FLTSYSLIB::FTimerConfiguration timer_stop; + + // + // Contactor Fault Control + // + SYSCTRL::ContactorFaultConfiguration contactor; + + + SystemControlConfiguration(): + reference_current_limit_rms(FP_ZERO), + reference_current_pfc_rms(FP_ZERO), + reference_voltage_rms(FP_ZERO), + reference_voltage_high_limit_rms(FP_ZERO), + reference_voltage_dc(FP_ZERO), + hardware(), + // + minimal_input_voltage_level(FP_ZERO), + // + scale_voltage_input_a(1.0), + scale_voltage_input_b(1.0), + scale_voltage_input_c(1.0), + // + scale_current_input_a(1.0), + scale_current_input_b(1.0), + scale_current_input_c(1.0), + // + scale_current_cell_a(1.0), + scale_current_cell_b(1.0), + scale_current_cell_c(1.0), + // + scale_voltage_load_a(1.0), + scale_voltage_load_b(1.0), + scale_voltage_load_c(1.0), + // + scale_current_load_a(1.0), + scale_current_load_b(1.0), + scale_current_load_c(1.0), + // + scale_current_bypass_a(1.0), + scale_current_bypass_b(1.0), + scale_current_bypass_c(1.0), + // + // System Alarm + phase_alert_monitor(), + // + //digital inputs + digital_input_config(), //3001-3020 + + // + // + //fan control + fan_control(), + // + // + rms_filter_analog_signal(), + + signal_decompose(), + + pll_abc_input_voltage(), + + algorithm_source_references(), + + generator_abc(), + //generator_pwm(), +#if TYPECONTROL == VECTORCONTROL + regulator_voltage_load_dq(), + integrator_voltage_dq(), + reference_voltage_dq_intensity(), + regulator_current_limit(), + regulator_current_pfc(), + regulator_current_load_dq(), + referencer_current_bypass_dq(), +#endif + +#if TYPECONTROL == SCALARCONTROL + regulator_voltage_load_active_reactive(), + regulator_current_limit(), + regulator_current_pfc(), + current_regulator_active(), + current_regulator_reactive(), + current_referencer(), + regulator_dc_voltage(), +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + drc_voltage_controller(), + // + drc_reference_voltage_direct_intensity(), + // + drc_regulator_current_load(), + // + drc_referencer_current_bypass(), + // + drc_regulator_current_limit(), + drc_regulator_current_pfc(), + // + drc_voltage_decomposer(), +#endif + + + + // + timer_start(), + timer_stop(), + // + contactor() + // + {} + void selfupdata() + { + +#if TYPECONTROL == VECTORCONTROL + + regulator_current_limit.low_saturation = reference_voltage_rms * 0.57735; + regulator_current_limit.high_saturation = reference_voltage_high_limit_rms * 0.57735; +#endif + +#if TYPECONTROL == SCALARCONTROL + + regulator_current_limit.high_saturation = reference_voltage_rms * 0.57735; + regulator_current_limit.low_saturation = FP_ZERO; + regulator_current_pfc.high_saturation = reference_voltage_rms * 0.57735; + regulator_current_pfc.low_saturation = -reference_voltage_rms * 0.57735; + regulator_dc_voltage.low_saturation = -reference_voltage_rms * 0.57735; + +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + drc_regulator_current_limit.low_saturation = reference_voltage_rms * 0.57735; + drc_regulator_current_limit.high_saturation = reference_voltage_high_limit_rms * 0.57735; +#endif + // + }; +};//end SystemControlConfiguration + + + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_SYSTEMCONFIGURATOR_H_ */ diff --git a/SYSCTRL/SystemControl.cpp b/SYSCTRL/SystemControl.cpp new file mode 100644 index 0000000..7607a8e --- /dev/null +++ b/SYSCTRL/SystemControl.cpp @@ -0,0 +1,1302 @@ +/* + * SystemControl.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SystemControl.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +SystemControl::SystemControl(): + m_mode(SYSCTRL::SystemControl::UNDEFINED), + m_algorithm_executed(SYSCTRL::AlgorithmContext::OFF), + turnQ1On(false), + + m_decompose_voltage_input_a(), + m_decompose_voltage_input_b(), + m_decompose_voltage_input_c(), + // + m_decompose_voltage_load_a(), + m_decompose_voltage_load_b(), + m_decompose_voltage_load_c(), + // + m_decompose_current_load_a(), + m_decompose_current_load_b(), + m_decompose_current_load_c(), + // + m_decompose_current_cell_a(), + m_decompose_current_cell_b(), + m_decompose_current_cell_c(), + // + m_decompose_current_bypass_a(), + m_decompose_current_bypass_b(), + m_decompose_current_bypass_c(), + // + m_rms_filter_current_input_a(), + m_rms_filter_current_input_b(), + m_rms_filter_current_input_c(), + // + m_rms_filter_current_cell_a(), + m_rms_filter_current_cell_b(), + m_rms_filter_current_cell_c(), + // + m_rms_filter_current_load_a(), + m_rms_filter_current_load_b(), + m_rms_filter_current_load_c(), + // + m_rms_filter_voltage_input_a(), + m_rms_filter_voltage_input_b(), + m_rms_filter_voltage_input_c(), + // + m_rms_filter_voltage_load_a(), + m_rms_filter_voltage_load_b(), + m_rms_filter_voltage_load_c(), + // + m_rms_filter_current_bypass_a(), + m_rms_filter_current_bypass_b(), + m_rms_filter_current_bypass_c(), + // + m_zero_filter_voltage_input_a(), + m_zero_filter_voltage_input_b(), + m_zero_filter_voltage_input_c(), + // + m_zero_filter_current_input_a(), + m_zero_filter_current_input_b(), + m_zero_filter_current_input_c(), + // + m_zero_filter_current_cell_a(), + m_zero_filter_current_cell_b(), + m_zero_filter_current_cell_c(), + // + m_zero_filter_voltage_load_a(), + m_zero_filter_voltage_load_b(), + m_zero_filter_voltage_load_c(), + // + m_zero_filter_current_load_a(), + m_zero_filter_current_load_b(), + m_zero_filter_current_load_c(), + // + m_zero_filter_current_bypass_a(), + m_zero_filter_current_bypass_b(), + m_zero_filter_current_bypass_c(), + // + m_cell_dc_voltage_a_filter(), + m_cell_dc_voltage_b_filter(), + m_cell_dc_voltage_c_filter(), + // + m_relative_filter_voltage_input_a(), + m_relative_filter_voltage_input_b(), + m_relative_filter_voltage_input_c(), + // + m_pll_abc_input_voltage(), + // + //Harmonica Analyzer + m_voltage_input_a_harmonica_filter_5(), + m_voltage_input_b_harmonica_filter_5(), + m_voltage_input_c_harmonica_filter_5(), + // + //Phase Alert monitor + m_phase_alert_monitor(), + // + m_enable_work_trigger(), + m_system_fault_trigger(), + // + m_q1_control_trigger(), + m_km1_control_trigger(), + m_km2_control_trigger(), + m_km3_control_trigger(), + m_km11_control_on_off_trigger(), + m_km11t_control_on_trigger(), + m_km11t_control_off_trigger(), + m_km1_external_command_trigger(), + m_km3_external_command_trigger(), + m_q1_external_command_trigger(), + m_vs_protection_control_trigger(), + // + m_q1_control_fault(), + m_km1_control_fault(), + m_km2_control_fault(), + m_km3_control_fault(), + // + m_system_setup(), + m_system_configuration(), + m_environment(), + m_algorithm(m_environment), + m_fram_db(), + // + m_test_read_word(), + m_test_write_word(), + m_modbus_break_counter(0), + m_rubus(NUMBER_RUBUSCELLS), + hardware_analog_current_fault(), + // + _slow_loop_execute(&SYSCTRL::SystemControl::_slow_loop_undef), + _execute_additional(&SYSCTRL::SystemControl::_additional_undef), + _execute(&SYSCTRL::SystemControl::_execute_ubdef) +// +{}//CONSTRUCTOR + + +void SystemControl::setup() +{ + static bool _status = true; + if(m_mode == SYSCTRL::SystemControl::UNDEFINED) + { + + + m_environment.time_sample_control = m_system_setup.time_sample_control; + m_environment.time_prescale_slow = m_system_setup.time_prescale_slow; + m_environment.time_prescale_additional = m_system_setup.time_prescale_additional; + m_environment.counter_slow = m_system_setup.time_prescale_slow; + m_environment.counter_additional = m_system_setup.time_prescale_additional; + m_environment.time_sample_slow = ((float)m_environment.time_prescale_slow)*m_environment.time_sample_control; + m_environment.time_sample_additional = ((float)m_environment.time_prescale_additional)*m_environment.time_sample_control; + _status &= m_environment.time_sample_control != FP_ZERO ? true : false; + _status &= m_environment.time_sample_slow >= m_environment.time_sample_control ? true : false; + _status &= m_environment.time_sample_additional >= m_environment.time_sample_control ? true : false; + + + m_environment.digital_output_inverse.all = 0xffffffff; + m_environment.digital_output.all = 0xffffffff; + + + // + // Algorithm + // + m_algorithm.setup(); + _status &= m_algorithm.compare(SYSCTRL::AlgorithmContext::CONFIGURATE); + //<> + + + + // + // DIGITAL INPUTS + // + m_environment.remote_start.setup(m_environment.time_sample_slow); //3001 + m_environment.remote_stop.setup(m_environment.time_sample_slow); //3002 + m_environment.remote_reset.setup(m_environment.time_sample_slow); //3003 + m_environment.remote_e_stop.setup(m_environment.time_sample_slow); //3004 + m_environment.auxiliary_q1.setup(m_environment.time_sample_slow); //3005 + m_environment.bypass_ready.setup(m_environment.time_sample_slow); //3006 + m_environment.transformer_inv_over_temperature_alarm.setup(m_environment.time_sample_slow); //3007 + m_environment.local_e_stop.setup(m_environment.time_sample_slow); //3008 + m_environment.cabinet_door_interlocked.setup(m_environment.time_sample_slow); //3009 + m_environment.arc_and_fire.setup(m_environment.time_sample_slow); //3010 + m_environment.hw_dvr_ready.setup(m_environment.time_sample_slow); //3011 + m_environment.auxiliary_km2.setup(m_environment.time_sample_slow); //3012 + m_environment.auxiliary_km11.setup(m_environment.time_sample_slow); //3013 + m_environment.transformer_t_over_temperature_fault.setup(m_environment.time_sample_slow); //3014 + m_environment.control_power_supply_status.setup(m_environment.time_sample_slow); //3015 + m_environment.auxiliary_km1.setup(m_environment.time_sample_slow); //3016 + m_environment.auxiliary_km3.setup(m_environment.time_sample_slow); //3017 + m_environment.transformer_inv_over_temperature_fault.setup(m_environment.time_sample_slow); //3018 + m_environment.fan_fault.setup(m_environment.time_sample_slow); //3019 + m_environment.local_remote.setup(m_environment.time_sample_slow); //3020 + _status &= m_environment.remote_start.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3001 + _status &= m_environment.remote_stop.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3002 + _status &= m_environment.remote_reset.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3003 + _status &= m_environment.remote_e_stop.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3004 + _status &= m_environment.auxiliary_q1.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3005 + _status &= m_environment.bypass_ready.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3006 + _status &= m_environment.transformer_inv_over_temperature_alarm.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3007 + _status &= m_environment.local_e_stop.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3008 + _status &= m_environment.cabinet_door_interlocked.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3009 + _status &= m_environment.arc_and_fire.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE);//3010 + _status &= m_environment.hw_dvr_ready.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE);//3011 + _status &= m_environment.auxiliary_km2.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE);//3012 + _status &= m_environment.auxiliary_km11.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE);//3013 + _status &= m_environment.transformer_t_over_temperature_fault.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE);//3014 + _status &= m_environment.control_power_supply_status.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE);//3015 + _status &= m_environment.auxiliary_km1.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3016 + _status &= m_environment.auxiliary_km3.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3017 + _status &= m_environment.transformer_inv_over_temperature_fault.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3018 + _status &= m_environment.fan_fault.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3019 + _status &= m_environment.local_remote.compare(FLTSYSLIB::DigitalInputAntiNoise::CONFIGURATE); //3020 + //<> + + + + // + // Phase Alarm Monitor + // + m_phase_alert_monitor.setup(m_environment.time_sample_slow); + //<> + + + // + // FAN CONTROL + // + m_environment.fan_control.setup(m_environment.time_sample_slow); + _status &= m_environment.fan_control.compare(SYSCTRL::FanTimerControl::CONFIGURATE); + //<> + + + // + // RMS Filters + // + m_rms_filter_current_input_a.setup(m_environment.time_sample_additional); + m_rms_filter_current_input_b.setup(m_environment.time_sample_additional); + m_rms_filter_current_input_c.setup(m_environment.time_sample_additional); + _status &= m_rms_filter_current_input_a.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_input_b.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_input_c.compare(FLTSYSLIB::RMS::CONFIGURATE); + // + m_rms_filter_current_cell_a.setup(m_environment.time_sample_additional); + m_rms_filter_current_cell_b.setup(m_environment.time_sample_additional); + m_rms_filter_current_cell_c.setup(m_environment.time_sample_additional); + _status &= m_rms_filter_current_cell_a.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_cell_b.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_cell_c.compare(FLTSYSLIB::RMS::CONFIGURATE); + // + m_rms_filter_current_load_a.setup(m_environment.time_sample_additional); + m_rms_filter_current_load_b.setup(m_environment.time_sample_additional); + m_rms_filter_current_load_c.setup(m_environment.time_sample_additional); + _status &= m_rms_filter_current_load_a.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_load_b.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_load_c.compare(FLTSYSLIB::RMS::CONFIGURATE); + // + m_rms_filter_voltage_input_a.setup(m_environment.time_sample_additional); + m_rms_filter_voltage_input_b.setup(m_environment.time_sample_additional); + m_rms_filter_voltage_input_c.setup(m_environment.time_sample_additional); + _status &= m_rms_filter_voltage_input_a.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_voltage_input_b.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_voltage_input_c.compare(FLTSYSLIB::RMS::CONFIGURATE); + // + m_rms_filter_voltage_load_a.setup(m_environment.time_sample_additional); + m_rms_filter_voltage_load_b.setup(m_environment.time_sample_additional); + m_rms_filter_voltage_load_c.setup(m_environment.time_sample_additional); + _status &= m_rms_filter_voltage_load_a.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_voltage_load_b.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_voltage_load_c.compare(FLTSYSLIB::RMS::CONFIGURATE); + // + m_rms_filter_current_bypass_a.setup(m_environment.time_sample_additional); + m_rms_filter_current_bypass_b.setup(m_environment.time_sample_additional); + m_rms_filter_current_bypass_c.setup(m_environment.time_sample_additional); + _status &= m_rms_filter_current_bypass_a.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_bypass_b.compare(FLTSYSLIB::RMS::CONFIGURATE); + _status &= m_rms_filter_current_bypass_c.compare(FLTSYSLIB::RMS::CONFIGURATE); + //<> + + + // + // Zero Drift Analog Signals + // + m_zero_filter_voltage_input_a.setup(m_environment.time_sample_slow); + m_zero_filter_voltage_input_b.setup(m_environment.time_sample_slow); + m_zero_filter_voltage_input_c.setup(m_environment.time_sample_slow); + _status &= m_zero_filter_voltage_input_a.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_voltage_input_b.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_voltage_input_c.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + // + m_zero_filter_current_input_a.setup(m_environment.time_sample_slow); + m_zero_filter_current_input_b.setup(m_environment.time_sample_slow); + m_zero_filter_current_input_c.setup(m_environment.time_sample_slow); + _status &= m_zero_filter_current_input_a.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_input_b.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_input_c.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + // + m_zero_filter_current_cell_a.setup(m_environment.time_sample_slow); + m_zero_filter_current_cell_b.setup(m_environment.time_sample_slow); + m_zero_filter_current_cell_c.setup(m_environment.time_sample_slow); + _status &= m_zero_filter_current_cell_a.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_cell_b.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_cell_c.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + // + m_zero_filter_voltage_load_a.setup(m_environment.time_sample_slow); + m_zero_filter_voltage_load_b.setup(m_environment.time_sample_slow); + m_zero_filter_voltage_load_c.setup(m_environment.time_sample_slow); + _status &= m_zero_filter_voltage_load_a.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_voltage_load_b.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_voltage_load_c.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + // + m_zero_filter_current_load_a.setup(m_environment.time_sample_slow); + m_zero_filter_current_load_b.setup(m_environment.time_sample_slow); + m_zero_filter_current_load_c.setup(m_environment.time_sample_slow); + _status &= m_zero_filter_current_load_a.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_load_b.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_load_c.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + // + m_zero_filter_current_bypass_a.setup(m_environment.time_sample_slow); + m_zero_filter_current_bypass_b.setup(m_environment.time_sample_slow); + m_zero_filter_current_bypass_c.setup(m_environment.time_sample_slow); + _status &= m_zero_filter_current_bypass_a.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_bypass_b.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_zero_filter_current_bypass_c.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + //<> + + + + // + //Cell DC Voltage Filter + // + m_cell_dc_voltage_a_filter.setup(m_environment.time_sample_control); + m_cell_dc_voltage_b_filter.setup(m_environment.time_sample_control); + m_cell_dc_voltage_c_filter.setup(m_environment.time_sample_control); + _status &= m_cell_dc_voltage_a_filter.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_cell_dc_voltage_b_filter.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + _status &= m_cell_dc_voltage_c_filter.compare(FLTSYSLIB::FilterForth::CONFIGURATE); + //<> + + + + // + // Signal Decompose + // + +#if TYPECONTROL == VECTORCONTROL + // + m_decompose_voltage_input_a.setup(m_environment.time_sample_slow); + m_decompose_voltage_input_b.setup(m_environment.time_sample_slow); + m_decompose_voltage_input_c.setup(m_environment.time_sample_slow); + // + m_decompose_voltage_load_a.setup(m_environment.time_sample_slow); + m_decompose_voltage_load_b.setup(m_environment.time_sample_slow); + m_decompose_voltage_load_c.setup(m_environment.time_sample_slow); + // + m_decompose_current_load_a.setup(m_environment.time_sample_slow); + m_decompose_current_load_b.setup(m_environment.time_sample_slow); + m_decompose_current_load_c.setup(m_environment.time_sample_slow); + // + m_decompose_current_cell_a.setup(m_environment.time_sample_slow); + m_decompose_current_cell_b.setup(m_environment.time_sample_slow); + m_decompose_current_cell_c.setup(m_environment.time_sample_slow); + // + m_decompose_current_bypass_a.setup(m_environment.time_sample_slow); + m_decompose_current_bypass_b.setup(m_environment.time_sample_slow); + m_decompose_current_bypass_c.setup(m_environment.time_sample_slow); + // +#endif +#if TYPECONTROL == SCALARCONTROL + m_decompose_voltage_input_a.setup(m_environment.time_sample_control); + m_decompose_voltage_input_b.setup(m_environment.time_sample_control); + m_decompose_voltage_input_c.setup(m_environment.time_sample_control); + // + m_decompose_voltage_load_a.setup(m_environment.time_sample_control); + m_decompose_voltage_load_b.setup(m_environment.time_sample_control); + m_decompose_voltage_load_c.setup(m_environment.time_sample_control); + // + m_decompose_current_load_a.setup(m_environment.time_sample_control); + m_decompose_current_load_b.setup(m_environment.time_sample_control); + m_decompose_current_load_c.setup(m_environment.time_sample_control); + // + m_decompose_current_cell_a.setup(m_environment.time_sample_control); + m_decompose_current_cell_b.setup(m_environment.time_sample_control); + m_decompose_current_cell_c.setup(m_environment.time_sample_control); + // + m_decompose_current_bypass_a.setup(m_environment.time_sample_control); + m_decompose_current_bypass_b.setup(m_environment.time_sample_control); + m_decompose_current_bypass_c.setup(m_environment.time_sample_control); +#endif + //<> + + + + // + // Relative Voltage Input + // + m_relative_filter_voltage_input_a.setup(m_system_setup.relative_voltage_input); + m_relative_filter_voltage_input_b.setup(m_system_setup.relative_voltage_input); + m_relative_filter_voltage_input_c.setup(m_system_setup.relative_voltage_input); + _status &= m_relative_filter_voltage_input_a.compare(SYSCTRL::SignalRelative::CONFIGURATE); + _status &= m_relative_filter_voltage_input_b.compare(SYSCTRL::SignalRelative::CONFIGURATE); + _status &= m_relative_filter_voltage_input_c.compare(SYSCTRL::SignalRelative::CONFIGURATE); + //<> + + + + // + // PLL Input Voltage + // + m_pll_abc_input_voltage.setup(m_environment.time_sample_control); + _status &= m_pll_abc_input_voltage.compare(FLTSYSLIB::PLLABCDVR::CONFIGURATE); + //<> + + + // + // Generator ABC + // + m_environment.generator_abc.setup(m_environment.time_sample_control); + //_status &= m_environment.generator_abc.compare(FLTSYSLIB::GeneratorABC::CONFIGURATE); + //<> + + + // + // Reference PWM-Generator + // + //m_environment.generator_pwm.setup(m_environment.time_sample_control); + //<> + + + // + // Harmonica Analyzer + // + m_voltage_input_a_harmonica_filter_5.setup(m_environment.time_sample_control); + m_voltage_input_b_harmonica_filter_5.setup(m_environment.time_sample_control); + m_voltage_input_c_harmonica_filter_5.setup(m_environment.time_sample_control); + _status &= m_voltage_input_a_harmonica_filter_5.compare(FLTSYSLIB::HarmonicaFilter4Order::CONFIGURATE); + _status &= m_voltage_input_b_harmonica_filter_5.compare(FLTSYSLIB::HarmonicaFilter4Order::CONFIGURATE); + _status &= m_voltage_input_c_harmonica_filter_5.compare(FLTSYSLIB::HarmonicaFilter4Order::CONFIGURATE); + //<> + + + + // + // Regulators + // +#if TYPECONTROL == VECTORCONTROL + m_environment.regulator_voltage_load_direct.setup(m_environment.time_sample_control); + m_environment.regulator_voltage_load_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_voltage_load_direct.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_voltage_load_quadrature.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.integrator_direct.setup(m_environment.time_sample_control); + m_environment.integrator_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.integrator_direct.compare(FLTSYSLIB::Integrator::CONFIGURATE); + _status &= m_environment.integrator_quadrature.compare(FLTSYSLIB::Integrator::CONFIGURATE); + // + m_environment.reference_voltage_direct_intensity.setup(m_environment.time_sample_control); + _status &= m_environment.reference_voltage_direct_intensity.compare(FLTSYSLIB::Filter::CONFIGURATE); + // +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_PI + m_environment.regulator_current_load_direct.setup(m_environment.time_sample_control); + m_environment.regulator_current_load_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_current_load_direct.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_current_load_quadrature.compare(FLTSYSLIB::PIController::CONFIGURATE); +#endif + // + m_environment.referencer_current_bypass_direct.setup(m_environment.time_sample_control); + m_environment.referencer_current_bypass_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.referencer_current_bypass_direct.compare(FLTSYSLIB::IController::CONFIGURATE); + _status &= m_environment.referencer_current_bypass_quadrature.compare(FLTSYSLIB::IController::CONFIGURATE); + // + m_environment.regulator_current_limit.setup(m_environment.time_sample_control); + m_environment.regulator_current_pfc.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_current_limit.compare(FLTSYSLIB::IController::CONFIGURATE); + _status &= m_environment.regulator_current_pfc.compare(FLTSYSLIB::PIController::CONFIGURATE); +#endif + +#if TYPECONTROL == SCALARCONTROL + m_environment.regulator_voltage_load_a_active.setup(m_environment.time_sample_control); + m_environment.regulator_voltage_load_a_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_voltage_load_a_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_voltage_load_a_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.regulator_voltage_load_b_active.setup(m_environment.time_sample_control); + m_environment.regulator_voltage_load_b_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_voltage_load_b_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_voltage_load_b_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.regulator_voltage_load_c_active.setup(m_environment.time_sample_control); + m_environment.regulator_voltage_load_c_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_voltage_load_c_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_voltage_load_c_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.regulator_current_limit_a.setup(m_environment.time_sample_control); + m_environment.regulator_current_pfc_a.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_current_limit_a.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_current_pfc_a.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.regulator_current_limit_b.setup(m_environment.time_sample_control); + m_environment.regulator_current_pfc_b.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_current_limit_b.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_current_pfc_b.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.regulator_current_limit_c.setup(m_environment.time_sample_control); + m_environment.regulator_current_pfc_c.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_current_limit_c.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_current_pfc_c.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.current_regulator_a_active.setup(m_environment.time_sample_control); + m_environment.current_regulator_a_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.current_regulator_a_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.current_regulator_a_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.current_regulator_b_active.setup(m_environment.time_sample_control); + m_environment.current_regulator_b_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.current_regulator_b_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.current_regulator_b_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.current_regulator_c_active.setup(m_environment.time_sample_control); + m_environment.current_regulator_c_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.current_regulator_c_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.current_regulator_c_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.current_referencer_a_active.setup(m_environment.time_sample_control); + m_environment.current_referencer_a_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.current_referencer_a_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.current_referencer_a_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.current_referencer_b_active.setup(m_environment.time_sample_control); + m_environment.current_referencer_b_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.current_referencer_b_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.current_referencer_b_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.current_referencer_c_active.setup(m_environment.time_sample_control); + m_environment.current_referencer_c_reactive.setup(m_environment.time_sample_control); + _status &= m_environment.current_referencer_c_active.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.current_referencer_c_reactive.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.regulator_dc_a.setup(m_environment.time_sample_control); + m_environment.regulator_dc_b.setup(m_environment.time_sample_control); + m_environment.regulator_dc_c.setup(m_environment.time_sample_control); + _status &= m_environment.regulator_dc_a.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_dc_b.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.regulator_dc_c.compare(FLTSYSLIB::PIController::CONFIGURATE); +#endif + // + //<> + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + m_environment.drc_positive_voltage_controller_direct.setup(m_environment.time_sample_control); + m_environment.drc_positive_voltage_controller_quadrature.setup(m_environment.time_sample_control); + m_environment.drc_negative_voltage_controller_direct.setup(m_environment.time_sample_control); + m_environment.drc_negative_voltage_controller_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.drc_positive_voltage_controller_direct.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.drc_positive_voltage_controller_quadrature.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.drc_negative_voltage_controller_direct.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.drc_negative_voltage_controller_quadrature.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.drc_reference_voltage_direct_intensity.setup(m_environment.time_sample_control); + _status &= m_environment.drc_reference_voltage_direct_intensity.compare(FLTSYSLIB::FilterSecond::CONFIGURATE); + // + m_environment.drc_regulator_current_load_direct.setup(m_environment.time_sample_control); + m_environment.drc_regulator_current_load_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.drc_regulator_current_load_direct.compare(FLTSYSLIB::PIController::CONFIGURATE); + _status &= m_environment.drc_regulator_current_load_quadrature.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.drc_referencer_current_bypass_direct.setup(m_environment.time_sample_control); + m_environment.drc_referencer_current_bypass_quadrature.setup(m_environment.time_sample_control); + _status &= m_environment.drc_referencer_current_bypass_direct.compare(FLTSYSLIB::IController::CONFIGURATE); + _status &= m_environment.drc_referencer_current_bypass_quadrature.compare(FLTSYSLIB::IController::CONFIGURATE); + // + m_environment.drc_regulator_current_limit.setup(m_environment.time_sample_control); + m_environment.drc_regulator_current_pfc.setup(m_environment.time_sample_control); + _status &= m_environment.drc_regulator_current_limit.compare(FLTSYSLIB::IController::CONFIGURATE); + _status &= m_environment.drc_regulator_current_pfc.compare(FLTSYSLIB::PIController::CONFIGURATE); + // + m_environment.drc_direct_voltage_decomposer.setup(m_environment.time_sample_control); + m_environment.drc_back_voltage_decomposer.setup(m_environment.time_sample_control); + // +#endif + //<> + + + // + // Timers + // + m_environment.timer_start.setup(m_environment.time_sample_control); + m_environment.timer_stop.setup(m_environment.time_sample_control); + _status &= m_environment.timer_start.compare(FLTSYSLIB::FTimer::CONFIGURATE); + _status &= m_environment.timer_stop.compare(FLTSYSLIB::FTimer::CONFIGURATE); + //<> + + + // + // Contactor Control Fault + // + m_q1_control_fault.setup(m_environment.time_sample_slow); + m_km1_control_fault.setup(m_environment.time_sample_slow); + m_km2_control_fault.setup(m_environment.time_sample_slow); + m_km3_control_fault.setup(m_environment.time_sample_slow); + + + + if(_status) + { + + m_mode = SYSCTRL::SystemControl::CONFIGURATE; +// m_environment.state_register.current.bit.stopped = 1; +// m_environment.state_register.privious.bit.stopped = 1; +// m_environment.state_register.shadow.bit.stopped = 1; + m_algorithm_executed = m_algorithm.get_algorithm(); + // + }//if + // + }//if + // +}//setup() +// +void SystemControl::configure() +{ + static bool _status = true; + //if(m_mode == SYSCTRL::SystemControl::CONFIGURATE) + { + + + // + // References + // +#if TYPECONTROL == VECTORCONTROL + // + m_environment.current_reference_limit = m_system_configuration.reference_current_limit_rms; + m_environment.current_reference_pfc = m_system_configuration.reference_current_pfc_rms; + // + m_environment.voltage_reference_load_direct = m_system_configuration.reference_voltage_rms; + m_environment.voltage_reference_limit_high = m_system_configuration.reference_voltage_high_limit_rms; + m_environment.voltage_reference_load_quadrature = FP_ZERO; + m_environment.voltage_reference_dc_cell = m_system_configuration.reference_voltage_dc; + // + _status &= (m_environment.current_reference_limit > FP_ZERO) ? true : false; + _status &= (m_environment.voltage_reference_load_direct > FP_ZERO) ? true : false; + _status &= (m_environment.voltage_reference_dc_cell > FP_ZERO) ? true : false; + // +#endif +#if TYPECONTROL == SCALARCONTROL + m_environment.phase_control.common_ref.current_limit_rms = m_system_configuration.reference_current_limit_rms; + m_environment.phase_control.common_ref.current_limit_ampl = 1.41421 * m_environment.phase_control.common_ref.current_limit_rms; + _status &= (m_environment.phase_control.common_ref.current_limit_rms > FP_ZERO) ? true : false; + // + m_environment.phase_control.common_ref.current_pfc_rms = m_system_configuration.reference_current_pfc_rms; + m_environment.phase_control.common_ref.current_pfc_ampl = 1.41421 * m_environment.phase_control.common_ref.current_pfc_rms; + // + m_environment.phase_control.common_ref.voltage_module_rms = m_system_configuration.reference_voltage_rms; + m_environment.phase_control.common_ref.voltage_module_ampl = 1.41421 * m_environment.phase_control.common_ref.voltage_module_rms; + _status &= (m_environment.phase_control.common_ref.voltage_module_rms > FP_ZERO) ? true : false; + // + m_environment.phase_control.common_ref.voltage_dc = 5.0 * 950.0; +#endif + //<> + + + // + // Algorithm Control + // + m_environment.algorithm_control.all = m_system_configuration.algorithm_control.all; + // preset control bits + SYSCTRL::MonitorDigitalInputSignal::preset(m_environment.algorithm_control.signal.enable_current_limit, m_environment.enable_current_limit); + SYSCTRL::MonitorDigitalInputSignal::preset(m_environment.algorithm_control.signal.enable_pfc, m_environment.enable_pfc); + SYSCTRL::MonitorDigitalInputSignal::preset(m_environment.algorithm_control.signal.enable_harmonica, m_environment.enable_harmonica); + SYSCTRL::MonitorDigitalInputSignal::preset(m_environment.algorithm_control.signal.enable_auto_offset, m_environment.enable_auto_offset); +#if TYPECONTROL == SCALARCONTROL + m_environment.phase_control.common_control_bit.signal.enable_current_limit = m_environment.enable_current_limit.signal.is_on; + m_environment.phase_control.common_control_bit.signal.enable_pfc = m_environment.enable_pfc.signal.is_on; + m_environment.phase_control.common_control_bit.signal.enable_harmonica = m_environment.enable_harmonica.signal.is_on; +#endif + //<> + + + + // + // High Voltage Cell + // + m_environment.hardware.configure(m_system_configuration.hardware); + _status &= (m_environment.hardware.level >= 1) && (m_environment.hardware.level <= 8) ? true : false; + +// m_environment.m_minimal_input_voltage_level = m_system_configuration.minimal_input_voltage_level; +// _status &= m_environment.m_minimal_input_voltage_level > FP_ZERO ? true : false; + + + + // + // Scale Analog Signals Setup + // + m_environment.scale_voltage_grid_a = m_system_configuration.scale_voltage_input_a; + m_environment.scale_voltage_grid_b = m_system_configuration.scale_voltage_input_b; + m_environment.scale_voltage_grid_c = m_system_configuration.scale_voltage_input_c; + _status &= m_environment.scale_voltage_grid_a > FP_ZERO ? true : false; + _status &= m_environment.scale_voltage_grid_b > FP_ZERO ? true : false; + _status &= m_environment.scale_voltage_grid_c > FP_ZERO ? true : false; + // + m_environment.scale_current_input_a = m_system_configuration.scale_current_input_a; + m_environment.scale_current_input_b = m_system_configuration.scale_current_input_b; + m_environment.scale_current_input_c = m_system_configuration.scale_current_input_c; + _status &= m_environment.scale_current_input_a > FP_ZERO ? true : false; + _status &= m_environment.scale_current_input_b > FP_ZERO ? true : false; + _status &= m_environment.scale_current_input_c > FP_ZERO ? true : false; + // + m_environment.scale_voltage_load_a = m_system_configuration.scale_voltage_load_a; + m_environment.scale_voltage_load_b = m_system_configuration.scale_voltage_load_b; + m_environment.scale_voltage_load_c = m_system_configuration.scale_voltage_load_c; + _status &= m_environment.scale_voltage_load_a > FP_ZERO ? true : false; + _status &= m_environment.scale_voltage_load_b > FP_ZERO ? true : false; + _status &= m_environment.scale_voltage_load_c > FP_ZERO ? true : false; + // + m_environment.scale_current_load_a = m_system_configuration.scale_current_load_a; + m_environment.scale_current_load_b = m_system_configuration.scale_current_load_b; + m_environment.scale_current_load_c = m_system_configuration.scale_current_load_c; + _status &= m_environment.scale_current_load_a > FP_ZERO ? true : false; + _status &= m_environment.scale_current_load_b > FP_ZERO ? true : false; + _status &= m_environment.scale_current_load_c > FP_ZERO ? true : false; + // + m_environment.scale_current_cell_a = m_system_configuration.scale_current_cell_a; + m_environment.scale_current_cell_b = m_system_configuration.scale_current_cell_b; + m_environment.scale_current_cell_c = m_system_configuration.scale_current_cell_c; + _status &= m_environment.scale_current_cell_a > FP_ZERO ? true : false; + _status &= m_environment.scale_current_cell_b > FP_ZERO ? true : false; + _status &= m_environment.scale_current_cell_c > FP_ZERO ? true : false; + // + m_environment.scale_current_bypass_a = m_system_configuration.scale_current_bypass_a; + m_environment.scale_current_bypass_b = m_system_configuration.scale_current_bypass_b; + m_environment.scale_current_bypass_c = m_system_configuration.scale_current_bypass_c; + _status &= m_environment.scale_current_bypass_a > FP_ZERO ? true : false; + _status &= m_environment.scale_current_bypass_b > FP_ZERO ? true : false; + _status &= m_environment.scale_current_bypass_c > FP_ZERO ? true : false; + //<> + + + + // + // Static Offset of Analog Signals + // + m_environment.offset_voltage_grid_static_a = FP_ZERO; + m_environment.offset_voltage_grid_static_b = FP_ZERO; + m_environment.offset_voltage_grid_static_c = FP_ZERO; + // + m_environment.offset_current_input_static_a = FP_ZERO; + m_environment.offset_current_input_static_b = FP_ZERO; + m_environment.offset_current_input_static_c = FP_ZERO; + // + m_environment.offset_current_cell_static_a = FP_ZERO; + m_environment.offset_current_cell_static_b = FP_ZERO; + m_environment.offset_current_cell_static_c = FP_ZERO; + // + m_environment.offset_voltage_load_static_a = FP_ZERO; + m_environment.offset_voltage_load_static_b = FP_ZERO; + m_environment.offset_voltage_load_static_c = FP_ZERO; + // + m_environment.offset_current_load_static_a = FP_ZERO; + m_environment.offset_current_load_static_b = FP_ZERO; + m_environment.offset_current_load_static_c = FP_ZERO; + // + m_environment.offset_current_bypass_static_a = FP_ZERO; + m_environment.offset_current_bypass_static_b = FP_ZERO; + m_environment.offset_current_bypass_static_c = FP_ZERO; + //<> + + + + // + // RMS Filters Setup + // + m_rms_filter_current_input_a.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_input_b.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_input_c.configure(m_system_configuration.rms_filter_analog_signal); + _status &= m_rms_filter_current_input_a.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_input_b.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_input_c.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + // + m_rms_filter_current_cell_a.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_cell_b.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_cell_c.configure(m_system_configuration.rms_filter_analog_signal); + _status &= m_rms_filter_current_cell_a.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_cell_b.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_cell_c.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + + m_rms_filter_current_load_a.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_load_b.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_load_c.configure(m_system_configuration.rms_filter_analog_signal); + _status &= m_rms_filter_current_load_a.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_load_b.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_load_c.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + + m_rms_filter_voltage_input_a.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_voltage_input_b.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_voltage_input_c.configure(m_system_configuration.rms_filter_analog_signal); + _status &= m_rms_filter_voltage_input_a.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_voltage_input_b.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_voltage_input_c.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + // + m_rms_filter_voltage_load_a.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_voltage_load_b.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_voltage_load_c.configure(m_system_configuration.rms_filter_analog_signal); + _status &= m_rms_filter_voltage_load_a.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_voltage_load_b.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_voltage_load_c.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + // + m_rms_filter_current_bypass_a.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_bypass_b.configure(m_system_configuration.rms_filter_analog_signal); + m_rms_filter_current_bypass_c.configure(m_system_configuration.rms_filter_analog_signal); + _status &= m_rms_filter_current_bypass_a.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_bypass_b.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + _status &= m_rms_filter_current_bypass_c.compare(FLTSYSLIB::RMSFSO::OPERATIONAL); + //<> + + + // + // Algorithm + // + m_algorithm.configure(); + _status &= m_algorithm.compare(SYSCTRL::AlgorithmContext::OPERATIONAL); + //<> + + + + // + // Zero Drift Current Input + // + m_zero_filter_voltage_input_a.configure(m_system_configuration.zero_filter); + m_zero_filter_voltage_input_b.configure(m_system_configuration.zero_filter); + m_zero_filter_voltage_input_c.configure(m_system_configuration.zero_filter); + _status &= m_zero_filter_voltage_input_a.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_voltage_input_b.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_voltage_input_c.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + // + m_zero_filter_current_input_a.configure(m_system_configuration.zero_filter); + m_zero_filter_current_input_b.configure(m_system_configuration.zero_filter); + m_zero_filter_current_input_c.configure(m_system_configuration.zero_filter); + _status &= m_zero_filter_current_input_a.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_input_b.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_input_c.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + // + m_zero_filter_current_cell_a.configure(m_system_configuration.zero_filter); + m_zero_filter_current_cell_b.configure(m_system_configuration.zero_filter); + m_zero_filter_current_cell_c.configure(m_system_configuration.zero_filter); + _status &= m_zero_filter_current_cell_a.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_cell_b.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_cell_c.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + // + m_zero_filter_voltage_load_a.configure(m_system_configuration.zero_filter); + m_zero_filter_voltage_load_b.configure(m_system_configuration.zero_filter); + m_zero_filter_voltage_load_c.configure(m_system_configuration.zero_filter); + _status &= m_zero_filter_voltage_load_a.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_voltage_load_b.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_voltage_load_c.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + // + m_zero_filter_current_load_a.configure(m_system_configuration.zero_filter); + m_zero_filter_current_load_b.configure(m_system_configuration.zero_filter); + m_zero_filter_current_load_c.configure(m_system_configuration.zero_filter); + _status &= m_zero_filter_current_load_a.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_load_b.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_load_c.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + // + m_zero_filter_current_bypass_a.configure(m_system_configuration.zero_filter); + m_zero_filter_current_bypass_b.configure(m_system_configuration.zero_filter); + m_zero_filter_current_bypass_c.configure(m_system_configuration.zero_filter); + _status &= m_zero_filter_current_bypass_a.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_bypass_b.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_zero_filter_current_bypass_c.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + //<> + + + // + // Cell DC Voltage Filter + // + m_cell_dc_voltage_a_filter.configure(m_system_configuration.cell_dc_voltage_filter); + m_cell_dc_voltage_b_filter.configure(m_system_configuration.cell_dc_voltage_filter); + m_cell_dc_voltage_c_filter.configure(m_system_configuration.cell_dc_voltage_filter); + _status &= m_cell_dc_voltage_a_filter.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_cell_dc_voltage_b_filter.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + _status &= m_cell_dc_voltage_c_filter.compare(FLTSYSLIB::FilterForth::OPERATIONAL); + //<> + + + + // + // Relative + // + m_relative_filter_voltage_input_a.configure(m_system_configuration.relative_voltage_input); + m_relative_filter_voltage_input_b.configure(m_system_configuration.relative_voltage_input); + m_relative_filter_voltage_input_c.configure(m_system_configuration.relative_voltage_input); + _status &= m_relative_filter_voltage_input_a.compare(SYSCTRL::SignalRelative::OPERATIONAL); + _status &= m_relative_filter_voltage_input_b.compare(SYSCTRL::SignalRelative::OPERATIONAL); + _status &= m_relative_filter_voltage_input_c.compare(SYSCTRL::SignalRelative::OPERATIONAL); + //<> + + + + // + // PLL ABC + // + m_pll_abc_input_voltage.configure(m_system_configuration.pll_abc_input_voltage); + _status &= m_pll_abc_input_voltage.compare(FLTSYSLIB::PLLABCDVR::OPERATIONAL); + //<> + + + // + // Signal Decompose + // + m_decompose_voltage_input_a.configure(m_system_configuration.signal_decompose); + m_decompose_voltage_input_b.configure(m_system_configuration.signal_decompose); + m_decompose_voltage_input_c.configure(m_system_configuration.signal_decompose); + // + m_decompose_voltage_load_a.configure(m_system_configuration.signal_decompose); + m_decompose_voltage_load_b.configure(m_system_configuration.signal_decompose); + m_decompose_voltage_load_c.configure(m_system_configuration.signal_decompose); + // + m_decompose_current_load_a.configure(m_system_configuration.signal_decompose); + m_decompose_current_load_b.configure(m_system_configuration.signal_decompose); + m_decompose_current_load_c.configure(m_system_configuration.signal_decompose); + // + m_decompose_current_cell_a.configure(m_system_configuration.signal_decompose); + m_decompose_current_cell_b.configure(m_system_configuration.signal_decompose); + m_decompose_current_cell_c.configure(m_system_configuration.signal_decompose); + // + m_decompose_current_bypass_a.configure(m_system_configuration.signal_decompose); + m_decompose_current_bypass_b.configure(m_system_configuration.signal_decompose); + m_decompose_current_bypass_c.configure(m_system_configuration.signal_decompose); + //<> + + + + + // + // DIGITAL INPUTS + // + m_environment.remote_start.configure(m_system_configuration.digital_input_config); //3001 + m_environment.remote_stop.configure(m_system_configuration.digital_input_config); //3002 + m_environment.remote_reset.configure(m_system_configuration.digital_input_config); //3003 + m_environment.remote_e_stop.configure(m_system_configuration.digital_input_config); //3004 + m_environment.auxiliary_q1.configure(m_system_configuration.digital_input_config); //3005 + m_environment.bypass_ready.configure(m_system_configuration.digital_input_config); //3006 + m_environment.transformer_inv_over_temperature_alarm.configure(m_system_configuration.digital_input_config); //3007 + m_environment.local_e_stop.configure(m_system_configuration.digital_input_config); //3008 + m_environment.cabinet_door_interlocked.configure(m_system_configuration.digital_input_config); //3009 + m_environment.arc_and_fire.configure(m_system_configuration.digital_input_config);//3010 + m_environment.hw_dvr_ready.configure(m_system_configuration.digital_input_config); //3011 + m_environment.auxiliary_km2.configure(m_system_configuration.digital_input_config); //3012 + m_environment.auxiliary_km11.configure(m_system_configuration.digital_input_config); //3013 + m_environment.transformer_t_over_temperature_fault.configure(m_system_configuration.digital_input_config);//3014 + m_environment.control_power_supply_status.configure(m_system_configuration.digital_input_config);//3015 + m_environment.auxiliary_km1.configure(m_system_configuration.digital_input_config); //3016 + m_environment.auxiliary_km3.configure(m_system_configuration.digital_input_config); //3017 + m_environment.transformer_inv_over_temperature_fault.configure(m_system_configuration.digital_input_config); //3018 + m_environment.fan_fault.configure(m_system_configuration.digital_input_config); //3019 + m_environment.local_remote.configure(m_system_configuration.digital_input_config); //3020 + _status &= m_environment.remote_start.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3001 + _status &= m_environment.remote_stop.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3002 + _status &= m_environment.remote_reset.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3003 + _status &= m_environment.remote_e_stop.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3004 + _status &= m_environment.auxiliary_q1.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3005 + _status &= m_environment.bypass_ready.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3006 + _status &= m_environment.transformer_inv_over_temperature_alarm.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3007 + _status &= m_environment.local_e_stop.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3008 + _status &= m_environment.cabinet_door_interlocked.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3009 + _status &= m_environment.arc_and_fire.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL);//3010 + _status &= m_environment.hw_dvr_ready.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3011 + _status &= m_environment.auxiliary_km2.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3012 + _status &= m_environment.auxiliary_km11.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3013 + _status &= m_environment.transformer_t_over_temperature_fault.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL);//3014 + _status &= m_environment.control_power_supply_status.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL);//3015 + _status &= m_environment.auxiliary_km1.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3016 + _status &= m_environment.auxiliary_km3.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3017 + _status &= m_environment.transformer_inv_over_temperature_fault.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3018 + _status &= m_environment.fan_fault.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3019 + _status &= m_environment.local_remote.compare(FLTSYSLIB::DigitalInputAntiNoise::OPERATIONAL); //3020 + //<> + + + + // + // Phase Alarm monitor + // + m_phase_alert_monitor.configure(m_system_configuration.phase_alert_monitor); + //<> + + + + // + // FAN CONTROL + // + m_environment.fan_control.configure(m_system_configuration.fan_control); + _status &= m_environment.fan_control.compare(SYSCTRL::FanTimerControl::OPERATIONAL); + //<> + + + + // + // Generator ABC + // + m_environment.generator_abc.configure(m_system_configuration.generator_abc); + //_status &= m_environment.generator_abc.compare(FLTSYSLIB::GeneratorABC::OPERATIONAL); + //<> + + // + // Algorithm Source References + // + m_environment.algorithm_source_references = m_system_configuration.algorithm_source_references; + + + // + // Reference PWM-Generator + // + //m_environment.generator_pwm.configure(m_system_configuration.generator_pwm); + //<> + + + // + // Harmonica Analyzer + // + m_voltage_input_a_harmonica_filter_5.configure(m_system_configuration.ph_harmonica_5); + m_voltage_input_b_harmonica_filter_5.configure(m_system_configuration.ph_harmonica_5); + m_voltage_input_c_harmonica_filter_5.configure(m_system_configuration.ph_harmonica_5); + _status &= m_voltage_input_a_harmonica_filter_5.compare(FLTSYSLIB::HarmonicaFilter4Order::OPERATIONAL); + _status &= m_voltage_input_b_harmonica_filter_5.compare(FLTSYSLIB::HarmonicaFilter4Order::OPERATIONAL); + _status &= m_voltage_input_c_harmonica_filter_5.compare(FLTSYSLIB::HarmonicaFilter4Order::OPERATIONAL); + //<> + + + + // + // Regulators + // +#if TYPECONTROL == VECTORCONTROL + m_environment.regulator_voltage_load_direct.configure(m_system_configuration.regulator_voltage_load_dq); + m_environment.regulator_voltage_load_quadrature.configure(m_system_configuration.regulator_voltage_load_dq); + _status &= m_environment.regulator_voltage_load_direct.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_voltage_load_quadrature.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.integrator_direct.configure(m_system_configuration.integrator_voltage_dq); + m_environment.integrator_quadrature.configure(m_system_configuration.integrator_voltage_dq); + _status &= m_environment.integrator_direct.compare(FLTSYSLIB::Integrator::OPERATIONAL); + _status &= m_environment.integrator_quadrature.compare(FLTSYSLIB::Integrator::OPERATIONAL); + // + m_environment.reference_voltage_direct_intensity.configure(m_system_configuration.reference_voltage_dq_intensity); + _status &= m_environment.reference_voltage_direct_intensity.compare(FLTSYSLIB::Filter::OPERATIONAL); + // +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_P + m_environment.regulator_current_load_direct.configure(m_system_configuration.regulator_current_load_dq); + m_environment.regulator_current_load_quadrature.configure(m_system_configuration.regulator_current_load_dq); + _status &= m_environment.regulator_current_load_direct.compare(FLTSYSLIB::PController::OPERATIONAL); + _status &= m_environment.regulator_current_load_quadrature.compare(FLTSYSLIB::PController::OPERATIONAL); +#endif +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_PI + m_environment.regulator_current_load_direct.configure(m_system_configuration.regulator_current_load_dq); + m_environment.regulator_current_load_quadrature.configure(m_system_configuration.regulator_current_load_dq); + _status &= m_environment.regulator_current_load_direct.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_current_load_quadrature.compare(FLTSYSLIB::PIController::OPERATIONAL); +#endif + // + m_environment.referencer_current_bypass_direct.configure(m_system_configuration.referencer_current_bypass_dq); + m_environment.referencer_current_bypass_quadrature.configure(m_system_configuration.referencer_current_bypass_dq); + _status &= m_environment.referencer_current_bypass_direct.compare(FLTSYSLIB::IController::OPERATIONAL); + _status &= m_environment.referencer_current_bypass_quadrature.compare(FLTSYSLIB::IController::OPERATIONAL); + // + m_system_configuration.regulator_current_limit.low_saturation = m_environment.voltage_reference_load_direct * 0.57735; + m_system_configuration.regulator_current_limit.high_saturation = m_environment.voltage_reference_limit_high * 0.57735; + m_environment.regulator_current_limit.configure(m_system_configuration.regulator_current_limit); + m_environment.regulator_current_pfc.configure(m_system_configuration.regulator_current_pfc); + _status &= m_environment.regulator_current_limit.compare(FLTSYSLIB::IController::OPERATIONAL); + _status &= m_environment.regulator_current_pfc.compare(FLTSYSLIB::PIController::OPERATIONAL); +#endif + +#if TYPECONTROL == SCALARCONTROL + m_environment.regulator_voltage_load_a_reactive.configure(m_system_configuration.regulator_voltage_load_active_reactive); + _status &= m_environment.regulator_voltage_load_a_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + m_environment.regulator_voltage_load_b_reactive.configure(m_system_configuration.regulator_voltage_load_active_reactive); + _status &= m_environment.regulator_voltage_load_b_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + m_environment.regulator_voltage_load_c_reactive.configure(m_system_configuration.regulator_voltage_load_active_reactive); + _status &= m_environment.regulator_voltage_load_c_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_system_configuration.regulator_voltage_load_active_reactive.low_saturation = FP_ZERO; + m_environment.regulator_voltage_load_a_active.configure(m_system_configuration.regulator_voltage_load_active_reactive); + _status &= m_environment.regulator_voltage_load_a_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + m_environment.regulator_voltage_load_b_active.configure(m_system_configuration.regulator_voltage_load_active_reactive); + _status &= m_environment.regulator_voltage_load_b_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + m_environment.regulator_voltage_load_c_active.configure(m_system_configuration.regulator_voltage_load_active_reactive); + _status &= m_environment.regulator_voltage_load_c_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + + + // + //m_system_configuration.regulator_current_limit.high_saturation = m_system_configuration.reference_voltage_rms; + //m_system_configuration.regulator_current_limit.low_saturation = FP_ZERO; + //m_system_configuration.regulator_current_pfc.high_saturation = m_system_configuration.reference_voltage_rms; + //m_system_configuration.regulator_current_pfc.low_saturation = -m_system_configuration.reference_voltage_rms; + + m_environment.regulator_current_limit_a.configure(m_system_configuration.regulator_current_limit); + m_environment.regulator_current_pfc_a.configure(m_system_configuration.regulator_current_pfc); + _status &= m_environment.regulator_current_limit_a.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_current_pfc_a.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.regulator_current_limit_b.configure(m_system_configuration.regulator_current_limit); + m_environment.regulator_current_pfc_b.configure(m_system_configuration.regulator_current_pfc); + _status &= m_environment.regulator_current_limit_b.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_current_pfc_b.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.regulator_current_limit_c.configure(m_system_configuration.regulator_current_limit); + m_environment.regulator_current_pfc_c.configure(m_system_configuration.regulator_current_pfc); + _status &= m_environment.regulator_current_limit_c.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_current_pfc_c.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.current_regulator_a_active.configure(m_system_configuration.current_regulator_active); + m_environment.current_regulator_a_reactive.configure(m_system_configuration.current_regulator_reactive); + _status &= m_environment.current_regulator_a_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.current_regulator_a_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.current_regulator_b_active.configure(m_system_configuration.current_regulator_active); + m_environment.current_regulator_b_reactive.configure(m_system_configuration.current_regulator_reactive); + _status &= m_environment.current_regulator_b_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.current_regulator_b_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.current_regulator_c_active.configure(m_system_configuration.current_regulator_active); + m_environment.current_regulator_c_reactive.configure(m_system_configuration.current_regulator_reactive); + _status &= m_environment.current_regulator_c_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.current_regulator_c_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.current_referencer_a_active.configure(m_system_configuration.current_referencer); + m_environment.current_referencer_a_reactive.configure(m_system_configuration.current_referencer); + _status &= m_environment.current_referencer_a_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.current_referencer_a_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.current_referencer_b_active.configure(m_system_configuration.current_referencer); + m_environment.current_referencer_b_reactive.configure(m_system_configuration.current_referencer); + _status &= m_environment.current_referencer_b_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.current_referencer_b_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.current_referencer_c_active.configure(m_system_configuration.current_referencer); + m_environment.current_referencer_c_reactive.configure(m_system_configuration.current_referencer); + _status &= m_environment.current_referencer_c_active.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.current_referencer_c_reactive.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + //m_system_configuration.regulator_dc_voltage.low_saturation = - m_environment.phase_control.common_ref.voltage_module_rms; + m_environment.regulator_dc_a.configure(m_system_configuration.regulator_dc_voltage); + m_environment.regulator_dc_b.configure(m_system_configuration.regulator_dc_voltage); + m_environment.regulator_dc_c.configure(m_system_configuration.regulator_dc_voltage); + _status &= m_environment.regulator_dc_a.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_dc_b.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.regulator_dc_c.compare(FLTSYSLIB::PIController::OPERATIONAL); +#endif + //<> + + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + m_environment.drc_positive_voltage_controller_direct.configure(m_system_configuration.drc_voltage_controller); + m_environment.drc_positive_voltage_controller_quadrature.configure(m_system_configuration.drc_voltage_controller); + m_environment.drc_negative_voltage_controller_direct.configure(m_system_configuration.drc_voltage_controller); + m_environment.drc_negative_voltage_controller_quadrature.configure(m_system_configuration.drc_voltage_controller); + _status &= m_environment.drc_positive_voltage_controller_direct.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.drc_positive_voltage_controller_quadrature.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.drc_negative_voltage_controller_direct.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.drc_negative_voltage_controller_quadrature.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.drc_reference_voltage_direct_intensity.configure(m_system_configuration.drc_reference_voltage_direct_intensity); + _status &= m_environment.drc_reference_voltage_direct_intensity.compare(FLTSYSLIB::FilterSecond::OPERATIONAL); + // + m_environment.drc_regulator_current_load_direct.configure(m_system_configuration.drc_regulator_current_load); + m_environment.drc_regulator_current_load_quadrature.configure(m_system_configuration.drc_regulator_current_load); + _status &= m_environment.drc_regulator_current_load_direct.compare(FLTSYSLIB::PIController::OPERATIONAL); + _status &= m_environment.drc_regulator_current_load_quadrature.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.drc_referencer_current_bypass_direct.configure(m_system_configuration.drc_referencer_current_bypass); + m_environment.drc_referencer_current_bypass_quadrature.configure(m_system_configuration.drc_referencer_current_bypass); + _status &= m_environment.drc_referencer_current_bypass_direct.compare(FLTSYSLIB::IController::OPERATIONAL); + _status &= m_environment.drc_referencer_current_bypass_quadrature.compare(FLTSYSLIB::IController::OPERATIONAL); + // + m_environment.drc_regulator_current_limit.configure(m_system_configuration.drc_regulator_current_limit); + m_environment.drc_regulator_current_pfc.configure(m_system_configuration.drc_regulator_current_pfc); + _status &= m_environment.drc_regulator_current_limit.compare(FLTSYSLIB::IController::OPERATIONAL); + _status &= m_environment.drc_regulator_current_pfc.compare(FLTSYSLIB::PIController::OPERATIONAL); + // + m_environment.drc_direct_voltage_decomposer.configure(m_system_configuration.drc_voltage_decomposer); + m_environment.drc_back_voltage_decomposer.configure(m_system_configuration.drc_voltage_decomposer); + // +#endif + //<> + + + + + + // + // Timers + // + m_environment.timer_start.configure(m_system_configuration.timer_start); + m_environment.timer_stop.configure(m_system_configuration.timer_stop); + _status &= m_environment.timer_start.compare(FLTSYSLIB::FTimer::OPERATIONAL); + _status &= m_environment.timer_stop.compare(FLTSYSLIB::FTimer::OPERATIONAL); + //<> + + + m_environment.digital_input_debug.all = (uint32_t)0; + + // + // Scale Compute + // + m_environment.scale_compute_voltage_command.all = 0; + m_environment.scale_compute_current_command.all = 0; + m_environment.scale_compute_voltage_input.set_enable(); + m_environment.scale_compute_voltage_load.set_enable(); + m_environment.scale_compute_current_input.set_enable(); + m_environment.scale_compute_current_cell.set_enable(); + m_environment.scale_compute_current_load.set_enable(); + m_environment.scale_compute_current_bypass.set_enable(); + //<> + + + //m_environment.digital_output_temp.all = 0xFFFFFFFF; + m_environment.digital_output_temp.all = (uint32_t)0; + + SYSCTRL::TriggerRegister::clear(m_enable_work_trigger); + SYSCTRL::TriggerRegister::clear(m_system_fault_trigger); + + + SYSCTRL::TriggerRegister::clear(m_q1_control_trigger); + SYSCTRL::TriggerRegister::clear(m_km1_control_trigger); + SYSCTRL::TriggerRegister::clear(m_km2_control_trigger); + SYSCTRL::TriggerRegister::clear(m_km3_control_trigger); + SYSCTRL::TriggerRegister::clear(m_km11_control_on_off_trigger); + SYSCTRL::TriggerRegister::clear(m_km11t_control_on_trigger); + SYSCTRL::TriggerRegister::clear(m_km11t_control_off_trigger); + SYSCTRL::TriggerRegister::clear(m_km1_external_command_trigger); + SYSCTRL::TriggerRegister::clear(m_km3_external_command_trigger); + SYSCTRL::TriggerRegister::clear(m_q1_external_command_trigger); + SYSCTRL::TriggerRegister::clear(m_vs_protection_control_trigger); + + + + + //m_environment.gen_symm_comp_inp_volt.configure(m_system_configuration.gen_inp_volt); + //m_environment.gen_symm_comp_out_volt.configure(m_system_configuration.gen_out_volt); + //m_environment.gen_symm_comp_out_current.configure(m_system_configuration.gen_out_current); + //m_environment.gen_symm_comp_input_current.configure(m_system_configuration.gen_input_current); + //m_environment.gen_symm_comp_bypass_current.configure(m_system_configuration.gen_bypass_current); + //m_environment.gen_symm_comp_cell_current.configure(m_system_configuration.gen_cell_current); + + + // + // Contactor Control Fault + // + m_q1_control_fault.configure(m_system_configuration.contactor); + m_km1_control_fault.configure(m_system_configuration.contactor); + m_km2_control_fault.configure(m_system_configuration.contactor); + m_km3_control_fault.configure(m_system_configuration.contactor); + //<> + + + // + // RUBUS Configuration + // + _modbusrtu_rubus_configurate(); + //<> + + + if(_status) + { + m_mode = SYSCTRL::SystemControl::OPERATIONAL; + _slow_loop_execute = &SYSCTRL::SystemControl::_slow_loop_operational; + _execute_additional = &SYSCTRL::SystemControl::_additional_operational; + _execute = &SYSCTRL::SystemControl::_execute_operational; + m_algorithm.set_strategy_off(); + m_algorithm.set_off(); + m_algorithm_executed = m_algorithm.get_algorithm(); + + // + // Response To Monitor + // + m_test_read_word.bit32.b00 = 1; + //<> + // + }//if + + }//if + // +}//configure() +// + +//#pragma FUNC_ALWAYS_INLINE +void SystemControl::reload() +{ + if(m_fram_db.is_free()) + { + TRAPSWRST; + + // + }//if + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SystemControl.h b/SYSCTRL/SystemControl.h new file mode 100644 index 0000000..3a37d87 --- /dev/null +++ b/SYSCTRL/SystemControl.h @@ -0,0 +1,256 @@ +/* + * SystemControl.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + + + + +#include +#include + +#include "framework.h" +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" + +#include "FRAM/FRAMheaders.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" +#include "SYSCTRL/HeadersMODBUSRTU.h" +#include "SYSCTRL/SystemConfigurator.h" +#include "SYSCTRL/SystemEnvironment.h" +#include "SYSCTRL/VectorSpinner.h" + + +#ifndef TRAPSWRST +#define TRAPSWRST __asm(" TRAP #20") +#endif + + + +#ifndef SYSCTRL_SYSTEMCONTROL_H_ +#define SYSCTRL_SYSTEMCONTROL_H_ + +namespace SYSCTRL +{ + + + +class SystemControl +{ +public: + enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL}; +private: + mode_t m_mode; + SYSCTRL::AlgorithmContext::algorithm_t m_algorithm_executed; + bool turnQ1On; +private: + //Decompose Signals + SYSCTRL::SignalDecompose m_decompose_voltage_input_a; + SYSCTRL::SignalDecompose m_decompose_voltage_input_b; + SYSCTRL::SignalDecompose m_decompose_voltage_input_c; + // + SYSCTRL::SignalDecompose m_decompose_voltage_load_a; + SYSCTRL::SignalDecompose m_decompose_voltage_load_b; + SYSCTRL::SignalDecompose m_decompose_voltage_load_c; + // + SYSCTRL::SignalDecompose m_decompose_current_load_a; + SYSCTRL::SignalDecompose m_decompose_current_load_b; + SYSCTRL::SignalDecompose m_decompose_current_load_c; + // + SYSCTRL::SignalDecompose m_decompose_current_bypass_a; + SYSCTRL::SignalDecompose m_decompose_current_bypass_b; + SYSCTRL::SignalDecompose m_decompose_current_bypass_c; + // + SYSCTRL::SignalDecompose m_decompose_current_cell_a; + SYSCTRL::SignalDecompose m_decompose_current_cell_b; + SYSCTRL::SignalDecompose m_decompose_current_cell_c; + // +private: + // + // RMS Filters + // + FLTSYSLIB::RMSF4O m_rms_filter_current_input_a; + FLTSYSLIB::RMSF4O m_rms_filter_current_input_b; + FLTSYSLIB::RMSF4O m_rms_filter_current_input_c; + // + FLTSYSLIB::RMSF4O m_rms_filter_current_cell_a; + FLTSYSLIB::RMSF4O m_rms_filter_current_cell_b; + FLTSYSLIB::RMSF4O m_rms_filter_current_cell_c; + // + FLTSYSLIB::RMSF4O m_rms_filter_current_load_a; + FLTSYSLIB::RMSF4O m_rms_filter_current_load_b; + FLTSYSLIB::RMSF4O m_rms_filter_current_load_c; + // + FLTSYSLIB::RMSF4O m_rms_filter_voltage_input_a; + FLTSYSLIB::RMSF4O m_rms_filter_voltage_input_b; + FLTSYSLIB::RMSF4O m_rms_filter_voltage_input_c; + // + FLTSYSLIB::RMSF4O m_rms_filter_voltage_load_a; + FLTSYSLIB::RMSF4O m_rms_filter_voltage_load_b; + FLTSYSLIB::RMSF4O m_rms_filter_voltage_load_c; + // + FLTSYSLIB::RMSF4O m_rms_filter_current_bypass_a; + FLTSYSLIB::RMSF4O m_rms_filter_current_bypass_b; + FLTSYSLIB::RMSF4O m_rms_filter_current_bypass_c; + // +private: + // + // Zero Drift Analog Signals + // + FLTSYSLIB::FilterForth m_zero_filter_voltage_input_a; + FLTSYSLIB::FilterForth m_zero_filter_voltage_input_b; + FLTSYSLIB::FilterForth m_zero_filter_voltage_input_c; + // + FLTSYSLIB::FilterForth m_zero_filter_current_input_a; + FLTSYSLIB::FilterForth m_zero_filter_current_input_b; + FLTSYSLIB::FilterForth m_zero_filter_current_input_c; + // + FLTSYSLIB::FilterForth m_zero_filter_current_cell_a; + FLTSYSLIB::FilterForth m_zero_filter_current_cell_b; + FLTSYSLIB::FilterForth m_zero_filter_current_cell_c; + // + FLTSYSLIB::FilterForth m_zero_filter_voltage_load_a; + FLTSYSLIB::FilterForth m_zero_filter_voltage_load_b; + FLTSYSLIB::FilterForth m_zero_filter_voltage_load_c; + // + FLTSYSLIB::FilterForth m_zero_filter_current_load_a; + FLTSYSLIB::FilterForth m_zero_filter_current_load_b; + FLTSYSLIB::FilterForth m_zero_filter_current_load_c; + // + FLTSYSLIB::FilterForth m_zero_filter_current_bypass_a; + FLTSYSLIB::FilterForth m_zero_filter_current_bypass_b; + FLTSYSLIB::FilterForth m_zero_filter_current_bypass_c; + // +private: + //Cell DC Voltage Filter + FLTSYSLIB::FilterForth m_cell_dc_voltage_a_filter; + FLTSYSLIB::FilterForth m_cell_dc_voltage_b_filter; + FLTSYSLIB::FilterForth m_cell_dc_voltage_c_filter; + // +private: + //PLL-ABC & Relative Input Voltage + SYSCTRL::SignalRelative m_relative_filter_voltage_input_a; + SYSCTRL::SignalRelative m_relative_filter_voltage_input_b; + SYSCTRL::SignalRelative m_relative_filter_voltage_input_c; + FLTSYSLIB::PLLABCDVR m_pll_abc_input_voltage; +private: + //Harmonica Analyzer + FLTSYSLIB::HarmonicaFilter4Order m_voltage_input_a_harmonica_filter_5; + FLTSYSLIB::HarmonicaFilter4Order m_voltage_input_b_harmonica_filter_5; + FLTSYSLIB::HarmonicaFilter4Order m_voltage_input_c_harmonica_filter_5; +private: + //Phase Alert monitor + SYSCTRL::PhaseAlertMonitor m_phase_alert_monitor; +private: + SYSCTRL::TriggerRegisterStructure m_enable_work_trigger; + SYSCTRL::TriggerRegisterStructure m_system_fault_trigger; +private: + SYSCTRL::TriggerRegisterStructure m_q1_control_trigger; + SYSCTRL::TriggerRegisterStructure m_km1_control_trigger; + SYSCTRL::TriggerRegisterStructure m_km2_control_trigger; + SYSCTRL::TriggerRegisterStructure m_km3_control_trigger; + SYSCTRL::TriggerRegisterStructure m_km11_control_on_off_trigger; + SYSCTRL::TriggerRegisterStructure m_km11t_control_on_trigger; + SYSCTRL::TriggerRegisterStructure m_km11t_control_off_trigger; + SYSCTRL::TriggerRegisterStructure m_km1_external_command_trigger; + SYSCTRL::TriggerRegisterStructure m_km3_external_command_trigger; + SYSCTRL::TriggerRegisterStructure m_q1_external_command_trigger; + SYSCTRL::TriggerRegisterStructure m_vs_protection_control_trigger; + +private: + SYSCTRL::ContactorFault m_q1_control_fault; + SYSCTRL::ContactorFault m_km1_control_fault; + SYSCTRL::ContactorFault m_km2_control_fault; + SYSCTRL::ContactorFault m_km3_control_fault; + +private: + SYSCTRL::SystemControlSetup m_system_setup; + SYSCTRL::SystemControlConfiguration m_system_configuration; + SYSCTRL::SystemEnvironment m_environment; + SYSCTRL::AlgorithmContext m_algorithm; + FRAM::FRAMDATABASE m_fram_db; +private: + MODBUSRTU::RUBUS_REGISTER_32 m_test_read_word; + MODBUSRTU::RUBUS_REGISTER_32 m_test_write_word; + MODBUSRTU::RUBUS m_rubus; + MODBUSRTU::RUBUSDataBase m_rubus_data; + uint16_t m_modbus_break_counter; +public: + SYSCTRL::HardwareAnalogCurrentFaultRegister hardware_analog_current_fault; +public: + SystemControl(); + void setup(); + void configure(); + void reload(); +public: + void process_analog_input(AnalogInput& analog_input); + void process_digital_input(DigitalInput& digital_input); + Uint32 get_digital_output(); +public: + void setup_hvcell(); + void send_hvcell_syn_signal(); + void send_hvcell_control_order(); + void set_hvcell_level(); + void get_pwm_version(); + void get_hvcell_state(); + void get_hvcell_dc_voltage(); + void get_hvcell_version(); + void send_hvcell_modulate_data(); + void get_cpu_cpld_version(); + void hardware_diagnostic(); +public: + bool slow_loop_is_active(); + void slow_loop_execute(); +private: + void (SystemControl::*_slow_loop_execute)(); + void _slow_loop_undef(); + void _slow_loop_operational(); +public: + bool additional_loop_is_active(); + void execute_additional(); +public: + bool symmetrical_calculator_loop_is_active(); + void execute_symmetrical_calculator(); +private: + void (SystemControl::*_execute_additional)(); + void _additional_undef(); + void _additional_operational(); +public: + void execute(); +private: + void (SystemControl::*_execute)(); + void _execute_ubdef(); + void _execute_operational(); +public: + void get_hard_code_setup(); + void get_hard_code_configuration(); + void upload_configuration(); +public: + void harmonica_multiplyer(float cos_alpha, float sin_alpha, float cos_beta, float sin_beta, float& out_cos, float& out_sin); +public: + void protection_thyristor_control(); +private: + void _rms_module_calculator(float xa, float xb, float xc, float& xrms); +private: + inline void _trigger_protection_thyristor_control(); +public: + void inc_break_counter(); + void set_break_counter(Uint16 count); + void modbusrtu_rubus_interface(Uint16 rdReg[], Uint16 wrReg[]); +private: + void _modbusrtu_rubus_read_write_register(); + inline void _modbusrtu_rubus_read_write_bool(bool& param); + inline void _modbusrtu_rubus_read_write_float(float& param); + inline void _modbusrtu_rubus_read_write_uint16(uint16_t& param); + inline void _modbusrtu_rubus_read_write_uint32(uint32_t& param); + inline void _modbusrtu_rubus_read_write_int16(int16_t& param); + inline void _modbusrtu_rubus_read_write_int32(int32_t& param); + void _modbusrtu_rubus_configurate(); +private: + inline float hvcell_dc_voltage_reciprocal(float& voltage); + // +}; +} /* namespace SYSCTRL */ +#endif /* SYSCTRL_SYSTEMCONTROL_H_ */ diff --git a/SYSCTRL/SystemControlExecute.cpp b/SYSCTRL/SystemControlExecute.cpp new file mode 100644 index 0000000..63d9650 --- /dev/null +++ b/SYSCTRL/SystemControlExecute.cpp @@ -0,0 +1,1324 @@ +/* + * SystemControlExecute.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + + +#include "SYSCTRL/SystemControl.h" + +namespace SYSCTRL +{ + + + +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::execute_additional() +{ + (this->*_execute_additional)(); +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_additional_undef() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_additional_operational() +{ + + + // + // RMS Filter + // + m_environment.rms_current_input_a = m_rms_filter_current_input_a.execute(m_environment.current_input_a); + m_environment.rms_current_input_b = m_rms_filter_current_input_b.execute(m_environment.current_input_b); + m_environment.rms_current_input_c = m_rms_filter_current_input_c.execute(m_environment.current_input_c); + // + m_environment.rms_current_cell_a = m_rms_filter_current_cell_a.execute(m_environment.current_cell_a); + m_environment.rms_current_cell_b = m_rms_filter_current_cell_b.execute(m_environment.current_cell_b); + m_environment.rms_current_cell_c = m_rms_filter_current_cell_c.execute(m_environment.current_cell_c); + // + m_environment.rms_current_load_a = m_rms_filter_current_load_a.execute(m_environment.current_load_a); + m_environment.rms_current_load_b = m_rms_filter_current_load_b.execute(m_environment.current_load_b); + m_environment.rms_current_load_c = m_rms_filter_current_load_c.execute(m_environment.current_load_c); + // + m_environment.rms_voltage_input_ab = m_rms_filter_voltage_input_a.execute(m_environment.voltage_grid_a - m_environment.voltage_grid_b); + m_environment.rms_voltage_input_bc = m_rms_filter_voltage_input_b.execute(m_environment.voltage_grid_b - m_environment.voltage_grid_c); + m_environment.rms_voltage_input_ca = m_rms_filter_voltage_input_c.execute(m_environment.voltage_grid_c - m_environment.voltage_grid_a); + // + m_environment.rms_current_bypass_a = m_rms_filter_current_bypass_a.execute(m_environment.current_bypass_a); + m_environment.rms_current_bypass_b = m_rms_filter_current_bypass_b.execute(m_environment.current_bypass_b); + m_environment.rms_current_bypass_c = m_rms_filter_current_bypass_c.execute(m_environment.current_bypass_c); + // + m_environment.rms_voltage_load_ab = m_rms_filter_voltage_load_a.execute(m_environment.voltage_load_a - m_environment.voltage_load_b); + m_environment.rms_voltage_load_bc = m_rms_filter_voltage_load_b.execute(m_environment.voltage_load_b - m_environment.voltage_load_c); + m_environment.rms_voltage_load_ca = m_rms_filter_voltage_load_c.execute(m_environment.voltage_load_c - m_environment.voltage_load_a); + //<> + + // + // RMS Module + // + // xrms = sqrt((xa*xa + xb*xb + xc*xc)/3) + SYSCTRL::SystemControl::_rms_module_calculator(m_environment.voltage_grid_a, m_environment.voltage_grid_b, m_environment.voltage_grid_c, m_environment.rms_voltage_input_module); + SYSCTRL::SystemControl::_rms_module_calculator(m_environment.voltage_load_a, m_environment.voltage_load_b, m_environment.voltage_load_c, m_environment.rms_voltage_load_module); + SYSCTRL::SystemControl::_rms_module_calculator(m_environment.current_input_a, m_environment.current_input_b, m_environment.current_input_c, m_environment.rms_current_input_module); + SYSCTRL::SystemControl::_rms_module_calculator(m_environment.current_load_a, m_environment.current_load_b, m_environment.current_load_c, m_environment.rms_current_load_module); + SYSCTRL::SystemControl::_rms_module_calculator(m_environment.current_bypass_a, m_environment.current_bypass_b, m_environment.current_bypass_c, m_environment.rms_current_bypass_module); + //<> + + + // + // FRAM Operation Control Bits + // + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.fram_operation.signal.burn, m_environment.fram_burn); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.fram_operation.signal.erase, m_environment.fram_erase); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.fram_operation.signal.verify, m_environment.fram_verify); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.fram_operation.signal.read, m_environment.fram_read); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.fram_operation.signal.restore, m_environment.fram_restore); + //<> + + // + // FRAM Control + // + if(m_fram_db.is_free()) + { + // FRAM is free + // + if(m_environment.fram_erase.signal.is_switched_on) + { + m_fram_db.set_erase(); + } + else + { + if(m_environment.fram_verify.signal.is_switched_on) + { + m_fram_db.set_verify(); + } + else + { + if(m_environment.fram_burn.signal.is_switched_on) + { + m_system_configuration.selfupdata(); + m_fram_db.update_buffer(&m_system_configuration); + m_fram_db.set_burn(); + } + else + { + if(m_environment.fram_restore.signal.is_switched_on) + { + m_fram_db.implement_dafault_configuration(); + m_fram_db.update_buffer(&m_system_configuration); + m_fram_db.set_restore(); + } + else + { + + + }//if else + // + }//if else + // + }//if else + // + }//if else + // + }//if + //<> + // + if(m_fram_db.is_busy()) + { + // FRAM is busy + //WAIT, READ, WRITE, ERASE, VERIFY, RESTORE + switch(m_fram_db.get_mode()) + { + case FRAM::FRAMDATABASE::READ: + { + m_fram_db.read_fram_index(); + break; + }// + case FRAM::FRAMDATABASE::BURN: + { + m_fram_db.write_fram_index(); + reload(); + break; + } + case FRAM::FRAMDATABASE::ERASE: + { + m_fram_db.erase_fram_index(); + break; + } + case FRAM::FRAMDATABASE::VERIFY: + { + m_fram_db.verify_fram_index(); + break; + } + case FRAM::FRAMDATABASE::RESTORE: + { + m_fram_db.restore_fram_index(); + reload(); + break; + } + default: + { + break; + } + }//switch + // + }//if + //<> + + + + // + // Response To Monitor + // + m_test_read_word.bit32.b00 = m_fram_db.is_free() ? 1 : 0; + //<> + + + // + // Algorithm Control + // + m_environment.algorithm_control.all = m_system_configuration.algorithm_control.all; + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.algorithm_control.signal.enable_current_limit, m_environment.enable_current_limit); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.algorithm_control.signal.enable_pfc, m_environment.enable_pfc); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.algorithm_control.signal.enable_harmonica, m_environment.enable_harmonica); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.algorithm_control.signal.enable_auto_offset, m_environment.enable_auto_offset); + // +#if TYPECONTROL == SCALARCONTROL + m_environment.phase_control.common_control_bit.signal.enable_current_limit = m_environment.enable_current_limit.signal.is_on; + m_environment.phase_control.common_control_bit.signal.enable_pfc = m_environment.enable_pfc.signal.is_on; + m_environment.phase_control.common_control_bit.signal.enable_harmonica = m_environment.enable_harmonica.signal.is_on; + // + m_environment.phase_control.phase_a.control_bit.all = m_environment.phase_control.common_control_bit.all; + m_environment.phase_control.phase_b.control_bit.all = m_environment.phase_control.common_control_bit.all; + m_environment.phase_control.phase_c.control_bit.all = m_environment.phase_control.common_control_bit.all; +#endif + //<> + +}// +// + + + +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::slow_loop_execute() +{ + (this->*_slow_loop_execute)(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_slow_loop_undef() +{}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_slow_loop_operational() +{ + + if(m_environment.allow_auto_offset) + { + m_environment.offset_voltage_grid_a = m_zero_filter_voltage_input_a.execute(m_environment.adc_voltage_grid_a); + m_environment.offset_voltage_grid_b = m_zero_filter_voltage_input_b.execute(m_environment.adc_voltage_grid_b); + m_environment.offset_voltage_grid_c = m_zero_filter_voltage_input_c.execute(m_environment.adc_voltage_grid_c); + // + m_environment.offset_current_input_a = m_zero_filter_current_input_a.execute(m_environment.adc_current_input_a); + m_environment.offset_current_input_b = m_zero_filter_current_input_b.execute(m_environment.adc_current_input_b); + m_environment.offset_current_input_c = m_zero_filter_current_input_c.execute(m_environment.adc_current_input_c); + // + m_environment.offset_current_bypass_a = m_zero_filter_current_bypass_a.execute(m_environment.adc_current_bypass_a); + m_environment.offset_current_bypass_b = m_zero_filter_current_bypass_b.execute(m_environment.adc_current_bypass_b); + m_environment.offset_current_bypass_c = m_zero_filter_current_bypass_c.execute(m_environment.adc_current_bypass_c); + // + m_environment.offset_current_cell_a = m_zero_filter_current_cell_a.execute(m_environment.adc_current_cell_a); + m_environment.offset_current_cell_b = m_zero_filter_current_cell_b.execute(m_environment.adc_current_cell_b); + m_environment.offset_current_cell_c = m_zero_filter_current_cell_c.execute(m_environment.adc_current_cell_c); + // + m_environment.offset_voltage_load_a = m_zero_filter_voltage_load_a.execute(m_environment.adc_voltage_load_a); + m_environment.offset_voltage_load_b = m_zero_filter_voltage_load_b.execute(m_environment.adc_voltage_load_b); + m_environment.offset_voltage_load_c = m_zero_filter_voltage_load_c.execute(m_environment.adc_voltage_load_c); + // + m_environment.offset_current_load_a = m_zero_filter_current_load_a.execute(m_environment.adc_current_load_a); + m_environment.offset_current_load_b = m_zero_filter_current_load_b.execute(m_environment.adc_current_load_b); + m_environment.offset_current_load_c = m_zero_filter_current_load_c.execute(m_environment.adc_current_load_c); + // + }//if + // + + + + // + // Phase Alert monitor + // + m_phase_alert_monitor.execute(m_environment.rms_voltage_input_ab, + m_environment.rms_voltage_input_bc, + m_environment.rms_voltage_input_ca, + m_environment.rms_current_load_a, + m_environment.rms_current_load_b, + m_environment.rms_current_load_c, + m_environment.rms_current_cell_a, + m_environment.rms_current_cell_b, + m_environment.rms_current_cell_c, + m_environment.rms_current_input_a, + m_environment.rms_current_input_b, + m_environment.rms_current_input_c); + + if(m_system_fault_trigger.signal.quit) + { + m_environment.phase_alert_monitor_register.phase_a.fault.all = m_environment.system_faults_register.phase_a.all; + m_environment.phase_alert_monitor_register.phase_b.fault.all = m_environment.system_faults_register.phase_b.all; + m_environment.phase_alert_monitor_register.phase_c.fault.all = m_environment.system_faults_register.phase_c.all; + m_environment.phase_alert_monitor_register.phase_a.warning.all = m_phase_alert_monitor.status.phase_a.warning.all; + m_environment.phase_alert_monitor_register.phase_b.warning.all = m_phase_alert_monitor.status.phase_b.warning.all; + m_environment.phase_alert_monitor_register.phase_c.warning.all = m_phase_alert_monitor.status.phase_c.warning.all; + // + } + else + { + m_environment.phase_alert_monitor_register = m_phase_alert_monitor.status; + // + }// + //<> + + + +#if (TYPECONTROL == VECTORCONTROL) || (TYPECONTROL == DIRECTREVERSECONTROL) + // + // Decompose Input Voltage + m_decompose_voltage_input_a.execute(m_environment.voltage_grid_a, m_environment.pll_abc_orts.phase_a.active, m_environment.pll_abc_orts.phase_a.reactive); + m_decompose_voltage_input_a.get_outputs(m_environment.projection_voltage_input_a.active, m_environment.projection_voltage_input_a.reactive); + // + m_decompose_voltage_input_b.execute(m_environment.voltage_grid_b, m_environment.pll_abc_orts.phase_b.active, m_environment.pll_abc_orts.phase_b.reactive); + m_decompose_voltage_input_b.get_outputs(m_environment.projection_voltage_input_b.active, m_environment.projection_voltage_input_b.reactive); + // + m_decompose_voltage_input_c.execute(m_environment.voltage_grid_c, m_environment.pll_abc_orts.phase_c.active, m_environment.pll_abc_orts.phase_c.reactive); + m_decompose_voltage_input_c.get_outputs(m_environment.projection_voltage_input_c.active, m_environment.projection_voltage_input_c.reactive); +// m_environment.projection_voltage_input_a = m_environment.test_projection_a; +// m_environment.projection_voltage_input_b = m_environment.test_projection_b; +// m_environment.projection_voltage_input_c = m_environment.test_projection_c; + + + // Ort Corrector + if(m_pll_abc_input_voltage.get_sync() && m_environment.auxiliary_q1.state.signal.is_on) + { + // Spinner + SYSCTRL::VectorSpinner::spin_calculator(m_environment.projection_voltage_input_a, m_environment.module_voltage_phase_a, m_environment.spinner_phase_a); + SYSCTRL::VectorSpinner::spin_calculator(m_environment.projection_voltage_input_b, m_environment.module_voltage_phase_b, m_environment.spinner_phase_b); + SYSCTRL::VectorSpinner::spin_calculator(m_environment.projection_voltage_input_c, m_environment.module_voltage_phase_c, m_environment.spinner_phase_c); + } + else + { + // Reset Spinner + m_environment.spinner_phase_a.active = 1.0; + m_environment.spinner_phase_a.reactive = FP_ZERO; + + m_environment.spinner_phase_b.active = 1.0; + m_environment.spinner_phase_b.reactive = FP_ZERO; + + m_environment.spinner_phase_c.active = 1.0; + m_environment.spinner_phase_c.reactive = FP_ZERO; + // + }//if else + // + SYSCTRL::VectorSpinner::ort_corrector(m_environment.spinner_phase_a, m_environment.pll_abc_orts.phase_a, m_environment.twisted_abc_orts.phase_a); + SYSCTRL::VectorSpinner::ort_corrector(m_environment.spinner_phase_b, m_environment.pll_abc_orts.phase_b, m_environment.twisted_abc_orts.phase_b); + SYSCTRL::VectorSpinner::ort_corrector(m_environment.spinner_phase_c, m_environment.pll_abc_orts.phase_c, m_environment.twisted_abc_orts.phase_c); + //<> + // + FLTSYSLIB::Transformation::ort_abc_jm_from_real(m_environment.twisted_abc_orts.phase_a.active, + m_environment.twisted_abc_orts.phase_b.active, + m_environment.twisted_abc_orts.phase_c.active, + m_environment.twisted_abc_orts.phase_a.reactive, + m_environment.twisted_abc_orts.phase_b.reactive, + m_environment.twisted_abc_orts.phase_c.reactive); + // + //m_environment.main_abc_orts = m_environment.pll_abc_orts; + //m_environment.main_abc_orts = m_environment.twisted_abc_orts; + // + /* + FLTSYSLIB::Transformation::clarke_forward(m_environment.main_abc_orts.phase_a.active, + m_environment.main_abc_orts.phase_b.active, + m_environment.main_abc_orts.phase_c.active, + m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive); + */ + // + //Decompose Load Voltage + m_decompose_voltage_load_a.execute(m_environment.voltage_load_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_voltage_load_a.get_outputs(m_environment.projection_voltage_load_a.active, m_environment.projection_voltage_load_a.reactive); + // + m_decompose_voltage_load_b.execute(m_environment.voltage_load_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_voltage_load_b.get_outputs(m_environment.projection_voltage_load_b.active, m_environment.projection_voltage_load_b.reactive); + // + m_decompose_voltage_load_c.execute(m_environment.voltage_load_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_voltage_load_c.get_outputs(m_environment.projection_voltage_load_c.active, m_environment.projection_voltage_load_c.reactive); + +// m_environment.projection_voltage_load_a = m_environment.test_projection_a; +// m_environment.projection_voltage_load_b = m_environment.test_projection_b; +// m_environment.projection_voltage_load_c = m_environment.test_projection_c; + + + //Decompose Load Current + m_decompose_current_load_a.execute(m_environment.current_load_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_current_load_a.get_outputs(m_environment.projection_current_load_a.active, m_environment.projection_current_load_a.reactive); + // + m_decompose_current_load_b.execute(m_environment.current_load_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_current_load_b.get_outputs(m_environment.projection_current_load_b.active, m_environment.projection_current_load_b.reactive); + // + m_decompose_current_load_c.execute(m_environment.current_load_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_current_load_c.get_outputs(m_environment.projection_current_load_c.active, m_environment.projection_current_load_c.reactive); + +// m_environment.projection_current_load_a = m_environment.test_projection_a; +// m_environment.projection_current_load_b = m_environment.test_projection_b; +// m_environment.projection_current_load_c = m_environment.test_projection_c; + + + //Decompose Bypass Current + m_decompose_current_bypass_a.execute(m_environment.current_bypass_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_current_bypass_a.get_outputs(m_environment.projection_current_bypass_a.active, m_environment.projection_current_bypass_a.reactive); + // + m_decompose_current_bypass_b.execute(m_environment.current_bypass_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_current_bypass_b.get_outputs(m_environment.projection_current_bypass_b.active, m_environment.projection_current_bypass_b.reactive); + // + m_decompose_current_bypass_c.execute(m_environment.current_bypass_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_current_bypass_c.get_outputs(m_environment.projection_current_bypass_c.active, m_environment.projection_current_bypass_c.reactive); + +// m_environment.projection_current_bypass_a = m_environment.test_projection_a; +// m_environment.projection_current_bypass_b = m_environment.test_projection_b; +// m_environment.projection_current_bypass_c = m_environment.test_projection_c; + + + //Decompose Cell Current + m_decompose_current_cell_a.execute(m_environment.current_cell_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_current_cell_a.get_outputs(m_environment.projection_current_cell_a.active, m_environment.projection_current_cell_a.reactive); + // + m_decompose_current_cell_b.execute(m_environment.current_cell_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_current_cell_b.get_outputs(m_environment.projection_current_cell_b.active, m_environment.projection_current_cell_b.reactive); + // + m_decompose_current_cell_c.execute(m_environment.current_cell_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_current_cell_c.get_outputs(m_environment.projection_current_cell_c.active, m_environment.projection_current_cell_c.reactive); + +#endif + + +}// +// + +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::execute_symmetrical_calculator() +{ + // + // Symmetrical Components + // + //define symmetrical components of input voltage + SYSCTRL::SymmetricalComponents::compute_symmetrical_components_axis_own(m_environment.projection_voltage_input_a, + m_environment.projection_voltage_input_b, + m_environment.projection_voltage_input_c, + m_environment.symmetrical_components_voltage_input); +// SYSCTRL::SymmetricalComponents::compute_symmetrical_components_axis_own(m_environment.test_projection_a, +// m_environment.test_projection_b, +// m_environment.test_projection_c, +// m_environment.symmetrical_components_voltage_input); + + //define symmetrical components of load voltage + SYSCTRL::SymmetricalComponents::compute_symmetrical_components_axis_own(m_environment.projection_voltage_load_a, + m_environment.projection_voltage_load_b, + m_environment.projection_voltage_load_c, + m_environment.symmetrical_components_voltage_load); + + //define symmetrical components of load current + SYSCTRL::SymmetricalComponents::compute_symmetrical_components_axis_own(m_environment.projection_current_load_a, + m_environment.projection_current_load_b, + m_environment.projection_current_load_c, + m_environment.symmetrical_components_current_load); + + //define symmetrical components of bypass current + SYSCTRL::SymmetricalComponents::compute_symmetrical_components_axis_own(m_environment.projection_current_bypass_a, + m_environment.projection_current_bypass_b, + m_environment.projection_current_bypass_c, + m_environment.symmetrical_components_current_bypass); + //<> +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::execute() +{ + (this->*_execute)(); + // +}//execute() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_execute_ubdef() +{ + // +}//_execute_ubdef() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_execute_operational() +{ + + + // + // External Command + // + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.start, m_environment.external_start); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.stop, m_environment.external_stop); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.reset, m_environment.external_reset); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.e_stop, m_environment.external_e_stop); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.km1_on, m_environment.external_km1_on); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.km1_off, m_environment.external_km1_off); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.km3_on, m_environment.external_km3_on); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.km3_off, m_environment.external_km3_off); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.q1_on, m_environment.external_q1_on); + SYSCTRL::MonitorDigitalInputSignal::implement(m_environment.external_command_word.signal.q1_off, m_environment.external_q1_off); + // + // + if (m_environment.external_q1_on.signal.is_switched_on) + { + turnQ1On = true; + } + + if (m_environment.external_q1_off.signal.is_switched_on) + { + turnQ1On = false; + } + + if(m_environment.system_fault.boolbit.b0) + { + turnQ1On = false; + } + // Command KM1 - on/off + SYSCTRL::TriggerRegister::setSet(m_km1_external_command_trigger, + !m_environment.system_fault.boolbit.b0 & + m_environment.input_discrete.signal.hw_dvr_ready & + m_environment.input_discrete.signal.bypass_ready & + (bool)m_environment.external_km1_on.signal.is_on); + SYSCTRL::TriggerRegister::setReset(m_km1_external_command_trigger, + (m_environment.system_fault.boolbit.b0 & m_environment.auxiliary_km2.state.signal.is_on) | + !m_environment.input_discrete.signal.hw_dvr_ready | + !m_environment.input_discrete.signal.bypass_ready | + (bool)m_environment.external_km1_off.signal.is_on); + SYSCTRL::TriggerRegister::execute_reset_priority(m_km1_external_command_trigger); + //<> + // + // Command KM3 - on/off + SYSCTRL::TriggerRegister::setSet(m_km3_external_command_trigger, + !m_environment.system_fault.boolbit.b0 & + m_environment.input_discrete.signal.hw_dvr_ready & + m_environment.input_discrete.signal.bypass_ready & + (bool)m_environment.external_km3_on.signal.is_on); + SYSCTRL::TriggerRegister::setReset(m_km3_external_command_trigger, + (m_environment.system_fault.boolbit.b0 & m_environment.auxiliary_km2.state.signal.is_on) | + !m_environment.input_discrete.signal.hw_dvr_ready | + !m_environment.input_discrete.signal.bypass_ready | + (bool)m_environment.external_km3_off.signal.is_on); + SYSCTRL::TriggerRegister::execute_reset_priority(m_km3_external_command_trigger); + //<> + // + // Command Q1 - on/off + SYSCTRL::TriggerRegister::setSet(m_q1_external_command_trigger, + !m_environment.system_fault.boolbit.b0 & + m_environment.input_discrete.signal.hw_dvr_ready & + m_environment.input_discrete.signal.bypass_ready & + //(bool)m_environment.external_q1_on.signal.is_on); + turnQ1On); + SYSCTRL::TriggerRegister::setReset(m_q1_external_command_trigger, + (m_environment.system_fault.boolbit.b0 & m_environment.auxiliary_km2.state.signal.is_on) | + !m_environment.input_discrete.signal.hw_dvr_ready | + !m_environment.input_discrete.signal.bypass_ready | + //(bool)m_environment.external_q1_off.signal.is_on); + !turnQ1On); + SYSCTRL::TriggerRegister::execute_reset_priority(m_q1_external_command_trigger); + //<> + + + // + // System Reset + // + static bool _reset_local = false; + _reset_local = m_environment.remote_reset.state.signal.is_on; + _reset_local |= m_environment.external_reset.signal.is_on; + _reset_local &= m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::OFF) | m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::FAULT); + //_reset &= (m_environment.remote_start.is_off() & m_environment.local_remote.is_on()); + //_reset &= (m_environment.remote_stop.is_off() & m_environment.local_remote.is_on()); + m_environment.system_reset.boolbit.b0 = _reset_local; + + if(m_environment.system_fault.boolbit.b0 & m_environment.system_reset.boolbit.b0) + { + m_phase_alert_monitor.reset(); + m_environment.hardware.reset(); + hardware_analog_current_fault.all = 0; + m_environment.system_faults_register.equipment.all = 0; + m_environment.system_faults_register.phase_a.all = 0; + m_environment.system_faults_register.phase_b.all = 0; + m_environment.system_faults_register.phase_c.all = 0; + // + }// + m_q1_control_fault.reset(m_environment.system_fault.boolbit.b0 & m_environment.system_reset.boolbit.b0); + m_km1_control_fault.reset(m_environment.system_fault.boolbit.b0 & m_environment.system_reset.boolbit.b0); + m_km2_control_fault.reset(m_environment.system_fault.boolbit.b0 & m_environment.system_reset.boolbit.b0); + m_km3_control_fault.reset(m_environment.system_fault.boolbit.b0 & m_environment.system_reset.boolbit.b0); + + + + // + // System Faults + // + if(m_system_fault_trigger.signal.negquit) + { + if(m_enable_work_trigger.signal.is_on) + { + m_environment.system_faults_register.phase_a.all = m_phase_alert_monitor.status.phase_a.fault.all; + m_environment.system_faults_register.phase_b.all = m_phase_alert_monitor.status.phase_b.fault.all; + m_environment.system_faults_register.phase_c.all = m_phase_alert_monitor.status.phase_c.fault.all; + // + } + else + { + m_environment.system_faults_register.phase_a.all = 0; + m_environment.system_faults_register.phase_b.all = 0; + m_environment.system_faults_register.phase_c.all = 0; + // + } + // + m_environment.system_faults_register.equipment.signal.remote_e_stop = m_environment.remote_e_stop.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.local_e_stop = (m_environment.local_e_stop.state.signal.is_on | m_environment.external_e_stop.signal.is_on); + m_environment.system_faults_register.equipment.signal.fan = m_environment.fan_fault.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.cells = m_environment.hardware.fault; +// m_environment.system_faults_register.equipment.signal.cabinet_door_open = m_environment.cabinet_door_interlocked.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.temperature_transformer_multi_winding = m_environment.transformer_inv_over_temperature_fault.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.temperature_transformer_phase_a = m_environment.transformer_t_over_temperature_fault.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.temperature_transformer_phase_b = m_environment.transformer_t_over_temperature_fault.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.temperature_transformer_phase_c = m_environment.transformer_t_over_temperature_fault.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.arc_and_fire = m_environment.arc_and_fire.state.signal.is_on; + m_environment.system_faults_register.equipment.signal.q1 = m_q1_control_fault.status.signal.fault; + m_environment.system_faults_register.equipment.signal.km1 = m_km1_control_fault.status.signal.fault; + m_environment.system_faults_register.equipment.signal.km2 = m_km2_control_fault.status.signal.fault; + m_environment.system_faults_register.equipment.signal.km3 = m_km3_control_fault.status.signal.fault; + //m_environment.system_faults_register.equipment.signal.sync_to_grid = !m_pll_abc_input_voltage.get_sync() & m_environment.input_discrete.signal.auxiliary_q1; + + } + + SYSCTRL::TriggerRegister::setSet(m_system_fault_trigger, + m_environment.system_faults_register.equipment.signal.remote_e_stop | + m_environment.system_faults_register.equipment.signal.local_e_stop | + (m_phase_alert_monitor.fault & m_enable_work_trigger.signal.is_on) | + m_environment.system_faults_register.equipment.signal.fan | + m_environment.system_faults_register.equipment.signal.cells | // DON'T FORGET BACK!!!!! + m_environment.system_faults_register.equipment.signal.temperature_transformer_multi_winding | + m_environment.system_faults_register.equipment.signal.temperature_transformer_phase_a | + m_environment.system_faults_register.equipment.signal.temperature_transformer_phase_b | + m_environment.system_faults_register.equipment.signal.temperature_transformer_phase_c | + m_environment.system_faults_register.equipment.signal.cabinet_door_open | + m_environment.system_faults_register.equipment.signal.arc_and_fire | + m_environment.system_faults_register.equipment.signal.q1 | + m_environment.system_faults_register.equipment.signal.km1 | + m_environment.system_faults_register.equipment.signal.km2 | + m_environment.system_faults_register.equipment.signal.km3 | + m_vs_protection_control_trigger.signal.quit); + + SYSCTRL::TriggerRegister::setReset(m_system_fault_trigger, m_environment.system_reset.boolbit.b0); + SYSCTRL::TriggerRegister::execute_set_priority(m_system_fault_trigger); + m_environment.system_fault.boolbit.b0 = (bool)m_system_fault_trigger.signal.is_on; + + + + // + // System Alarm (Warning) + // + static bool _alarm_local; + _alarm_local = false; + _alarm_local |= m_phase_alert_monitor.warning; + _alarm_local |= m_environment.transformer_inv_over_temperature_alarm.state.signal.is_on; + m_environment.system_alarm.boolbit.b0 = _alarm_local; + + + + // + // System Ready + // + static bool _ready_local = true; + _ready_local = !m_environment.system_fault.boolbit.b0; + _ready_local &= m_environment.input_discrete.signal.control_power_supply_status; + _ready_local &= m_environment.auxiliary_q1.state.signal.is_on; + _ready_local &= m_environment.bypass_ready.state.signal.is_on; + _ready_local &= (m_environment.auxiliary_km2.state.signal.is_on | m_environment.enable_work.boolbit.b0); + _ready_local &= m_environment.auxiliary_km11.state.signal.is_on; + _ready_local &= m_pll_abc_input_voltage.get_sync(); // DON'T FORGET BACK!!!!! + _ready_local &= m_environment.auxiliary_km1.state.signal.is_on; + _ready_local &= m_environment.auxiliary_km3.state.signal.is_on; + _ready_local &= m_environment.hardware.enable; + m_environment.system_ready.boolbit.b0 = _ready_local; + + + + // + // Enable Work + // + SYSCTRL::TriggerRegister::setSet(m_enable_work_trigger, + m_environment.system_ready.boolbit.b0 & + ( + (m_environment.local_remote.state.signal.is_off & m_environment.remote_start.state.signal.is_switched_on) | + (m_environment.local_remote.state.signal.is_on & m_environment.external_start.signal.is_on) + ) + ); + SYSCTRL::TriggerRegister::setReset(m_enable_work_trigger, + !m_environment.system_ready.boolbit.b0 | + m_environment.enable_work_reset.boolbit.b0); + SYSCTRL::TriggerRegister::execute_reset_priority(m_enable_work_trigger); + m_environment.enable_work.boolbit.b0 = (bool)m_enable_work_trigger.signal.is_on; + m_environment.enable_work_is_on.boolbit.b0 = (bool)m_enable_work_trigger.signal.is_switched_on; + m_environment.enable_work_is_off.boolbit.b0 = (bool)m_enable_work_trigger.signal.is_off; + m_environment.enable_work_reset.boolbit.b0 = false; + + + + // + // Auto offset scan + // + m_environment.allow_auto_offset = !m_environment.enable_work.boolbit.b0 & m_environment.enable_auto_offset.signal.is_on; + + + // + // Execute Control Loop + // + + + // Generator ABC + // FOR DEBUG ONLY + #if 3 == 2 + //m_environment.generator_abc.execute(); + //m_environment.generator_abc.get_out(m_environment.gen_ort_a, m_environment.gen_ort_b, m_environment.gen_ort_c); + //FLTSYSLIB::Transformation::clarke_forward(m_environment.gen_ort_a, m_environment.gen_ort_b, m_environment.gen_ort_c, m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + // + //m_environment.gen_symm_comp_inp_volt.execute(m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + //m_environment.gen_symm_comp_inp_volt.get_output(m_environment.voltage_input_a, m_environment.voltage_input_b, m_environment.voltage_input_c); + // + //m_environment.gen_symm_comp_out_volt.execute(m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + //m_environment.gen_symm_comp_out_volt.get_output(m_environment.voltage_load_a, m_environment.voltage_load_b, m_environment.voltage_load_c); + // + //m_environment.gen_symm_comp_out_current.execute(m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + //m_environment.gen_symm_comp_out_current.get_output(m_environment.current_load_a, m_environment.current_load_b, m_environment.current_load_c); + // + //m_environment.gen_symm_comp_input_current.execute(m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + //m_environment.gen_symm_comp_input_current.get_output(m_environment.current_input_a, m_environment.current_input_b, m_environment.current_input_c); + // + //m_environment.gen_symm_comp_bypass_current.execute(m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + //m_environment.gen_symm_comp_bypass_current.get_output(m_environment.current_bypass_a, m_environment.current_bypass_b, m_environment.current_bypass_c); + // + //m_environment.gen_symm_comp_cell_current.execute(m_environment.gen_ort_alpha, m_environment.gen_ort_beta); + //m_environment.gen_symm_comp_cell_current.get_output(m_environment.current_cell_a, m_environment.current_cell_b, m_environment.current_cell_c); + #endif + + + // + // Relative Input Voltage + // + if(m_environment.auxiliary_q1.state.signal.is_on) + { + // Q1 is on + m_environment.reference_phase_a = m_environment.voltage_grid_a; + m_environment.reference_phase_b = m_environment.voltage_grid_b; + m_environment.reference_phase_c = m_environment.voltage_grid_c; + + } + else + { + // Q1 is off + m_environment.reference_phase_a = m_environment.voltage_load_a; + m_environment.reference_phase_b = m_environment.voltage_load_b; + m_environment.reference_phase_c = m_environment.voltage_load_c; + // + }//if else + // + + m_relative_filter_voltage_input_a.execute(m_environment.reference_phase_a); + m_relative_filter_voltage_input_b.execute(m_environment.reference_phase_b); + m_relative_filter_voltage_input_c.execute(m_environment.reference_phase_c); + + m_relative_filter_voltage_input_a.get_outputs(m_environment.relative_voltage_input_a.amplitude, m_environment.relative_voltage_input_a.relative); + m_relative_filter_voltage_input_b.get_outputs(m_environment.relative_voltage_input_b.amplitude, m_environment.relative_voltage_input_b.relative); + m_relative_filter_voltage_input_c.get_outputs(m_environment.relative_voltage_input_c.amplitude, m_environment.relative_voltage_input_c.relative); + //<> + + m_environment.generator_abc.execute(); + m_environment.generator_abc.get_out(m_environment.gen_ort_a, m_environment.gen_ort_b, m_environment.gen_ort_c); + + if (m_environment.auxiliary_q1.state.signal.is_on) + { + m_environment.relative_voltage_input_a.relative = m_environment.gen_ort_a; + m_environment.relative_voltage_input_b.relative = m_environment.gen_ort_b; + m_environment.relative_voltage_input_c.relative = m_environment.gen_ort_c; + } + else + { + m_environment.relative_voltage_input_a.relative = 0; + m_environment.relative_voltage_input_b.relative = 0; + m_environment.relative_voltage_input_c.relative = 0; + } + // + // PLL-ABC Input Voltage + // + m_pll_abc_input_voltage.execute(m_environment.relative_voltage_input_a.relative, + m_environment.relative_voltage_input_b.relative, + m_environment.relative_voltage_input_c.relative); + + m_pll_abc_input_voltage.get_output(m_environment.pll_abc_orts.phase_a.active, + m_environment.pll_abc_orts.phase_b.active, + m_environment.pll_abc_orts.phase_c.active); + + FLTSYSLIB::Transformation::ort_abc_jm_from_real(m_environment.pll_abc_orts.phase_a.active, + m_environment.pll_abc_orts.phase_b.active, + m_environment.pll_abc_orts.phase_c.active, + m_environment.pll_abc_orts.phase_a.reactive, + m_environment.pll_abc_orts.phase_b.reactive, + m_environment.pll_abc_orts.phase_c.reactive); + + + + //if(m_environment.auxiliary_q1.state.signal.is_on) + if(m_pll_abc_input_voltage.get_sync()) + { + m_environment.grid_frequency = m_pll_abc_input_voltage.get_frequency(); + } + else + { + m_environment.grid_frequency = FP_ZERO; + // + }// + + + +#if TYPECONTROL == VECTORCONTROL + // + m_environment.main_abc_orts = m_environment.pll_abc_orts; + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.main_abc_orts.phase_a.active, + m_environment.main_abc_orts.phase_b.active, + m_environment.main_abc_orts.phase_c.active, + m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.voltage_grid_a, + m_environment.voltage_grid_b, + m_environment.voltage_grid_c, + m_environment.voltage_grid_alpha, + m_environment.voltage_grid_beta); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.voltage_load_a, + m_environment.voltage_load_b, + m_environment.voltage_load_c, + m_environment.voltage_load_alpha, + m_environment.voltage_load_beta); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.current_load_a, + m_environment.current_load_b, + m_environment.current_load_c, + m_environment.current_load_alpha, + m_environment.current_load_beta); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.current_bypass_a, + m_environment.current_bypass_b, + m_environment.current_bypass_c, + m_environment.current_bypass_alpha, + m_environment.current_bypass_beta); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.current_cell_a, + m_environment.current_cell_b, + m_environment.current_cell_c, + m_environment.current_cell_alpha, + m_environment.current_cell_beta); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.voltage_grid_alpha, + m_environment.voltage_grid_beta, + m_environment.voltage_grid_direct, + m_environment.voltage_grid_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.voltage_load_alpha, + m_environment.voltage_load_beta, + m_environment.voltage_load_direct, + m_environment.voltage_load_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.current_load_alpha, + m_environment.current_load_beta, + m_environment.current_load_direct, + m_environment.current_load_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.current_bypass_alpha, + m_environment.current_bypass_beta, + m_environment.current_bypass_direct, + m_environment.current_bypass_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.current_cell_alpha, + m_environment.current_cell_beta, + m_environment.current_cell_direct, + m_environment.current_cell_quadrature); + // +#endif + + +#if TYPECONTROL == SCALARCONTROL + + // Decompose Input Voltage + m_decompose_voltage_input_a.execute(m_environment.voltage_grid_a, m_environment.pll_abc_orts.phase_a.active, m_environment.pll_abc_orts.phase_a.reactive); + m_decompose_voltage_input_a.get_outputs(m_environment.projection_voltage_input_a.active, m_environment.projection_voltage_input_a.reactive); + // + m_decompose_voltage_input_b.execute(m_environment.voltage_grid_b, m_environment.pll_abc_orts.phase_b.active, m_environment.pll_abc_orts.phase_b.reactive); + m_decompose_voltage_input_b.get_outputs(m_environment.projection_voltage_input_b.active, m_environment.projection_voltage_input_b.reactive); + // + m_decompose_voltage_input_c.execute(m_environment.voltage_grid_c, m_environment.pll_abc_orts.phase_c.active, m_environment.pll_abc_orts.phase_c.reactive); + m_decompose_voltage_input_c.get_outputs(m_environment.projection_voltage_input_c.active, m_environment.projection_voltage_input_c.reactive); +// m_environment.projection_voltage_input_a = m_environment.test_projection_a; +// m_environment.projection_voltage_input_b = m_environment.test_projection_b; +// m_environment.projection_voltage_input_c = m_environment.test_projection_c; + + + // Main Ort Corrector + if(m_pll_abc_input_voltage.get_sync() && m_environment.auxiliary_q1.state.signal.is_on) + { + + // Spinner + SYSCTRL::VectorSpinner::spin_calculator(m_environment.projection_voltage_input_a, m_environment.module_voltage_phase_a, m_environment.spinner_phase_a); + SYSCTRL::VectorSpinner::spin_calculator(m_environment.projection_voltage_input_b, m_environment.module_voltage_phase_b, m_environment.spinner_phase_b); + SYSCTRL::VectorSpinner::spin_calculator(m_environment.projection_voltage_input_c, m_environment.module_voltage_phase_c, m_environment.spinner_phase_c); + } + else + { + // Reset Spinner + m_environment.spinner_phase_a.active = 1.0; + m_environment.spinner_phase_a.reactive = FP_ZERO; + + m_environment.spinner_phase_b.active = 1.0; + m_environment.spinner_phase_b.reactive = FP_ZERO; + + m_environment.spinner_phase_c.active = 1.0; + m_environment.spinner_phase_c.reactive = FP_ZERO; + // + }//if else + // + SYSCTRL::VectorSpinner::ort_corrector(m_environment.spinner_phase_a, m_environment.pll_abc_orts.phase_a, m_environment.twisted_abc_orts.phase_a); + SYSCTRL::VectorSpinner::ort_corrector(m_environment.spinner_phase_b, m_environment.pll_abc_orts.phase_b, m_environment.twisted_abc_orts.phase_b); + SYSCTRL::VectorSpinner::ort_corrector(m_environment.spinner_phase_c, m_environment.pll_abc_orts.phase_c, m_environment.twisted_abc_orts.phase_c); + //<> + // + FLTSYSLIB::Transformation::ort_abc_jm_from_real(m_environment.twisted_abc_orts.phase_a.active, + m_environment.twisted_abc_orts.phase_b.active, + m_environment.twisted_abc_orts.phase_c.active, + m_environment.twisted_abc_orts.phase_a.reactive, + m_environment.twisted_abc_orts.phase_b.reactive, + m_environment.twisted_abc_orts.phase_c.reactive); + // + //m_environment.main_abc_orts = m_environment.pll_abc_orts; + m_environment.main_abc_orts = m_environment.twisted_abc_orts; + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.main_abc_orts.phase_a.active, + m_environment.main_abc_orts.phase_b.active, + m_environment.main_abc_orts.phase_c.active, + m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive); + // + //Decompose Load Voltage + m_decompose_voltage_load_a.execute(m_environment.voltage_load_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_voltage_load_a.get_outputs(m_environment.projection_voltage_load_a.active, m_environment.projection_voltage_load_a.reactive); + m_decompose_voltage_load_a.get_outputs(m_environment.phase_control.phase_a.feedback.voltage_ampl_real, m_environment.phase_control.phase_a.feedback.voltage_ampl_jm); + // + m_decompose_voltage_load_b.execute(m_environment.voltage_load_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_voltage_load_b.get_outputs(m_environment.projection_voltage_load_b.active, m_environment.projection_voltage_load_b.reactive); + m_decompose_voltage_load_b.get_outputs(m_environment.phase_control.phase_b.feedback.voltage_ampl_real, m_environment.phase_control.phase_b.feedback.voltage_ampl_jm); + // + m_decompose_voltage_load_c.execute(m_environment.voltage_load_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_voltage_load_c.get_outputs(m_environment.projection_voltage_load_c.active, m_environment.projection_voltage_load_c.reactive); + m_decompose_voltage_load_c.get_outputs(m_environment.phase_control.phase_c.feedback.voltage_ampl_real, m_environment.phase_control.phase_c.feedback.voltage_ampl_jm); + +// m_environment.projection_voltage_load_a = m_environment.test_projection_a; +// m_environment.projection_voltage_load_b = m_environment.test_projection_b; +// m_environment.projection_voltage_load_c = m_environment.test_projection_c; + + + //Decompose Load Current + m_decompose_current_load_a.execute(m_environment.current_load_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_current_load_a.get_outputs(m_environment.projection_current_load_a.active, m_environment.projection_current_load_a.reactive); + m_decompose_current_load_a.get_outputs(m_environment.phase_control.phase_a.feedback.current_ampl_real, m_environment.phase_control.phase_a.feedback.current_ampl_jm); + // + m_decompose_current_load_b.execute(m_environment.current_load_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_current_load_b.get_outputs(m_environment.projection_current_load_b.active, m_environment.projection_current_load_b.reactive); + m_decompose_current_load_b.get_outputs(m_environment.phase_control.phase_b.feedback.current_ampl_real, m_environment.phase_control.phase_b.feedback.current_ampl_jm); + // + m_decompose_current_load_c.execute(m_environment.current_load_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_current_load_c.get_outputs(m_environment.projection_current_load_c.active, m_environment.projection_current_load_c.reactive); + m_decompose_current_load_c.get_outputs(m_environment.phase_control.phase_c.feedback.current_ampl_real, m_environment.phase_control.phase_c.feedback.current_ampl_jm); + +// m_environment.projection_current_load_a = m_environment.test_projection_a; +// m_environment.projection_current_load_b = m_environment.test_projection_b; +// m_environment.projection_current_load_c = m_environment.test_projection_c; + + + //Decompose Bypass Current + m_decompose_current_bypass_a.execute(m_environment.current_bypass_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_current_bypass_a.get_outputs(m_environment.projection_current_bypass_a.active, m_environment.projection_current_bypass_a.reactive); + // + m_decompose_current_bypass_b.execute(m_environment.current_bypass_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_current_bypass_b.get_outputs(m_environment.projection_current_bypass_b.active, m_environment.projection_current_bypass_b.reactive); + // + m_decompose_current_bypass_c.execute(m_environment.current_bypass_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_current_bypass_c.get_outputs(m_environment.projection_current_bypass_c.active, m_environment.projection_current_bypass_c.reactive); + +// m_environment.projection_current_bypass_a = m_environment.test_projection_a; +// m_environment.projection_current_bypass_b = m_environment.test_projection_b; +// m_environment.projection_current_bypass_c = m_environment.test_projection_c; + + + //Decompose Cell Current + m_decompose_current_cell_a.execute(m_environment.current_cell_a, m_environment.main_abc_orts.phase_a.active, m_environment.main_abc_orts.phase_a.reactive); + m_decompose_current_cell_a.get_outputs(m_environment.projection_current_cell_a.active, m_environment.projection_current_cell_a.reactive); + // + m_decompose_current_cell_b.execute(m_environment.current_cell_b, m_environment.main_abc_orts.phase_b.active, m_environment.main_abc_orts.phase_b.reactive); + m_decompose_current_cell_b.get_outputs(m_environment.projection_current_cell_b.active, m_environment.projection_current_cell_b.reactive); + // + m_decompose_current_cell_c.execute(m_environment.current_cell_c, m_environment.main_abc_orts.phase_c.active, m_environment.main_abc_orts.phase_c.reactive); + m_decompose_current_cell_c.get_outputs(m_environment.projection_current_cell_c.active, m_environment.projection_current_cell_c.reactive); + // +#endif + + + + + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + m_environment.main_abc_orts = m_environment.pll_abc_orts; + // + FLTSYSLIB::Transformation::ort_direct_to_back(m_environment.main_abc_orts.phase_a.active, + m_environment.main_abc_orts.phase_b.active, + m_environment.main_abc_orts.phase_c.active, + m_environment.main_abc_reverse_orts.phase_a.active, + m_environment.main_abc_reverse_orts.phase_b.active, + m_environment.main_abc_reverse_orts.phase_c.active); + // + FLTSYSLIB::Transformation::ort_back_to_orthogonal(m_environment.main_abc_reverse_orts.phase_a.active, + m_environment.main_abc_reverse_orts.phase_b.active, + m_environment.main_abc_reverse_orts.phase_c.active, + m_environment.main_abc_reverse_orts.phase_a.reactive, + m_environment.main_abc_reverse_orts.phase_b.reactive, + m_environment.main_abc_reverse_orts.phase_c.reactive); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.main_abc_orts.phase_a.active, + m_environment.main_abc_orts.phase_b.active, + m_environment.main_abc_orts.phase_c.active, + m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.voltage_grid_a, + m_environment.voltage_grid_b, + m_environment.voltage_grid_c, + m_environment.drc_voltage_grid_alpha, + m_environment.drc_voltage_grid_beta); + // + /* + FLTSYSLIB::Transformation::clarke_forward(m_environment.voltage_load_a, + m_environment.voltage_load_b, + m_environment.voltage_load_c, + m_environment.drc_voltage_load_alpha, + m_environment.drc_voltage_load_beta); + */ + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.current_load_a, + m_environment.current_load_b, + m_environment.current_load_c, + m_environment.drc_current_load_alpha, + m_environment.drc_current_load_beta); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.current_bypass_a, + m_environment.current_bypass_b, + m_environment.current_bypass_c, + m_environment.drc_current_bypass_alpha, + m_environment.drc_current_bypass_beta); + // + FLTSYSLIB::Transformation::clarke_forward(m_environment.current_cell_a, + m_environment.current_cell_b, + m_environment.current_cell_c, + m_environment.drc_current_cell_alpha, + m_environment.drc_current_cell_beta); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.drc_voltage_grid_alpha, + m_environment.drc_voltage_grid_beta, + m_environment.drc_voltage_grid_direct, + m_environment.drc_voltage_grid_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.drc_current_load_alpha, + m_environment.drc_current_load_beta, + m_environment.drc_current_load_direct, + m_environment.drc_current_load_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.drc_current_bypass_alpha, + m_environment.drc_current_bypass_beta, + m_environment.drc_current_bypass_direct, + m_environment.drc_current_bypass_quadrature); + // + FLTSYSLIB::Transformation::park_forward(m_environment.main_ab_orts.active, + m_environment.main_ab_orts.reactive, + m_environment.drc_current_cell_alpha, + m_environment.drc_current_cell_beta, + m_environment.drc_current_cell_direct, + m_environment.drc_current_cell_quadrature); + // + m_environment.drc_direct_voltage_decomposer.execute(m_environment.voltage_load_a, + m_environment.voltage_load_b, + m_environment.voltage_load_c, + m_environment.main_abc_orts.phase_a.active, + m_environment.main_abc_orts.phase_b.active, + m_environment.main_abc_orts.phase_c.active, + m_environment.main_abc_orts.phase_a.reactive, + m_environment.main_abc_orts.phase_b.reactive, + m_environment.main_abc_orts.phase_c.reactive); + // + m_environment.drc_back_voltage_decomposer.execute(m_environment.voltage_load_a, + m_environment.voltage_load_b, + m_environment.voltage_load_c, + m_environment.main_abc_reverse_orts.phase_a.active, + m_environment.main_abc_reverse_orts.phase_b.active, + m_environment.main_abc_reverse_orts.phase_c.active, + m_environment.main_abc_reverse_orts.phase_a.reactive, + m_environment.main_abc_reverse_orts.phase_b.reactive, + m_environment.main_abc_reverse_orts.phase_c.reactive); + // + m_environment.drc_positive_voltage_load_direct = m_environment.drc_direct_voltage_decomposer.direct; + m_environment.drc_positive_voltage_load_quadrature = m_environment.drc_direct_voltage_decomposer.quadrature; + m_environment.drc_negaative_voltage_load_direct = m_environment.drc_back_voltage_decomposer.direct; + m_environment.drc_negative_voltage_load_quadrature = m_environment.drc_back_voltage_decomposer.quadrature; + // +#endif + + + + +/* + harmonica_multiplyer(m_environment.main_ab_orts.active, m_environment.main_ab_orts.reactive, + m_environment.main_ab_orts.active, m_environment.main_ab_orts.reactive, + m_environment.harmonica_2.active, m_environment.harmonica_2.reactive); + */ + // + /* + harmonica_multiplyer(m_environment.harmonica_2.active, m_environment.harmonica_2.reactive, + m_environment.main_ab_orts.active, m_environment.main_ab_orts.active, + m_environment.harmonica_3.active, m_environment.harmonica_3.reactive); + */ + // + /* + harmonica_multiplyer(m_environment.harmonica_2.active, m_environment.harmonica_2.reactive, + m_environment.harmonica_3.active, m_environment.harmonica_3.reactive, + m_environment.harmonica_5.active, m_environment.harmonica_5.reactive); + */ + // + /* + harmonica_multiplyer(m_environment.harmonica_2.active, m_environment.harmonica_2.reactive, + m_environment.harmonica_5.active, m_environment.harmonica_5.reactive, + m_environment.harmonica_7.active, m_environment.harmonica_7.reactive); + */ + // + /* + harmonica_multiplyer(m_environment.harmonica_2.active, m_environment.harmonica_2.reactive, + m_environment.harmonica_7.active, m_environment.harmonica_7.reactive, + m_environment.harmonica_9.active, m_environment.harmonica_9.reactive); + */ + // + /* + harmonica_multiplyer(m_environment.harmonica_2.active, m_environment.harmonica_2.reactive, + m_environment.harmonica_9.active, m_environment.harmonica_9.reactive, + m_environment.harmonica_11.active, m_environment.harmonica_11.reactive); + */ + // + + //m_environment.voltage_input_a_harmonica_5 = m_voltage_input_a_harmonica_filter_5.execute(m_environment.voltage_input_a, m_environment.sys_ort_cos_h5, m_environment.sys_ort_sin_h5); + //m_environment.voltage_input_b_harmonica_5 = m_voltage_input_b_harmonica_filter_5.execute(m_environment.voltage_input_b, m_environment.sys_ort_cos_h5, m_environment.sys_ort_sin_h5); + //m_environment.voltage_input_c_harmonica_5 = m_voltage_input_c_harmonica_filter_5.execute(m_environment.voltage_input_c, m_environment.sys_ort_cos_h5, m_environment.sys_ort_sin_h5); + + // + // Define algorithm + // + m_algorithm.strategy(); + m_algorithm_executed = m_algorithm.get_algorithm(); + m_algorithm.execute(); + m_algorithm.get_ref_invertor_voltage(m_environment.hardware.hvcell.data_u, m_environment.hardware.hvcell.data_v, m_environment.hardware.hvcell.data_w); + + + // Q1 Control + // on - 4006; off - 4007 + SYSCTRL::TriggerRegister::setSet(m_q1_control_trigger, + (!m_environment.system_fault.boolbit.b0) & m_q1_external_command_trigger.signal.quit); + SYSCTRL::TriggerRegister::setReset(m_q1_control_trigger, + m_q1_external_command_trigger.signal.negquit); + SYSCTRL::TriggerRegister::execute_reset_priority(m_q1_control_trigger); + + // KM1 Control + // on - 4011; off - 4012 + SYSCTRL::TriggerRegister::setSet(m_km1_control_trigger, + (!m_environment.system_fault.boolbit.b0) & m_km1_external_command_trigger.signal.quit); + SYSCTRL::TriggerRegister::setReset(m_km1_control_trigger, + m_km1_external_command_trigger.signal.negquit); + SYSCTRL::TriggerRegister::execute_reset_priority(m_km1_control_trigger); + + // KM3 Control + // on - 4018; off - 4020 + SYSCTRL::TriggerRegister::setSet(m_km3_control_trigger, + (!m_environment.system_fault.boolbit.b0) & m_km3_external_command_trigger.signal.quit); + SYSCTRL::TriggerRegister::setReset(m_km3_control_trigger, + m_km3_external_command_trigger.signal.negquit); + SYSCTRL::TriggerRegister::execute_reset_priority(m_km3_control_trigger); + + // KM11 Control + // on/off - 4008 + SYSCTRL::TriggerRegister::setSet(m_km11_control_on_off_trigger, m_environment.arc_and_fire.state.signal.is_off); + SYSCTRL::TriggerRegister::setReset(m_km11_control_on_off_trigger, m_environment.arc_and_fire.state.signal.is_on); + SYSCTRL::TriggerRegister::execute_reset_priority(m_km11_control_on_off_trigger); + + + + // KM2 Control + // on - 4013; off - 4014 + SYSCTRL::TriggerRegister::setSet(m_km2_control_trigger, + m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::UNKNOWN) | + (m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::START) & m_environment.timer_start.is_running()) | + (m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::STOP) & m_environment.timer_stop.is_finished()) | + m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::FAULT) | + m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::OFF) + ); + SYSCTRL::TriggerRegister::setReset(m_km2_control_trigger, + (m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::START) & m_environment.timer_start.is_finished()) | + (m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::STOP) & m_environment.timer_stop.is_running()) | + m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::SOURCE) | + m_algorithm.compare_algorithm(SYSCTRL::AlgorithmContext::WORK) + ); + SYSCTRL::TriggerRegister::execute_reset_priority(m_km2_control_trigger); + + + // Short Circuit VS Control + SYSCTRL::TriggerRegister::setSet(m_vs_protection_control_trigger, + m_environment.auxiliary_km2.state.signal.is_off & m_vs_protection_control_trigger.signal.quit); + SYSCTRL::TriggerRegister::setReset(m_vs_protection_control_trigger, + m_environment.auxiliary_km2.state.signal.is_on); + SYSCTRL::TriggerRegister::execute_reset_priority(m_vs_protection_control_trigger); + hardware_analog_current_fault.signal.vs = m_vs_protection_control_trigger.signal.quit; + + // + // Digital Output Register filling + // + + m_environment.digital_output.signal.work = m_environment.enable_work.boolbit.b0; // 4001 Running + // + m_environment.digital_output.signal.fault = m_environment.system_fault.boolbit.b0; // 4002 Fault + // + m_environment.digital_output.signal.ready = m_environment.system_ready.boolbit.b0; // 4003 Ready; + // + m_environment.digital_output.signal.alarm = m_environment.system_alarm.boolbit.b0; // 4004 Alarm; + // + m_environment.digital_output.signal.off_high_voltage_q1 = m_environment.system_fault.boolbit.b0; // 4005 off Q1 + // +// m_environment.digital_output.signal.on_q1 = m_q1_control_trigger.signal.quit & !m_environment.input_discrete.signal.auxiliary_q1; // 4006 on Q1 + m_environment.digital_output.signal.on_q1 = m_q1_control_trigger.signal.quit; // 4006 on Q1 + // + m_environment.digital_output.signal.off_q1 = m_q1_control_trigger.signal.negquit & m_environment.input_discrete.signal.auxiliary_q1; // 4007 off Q1 + // + m_environment.digital_output.signal.on_km11 = m_km11_control_on_off_trigger.signal.quit; // 4008 on KM11 + // + m_environment.digital_output.signal.vs_control = m_vs_protection_control_trigger.signal.quit; // 4009 Short Circuit VS + // + m_environment.digital_output.signal.allow_on_high_voltage = !m_environment.system_fault.boolbit.b0; // 4010 enable on Q1 + // + m_environment.digital_output.signal.on_km1 = m_km1_control_trigger.signal.quit & !m_environment.input_discrete.signal.auxiliary_km1; // 4011 on KM1 + // + m_environment.digital_output.signal.off_km1 = m_km1_control_trigger.signal.negquit & m_environment.input_discrete.signal.auxiliary_km1; // 4012 off KM1 + // + m_environment.digital_output.signal.on_km2 = m_km2_control_trigger.signal.quit & m_environment.auxiliary_km2.state.signal.is_off; // 4013 on KM2 + // + m_environment.digital_output.signal.off_km2 = m_km2_control_trigger.signal.negquit & m_environment.auxiliary_km2.state.signal.is_on; // 4014 off KM2 + // + m_environment.digital_output.signal.high_voltage_indicator = m_environment.auxiliary_q1.state.signal.is_on; // 4015 high voltage!! + // + m_environment.digital_output.signal.reserved_b15 = m_km1_control_trigger.signal.quit; // 4016 + // + m_environment.digital_output.signal.mode_local_remote = m_environment.local_remote.state.signal.is_on; // 4017 Local/Remote indication + // + m_environment.digital_output.signal.on_km3 = m_km3_control_trigger.signal.quit & !m_environment.input_discrete.signal.auxiliary_km3; // 4018 on KM3 + // + m_environment.digital_output.signal.on_km11t = m_environment.fan_control.is_on(); // 4019 on KM11T + // + m_environment.digital_output.signal.off_km3 = m_km3_control_trigger.signal.negquit & m_environment.input_discrete.signal.auxiliary_km3; // 4020 off KM3 + + // FOR DEBUG ONLY + //m_environment.digital_output.all = m_environment.digital_output_temp.all; + + + m_environment.digital_output_inverse.all = m_environment.digital_output.all ^ 0xFFFFFFFF ; + + + // FOR DEBUG ONLY !!!! + //m_environment.digital_output_inverse.all = m_environment.digital_output_temp.all ^ 0xFFFFFFFF ; + //m_environment.digital_output_inverse.all = m_environment.digital_output_temp.all; + + + m_environment.counter_slow--; + m_environment.counter_additional--; + m_environment.counter_symmetrical--; + + + + // Generator PWM + #if 2 == 3 + static float _gen_pwm_a, _gen_pwm_b, _gen_pwm_c; + m_environment.generator_pwm.implement(); + m_environment.generator_pwm.get_out(_gen_pwm_a, _gen_pwm_b, _gen_pwm_c); + + m_environment.hardware.hvcell.data_u = m_environment.amplitude_generator_pwm * _gen_pwm_a; + m_environment.hardware.hvcell.data_v = m_environment.amplitude_generator_pwm * _gen_pwm_b; + m_environment.hardware.hvcell.data_w = m_environment.amplitude_generator_pwm * _gen_pwm_c; + #endif + + + + // + // Scale Compute + // + /* + if(m_environment.scale_compute_voltage_command.bit.start == 1) + { + m_environment.scale_compute_voltage_command.bit.start = 0; + m_environment.scale_compute_voltage_input.fix(); + m_environment.scale_compute_voltage_load.fix(); + // + }//if + */ + // + /* + if(m_environment.scale_compute_current_command.bit.start == 1) + { + m_environment.scale_compute_current_command.bit.start = 0; + //m_environment.scale_compute_current_cell.fix(); + //m_environment.scale_compute_current_load.fix(); + //m_environment.scale_compute_current_bypass.fix(); + //m_environment.scale_compute_current_input.fix(); + // + }//if + */ + + // +}//_execute_operational() +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SystemControlMODBUSRTU.cpp b/SYSCTRL/SystemControlMODBUSRTU.cpp new file mode 100644 index 0000000..5ec4786 --- /dev/null +++ b/SYSCTRL/SystemControlMODBUSRTU.cpp @@ -0,0 +1,1465 @@ +/* + * SystemControlMODBUSRTU.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + + +#include "SYSCTRL/SystemControl.h" + +namespace SYSCTRL +{ + + +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::inc_break_counter() +{ + m_modbus_break_counter++; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::set_break_counter(Uint16 count) +{ + m_modbus_break_counter = count; + // +}// +// + +//#pragma CODE_SECTION("ramfuncs"); +void SystemControl::modbusrtu_rubus_interface(Uint16 rdReg[], Uint16 wrReg[]) +{ + // + // Accept data + m_rubus.response_shadow.command.all = 0; + m_rubus.accepted.command_start.all = wrReg[1]; + m_rubus.accepted.id.byte.bt1 = m_rubus.accepted.command_start.byte.bt1; + m_rubus.accepted.com.byte.bt0 = m_rubus.accepted.command_start.byte.bt0; + + m_rubus.accepted.index = wrReg[2]; + + m_environment.external_command_word.all = (uint16_t)wrReg[6]; + + + if(m_rubus.accepted.command_start.all == 0) + { + //command reset + m_rubus.accepted.command_end.all = 0x0000; + m_rubus.accepted.com.all = 0x0000; + m_rubus.accepted.data.word.wL.all = 0x0000; + m_rubus.accepted.data.word.wH.all = 0x0000; + m_rubus.accepted.id.all = 0x0000; + m_rubus.accepted.index = 0x0000; + + m_rubus.response_shadow.command.all = 0x0000; + m_rubus.response_shadow.index = 0x0000; + m_rubus.response_shadow.data.word.wL.all = 0x0000; + m_rubus.response_shadow.data.word.wH.all = 0x0000; + + m_rubus.mode = MODBUSRTU::RUBUS::RUBUS_RESET; + } + else + { + // not reset + // + if(m_rubus.accepted.com.bit.b00 == 0) + { + // highly likely command is read + m_rubus.accepted.data.all = (uint32_t)0; + m_rubus.accepted.command_end.all = wrReg[3]; + + // + } + else + { + // highly likely command is write + m_rubus.accepted.data.word.wL.all = wrReg[3]; + m_rubus.accepted.data.word.wH.all = wrReg[4]; + m_rubus.accepted.command_end.all = wrReg[5]; + + // + }//if else + // + if(m_rubus.accepted.command_start.all == m_rubus.accepted.command_end.all) + { + if((m_rubus.accepted.index != 0)&&(m_rubus.accepted.index <= m_rubus.size)) + { + + // command & index is valid + // + if(m_rubus.accepted.com.bit.b00 == 0) + { + //command is read + m_rubus.mode = MODBUSRTU::RUBUS::RUBUS_READ; + } + else + { + //command is write + m_rubus.mode = MODBUSRTU::RUBUS::RUBUS_WRITE; + // + }//if else + + _modbusrtu_rubus_read_write_register(); + + // + } + else + { + + // index is not valid + // error - wrong index + m_rubus.mode = MODBUSRTU::RUBUS::RUBUS_ERROR; + // + }//if else + // + } + else + { + // command is not valid + // error - wrong command + m_rubus.mode = MODBUSRTU::RUBUS::RUBUS_RESET; + // + }//if else + // + + + }//if else + // + switch(m_rubus.mode) + { + case MODBUSRTU::RUBUS::RUBUS_RESET: + { + //reset or wrong command + m_rubus.accepted.id.all = 0x0000; + m_rubus.accepted.com.all = 0x0000; + m_rubus.accepted.data.all = (uint32_t)0; + m_rubus.response_shadow.command.all = 0x0000; + m_rubus.response_shadow.data.word.wL.all = 0x0000; + m_rubus.response_shadow.data.word.wH.all = 0x0000; + m_rubus.response = m_rubus.response_shadow; + rdReg[1] = 0x0000; + rdReg[2] = 0x0000; + rdReg[3] = 0x0000; + rdReg[4] = 0x0000; + rdReg[5] = 0x0000; + break; + } + case MODBUSRTU::RUBUS::RUBUS_READ: + { + //command is read + m_rubus.response = m_rubus.response_shadow; + rdReg[1] = m_rubus.response.command.all; + rdReg[2] = m_rubus.response.data.word.wL.all; + rdReg[3] = m_rubus.response.data.word.wH.all; + rdReg[4] = m_rubus.response.command.all; + rdReg[5] = 0x0000; + break; + } + case MODBUSRTU::RUBUS::RUBUS_WRITE: + { + //command is write + m_rubus.response = m_rubus.response_shadow; + rdReg[1] = m_rubus.response.command.all; + rdReg[2] = 0; + rdReg[3] = 0; + rdReg[4] = 0; + rdReg[5] = 0x0000; + break; + } + case MODBUSRTU::RUBUS::RUBUS_ERROR: + { + //wrong index + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all + m_rubus.mask.error_response.all; + m_rubus.response_shadow.data.word.wL.all = 0x0000; + m_rubus.response_shadow.data.word.wH.all = 0x0000; + m_rubus.response = m_rubus.response_shadow; + rdReg[1] = m_rubus.response.command.all; + rdReg[2] = 0x0000; + rdReg[3] = 0x0000; + rdReg[4] = 0x0000; + rdReg[5] = 0x0000; + break; + } + default: + { + + break; + } + }//switch + // + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_modbusrtu_rubus_read_write_register() +{ +/* switch(m_rubus.accepted.index) + { + case 1: + { + _modbusrtu_rubus_read_write_float(m_temp_configuration.regulator_voltage_load.gain); + break; + } + + case 2: + { + _modbusrtu_rubus_read_write_float(m_temp_configuration.regulator_voltage_load.time); + break; + } + case 3: + { + _modbusrtu_rubus_read_write_float(m_temp_configuration.regulator_voltage_load.low_saturation); + break; + } + case 4: + { + _modbusrtu_rubus_read_write_float(m_temp_configuration.regulator_voltage_load.high_saturation); + break; + } + default: + { + m_rubus.response.data.f = FP_ZERO; + + break; + } + }*/ //switch + // + + + + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + // + m_rubus.m_cell = m_rubus_data.get_register(m_rubus.accepted.index); + m_rubus.cell_data.all = m_rubus.m_cell.read_register().all; + // + switch(m_rubus.m_cell.get_type()) + { + case MODBUSRTU::RUBUS_BOOL: + { + //command is read + m_rubus.response_shadow.data.b = m_rubus.m_cell.read_register().b; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_FLOAT: + { + //command is read + m_rubus.response_shadow.data.f = m_rubus.m_cell.read_register().f; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_float.all; + break; + } + case MODBUSRTU::RUBUS_UINT8: + { + //command is read + m_rubus.response_shadow.data.u8 = m_rubus.m_cell.read_register().u8; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_uint8.all; + break; + } + case MODBUSRTU::RUBUS_UINT16: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_uint16.all; + break; + } + case MODBUSRTU::RUBUS_UINT32: + { + //command is read + m_rubus.response_shadow.data.u32 = m_rubus.m_cell.read_register().u32; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_uint32.all; + break; + } + case MODBUSRTU::RUBUS_INT8: + { + //command is read + m_rubus.response_shadow.data.i8 = m_rubus.m_cell.read_register().i8; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_int8.all; + break; + } + case MODBUSRTU::RUBUS_INT16: + { + //command is read + m_rubus.response_shadow.data.i16 = m_rubus.m_cell.read_register().i16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_int16.all; + break; + } + case MODBUSRTU::RUBUS_INT32: + { + //command is read + m_rubus.response_shadow.data.i32 = m_rubus.m_cell.read_register().i32; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_int32.all; + break; + } + case MODBUSRTU::RUBUS_BIT0: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT1: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT2: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT3: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT4: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT5: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT6: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT7: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT8: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT9: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT10: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT11: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT12: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT13: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT14: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT15: + { + //command is read + m_rubus.response_shadow.data.u16 = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT16: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT17: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT18: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT19: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT20: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT21: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT22: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT23: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT24: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT25: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT26: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT27: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT28: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT29: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT30: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + case MODBUSRTU::RUBUS_BIT31: + { + //command is read + m_rubus.response_shadow.data.word.wH.all = m_rubus.m_cell.read_register().u16; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + break; + } + // + }//switch + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + // + m_rubus.m_cell = m_rubus_data.get_register(m_rubus.accepted.index); + m_rubus.response_shadow.command.all = m_rubus.m_cell.write_register(m_rubus.accepted.data.all); + m_rubus.response_shadow.command.all |= m_rubus.accepted.command_start.all; + // + }//if + // +}// + + +//#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_modbusrtu_rubus_read_write_bool(bool& param) +{ + + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + m_rubus.response_shadow.data.f = param; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_bool.all; + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + param = m_rubus.accepted.data.b; + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all; + // + }//if + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_modbusrtu_rubus_read_write_float(float& param) +{ + + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + m_rubus.response_shadow.data.f = param; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_float.all; + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + param = m_rubus.accepted.data.f; + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all; + // + }//if + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_modbusrtu_rubus_read_write_uint16(uint16_t& param) +{ + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + m_rubus.response_shadow.data.u16 = param; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_uint16.all; + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + param = m_rubus.accepted.data.u16; + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all; + // + }//if + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_modbusrtu_rubus_read_write_uint32(uint32_t& param) +{ + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + m_rubus.response_shadow.data.u32 = param; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_uint32.all; + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + param = m_rubus.accepted.data.u32; + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all; + // + }//if + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_modbusrtu_rubus_read_write_int16(int16_t& param) +{ + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + m_rubus.response_shadow.data.i16 = param; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_int16.all; + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + param = m_rubus.accepted.data.i16; + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all; + // + }//if + // +}// +// +//#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_modbusrtu_rubus_read_write_int32(int32_t& param) +{ + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_READ) + { + //command is read + m_rubus.response_shadow.data.i32 = param; + m_rubus.response_shadow.command.byte.bt1 = m_rubus.accepted.id.byte.bt1; + m_rubus.response_shadow.command.bit.b00 = m_rubus.accepted.com.bit.b00; + m_rubus.response_shadow.command.all |= m_rubus.mask.rubus_int32.all; + // + }//if + // + if(m_rubus.mode == MODBUSRTU::RUBUS::RUBUS_WRITE) + { + //command is write + param = m_rubus.accepted.data.i32; + m_rubus.response_shadow.command.all = m_rubus.accepted.command_start.all; + // + }//if + // +}// +// +void SystemControl::_modbusrtu_rubus_configurate() +{ + + + m_rubus_data.add_register_uint32(1, 1, &m_test_read_word.u32); + // + m_rubus_data.add_register_float(2, 1, &m_environment.rms_voltage_input_ab); + m_rubus_data.add_register_float(3, 1, &m_environment.rms_voltage_input_bc); + m_rubus_data.add_register_float(4, 1, &m_environment.rms_voltage_input_ca); + // + m_rubus_data.add_register_float(5, 1, &m_environment.rms_voltage_load_ab); + m_rubus_data.add_register_float(6, 1, &m_environment.rms_voltage_load_bc); + m_rubus_data.add_register_float(7, 1, &m_environment.rms_voltage_load_ca); + // + m_rubus_data.add_register_float(8, 1, &m_environment.rms_current_input_a); + m_rubus_data.add_register_float(9, 1, &m_environment.rms_current_input_b); + m_rubus_data.add_register_float(10, 1, &m_environment.rms_current_input_c); + // + m_rubus_data.add_register_float(11, 1, &m_environment.rms_current_load_a); + m_rubus_data.add_register_float(12, 1, &m_environment.rms_current_load_b); + m_rubus_data.add_register_float(13, 1, &m_environment.rms_current_load_c); + // + m_rubus_data.add_register_float(14, 1, &m_environment.rms_current_cell_a); + m_rubus_data.add_register_float(15, 1, &m_environment.rms_current_cell_b); + m_rubus_data.add_register_float(16, 1, &m_environment.rms_current_cell_c); + // + m_rubus_data.add_register_float(17, 1, &m_environment.rms_current_bypass_a); + m_rubus_data.add_register_float(18, 1, &m_environment.rms_current_bypass_b); + m_rubus_data.add_register_float(19, 1, &m_environment.rms_current_bypass_c); + // + m_rubus_data.add_register_float(20, 1, &m_environment.voltage_grid_a); + m_rubus_data.add_register_float(21, 1, &m_environment.voltage_grid_b); + m_rubus_data.add_register_float(22, 1, &m_environment.voltage_grid_c); + // + m_rubus_data.add_register_float(23, 1, &m_environment.voltage_load_a); + m_rubus_data.add_register_float(24, 1, &m_environment.voltage_load_b); + m_rubus_data.add_register_float(25, 1, &m_environment.voltage_load_c); + // + m_rubus_data.add_register_float(26, 1, &m_environment.current_input_a); + m_rubus_data.add_register_float(27, 1, &m_environment.current_input_b); + m_rubus_data.add_register_float(28, 1, &m_environment.current_input_c); + // + m_rubus_data.add_register_float(29, 1, &m_environment.current_load_a); + m_rubus_data.add_register_float(30, 1, &m_environment.current_load_b); + m_rubus_data.add_register_float(31, 1, &m_environment.current_load_c); + // + m_rubus_data.add_register_float(32, 1, &m_environment.current_cell_a); + m_rubus_data.add_register_float(33, 1, &m_environment.current_cell_b); + m_rubus_data.add_register_float(34, 1, &m_environment.current_cell_c); + // + m_rubus_data.add_register_float(35, 1, &m_environment.current_bypass_a); + m_rubus_data.add_register_float(36, 1, &m_environment.current_bypass_b); + m_rubus_data.add_register_float(37, 1, &m_environment.current_bypass_c); + // + // reserved 38 + // reserved 39 + // reserved 40 + // reserved 41 + // reserved 42 + // reserved 43 + // reserved 44 + // reserved 45 + // + m_rubus_data.add_register_float(46, 0, &m_system_configuration.scale_voltage_input_a); + m_rubus_data.add_register_float(47, 0, &m_system_configuration.scale_voltage_input_b); + m_rubus_data.add_register_float(48, 0, &m_system_configuration.scale_voltage_input_c); + // + m_rubus_data.add_register_float(49, 0, &m_system_configuration.scale_voltage_load_a); + m_rubus_data.add_register_float(50, 0, &m_system_configuration.scale_voltage_load_b); + m_rubus_data.add_register_float(51, 0, &m_system_configuration.scale_voltage_load_c); + // + m_rubus_data.add_register_float(52, 0, &m_system_configuration.scale_current_input_a); + m_rubus_data.add_register_float(53, 0, &m_system_configuration.scale_current_input_b); + m_rubus_data.add_register_float(54, 0, &m_system_configuration.scale_current_input_c); + // + m_rubus_data.add_register_float(55, 0, &m_system_configuration.scale_current_load_a); + m_rubus_data.add_register_float(56, 0, &m_system_configuration.scale_current_load_b); + m_rubus_data.add_register_float(57, 0, &m_system_configuration.scale_current_load_c); + // + m_rubus_data.add_register_float(58, 0, &m_system_configuration.scale_current_cell_a); + m_rubus_data.add_register_float(59, 0, &m_system_configuration.scale_current_cell_b); + m_rubus_data.add_register_float(60, 0, &m_system_configuration.scale_current_cell_c); + // + m_rubus_data.add_register_float(61, 0, &m_system_configuration.scale_current_bypass_a); + m_rubus_data.add_register_float(62, 0, &m_system_configuration.scale_current_bypass_b); + m_rubus_data.add_register_float(63, 0, &m_system_configuration.scale_current_bypass_c); + // + m_rubus_data.add_register_float(64, 1, &m_environment.offset_voltage_grid_a); + m_rubus_data.add_register_float(65, 1, &m_environment.offset_voltage_grid_b); + m_rubus_data.add_register_float(66, 1, &m_environment.offset_voltage_grid_c); + // + m_rubus_data.add_register_float(67, 1, &m_environment.offset_voltage_load_a); + m_rubus_data.add_register_float(68, 1, &m_environment.offset_voltage_load_b); + m_rubus_data.add_register_float(69, 1, &m_environment.offset_voltage_load_c); + // + m_rubus_data.add_register_float(70, 1, &m_environment.offset_current_input_a); + m_rubus_data.add_register_float(71, 1, &m_environment.offset_current_input_b); + m_rubus_data.add_register_float(72, 1, &m_environment.offset_current_input_c); + // + m_rubus_data.add_register_float(73, 1, &m_environment.offset_current_load_a); + m_rubus_data.add_register_float(74, 1, &m_environment.offset_current_load_b); + m_rubus_data.add_register_float(75, 1, &m_environment.offset_current_load_c); + // + m_rubus_data.add_register_float(76, 1, &m_environment.offset_current_cell_a); + m_rubus_data.add_register_float(77, 1, &m_environment.offset_current_cell_b); + m_rubus_data.add_register_float(78, 1, &m_environment.offset_current_cell_c); + // + m_rubus_data.add_register_float(79, 1, &m_environment.offset_current_bypass_a); + m_rubus_data.add_register_float(80, 1, &m_environment.offset_current_bypass_b); + m_rubus_data.add_register_float(81, 1, &m_environment.offset_current_bypass_c); + // + m_rubus_data.add_register_uint16(82, 1, &m_environment.hardware.hvcell.state[0][0].all); + m_rubus_data.add_register_uint16(83, 1, &m_environment.hardware.hvcell.state[0][1].all); + m_rubus_data.add_register_uint16(84, 1, &m_environment.hardware.hvcell.state[0][2].all); + m_rubus_data.add_register_uint16(85, 1, &m_environment.hardware.hvcell.state[0][3].all); + m_rubus_data.add_register_uint16(86, 1, &m_environment.hardware.hvcell.state[0][4].all); + m_rubus_data.add_register_uint16(87, 1, &m_environment.hardware.hvcell.state[0][5].all); + m_rubus_data.add_register_uint16(88, 1, &m_environment.hardware.hvcell.state[0][6].all); + m_rubus_data.add_register_uint16(89, 1, &m_environment.hardware.hvcell.state[0][7].all); + m_rubus_data.add_register_uint16(90, 1, &m_environment.hardware.hvcell.state[0][8].all); + m_rubus_data.add_register_uint16(91, 1, &m_environment.hardware.hvcell.state[0][9].all); + // + m_rubus_data.add_register_uint16(92, 1, &m_environment.hardware.hvcell.state[1][0].all); + m_rubus_data.add_register_uint16(93, 1, &m_environment.hardware.hvcell.state[1][1].all); + m_rubus_data.add_register_uint16(94, 1, &m_environment.hardware.hvcell.state[1][2].all); + m_rubus_data.add_register_uint16(95, 1, &m_environment.hardware.hvcell.state[1][3].all); + m_rubus_data.add_register_uint16(96, 1, &m_environment.hardware.hvcell.state[1][4].all); + m_rubus_data.add_register_uint16(97, 1, &m_environment.hardware.hvcell.state[1][5].all); + m_rubus_data.add_register_uint16(98, 1, &m_environment.hardware.hvcell.state[1][6].all); + m_rubus_data.add_register_uint16(99, 1, &m_environment.hardware.hvcell.state[1][7].all); + m_rubus_data.add_register_uint16(100, 1, &m_environment.hardware.hvcell.state[1][8].all); + m_rubus_data.add_register_uint16(101, 1, &m_environment.hardware.hvcell.state[1][9].all); + // + m_rubus_data.add_register_uint16(102, 1, &m_environment.hardware.hvcell.state[2][0].all); + m_rubus_data.add_register_uint16(103, 1, &m_environment.hardware.hvcell.state[2][1].all); + m_rubus_data.add_register_uint16(104, 1, &m_environment.hardware.hvcell.state[2][2].all); + m_rubus_data.add_register_uint16(105, 1, &m_environment.hardware.hvcell.state[2][3].all); + m_rubus_data.add_register_uint16(106, 1, &m_environment.hardware.hvcell.state[2][4].all); + m_rubus_data.add_register_uint16(107, 1, &m_environment.hardware.hvcell.state[2][5].all); + m_rubus_data.add_register_uint16(108, 1, &m_environment.hardware.hvcell.state[2][6].all); + m_rubus_data.add_register_uint16(109, 1, &m_environment.hardware.hvcell.state[2][7].all); + m_rubus_data.add_register_uint16(110, 1, &m_environment.hardware.hvcell.state[2][8].all); + m_rubus_data.add_register_uint16(111, 1, &m_environment.hardware.hvcell.state[2][9].all); + // + m_rubus_data.add_register_float(112, 1, &m_environment.hardware.hvcell.dc_voltage[0][0]); + m_rubus_data.add_register_float(113, 1, &m_environment.hardware.hvcell.dc_voltage[0][1]); + m_rubus_data.add_register_float(114, 1, &m_environment.hardware.hvcell.dc_voltage[0][2]); + m_rubus_data.add_register_float(115, 1, &m_environment.hardware.hvcell.dc_voltage[0][3]); + m_rubus_data.add_register_float(116, 1, &m_environment.hardware.hvcell.dc_voltage[0][4]); + m_rubus_data.add_register_float(117, 1, &m_environment.hardware.hvcell.dc_voltage[0][5]); + m_rubus_data.add_register_float(118, 1, &m_environment.hardware.hvcell.dc_voltage[0][6]); + m_rubus_data.add_register_float(119, 1, &m_environment.hardware.hvcell.dc_voltage[0][7]); + m_rubus_data.add_register_float(120, 1, &m_environment.hardware.hvcell.dc_voltage[0][8]); + m_rubus_data.add_register_float(121, 1, &m_environment.hardware.hvcell.dc_voltage[0][9]); + // + m_rubus_data.add_register_float(122, 1, &m_environment.hardware.hvcell.dc_voltage[1][0]); + m_rubus_data.add_register_float(123, 1, &m_environment.hardware.hvcell.dc_voltage[1][1]); + m_rubus_data.add_register_float(124, 1, &m_environment.hardware.hvcell.dc_voltage[1][2]); + m_rubus_data.add_register_float(125, 1, &m_environment.hardware.hvcell.dc_voltage[1][3]); + m_rubus_data.add_register_float(126, 1, &m_environment.hardware.hvcell.dc_voltage[1][4]); + m_rubus_data.add_register_float(127, 1, &m_environment.hardware.hvcell.dc_voltage[1][5]); + m_rubus_data.add_register_float(128, 1, &m_environment.hardware.hvcell.dc_voltage[1][6]); + m_rubus_data.add_register_float(129, 1, &m_environment.hardware.hvcell.dc_voltage[1][7]); + m_rubus_data.add_register_float(130, 1, &m_environment.hardware.hvcell.dc_voltage[1][8]); + m_rubus_data.add_register_float(131, 1, &m_environment.hardware.hvcell.dc_voltage[1][9]); + // + m_rubus_data.add_register_float(132, 1, &m_environment.hardware.hvcell.dc_voltage[2][0]); + m_rubus_data.add_register_float(133, 1, &m_environment.hardware.hvcell.dc_voltage[2][1]); + m_rubus_data.add_register_float(134, 1, &m_environment.hardware.hvcell.dc_voltage[2][2]); + m_rubus_data.add_register_float(135, 1, &m_environment.hardware.hvcell.dc_voltage[2][3]); + m_rubus_data.add_register_float(136, 1, &m_environment.hardware.hvcell.dc_voltage[2][4]); + m_rubus_data.add_register_float(137, 1, &m_environment.hardware.hvcell.dc_voltage[2][5]); + m_rubus_data.add_register_float(138, 1, &m_environment.hardware.hvcell.dc_voltage[2][6]); + m_rubus_data.add_register_float(139, 1, &m_environment.hardware.hvcell.dc_voltage[2][7]); + m_rubus_data.add_register_float(140, 1, &m_environment.hardware.hvcell.dc_voltage[2][8]); + m_rubus_data.add_register_float(141, 1, &m_environment.hardware.hvcell.dc_voltage[2][9]); + // + m_rubus_data.add_register_uint16(142, 1, &m_environment.hardware.hvcell.version[0][0]); + m_rubus_data.add_register_uint16(143, 1, &m_environment.hardware.hvcell.version[0][1]); + m_rubus_data.add_register_uint16(144, 1, &m_environment.hardware.hvcell.version[0][2]); + m_rubus_data.add_register_uint16(145, 1, &m_environment.hardware.hvcell.version[0][3]); + m_rubus_data.add_register_uint16(146, 1, &m_environment.hardware.hvcell.version[0][4]); + m_rubus_data.add_register_uint16(147, 1, &m_environment.hardware.hvcell.version[0][5]); + m_rubus_data.add_register_uint16(148, 1, &m_environment.hardware.hvcell.version[0][6]); + m_rubus_data.add_register_uint16(149, 1, &m_environment.hardware.hvcell.version[0][7]); + m_rubus_data.add_register_uint16(150, 1, &m_environment.hardware.hvcell.version[0][8]); + m_rubus_data.add_register_uint16(151, 1, &m_environment.hardware.hvcell.version[0][9]); + // + m_rubus_data.add_register_uint16(152, 1, &m_environment.hardware.hvcell.version[1][0]); + m_rubus_data.add_register_uint16(153, 1, &m_environment.hardware.hvcell.version[1][1]); + m_rubus_data.add_register_uint16(154, 1, &m_environment.hardware.hvcell.version[1][2]); + m_rubus_data.add_register_uint16(155, 1, &m_environment.hardware.hvcell.version[1][3]); + m_rubus_data.add_register_uint16(156, 1, &m_environment.hardware.hvcell.version[1][4]); + m_rubus_data.add_register_uint16(157, 1, &m_environment.hardware.hvcell.version[1][5]); + m_rubus_data.add_register_uint16(158, 1, &m_environment.hardware.hvcell.version[1][6]); + m_rubus_data.add_register_uint16(159, 1, &m_environment.hardware.hvcell.version[1][7]); + m_rubus_data.add_register_uint16(160, 1, &m_environment.hardware.hvcell.version[1][8]); + m_rubus_data.add_register_uint16(161, 1, &m_environment.hardware.hvcell.version[1][9]); + // + m_rubus_data.add_register_uint16(162, 1, &m_environment.hardware.hvcell.version[2][0]); + m_rubus_data.add_register_uint16(163, 1, &m_environment.hardware.hvcell.version[2][1]); + m_rubus_data.add_register_uint16(164, 1, &m_environment.hardware.hvcell.version[2][2]); + m_rubus_data.add_register_uint16(165, 1, &m_environment.hardware.hvcell.version[2][3]); + m_rubus_data.add_register_uint16(166, 1, &m_environment.hardware.hvcell.version[2][4]); + m_rubus_data.add_register_uint16(167, 1, &m_environment.hardware.hvcell.version[2][5]); + m_rubus_data.add_register_uint16(168, 1, &m_environment.hardware.hvcell.version[2][6]); + m_rubus_data.add_register_uint16(169, 1, &m_environment.hardware.hvcell.version[2][7]); + m_rubus_data.add_register_uint16(170, 1, &m_environment.hardware.hvcell.version[2][8]); + m_rubus_data.add_register_uint16(171, 1, &m_environment.hardware.hvcell.version[2][9]); + // + + + //System Orts + m_rubus_data.add_register_float(172, 1, &m_environment.main_abc_orts.phase_a.active); + m_rubus_data.add_register_float(173, 1, &m_environment.main_abc_orts.phase_a.reactive); + // + m_rubus_data.add_register_float(174, 1, &m_environment.main_abc_orts.phase_b.active); + m_rubus_data.add_register_float(175, 1, &m_environment.main_abc_orts.phase_b.reactive); + // + m_rubus_data.add_register_float(176, 1, &m_environment.main_abc_orts.phase_c.active); + m_rubus_data.add_register_float(177, 1, &m_environment.main_abc_orts.phase_c.reactive); + // + m_rubus_data.add_register_float(178, 1, &m_environment.main_ab_orts.active); + m_rubus_data.add_register_float(179, 1, &m_environment.main_ab_orts.reactive); + // + m_rubus_data.add_register_float(180, 1, &m_environment.harmonica_2.active); + m_rubus_data.add_register_float(181, 1, &m_environment.harmonica_2.reactive); + // + m_rubus_data.add_register_float(182, 1, &m_environment.harmonica_3.active); + m_rubus_data.add_register_float(183, 1, &m_environment.harmonica_3.reactive); + // + m_rubus_data.add_register_float(184, 1, &m_environment.harmonica_5.active); + m_rubus_data.add_register_float(185, 1, &m_environment.harmonica_5.reactive); + // + m_rubus_data.add_register_float(186, 1, &m_environment.harmonica_7.active); + m_rubus_data.add_register_float(187, 1, &m_environment.harmonica_7.reactive); + // + m_rubus_data.add_register_float(188, 1, &m_environment.harmonica_9.active); + m_rubus_data.add_register_float(189, 1, &m_environment.harmonica_9.reactive); + // + m_rubus_data.add_register_float(190, 1, &m_environment.harmonica_11.active); + m_rubus_data.add_register_float(191, 1, &m_environment.harmonica_11.reactive); + // + + //System State + m_rubus_data.add_register_uint16(192, 1, &m_environment.system_alarm.all); + m_rubus_data.add_register_uint16(193, 1, &m_environment.system_fault.all); + m_rubus_data.add_register_uint16(194, 1, &m_environment.system_reset.all); + m_rubus_data.add_register_uint16(195, 1, &m_environment.system_ready.all); + m_rubus_data.add_register_uint16(196, 1, &m_environment.short_circuit.all); + m_rubus_data.add_register_uint16(197, 1, &m_environment.enable_work.all); + m_rubus_data.add_register_uint16(198, 1, &m_environment.enable_work_reset.all); +// m_rubus_data.add_register_bool(199, 1, &m_environment.enable_auto_offset); + + + m_rubus_data.add_register_uint32(200, 1, &m_environment.input_discrete.all); + m_rubus_data.add_register_uint32(201, 1, &m_environment.digital_output.all); + //m_rubus_data.add_register_uint32(201, 1, &m_environment.digital_output_temp.all); + + + //Phase Alert monitor + m_rubus_data.add_register_uint16(202, 1, &m_environment.phase_alert_monitor_register.phase_a.fault.all); + m_rubus_data.add_register_uint16(203, 1, &m_environment.phase_alert_monitor_register.phase_a.warning.all); + m_rubus_data.add_register_uint16(204, 1, &m_environment.phase_alert_monitor_register.phase_b.fault.all); + m_rubus_data.add_register_uint16(205, 1, &m_environment.phase_alert_monitor_register.phase_b.warning.all); + m_rubus_data.add_register_uint16(206, 1, &m_environment.phase_alert_monitor_register.phase_c.fault.all); + m_rubus_data.add_register_uint16(207, 1, &m_environment.phase_alert_monitor_register.phase_c.warning.all); + //<> + + + + // Projections + m_rubus_data.add_register_float(208, 1, &m_environment.projection_voltage_input_a.active); + m_rubus_data.add_register_float(209, 1, &m_environment.projection_voltage_input_a.reactive); + // + m_rubus_data.add_register_float(210, 1, &m_environment.projection_voltage_input_b.active); + m_rubus_data.add_register_float(211, 1, &m_environment.projection_voltage_input_b.reactive); + // + m_rubus_data.add_register_float(212, 1, &m_environment.projection_voltage_input_c.active); + m_rubus_data.add_register_float(213, 1, &m_environment.projection_voltage_input_c.reactive); + // + // + m_rubus_data.add_register_float(214, 1, &m_environment.projection_voltage_load_a.active); + m_rubus_data.add_register_float(215, 1, &m_environment.projection_voltage_load_a.reactive); + // + m_rubus_data.add_register_float(216, 1, &m_environment.projection_voltage_load_b.active); + m_rubus_data.add_register_float(217, 1, &m_environment.projection_voltage_load_b.reactive); + // + m_rubus_data.add_register_float(218, 1, &m_environment.projection_voltage_load_c.active); + m_rubus_data.add_register_float(219, 1, &m_environment.projection_voltage_load_c.reactive); + // + // + m_rubus_data.add_register_float(220, 1, &m_environment.projection_current_load_a.active); + m_rubus_data.add_register_float(221, 1, &m_environment.projection_current_load_a.reactive); + // + m_rubus_data.add_register_float(222, 1, &m_environment.projection_current_load_b.active); + m_rubus_data.add_register_float(223, 1, &m_environment.projection_current_load_b.reactive); + // + m_rubus_data.add_register_float(224, 1, &m_environment.projection_current_load_c.active); + m_rubus_data.add_register_float(225, 1, &m_environment.projection_current_load_c.reactive); + // + m_rubus_data.add_register_float(226, 1, &m_environment.projection_current_bypass_a.active); + m_rubus_data.add_register_float(227, 1, &m_environment.projection_current_bypass_a.reactive); + // + m_rubus_data.add_register_float(228, 1, &m_environment.projection_current_bypass_b.active); + m_rubus_data.add_register_float(229, 1, &m_environment.projection_current_bypass_b.reactive); + // + m_rubus_data.add_register_float(230, 1, &m_environment.projection_current_bypass_c.active); + m_rubus_data.add_register_float(231, 1, &m_environment.projection_current_bypass_c.reactive); + //<> + + + //Symmetrical Components Input Voltage + m_rubus_data.add_register_float(232, 1, &m_environment.symmetrical_components_voltage_input.direct.a.active); + m_rubus_data.add_register_float(233, 1, &m_environment.symmetrical_components_voltage_input.direct.a.reactive); + m_rubus_data.add_register_float(234, 1, &m_environment.symmetrical_components_voltage_input.direct.b.active); + m_rubus_data.add_register_float(235, 1, &m_environment.symmetrical_components_voltage_input.direct.b.reactive); + m_rubus_data.add_register_float(236, 1, &m_environment.symmetrical_components_voltage_input.direct.c.active); + m_rubus_data.add_register_float(237, 1, &m_environment.symmetrical_components_voltage_input.direct.c.reactive); + // + m_rubus_data.add_register_float(238, 1, &m_environment.symmetrical_components_voltage_input.inverse.a.active); + m_rubus_data.add_register_float(239, 1, &m_environment.symmetrical_components_voltage_input.inverse.a.reactive); + m_rubus_data.add_register_float(240, 1, &m_environment.symmetrical_components_voltage_input.inverse.b.active); + m_rubus_data.add_register_float(241, 1, &m_environment.symmetrical_components_voltage_input.inverse.b.reactive); + m_rubus_data.add_register_float(242, 1, &m_environment.symmetrical_components_voltage_input.inverse.c.active); + m_rubus_data.add_register_float(243, 1, &m_environment.symmetrical_components_voltage_input.inverse.c.reactive); + // + m_rubus_data.add_register_float(244, 1, &m_environment.symmetrical_components_voltage_input.zero.a.active); + m_rubus_data.add_register_float(245, 1, &m_environment.symmetrical_components_voltage_input.zero.a.reactive); + m_rubus_data.add_register_float(246, 1, &m_environment.symmetrical_components_voltage_input.zero.b.active); + m_rubus_data.add_register_float(247, 1, &m_environment.symmetrical_components_voltage_input.zero.b.reactive); + m_rubus_data.add_register_float(248, 1, &m_environment.symmetrical_components_voltage_input.zero.c.active); + m_rubus_data.add_register_float(249, 1, &m_environment.symmetrical_components_voltage_input.zero.c.reactive); + //<> + + + //Symmetrical Components Load Voltage + m_rubus_data.add_register_float(250, 1, &m_environment.symmetrical_components_voltage_load.direct.a.active); + m_rubus_data.add_register_float(251, 1, &m_environment.symmetrical_components_voltage_load.direct.a.reactive); + m_rubus_data.add_register_float(252, 1, &m_environment.symmetrical_components_voltage_load.direct.b.active); + m_rubus_data.add_register_float(253, 1, &m_environment.symmetrical_components_voltage_load.direct.b.reactive); + m_rubus_data.add_register_float(254, 1, &m_environment.symmetrical_components_voltage_load.direct.c.active); + m_rubus_data.add_register_float(255, 1, &m_environment.symmetrical_components_voltage_load.direct.c.reactive); + // + m_rubus_data.add_register_float(256, 1, &m_environment.symmetrical_components_voltage_load.inverse.a.active); + m_rubus_data.add_register_float(257, 1, &m_environment.symmetrical_components_voltage_load.inverse.a.reactive); + m_rubus_data.add_register_float(258, 1, &m_environment.symmetrical_components_voltage_load.inverse.b.active); + m_rubus_data.add_register_float(259, 1, &m_environment.symmetrical_components_voltage_load.inverse.b.reactive); + m_rubus_data.add_register_float(260, 1, &m_environment.symmetrical_components_voltage_load.inverse.c.active); + m_rubus_data.add_register_float(261, 1, &m_environment.symmetrical_components_voltage_load.inverse.c.reactive); + // + m_rubus_data.add_register_float(262, 1, &m_environment.symmetrical_components_voltage_load.zero.a.active); + m_rubus_data.add_register_float(263, 1, &m_environment.symmetrical_components_voltage_load.zero.a.reactive); + m_rubus_data.add_register_float(264, 1, &m_environment.symmetrical_components_voltage_load.zero.b.active); + m_rubus_data.add_register_float(265, 1, &m_environment.symmetrical_components_voltage_load.zero.b.reactive); + m_rubus_data.add_register_float(266, 1, &m_environment.symmetrical_components_voltage_load.zero.c.active); + m_rubus_data.add_register_float(267, 1, &m_environment.symmetrical_components_voltage_load.zero.c.reactive); + //<> + + + //Symmetrical Components Load Current + m_rubus_data.add_register_float(268, 1, &m_environment.symmetrical_components_current_load.direct.a.active); + m_rubus_data.add_register_float(269, 1, &m_environment.symmetrical_components_current_load.direct.a.reactive); + m_rubus_data.add_register_float(270, 1, &m_environment.symmetrical_components_current_load.direct.b.active); + m_rubus_data.add_register_float(271, 1, &m_environment.symmetrical_components_current_load.direct.b.reactive); + m_rubus_data.add_register_float(272, 1, &m_environment.symmetrical_components_current_load.direct.c.active); + m_rubus_data.add_register_float(273, 1, &m_environment.symmetrical_components_current_load.direct.c.reactive); + // + m_rubus_data.add_register_float(274, 1, &m_environment.symmetrical_components_current_load.inverse.a.active); + m_rubus_data.add_register_float(275, 1, &m_environment.symmetrical_components_current_load.inverse.a.reactive); + m_rubus_data.add_register_float(276, 1, &m_environment.symmetrical_components_current_load.inverse.b.active); + m_rubus_data.add_register_float(277, 1, &m_environment.symmetrical_components_current_load.inverse.b.reactive); + m_rubus_data.add_register_float(278, 1, &m_environment.symmetrical_components_current_load.inverse.c.active); + m_rubus_data.add_register_float(279, 1, &m_environment.symmetrical_components_current_load.inverse.c.reactive); + // + m_rubus_data.add_register_float(280, 1, &m_environment.symmetrical_components_current_load.zero.a.active); + m_rubus_data.add_register_float(281, 1, &m_environment.symmetrical_components_current_load.zero.a.reactive); + m_rubus_data.add_register_float(282, 1, &m_environment.symmetrical_components_current_load.zero.b.active); + m_rubus_data.add_register_float(283, 1, &m_environment.symmetrical_components_current_load.zero.b.reactive); + m_rubus_data.add_register_float(284, 1, &m_environment.symmetrical_components_current_load.zero.c.active); + m_rubus_data.add_register_float(285, 1, &m_environment.symmetrical_components_current_load.zero.c.reactive); + //<> + + + //Symmetrical Components Bypass Current + m_rubus_data.add_register_float(286, 1, &m_environment.symmetrical_components_current_bypass.direct.a.active); + m_rubus_data.add_register_float(287, 1, &m_environment.symmetrical_components_current_bypass.direct.a.reactive); + m_rubus_data.add_register_float(288, 1, &m_environment.symmetrical_components_current_bypass.direct.b.active); + m_rubus_data.add_register_float(289, 1, &m_environment.symmetrical_components_current_bypass.direct.b.reactive); + m_rubus_data.add_register_float(290, 1, &m_environment.symmetrical_components_current_bypass.direct.c.active); + m_rubus_data.add_register_float(291, 1, &m_environment.symmetrical_components_current_bypass.direct.c.reactive); + // + m_rubus_data.add_register_float(292, 1, &m_environment.symmetrical_components_current_bypass.inverse.a.active); + m_rubus_data.add_register_float(293, 1, &m_environment.symmetrical_components_current_bypass.inverse.a.reactive); + m_rubus_data.add_register_float(294, 1, &m_environment.symmetrical_components_current_bypass.inverse.b.active); + m_rubus_data.add_register_float(295, 1, &m_environment.symmetrical_components_current_bypass.inverse.b.reactive); + m_rubus_data.add_register_float(296, 1, &m_environment.symmetrical_components_current_bypass.inverse.c.active); + m_rubus_data.add_register_float(297, 1, &m_environment.symmetrical_components_current_bypass.inverse.c.reactive); + // + m_rubus_data.add_register_float(298, 1, &m_environment.symmetrical_components_current_bypass.zero.a.active); + m_rubus_data.add_register_float(299, 1, &m_environment.symmetrical_components_current_bypass.zero.a.reactive); + m_rubus_data.add_register_float(300, 1, &m_environment.symmetrical_components_current_bypass.zero.b.active); + m_rubus_data.add_register_float(301, 1, &m_environment.symmetrical_components_current_bypass.zero.b.reactive); + m_rubus_data.add_register_float(302, 1, &m_environment.symmetrical_components_current_bypass.zero.c.active); + m_rubus_data.add_register_float(303, 1, &m_environment.symmetrical_components_current_bypass.zero.c.reactive); + //<> + + + + // + // External Command + // + m_rubus_data.add_register_uint16(304, 0, &m_environment.external_command_word.all); + //<> + + + + + //********************************************************* + // + // Configuration Parameters + // + //********************************************************* + // + // + // + // Referances + // + m_rubus_data.add_register_float(305, 0, &m_system_configuration.reference_current_limit_rms); + m_rubus_data.add_register_float(306, 0, &m_system_configuration.reference_current_pfc_rms); + m_rubus_data.add_register_float(307, 0, &m_system_configuration.reference_voltage_rms); + m_rubus_data.add_register_float(308, 0, &m_system_configuration.reference_voltage_high_limit_rms); + //<> + + + // + // Algoritm Control + // + m_rubus_data.add_register_uint16(309, 0, &m_system_configuration.algorithm_control.all); + //<> + + + // + // Flash Operation + // + m_rubus_data.add_register_uint16(310, 0, &m_environment.fram_operation.all); + //<> + + + + // + // System Alarm + // + // exceed voltage level 1 + m_rubus_data.add_register_float(311, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_1.level); + m_rubus_data.add_register_float(312, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_1.period); + // + // exceed voltage level 2 + m_rubus_data.add_register_float(313, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_2.level); + m_rubus_data.add_register_float(314, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_2.period); + // + // exceed voltage level 3 + m_rubus_data.add_register_float(315, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_3.level); + m_rubus_data.add_register_float(316, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_3.period); + // + // exceed voltage level 4 + m_rubus_data.add_register_float(317, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_4.level); + m_rubus_data.add_register_float(318, 0, &m_system_configuration.phase_alert_monitor.voltage_exceed_level_4.period); + // + // decrease voltage level 1 + m_rubus_data.add_register_float(319, 0, &m_system_configuration.phase_alert_monitor.voltage_decrease_level_1.level); + m_rubus_data.add_register_float(320, 0, &m_system_configuration.phase_alert_monitor.voltage_decrease_level_1.period); + // + // decrease voltage level 2 + m_rubus_data.add_register_float(321, 0, &m_system_configuration.phase_alert_monitor.voltage_decrease_level_2.level); + m_rubus_data.add_register_float(322, 0, &m_system_configuration.phase_alert_monitor.voltage_decrease_level_2.period); + // + // decrease voltage level 3 + m_rubus_data.add_register_float(323, 0, &m_system_configuration.phase_alert_monitor.voltage_decrease_level_3.level); + m_rubus_data.add_register_float(324, 0, &m_system_configuration.phase_alert_monitor.voltage_decrease_level_3.period); + // + // current overload level 1 120% 60s + m_rubus_data.add_register_float(325, 0, &m_system_configuration.phase_alert_monitor.current_overload_level_1.level); + m_rubus_data.add_register_float(326, 0, &m_system_configuration.phase_alert_monitor.current_overload_level_1.period); + // + // current overload level 2 130% 10s + m_rubus_data.add_register_float(327, 0, &m_system_configuration.phase_alert_monitor.current_overload_level_2.level); + m_rubus_data.add_register_float(328, 0, &m_system_configuration.phase_alert_monitor.current_overload_level_2.period); + // + // current overload level 3 150% 1ms + m_rubus_data.add_register_float(329, 0, &m_system_configuration.phase_alert_monitor.current_overload_level_3.level); + m_rubus_data.add_register_float(330, 0, &m_system_configuration.phase_alert_monitor.current_overload_level_3.period); + // + // current invertor overload level 1 110% 60s + m_rubus_data.add_register_float(331, 0, &m_system_configuration.phase_alert_monitor.current_invertor_overload_level_1.level); + m_rubus_data.add_register_float(332, 0, &m_system_configuration.phase_alert_monitor.current_invertor_overload_level_1.period); + // + // current invertor overload level 2 130% 10s + m_rubus_data.add_register_float(333, 0, &m_system_configuration.phase_alert_monitor.current_invertor_overload_level_2.level); + m_rubus_data.add_register_float(334, 0, &m_system_configuration.phase_alert_monitor.current_invertor_overload_level_2.period); + // + // current invertor overload level 3 150% 1ms + m_rubus_data.add_register_float(335, 0, &m_system_configuration.phase_alert_monitor.current_invertor_overload_level_3.level); + m_rubus_data.add_register_float(336, 0, &m_system_configuration.phase_alert_monitor.current_invertor_overload_level_3.period); + // + // current input overload level 1 110% 60s + m_rubus_data.add_register_float(337, 0, &m_system_configuration.phase_alert_monitor.current_input_overload_level_1.level); + m_rubus_data.add_register_float(338, 0, &m_system_configuration.phase_alert_monitor.current_input_overload_level_1.period); + // + // current input overload level 2 130% 10s + m_rubus_data.add_register_float(339, 0, &m_system_configuration.phase_alert_monitor.current_input_overload_level_2.level); + m_rubus_data.add_register_float(340, 0, &m_system_configuration.phase_alert_monitor.current_input_overload_level_2.period); + // + // current input overload level 3 150% 1ms + m_rubus_data.add_register_float(341, 0, &m_system_configuration.phase_alert_monitor.current_input_overload_level_3.level); + m_rubus_data.add_register_float(342, 0, &m_system_configuration.phase_alert_monitor.current_input_overload_level_3.period); + //<> + + + // + // DIGITAL INPUTS + // + m_rubus_data.add_register_float(343, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(338, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(339, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(340, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(341, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(342, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(343, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(344, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(345, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(346, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(347, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(348, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(349, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(350, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(351, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(352, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(353, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(354, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(355, 0, &m_system_configuration.digital_input_config.period); +// m_rubus_data.add_register_float(356, 0, &m_system_configuration.digital_input_config.period); + //<> + + + + // + // Voltage PLL-ABC Parameters + // + m_rubus_data.add_register_float(357, 0, &m_system_configuration.pll_abc_input_voltage.frequency_nominal); + m_rubus_data.add_register_float(358, 0, &m_system_configuration.pll_abc_input_voltage.filter.time); + m_rubus_data.add_register_float(359, 0, &m_system_configuration.pll_abc_input_voltage.controller.gain); + m_rubus_data.add_register_float(360, 0, &m_system_configuration.pll_abc_input_voltage.controller.time); + m_rubus_data.add_register_float(361, 0, &m_system_configuration.pll_abc_input_voltage.controller.low_saturation); + m_rubus_data.add_register_float(362, 0, &m_system_configuration.pll_abc_input_voltage.controller.high_saturation); + //<> + + + + // + // Signal Decompose + // + m_rubus_data.add_register_float(363, 0, &m_system_configuration.signal_decompose.projection_filter.time); + m_rubus_data.add_register_float(364, 0, &m_system_configuration.signal_decompose.projection_filter.a3); + m_rubus_data.add_register_float(365, 0, &m_system_configuration.signal_decompose.projection_filter.a2); + m_rubus_data.add_register_float(366, 0, &m_system_configuration.signal_decompose.projection_filter.a1); + //<> + + + + // + // Amplitude Filter Parameters + // + m_rubus_data.add_register_float(367, 0, &m_system_configuration.ampl_filter_current.time); + m_rubus_data.add_register_float(368, 0, &m_system_configuration.ampl_filter_current.a3); + m_rubus_data.add_register_float(369, 0, &m_system_configuration.ampl_filter_current.a2); + m_rubus_data.add_register_float(370, 0, &m_system_configuration.ampl_filter_current.a1); + //<> + + + // + // RMS Filter Parameters + // + m_rubus_data.add_register_float(371, 0, &m_system_configuration.rms_filter_analog_signal.time); + m_rubus_data.add_register_float(372, 0, &m_system_configuration.rms_filter_analog_signal.a3); + m_rubus_data.add_register_float(373, 0, &m_system_configuration.rms_filter_analog_signal.a2); + m_rubus_data.add_register_float(374, 0, &m_system_configuration.rms_filter_analog_signal.a1); + //<> + + + // + // Regulators + // +#if TYPECONTROL == VECTORCONTROL + // + m_rubus_data.add_register_float(375, 0, &m_system_configuration.regulator_voltage_load_dq.gain); + m_rubus_data.add_register_float(376, 0, &m_system_configuration.regulator_voltage_load_dq.time); + m_rubus_data.add_register_float(377, 0, &m_system_configuration.regulator_voltage_load_dq.high_saturation); + m_rubus_data.add_register_float(378, 0, &m_system_configuration.regulator_voltage_load_dq.low_saturation); + // + //m_rubus_data.add_register_float(379, 0, &m_system_configuration.regulator_current_limit.gain); + m_rubus_data.add_register_float(380, 0, &m_system_configuration.regulator_current_limit.time); + m_rubus_data.add_register_float(381, 1, &m_system_configuration.regulator_current_limit.high_saturation); + m_rubus_data.add_register_float(382, 1, &m_system_configuration.regulator_current_limit.low_saturation); + // + m_rubus_data.add_register_float(383, 0, &m_system_configuration.regulator_current_pfc.gain); + m_rubus_data.add_register_float(384, 0, &m_system_configuration.regulator_current_pfc.time); + m_rubus_data.add_register_float(385, 0, &m_system_configuration.regulator_current_pfc.high_saturation); + m_rubus_data.add_register_float(386, 0, &m_system_configuration.regulator_current_pfc.low_saturation); + // + //m_rubus_data.add_register_float(387, 0, &m_system_configuration); + m_rubus_data.add_register_float(388, 0, &m_system_configuration.integrator_voltage_dq.time); + m_rubus_data.add_register_float(389, 0, &m_system_configuration.integrator_voltage_dq.high_saturation); + m_rubus_data.add_register_float(390, 0, &m_system_configuration.integrator_voltage_dq.low_saturation); + // +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_P + m_rubus_data.add_register_float(391, 0, &m_system_configuration.regulator_current_load_dq.gain); + //m_rubus_data.add_register_float(392, 0, &m_system_configuration.regulator_current_load_dq.time); + m_rubus_data.add_register_float(393, 0, &m_system_configuration.regulator_current_load_dq.high_saturation); + m_rubus_data.add_register_float(394, 0, &m_system_configuration.regulator_current_load_dq.low_saturation); +#endif +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_PI + m_rubus_data.add_register_float(391, 0, &m_system_configuration.regulator_current_load_dq.gain); + m_rubus_data.add_register_float(392, 0, &m_system_configuration.regulator_current_load_dq.time); + m_rubus_data.add_register_float(393, 0, &m_system_configuration.regulator_current_load_dq.high_saturation); + m_rubus_data.add_register_float(394, 0, &m_system_configuration.regulator_current_load_dq.low_saturation); +#endif + // + //m_rubus_data.add_register_float(395, 0, &m_system_configuration); + m_rubus_data.add_register_float(396, 0, &m_system_configuration.referencer_current_bypass_dq.time); + m_rubus_data.add_register_float(397, 0, &m_system_configuration.referencer_current_bypass_dq.high_saturation); + m_rubus_data.add_register_float(398, 0, &m_system_configuration.referencer_current_bypass_dq.low_saturation); + // +#endif + +#if TYPECONTROL == SCALARCONTROL + // + m_rubus_data.add_register_float(375, 0, &m_system_configuration.regulator_voltage_load_active_reactive.gain); + m_rubus_data.add_register_float(376, 0, &m_system_configuration.regulator_voltage_load_active_reactive.time); + m_rubus_data.add_register_float(377, 0, &m_system_configuration.regulator_voltage_load_active_reactive.high_saturation); + m_rubus_data.add_register_float(378, 0, &m_system_configuration.regulator_voltage_load_active_reactive.low_saturation); + // + m_rubus_data.add_register_float(379, 0, &m_system_configuration.regulator_current_limit.gain); + m_rubus_data.add_register_float(380, 0, &m_system_configuration.regulator_current_limit.time); + m_rubus_data.add_register_float(381, 0, &m_system_configuration.regulator_current_limit.high_saturation); + m_rubus_data.add_register_float(382, 0, &m_system_configuration.regulator_current_limit.low_saturation); + // + m_rubus_data.add_register_float(383, 0, &m_system_configuration.regulator_current_pfc.gain); + m_rubus_data.add_register_float(384, 0, &m_system_configuration.regulator_current_pfc.time); + m_rubus_data.add_register_float(385, 0, &m_system_configuration.regulator_current_pfc.high_saturation); + m_rubus_data.add_register_float(386, 0, &m_system_configuration.regulator_current_pfc.low_saturation); + // + m_rubus_data.add_register_float(387, 0, &m_system_configuration.current_regulator_active.gain); + m_rubus_data.add_register_float(388, 0, &m_system_configuration.current_regulator_active.time); + m_rubus_data.add_register_float(389, 0, &m_system_configuration.current_regulator_active.high_saturation); + m_rubus_data.add_register_float(390, 0, &m_system_configuration.current_regulator_active.low_saturation); + // + m_rubus_data.add_register_float(391, 0, &m_system_configuration.current_regulator_reactive.gain); + m_rubus_data.add_register_float(392, 0, &m_system_configuration.current_regulator_reactive.time); + m_rubus_data.add_register_float(393, 0, &m_system_configuration.current_regulator_reactive.high_saturation); + m_rubus_data.add_register_float(394, 0, &m_system_configuration.current_regulator_reactive.low_saturation); + // + m_rubus_data.add_register_float(395, 0, &m_system_configuration.current_referencer.gain); + m_rubus_data.add_register_float(396, 0, &m_system_configuration.current_referencer.time); + m_rubus_data.add_register_float(397, 0, &m_system_configuration.current_referencer.high_saturation); + m_rubus_data.add_register_float(398, 0, &m_system_configuration.current_referencer.low_saturation); + // +#endif + //<> + + + // + // MODBUS Break Counter + // + m_rubus_data.add_register_uint16(399, 0, &m_modbus_break_counter); + //<> + + // + // ID SOFTWARE + // + m_rubus_data.add_register_uint16(400, 0, &m_environment.id_software.class_id); + m_rubus_data.add_register_uint16(401, 0, &m_environment.id_software.part_id); + m_rubus_data.add_register_uint16(402, 0, &m_environment.id_software.software_version); + m_rubus_data.add_register_uint16(403, 0, &m_environment.id_software.protocol_version); + //<> + + + // + // Equipment Faults + // + m_rubus_data.add_register_uint16(416, 1, &m_environment.system_faults_register.equipment.all); + //<> + + // + // Grid Frequency form PLL + // + m_rubus_data.add_register_float(417, 0, &m_environment.grid_frequency); + //<> + + + // + // +}// + +// +// +} /* namespace SYSCTRL */ + diff --git a/SYSCTRL/SystemControlMethods.cpp b/SYSCTRL/SystemControlMethods.cpp new file mode 100644 index 0000000..1e23876 --- /dev/null +++ b/SYSCTRL/SystemControlMethods.cpp @@ -0,0 +1,492 @@ +/* + * SystemControlMethods.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SystemControl.h" + +namespace SYSCTRL +{ + + + +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::process_analog_input(AnalogInput& analog_input) +{ + + m_environment.analog_input = analog_input; + + + + + m_environment.adc_voltage_grid_a = (float)m_environment.analog_input.analog_input_channel_1004 - m_environment.offset_voltage_grid_static_a; + m_environment.adc_voltage_grid_b = (float)m_environment.analog_input.analog_input_channel_1002 - m_environment.offset_voltage_grid_static_b; + m_environment.adc_voltage_grid_c = (float)m_environment.analog_input.analog_input_channel_1003 - m_environment.offset_voltage_grid_static_c; + // + m_environment.adc_current_input_a = (float)m_environment.analog_input.analog_input_channel_1001 - m_environment.offset_current_input_static_a; + m_environment.adc_current_input_b = (float)m_environment.analog_input.analog_input_channel_1005 - m_environment.offset_current_input_static_b; + m_environment.adc_current_input_c = (float)m_environment.analog_input.analog_input_channel_1007 - m_environment.offset_current_input_static_c; + // + m_environment.adc_current_cell_a = (float)m_environment.analog_input.analog_input_channel_1010 - m_environment.offset_current_cell_static_a; + m_environment.adc_current_cell_b = (float)m_environment.analog_input.analog_input_channel_1011 - m_environment.offset_current_cell_static_b; + m_environment.adc_current_cell_c = (float)m_environment.analog_input.analog_input_channel_1012 - m_environment.offset_current_cell_static_c; + // + m_environment.adc_voltage_load_a = (float)m_environment.analog_input.analog_input_channel_1016 - m_environment.offset_voltage_load_static_a; + m_environment.adc_voltage_load_b = (float)m_environment.analog_input.analog_input_channel_1017 - m_environment.offset_voltage_load_static_b; + m_environment.adc_voltage_load_c = (float)m_environment.analog_input.analog_input_channel_1018 - m_environment.offset_voltage_load_static_c; + // + m_environment.adc_current_load_a = (float)m_environment.analog_input.analog_input_channel_1013 - m_environment.offset_current_load_static_a; + m_environment.adc_current_load_b = (float)m_environment.analog_input.analog_input_channel_1014 - m_environment.offset_current_load_static_b; + m_environment.adc_current_load_c = (float)m_environment.analog_input.analog_input_channel_1015 - m_environment.offset_current_load_static_c; + // + m_environment.adc_current_bypass_a = (float)m_environment.analog_input.analog_input_channel_1006 - m_environment.offset_current_bypass_static_a; + m_environment.adc_current_bypass_b = (float)m_environment.analog_input.analog_input_channel_1008 - m_environment.offset_current_bypass_static_b; + m_environment.adc_current_bypass_c = (float)m_environment.analog_input.analog_input_channel_1009 - m_environment.offset_current_bypass_static_c; + //<> + + + + + m_environment.voltage_grid_a = m_environment.scale_voltage_grid_a * (m_environment.adc_voltage_grid_a - m_environment.offset_voltage_grid_a); + m_environment.voltage_grid_b = m_environment.scale_voltage_grid_b * (m_environment.adc_voltage_grid_b - m_environment.offset_voltage_grid_b); + m_environment.voltage_grid_c = m_environment.scale_voltage_grid_c * (m_environment.adc_voltage_grid_c - m_environment.offset_voltage_grid_c); + // + m_environment.current_input_a = m_environment.scale_current_input_a * (m_environment.adc_current_input_a - m_environment.offset_current_input_a); + m_environment.current_input_b = m_environment.scale_current_input_b * (m_environment.adc_current_input_b - m_environment.offset_current_input_b); + m_environment.current_input_c = m_environment.scale_current_input_c * (m_environment.adc_current_input_c - m_environment.offset_current_input_c); + // + m_environment.current_bypass_a = m_environment.scale_current_bypass_a * (m_environment.adc_current_bypass_a - m_environment.offset_current_bypass_a); + m_environment.current_bypass_b = m_environment.scale_current_bypass_b * (m_environment.adc_current_bypass_b - m_environment.offset_current_bypass_b); + m_environment.current_bypass_c = m_environment.scale_current_bypass_c * (m_environment.adc_current_bypass_c - m_environment.offset_current_bypass_c); + // + m_environment.current_cell_a = m_environment.scale_current_cell_a * (m_environment.adc_current_cell_a - m_environment.offset_current_cell_a); + m_environment.current_cell_b = m_environment.scale_current_cell_b * (m_environment.adc_current_cell_b - m_environment.offset_current_cell_b); + m_environment.current_cell_c = m_environment.scale_current_cell_c * (m_environment.adc_current_cell_c - m_environment.offset_current_cell_c); + // + m_environment.voltage_load_a = m_environment.scale_voltage_load_a * (m_environment.adc_voltage_load_a - m_environment.offset_voltage_load_a); + m_environment.voltage_load_b = m_environment.scale_voltage_load_b * (m_environment.adc_voltage_load_b - m_environment.offset_voltage_load_b); + m_environment.voltage_load_c = m_environment.scale_voltage_load_c * (m_environment.adc_voltage_load_c - m_environment.offset_voltage_load_c); + // + m_environment.current_load_a = m_environment.scale_current_load_a * (m_environment.adc_current_load_a - m_environment.offset_current_load_a); + m_environment.current_load_b = m_environment.scale_current_load_b * (m_environment.adc_current_load_b - m_environment.offset_current_load_b); + m_environment.current_load_c = m_environment.scale_current_load_c * (m_environment.adc_current_load_c - m_environment.offset_current_load_c); + //<> + + // +// m_environment.m_rms_voltage_input_max = fmaxf(m_environment.m_rms_voltage_input_a, m_environment.m_rms_voltage_input_b); +// m_environment.m_rms_voltage_input_max = fmaxf(m_environment.m_rms_voltage_input_max, m_environment.m_rms_voltage_input_c); +// m_environment.m_rms_voltage_input_min = fminf(m_environment.m_rms_voltage_input_a, m_environment.m_rms_voltage_input_b); +// m_environment.m_rms_voltage_input_min = fminf(m_environment.m_rms_voltage_input_min, m_environment.m_rms_voltage_input_c); +// m_environment.m_rms_voltage_input_avr = (0.333333)*(m_environment.m_rms_voltage_input_a + m_environment.m_rms_voltage_input_b + m_environment.m_rms_voltage_input_c); + + + // +}//process_analog_input() + + +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::process_digital_input(DigitalInput& digital_input) +{ + + //m_environment.input_discrete.digital.all = digital_input.all; + m_environment.digital_input.all = digital_input.all; + + // FOR DEBUG ONLY!!!!!!! + //m_environment.digital_input.bits.DI_3016 = m_km1_external_command_trigger.getOUT(); + + // FOR DEBUG ONLY!!!!!!! + //m_environment.digital_input.bits.DI_3017 = m_km3_external_command_trigger.getOUT(); + + // FOR DEBUG ONLY!!!!!!! + //m_environment.digital_input.bits.DI_3005 = m_q1_external_command_trigger.getOUT(); + + //m_environment.digital_input.bits.DI_3005 = m_environment.digital_input_debug.bits.DI_3005; + //m_environment.input_discrete.signal.auxiliary_q1 = m_environment.digital_input_debug.bits.DI_3005; + // FOR DEBUG ONLY!!!!!!! + //m_environment.input_discrete.digital.all = m_environment.digital_input_debug.all; + //m_environment.digital_input.all = m_environment.digital_input_debug.all; + + + // + // DIGITAL INPUTS + // + m_environment.remote_start.execute(!digital_input.bits.DI_3001); //3001 + m_environment.remote_stop.execute(!digital_input.bits.DI_3002); //3002 + m_environment.remote_reset.execute(!digital_input.bits.DI_3003); //3003 + m_environment.remote_e_stop.execute(!digital_input.bits.DI_3004); //3004 + m_environment.auxiliary_q1.execute(!digital_input.bits.DI_3005); //3005 +// m_environment.auxiliary_q1.execute(m_q1_control_trigger.signal.quit); //3005 +// m_environment.bypass_ready.execute(!digital_input.bits.DI_3006); //3006 + m_environment.transformer_inv_over_temperature_alarm.execute(!digital_input.bits.DI_3007); //3007 + m_environment.local_e_stop.execute(!digital_input.bits.DI_3008); //3008 + m_environment.cabinet_door_interlocked.execute(digital_input.bits.DI_3009); //3009 + m_environment.arc_and_fire.execute(!digital_input.bits.DI_3010);//3010 +// m_environment.hw_dvr_ready.execute(!digital_input.bits.DI_3011); //3011 +// m_environment.auxiliary_km2.execute(!digital_input.bits.DI_3012); //3012 + m_environment.auxiliary_km2.execute(m_km2_control_trigger.signal.quit); //3012 +// m_environment.auxiliary_km11.execute(!digital_input.bits.DI_3013); //3013 + m_environment.transformer_t_over_temperature_fault.execute(!digital_input.bits.DI_3014);//3014 + m_environment.control_power_supply_status.execute(!digital_input.bits.DI_3015);//3015 +// m_environment.auxiliary_km1.execute(!digital_input.bits.DI_3016); //3016 + m_environment.auxiliary_km1.execute(m_km1_control_trigger.signal.quit); //3016 +// m_environment.auxiliary_km3.execute(!digital_input.bits.DI_3017); //3017 + m_environment.auxiliary_km3.execute(m_km3_control_trigger.signal.quit); //3017 + m_environment.transformer_inv_over_temperature_fault.execute(!digital_input.bits.DI_3018); //3018 + m_environment.fan_fault.execute(!digital_input.bits.DI_3019); //3019 + m_environment.local_remote.execute(digital_input.bits.DI_3020); //3020 1-Local, 0-Remote + // + + // DIGITAL INPUTS cleaned from noise + m_environment.input_discrete.field.DI_3001 = m_environment.remote_start.state.signal.is_on; //3001 + m_environment.input_discrete.field.DI_3002 = m_environment.remote_stop.state.signal.is_on; //3002 + m_environment.input_discrete.field.DI_3003 = m_environment.remote_reset.state.signal.is_on; //3003 + m_environment.input_discrete.field.DI_3004 = m_environment.remote_e_stop.state.signal.is_on; //3004 + m_environment.input_discrete.field.DI_3005 = m_environment.auxiliary_q1.state.signal.is_on; //3005 + m_environment.input_discrete.field.DI_3006 = m_environment.bypass_ready.state.signal.is_on; //3006 + m_environment.input_discrete.field.DI_3007 = m_environment.transformer_inv_over_temperature_alarm.state.signal.is_on; //3007 + m_environment.input_discrete.field.DI_3008 = m_environment.local_e_stop.state.signal.is_on; //3008 + m_environment.input_discrete.field.DI_3009 = m_environment.cabinet_door_interlocked.state.signal.is_on; //3009 + m_environment.input_discrete.field.DI_3010 = m_environment.arc_and_fire.state.signal.is_on;//3010 + m_environment.input_discrete.field.DI_3011 = m_environment.hw_dvr_ready.state.signal.is_on; //3011 + m_environment.input_discrete.field.DI_3012 = m_environment.auxiliary_km2.state.signal.is_on; //3012 + m_environment.input_discrete.field.DI_3013 = m_environment.auxiliary_km11.state.signal.is_on; //3013 + m_environment.input_discrete.field.DI_3014 = m_environment.transformer_t_over_temperature_fault.state.signal.is_on;//3014 + m_environment.input_discrete.field.DI_3015 = m_environment.control_power_supply_status.state.signal.is_on;//3015 + m_environment.input_discrete.field.DI_3016 = m_environment.auxiliary_km1.state.signal.is_on; //3016 + m_environment.input_discrete.field.DI_3017 = m_environment.auxiliary_km3.state.signal.is_on; //3017 + m_environment.input_discrete.field.DI_3018 = m_environment.transformer_inv_over_temperature_fault.state.signal.is_on; //3018 + m_environment.input_discrete.field.DI_3019 = m_environment.fan_fault.state.signal.is_on; //3019 + m_environment.input_discrete.field.DI_3020 = m_environment.local_remote.state.signal.is_on; //3020 1-Local, 0-Remote + //<> + + // FOR DEBUG ONLY!!!!!!! + //m_environment.input_discrete.all = m_environment.digital_input_debug.all; + + + // + // Contactor Fault Control + // + m_q1_control_fault.execute(m_q1_control_trigger.signal.quit & m_environment.input_discrete.signal.hw_dvr_ready, + m_environment.input_discrete.signal.auxiliary_q1 & m_environment.input_discrete.signal.hw_dvr_ready); + m_km1_control_fault.execute(m_km1_control_trigger.signal.quit & m_environment.input_discrete.signal.hw_dvr_ready, + m_environment.auxiliary_km1.state.signal.is_on & m_environment.input_discrete.signal.hw_dvr_ready); + m_km2_control_fault.execute(m_km2_control_trigger.signal.quit & m_environment.input_discrete.signal.hw_dvr_ready, + m_environment.auxiliary_km2.state.signal.is_on & m_environment.input_discrete.signal.hw_dvr_ready); + m_km3_control_fault.execute(m_km3_control_trigger.signal.quit & m_environment.input_discrete.signal.hw_dvr_ready, + m_environment.auxiliary_km3.state.signal.is_on & m_environment.input_discrete.signal.hw_dvr_ready); + //<> + + + // + // Fan Control + // + m_environment.fan_control.execute(m_environment.auxiliary_q1.state.signal.is_switched_on, m_environment.auxiliary_q1.state.signal.is_off); + //<> + + + + // + // FOR DEBUG ONLY + // + //m_environment.input_discrete.all = m_environment.input_discrete_debug_only.all; + + + // +}//process_digital_input() + +// +#pragma CODE_SECTION("ramfuncs"); +Uint32 SystemControl::get_digital_output() +{ + return (Uint32)m_environment.digital_output_inverse.all; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::setup_hvcell() +{ + m_environment.hardware.ref_control_order = ORDER_STOP; + //m_environment.hardware.control_order = ORDER_SELFCHECK; + set_hvcell_level(); + send_hvcell_control_order(); + get_hvcell_version(); + get_pwm_version(); + get_hvcell_state(); + get_cpu_cpld_version(); + // +}//selftest_hvcell() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::send_hvcell_syn_signal() +{ + sendSynSignal(); + // +}//send_syn_signal() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::send_hvcell_control_order() +{ + if(m_environment.hardware.control_order_cell != m_environment.hardware.ref_control_order) + { + m_environment.hardware.control_order_cell = m_environment.hardware.ref_control_order; + // + }//if + // + sendControlOrder(m_environment.hardware.control_order_cell); + // +}//send_control_order() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::set_hvcell_level() +{ + m_environment.hardware.error = setCellLevel(m_environment.hardware.level); + //m_environment.hardware.error = setCellLevel(m_environment.hardware.level, m_environment.hardware.switching_freq); + // +}//set_cell_level() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::get_pwm_version() +{ + getPwmVersion(m_environment.hardware.pwm_version); + // +}//get_pwm_version() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::get_hvcell_state() +{ + getCellState(m_environment.hardware.level, m_environment.hardware.hvcell.state); + // +}//get_cell_state() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::get_hvcell_dc_voltage() +{ + static float aux_a = FP_ZERO, aux_b = FP_ZERO, aux_c = FP_ZERO; + + getCellDCVoltage(m_environment.hardware.level, m_environment.hardware.hvcell.dc_voltage); + + aux_a = FP_ZERO; + aux_b = FP_ZERO; + aux_c = FP_ZERO; + // + for(Uint16 cellnum = 0; cellnum < m_environment.hardware.level; cellnum++) + { + aux_a += m_environment.hardware.hvcell.dc_voltage[0][cellnum]; + aux_b += m_environment.hardware.hvcell.dc_voltage[1][cellnum]; + aux_c += m_environment.hardware.hvcell.dc_voltage[2][cellnum]; + // + }//for + // + m_environment.cell_dc_voltage_a = aux_a; + m_environment.cell_dc_voltage_b = aux_b; + m_environment.cell_dc_voltage_c = aux_c; + // + m_environment.cell_dc_voltage_a_average = m_cell_dc_voltage_a_filter.execute(aux_a); + m_environment.cell_dc_voltage_b_average = m_cell_dc_voltage_b_filter.execute(aux_b); + m_environment.cell_dc_voltage_c_average = m_cell_dc_voltage_c_filter.execute(aux_c); + + //m_environment.cell_dc_voltage_a_reciprocal = hvcell_dc_voltage_reciprocal(m_environment.cell_dc_voltage_a_average); + //m_environment.cell_dc_voltage_b_reciprocal = hvcell_dc_voltage_reciprocal(m_environment.cell_dc_voltage_b_average); + //m_environment.cell_dc_voltage_c_reciprocal = hvcell_dc_voltage_reciprocal(m_environment.cell_dc_voltage_c_average); + + m_environment.cell_dc_voltage_a_reciprocal = 1.0/5.0/900.0; + m_environment.cell_dc_voltage_b_reciprocal = 1.0/5.0/900.0; + m_environment.cell_dc_voltage_c_reciprocal = 1.0/5.0/900.0; + +#if TYPECONTROL == SCALARCONTROL + m_environment.phase_control.phase_a.feedback.voltage_cell_dc_reciprocal = m_environment.cell_dc_voltage_a_reciprocal; + m_environment.phase_control.phase_b.feedback.voltage_cell_dc_reciprocal = m_environment.cell_dc_voltage_b_reciprocal; + m_environment.phase_control.phase_c.feedback.voltage_cell_dc_reciprocal = m_environment.cell_dc_voltage_c_reciprocal; +#endif + + // +}//get_cell_dc_voltage() +// +#pragma CODE_SECTION("ramfuncs"); +inline float SystemControl::hvcell_dc_voltage_reciprocal(float& voltage) +{ + if(voltage > FP_ZERO) + { + return 1.0/voltage; + // + } + else + { + return FP_ZERO; + // + }//if else + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::get_hvcell_version() +{ + getCellVersion(m_environment.hardware.level, m_environment.hardware.hvcell.version); + // +}//get_cell_version() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::send_hvcell_modulate_data() +{ + static float _data_u = FP_ZERO; + static float _data_v = FP_ZERO; + static float _data_w = FP_ZERO; + // + if(m_environment.hardware.hvcell.data_u >= (float)(1.0)) + { + _data_u = (float)(1.0); + } + else + { + if(m_environment.hardware.hvcell.data_u <= (float)(-1.0)) + { + _data_u = (float)(-1.0); + } + else + { + _data_u = m_environment.hardware.hvcell.data_u; + } + } + // + if(m_environment.hardware.hvcell.data_v >= (float)(1.0)) + { + _data_v = (float)(1.0); + } + else + { + if(m_environment.hardware.hvcell.data_v <= (float)(-1.0)) + { + _data_v = (float)(-1.0); + } + else + { + _data_v = m_environment.hardware.hvcell.data_v; + } + } + // + if(m_environment.hardware.hvcell.data_w >= (float)(1.0)) + { + _data_w = (float)(1.0); + } + else + { + if(m_environment.hardware.hvcell.data_w <= (float)(-1.0)) + { + _data_w = (float)(-1.0); + } + else + { + _data_w = m_environment.hardware.hvcell.data_w; + } + } + // + sendModulateData(_data_u, _data_v, _data_w); + //sendModulateData(m_environment.hardware.hvcell.data_u, m_environment.hardware.hvcell.data_v, m_environment.hardware.hvcell.data_w, m_environment.hardware.switching_freq); + // +}//send_modulate_data() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::get_cpu_cpld_version() +{ + m_environment.hardware.cpu_cpld_version = getCpuCpldVersion(); + // +}//get_cpu_cpld_version() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::hardware_diagnostic() +{ + m_environment.hardware.check_status(); + m_environment.hardware.check_faults(SYSCTRL::AlgorithmContext::OFF == m_algorithm_executed ? SYSCTRL::HardWare::SHORT : SYSCTRL::HardWare::COMPLETE); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::harmonica_multiplyer(float cos_alpha, float sin_alpha, float cos_beta, float sin_beta, float& out_cos, float& out_sin) +{ + out_cos = cos_alpha * cos_beta - sin_alpha * sin_beta; + out_sin = sin_alpha * cos_beta + cos_alpha * sin_beta; + // +}//harmonica_multiplyer() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::protection_thyristor_control() +{ + // + // Short Circuit VS Control + _trigger_protection_thyristor_control(); + m_environment.digital_output.signal.vs_control = m_vs_protection_control_trigger.signal.quit; // 4009 Short Circuit VS Thyristor + m_environment.digital_output_inverse.all = m_environment.digital_output.all ^ 0xFFFFFFFF ; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void SystemControl::_trigger_protection_thyristor_control() +{ + SYSCTRL::TriggerRegister::setSet(m_vs_protection_control_trigger, + m_environment.auxiliary_km2.state.signal.is_off); + SYSCTRL::TriggerRegister::setReset(m_vs_protection_control_trigger, + m_environment.auxiliary_km2.state.signal.is_on); + SYSCTRL::TriggerRegister::execute_reset_priority(m_vs_protection_control_trigger); + hardware_analog_current_fault.signal.fault = 0; + hardware_analog_current_fault.signal.vs = m_vs_protection_control_trigger.signal.quit; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool SystemControl::slow_loop_is_active() +{ + if(m_environment.counter_slow <= 0) + { + m_environment.counter_slow = m_environment.time_prescale_slow; + return true; + } + else + { + return false; + // + }//if else + // +}//slow_loop_is_active() +// +#pragma CODE_SECTION("ramfuncs"); +bool SystemControl::additional_loop_is_active() +{ + if(m_environment.counter_additional <= 0) + { + m_environment.counter_additional = m_environment.time_prescale_additional; + return true; + } + else + { + return false; + // + }//if else + // +}//additional_loop_is_active() +// +#pragma CODE_SECTION("ramfuncs"); +bool SystemControl::symmetrical_calculator_loop_is_active() +{ + if(m_environment.counter_symmetrical <= 0) + { + m_environment.counter_symmetrical = m_environment.time_prescale_symmetrical; + return true; + } + else + { + return false; + // + }//if else + // +}//symmetrical_calculator_loop_is_active() +// +#pragma CODE_SECTION("ramfuncs"); +void SystemControl::_rms_module_calculator(float xa, float xb, float xc, float& xrms) +{ + xrms = sqrtf(0.333333*(xa*xa + xb*xb + xc*xc)); + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/SystemDefinitions.h b/SYSCTRL/SystemDefinitions.h new file mode 100644 index 0000000..d05c40e --- /dev/null +++ b/SYSCTRL/SystemDefinitions.h @@ -0,0 +1,304 @@ +/* + * SystemDefinitions.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_SYSTEMDEFINITIONS_H_ +#define SYSCTRL_SYSTEMDEFINITIONS_H_ + +namespace SYSCTRL +{ + + + +struct Register16BitField +{ + uint16_t b00: 1; + uint16_t b01: 1; + uint16_t b02: 1; + uint16_t b03: 1; + uint16_t b04: 1; + uint16_t b05: 1; + uint16_t b06: 1; + uint16_t b07: 1; + uint16_t b08: 1; + uint16_t b09: 1; + uint16_t b10: 1; + uint16_t b11: 1; + uint16_t b12: 1; + uint16_t b13: 1; + uint16_t b14: 1; + uint16_t b15: 1; +};//Register16BitField + +struct Register16ByteField +{ + uint16_t bt0 :8; + uint16_t bt1 :8; +};//Register16ByteField + +struct Register16WordField +{ + uint16_t wL :16; +};//Register16WordField + + +union Register16 +{ + uint16_t all; + Register16BitField bit; + Register16ByteField byte; +};//Register16 + + +struct Register32BitField +{ + uint16_t b00: 1; + uint16_t b01: 1; + uint16_t b02: 1; + uint16_t b03: 1; + uint16_t b04: 1; + uint16_t b05: 1; + uint16_t b06: 1; + uint16_t b07: 1; + uint16_t b08: 1; + uint16_t b09: 1; + uint16_t b10: 1; + uint16_t b11: 1; + uint16_t b12: 1; + uint16_t b13: 1; + uint16_t b14: 1; + uint16_t b15: 1; + uint16_t b16: 1; + uint16_t b17: 1; + uint16_t b18: 1; + uint16_t b19: 1; + uint16_t b20: 1; + uint16_t b21: 1; + uint16_t b22: 1; + uint16_t b23: 1; + uint16_t b24: 1; + uint16_t b25: 1; + uint16_t b26: 1; + uint16_t b27: 1; + uint16_t b28: 1; + uint16_t b29: 1; + uint16_t b30: 1; + uint16_t b31: 1; +};//Register32BitField + + +struct Register32ByteField +{ + uint16_t bt0 :8; + uint16_t bt1 :8; + uint16_t bt2 :8; + uint16_t bt3 :8; +};//Register32ByteField + +struct Register32WordField +{ + uint16_t wL :16; + uint16_t wH :16; +};//Register32WordField + + +union Register32 +{ + uint32_t all; + Register32BitField bit; + Register32ByteField byte; + Register32WordField word; +};//Register32 + + + +struct BoolRegisterBitField +{ + uint16_t b0 :1; +};//BoolRegisterBitField + +union BoolRegister +{ + uint16_t all; + BoolRegisterBitField boolbit; + BoolRegister(): + all(0) + {} +};//BoolRegister + + + + + +#define CURRENT_LIMIT_RMS (float)(100.0) +#define CURRENT_PFC_RMS (float)(0.0) +#define GRID_VOLTAGE_REFERENCE (float)(6000.0) +#define GRID_VOLTAGE_HIGH_LIMIT (float)(6600.0) +#define CELL_DC_VOLTAGE_REFERENCE (float)(5.0*950.0) + + +#define REGULATOR_CURRENT_LIMIT_LOW_SATURATION (float)(GRID_VOLTAGE_REFERENCE * 0.57735) +#define REGULATOR_CURRENT_LIMIT_HIGH_SATURATION (float)(GRID_VOLTAGE_HIGH_LIMIT * 0.57735) + +#define REGULATOR_CURRENT_PFC_HIGH_SATURATION (float)(GRID_VOLTAGE_REFERENCE * 0.57735) +#define REGULATOR_CURRENT_PFC_LOW_SATURATION (float)((-1.0)*GRID_VOLTAGE_REFERENCE * 0.57735) + +#define CONTROL_BIT_ENABLE_CURRENT_LIMIT (uint16_t)(0x0001) +#define CONTROL_BIT_ENABLE_PFC (uint16_t)(0x0002) +#define CONTROL_BIT_ENABLE_HARMONICA (uint16_t)(0x0004) +#define CONTROL_BIT_ENABLE_AUTO_OFFSET (uint16_t)(0x0008) + +#define ENABLE_CONTROL_BIT (uint16_t)(\ + CONTROL_BIT_ENABLE_CURRENT_LIMIT |\ + CONTROL_BIT_ENABLE_PFC |\ + CONTROL_BIT_ENABLE_AUTO_OFFSET \ + ) +// CONTROL_BIT_ENABLE_CURRENT_LIMIT |\// +// CONTROL_BIT_ENABLE_PFC |\// + + + + +// +// Voltage PLL-ABC Parameters +// +#define PLLABC_FREQUENCY_NOMINAL (float)(2.0*FP_PI*50.0) +#define PLLABC_FREQUENCY_CUT (float)(2.0*FP_PI*10.0) +#define PLLABC_FREQUENCY_LIMIT_HI PLLABC_FREQUENCY_CUT +#define PLLABC_FREQUENCY_LIMIT_LOW -PLLABC_FREQUENCY_CUT + + + + +/* + struct EquipmentFaultsBitFieldStructure + { + + uint16_t remote_e_stop : 1; //0 + uint16_t local_e_stop : 1; //1 + uint16_t fan : 1; //2 + uint16_t cells : 1; //3 + // + uint16_t temperature_transformer_multi_winding : 1; //4 + uint16_t temperature_transformer_phase_a : 1; //5 + uint16_t temperature_transformer_phase_b : 1; //6 + uint16_t temperature_transformer_phase_c : 1; //7 + // + uint16_t cabinet_door_open : 1; //8 + uint16_t reserved_09 : 1; //9 + uint16_t reserved_10 : 1; //10 + uint16_t reserved_11 : 1; //11 + // + uint16_t reserved_12 : 1; //12 + uint16_t reserved_13 : 1; //13 + uint16_t reserved_14 : 1; //14 + uint16_t reserved_15 : 1; //15 + + };//EquipmentFaultsBitFieldStructure +*/ + +#define REMOTE_E_STOP 0//0x0001 +#define LOCAL_E_STOP 0//0x0002 +#define FAN 0//0x0004 +#define CELLS 0//0x0008 +#define TEMPERATURE_TRANSFORMER_MULTI_WINDINGS 0//0x0010 +#define TEMPERATURE_TRANSFORMER_PHASE_A 0//0x0020 +#define TEMPERATURE_TRANSFORMER_PHASE_B 0//0x0040 +#define TEMPERATURE_TRANSFORMER_PHASE_C 0//0x0080 +#define CABINET_DOOR_OPEN 0x0100 +#define ENABLE_EQUIPMENT_RESTART 0x0100 +/* +#define ENABLE_EQUIPMENT_RESTART (uint16_t)(\ + REMOTE_E_STOP |\ + LOCAL_E_STOP |\ + FAN |\ + CELLS |\ + TEMPERATURE_TRANSFORMER_MULTI_WINDINGS |\ + TEMPERATURE_TRANSFORMER_PHASE_A |\ + TEMPERATURE_TRANSFORMER_PHASE_B |\ + TEMPERATURE_TRANSFORMER_PHASE_C |\ + CABINET_DOOR_OPEN \ + ) +*/ + +/* + struct PhaseFaultBit + { + uint16_t exceed_voltage_level_3 :1; // 0 + uint16_t exceed_voltage_level_4 :1; // 1 + uint16_t decrease_voltage_level_3 :1; // 2 + uint16_t phase_lost :1; // 3 + // + uint16_t short_circuit :1; // 4 + uint16_t high_current :1; // 5 + uint16_t overload_current_level_1 :1; // 6 + uint16_t overload_current_level_2 :1; // 7 + // + uint16_t overload_current_level_3 :1; // 8 + uint16_t overload_invertor_current_level_1 :1; // 9 + uint16_t overload_invertor_current_level_2 :1; // 10 + uint16_t overload_invertor_current_level_3 :1; // 11 + // + uint16_t reserved_12 :1; // 12 + uint16_t reserved_13 :1; // 13 + uint16_t reserved_14 :1; // 14 + uint16_t reserved_15 :1; // 15 + };//PhaseFaultBit +*/ + +#define EXCEED_VOLTAGE_LEVEL_3 (uint16_t)0x0001 +#define EXCEED_VOLTAGE_LEVEL_4 (uint16_t)0x0002 +#define DECREASE_VOLTAGE_LEVEL_3 (uint16_t)0x0004 +#define LOST_PHASE (uint16_t)0x0008 +#define SHORT_CIRCUIT (uint16_t)0x0010 +#define HIGH_CURRENT (uint16_t)0x0020 +#define OVERLOAD_CURRENT_LEVEL_1 (uint16_t)0x0040 +#define OVERLOAD_CURRENT_LEVEL_2 (uint16_t)0x0080 +#define OVERLOAD_CURRENT_LEVEL_3 (uint16_t)0x0100 +#define OVERLOAD_INVERTOR_CURRENT_LEVEL_1 (uint16_t)0x0200 +#define OVERLOAD_INVERTOR_CURRENT_LEVEL_2 (uint16_t)0x0400 +#define OVERLOAD_INVERTOR_CURRENT_LEVEL_3 (uint16_t)0x0800 +#define ENABLE_PHASE_RESTART 0 +/* +#define ENABLE_PHASE_RESTART (uint16_t)(\ + EXCEED_VOLTAGE_LEVEL_3 |\ + EXCEED_VOLTAGE_LEVEL_4 |\ + DECREASE_VOLTAGE_LEVEL_3 |\ + LOST_PHASE |\ + SHORT_CIRCUIT |\ + HIGH_CURRENT |\ + OVERLOAD_CURRENT_LEVEL_1 |\ + OVERLOAD_CURRENT_LEVEL_2 |\ + OVERLOAD_CURRENT_LEVEL_3 |\ + OVERLOAD_INVERTOR_CURRENT_LEVEL_1 |\ + OVERLOAD_INVERTOR_CURRENT_LEVEL_2 |\ + OVERLOAD_INVERTOR_CURRENT_LEVEL_3 \ + ) +*/ + + + +#define NOMINAL_GRID_VOLTAGE (float)6000.0 +#define PROTECTION_EXCEED_VOLTAGE_LEVEL_1_PERCENT (float)10.0 +#define PROTECTION_EXCEED_VOLTAGE_LEVEL_2_PERCENT (float)15.0 +#define PROTECTION_EXCEED_VOLTAGE_LEVEL_3_PERCENT (float)20.0 +#define PROTECTION_EXCEED_VOLTAGE_LEVEL_4_PERCENT (float)50.0 +#define PROTECTION_DECREASE_VOLTAGE_LEVEL_1_PERCENT (float)15.0 +#define PROTECTION_DECREASE_VOLTAGE_LEVEL_2_PERCENT (float)25.0 +#define PROTECTION_DECREASE_VOLTAGE_LEVEL_3_PERCENT (float)35.0 + + + + + + + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_SYSTEMDEFINITIONS_H_ */ diff --git a/SYSCTRL/SystemEnvironment.cpp b/SYSCTRL/SystemEnvironment.cpp new file mode 100644 index 0000000..d77e840 --- /dev/null +++ b/SYSCTRL/SystemEnvironment.cpp @@ -0,0 +1,614 @@ +/* + * SystemEnvironment.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/SystemEnvironment.h" + +namespace SYSCTRL +{ + +//CONSTRUCTOR +SystemEnvironment::SystemEnvironment(): + id_software(), + time_sample_control(-1.0), + time_sample_slow(-1.0), + time_sample_additional(-1.0), + time_prescale_slow(0), + time_prescale_additional(0), + time_prescale_symmetrical((Uint16)14325), + counter_slow(0), + counter_additional(0), + counter_symmetrical(333), + // + fram_operation(), + fram_burn(), + fram_erase(), + fram_verify(), + fram_read(), + fram_restore(), + // + analog_input(), + // + scale_voltage_grid_a(1.0), + scale_voltage_grid_b(1.0), + scale_voltage_grid_c(1.0), + // + scale_current_input_a(1.0), + scale_current_input_b(1.0), + scale_current_input_c(1.0), + // + scale_current_cell_a(1.0), + scale_current_cell_b(1.0), + scale_current_cell_c(1.0), + // + scale_voltage_load_a(1.0), + scale_voltage_load_b(1.0), + scale_voltage_load_c(1.0), + // + scale_current_load_a(1.0), + scale_current_load_b(1.0), + scale_current_load_c(1.0), + // + scale_current_bypass_a(1.0), + scale_current_bypass_b(1.0), + scale_current_bypass_c(1.0), + // + // + offset_voltage_grid_a(FP_ZERO), + offset_voltage_grid_b(FP_ZERO), + offset_voltage_grid_c(FP_ZERO), + // + offset_current_input_a(FP_ZERO), + offset_current_input_b(FP_ZERO), + offset_current_input_c(FP_ZERO), + // + offset_current_cell_a(FP_ZERO), + offset_current_cell_b(FP_ZERO), + offset_current_cell_c(FP_ZERO), + // + offset_voltage_load_a(FP_ZERO), + offset_voltage_load_b(FP_ZERO), + offset_voltage_load_c(FP_ZERO), + // + offset_current_load_a(FP_ZERO), + offset_current_load_b(FP_ZERO), + offset_current_load_c(FP_ZERO), + // + offset_current_bypass_a(FP_ZERO), + offset_current_bypass_b(FP_ZERO), + offset_current_bypass_c(FP_ZERO), + // + // + offset_voltage_grid_static_a(FP_ZERO), + offset_voltage_grid_static_b(FP_ZERO), + offset_voltage_grid_static_c(FP_ZERO), + // + offset_current_input_static_a(FP_ZERO), + offset_current_input_static_b(FP_ZERO), + offset_current_input_static_c(FP_ZERO), + // + offset_current_cell_static_a(FP_ZERO), + offset_current_cell_static_b(FP_ZERO), + offset_current_cell_static_c(FP_ZERO), + // + offset_voltage_load_static_a(FP_ZERO), + offset_voltage_load_static_b(FP_ZERO), + offset_voltage_load_static_c(FP_ZERO), + // + offset_current_load_static_a(FP_ZERO), + offset_current_load_static_b(FP_ZERO), + offset_current_load_static_c(FP_ZERO), + // + offset_current_bypass_static_a(FP_ZERO), + offset_current_bypass_static_b(FP_ZERO), + offset_current_bypass_static_c(FP_ZERO), + // + // + adc_voltage_grid_a(FP_ZERO), + adc_voltage_grid_b(FP_ZERO), + adc_voltage_grid_c(FP_ZERO), + // + adc_current_input_a(FP_ZERO), + adc_current_input_b(FP_ZERO), + adc_current_input_c(FP_ZERO), + // + adc_current_cell_a(FP_ZERO), + adc_current_cell_b(FP_ZERO), + adc_current_cell_c(FP_ZERO), + // + adc_voltage_load_a(FP_ZERO), + adc_voltage_load_b(FP_ZERO), + adc_voltage_load_c(FP_ZERO), + // + adc_current_load_a(FP_ZERO), + adc_current_load_b(FP_ZERO), + adc_current_load_c(FP_ZERO), + // + adc_current_bypass_a(FP_ZERO), + adc_current_bypass_b(FP_ZERO), + adc_current_bypass_c(FP_ZERO), + // + // + voltage_grid_a(FP_ZERO), + voltage_grid_b(FP_ZERO), + voltage_grid_c(FP_ZERO), + // + current_input_a(FP_ZERO), + current_input_b(FP_ZERO), + current_input_c(FP_ZERO), + // + current_cell_a(FP_ZERO), + current_cell_b(FP_ZERO), + current_cell_c(FP_ZERO), + // + current_bypass_a(FP_ZERO), + current_bypass_b(FP_ZERO), + current_bypass_c(FP_ZERO), + // + voltage_load_a(FP_ZERO), + voltage_load_b(FP_ZERO), + voltage_load_c(FP_ZERO), + // + current_load_a(FP_ZERO), + current_load_b(FP_ZERO), + current_load_c(FP_ZERO), + // + +#if TYPECONTROL == VECTORCONTROL + voltage_grid_alpha(FP_ZERO), + voltage_grid_beta(FP_ZERO), + // + voltage_grid_direct(FP_ZERO), + voltage_grid_quadrature(FP_ZERO), + // + voltage_load_alpha(FP_ZERO), + voltage_load_beta(FP_ZERO), + // + voltage_load_direct(FP_ZERO), + voltage_load_quadrature(FP_ZERO), + // + current_load_alpha(FP_ZERO), + current_load_beta(FP_ZERO), + // + current_load_direct(FP_ZERO), + current_load_quadrature(FP_ZERO), + // + current_bypass_alpha(FP_ZERO), + current_bypass_beta(FP_ZERO), + // + current_bypass_direct(FP_ZERO), + current_bypass_quadrature(FP_ZERO), + // + current_cell_alpha(FP_ZERO), + current_cell_beta(FP_ZERO), + // + current_cell_direct(FP_ZERO), + current_cell_quadrature(FP_ZERO), + // + current_reference_limit(FP_ZERO), + current_reference_pfc(FP_ZERO), + // + voltage_reference_limit_high(FP_ZERO), + voltage_reference_load_direct(FP_ZERO), + voltage_reference_load_quadrature(FP_ZERO), + voltage_reference_dc_cell(FP_ZERO), + // + voltage_pi_reg_out_direct(FP_ZERO), + voltage_pi_reg_out_quadrature(FP_ZERO), + // + voltage_cell_direct(FP_ZERO), + voltage_cell_quadrature(FP_ZERO), + // + voltage_cell_alpha(FP_ZERO), + voltage_cell_beta(FP_ZERO), + // + voltage_cell_a(FP_ZERO), + voltage_cell_b(FP_ZERO), + voltage_cell_c(FP_ZERO), +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + drc_voltage_grid_alpha(FP_ZERO), + drc_voltage_grid_beta(FP_ZERO), + // + drc_voltage_grid_direct(FP_ZERO), + drc_voltage_grid_quadrature(FP_ZERO), + // + drc_positive_voltage_load_direct(FP_ZERO), + drc_positive_voltage_load_quadrature(FP_ZERO), + drc_negaative_voltage_load_direct(FP_ZERO), + drc_negative_voltage_load_quadrature(FP_ZERO), + // + drc_current_load_alpha(FP_ZERO), + drc_current_load_beta(FP_ZERO), + // + drc_current_load_direct(FP_ZERO), + drc_current_load_quadrature(FP_ZERO), + // + drc_current_bypass_alpha(FP_ZERO), + drc_current_bypass_beta(FP_ZERO), + // + drc_current_bypass_direct(FP_ZERO), + drc_current_bypass_quadrature(FP_ZERO), + // + drc_current_cell_alpha(FP_ZERO), + drc_current_cell_beta(FP_ZERO), + // + drc_current_cell_direct(FP_ZERO), + drc_current_cell_quadrature(FP_ZERO), + // + drc_current_reference_limit(FP_ZERO), + drc_current_reference_pfc(FP_ZERO), + // + drc_voltage_reference_limit_high(FP_ZERO), + drc_voltage_reference_load_direct(FP_ZERO), + drc_voltage_reference_load_quadrature(FP_ZERO), + drc_voltage_reference_dc_cell(FP_ZERO), + drc_voltage_reference_zero(FP_ZERO), + // + drc_positive_voltage_cell_direct(FP_ZERO), + drc_positive_voltage_cell_quadrature(FP_ZERO), + drc_negative_voltage_cell_direct(FP_ZERO), + drc_negative_voltage_cell_quadrature(FP_ZERO), + // + drc_positive_voltage_cell_alpha(FP_ZERO), + drc_positive_voltage_cell_beta(FP_ZERO), + drc_negative_voltage_cell_alpha(FP_ZERO), + drc_negative_voltage_cell_beta(FP_ZERO), + // + drc_positive_voltage_cell_a(FP_ZERO), + drc_positive_voltage_cell_b(FP_ZERO), + drc_positive_voltage_cell_c(FP_ZERO), + // + drc_negative_voltage_cell_a(FP_ZERO), + drc_negative_voltage_cell_b(FP_ZERO), + drc_negative_voltage_cell_c(FP_ZERO), + // + drc_voltage_cell_a(FP_ZERO), + drc_voltage_cell_b(FP_ZERO), + drc_voltage_cell_c(FP_ZERO), +#endif + + + + reference_phase_a(FP_ZERO), + reference_phase_b(FP_ZERO), + reference_phase_c(FP_ZERO), + // + reference_phase_alpha(FP_ZERO), + reference_phase_betta(FP_ZERO), + // + reference_phase_d(FP_ZERO), + reference_phase_q(FP_ZERO), + // + scale_compute_voltage_command(), + scale_compute_current_command(), + scale_compute_voltage_input(this->rms_voltage_input_ab, + this->rms_voltage_input_bc, + this->rms_voltage_input_ca, + this->scale_voltage_grid_a, + this->scale_voltage_grid_b, + this->scale_voltage_grid_c), + scale_compute_voltage_load(this->rms_voltage_load_ab, + this->rms_voltage_load_bc, + this->rms_voltage_load_ca, + this->scale_voltage_load_a, + this->scale_voltage_load_b, + this->scale_voltage_load_c), + scale_compute_current_input(this->rms_current_input_a, + this->rms_current_input_b, + this->rms_current_input_c, + this->scale_current_input_a, + this->scale_current_input_b, + this->scale_current_input_c), + scale_compute_current_cell(this->rms_current_cell_a, + this->rms_current_cell_b, + this->rms_current_cell_c, + this->scale_current_cell_a, + this->scale_current_cell_b, + this->scale_current_cell_c), + scale_compute_current_load(this->rms_current_load_a, + this->rms_current_load_b, + this->rms_current_load_c, + this->scale_current_load_a, + this->scale_current_load_b, + this->scale_current_load_c), + scale_compute_current_bypass(this->rms_current_bypass_a, + this->rms_current_bypass_b, + this->rms_current_bypass_c, + this->scale_current_bypass_a, + this->scale_current_bypass_b, + this->scale_current_bypass_c), + + + spinner_phase_a(), + spinner_phase_b(), + spinner_phase_c(), + // + module_voltage_phase_a(), + module_voltage_phase_b(), + module_voltage_phase_c(), + // + + //Signal Decompose + relative_voltage_input_a(), + relative_voltage_input_b(), + relative_voltage_input_c(), + // + projection_voltage_input_a(), + projection_voltage_input_b(), + projection_voltage_input_c(), + // + projection_voltage_load_a(), + projection_voltage_load_b(), + projection_voltage_load_c(), + // + projection_current_load_a(), + projection_current_load_b(), + projection_current_load_c(), + // + projection_current_cell_a(), + projection_current_cell_b(), + projection_current_cell_c(), + // + projection_current_bypass_a(), + projection_current_bypass_b(), + projection_current_bypass_c(), + +// test_projection_a(), +// test_projection_b(), +// test_projection_c(), + + //Symmetrical Components + symmetrical_components_voltage_input(), + symmetrical_components_voltage_load(), + symmetrical_components_current_load(), + symmetrical_components_current_bypass(), + + // + //RMS value + // + rms_voltage_input_ab(FP_ZERO), + rms_voltage_input_bc(FP_ZERO), + rms_voltage_input_ca(FP_ZERO), + rms_voltage_input_module(FP_ZERO), + // + rms_voltage_load_ab(FP_ZERO), + rms_voltage_load_bc(FP_ZERO), + rms_voltage_load_ca(FP_ZERO), + rms_voltage_load_module(FP_ZERO), + // + rms_current_input_a(FP_ZERO), + rms_current_input_b(FP_ZERO), + rms_current_input_c(FP_ZERO), + rms_current_input_module(FP_ZERO), + // + rms_current_load_a(FP_ZERO), + rms_current_load_b(FP_ZERO), + rms_current_load_c(FP_ZERO), + rms_current_load_module(FP_ZERO), + // + rms_current_bypass_a(FP_ZERO), + rms_current_bypass_b(FP_ZERO), + rms_current_bypass_c(FP_ZERO), + rms_current_bypass_module(FP_ZERO), + // + rms_current_cell_a(FP_ZERO), + rms_current_cell_b(FP_ZERO), + rms_current_cell_c(FP_ZERO), + // + hardware(), + cell_dc_voltage_a(FP_ZERO), + cell_dc_voltage_b(FP_ZERO), + cell_dc_voltage_c(FP_ZERO), + cell_dc_voltage_a_average(FP_ZERO), + cell_dc_voltage_b_average(FP_ZERO), + cell_dc_voltage_c_average(FP_ZERO), + cell_dc_voltage_a_reciprocal(FP_ZERO), + cell_dc_voltage_b_reciprocal(FP_ZERO), + cell_dc_voltage_c_reciprocal(FP_ZERO), + + system_alarm(), + system_fault(), + system_reset(), + system_ready(), + short_circuit(), + enable_work(), + enable_work_previous(), + enable_work_is_on(), + enable_work_is_off(), + enable_work_reset(), + system_faults_register(), + + external_command_word(), + external_start(), + external_stop(), + external_reset(), + external_e_stop(), + external_km1_on(0), + external_km1_off(), + external_km3_on(), + external_km3_off(), + external_q1_on(), + external_q1_off(), + + + gen_ort_a(FP_ZERO), + gen_ort_b(FP_ZERO), + gen_ort_c(FP_ZERO), + gen_ort_alpha(FP_ZERO), + gen_ort_beta(FP_ZERO), + + grid_frequency(FP_ZERO), + status_pll_sync(false), + + + //PLL-ABC + pll_abc_orts(), + main_abc_orts(), + main_abc_reverse_orts(), + twisted_abc_orts(), + main_ab_orts(), + harmonica_2(), + harmonica_3(), + harmonica_5(), + harmonica_7(), + harmonica_9(), + harmonica_11(), + + //Algorithm Control + algorithm_control(), + enable_current_limit(), + enable_pfc(), + enable_harmonica(), + enable_auto_offset(), + allow_auto_offset(false), + + //AlgorithmPhaseControl +#if TYPECONTROL == SCALARCONTROL + phase_control(), + start_control(), +#endif + algorithm_source_references(), + + + //Harmonica Analyzer + voltage_input_a_harmonica_5(), + voltage_input_b_harmonica_5(), + voltage_input_c_harmonica_5(), + + + //Framework data + digital_output_inverse(), + digital_output(), + digital_input(), + digital_output_temp(), + + + //Phase Alarm monitor + phase_alert_monitor_register(), + + + //Fan Control + fan_control(), + + // + //digital inputs + remote_start(), //3001 + remote_stop(), //3002 + remote_reset(), //3003 + remote_e_stop(), //3004 + auxiliary_q1(), //3005 + bypass_ready(), //3006 + transformer_inv_over_temperature_alarm(), //3007 + local_e_stop(), //3008 + cabinet_door_interlocked(), //3009 + arc_and_fire(),//3010 + hw_dvr_ready(), //3011 + auxiliary_km2(), //3012 + auxiliary_km11(), //3013 + transformer_t_over_temperature_fault(),//3014 + control_power_supply_status(),//3015 + auxiliary_km1(), //3016 + auxiliary_km3(), //3017 + transformer_inv_over_temperature_fault(), //3018 + fan_fault(), //3019 + local_remote(), //3020 + input_discrete(), + //input_discrete_debug_only(), + // + generator_abc(), + //gen_symm_comp_inp_volt(), + //amplitude_generator_pwm(1.0), + //generator_pwm(), + // +#if TYPECONTROL == VECTORCONTROL + regulator_voltage_load_direct(), + regulator_voltage_load_quadrature(), + // + integrator_direct(), + integrator_quadrature(), + // + regulator_current_load_direct(), + regulator_current_load_quadrature(), + // + reference_voltage_direct_intensity(), + // + referencer_current_bypass_direct(), + referencer_current_bypass_quadrature(), + // + regulator_current_limit(), + regulator_current_pfc(), +#endif + // + // +#if TYPECONTROL == SCALARCONTROL + regulator_voltage_load_a_active(), + regulator_voltage_load_a_reactive(), + regulator_voltage_load_b_active(), + regulator_voltage_load_b_reactive(), + regulator_voltage_load_c_active(), + regulator_voltage_load_c_reactive(), + // + regulator_current_limit_a(), + regulator_current_pfc_a(), + regulator_current_limit_b(), + regulator_current_pfc_b(), + regulator_current_limit_c(), + regulator_current_pfc_c(), + // + current_regulator_a_active(), + current_regulator_a_reactive(), + current_regulator_b_active(), + current_regulator_b_reactive(), + current_regulator_c_active(), + current_regulator_c_reactive(), + current_referencer_a_active(), + current_referencer_a_reactive(), + current_referencer_b_active(), + current_referencer_b_reactive(), + current_referencer_c_active(), + current_referencer_c_reactive(), + // + regulator_dc_a(), + regulator_dc_b(), + regulator_dc_c(), +#endif + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + drc_positive_voltage_controller_direct(), + drc_positive_voltage_controller_quadrature(), + drc_negative_voltage_controller_direct(), + drc_negative_voltage_controller_quadrature(), + // + drc_reference_voltage_direct_intensity(), + // + drc_regulator_current_load_direct(), + drc_regulator_current_load_quadrature(), + // + drc_referencer_current_bypass_direct(), + drc_referencer_current_bypass_quadrature(), + // + drc_regulator_current_limit(), + drc_regulator_current_pfc(), + // + drc_direct_voltage_decomposer(), + drc_back_voltage_decomposer(), +#endif + // + timer_start(), + timer_stop() + // +{ + bypass_ready.state.all = 0x15; + auxiliary_km11.state.all = 0x15; + hw_dvr_ready.state.all = 0x15; +}//CONSTRUCTOR + +} /* namespace SYSCTRL */ + diff --git a/SYSCTRL/SystemEnvironment.h b/SYSCTRL/SystemEnvironment.h new file mode 100644 index 0000000..b6810b2 --- /dev/null +++ b/SYSCTRL/SystemEnvironment.h @@ -0,0 +1,1168 @@ +/* + * SystemEnvironment.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "framework.h" +#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File +#include "DSP2833x_Examples.h" +#include "SYSCTRL/TypeControl.h" +#include "SYSCTRL/DRCDecomposer.h" +#include "SYSCTRL/SystemDefinitions.h" +#include "SYSCTRL/FanTimerControl.h" +#include "SYSCTRL/HardWare.h" +#include "SYSCTRL/MonitorDigitalInputSignal.h" +#include "SYSCTRL/PhaseAlertMonitor.h" +#include "SYSCTRL/SignalDecompose.h" +#include "SYSCTRL/SymmetricalComponents.h" +#include "SYSCTRL/ScaleCompute.h" +#include "SYSCTRL/SystemDefinitions.h" +#include "SYSCTRL/HeadersFLTSYSLIB.h" +#include "SYSCTRL/GeneratorSymmetricalComponents.h" +#include "SYSCTRL/TriggerBase.h" +#include "SYSCTRL/TriggerFault.h" +#include "SYSCTRL/TriggerRS.h" +#include "SYSCTRL/TriggerRegister.h" + + + + +#ifndef SYSCTRL_SYSTEMENVIRONMENT_H_ +#define SYSCTRL_SYSTEMENVIRONMENT_H_ + + +namespace SYSCTRL +{ + +#define SOFTWARE_CLASS_ID ((uint16_t)(0x0001)) +#define SOFTWARE_PART_ID ((uint16_t)(0x0001)) +#define SOFTWARE_SOFTWARE_VERSION ((uint16_t)(0x0101)) +#define SOFTWARE_PROTOCOL_VERSION ((uint16_t)(0x0101)) + + +struct IDSOFTWARE +{ + uint16_t class_id; + uint16_t part_id; + uint16_t software_version; + uint16_t protocol_version; + IDSOFTWARE(): + class_id(SOFTWARE_CLASS_ID), + part_id(SOFTWARE_PART_ID), + software_version(SOFTWARE_SOFTWARE_VERSION), + protocol_version(SOFTWARE_PROTOCOL_VERSION) + {} +};//IDSOFTWARE + + +struct InputDiscreteSignalsBitField +{ + uint32_t remote_start: 1; // DI_3001 - bit 0 + uint32_t remote_stop: 1; // DI_3002 - bit 1 + uint32_t remote_reset: 1; // DI_3003 - bit 2 + uint32_t remote_e_stop: 1; // DI_3004 - bit 3 + uint32_t auxiliary_q1: 1; // DI_3005 - bit 4 + uint32_t bypass_ready: 1; // DI_3006 - bit 5 + uint32_t transformer_dvr_over_temperature_alarm: 1; // DI_3007 - bit 6 + uint32_t local_e_stop: 1; // DI_3008 - bit 7 + uint32_t cabinet_door_interlocked: 1; // DI_3009 - bit 8 + uint32_t arc_and_fire: 1; // DI_3010 - bit 9 + uint32_t hw_dvr_ready: 1; // DI_3011 - bit 10 + uint32_t auxiliary_km2: 1; // DI_3012 - bit 11 + uint32_t auxiliary_km11: 1; // DI_3013 - bit 12 + uint32_t transformer_t_over_temperature_fault: 1; // DI_3014 - bit 13 + uint32_t control_power_supply_status: 1; // DI_3015 - bit 14 + uint32_t auxiliary_km1: 1; // DI_3016 - bit 15 + uint32_t auxiliary_km3: 1; // DI_3017 - bit 16 + uint32_t transformer_dvr_over_temperature_fault: 1; // DI_3018 - bit 17 + uint32_t fan_fault: 1; // DI_3019 - bit 18 + uint32_t local_remote: 1; // DI_3010 - bit 19 + uint32_t reserved: 12; // reserved - bit 31-20 +};//InputDiscreteSignalsBitField + + +union InputDiscreteSignals +{ + uint32_t all; + Register32BitField bit; + DigitalInput digital; + DigitalInputBitField field; + SYSCTRL::InputDiscreteSignalsBitField signal; + InputDiscreteSignals(): + all((uint32_t)0) + {} +};//InputDiscreteSignals + + +struct OutputDiscteteSignalsBitField +{ + uint32_t work: 1; // DO_4001 - bit 0 + uint32_t fault: 1; // DO_4002 - bit 1 + uint32_t ready: 1; // DO_4003 - bit 2 + uint32_t alarm: 1; // DO_4004 - bit 3 + uint32_t off_high_voltage_q1: 1; // DO_4005 - bit 4 + uint32_t on_q1: 1; // DO_4006 - bit 5 + uint32_t off_q1: 1; // DO_4007 - bit 6 + uint32_t on_km11: 1; // DO_4008 - bit 7 + uint32_t vs_control: 1; // DO_4009 - bit 8 + uint32_t allow_on_high_voltage: 1; // DO_4010 - bit 9 + uint32_t on_km1: 1; // DO_4011 - bit 10 + uint32_t off_km1: 1; // DO_4012 - bit 11 + uint32_t on_km2: 1; // DO_4013 - bit 12 + uint32_t off_km2: 1; // DO_4014 - bit 13 + uint32_t high_voltage_indicator: 1; // DO_4015 - bit 14 + uint32_t reserved_b15: 1; // DO_4016 - bit 15 + uint32_t mode_local_remote: 1; // DO_4017 - bit 16 + uint32_t on_km3: 1; // DO_4018 - bit 17 + uint32_t on_km11t: 1; // DO_4019 - bit 18 + uint32_t off_km3: 1; // DO_4020 - bit 19 + uint32_t reserved_12: 12; // reserved - bit 31-20 +};//OutputDiscteteSignalsBitField + +union OutputDiscteteSignalsRegister +{ + uint32_t all; + Register32BitField bit; + DigitalOutputBitField field; + OutputDiscteteSignalsBitField signal; + OutputDiscteteSignalsRegister(): + all((uint32_t)0) + {} +};//OutputDiscteteSignalsRegister + + +struct ExternalCommandWordBitField +{ + uint16_t start: 1; //0 + uint16_t stop: 1; //1 + uint16_t reset: 1; //2 + uint16_t e_stop: 1; //3 + uint16_t km1_on: 1; //4 + uint16_t km1_off: 1; //5 + uint16_t km3_on: 1; //6 + uint16_t km3_off: 1; //7 + uint16_t q1_on: 1; //8 + uint16_t q1_off: 1; //9 + // +};//ExternalCommandWordBitField + +union ExternalCommandWordRegister +{ + uint16_t all; + Register16BitField bit; + ExternalCommandWordBitField signal; + ExternalCommandWordRegister(): + all((uint16_t)0) + {} +};//ExternalCommandWordRegister + + +struct AlgorithmControlBits +{ + uint16_t enable_current_limit: 1; //0 + uint16_t enable_pfc: 1; //1 + uint16_t enable_harmonica: 1; //2 + uint16_t enable_auto_offset: 1; //3 +};//AlgorithmControlBits +// +union AlgorithmControlRegister +{ + uint16_t all; + Register16BitField bit; + AlgorithmControlBits signal; + AlgorithmControlRegister(): + all((uint16_t)9) + {} +};//AlgorithmControlRegister + + +struct FlashOperationBitField +{ + uint16_t burn: 1; //0 + uint16_t erase: 1; //1 + uint16_t verify: 1; //2 + uint16_t read: 1; //3 + uint16_t restore: 1; //4 +};// + +union FlashOperationRegister +{ + uint16_t all; + Register16BitField bit; + FlashOperationBitField signal; + FlashOperationRegister(): + all((uint16_t)0) + {} +};//FlashOperationRegister + + +struct VecorModuleStructure +{ + float module; + float reciprocal; + VecorModuleStructure(): + module(FP_ZERO), + reciprocal(FP_ZERO) + {} +};//VecorModuleStructure + + +struct VectorOrthogonalProjection +{ + float active; + float reactive; + VectorOrthogonalProjection(): + active(FP_ZERO), + reactive(FP_ZERO) + {} +};// + +struct SystemABCOrts +{ + VectorOrthogonalProjection phase_a; + VectorOrthogonalProjection phase_b; + VectorOrthogonalProjection phase_c; + SystemABCOrts(): + phase_a(), + phase_b(), + phase_c() + {} +};// + + +struct AlgorithmCommonConstants +{ + float transformation_coefficient; + float transformation_coefficient_reciprocal; + AlgorithmCommonConstants(): + transformation_coefficient(25.0), + transformation_coefficient_reciprocal(1.0/25.0) + {} +};//AlgorithmCommonConstants + + +struct AlgorithmCommonReference +{ + float current_limit_rms; + float current_limit_ampl; + float current_pfc_rms; + float current_pfc_ampl; + float voltage_module_rms; + float voltage_module_ampl; + float voltage_rms_real; + float voltage_rms_jm; + float voltage_ampl_real; + float voltage_ampl_jm; + float voltage_dc; + AlgorithmCommonReference(): + current_limit_rms(FP_ZERO), + current_limit_ampl(FP_ZERO), + current_pfc_rms(FP_ZERO), + current_pfc_ampl(FP_ZERO), + voltage_module_rms(FP_ZERO), + voltage_module_ampl(FP_ZERO), + voltage_rms_real(FP_ZERO), + voltage_rms_jm(FP_ZERO), + voltage_ampl_real(FP_ZERO), + voltage_ampl_jm(FP_ZERO), + voltage_dc() + {} +};//AlgorithmCommonReference + + +struct HardwareAnalogCurrentFaultBitField +{ + uint16_t phase_a: 1; + uint16_t phase_b: 1; + uint16_t phase_c: 1; + uint16_t fault: 1; + uint16_t vs: 1; +};//HardwareAnalogCurrentFaultBitField + +union HardwareAnalogCurrentFaultRegister +{ + uint16_t all; + Register16BitField bit; + HardwareAnalogCurrentFaultBitField signal; + HardwareAnalogCurrentFaultRegister(): + all((uint16_t)0) + {} +};//HardwareAnalogCurrentFaultRegister + + + + +struct AlgorithmSinglePhaseReference +{ + float voltage_dc; + float current_ampl_limit_const; + float current_ampl_pfc_const; + // + float voltage_ampl_real_const; + float voltage_ampl_jm_const; + // + float voltage_limit; + float voltage_pfc; + // + float voltage_ampl_real; + float voltage_ampl_jm; + float voltage_cell_ampl_real; + float voltage_cell_ampl_jm; + float voltage_cell_real; + float voltage_cell_jm; + float voltage_cell; + float voltage_cell_relative; + AlgorithmSinglePhaseReference(): + voltage_dc(FP_ZERO), + current_ampl_limit_const(FP_ZERO), + current_ampl_pfc_const(FP_ZERO), + voltage_ampl_real_const(FP_ZERO), + voltage_ampl_jm_const(FP_ZERO), + voltage_limit(FP_ZERO), + voltage_pfc(FP_ZERO), + voltage_ampl_real(FP_ZERO), + voltage_ampl_jm(FP_ZERO), + voltage_cell_ampl_real(FP_ZERO), + voltage_cell_ampl_jm(FP_ZERO), + voltage_cell_real(FP_ZERO), + voltage_cell_jm(FP_ZERO), + voltage_cell(FP_ZERO), + voltage_cell_relative(FP_ZERO) + {} +};//AlgorithmSinglePhaseReference + + +struct AlgorithmSinglePhaseFeedback +{ + float voltage_ampl_real; + float voltage_ampl_jm; + // + float current_module; + float current_ampl_real; + float current_ampl_jm; + // + float voltage_cell_dc_reciprocal; + AlgorithmSinglePhaseFeedback(): + voltage_ampl_real(FP_ZERO), + voltage_ampl_jm(FP_ZERO), + current_ampl_real(FP_ZERO), + current_ampl_jm(FP_ZERO), + voltage_cell_dc_reciprocal(FP_ZERO) + {} +};//AlgorithmSinglePhaseFeedback + + +struct AlgorithmSinglePhaseControl +{ + AlgorithmControlRegister control_bit; + AlgorithmSinglePhaseReference reference; + AlgorithmSinglePhaseFeedback feedback; + AlgorithmSinglePhaseControl(): + control_bit(), + reference(), + feedback() + {} +};//AlgorithmSinglePhaseControl + + +struct AlgorithmPhaseControl +{ + AlgorithmControlRegister common_control_bit; + AlgorithmCommonReference common_ref; + AlgorithmSinglePhaseControl phase_a; + AlgorithmSinglePhaseControl phase_b; + AlgorithmSinglePhaseControl phase_c; + AlgorithmCommonConstants constants; + AlgorithmPhaseControl(): + common_control_bit(), + common_ref(), + phase_a(), + phase_b(), + phase_c(), + constants() + {} +};//AlgorithmPhaseControl + + +struct AlgorithmStartSinglePhaseReference +{ + float current_bypass_active; + float current_bypass_reactive; + // + float current_cell_active; + float current_cell_reactive; + // + float voltage_cell_ampl_active; + float voltage_cell_ampl_reactive; + // + float voltage_cell_active; + float voltage_cell_reactive; + float voltage_cell; + float voltage_cell_relative; + AlgorithmStartSinglePhaseReference(): + current_bypass_active(FP_ZERO), + current_bypass_reactive(FP_ZERO), + current_cell_active(FP_ZERO), + current_cell_reactive(FP_ZERO), + voltage_cell_ampl_active(FP_ZERO), + voltage_cell_ampl_reactive(FP_ZERO), + voltage_cell_active(FP_ZERO), + voltage_cell_reactive(FP_ZERO), + voltage_cell(FP_ZERO), + voltage_cell_relative(FP_ZERO) + {} +};// + +struct AlgorithmStartSinglePhaseFeedback +{ + float current_bypass_active; + float current_bypass_reactive; + // + float current_cell_active; + float current_cell_reactive; + AlgorithmStartSinglePhaseFeedback(): + current_bypass_active(FP_ZERO), + current_bypass_reactive(FP_ZERO), + current_cell_active(FP_ZERO), + current_cell_reactive(FP_ZERO) + {} + +};// + +struct AlgorithmStartSinglePhaseControl +{ + VectorOrthogonalProjection test_ref; + AlgorithmStartSinglePhaseReference reference; + AlgorithmStartSinglePhaseFeedback feedback; + AlgorithmStartSinglePhaseControl(): + test_ref(), + reference(), + feedback() + {} +};// + +struct AlgorithmStartPhaseControl +{ + VectorOrthogonalProjection common_ref; + AlgorithmStartSinglePhaseControl phase_a; + AlgorithmStartSinglePhaseControl phase_b; + AlgorithmStartSinglePhaseControl phase_c; + AlgorithmStartPhaseControl(): + common_ref(), + phase_a(), + phase_b(), + phase_c() + {} +};// + +struct AlgorithmSourceReference +{ + float voltage; + float phase_shift; + AlgorithmSourceReference(): + voltage(FP_ZERO), + phase_shift(FP_ZERO) + {} +};// + +struct EquipmentFaultsBitFieldStructure +{ + uint16_t remote_e_stop : 1; //0 + uint16_t local_e_stop : 1; //1 + uint16_t fan : 1; //2 + uint16_t cells : 1; //3 + // + uint16_t temperature_transformer_multi_winding : 1; //4 + uint16_t temperature_transformer_phase_a : 1; //5 + uint16_t temperature_transformer_phase_b : 1; //6 + uint16_t temperature_transformer_phase_c : 1; //7 + // + uint16_t cabinet_door_open : 1; //8 + uint16_t arc_and_fire : 1; //9 + uint16_t q1 : 1; //10 + uint16_t km1 : 1; //11 + // + uint16_t km2 : 1; //12 + uint16_t km3 : 1; //13 + uint16_t sync_to_grid : 1; //14 + uint16_t reserved_15 : 1; //15 +};//EquipmentFaultsBitFieldStructure + + +union EquipmentFaultsRegister +{ + uint16_t all; + struct Register16BitField bit; + struct EquipmentFaultsBitFieldStructure signal; + EquipmentFaultsRegister(): + all(uint16_t(0)) + {} +};//EquipmentFaultsRegister + + +struct SystemFaultsRegister +{ + union PhaseFaultRegister phase_a; + union PhaseFaultRegister phase_b; + union PhaseFaultRegister phase_c; + union EquipmentFaultsRegister equipment; + SystemFaultsRegister(): + phase_a(), + phase_b(), + phase_c(), + equipment() + {} +};//SystemFaultsBitFieldStructure + + + + +class SystemEnvironment +{ +public: + // + IDSOFTWARE id_software; + // + float time_sample_control; + float time_sample_slow; + float time_sample_additional; + Uint16 time_prescale_slow; + Uint16 time_prescale_additional; + Uint16 time_prescale_symmetrical; + int16 counter_slow; + int16 counter_additional; + int16 counter_symmetrical; + // + SYSCTRL::FlashOperationRegister fram_operation; + SYSCTRL::MonitorDigitalInputSignalRegister fram_burn; + SYSCTRL::MonitorDigitalInputSignalRegister fram_erase; + SYSCTRL::MonitorDigitalInputSignalRegister fram_verify; + SYSCTRL::MonitorDigitalInputSignalRegister fram_read; + SYSCTRL::MonitorDigitalInputSignalRegister fram_restore; + // + AnalogInput analog_input; + // + //Analog Signal Scales + float scale_voltage_grid_a; + float scale_voltage_grid_b; + float scale_voltage_grid_c; + // + float scale_current_input_a; + float scale_current_input_b; + float scale_current_input_c; + // + float scale_current_cell_a; + float scale_current_cell_b; + float scale_current_cell_c; + // + float scale_voltage_load_a; + float scale_voltage_load_b; + float scale_voltage_load_c; + // + float scale_current_load_a; + float scale_current_load_b; + float scale_current_load_c; + // + float scale_current_bypass_a; + float scale_current_bypass_b; + float scale_current_bypass_c; + // + //Analog Signals Offset + float offset_voltage_grid_a; + float offset_voltage_grid_b; + float offset_voltage_grid_c; + // + float offset_current_input_a; + float offset_current_input_b; + float offset_current_input_c; + // + float offset_current_cell_a; + float offset_current_cell_b; + float offset_current_cell_c; + // + float offset_voltage_load_a; + float offset_voltage_load_b; + float offset_voltage_load_c; + // + float offset_current_load_a; + float offset_current_load_b; + float offset_current_load_c; + // + float offset_current_bypass_a; + float offset_current_bypass_b; + float offset_current_bypass_c; + + // + //Analog Signals Offset Static + float offset_voltage_grid_static_a; + float offset_voltage_grid_static_b; + float offset_voltage_grid_static_c; + // + float offset_current_input_static_a; + float offset_current_input_static_b; + float offset_current_input_static_c; + // + float offset_current_cell_static_a; + float offset_current_cell_static_b; + float offset_current_cell_static_c; + // + float offset_voltage_load_static_a; + float offset_voltage_load_static_b; + float offset_voltage_load_static_c; + // + float offset_current_load_static_a; + float offset_current_load_static_b; + float offset_current_load_static_c; + // + float offset_current_bypass_static_a; + float offset_current_bypass_static_b; + float offset_current_bypass_static_c; + + // + // ADC Analog Signals + float adc_voltage_grid_a; + float adc_voltage_grid_b; + float adc_voltage_grid_c; + // + float adc_current_input_a; + float adc_current_input_b; + float adc_current_input_c; + // + float adc_current_cell_a; + float adc_current_cell_b; + float adc_current_cell_c; + // + float adc_voltage_load_a; + float adc_voltage_load_b; + float adc_voltage_load_c; + // + float adc_current_load_a; + float adc_current_load_b; + float adc_current_load_c; + // + float adc_current_bypass_a; + float adc_current_bypass_b; + float adc_current_bypass_c; + + // + // Analog Signals + float voltage_grid_a; + float voltage_grid_b; + float voltage_grid_c; + // + float current_input_a; + float current_input_b; + float current_input_c; + // + float current_cell_a; + float current_cell_b; + float current_cell_c; + // + float voltage_load_a; + float voltage_load_b; + float voltage_load_c; + // + float current_load_a; + float current_load_b; + float current_load_c; + // + float current_bypass_a; + float current_bypass_b; + float current_bypass_c; + // +#if TYPECONTROL == VECTORCONTROL + float voltage_grid_alpha; + float voltage_grid_beta; + // + float voltage_grid_direct; + float voltage_grid_quadrature; + // + float voltage_load_alpha; + float voltage_load_beta; + // + float voltage_load_direct; + float voltage_load_quadrature; + // + float current_load_alpha; + float current_load_beta; + // + float current_load_direct; + float current_load_quadrature; + // + float current_bypass_alpha; + float current_bypass_beta; + // + float current_bypass_direct; + float current_bypass_quadrature; + // + float current_cell_alpha; + float current_cell_beta; + // + float current_cell_direct; + float current_cell_quadrature; + // + float current_reference_limit; + float current_reference_pfc; + // + float voltage_reference_limit_high; + float voltage_reference_load_direct; + float voltage_reference_load_quadrature; + float voltage_reference_dc_cell; + // + float voltage_pi_reg_out_direct; + float voltage_pi_reg_out_quadrature; + // + float voltage_cell_direct; + float voltage_cell_quadrature; + // + float voltage_cell_alpha; + float voltage_cell_beta; + // + float voltage_cell_a; + float voltage_cell_b; + float voltage_cell_c; +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + float drc_voltage_grid_alpha; + float drc_voltage_grid_beta; + // + float drc_voltage_grid_direct; + float drc_voltage_grid_quadrature; + // + float drc_positive_voltage_load_direct; + float drc_positive_voltage_load_quadrature; + float drc_negaative_voltage_load_direct; + float drc_negative_voltage_load_quadrature; + // + float drc_current_load_alpha; + float drc_current_load_beta; + // + float drc_current_load_direct; + float drc_current_load_quadrature; + // + float drc_current_bypass_alpha; + float drc_current_bypass_beta; + // + float drc_current_bypass_direct; + float drc_current_bypass_quadrature; + // + float drc_current_cell_alpha; + float drc_current_cell_beta; + // + float drc_current_cell_direct; + float drc_current_cell_quadrature; + // + float drc_current_reference_limit; + float drc_current_reference_pfc; + // + float drc_voltage_reference_limit_high; + float drc_voltage_reference_load_direct; + float drc_voltage_reference_load_quadrature; + float drc_voltage_reference_zero; + float drc_voltage_reference_dc_cell; + // + float drc_positive_voltage_cell_direct; + float drc_positive_voltage_cell_quadrature; + float drc_negative_voltage_cell_direct; + float drc_negative_voltage_cell_quadrature; + // + float drc_positive_voltage_cell_alpha; + float drc_positive_voltage_cell_beta; + float drc_negative_voltage_cell_alpha; + float drc_negative_voltage_cell_beta; + // + float drc_positive_voltage_cell_a; + float drc_positive_voltage_cell_b; + float drc_positive_voltage_cell_c; + // + float drc_negative_voltage_cell_a; + float drc_negative_voltage_cell_b; + float drc_negative_voltage_cell_c; + // + float drc_voltage_cell_a; + float drc_voltage_cell_b; + float drc_voltage_cell_c; +#endif + + + // + // Reference Vector + float reference_phase_a; + float reference_phase_b; + float reference_phase_c; + // + float reference_phase_alpha; + float reference_phase_betta; + // + float reference_phase_d; + float reference_phase_q; + + //Scale Compute + SYSCTRL::ScaleComputeCommandRegister scale_compute_voltage_command; + SYSCTRL::ScaleComputeCommandRegister scale_compute_current_command; + SYSCTRL::ScaleCompute scale_compute_voltage_input; + SYSCTRL::ScaleCompute scale_compute_voltage_load; + SYSCTRL::ScaleCompute scale_compute_current_input; + SYSCTRL::ScaleCompute scale_compute_current_cell; + SYSCTRL::ScaleCompute scale_compute_current_load; + SYSCTRL::ScaleCompute scale_compute_current_bypass; + + // + SYSCTRL::ProjectionAnalogSignalStructure spinner_phase_a; + SYSCTRL::ProjectionAnalogSignalStructure spinner_phase_b; + SYSCTRL::ProjectionAnalogSignalStructure spinner_phase_c; + // + SYSCTRL::VecorModuleStructure module_voltage_phase_a; + SYSCTRL::VecorModuleStructure module_voltage_phase_b; + SYSCTRL::VecorModuleStructure module_voltage_phase_c; + // + + //Signal Decompose + SYSCTRL::RelativeAnalogSignalStructure relative_voltage_input_a; + SYSCTRL::RelativeAnalogSignalStructure relative_voltage_input_b; + SYSCTRL::RelativeAnalogSignalStructure relative_voltage_input_c; + // + SYSCTRL::ProjectionAnalogSignalStructure projection_voltage_input_a; + SYSCTRL::ProjectionAnalogSignalStructure projection_voltage_input_b; + SYSCTRL::ProjectionAnalogSignalStructure projection_voltage_input_c; + // + SYSCTRL::ProjectionAnalogSignalStructure projection_voltage_load_a; + SYSCTRL::ProjectionAnalogSignalStructure projection_voltage_load_b; + SYSCTRL::ProjectionAnalogSignalStructure projection_voltage_load_c; + // + SYSCTRL::ProjectionAnalogSignalStructure projection_current_load_a; + SYSCTRL::ProjectionAnalogSignalStructure projection_current_load_b; + SYSCTRL::ProjectionAnalogSignalStructure projection_current_load_c; + // + SYSCTRL::ProjectionAnalogSignalStructure projection_current_cell_a; + SYSCTRL::ProjectionAnalogSignalStructure projection_current_cell_b; + SYSCTRL::ProjectionAnalogSignalStructure projection_current_cell_c; + // + SYSCTRL::ProjectionAnalogSignalStructure projection_current_bypass_a; + SYSCTRL::ProjectionAnalogSignalStructure projection_current_bypass_b; + SYSCTRL::ProjectionAnalogSignalStructure projection_current_bypass_c; + +// SYSCTRL::ProjectionAnalogSignalStructure test_projection_a; +// SYSCTRL::ProjectionAnalogSignalStructure test_projection_b; +// SYSCTRL::ProjectionAnalogSignalStructure test_projection_c; + // + //Symmetrical Components + SYSCTRL::SymmetricalComponentsStructure symmetrical_components_voltage_input; + SYSCTRL::SymmetricalComponentsStructure symmetrical_components_voltage_load; + SYSCTRL::SymmetricalComponentsStructure symmetrical_components_current_load; + SYSCTRL::SymmetricalComponentsStructure symmetrical_components_current_bypass; + + //RMS value of Analog Signals + float rms_voltage_input_ab; + float rms_voltage_input_bc; + float rms_voltage_input_ca; + float rms_voltage_input_module; + // + float rms_voltage_load_ab; + float rms_voltage_load_bc; + float rms_voltage_load_ca; + float rms_voltage_load_module; + // + float rms_current_input_a; + float rms_current_input_b; + float rms_current_input_c; + float rms_current_input_module; + // + float rms_current_load_a; + float rms_current_load_b; + float rms_current_load_c; + float rms_current_load_module; + // + float rms_current_bypass_a; + float rms_current_bypass_b; + float rms_current_bypass_c; + float rms_current_bypass_module; + // + float rms_current_cell_a; + float rms_current_cell_b; + float rms_current_cell_c; + // + + //High Voltage Cells + SYSCTRL::HardWare hardware; + float cell_dc_voltage_a; + float cell_dc_voltage_b; + float cell_dc_voltage_c; + float cell_dc_voltage_a_average; + float cell_dc_voltage_b_average; + float cell_dc_voltage_c_average; + float cell_dc_voltage_a_reciprocal; + float cell_dc_voltage_b_reciprocal; + float cell_dc_voltage_c_reciprocal; + // + + //System State + SYSCTRL::BoolRegister system_alarm; + SYSCTRL::BoolRegister system_fault; + SYSCTRL::BoolRegister system_reset; + SYSCTRL::BoolRegister system_ready; + SYSCTRL::BoolRegister short_circuit; + SYSCTRL::BoolRegister enable_work; + SYSCTRL::BoolRegister enable_work_previous; + SYSCTRL::BoolRegister enable_work_is_on; + SYSCTRL::BoolRegister enable_work_is_off; + SYSCTRL::BoolRegister enable_work_reset; + SYSCTRL::SystemFaultsRegister system_faults_register; + + + //External Command + SYSCTRL::ExternalCommandWordRegister external_command_word; + SYSCTRL::MonitorDigitalInputSignalRegister external_start; + SYSCTRL::MonitorDigitalInputSignalRegister external_stop; + SYSCTRL::MonitorDigitalInputSignalRegister external_reset; + SYSCTRL::MonitorDigitalInputSignalRegister external_e_stop; + SYSCTRL::MonitorDigitalInputSignalRegister external_km1_on; + SYSCTRL::MonitorDigitalInputSignalRegister external_km1_off; + SYSCTRL::MonitorDigitalInputSignalRegister external_km3_on; + SYSCTRL::MonitorDigitalInputSignalRegister external_km3_off; + SYSCTRL::MonitorDigitalInputSignalRegister external_q1_on; + SYSCTRL::MonitorDigitalInputSignalRegister external_q1_off; + + // + // PLL + float grid_frequency; + bool status_pll_sync; + // + + //Generator Orts // FOR DEBUG + float gen_ort_a; + float gen_ort_b; + float gen_ort_c; + float gen_ort_alpha; + float gen_ort_beta; + + //System Orts + SystemABCOrts pll_abc_orts; + SystemABCOrts twisted_abc_orts; + SystemABCOrts main_abc_orts; + SystemABCOrts main_abc_reverse_orts; + VectorOrthogonalProjection main_ab_orts; + // + VectorOrthogonalProjection harmonica_2; + VectorOrthogonalProjection harmonica_3; + VectorOrthogonalProjection harmonica_5; + VectorOrthogonalProjection harmonica_7; + VectorOrthogonalProjection harmonica_9; + VectorOrthogonalProjection harmonica_11; + + // Algorithm Control + SYSCTRL::AlgorithmControlRegister algorithm_control; + SYSCTRL::MonitorDigitalInputSignalRegister enable_current_limit; + SYSCTRL::MonitorDigitalInputSignalRegister enable_pfc; + SYSCTRL::MonitorDigitalInputSignalRegister enable_harmonica; + SYSCTRL::MonitorDigitalInputSignalRegister enable_auto_offset; + bool allow_auto_offset; + + // AlgorithmPhaseControl +#if TYPECONTROL == SCALARCONTROL + AlgorithmPhaseControl phase_control; + AlgorithmStartPhaseControl start_control; +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + +#endif + + + + //AlgorithmSource + AlgorithmSourceReference algorithm_source_references; + + // Harmonica Analyzer + FLTSYSLIB::HarmonicaStructure voltage_input_a_harmonica_5; + FLTSYSLIB::HarmonicaStructure voltage_input_b_harmonica_5; + FLTSYSLIB::HarmonicaStructure voltage_input_c_harmonica_5; + + // Framework data + OutputDiscteteSignalsRegister digital_output_inverse; + OutputDiscteteSignalsRegister digital_output; + //OutputDiscteteSignalsRegister digital_output_debug_only; + OutputDiscteteSignalsRegister digital_output_temp; + //DigitalOuput digital_output_inverse; + //DigitalOuput digital_output; + //DigitalOuput digital_output_temp; + DigitalInput digital_input; + + + // Phase Alert Monitor + SYSCTRL::PhaseAlertRegister phase_alert_monitor_register; + + //Fan Control + SYSCTRL::FanTimerControl fan_control; + // + + // DIGITAL INPUTS + FLTSYSLIB::DigitalInputAntiNoise remote_start; //3001 + FLTSYSLIB::DigitalInputAntiNoise remote_stop; //3002 + FLTSYSLIB::DigitalInputAntiNoise remote_reset; //3003 + FLTSYSLIB::DigitalInputAntiNoise remote_e_stop; //3004 + FLTSYSLIB::DigitalInputAntiNoise auxiliary_q1; //3005 + FLTSYSLIB::DigitalInputAntiNoise bypass_ready; //3006 + FLTSYSLIB::DigitalInputAntiNoise transformer_inv_over_temperature_alarm; //3007 + FLTSYSLIB::DigitalInputAntiNoise local_e_stop; //3008 + FLTSYSLIB::DigitalInputAntiNoise cabinet_door_interlocked; //3009 + FLTSYSLIB::DigitalInputAntiNoise arc_and_fire; //3010 + FLTSYSLIB::DigitalInputAntiNoise hw_dvr_ready; //3011 + FLTSYSLIB::DigitalInputAntiNoise auxiliary_km2; //3012 + FLTSYSLIB::DigitalInputAntiNoise auxiliary_km11; //3013 + FLTSYSLIB::DigitalInputAntiNoise transformer_t_over_temperature_fault;//3014 + FLTSYSLIB::DigitalInputAntiNoise control_power_supply_status; //3015 + FLTSYSLIB::DigitalInputAntiNoise auxiliary_km1; //3016 + FLTSYSLIB::DigitalInputAntiNoise auxiliary_km3; //3017 + FLTSYSLIB::DigitalInputAntiNoise transformer_inv_over_temperature_fault; //3018 + FLTSYSLIB::DigitalInputAntiNoise fan_fault; //3019 + FLTSYSLIB::DigitalInputAntiNoise local_remote; //3020 off-local/on-remote + + + + SYSCTRL::InputDiscreteSignals input_discrete; + DigitalInput digital_input_debug; + //SYSCTRL::InputDiscreteSignals input_discrete_debug_only; + // + + // ABC-Generator + FLTSYSLIB::GeneratorABC generator_abc; + //SYSCTRL::GeneratorSymmetricalComponents gen_symm_comp_inp_volt; + //SYSCTRL::GeneratorSymmetricalComponents gen_symm_comp_out_volt; + //SYSCTRL::GeneratorSymmetricalComponents gen_symm_comp_out_current; + //SYSCTRL::GeneratorSymmetricalComponents gen_symm_comp_input_current; + //SYSCTRL::GeneratorSymmetricalComponents gen_symm_comp_bypass_current; + //SYSCTRL::GeneratorSymmetricalComponents gen_symm_comp_cell_current; + // Reference PWM-Generator + //float amplitude_generator_pwm; + //FLTSYSLIB::GeneratorABC generator_pwm; + + + //Phase Voltage Regulators - Normal & Stop Algorithms + // + // + + +#if TYPECONTROL == VECTORCONTROL + // + FLTSYSLIB::PIController regulator_voltage_load_direct; + FLTSYSLIB::PIController regulator_voltage_load_quadrature; + // + FLTSYSLIB::Integrator integrator_direct; + FLTSYSLIB::Integrator integrator_quadrature; + // + FLTSYSLIB::Filter reference_voltage_direct_intensity; + // +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_PI + FLTSYSLIB::PIController regulator_current_load_direct; + FLTSYSLIB::PIController regulator_current_load_quadrature; +#endif +#if TYPECURRENTCONTROLLER == CURRENTCONTROLLER_P + FLTSYSLIB::PController regulator_current_load_direct; + FLTSYSLIB::PController regulator_current_load_quadrature; +#endif + + // + FLTSYSLIB::IController referencer_current_bypass_direct; + FLTSYSLIB::IController referencer_current_bypass_quadrature; + // + FLTSYSLIB::IController regulator_current_limit; + FLTSYSLIB::PIController regulator_current_pfc; + // +#endif + + +#if TYPECONTROL == SCALARCONTROL + // + FLTSYSLIB::PIController regulator_voltage_load_a_active; + FLTSYSLIB::PIController regulator_voltage_load_a_reactive; + // + FLTSYSLIB::PIController regulator_voltage_load_b_active; + FLTSYSLIB::PIController regulator_voltage_load_b_reactive; + // + FLTSYSLIB::PIController regulator_voltage_load_c_active; + FLTSYSLIB::PIController regulator_voltage_load_c_reactive; + // + //Load Current Regulators + FLTSYSLIB::PIController regulator_current_limit_a; + FLTSYSLIB::PIController regulator_current_pfc_a; + // + FLTSYSLIB::PIController regulator_current_limit_b; + FLTSYSLIB::PIController regulator_current_pfc_b; + // + FLTSYSLIB::PIController regulator_current_limit_c; + FLTSYSLIB::PIController regulator_current_pfc_c; + // + //Current Regulators - Start Algorithm + FLTSYSLIB::PIController current_regulator_a_active; + FLTSYSLIB::PIController current_regulator_a_reactive; + // + FLTSYSLIB::PIController current_regulator_b_active; + FLTSYSLIB::PIController current_regulator_b_reactive; + // + FLTSYSLIB::PIController current_regulator_c_active; + FLTSYSLIB::PIController current_regulator_c_reactive; + // + //Current Referencer - Start Algorithm + FLTSYSLIB::PIController current_referencer_a_active; + FLTSYSLIB::PIController current_referencer_a_reactive; + // + FLTSYSLIB::PIController current_referencer_b_active; + FLTSYSLIB::PIController current_referencer_b_reactive; + // + FLTSYSLIB::PIController current_referencer_c_active; + FLTSYSLIB::PIController current_referencer_c_reactive; + // + //POWER CELL DC Voltage Regulator + FLTSYSLIB::PIController regulator_dc_a; + FLTSYSLIB::PIController regulator_dc_b; + FLTSYSLIB::PIController regulator_dc_c; + // +#endif + + +#if TYPECONTROL == DIRECTREVERSECONTROL + // + FLTSYSLIB::PIController drc_positive_voltage_controller_direct; + FLTSYSLIB::PIController drc_positive_voltage_controller_quadrature; + FLTSYSLIB::PIController drc_negative_voltage_controller_direct; + FLTSYSLIB::PIController drc_negative_voltage_controller_quadrature; + // + FLTSYSLIB::FilterSecond drc_reference_voltage_direct_intensity; + // + FLTSYSLIB::PIController drc_regulator_current_load_direct; + FLTSYSLIB::PIController drc_regulator_current_load_quadrature; + // + FLTSYSLIB::IController drc_referencer_current_bypass_direct; + FLTSYSLIB::IController drc_referencer_current_bypass_quadrature; + // + FLTSYSLIB::IController drc_regulator_current_limit; + FLTSYSLIB::PIController drc_regulator_current_pfc; + // + SYSCTRL::DRCDecomposer drc_direct_voltage_decomposer; + SYSCTRL::DRCDecomposer drc_back_voltage_decomposer; +#endif + + // + // Timers + FLTSYSLIB::FTimer timer_start; + FLTSYSLIB::FTimer timer_stop; + // +public: + SystemEnvironment(); + // +};//SystemEnvironment + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_SYSTEMENVIRONMENT_H_ */ + + diff --git a/SYSCTRL/TriggerBase.cpp b/SYSCTRL/TriggerBase.cpp new file mode 100644 index 0000000..ba083c6 --- /dev/null +++ b/SYSCTRL/TriggerBase.cpp @@ -0,0 +1,17 @@ +/* + * TriggerBase.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/TriggerBase.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +TriggerBase::TriggerBase(): + m_trigger() +{}//CONSTRUCTOR + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/TriggerBase.h b/SYSCTRL/TriggerBase.h new file mode 100644 index 0000000..ab380aa --- /dev/null +++ b/SYSCTRL/TriggerBase.h @@ -0,0 +1,60 @@ +/* + * TriggerBase.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_TRIGGERBASE_H_ +#define SYSCTRL_TRIGGERBASE_H_ + +namespace SYSCTRL +{ + + + +struct TriggerBaseBitField +{ + uint16_t out:1; + uint16_t out_shadow:1; + uint16_t out_privious:1; + uint16_t set:1; + uint16_t reset:1; + uint16_t positive:1; + uint16_t negative:1; +};//TriggerBaseBitField + +union TriggerBaseRegister +{ + uint16_t all; + TriggerBaseBitField bit; + TriggerBaseRegister(): + all(0) + {} +};//TriggerBaseRegister + + +class TriggerBase +{ +protected: + TriggerBaseRegister m_trigger; +public: + TriggerBase(); +public: + virtual void setSET(bool set) = 0; + virtual void setRESET(bool reset) = 0; + virtual void execute() = 0; + virtual void clear() = 0; + virtual bool getOUT() = 0; + virtual bool getPOSITIVE() = 0; + virtual bool getNEGATIVE() = 0; + virtual bool isPOSITIVE() = 0; + virtual bool isNEGATIVE() = 0; +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_TRIGGERBASE_H_ */ diff --git a/SYSCTRL/TriggerFault.cpp b/SYSCTRL/TriggerFault.cpp new file mode 100644 index 0000000..4800d76 --- /dev/null +++ b/SYSCTRL/TriggerFault.cpp @@ -0,0 +1,87 @@ +/* + * TriggerFault.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/TriggerFault.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +TriggerFault::TriggerFault(): + SYSCTRL::TriggerBase() +{}//CONSTRUCTOR + +#pragma CODE_SECTION("ramfuncs"); +void TriggerFault::setSET(bool set) +{ + m_trigger.bit.set = set; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerFault::setRESET(bool reset) +{ + m_trigger.bit.reset = reset; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerFault::execute() +{ + // Q(i) = S | (nR & Q(i-1)) + // + m_trigger.bit.out_privious = m_trigger.bit.out; + m_trigger.bit.out_shadow = m_trigger.bit.set | (!m_trigger.bit.reset & m_trigger.bit.out_privious); + m_trigger.bit.out = m_trigger.bit.out_shadow; + m_trigger.bit.positive = !m_trigger.bit.out_privious & m_trigger.bit.out; + m_trigger.bit.negative = m_trigger.bit.out_privious & !m_trigger.bit.out; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerFault::clear() +{ + m_trigger.all = 0; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerFault::getOUT() +{ + return m_trigger.bit.out; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerFault::getPOSITIVE() +{ + return m_trigger.bit.positive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerFault::getNEGATIVE() +{ + return m_trigger.bit.negative; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerFault::isPOSITIVE() +{ + return m_trigger.bit.positive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerFault::isNEGATIVE() +{ + return m_trigger.bit.negative; + // +}// +// + +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/TriggerFault.h b/SYSCTRL/TriggerFault.h new file mode 100644 index 0000000..cd33c4b --- /dev/null +++ b/SYSCTRL/TriggerFault.h @@ -0,0 +1,36 @@ +/* + * TriggerFault.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_TRIGGERFAULT_H_ +#define SYSCTRL_TRIGGERFAULT_H_ + +#include "SYSCTRL/TriggerBase.h" + +namespace SYSCTRL +{ + +class TriggerFault: public TriggerBase +{ +public: + TriggerFault(); + void setSET(bool set); + void setRESET(bool reset); + void execute(); + void clear(); + bool getOUT(); + bool getPOSITIVE(); + bool getNEGATIVE(); + bool isPOSITIVE(); + bool isNEGATIVE(); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_TRIGGERFAULT_H_ */ diff --git a/SYSCTRL/TriggerRS.cpp b/SYSCTRL/TriggerRS.cpp new file mode 100644 index 0000000..a03fc67 --- /dev/null +++ b/SYSCTRL/TriggerRS.cpp @@ -0,0 +1,87 @@ +/* + * TriggerRS.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/TriggerRS.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +TriggerRS::TriggerRS(): + SYSCTRL::TriggerBase() +// +{}//CONSTRUCTOR + +#pragma CODE_SECTION("ramfuncs"); +void TriggerRS::setSET(bool set) +{ + m_trigger.bit.set = set; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRS::setRESET(bool reset) +{ + m_trigger.bit.reset = reset; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRS::execute() +{ + // Q(i) = (nR & (S | Q(i-1))) | (S & Q(i-1)) + // + m_trigger.bit.out_privious = m_trigger.bit.out; + m_trigger.bit.out_shadow = (!m_trigger.bit.reset & (m_trigger.bit.set | m_trigger.bit.out_privious)) | (m_trigger.bit.set & m_trigger.bit.out_privious); + m_trigger.bit.out = m_trigger.bit.out_shadow; + m_trigger.bit.positive = !m_trigger.bit.out_privious & m_trigger.bit.out; + m_trigger.bit.negative = m_trigger.bit.out_privious & !m_trigger.bit.out; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRS::clear() +{ + m_trigger.all = 0; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerRS::getOUT() +{ + return m_trigger.bit.out; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerRS::getPOSITIVE() +{ + return m_trigger.bit.positive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerRS::getNEGATIVE() +{ + return m_trigger.bit.negative; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerRS::isPOSITIVE() +{ + return m_trigger.bit.positive; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +bool TriggerRS::isNEGATIVE() +{ + return m_trigger.bit.negative; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/TriggerRS.h b/SYSCTRL/TriggerRS.h new file mode 100644 index 0000000..a68d7a8 --- /dev/null +++ b/SYSCTRL/TriggerRS.h @@ -0,0 +1,36 @@ +/* + * TriggerRS.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#ifndef SYSCTRL_TRIGGERRS_H_ +#define SYSCTRL_TRIGGERRS_H_ + +#include "SYSCTRL/TriggerBase.h" + +namespace SYSCTRL +{ + +class TriggerRS: public TriggerBase +{ +public: + TriggerRS(); + void setSET(bool set); + void setRESET(bool reset); + void execute(); + void clear(); + bool getOUT(); + bool getPOSITIVE(); + bool getNEGATIVE(); + bool isPOSITIVE(); + bool isNEGATIVE(); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_TRIGGERRS_H_ */ diff --git a/SYSCTRL/TriggerRegister.cpp b/SYSCTRL/TriggerRegister.cpp new file mode 100644 index 0000000..3e682fd --- /dev/null +++ b/SYSCTRL/TriggerRegister.cpp @@ -0,0 +1,91 @@ +/* + * TriggerRegisterBase.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/TriggerRegister.h" + +namespace SYSCTRL +{ + +TriggerRegister::TriggerRegister() +{} +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::clear(TriggerRegisterStructure& trigger) +{ + trigger.all = 0x0028; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::set(TriggerRegisterStructure& trigger) +{ + trigger.all = 0x0014; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::execute_set_priority(TriggerRegisterStructure& trigger) +{ + // Q(i) = S | (nR & Q(i-1)) + // + trigger.signal.quit_privious = trigger.signal.quit; + trigger.signal.quit = trigger.signal.set | ((!trigger.signal.reset) & trigger.signal.quit_privious); + SYSCTRL::TriggerRegister::_signal_constructor(trigger); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::execute_reset_priority(TriggerRegisterStructure& trigger) +{ + // Q(i) = nR & (S | Q(i-1)) + // + trigger.signal.quit_privious = trigger.signal.quit; + trigger.signal.quit = (!trigger.signal.reset) & (trigger.signal.set | trigger.signal.quit_privious); + SYSCTRL::TriggerRegister::_signal_constructor(trigger); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::execute_rs(TriggerRegisterStructure& trigger) +{ + // Q(i) = (nR & (S | Q(i-1))) | (S & Q(i-1)) + // + trigger.signal.quit_privious = trigger.signal.quit; + trigger.signal.quit = ((!trigger.signal.reset) & (trigger.signal.set | trigger.signal.quit_privious)) | + (trigger.signal.set & trigger.signal.quit_privious); + SYSCTRL::TriggerRegister::_signal_constructor(trigger); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::setSet(TriggerRegisterStructure& trigger, bool ref) +{ + trigger.signal.set = ref; + trigger.signal.is_on = ref; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void TriggerRegister::setReset(TriggerRegisterStructure& trigger, bool ref) +{ + trigger.signal.reset = ref; + trigger.signal.is_off = ref; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void TriggerRegister::_signal_constructor(TriggerRegisterStructure& trigger) +{ + trigger.signal.is_on = trigger.signal.quit; + trigger.signal.negquit = !trigger.signal.quit; + trigger.signal.is_off = !trigger.signal.quit; + trigger.signal.is_switched_on = trigger.signal.quit & (!trigger.signal.quit_privious); + trigger.signal.is_switched_off = (!trigger.signal.quit) & trigger.signal.quit_privious; + // +}// +// +} /* namespace SYSCTRL */ + diff --git a/SYSCTRL/TriggerRegister.h b/SYSCTRL/TriggerRegister.h new file mode 100644 index 0000000..2f13708 --- /dev/null +++ b/SYSCTRL/TriggerRegister.h @@ -0,0 +1,67 @@ +/* + * TriggerRegister.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/SystemDefinitions.h" + +#ifndef SYSCTRL_TRIGGERREGISTER_H_ +#define SYSCTRL_TRIGGERREGISTER_H_ + + +namespace SYSCTRL +{ + + +struct TriggerRegisterSignalBitFiled +{ + uint16_t set:1; + uint16_t reset:1; + uint16_t quit:1; + uint16_t negquit:1; + uint16_t is_on:1; + uint16_t is_off:1; + uint16_t is_switched_on:1; + uint16_t is_switched_off:1; + uint16_t quit_privious:1; + // +};// + +union TriggerRegisterStructure +{ + uint16_t all; + Register16BitField bit; + TriggerRegisterSignalBitFiled signal; + TriggerRegisterStructure(): + all(uint16_t(0x28)) + {} + TriggerRegisterStructure(uint16_t val): + all(val) + {} +};//TriggerRegisterUnion + + + +class TriggerRegister +{ +public: + TriggerRegister(); + static void clear(TriggerRegisterStructure& trigger); + static void set(TriggerRegisterStructure& trigger); + static void execute_set_priority(TriggerRegisterStructure& trigger); + static void execute_reset_priority(TriggerRegisterStructure& trigger); + static void execute_rs(TriggerRegisterStructure& trigger); + static void setSet(TriggerRegisterStructure& trigger, bool ref); + static void setReset(TriggerRegisterStructure& trigger, bool ref); +private: + static inline void _signal_constructor(TriggerRegisterStructure& trigger); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_TRIGGERREGISTER_H_ */ diff --git a/SYSCTRL/TypeControl.h b/SYSCTRL/TypeControl.h new file mode 100644 index 0000000..df50db7 --- /dev/null +++ b/SYSCTRL/TypeControl.h @@ -0,0 +1,45 @@ +/* + * TypeControl.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#ifndef SYSCTRL_TYPECONTROL_H_ +#define SYSCTRL_TYPECONTROL_H_ + + +#ifndef VECTORCONTROL +#define VECTORCONTROL 1 +#endif + +#ifndef SCALARCONTROL +#define SCALARCONTROL 2 +#endif + +#ifndef DIRECTREVERSECONTROL +#define DIRECTREVERSECONTROL 3 +#endif + +#ifndef TYPECONTROL +//#define TYPECONTROL VECTORCONTROL +//#define TYPECONTROL SCALARCONTROL +#define TYPECONTROL DIRECTREVERSECONTROL +#endif + + +#define CURRENTCONTROLLER_PI 1 +#define CURRENTCONTROLLER_P 2 + +#define TYPECURRENTCONTROLLER CURRENTCONTROLLER_PI +//#define TYPECURRENTCONTROLLER CURRENTCONTROLLER_P + + +#define VOLTAGE_CONTROLLER_I 1 +#define VOLTAGE_CONTROLLER_PII 2 +#define TYPE_VOLTAGE_CONTROLLER VOLTAGE_CONTROLLER_I +//#define TYPE_VOLTAGE_CONTROLLER VOLTAGE_CONTROLLER_PII + + + +#endif /* SYSCTRL_TYPECONTROL_H_ */ diff --git a/SYSCTRL/VectorSpinner.cpp b/SYSCTRL/VectorSpinner.cpp new file mode 100644 index 0000000..8fec544 --- /dev/null +++ b/SYSCTRL/VectorSpinner.cpp @@ -0,0 +1,54 @@ +/* + * VectorSpinner.cpp + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include "SYSCTRL/VectorSpinner.h" + +namespace SYSCTRL +{ +//CONSTRUCTOR +VectorSpinner::VectorSpinner() +{}//CONSTRUCTOR +// +#pragma CODE_SECTION("ramfuncs"); +void VectorSpinner::spin_calculator(SYSCTRL::ProjectionAnalogSignalStructure& projection, SYSCTRL::VecorModuleStructure& module, SYSCTRL::ProjectionAnalogSignalStructure& spinner) +{ + module.module = sqrtf(projection.active * projection.active + projection.reactive * projection.reactive); + if(module.module > FP_ZERO) + { + module.reciprocal = 1.0/module.module; + // + spinner.active = module.reciprocal * projection.active; + spinner.reactive = -module.reciprocal * projection.reactive; + // + } + else + { + spinner.active = 1.0; + spinner.reactive = FP_ZERO; + // + };//if else + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void VectorSpinner::spin_reset(SYSCTRL::ProjectionAnalogSignalStructure& spinner) +{ + spinner.active = 1.0; + spinner.reactive = FP_ZERO; + // +}// +// + +#pragma CODE_SECTION("ramfuncs"); +void VectorSpinner::ort_corrector(SYSCTRL::ProjectionAnalogSignalStructure& spinner, SYSCTRL::VectorOrthogonalProjection& ort, SYSCTRL::VectorOrthogonalProjection& twisted) +{ + twisted.active = spinner.active * ort.active + spinner.reactive * ort.reactive; + twisted.reactive = -spinner.reactive * ort.active + spinner.active * ort.reactive; + // +}// +// +} /* namespace SYSCTRL */ diff --git a/SYSCTRL/VectorSpinner.h b/SYSCTRL/VectorSpinner.h new file mode 100644 index 0000000..e5f6e6c --- /dev/null +++ b/SYSCTRL/VectorSpinner.h @@ -0,0 +1,31 @@ +/* + * VectorSpinner.h + * + * Author: Aleksey Gerasimenko + * gerasimenko.aleksey.n@gmail.com + */ + +#include +#include + +#include "SYSCTRL/SystemEnvironment.h" + +#ifndef SYSCTRL_VECTORSPINNER_H_ +#define SYSCTRL_VECTORSPINNER_H_ + +namespace SYSCTRL +{ + + +class VectorSpinner +{ +public: + VectorSpinner(); + static void spin_calculator(SYSCTRL::ProjectionAnalogSignalStructure& projection, SYSCTRL::VecorModuleStructure& module, SYSCTRL::ProjectionAnalogSignalStructure& spinner); + static void spin_reset(SYSCTRL::ProjectionAnalogSignalStructure& spinner); + static void ort_corrector(SYSCTRL::ProjectionAnalogSignalStructure& spinner, SYSCTRL::VectorOrthogonalProjection& ort, SYSCTRL::VectorOrthogonalProjection& twisted); +}; + +} /* namespace SYSCTRL */ + +#endif /* SYSCTRL_VECTORSPINNER_H_ */ diff --git a/cmd/DSP2833x_Headers_nonBIOS.cmd b/cmd/DSP2833x_Headers_nonBIOS.cmd new file mode 100644 index 0000000..9da1026 --- /dev/null +++ b/cmd/DSP2833x_Headers_nonBIOS.cmd @@ -0,0 +1,183 @@ +/* +// TI File $Revision: /main/8 $ +// Checkin $Date: June 2, 2008 11:12:24 $ +//########################################################################### +// +// FILE: DSP2833x_Headers_nonBIOS.cmd +// +// TITLE: DSP2833x Peripheral registers linker command file +// +// DESCRIPTION: +// +// This file is for use in Non-BIOS applications. +// +// Linker command file to place the peripheral structures +// used within the DSP2833x headerfiles into the correct memory +// mapped locations. +// +// This version of the file includes the PieVectorTable structure. +// For BIOS applications, please use the DSP2833x_Headers_BIOS.cmd file +// which does not include the PieVectorTable structure. +// +//########################################################################### +// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $ +// $Release Date: August 1, 2008 $ +//########################################################################### +*/ + +MEMORY +{ + PAGE 0: /* Program Memory */ + + PAGE 1: /* Data Memory */ + + DEV_EMU : origin = 0x000880, length = 0x000180 /* device emulation registers */ + FLASH_REGS : origin = 0x000A80, length = 0x000060 /* FLASH registers */ + CSM : origin = 0x000AE0, length = 0x000010 /* code security module registers */ + + ADC_MIRROR : origin = 0x000B00, length = 0x000010 /* ADC Results register mirror */ + + XINTF : origin = 0x000B20, length = 0x000020 /* external interface registers */ + + CPU_TIMER0 : origin = 0x000C00, length = 0x000008 /* CPU Timer0 registers */ + CPU_TIMER1 : origin = 0x000C08, length = 0x000008 /* CPU Timer0 registers (CPU Timer1 & Timer2 reserved TI use)*/ + CPU_TIMER2 : origin = 0x000C10, length = 0x000008 /* CPU Timer0 registers (CPU Timer1 & Timer2 reserved TI use)*/ + + PIE_CTRL : origin = 0x000CE0, length = 0x000020 /* PIE control registers */ + PIE_VECT : origin = 0x000D00, length = 0x000100 /* PIE Vector Table */ + + DMA : origin = 0x001000, length = 0x000200 /* DMA registers */ + + MCBSPA : origin = 0x005000, length = 0x000040 /* McBSP-A registers */ + MCBSPB : origin = 0x005040, length = 0x000040 /* McBSP-B registers */ + + ECANA : origin = 0x006000, length = 0x000040 /* eCAN-A control and status registers */ + ECANA_LAM : origin = 0x006040, length = 0x000040 /* eCAN-A local acceptance masks */ + ECANA_MOTS : origin = 0x006080, length = 0x000040 /* eCAN-A message object time stamps */ + ECANA_MOTO : origin = 0x0060C0, length = 0x000040 /* eCAN-A object time-out registers */ + ECANA_MBOX : origin = 0x006100, length = 0x000100 /* eCAN-A mailboxes */ + + ECANB : origin = 0x006200, length = 0x000040 /* eCAN-B control and status registers */ + ECANB_LAM : origin = 0x006240, length = 0x000040 /* eCAN-B local acceptance masks */ + ECANB_MOTS : origin = 0x006280, length = 0x000040 /* eCAN-B message object time stamps */ + ECANB_MOTO : origin = 0x0062C0, length = 0x000040 /* eCAN-B object time-out registers */ + ECANB_MBOX : origin = 0x006300, length = 0x000100 /* eCAN-B mailboxes */ + + EPWM1 : origin = 0x006800, length = 0x000022 /* Enhanced PWM 1 registers */ + EPWM2 : origin = 0x006840, length = 0x000022 /* Enhanced PWM 2 registers */ + EPWM3 : origin = 0x006880, length = 0x000022 /* Enhanced PWM 3 registers */ + EPWM4 : origin = 0x0068C0, length = 0x000022 /* Enhanced PWM 4 registers */ + EPWM5 : origin = 0x006900, length = 0x000022 /* Enhanced PWM 5 registers */ + EPWM6 : origin = 0x006940, length = 0x000022 /* Enhanced PWM 6 registers */ + + ECAP1 : origin = 0x006A00, length = 0x000020 /* Enhanced Capture 1 registers */ + ECAP2 : origin = 0x006A20, length = 0x000020 /* Enhanced Capture 2 registers */ + ECAP3 : origin = 0x006A40, length = 0x000020 /* Enhanced Capture 3 registers */ + ECAP4 : origin = 0x006A60, length = 0x000020 /* Enhanced Capture 4 registers */ + ECAP5 : origin = 0x006A80, length = 0x000020 /* Enhanced Capture 5 registers */ + ECAP6 : origin = 0x006AA0, length = 0x000020 /* Enhanced Capture 6 registers */ + + EQEP1 : origin = 0x006B00, length = 0x000040 /* Enhanced QEP 1 registers */ + EQEP2 : origin = 0x006B40, length = 0x000040 /* Enhanced QEP 2 registers */ + + GPIOCTRL : origin = 0x006F80, length = 0x000040 /* GPIO control registers */ + GPIODAT : origin = 0x006FC0, length = 0x000020 /* GPIO data registers */ + GPIOINT : origin = 0x006FE0, length = 0x000020 /* GPIO interrupt/LPM registers */ + + SYSTEM : origin = 0x007010, length = 0x000020 /* System control registers */ + SPIA : origin = 0x007040, length = 0x000010 /* SPI-A registers */ + SCIA : origin = 0x007050, length = 0x000010 /* SCI-A registers */ + XINTRUPT : origin = 0x007070, length = 0x000010 /* external interrupt registers */ + + ADC : origin = 0x007100, length = 0x000020 /* ADC registers */ + + SCIB : origin = 0x007750, length = 0x000010 /* SCI-B registers */ + + SCIC : origin = 0x007770, length = 0x000010 /* SCI-C registers */ + + I2CA : origin = 0x007900, length = 0x000040 /* I2C-A registers */ + + CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations. */ + + PARTID : origin = 0x380090, length = 0x000001 /* Part ID register location */ +} + + +SECTIONS +{ + PieVectTableFile : > PIE_VECT, PAGE = 1 + +/*** Peripheral Frame 0 Register Structures ***/ + DevEmuRegsFile : > DEV_EMU, PAGE = 1 + FlashRegsFile : > FLASH_REGS, PAGE = 1 + CsmRegsFile : > CSM, PAGE = 1 + AdcMirrorFile : > ADC_MIRROR, PAGE = 1 + XintfRegsFile : > XINTF, PAGE = 1 + CpuTimer0RegsFile : > CPU_TIMER0, PAGE = 1 + CpuTimer1RegsFile : > CPU_TIMER1, PAGE = 1 + CpuTimer2RegsFile : > CPU_TIMER2, PAGE = 1 + PieCtrlRegsFile : > PIE_CTRL, PAGE = 1 + DmaRegsFile : > DMA, PAGE = 1 + +/*** Peripheral Frame 3 Register Structures ***/ + McbspaRegsFile : > MCBSPA, PAGE = 1 + McbspbRegsFile : > MCBSPB, PAGE = 1 + +/*** Peripheral Frame 1 Register Structures ***/ + ECanaRegsFile : > ECANA, PAGE = 1 + ECanaLAMRegsFile : > ECANA_LAM PAGE = 1 + ECanaMboxesFile : > ECANA_MBOX PAGE = 1 + ECanaMOTSRegsFile : > ECANA_MOTS PAGE = 1 + ECanaMOTORegsFile : > ECANA_MOTO PAGE = 1 + + ECanbRegsFile : > ECANB, PAGE = 1 + ECanbLAMRegsFile : > ECANB_LAM PAGE = 1 + ECanbMboxesFile : > ECANB_MBOX PAGE = 1 + ECanbMOTSRegsFile : > ECANB_MOTS PAGE = 1 + ECanbMOTORegsFile : > ECANB_MOTO PAGE = 1 + + EPwm1RegsFile : > EPWM1 PAGE = 1 + EPwm2RegsFile : > EPWM2 PAGE = 1 + EPwm3RegsFile : > EPWM3 PAGE = 1 + EPwm4RegsFile : > EPWM4 PAGE = 1 + EPwm5RegsFile : > EPWM5 PAGE = 1 + EPwm6RegsFile : > EPWM6 PAGE = 1 + + ECap1RegsFile : > ECAP1 PAGE = 1 + ECap2RegsFile : > ECAP2 PAGE = 1 + ECap3RegsFile : > ECAP3 PAGE = 1 + ECap4RegsFile : > ECAP4 PAGE = 1 + ECap5RegsFile : > ECAP5 PAGE = 1 + ECap6RegsFile : > ECAP6 PAGE = 1 + + EQep1RegsFile : > EQEP1 PAGE = 1 + EQep2RegsFile : > EQEP2 PAGE = 1 + + GpioCtrlRegsFile : > GPIOCTRL PAGE = 1 + GpioDataRegsFile : > GPIODAT PAGE = 1 + GpioIntRegsFile : > GPIOINT PAGE = 1 + +/*** Peripheral Frame 2 Register Structures ***/ + SysCtrlRegsFile : > SYSTEM, PAGE = 1 + SpiaRegsFile : > SPIA, PAGE = 1 + SciaRegsFile : > SCIA, PAGE = 1 + XIntruptRegsFile : > XINTRUPT, PAGE = 1 + AdcRegsFile : > ADC, PAGE = 1 + ScibRegsFile : > SCIB, PAGE = 1 + ScicRegsFile : > SCIC, PAGE = 1 + I2caRegsFile : > I2CA, PAGE = 1 + +/*** Code Security Module Register Structures ***/ + CsmPwlFile : > CSM_PWL, PAGE = 1 + +/*** Device Part ID Register Structures ***/ + PartIdRegsFile : > PARTID, PAGE = 1 + +} + + +/* +//=========================================================================== +// End of file. +//=========================================================================== +*/ diff --git a/cmd/F28335.cmd b/cmd/F28335.cmd new file mode 100644 index 0000000..8d5d4e8 --- /dev/null +++ b/cmd/F28335.cmd @@ -0,0 +1,213 @@ +/* +// TI File $Revision: /main/10 $ +// Checkin $Date: July 9, 2008 13:43:56 $ +//########################################################################### +// +// FILE: F28335.cmd +// +// TITLE: Linker Command File For F28335 Device +// +//########################################################################### +// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $ +// $Release Date: August 1, 2008 $ +//########################################################################### +*/ + +/* ====================================================== +// For Code Composer Studio V2.2 and later +// --------------------------------------- +// In addition to this memory linker command file, +// add the header linker command file directly to the project. +// The header linker command file is required to link the +// peripheral structures to the proper locations within +// the memory map. +// +// The header linker files are found in \DSP2833x_Headers\cmd +// +// For BIOS applications add: DSP2833x_Headers_BIOS.cmd +// For nonBIOS applications add: DSP2833x_Headers_nonBIOS.cmd +========================================================= */ + +/* ====================================================== +// For Code Composer Studio prior to V2.2 +// -------------------------------------- +// 1) Use one of the following -l statements to include the +// header linker command file in the project. The header linker +// file is required to link the peripheral structures to the proper +// locations within the memory map */ + +/* Uncomment this line to include file only for non-BIOS applications */ +/* -l DSP2833x_Headers_nonBIOS.cmd */ + +/* Uncomment this line to include file only for BIOS applications */ +/* -l DSP2833x_Headers_BIOS.cmd */ + +/* 2) In your project add the path to \DSP2833x_headers\cmd to the + library search path under project->build options, linker tab, + library search path (-i). +/*========================================================= */ + +/* Define the memory block start/length for the F28335 + PAGE 0 will be used to organize program sections + PAGE 1 will be used to organize data sections + + Notes: + Memory blocks on F28335 are uniform (ie same + physical memory) in both PAGE 0 and PAGE 1. + That is the same memory region should not be + defined for both PAGE 0 and PAGE 1. + Doing so will result in corruption of program + and/or data. + + L0/L1/L2 and L3 memory blocks are mirrored - that is + they can be accessed in high memory or low memory. + For simplicity only one instance is used in this + linker file. + + Contiguous SARAM memory blocks can be combined + if required to create a larger memory block. + */ + + +MEMORY +{ +PAGE 0: /* Program Memory */ + /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */ + + ZONE0 : origin = 0x004000, length = 0x001000 /* XINTF zone 0 */ + RAML0 : origin = 0x008000, length = 0x004000 /* on-chip RAM block L0 */ +/* RAML1 : origin = 0x009000, length = 0x001000 */ /* on-chip RAM block L1 */ +/* RAML2 : origin = 0x00A000, length = 0x001000 */ /* on-chip RAM block L2 */ +/* RAML3 : origin = 0x00B000, length = 0x001000 */ /* on-chip RAM block L3 */ + + ZONE6 : origin = 0x0100000, length = 0x100000 /* XINTF zone 6 */ + ZONE7A : origin = 0x0200000, length = 0x00FC00 /* XINTF zone 7 - program space */ + FLASHH : origin = 0x300000, length = 0x008000 /* on-chip FLASH */ + FLASHG : origin = 0x308000, length = 0x008000 /* on-chip FLASH */ + FLASHF : origin = 0x310000, length = 0x008000 /* on-chip FLASH */ + FLASHE : origin = 0x318000, length = 0x008000 /* on-chip FLASH */ + FLASHD : origin = 0x320000, length = 0x004000 /* on-chip FLASH */ + FLASHC : origin = 0x324000, length = 0x004000 /* on-chip FLASH */ + FLASHA : origin = 0x32A000, length = 0x015F80 /* on-chip FLASH */ + CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */ + BEGIN : origin = 0x33FFF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */ + CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */ + OTP : origin = 0x380400, length = 0x000400 /* on-chip OTP */ + ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved memory */ + + IQTABLES : origin = 0x3FE000, length = 0x000b50 /* IQ Math Tables in Boot ROM */ + IQTABLES2 : origin = 0x3FEB50, length = 0x00008c /* IQ Math Tables in Boot ROM */ + FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* FPU Tables in Boot ROM */ + ROM : origin = 0x3FF27C, length = 0x000D44 /* Boot ROM */ + RESET : origin = 0x3FFFC0, length = 0x000002 /* part of boot ROM */ + VECTORS : origin = 0x3FFFC2, length = 0x00003E /* part of boot ROM */ + +PAGE 1 : /* Data Memory */ + /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */ + /* Registers remain on PAGE1 */ + + BOOT_RSVD : origin = 0x000000, length = 0x000050 /* Part of M0, BOOT rom will use this for stack */ + RAMM0 : origin = 0x000050, length = 0x0003B0 /* on-chip RAM block M0 */ + RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */ + + RAML4 : origin = 0x00C001, length = 0x003500 /* on-chip RAM block L1 */ + RAML5 : origin = 0x00F501, length = 0x0000FF /* on-chip RAM block L1 */ + RAML6 : origin = 0x00F600, length = 0x000400 /* on-chip RAM block L1 */ + RAML7 : origin = 0x00FA00, length = 0x000200 /* on-chip RAM block L1 */ + ZONE7B : origin = 0x20FC00, length = 0x000400 /* XINTF zone 7 - data space */ + FLASHB : origin = 0x328000, length = 0x002000 /* on-chip FLASH */ +} + +/* Allocate sections to memory blocks. + Note: + codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code + execution when booting to flash + ramfuncs user defined section to store functions that will be copied from Flash into RAM +*/ + +SECTIONS +{ + + /* Allocate program areas: */ + .cinit : > FLASHA PAGE = 0 + .pinit : > FLASHA, PAGE = 0 + .text : > FLASHA PAGE = 0 + codestart : > BEGIN PAGE = 0 + ramfuncs : LOAD = FLASHD, + RUN = RAML0, + LOAD_START(_RamfuncsLoadStart), + LOAD_END(_RamfuncsLoadEnd), + RUN_START(_RamfuncsRunStart), + PAGE = 0 + + MainLoop : LOAD = FLASHD, + RUN = RAML0, + LOAD_START(_MainLoopLoadStart), + LOAD_END(_MainLoopLoadEnd), + RUN_START(_MainLoopRunStart), + PAGE = 0 + + + csmpasswds : > CSM_PWL PAGE = 0 + csm_rsvd : > CSM_RSVD PAGE = 0 + + /* Allocate uninitalized data sections: */ + .stack : > RAMM1 PAGE = 1 + .ebss : > RAML4 PAGE = 1 + .esysmem : > RAMM1 PAGE = 1 + + /* Initalized sections go in Flash */ + /* For SDFlash to program these, they must be allocated to page 0 */ + .econst : > FLASHA PAGE = 0 + .switch : > FLASHA PAGE = 0 + + /* Allocate IQ math areas: */ + IQmath : > FLASHC PAGE = 0 /* Math Code */ + IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD + + /* Uncomment the section below if calling the IQNexp() or IQexp() + functions from the IQMath.lib library in order to utilize the + relevant IQ Math table in Boot ROM (This saves space and Boot ROM + is 1 wait-state). If this section is not uncommented, IQmathTables2 + will be loaded into other memory (SARAM, Flash, etc.) and will take + up space, but 0 wait-state is possible. + */ + /* + IQmathTables2 : > IQTABLES2, PAGE = 0, TYPE = NOLOAD + { + + IQmath.lib (IQmathTablesRam) + + } + */ + + FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD + + /* Allocate DMA-accessible RAM sections: */ + DMARAML4 : > RAML4, PAGE = 1 + DMARAML5 : > RAML5, PAGE = 1 + DMARAML6 : > RAML6, PAGE = 1 + DMARAML7 : > RAML7, PAGE = 1 + + /* Allocate 0x400 of XINTF Zone 7 to storing data */ + ZONE7DATA : > ZONE7B, PAGE = 1 + + /* .reset is a standard section used by the compiler. It contains the */ + /* the address of the start of _c_int00 for C Code. /* + /* When using the boot ROM this section and the CPU vector */ + /* table is not needed. Thus the default type is set here to */ + /* DSECT */ + .reset : > RESET, PAGE = 0, TYPE = DSECT + vectors : > VECTORS PAGE = 0, TYPE = DSECT + + /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */ + .adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD + +} + +/* +//=========================================================================== +// End of file. +//=========================================================================== +*/ + diff --git a/cmd/F28335frmwrk.cmd b/cmd/F28335frmwrk.cmd new file mode 100644 index 0000000..8703dc1 --- /dev/null +++ b/cmd/F28335frmwrk.cmd @@ -0,0 +1,232 @@ +/* +// TI File $Revision: /main/10 $ +// Checkin $Date: July 9, 2008 13:43:56 $ +//########################################################################### +// +// FILE: F28335.cmd +// +// TITLE: Linker Command File For F28335 Device +// +//########################################################################### +// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $ +// $Release Date: August 1, 2008 $ +//########################################################################### +*/ + +/* ====================================================== +// For Code Composer Studio V2.2 and later +// --------------------------------------- +// In addition to this memory linker command file, +// add the header linker command file directly to the project. +// The header linker command file is required to link the +// peripheral structures to the proper locations within +// the memory map. +// +// The header linker files are found in \DSP2833x_Headers\cmd +// +// For BIOS applications add: DSP2833x_Headers_BIOS.cmd +// For nonBIOS applications add: DSP2833x_Headers_nonBIOS.cmd +========================================================= */ + +/* ====================================================== +// For Code Composer Studio prior to V2.2 +// -------------------------------------- +// 1) Use one of the following -l statements to include the +// header linker command file in the project. The header linker +// file is required to link the peripheral structures to the proper +// locations within the memory map */ + +/* Uncomment this line to include file only for non-BIOS applications */ +/* -l DSP2833x_Headers_nonBIOS.cmd */ + +/* Uncomment this line to include file only for BIOS applications */ +/* -l DSP2833x_Headers_BIOS.cmd */ + +/* 2) In your project add the path to \DSP2833x_headers\cmd to the + library search path under project->build options, linker tab, + library search path (-i). +/*========================================================= */ + +/* Define the memory block start/length for the F28335 + PAGE 0 will be used to organize program sections + PAGE 1 will be used to organize data sections + + Notes: + Memory blocks on F28335 are uniform (ie same + physical memory) in both PAGE 0 and PAGE 1. + That is the same memory region should not be + defined for both PAGE 0 and PAGE 1. + Doing so will result in corruption of program + and/or data. + + L0/L1/L2 and L3 memory blocks are mirrored - that is + they can be accessed in high memory or low memory. + For simplicity only one instance is used in this + linker file. + + Contiguous SARAM memory blocks can be combined + if required to create a larger memory block. + */ + + +MEMORY +{ +PAGE 0: /* Program Memory */ + /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */ + + ZONE0 : origin = 0x004000, length = 0x001000 /* XINTF zone 0 */ + RAML0 : origin = 0x008000, length = 0x004000 /* on-chip RAM block L0 */ +/* RAML1 : origin = 0x009000, length = 0x001000 */ /* on-chip RAM block L1 */ +/* RAML2 : origin = 0x00A000, length = 0x001000 */ /* on-chip RAM block L2 */ +/* RAML3 : origin = 0x00B000, length = 0x001000 */ /* on-chip RAM block L3 */ + + ZONE6 : origin = 0x0100000, length = 0x100000 /* XINTF zone 6 */ + ZONE7A : origin = 0x0200000, length = 0x00FC00 /* XINTF zone 7 - program space */ + FLASHH : origin = 0x300000, length = 0x008000 /* on-chip FLASH */ + FLASHG : origin = 0x308000, length = 0x008000 /* on-chip FLASH */ + FLASHF : origin = 0x310000, length = 0x008000 /* on-chip FLASH */ + FLASHE : origin = 0x318000, length = 0x008000 /* on-chip FLASH */ + FLASHD : origin = 0x320000, length = 0x004000 /* on-chip FLASH */ + FLASHC : origin = 0x324000, length = 0x004000 /* on-chip FLASH */ + FLASHA : origin = 0x32A000, length = 0x015F80 /* on-chip FLASH */ + CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */ + BEGIN : origin = 0x33FFF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */ + CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */ + OTP : origin = 0x380400, length = 0x000400 /* on-chip OTP */ + ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved memory */ + + IQTABLES : origin = 0x3FE000, length = 0x000b50 /* IQ Math Tables in Boot ROM */ + IQTABLES2 : origin = 0x3FEB50, length = 0x00008c /* IQ Math Tables in Boot ROM */ + FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* FPU Tables in Boot ROM */ + ROM : origin = 0x3FF27C, length = 0x000D44 /* Boot ROM */ + RESET : origin = 0x3FFFC0, length = 0x000002 /* part of boot ROM */ + VECTORS : origin = 0x3FFFC2, length = 0x00003E /* part of boot ROM */ + +PAGE 1 : /* Data Memory */ + /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */ + /* Registers remain on PAGE1 */ + + BOOT_RSVD : origin = 0x000000, length = 0x000050 /* Part of M0, BOOT rom will use this for stack */ + RAMM0 : origin = 0x000050, length = 0x0003B0 /* on-chip RAM block M0 */ + RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */ + + //RAML4 : origin = 0x00C001, length = 0x003500 /* on-chip RAM block L1 */ + //RAML5 : origin = 0x00F501, length = 0x0000FF /* on-chip RAM block L1 */ + //RAML6 : origin = 0x00F600, length = 0x000400 /* on-chip RAM block L1 */ + //RAML7 : origin = 0x00FA00, length = 0x000200 /* on-chip RAM block L1 */ + RAML4567 : origin = 0x00C001, length = 0x003BFF /* on-chip RAM block L1 */ + + ZONE7B : origin = 0x20FC00, length = 0x000400 /* XINTF zone 7 - data space */ + FLASHB : origin = 0x328000, length = 0x002000 /* on-chip FLASH */ +} + +/* Allocate sections to memory blocks. + Note: + codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code + execution when booting to flash + ramfuncs user defined section to store functions that will be copied from Flash into RAM +*/ + +SECTIONS +{ + + /* Allocate program areas: */ + .cinit : > FLASHA PAGE = 0 + .pinit : > FLASHA, PAGE = 0 + .text : > FLASHA PAGE = 0 + codestart : > BEGIN PAGE = 0 + ramfuncs : LOAD = FLASHE, + RUN = RAML0, + LOAD_START(_RamfuncsLoadStart), + LOAD_END(_RamfuncsLoadEnd), + RUN_START(_RamfuncsRunStart), + PAGE = 0 + + MainLoop : LOAD = FLASHE, + RUN = RAML0, + LOAD_START(_MainLoopLoadStart), + LOAD_END(_MainLoopLoadEnd), + RUN_START(_MainLoopRunStart), + PAGE = 0 +/* + Flash28_API: + { + -lFlash28335_API_V210.lib(.econst) + -lFlash28335_API_V210.lib(.text) + } LOAD = FLASHE, + RUN = RAML0, + LOAD_START(_Flash28_API_LoadStart), + LOAD_END(_Flash28_API_LoadEnd), + RUN_START(_Flash28_API_RunStart), + PAGE = 0 +*/ + + + csmpasswds : > CSM_PWL PAGE = 0 + csm_rsvd : > CSM_RSVD PAGE = 0 + + /* Allocate uninitalized data sections: */ + /*.stack : > RAMM1 PAGE = 1 */ + .stack : > RAML4567 PAGE = 1 + .ebss : > RAML4567 PAGE = 1 + .esysmem : > RAMM1 PAGE = 1 + + /* Initalized sections go in Flash */ + /* For SDFlash to program these, they must be allocated to page 0 */ + .econst : > FLASHA PAGE = 0 + .switch : > FLASHA PAGE = 0 + + /* User section */ + .usect :> FLASHH PAGE = 0 + + + /* Allocate IQ math areas: */ + IQmath : > FLASHC PAGE = 0 /* Math Code */ + IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD + + /* Uncomment the section below if calling the IQNexp() or IQexp() + functions from the IQMath.lib library in order to utilize the + relevant IQ Math table in Boot ROM (This saves space and Boot ROM + is 1 wait-state). If this section is not uncommented, IQmathTables2 + will be loaded into other memory (SARAM, Flash, etc.) and will take + up space, but 0 wait-state is possible. + */ + /* + IQmathTables2 : > IQTABLES2, PAGE = 0, TYPE = NOLOAD + { + + IQmath.lib (IQmathTablesRam) + + } + */ + + FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD + + /* Allocate DMA-accessible RAM sections: */ +// DMARAML4 : > RAML4, PAGE = 1 +// DMARAML5 : > RAML5, PAGE = 1 +// DMARAML6 : > RAML6, PAGE = 1 +// DMARAML7 : > RAML7, PAGE = 1 + + /* Allocate 0x400 of XINTF Zone 7 to storing data */ + ZONE7DATA : > ZONE7B, PAGE = 1 + + /* .reset is a standard section used by the compiler. It contains the */ + /* the address of the start of _c_int00 for C Code. /* + /* When using the boot ROM this section and the CPU vector */ + /* table is not needed. Thus the default type is set here to */ + /* DSECT */ + .reset : > RESET, PAGE = 0, TYPE = DSECT + vectors : > VECTORS PAGE = 0, TYPE = DSECT + + /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */ + .adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD + +} + +/* +//=========================================================================== +// End of file. +//=========================================================================== +*/ + diff --git a/dvr_main.cpp b/dvr_main.cpp new file mode 100644 index 0000000..aab1074 --- /dev/null +++ b/dvr_main.cpp @@ -0,0 +1,500 @@ +/***************************************************************************** + * File Name:app_main.c + * Author:ZD + * Brief: + * Note: + * Last Updated for Version:1.0 + * Date of the Last Update:18-06-2020 + *****************************************************************************/ + + +#include +#include + +#include "framework.h" + +#include "F28335/Flash2833x_API_Config.h" +#include "F28335/Flash2833x_API_Library.h" + +#include "SYSCTRL/TypeControl.h" +#include "SYSCTRL/SystemControl.h" +#include "FLASH/FLASHHeaders.h" + +/***************************************************************************** + *****************************************************************************/ +#include "FRAM/FRAMDATABASE.h" +#include "FRAM/FRAMDataObjects.h" +#include "FRAM/FRAMVariant.h" +#include "FRAM/ROM.h" + +/***************************************************************************** + *****************************************************************************/ + +float TISR = periodtriangle; +float cellVoltage[3][13]; +CellState cellState[3][13]; +Uint16 cellVersion[3][13]; +Uint16 pwmVersion[3]; +Uint32 cpu_cpld_version; + + +/***************************************************************************** + *****************************************************************************/ +#define TIMEINTERVALBREAKRESETMODBUS (Uint16)(100/0.4) +Uint16 endlesscounter = 0; +Uint16 endlesscounter_epwm = 0; +Uint16 counter_break_state = 0; +Uint16 counter_reset = 0; +stateHandle *state_modbus; +stateHandle *state_modbus_init; +enum MODBUS_RTU_EVENT_RS +{ + ENTYR = 1, // state entry event + EXIT = 2, // state exit event + TIMEOUT3_5CHAR = 3, // All datagram have been received + TIMEOUT1_5CHAR = 4, // Interval time of each byte in datagram. Not used + RX_READY = 5, // SCIRXST.bit.RXRDY. Serial port received a serial data (one byte) + TX_READY = 6, // All datagram have been sent + TX_WAIT = 7 // Wait for the datagram to be sent +}; +// +/***************************************************************************** + *****************************************************************************/ +//Uint16 m_readCoils[300] = {0}; +//Uint16 m_writeCoils[300] = {0}; +#define LENGHTMODBUSBUFFER 30 +Uint16 m_readRegisters[LENGHTMODBUSBUFFER] = {0}; +Uint16 m_writeRegisters[LENGHTMODBUSBUFFER] = {0}; +Uint16 counter_current_faults = 0; + +//Uint16 m_canData_cpu2com_coils[16] = { 0 }; +//Uint16 m_canData_cpu2com_registers[50] = { 0 }; +//Uint16 m_canData_com2cpu_coils[16] = { 0 }; +//Uint16 m_canData_com2cpu_registers[50] = { 0 }; +/***************************************************************************** + *****************************************************************************/ +//FLASH::TestFlashDataBase default_configuration; +//FLASH::FLASHACCESS flash_local; +//FLASH::FLASHDATABASEConfiguration flash_config(flash_local); +//SYSCTRL::SystemControlSetup dvr_setup; +//SYSCTRL::SystemControlConfiguration dvr_config; +SYSCTRL::SystemControl dvr_control = SYSCTRL::SystemControl(); + +#define MAGIC_NUMBER_TIMER1 ((Uint32)6) +#define MAGIC_NUMBER_TIMER2 ((Uint32)6) +Uint32 timer1_result = (Uint32)0; +Uint32 timer2_result = (Uint32)0; +Uint32 timer1_magic = MAGIC_NUMBER_TIMER1; +Uint32 timer2_magic = MAGIC_NUMBER_TIMER2; +void measure_timer1_reset(); +void measure_timer2_reset(); +inline void measure_timer1_start(); +inline void measure_timer2_start(); +inline void measure_timer1_stop(Uint32 magic, Uint32& result); +inline void measure_timer2_stop(Uint32 magic, Uint32& result); +void WDReset(void); + +/***************************************************************************** + ******************************************************************************/ + + +/***************************************************************************** + ** Global Function Declare + *****************************************************************************/ +interrupt void epwm1_isr(void); +interrupt void reload_isr(void); +void service_routine(); +void modbus_registers_config(); +/***************************************************************************** + ** Local Function Declare + *****************************************************************************/ +void main(void) +{ + InitSysCtrl(); + InitEPwm(); + DINT; + + InitPieCtrl(); + + IER = 0x0000; + IFR = 0x0000; + + InitPieVectTable(); + EALLOW; + PieVectTable.EPWM1_INT = &epwm1_isr; + PieVectTable.USER1 = &reload_isr; //User defined Interrupt + EDIS; + + InitCpuTimers(); + ConfigCpuTimer(&CpuTimer0, 150, TISR); + + EALLOW; + SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; + EDIS; + InitEPwm1(); + InitEPwm5(); + InitEPwm6(); + EALLOW; + SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; + EDIS; +// symbols are created by the linker. Refer to the F28335.cmd file. + MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); +// Call Flash Initialization to setup flash waitstates +// This function must reside in RAM + MemCopy(&MainLoopLoadStart, &MainLoopLoadEnd, &MainLoopRunStart); + + // Copy the Flash API functions to SARAM + //MemCopy(&Flash28_API_LoadStart, &Flash28_API_LoadEnd, &Flash28_API_RunStart); + + DINT; + + Flash_CPUScaleFactor = SCALE_FACTOR; + + InitFlash(); + +// flash.setup(SECTORH, (Uint16*) 0x300000, (Uint16*) 0x307FFF); + + IER |= M_INT3; + PieCtrlRegs.PIEIER3.bit.INTx1 = 1; + + Gpio_setup1(); + + InitXintf(); + + InitECanGpio(); + InitECan(); + + InitSci(); + + InitEQep1Gpio(); + EQep1Regs.QDECCTL.bit.QSRC = 00; + EQep1Regs.QDECCTL.bit.XCR = 0; + EQep1Regs.QEPCTL.bit.FREE_SOFT = 2; + EQep1Regs.QPOSMAX = 0xffffffff; + EQep1Regs.QEPCTL.bit.QPEN = 1; + EQep1Regs.QPOSCNT = 0x00000000; + + frameworkDataInit(); // Initialize global Variable + + etmp.signal=0; + modbusCtor(&modbusHMI,eBufferHMI, &modbusHMIPort); + modbusInit(&modbusHMI,&etmp); + + modbusSlaveBufferSet( + &modbusHMI, + OUTPUTCOILS, + readCoils, + sizeof(readCoils)/sizeof(Uint16), + 20); // Set to the starting address you need + modbusSlaveBufferSet( + &modbusHMI, + INPUTCOILS, + writeCoils, + sizeof(writeCoils)/sizeof(Uint16), + 20); // Set to the starting address you need + modbusSlaveBufferSet( + &modbusHMI, + OUTPUTREGISTERS, + readRegisters, + sizeof(readRegisters)/sizeof(Uint16), + 310); // Set to the starting address you need + modbusSlaveBufferSet( + &modbusHMI, + INPUTREGISTERS, + writeRegisters, + sizeof(writeRegisters)/sizeof(Uint16), + 310); // Set to the starting address you need + + + measure_timer1_reset(); + measure_timer2_reset(); + + dvr_control.get_hard_code_setup(); + //dvr_control.get_hard_code_configuration(); + dvr_control.upload_configuration(); + + dvr_control.setup(); + dvr_control.configure(); + + dvr_control.setup_hvcell(); + state_modbus_init = &modbusHMI.super.initState; + + //flash_local.setup(SECTORG, (Uint16*)0x308000, (Uint16*)0x30FFFF); + //flash_config.register_configuration_parameters(&test_configuration); + //flash_config.load_flash(&test_configuration); + + + + //framdb.read_from_fram_to_buffer(); + //framdb.register_configuration_parameters(); + //framdb.get_dafault_configuration(); + //framdb.upload_configuration(); + + EINT; + ERTM; + + + // + // Watchdog Setup + // + ServiceDog(); + EALLOW; + SysCtrlRegs.WDCR= 0x002C; + EDIS; + ServiceDog(); + + + // + service_routine(); + // +}//end main() +// + + +#pragma CODE_SECTION("ramfuncs"); +void service_routine() +{ + + while(1) + { + /***********************************************************************/ + // Detect Hardware Current Cell Fault + if((GpioDataRegs.GPADAT.bit.GPIO12 == 1) || (GpioDataRegs.GPADAT.bit.GPIO13 == 1) || (GpioDataRegs.GPADAT.bit.GPIO20 == 1)) + { + counter_current_faults++; + dvr_control.hardware_analog_current_fault.signal.phase_a = GpioDataRegs.GPADAT.bit.GPIO12; + dvr_control.hardware_analog_current_fault.signal.phase_b = GpioDataRegs.GPADAT.bit.GPIO13; + dvr_control.hardware_analog_current_fault.signal.phase_c = GpioDataRegs.GPADAT.bit.GPIO20; + dvr_control.hardware_analog_current_fault.signal.fault = 1; + }//if + + if(!dvr_control.hardware_analog_current_fault.signal.vs && dvr_control.hardware_analog_current_fault.signal.fault) + { + dvr_control.protection_thyristor_control(); + digitalOutput.all = (Uint32)dvr_control.get_digital_output(); + writeDigitalOutput(digitalOutput.all); // Write digital output + sendControlOrder(ORDER_START); + sendModulateData(0,0,0); // Send modulate data + // + }//if + // + /***********************************************************************/ + + ECanbRx(); // Receiving communication board data + modbusRun(&modbusHMI); // Running MODBUS state machine + + /****************************user code*************************************/ + // Add your code here + //measure_timer2_start(); + //measure_timer2_stop(timer2_magic, timer2_result); + // + // MODBUS Service + dvr_control.modbusrtu_rubus_interface(readRegisters, writeRegisters); + // + if(dvr_control.additional_loop_is_active()) + { + dvr_control.execute_additional(); + dvr_control.set_hvcell_level(); + dvr_control.get_hvcell_version(); + dvr_control.get_pwm_version(); + dvr_control.get_cpu_cpld_version(); + dvr_control.get_hvcell_state(); + dvr_control.hardware_diagnostic(); + // + }//if + // + if(dvr_control.slow_loop_is_active()) + { + digitalInput.all = readDigitalInput(); // Read digital input + // + digitalOutput.all = (Uint32)dvr_control.get_digital_output(); + writeDigitalOutput(digitalOutput.all); // Write digital output + // + dvr_control.process_digital_input(digitalInput); + dvr_control.slow_loop_execute(); + // + // Analog output + setAnalogOutput2001_2005(a2001_2005); // analog output + setAnalogOutput2002_2006(a2002_2006); // analog output + setAnalogOutput2003_2007(a2003_2007); // analog output + setAnalogOutput2004_2008(a2004_2008); // analog output + // + // + }//if + // + if(dvr_control.symmetrical_calculator_loop_is_active()) + { + dvr_control.execute_symmetrical_calculator(); + // + }//if + // + /* + for(int16_t i=0; i= TIMEINTERVALBREAKRESETMODBUS) + { + counter_break_state = 0; + counter_reset++; + dvr_control.inc_break_counter(); + modbusInit(&modbusHMI,&etmp); + } + /****************************user code end*********************************/ + + EPwm1Regs.ETCLR.bit.INT = 1; + PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; +} +/***************************************************************************** + ** No more. + ****************************************************************************/ +// +#pragma CODE_SECTION("ramfuncs"); +interrupt void reload_isr(void) +{ + // + WDReset(); + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void measure_timer1_reset() +{ + // + CpuTimer1Regs.TCR.bit.TSS = 1; // Stop CPU Timer + CpuTimer1Regs.PRD.all = 0xFFFFFFFF; + CpuTimer1Regs.TCR.bit.TRB = 1; // Reload CPU Timer + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void measure_timer2_reset() +{ + // + CpuTimer2Regs.TCR.bit.TSS = 1; // Stop CPU Timer + CpuTimer2Regs.PRD.all = 0xFFFFFFFF; + CpuTimer2Regs.TCR.bit.TRB = 1; // Reload CPU Timer + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void measure_timer1_start() +{ + // + CpuTimer1Regs.TCR.bit.TSS = 1; // Stop CPU Timer; + CpuTimer1Regs.TCR.bit.TRB = 1; // Reload CPU Timer; + CpuTimer1Regs.TCR.bit.TSS = 0; // Start CPU Timer; + CpuTimer1.InterruptCount++; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +inline void measure_timer2_start() +{ + // + CpuTimer2Regs.TCR.bit.TSS = 1; // Stop CPU Timer; + CpuTimer2Regs.TCR.bit.TRB = 1; // Reload CPU Timer; + CpuTimer2Regs.TCR.bit.TSS = 0; // Start CPU Timer; + CpuTimer2.InterruptCount++; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void measure_timer1_stop(Uint32 magic, Uint32& result) +{ + // + CpuTimer1Regs.TCR.bit.TSS = 1; // Stop CPU Timer + // + result = CpuTimer1Regs.PRD.all - CpuTimer1Regs.TIM.all - magic; + // +}// +// +#pragma CODE_SECTION("ramfuncs"); +void measure_timer2_stop(Uint32 magic, Uint32& result) +{ + // + CpuTimer2Regs.TCR.bit.TSS = 1; // Stop CPU Timer + // + result = CpuTimer2Regs.PRD.all - CpuTimer2Regs.TIM.all - magic; + // +}// +// +void WDReset(void) +{ + EALLOW; + SysCtrlRegs.WDCR= 0x0078; + EDIS; +} +// +