added ScaleGAM

This commit is contained in:
Martino Ferrari
2026-02-11 14:14:56 +01:00
parent 47d7f8c446
commit fa5db368cd
4 changed files with 278 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id: Makefile.gcc 3 2012-01-15 16:26:07Z aneto $
#
#############################################################
include Makefile.inc

View File

@@ -0,0 +1,53 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id: Makefile.inc 3 2012-01-15 16:26:07Z aneto $
#
#############################################################
OBJSX=ScaleGAM.x
PACKAGE=GAMs
ROOT_DIR=../../../../obj
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
INCLUDES += -I.
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L0Types
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L1Portability
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L2Objects
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L3Streams
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Messages
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Configuration
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L5GAMs
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L1Portability
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L3Services
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L4Messages
all: $(OBJS) $(SUBPROJ) \
$(BUILD_DIR)/ScaleGAM$(LIBEXT) \
$(BUILD_DIR)/ScaleGAM$(DLLEXT)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -0,0 +1,127 @@
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "CompilerTypes.h"
#include "DataSourceI.h"
#include "ScaleGAM.h"
#include "TypeDescriptor.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe {} // namespace MARTe
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe {
const MARTe::uint32 NUM_OUTPUTS = 1u;
const MARTe::uint32 NUM_PARAMS = 0u;
ScaleGAM::ScaleGAM() : GAM(), MessageI() {
factors = NULL_PTR(float32 *);
inputs = NULL_PTR(float32 *);
outputs = NULL_PTR(float32 *);
}
ScaleGAM::~ScaleGAM() {
if (factors != NULL_PTR(float32 *)) {
delete[] factors;
}
}
bool ScaleGAM::Setup() {
bool ok = numberOfInputSignals == numberOfOutputSignals;
for (uint32 i = 0; i < numberOfInputSignals && ok; i++) {
if (GetSignalType(InputSignals, i) != Float32Bit) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"Input %d should be float32", i);
ok = false;
}
if (GetSignalType(OutputSignals, i) != Float32Bit) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"Output %d should be float32", i);
ok = false;
}
}
inputs = (float32 *)inputSignalsMemory;
outputs = (float32 *)outputSignalsMemory;
return ok;
}
bool ScaleGAM::Initialise(StructuredDataI &data) {
bool ret = GAM::Initialise(data);
uint32 nin = 0;
if (ret && data.MoveRelative("InputSignals")) {
nin = data.GetNumberOfChildren();
if (nin == 0) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"Number of inputs should > 0");
ret = false;
} else {
factors = new float32[nin];
}
for (uint32 i = 0; i < nin && ret; i++) {
ret = data.MoveToChild(i);
if (!ret) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"Impossible to move to children %d", i);
data.MoveToAncestor(1u);
break;
}
ret = data.Read("Factor", factors[i]);
if (!ret) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"Impossible to move to read `Factor` for signal n %d ", i);
data.MoveToAncestor(1u);
break;
}
}
ret = data.MoveToAncestor(1u) & ret;
} else {
REPORT_ERROR(ErrorManagement::InitialisationError,
"No input signals found");
ret &= false;
}
if (ret && data.MoveRelative("OutputSignals")) {
uint32 nout = data.GetNumberOfChildren();
if (nout != nin) {
REPORT_ERROR(
ErrorManagement::InitialisationError,
"Number of Outputs should be exactly equal to number of outputs",
NUM_OUTPUTS);
ret = false;
}
ret = data.MoveToAncestor(1u);
} else {
REPORT_ERROR(ErrorManagement::InitialisationError,
"No output signals, exactly %d outputs are needed",
NUM_OUTPUTS);
ret = false;
}
REPORT_ERROR(ret ? ErrorManagement::Information
: ErrorManagement::InitialisationError,
ret ? "%s Initialised" : "%s Failed to initialise", GetName());
return ret;
}
bool ScaleGAM::Execute() {
for (uint32 i = 0; i < numberOfInputSignals; i++) {
outputs[i] = inputs[i] / factors[i];
}
return true;
}
CLASS_REGISTER(ScaleGAM, "1.0")
} /* namespace MARTe */

View File

@@ -0,0 +1,71 @@
#ifndef SCALE_GAM_H
#define SCALE_GAM_H
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "Architecture/x86_gcc/CompilerTypes.h"
#include "GAM.h"
#include "MessageI.h"
/*---------------------------------------------------------------------------*/
/* Class declaration */
/*---------------------------------------------------------------------------*/
namespace MARTe {
class ScaleGAM : public GAM, public MessageI {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief Constructor. NOOP.
*/
ScaleGAM();
/**
* @brief Destructor. NOOP.
*/
virtual ~ScaleGAM();
/**
* @brief Initialises the output signal memory with default values provided
* through configuration.
* @return true if the pre-conditions are met.
* @pre
* The pairs of signals have the same byte size.
*/
virtual bool Setup();
/**
* @see DataSourceI::Initialise
* @details Initialise the parameters of the ComparatorGAM
* @return true if the pre-conditions are met.
* @pre
* The number of input signals is even and each pair of signals have the same
* type.
**/
virtual bool Initialise(StructuredDataI &data);
/**
* @brief Execute method. NOOP.
* @return true.
*/
virtual bool Execute();
private:
float32 * inputs;
float32 * outputs;
float32 * factors;
};
} // namespace MARTe
/*---------------------------------------------------------------------------*/
/* Inline method definitions */
/*---------------------------------------------------------------------------*/
#endif