Implemented backend hr resolution data, splitted test gam

This commit is contained in:
Martino Ferrari
2026-05-19 14:14:22 +02:00
parent c122369ca7
commit 620542a722
13 changed files with 610 additions and 35 deletions
+25
View File
@@ -0,0 +1,25 @@
#############################################################
#
# 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.
#
#############################################################
include Makefile.inc
+38
View File
@@ -0,0 +1,38 @@
#############################################################
#
# 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.
#
#############################################################
OBJSX=
SPB = SineArrayGAM.x
PACKAGE=Components
ROOT_DIR=../../..
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
all: $(OBJS) $(SUBPROJ)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
@@ -0,0 +1,25 @@
#############################################################
#
# 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.
#
#############################################################
include Makefile.inc
@@ -0,0 +1,52 @@
#############################################################
#
# 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.
#
#############################################################
OBJSX = SineArrayGAM.x
PACKAGE=Components/GAMs
ROOT_DIR=../../../../
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) \
$(BUILD_DIR)/SineArrayGAM$(LIBEXT) \
$(BUILD_DIR)/SineArrayGAM$(DLLEXT)
echo $(OBJS)
-include depends.$(TARGET)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
@@ -0,0 +1,118 @@
/**
* @file SineArrayGAM.cpp
* @brief Source file for class SineArrayGAM
* @date 15/05/2026
* @author Martino Ferrari
*
* @copyright 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
*
* @warning 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 permissions and limitations under the Licence.
*/
#define DLL_API
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
#include <cmath>
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "SineArrayGAM.h"
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe {
SineArrayGAM::SineArrayGAM() :
GAM(),
frequency(1.0),
amplitude(1.0),
offset(0.0),
phase(0.0),
samplingRate(1000000.0),
nElements(0u),
sampleOffset(0ull),
outputBuf(NULL_PTR(float32 *)) {
}
SineArrayGAM::~SineArrayGAM() {
}
bool SineArrayGAM::Initialise(StructuredDataI &data) {
bool ok = GAM::Initialise(data);
if (ok) {
if (!data.Read("Frequency", frequency)) {
frequency = 1.0;
}
if (!data.Read("Amplitude", amplitude)) {
amplitude = 1.0;
}
if (!data.Read("Offset", offset)) {
offset = 0.0;
}
if (!data.Read("Phase", phase)) {
phase = 0.0;
}
if (!data.Read("SamplingRate", samplingRate)) {
samplingRate = 1000000.0;
}
if (samplingRate <= 0.0) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"SineArrayGAM: SamplingRate must be greater than zero");
ok = false;
}
}
return ok;
}
bool SineArrayGAM::Setup() {
bool ok = (GetNumberOfOutputSignals() == 1u);
if (!ok) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"SineArrayGAM: exactly one output signal is required");
return false;
}
uint32 sz = 0u;
ok = GetSignalByteSize(OutputSignals, 0u, sz);
if (ok) {
nElements = sz / static_cast<uint32>(sizeof(float32));
outputBuf = reinterpret_cast<float32 *>(GetOutputSignalMemory(0u));
ok = (outputBuf != NULL_PTR(float32 *)) && (nElements > 0u);
if (!ok) {
REPORT_ERROR(ErrorManagement::InitialisationError,
"SineArrayGAM: failed to resolve output signal memory");
}
}
return ok;
}
bool SineArrayGAM::Execute() {
static const float64 TWO_PI = 6.28318530717958647692;
const float64 twoPiF = TWO_PI * frequency;
const float64 invSr = 1.0 / samplingRate;
for (uint32 i = 0u; i < nElements; i++) {
float64 t = static_cast<float64>(sampleOffset + static_cast<uint64>(i)) * invSr;
outputBuf[i] = static_cast<float32>(amplitude * std::sin(twoPiF * t + phase) + offset);
}
sampleOffset += static_cast<uint64>(nElements);
return true;
}
CLASS_REGISTER(SineArrayGAM, "1.0")
} /* namespace MARTe */
@@ -0,0 +1,105 @@
/**
* @file SineArrayGAM.h
* @brief GAM that fills a float32 array with a continuous sinusoidal waveform.
* @date 15/05/2026
* @author Martino Ferrari
*
* @copyright 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
*
* @warning 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 permissions and limitations under the Licence.
*
* @details Each Execute() call fills one float32 output array with N samples of:
* v[k] = Amplitude * sin(2π * Frequency * (sampleOffset + k) / SamplingRate + Phase) + Offset
*
* The sampleOffset accumulates across calls so the waveform phase is continuous.
*
* Configuration:
* <pre>
* +MyGAM = {
* Class = SineArrayGAM
* Frequency = 1000.0 // Signal frequency in Hz (default 1.0)
* Amplitude = 1.0 // Signal amplitude (default 1.0)
* Offset = 0.0 // DC offset (default 0.0)
* Phase = 0.0 // Phase in radians (default 0.0)
* SamplingRate = 1000000.0 // Sample rate in Hz; must match UDPStreamer signal (default 1000000.0)
* OutputSignals = {
* Ch1 = { DataSource = DDB; Type = float32; NumberOfElements = 1000 }
* }
* }
* </pre>
*
* Exactly one output signal of type float32 is required.
*/
#ifndef SINEARRAYGAM_H_
#define SINEARRAYGAM_H_
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "CompilerTypes.h"
#include "GAM.h"
/*---------------------------------------------------------------------------*/
/* Class declaration */
/*---------------------------------------------------------------------------*/
namespace MARTe {
class SineArrayGAM : public GAM {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief Constructor. Sets safe defaults.
*/
SineArrayGAM();
/**
* @brief Destructor.
*/
virtual ~SineArrayGAM();
/**
* @brief Reads Frequency, Amplitude, Offset, Phase, SamplingRate from config.
*/
virtual bool Initialise(StructuredDataI &data);
/**
* @brief Resolves the output signal pointer and element count.
* @return true if exactly one float32 output signal is present.
*/
virtual bool Setup();
/**
* @brief Fills the output array with the next N sinusoidal samples.
* @return true always.
*/
virtual bool Execute();
private:
float64 frequency; /**< Signal frequency [Hz] */
float64 amplitude; /**< Signal amplitude */
float64 offset; /**< DC offset */
float64 phase; /**< Phase offset [radians] */
float64 samplingRate; /**< Sample rate [Hz] */
uint32 nElements; /**< Number of output elements per cycle */
uint64 sampleOffset; /**< Cumulative sample count for continuous phase */
float32 *outputBuf; /**< Pointer to the output signal memory */
};
} /* namespace MARTe */
#endif /* SINEARRAYGAM_H_ */