/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2025 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_plc_macro_div.h -- Runtime environment - PLC
Contains macros for object that does not fit anywhere else.
This code is used in the PLC-program environment. */
#define Backup_init(object, data) strcpy(&(object->DataName), data);
WindowPlc
#define windowplc_exec(object) \
if (object->ScanOff) \
return; \
pwr_tTime wplc_exec_start, wplc_exec_end; \
time_GetTimeMonotonic(&wplc_exec_start)
#define windowplc_exec2(object) \
time_GetTimeMonotonic(&wplc_exec_end); \
object->ExecTime = time_AdiffToFloat(&wplc_exec_end, &wplc_exec_start); \
if (object->ExecTime > object->MaxExecTime) \
object->MaxExecTime = object->ExecTime;
WindowCond
#define windowcond_exec(object) \
if (object->ScanOff) \
return;
#define windowcond_exec2(object)
WindowOrderact
#define windoworderact_exec(object) \
if (object->ScanOff) \
return;
#define windoworderact_exec2(object)
WindowSubstep
#define windowsubstep_exec(object) \
if (object->ScanOff) \
return;
#define windowsubstep_exec2(object)
ScanTime
#define ScanTime_exec(object) object->Time = *object->ScanTime;
FirstScan
#define FirstScan_exec(object) object->Status = tp->first_scan;
IOSimulFlag
#define IOSimulFlag_exec(object) \
if (tp->pp->IOHandler) \
object->Status = tp->pp->IOHandler->IOSimulFlag;
Abs
#define Abs_exec(object, in) object->ActVal = ABS(in);
IAbs
#define IAbs_exec(object, in) object->ActVal = ABS(in);
Sin
#define Sin_exec(object, in) \
object->ActVal = object->FactorVal * sinf(object->FactorIn * in);
Cos
#define Cos_exec(object, in) \
object->ActVal = object->FactorVal * cosf(object->FactorIn * in);
Tan
#define Tan_exec(object, in) \
object->ActVal = object->FactorVal * tanf(object->FactorIn * in);
ASin
#define ASin_exec(object, in) \
object->ActVal = object->FactorVal * asinf(object->FactorIn * in);
ACos
#define ACos_exec(object, in) \
object->ActVal = object->FactorVal * acosf(object->FactorIn * in);
ATan
#define ATan_exec(object, in) \
object->ActVal = object->FactorVal * atanf(object->FactorIn * in);
Sqrt
#define Sqrt_exec(object, in) \
object->ActVal = object->FactorVal * sqrtf(object->FactorIn * in);
Even
#define Even_exec(object, in) object->Status = ((in & 1) == 0);
Odd
#define Odd_exec(object, in) object->Status = ((in & 1) != 0);
Ln
#define Ln_exec(object, in) \
object->ActVal = object->FactorVal * logf(object->FactorIn * in);
Log
#define Log_exec(object, in) \
object->ActVal = object->FactorVal * log10f(object->FactorIn * in);
Exp
#define Exp_exec(object, in) \
object->ActVal = object->FactorVal * expf(object->FactorIn * in);
BwAnd
#define BwAnd_exec(t, o) o->Status = *o->In1P & *o->In2P;
BwOr
#define BwOr_exec(t, o) o->Status = *o->In1P | *o->In2P;
BwInv
#define BwInv_exec(t, o) o->Out = ~(*o->InP);
GetDatap
#define GetDatap_exec(object, in) memcpy(&object->Out, &in, 12);
GetDataRefp
#define GetDataRefp_exec(object, in) \
memcpy(&object->ActVal, &in, sizeof(object->ActVal));
GetDatainput
#define GetDataInput_exec(object, in) \
if (in) \
memcpy(&object->OutDataP, in, 12);
PulseTrain
#define PulseTrain_exec(o) \
o->P30s = (tp->before_scan.tv_sec / 15) & 1 ? 1 : 0; \
o->P10s = (tp->before_scan.tv_sec / 5) & 1 ? 1 : 0; \
o->P5s \
= ((tp->before_scan.tv_sec * 10 + tp->before_scan.tv_nsec / 100000000) \
/ 25) \
& 1 \
? 1 \
: 0; \
o->P2s = tp->before_scan.tv_sec & 1 ? 1 : 0; \
o->P1s = (tp->before_scan.tv_nsec / 500000000) & 1 ? 1 : 0; \
o->P500ms = (tp->before_scan.tv_nsec / 250000000) & 1 ? 1 : 0; \
o->P200ms = (tp->before_scan.tv_nsec / 100000000) & 1 ? 1 : 0; \
o->P100ms = (tp->before_scan.tv_nsec / 50000000) & 1 ? 1 : 0; \
o->P50ms = (tp->before_scan.tv_nsec / 25000000) & 1 ? 1 : 0; \
o->P20ms = (tp->before_scan.tv_nsec / 10000000) & 1 ? 1 : 0; \
o->P10ms = (tp->before_scan.tv_nsec / 5000000) & 1 ? 1 : 0; \
o->P5ms = (tp->before_scan.tv_nsec / 2500000) & 1 ? 1 : 0; \
o->P2ms = (tp->before_scan.tv_nsec / 1000000) & 1 ? 1 : 0; \
o->P1ms = (tp->before_scan.tv_nsec / 500000) & 1 ? 1 : 0;
PulseTrainM
#define PulseTrainM_exec(o) \
o->P128s = (tp->before_scan.tv_sec / 64) & 1 ? 1 : 0; \
o->P64s = (tp->before_scan.tv_sec / 32) & 1 ? 1 : 0; \
o->P32s = (tp->before_scan.tv_sec / 16) & 1 ? 1 : 0; \
o->P16s = (tp->before_scan.tv_sec / 8) & 1 ? 1 : 0; \
o->P8s = (tp->before_scan.tv_sec / 4) & 1 ? 1 : 0; \
o->P4s = (tp->before_scan.tv_sec / 2) & 1 ? 1 : 0; \
o->P2s = tp->before_scan.tv_sec & 1 ? 1 : 0; \
o->P1s = (tp->before_scan.tv_nsec / 500000000) & 1 ? 1 : 0; \
o->P500ms = (tp->before_scan.tv_nsec / 250000000) & 1 ? 1 : 0; \
o->P250ms = (tp->before_scan.tv_nsec / 125000000) & 1 ? 1 : 0; \
o->P125ms = (tp->before_scan.tv_nsec / 62500000) & 1 ? 1 : 0; \
o->P62ms = (tp->before_scan.tv_nsec / 31250000) & 1 ? 1 : 0; \
o->P31ms = (tp->before_scan.tv_nsec / 15625000) & 1 ? 1 : 0; \
o->P15ms = (tp->before_scan.tv_nsec / 7812500) & 1 ? 1 : 0;
ISwap16
#define ISwap16_exec(o, in) { \
unsigned int tmp; \
tmp = (in << 8) & 0xff00ff00; \
tmp |= (in >> 8) & 0xff00ff; \
o->ActVal = tmp; \
}
ISwap32
#define ISwap32_exec(o, in) { \
unsigned int tmp; \
tmp = (in << 24) & 0xff000000; \
tmp |= (in << 8) & 0xff0000; \
tmp |= (in >> 8) & 0xff00; \
tmp |= (in >> 24) & 0xff; \
o->ActVal = tmp; \
}
#define GetBus_generic_exec(tp, o, bus) { \
o->Out = *bus; \
}
#define CStoBus_generic_exec(tp, o, bus) { \
if (o->Cond) \
*bus = *o->InP; \
}