Improved uo and added timerarraygam for testing
This commit is contained in:
@@ -24,7 +24,8 @@
|
||||
|
||||
OBJSX=
|
||||
|
||||
SPB = SineArrayGAM.x
|
||||
SPB = SineArrayGAM.x \
|
||||
TimeArrayGAM.x
|
||||
|
||||
PACKAGE=Components
|
||||
ROOT_DIR=../../..
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
include Makefile.inc
|
||||
@@ -0,0 +1,28 @@
|
||||
OBJSX = TimeArrayGAM.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)/TimeArrayGAM$(LIBEXT) \
|
||||
$(BUILD_DIR)/TimeArrayGAM$(DLLEXT)
|
||||
echo $(OBJS)
|
||||
|
||||
-include depends.$(TARGET)
|
||||
|
||||
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @file TimeArrayGAM.cpp
|
||||
* @brief Source file for class TimeArrayGAM
|
||||
* @date 19/05/2026
|
||||
* @author Martino Ferrari
|
||||
*/
|
||||
|
||||
#define DLL_API
|
||||
|
||||
#include "AdvancedErrorManagement.h"
|
||||
#include "TimeArrayGAM.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
TimeArrayGAM::TimeArrayGAM() :
|
||||
GAM(),
|
||||
samplingRate(1000000.0),
|
||||
anchorIsFirst(true),
|
||||
nElements(0u),
|
||||
inputTime(NULL_PTR(uint32 *)),
|
||||
outputBuf(NULL_PTR(uint64 *)) {
|
||||
}
|
||||
|
||||
TimeArrayGAM::~TimeArrayGAM() {
|
||||
}
|
||||
|
||||
bool TimeArrayGAM::Initialise(StructuredDataI &data) {
|
||||
bool ok = GAM::Initialise(data);
|
||||
if (ok) {
|
||||
if (!data.Read("SamplingRate", samplingRate) || samplingRate <= 0.0) {
|
||||
REPORT_ERROR(ErrorManagement::InitialisationError,
|
||||
"TimeArrayGAM: SamplingRate > 0 is required.");
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
StreamString anchor;
|
||||
(void) data.Read("Anchor", anchor);
|
||||
if (anchor.Size() == 0u || anchor == "FirstSample") {
|
||||
anchorIsFirst = true; /* default */
|
||||
}
|
||||
else if (anchor == "LastSample") {
|
||||
anchorIsFirst = false;
|
||||
}
|
||||
else {
|
||||
REPORT_ERROR(ErrorManagement::InitialisationError,
|
||||
"TimeArrayGAM: Anchor must be 'FirstSample' or 'LastSample'.");
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TimeArrayGAM::Setup() {
|
||||
bool ok = (GetNumberOfInputSignals() == 1u) && (GetNumberOfOutputSignals() == 1u);
|
||||
if (!ok) {
|
||||
REPORT_ERROR(ErrorManagement::InitialisationError,
|
||||
"TimeArrayGAM: exactly one input and one output signal are required.");
|
||||
return false;
|
||||
}
|
||||
|
||||
inputTime = reinterpret_cast<uint32 *>(GetInputSignalMemory(0u));
|
||||
outputBuf = reinterpret_cast<uint64 *>(GetOutputSignalMemory(0u));
|
||||
ok = (inputTime != NULL_PTR(uint32 *)) && (outputBuf != NULL_PTR(uint64 *));
|
||||
if (!ok) {
|
||||
REPORT_ERROR(ErrorManagement::InitialisationError,
|
||||
"TimeArrayGAM: failed to resolve signal memory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 sz = 0u;
|
||||
ok = GetSignalByteSize(OutputSignals, 0u, sz);
|
||||
if (ok) {
|
||||
nElements = sz / static_cast<uint32>(sizeof(uint32));
|
||||
ok = (nElements > 0u);
|
||||
}
|
||||
if (!ok) {
|
||||
REPORT_ERROR(ErrorManagement::InitialisationError,
|
||||
"TimeArrayGAM: output signal must be a non-empty uint32 array.");
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TimeArrayGAM::Execute() {
|
||||
/* Period in nanoseconds — uint64 preserves sub-microsecond resolution
|
||||
* even at sampling rates > 1 MHz where the µs period would be < 1. */
|
||||
uint64 periodNs = static_cast<uint64>(1000000000.0 / samplingRate + 0.5);
|
||||
/* Input is uint32 microseconds (LinuxTimer); convert to nanoseconds. */
|
||||
uint64 anchorNs = static_cast<uint64>(*inputTime) * 1000u;
|
||||
|
||||
if (anchorIsFirst) {
|
||||
/* out[k] = anchorNs + k * periodNs */
|
||||
for (uint32 k = 0u; k < nElements; k++) {
|
||||
outputBuf[k] = anchorNs + static_cast<uint64>(k) * periodNs;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* out[k] = anchorNs - (N-1-k) * periodNs */
|
||||
for (uint32 k = 0u; k < nElements; k++) {
|
||||
outputBuf[k] = anchorNs - static_cast<uint64>(nElements - 1u - k) * periodNs;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CLASS_REGISTER(TimeArrayGAM, "1.0")
|
||||
|
||||
} /* namespace MARTe */
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @file TimeArrayGAM.h
|
||||
* @brief GAM that expands a scalar timer value into a per-sample uint32 time array.
|
||||
* @date 19/05/2026
|
||||
* @author Martino Ferrari
|
||||
*
|
||||
* @details Each Execute() call reads one uint32 scalar input (time in microseconds,
|
||||
* e.g. from LinuxTimer) and fills a uint32[N] output array where element[k] holds
|
||||
* the reconstructed timestamp of sample k:
|
||||
*
|
||||
* Anchor = FirstSample: out[k] = input + k * period_us
|
||||
* Anchor = LastSample: out[k] = input - (N-1-k) * period_us
|
||||
*
|
||||
* The resulting time array is suitable as the TimeSignal for a UDPStreamer signal
|
||||
* configured with TimeMode = FullArray, providing exact per-sample timestamps.
|
||||
*
|
||||
* Configuration:
|
||||
* <pre>
|
||||
* +TimeArrayGAM1 = {
|
||||
* Class = TimeArrayGAM
|
||||
* SamplingRate = 1000000.0 // Sample rate in Hz (must match data signal)
|
||||
* Anchor = FirstSample // FirstSample (default) or LastSample
|
||||
* InputSignals = {
|
||||
* Time = { DataSource = DDB; Type = uint32 }
|
||||
* }
|
||||
* OutputSignals = {
|
||||
* TimeArray = { DataSource = DDB; Type = uint32; NumberOfElements = 1000 }
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Exactly one uint32 input signal and one uint32 output array are required.
|
||||
*/
|
||||
|
||||
#ifndef TIMEARRAYGAM_H_
|
||||
#define TIMEARRAYGAM_H_
|
||||
|
||||
#include "CompilerTypes.h"
|
||||
#include "GAM.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
class TimeArrayGAM : public GAM {
|
||||
public:
|
||||
CLASS_REGISTER_DECLARATION()
|
||||
|
||||
TimeArrayGAM();
|
||||
virtual ~TimeArrayGAM();
|
||||
|
||||
virtual bool Initialise(StructuredDataI &data);
|
||||
virtual bool Setup();
|
||||
virtual bool Execute();
|
||||
|
||||
private:
|
||||
float64 samplingRate; /**< Sample rate [Hz] */
|
||||
bool anchorIsFirst; /**< true = FirstSample anchor, false = LastSample */
|
||||
uint32 nElements; /**< Number of output elements */
|
||||
uint32 *inputTime; /**< Pointer to scalar input (microseconds, uint32 from LinuxTimer) */
|
||||
uint64 *outputBuf; /**< Pointer to output array (nanoseconds, uint64) */
|
||||
};
|
||||
|
||||
} /* namespace MARTe */
|
||||
|
||||
#endif /* TIMEARRAYGAM_H_ */
|
||||
Reference in New Issue
Block a user