Testing UART output

Signed-off-by: Bernardo Carvalho <bernardo.carvalho@tecnico.ulisboa.pt>
This commit is contained in:
2025-10-18 00:35:57 +01:00
parent ba6c07987e
commit 39176574a5
2 changed files with 497 additions and 483 deletions

View File

@@ -30,8 +30,8 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> // for close()
#include <math.h> #include <math.h>
#include <unistd.h> // for close()
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Project header includes */ /* Project header includes */
@@ -48,355 +48,365 @@
/* Method definitions */ /* Method definitions */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
namespace MARTe { namespace MARTe {
const float32 DAC_RANGE = 20.0; const float32 DAC_RANGE = 20.0;
const float32 ATCA_IOP_MAX_DAC_RANGE = 20.0; // const float32 ATCA_IOP_MAX_DAC_RANGE = 20.0;
UARTOutput::UARTOutput() : UARTOutput::UARTOutput() : DataSourceI(), MessageI() {
DataSourceI(), // boardFileDescriptor = -1;
MessageI() { // numberOfDACsEnabled = 0u;
//boardFileDescriptor = -1; // isMaster = 0u;
//numberOfDACsEnabled = 0u; // deviceName = "";
//isMaster = 0u; // boardId = 2u;
//deviceName = ""; triggerSet = false;
//boardId = 2u; uint32 n;
triggerSet = false; // for (n = 0u; n < ATCA_IOP_MAX_DAC_CHANNELS; n++) {
uint32 n; // dacEnabled[n] = false;
//for (n = 0u; n < ATCA_IOP_MAX_DAC_CHANNELS; n++) { outputRange = DAC_RANGE;
//dacEnabled[n] = false; //}
outputRange = ATCA_IOP_MAX_DAC_RANGE;
//}
//channelsMemory = NULL_PTR(float32 *); // channelsMemory = NULL_PTR(float32 *);
channelMemory = 0.0;//NULL_PTR(float32 *); channelValue = 0.0; // NULL_PTR(float32 *);
filter = ReferenceT<RegisteredMethodsMessageFilter>(GlobalObjectsDatabase::Instance()->GetStandardHeap()); filter = ReferenceT<RegisteredMethodsMessageFilter>(
filter->SetDestination(this); GlobalObjectsDatabase::Instance()->GetStandardHeap());
ErrorManagement::ErrorType ret = MessageI::InstallMessageFilter(filter); filter->SetDestination(this);
if (!ret.ErrorsCleared()) { ErrorManagement::ErrorType ret = MessageI::InstallMessageFilter(filter);
REPORT_ERROR(ErrorManagement::FatalError, "Failed to install message filters"); if (!ret.ErrorsCleared()) {
} REPORT_ERROR(ErrorManagement::FatalError,
} "Failed to install message filters");
/*lint -e{1551} the destructor must guarantee that the Timer SingleThreadService is stopped.*/
UARTOutput::~UARTOutput() {
if (boardFileDescriptor != -1) {
uint32 statusReg = 0;
//REPORT_ERROR(ErrorManagement::Information, " Close Device Status Reg %d, 0x%x", rc, statusReg);
close(boardFileDescriptor);
REPORT_ERROR(ErrorManagement::Information, "Close device %d OK. Status Reg 0x%x,", boardFileDescriptor, statusReg);
}
/*
if (channelsMemory != NULL_PTR(float32 *)) {
delete[] channelsMemory;
}
*/
} }
}
bool UARTOutput::AllocateMemory() { /*lint -e{1551} the destructor must guarantee that the Timer SingleThreadService
return true; * is stopped.*/
UARTOutput::~UARTOutput() {
// REPORT_ERROR(ErrorManagement::Information, " Close Device Status Reg %d,
// 0x%x", rc, statusReg); close(boardFileDescriptor);
serial.Close();
REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "Close %s OK.",
portName);
/*
if (channelsMemory != NULL_PTR(float32 *)) {
delete[] channelsMemory;
} }
*/
}
uint32 UARTOutput::GetNumberOfMemoryBuffers() { bool UARTOutput::AllocateMemory() { return true; }
return 1u;
uint32 UARTOutput::GetNumberOfMemoryBuffers() { return 1u; }
/*lint -e{715} [MISRA C++ Rule 0-1-11], [MISRA C++ Rule 0-1-12]. Justification:
* The memory buffer is independent of the bufferIdx.*/
bool UARTOutput::GetSignalMemoryBuffer(const uint32 signalIdx,
const uint32 bufferIdx,
void *&signalAddress) {
bool ok = (signalIdx < (UART_MAX_CHANNELS));
if (ok) {
// if (channelsMemory != NULL_PTR(float32 *)) {
signalAddress = &channelValue;
//}
} }
return ok;
}
/*lint -e{715} [MISRA C++ Rule 0-1-11], [MISRA C++ Rule 0-1-12]. Justification: The memory buffer is independent of the bufferIdx.*/ const char8 *UARTOutput::GetBrokerName(StructuredDataI &data,
bool UARTOutput::GetSignalMemoryBuffer(const uint32 signalIdx, const uint32 bufferIdx, void*& signalAddress) { const SignalDirection direction) {
bool ok = (signalIdx < (UART_MAX_CHANNELS)); const char8 *brokerName = NULL_PTR(const char8 *);
if (ok) { if (direction == OutputSignals) {
//if (channelsMemory != NULL_PTR(float32 *)) {
signalAddress = &channelMemory;
//}
}
return ok;
}
const char8* UARTOutput::GetBrokerName(StructuredDataI& data, const SignalDirection direction) {
const char8 *brokerName = NULL_PTR(const char8 *);
if (direction == OutputSignals) {
uint32 trigger = 0u;
if (!data.Read("Trigger", trigger)) {
trigger = 0u;
}
if (trigger == 1u) {
brokerName = "MemoryMapSynchronisedOutputBroker";
triggerSet = true;
}
else {
brokerName = "MemoryMapOutputBroker";
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "DataSource not compatible with InputSignals");
}
return brokerName;
}
bool UARTOutput::GetInputBrokers(ReferenceContainer& inputBrokers, const char8* const functionName, void* const gamMemPtr) {
return false;
}
bool UARTOutput::GetOutputBrokers(ReferenceContainer& outputBrokers, const char8* const functionName, void* const gamMemPtr) {
//Check if there is a Trigger signal for this function.
uint32 functionIdx = 0u;
uint32 nOfFunctionSignals = 0u;
uint32 i;
bool triggerGAM = false;
bool ok = GetFunctionIndex(functionIdx, functionName);
if (ok) {
ok = GetFunctionNumberOfSignals(OutputSignals, functionIdx, nOfFunctionSignals);
}
uint32 trigger = 0u; uint32 trigger = 0u;
for (i = 0u; (i < nOfFunctionSignals) && (ok) && (!triggerGAM); i++) { if (!data.Read("Trigger", trigger)) {
ok = GetFunctionSignalTrigger(OutputSignals, functionIdx, i, trigger); trigger = 0u;
triggerGAM = (trigger == 1u);
} }
if ((ok) && (triggerGAM)) {
ReferenceT<MemoryMapSynchronisedOutputBroker> broker("MemoryMapSynchronisedOutputBroker");
ok = broker.IsValid();
if (ok) { if (trigger == 1u) {
ok = broker->Init(OutputSignals, *this, functionName, gamMemPtr); brokerName = "MemoryMapSynchronisedOutputBroker";
} triggerSet = true;
if (ok) { } else {
ok = outputBrokers.Insert(broker); brokerName = "MemoryMapOutputBroker";
} }
//Must also add the signals which are not triggering but that belong to the same GAM... } else {
if (ok) { REPORT_ERROR(ErrorManagement::ParametersError,
if (nOfFunctionSignals > 1u) { "DataSource not compatible with InputSignals");
ReferenceT<MemoryMapOutputBroker> brokerNotSync("MemoryMapOutputBroker"); }
ok = brokerNotSync.IsValid(); return brokerName;
if (ok) { }
ok = brokerNotSync->Init(OutputSignals, *this, functionName, gamMemPtr); bool UARTOutput::GetInputBrokers(ReferenceContainer &inputBrokers,
} const char8 *const functionName,
if (ok) { void *const gamMemPtr) {
ok = outputBrokers.Insert(brokerNotSync); return false;
} }
bool UARTOutput::GetOutputBrokers(ReferenceContainer &outputBrokers,
const char8 *const functionName,
void *const gamMemPtr) {
// Check if there is a Trigger signal for this function.
uint32 functionIdx = 0u;
uint32 nOfFunctionSignals = 0u;
uint32 i;
bool triggerGAM = false;
bool ok = GetFunctionIndex(functionIdx, functionName);
if (ok) {
ok = GetFunctionNumberOfSignals(OutputSignals, functionIdx,
nOfFunctionSignals);
}
uint32 trigger = 0u;
for (i = 0u; (i < nOfFunctionSignals) && (ok) && (!triggerGAM); i++) {
ok = GetFunctionSignalTrigger(OutputSignals, functionIdx, i, trigger);
triggerGAM = (trigger == 1u);
}
if ((ok) && (triggerGAM)) {
ReferenceT<MemoryMapSynchronisedOutputBroker> broker(
"MemoryMapSynchronisedOutputBroker");
ok = broker.IsValid();
if (ok) {
ok = broker->Init(OutputSignals, *this, functionName, gamMemPtr);
}
if (ok) {
ok = outputBrokers.Insert(broker);
}
// Must also add the signals which are not triggering but that belong to the
// same GAM...
if (ok) {
if (nOfFunctionSignals > 1u) {
ReferenceT<MemoryMapOutputBroker> brokerNotSync(
"MemoryMapOutputBroker");
ok = brokerNotSync.IsValid();
if (ok) {
ok = brokerNotSync->Init(OutputSignals, *this, functionName,
gamMemPtr);
}
if (ok) {
ok = outputBrokers.Insert(brokerNotSync);
} }
} }
} }
} else {
ReferenceT<MemoryMapOutputBroker> brokerNotSync("MemoryMapOutputBroker");
ok = brokerNotSync.IsValid();
if (ok) {
ok = brokerNotSync->Init(OutputSignals, *this, functionName, gamMemPtr);
}
if (ok) {
ok = outputBrokers.Insert(brokerNotSync);
}
}
return ok;
}
/*lint -e{715} [MISRA C++ Rule 0-1-11], [MISRA C++ Rule 0-1-12]. Justification:
* the counter and the timer are always reset irrespectively of the states being
* changed.*/
bool UARTOutput::PrepareNextState(const char8 *const currentStateName,
const char8 *const nextStateName) {
return true;
}
bool UARTOutput::Initialise(StructuredDataI &data) {
bool ok = DataSourceI::Initialise(data);
// StreamString portName;
if (ok) {
ok = data.Read("PortName", portName);
if (ok) {
REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
"The port name is set to %s", portName.Buffer());
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"The port name property shall be set");
}
}
uint32 baudRate = 0u;
if (ok) {
ok = data.Read("BaudRate", baudRate);
if (ok) {
REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
"The baud rate is set to %d", baudRate);
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"The baud rate property shall be set");
}
}
if (ok) {
if (!data.Read("Timeout", timeout)) {
timeout = 1000u;
}
}
/*
if (ok) {
ok = data.Read("SerialTimeout", serialTimeout);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "The serial timeout is set to
%d", serialTimeout);
}
else { else {
ReferenceT<MemoryMapOutputBroker> brokerNotSync("MemoryMapOutputBroker"); REPORT_ERROR(ErrorManagement::ParametersError, "The serial timeout
ok = brokerNotSync.IsValid(); property shall be set");
if (ok) {
ok = brokerNotSync->Init(OutputSignals, *this, functionName, gamMemPtr);
}
if (ok) {
ok = outputBrokers.Insert(brokerNotSync);
}
} }
return ok; }
*/
if (ok) {
ok = serial.SetSpeed(baudRate);
}
if (ok) {
ok = serial.Open(portName.Buffer());
}
if (!ok) {
REPORT_ERROR_PARAMETERS(ErrorManagement::ParametersError,
"The port %s Not opened.", portName);
} }
/*lint -e{715} [MISRA C++ Rule 0-1-11], [MISRA C++ Rule 0-1-12]. Justification: the counter and the timer are always reset irrespectively of the states being changed.*/ // Get individual signal parameters
bool UARTOutput::PrepareNextState(const char8* const currentStateName, const char8* const nextStateName) { uint32 i = 0u;
return true; if (ok) {
} ok = data.MoveRelative("Signals");
if (!ok) {
bool UARTOutput::Initialise(StructuredDataI& data) { REPORT_ERROR(ErrorManagement::ParametersError,
bool ok = DataSourceI::Initialise(data); "Could not move to the Signals section");
StreamString portName;
if (ok) {
ok = data.Read("PortName", portName);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "The port name is set to %s", portName.Buffer());
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "The port name property shall be set");
}
} }
uint32 baudRate = 0u; // Do not allow to add signals in run-time
if (ok) { if (ok) {
ok = data.Read("BaudRate", baudRate); ok = signalsDatabase.MoveRelative("Signals");
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "The baud rate is set to %d", baudRate);
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "The baud rate property shall be set");
}
} }
if (ok) { if (ok) {
if (!data.Read("Timeout", timeout)) { ok = signalsDatabase.Write("Locked", 1u);
timeout = 1000u;
}
} }
if (ok) { if (ok) {
ok = data.Read("SerialTimeout", serialTimeout); ok = signalsDatabase.MoveToAncestor(1u);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "The serial timeout is set to %d", serialTimeout);
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "The serial timeout property shall be set");
}
} }
if (ok) { // while ((i < ATCA_IOP_MAX_DAC_CHANNELS) && (ok)) {
ok = serial.SetSpeed(baudRate); if (data.MoveRelative(data.GetChildName(0))) {
} // uint32 channelId;
if (ok) { float64 range;
ok = serial.Open(portName.Buffer()); ok = data.Read("OutputRange", range);
}
//Get individual signal parameters
uint32 i = 0u;
if (ok) {
ok = data.MoveRelative("Signals");
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not move to the Signals section");
}
//Do not allow to add signals in run-time
if (ok) { if (ok) {
ok = signalsDatabase.MoveRelative("Signals"); // if (data.Read("OutputRange", range)) {
} ok = (range > 0.0) && (range <= DAC_RANGE);
if (ok) { if (!ok) {
ok = signalsDatabase.Write("Locked", 1u); REPORT_ERROR(ErrorManagement::ParametersError,
} "Invalid OutputRange specified.");
if (ok) { }
ok = signalsDatabase.MoveToAncestor(1u); if (ok) {
} outputRange = range;
// while ((i < ATCA_IOP_MAX_DAC_CHANNELS) && (ok)) { REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
if (data.MoveRelative(data.GetChildName(0))) { " Parameter DAC Output Range %f", range);
//uint32 channelId; // dacEnabled[i] = true;
float32 range; // numberOfDACsEnabled++;
ok = data.Read("OutputRange", range); }
if (ok) { } else {
//if (data.Read("OutputRange", range)) { REPORT_ERROR(ErrorManagement::ParametersError,
ok = (range > 0.0) && (range <= ATCA_IOP_MAX_DAC_RANGE); "The OutputRange shall be specified.");
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Invalid OutputRange specified.");
}
if (ok) {
outputRange = range;
REPORT_ERROR_PARAMETERS(ErrorManagement::Information, " Parameter DAC Output Range %f", range);
//dacEnabled[i] = true;
//numberOfDACsEnabled++;
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "The OutputRange shall be specified.");
}
if (ok) {
ok = data.MoveToAncestor(1u);
}
}
} }
if (ok) { if (ok) {
ok = data.MoveToAncestor(1u); ok = data.MoveToAncestor(1u);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not move to the parent section");
}
} }
//REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "numberOfDACsEnabled %d", numberOfDACsEnabled);
return ok;
} }
}
if (ok) {
ok = data.MoveToAncestor(1u);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Could not move to the parent section");
}
}
bool UARTOutput::SetConfiguredDatabase(StructuredDataI& data) { // REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "numberOfDACsEnabled
uint32 i; // %d", numberOfDACsEnabled);
bool ok = DataSourceI::SetConfiguredDatabase(data); return ok;
}
bool UARTOutput::SetConfiguredDatabase(StructuredDataI &data) {
uint32 i;
bool ok = DataSourceI::SetConfiguredDatabase(data);
if (ok) {
ok = triggerSet;
}
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"At least one Trigger signal shall be set.");
}
if (ok) {
// for (i = 0u; (i < numberOfDACsEnabled) && (ok); i++) {
ok = (GetSignalType(0u) == Float32Bit);
//}
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"All the DAC signals shall be of type Float32Bit");
}
}
uint32 nOfFunctions = GetNumberOfFunctions();
uint32 functionIdx;
// Check that the number of samples for all the signals is one
for (functionIdx = 0u; (functionIdx < nOfFunctions) && (ok); functionIdx++) {
uint32 nOfSignals = 0u;
ok = GetFunctionNumberOfSignals(OutputSignals, functionIdx, nOfSignals);
for (i = 0u; (i < nOfSignals) && (ok); i++) {
uint32 nSamples = 0u;
ok = GetFunctionSignalSamples(OutputSignals, functionIdx, i, nSamples);
if (ok) { if (ok) {
ok = triggerSet; ok = (nSamples == 1u);
} }
if (!ok) { if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "At least one Trigger signal shall be set."); REPORT_ERROR(ErrorManagement::ParametersError,
"The number of samples shall be exactly one");
} }
if (ok) {
//for (i = 0u; (i < numberOfDACsEnabled) && (ok); i++) {
ok = (GetSignalType(0u) == Float32Bit);
//}
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "All the DAC signals shall be of type Float32Bit");
}
}
uint32 nOfFunctions = GetNumberOfFunctions();
uint32 functionIdx;
//Check that the number of samples for all the signals is one
for (functionIdx = 0u; (functionIdx < nOfFunctions) && (ok); functionIdx++) {
uint32 nOfSignals = 0u;
ok = GetFunctionNumberOfSignals(OutputSignals, functionIdx, nOfSignals);
for (i = 0u; (i < nOfSignals) && (ok); i++) {
uint32 nSamples = 0u;
ok = GetFunctionSignalSamples(OutputSignals, functionIdx, i, nSamples);
if (ok) {
ok = (nSamples == 1u);
}
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "The number of samples shall be exactly one");
}
}
}
StreamString fullDeviceName;
//Configure the board
if (ok) {
ok = fullDeviceName.Printf("%s_dac_%d", deviceName.Buffer(), boardId);
//ok = fullDeviceName.Printf("%s", deviceName.Buffer());
}
if (ok) {
ok = fullDeviceName.Seek(0LLU);
}
if (ok) {
boardFileDescriptor = open(fullDeviceName.Buffer(), O_RDWR);
ok = (boardFileDescriptor > -1);
if (!ok) {
REPORT_ERROR_PARAMETERS(ErrorManagement::ParametersError, "Could not open device %s", fullDeviceName);
}
else
REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "Open device %s OK", fullDeviceName);
}
if (ok) {
//Allocate memory
//channelsMemory = new float32[ATCA_IOP_MAX_DAC_CHANNELS];
}
return ok;
} }
bool UARTOutput::Synchronise() {
uint32 i;
int32 w = 24;
bool ok = true;
//if (channelsMemory != NULL_PTR(float32 *)) {
// value = channelsMemory[0] / DAC_RANGE;
//for (i = 0u; (i < 2u) && (ok); i++) {
//for (i = 0u; (i < numberOfDACsEnabled ) && (ok); i++) {
float32 value = channelMemory / outputRange;
//w = SetDacReg(i, value);
write(boardFileDescriptor, &w, 4);
// value = channelsMemory[1] / DAC_RANGE;
//value = channelsMemory[1] / DAC_RANGE * pow(2,17);
// w = SetDacReg(1, value);
//w = 0x000FFFFF & static_cast<uint32>(value);
// write(boardFileDescriptor, &w, 4);
//REPORT_ERROR(ErrorManagement::Information, " Writing DAC 0 0x%x", w);
/*
w = dacValues[i];
}
*/
return ok;
}
/*
int32 UARTOutput::SetDacReg(uint32 channel, float32 val) const {
if (val > 1.0)
val = 1.0;
if (val < -1.0)
val = -1.0;
int32 dacReg = static_cast<int32>(val * pow(2,17));
if (dacReg > 0x1FFFF) // 131071
dacReg = 0x1FFFF;
if (dacReg < -131072) // -0x20000
dacReg = -131072;
dacReg &= 0x0003FFFF; // keep 18 lsb
dacReg |= (0xF & channel) << 28;
return dacReg;
}
*/
CLASS_REGISTER(UARTOutput, "1.0")
} }
// vim: syntax=cpp ts=2 sw=2 sts=2 sr et
return ok;
}
bool UARTOutput::Synchronise() {
uint32 i;
int32 w = 24;
bool ok = true;
char8 text[] = "ola";
// if (channelsMemory != NULL_PTR(float32 *)) {
// value = channelsMemory[0] / DAC_RANGE;
// for (i = 0u; (i < numberOfDACsEnabled ) && (ok); i++) {
int32 ser_value = channelValue / outputRange * 1000000.0;
REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
"Synchronise called. value: %f, %d", channelValue,
ser_value);
// w = SetDacReg(i, value);
char8 *data = reinterpret_cast<char8 *>(&ser_value);
serial.Write(data, sizeof(int32));
// serial.Write(text, 4);
// write(boardFileDescriptor, &w, 4);
// value = channelsMemory[1] / DAC_RANGE;
// value = channelsMemory[1] / DAC_RANGE * pow(2,17);
// w = SetDacReg(1, value);
// w = 0x000FFFFF & static_cast<uint32>(value);
// write(boardFileDescriptor, &w, 4);
// REPORT_ERROR(ErrorManagement::Information, " Writing DAC 0 0x%x", w);
/*
w = dacValues[i];
}
*/
return ok;
}
/*
int32 UARTOutput::SetDacReg(uint32 channel, float32 val) const {
if (val > 1.0)
val = 1.0;
if (val < -1.0)
val = -1.0;
int32 dacReg = static_cast<int32>(val * pow(2,17));
if (dacReg > 0x1FFFF) // 131071
dacReg = 0x1FFFF;
if (dacReg < -131072) // -0x20000
dacReg = -131072;
dacReg &= 0x0003FFFF; // keep 18 lsb
dacReg |= (0xF & channel) << 28;
return dacReg;
}
*/
CLASS_REGISTER(UARTOutput, "1.0")
} // namespace MARTe
// vim: syntax=cpp ts=2 sw=2 sts=2 sr et

View File

@@ -37,42 +37,44 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include "BasicUART.h" #include "BasicUART.h"
#include "DataSourceI.h" #include "DataSourceI.h"
#include "EventSem.h"
#include "EmbeddedServiceMethodBinderI.h" #include "EmbeddedServiceMethodBinderI.h"
#include "SingleThreadService.h" #include "EventSem.h"
#include "MessageI.h" #include "MessageI.h"
#include "RegisteredMethodsMessageFilter.h" #include "RegisteredMethodsMessageFilter.h"
#include "SingleThreadService.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Class declaration */ /* Class declaration */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
namespace MARTe { namespace MARTe {
/** /**
* The number of signals * The number of signals
*/ */
const uint32 ATCA_IOP_N_DACs = 2u; // const uint32 ATCA_IOP_N_DACs = 2u;
const uint32 UART_MAX_CHANNELS = 1u; const uint32 UART_MAX_CHANNELS = 1u;
/** /**
* @brief A DataSource which provides an analogue output interface to the ATCA IOP boards. * @brief A DataSource which provides an analogue output interface to the ATCA
IOP boards.
* @details The configuration syntax is (names are only given as an example): * @details The configuration syntax is (names are only given as an example):
* *
* <pre> * <pre>
* +AtcaIop_0_DAC = { * +AtcaIop_UartOut = {
* Class = AtcaIop::UARTOutput * Class = AtcaIop::UARTOutput
* DeviceName = "/dev/atca_v6_dac_2" //Mandatory * PortName = "/dev/ttyUSB0" //Name of the UART port, Mandatory
* PortName = "/dev/ttyUSB0" //Name of the UART port
* BaudRate = 115200 //BAUD UART rate * BaudRate = 115200 //BAUD UART rate
* Timeout = 200000 //Maximum time to wait for data * //Timeout = 200000 //Maximum time to wait for data
* CPUMask = 8 //Affinity of the CPU of where to read data from * CPUMask = 8 //Affinity of the CPU of where to read data from
* Signals = { * Signals = {
* DAC0_0 = { * SerialOut = {
* Type = float32 //Mandatory. Only type that is supported. * Type = float32//Mandatory. Only type that is supported.
* OutputRange = 10.0 //Mandatory. The channel Module Output Range in volt. * OutputRange = 10.0 //Mandatory. The channel Module Output Range
* //OutputPolarity = Bipolar //Optional. Possible values: Bipolar, Unipolar. Default value Unipolar. in volt.
* //OutputPolarity = Bipolar //Optional. Possible values: Bipolar,
Unipolar. Default value Unipolar.
* } * }
* Packet = { //Actual data to write * Packet = { //Actual data to write
* Type = uint8 * Type = uint8
@@ -82,180 +84,182 @@ namespace MARTe {
* } * }
* } * }
* </pre> * </pre>
* Note that at least one of the GAMs writing to this DataSource must have set one of the signals with Trigger=1 (which forces the writing of all the signals to the DAC). * Note that at least one of the GAMs writing to this DataSource must have set
one of the signals with Trigger=1 (which forces the writing of all the signals
to the DAC).
*/ */
class UARTOutput: public DataSourceI, public MessageI { class UARTOutput : public DataSourceI, public MessageI {
public: public:
CLASS_REGISTER_DECLARATION() CLASS_REGISTER_DECLARATION()
/** /**
* @brief Default constructor * @brief Default constructor
* @post * @post
* Counter = 0 * Counter = 0
* Time = 0 * Time = 0
*/ */
UARTOutput (); UARTOutput();
/** /**
* @brief Destructor. Stops the EmbeddedThread. * @brief Destructor. Stops the EmbeddedThread.
*/ */
virtual ~UARTOutput(); virtual ~UARTOutput();
/** /**
* @brief See DataSourceI::AllocateMemory. * @brief See DataSourceI::AllocateMemory.
* * @return true. * * @return true.
*/ */
virtual bool AllocateMemory(); virtual bool AllocateMemory();
/** /**
gg* @brief See DataSourceI::GetNumberOfMemoryBuffers. gg* @brief See DataSourceI::GetNumberOfMemoryBuffers.
* @return 1. * @return 1.
*/ */
virtual uint32 GetNumberOfMemoryBuffers(); virtual uint32 GetNumberOfMemoryBuffers();
/** /**
* @brief See DataSourceI::GetSignalMemoryBuffer. * @brief See DataSourceI::GetSignalMemoryBuffer.
*/ */
virtual bool GetSignalMemoryBuffer(const uint32 signalIdx, virtual bool GetSignalMemoryBuffer(const uint32 signalIdx,
const uint32 bufferIdx, const uint32 bufferIdx,
void *&signalAddress); void *&signalAddress);
/**
* @brief See DataSourceI::GetNumberOfMemoryBuffers.
* @details Only OutputSignals are supported.
* @return MemoryMapSynchronisedOutputBroker if Trigger == 1 for any of the
* signals, MemoryMapOutputBroker otherwise.
*/
virtual const char8 *GetBrokerName(StructuredDataI &data,
const SignalDirection direction);
/** /**
* @brief See DataSourceI::GetNumberOfMemoryBuffers. * @brief See DataSourceI::GetInputBrokers.
* @details Only OutputSignals are supported. * @return false.
* @return MemoryMapSynchronisedOutputBroker if Trigger == 1 for any of the signals, MemoryMapOutputBroker otherwise. */
*/ virtual bool GetInputBrokers(ReferenceContainer &inputBrokers,
virtual const char8 *GetBrokerName(StructuredDataI &data, const SignalDirection direction); const char8 *const functionName,
void *const gamMemPtr);
/** /**
* @brief See DataSourceI::GetInputBrokers. * @brief See DataSourceI::GetOutputBrokers.
* @return false. * @details If the functionName is one of the functions which requested a
*/ * Trigger, it adds a MemoryMapSynchronisedOutputBroker instance to the
virtual bool GetInputBrokers(ReferenceContainer &inputBrokers, * outputBrokers, otherwise it adds a MemoryMapOutputBroker instance to the
const char8* const functionName, * outputBrokers.
void * const gamMemPtr); * @param[out] outputBrokers where the BrokerI instances have to be added to.
* @param[in] functionName name of the function being queried.
* @param[in] gamMemPtr the GAM memory where the signals will be read from.
* @return true if the outputBrokers can be successfully configured.
*/
virtual bool GetOutputBrokers(ReferenceContainer &outputBrokers,
const char8 *const functionName,
void *const gamMemPtr);
/** /**
* @brief See DataSourceI::GetOutputBrokers. * @brief See StatefulI::PrepareNextState.
* @details If the functionName is one of the functions which requested a Trigger, * @details NOOP.
* it adds a MemoryMapSynchronisedOutputBroker instance to the outputBrokers, * @return true.
* otherwise it adds a MemoryMapOutputBroker instance to the outputBrokers. */
* @param[out] outputBrokers where the BrokerI instances have to be added to. virtual bool PrepareNextState(const char8 *const currentStateName,
* @param[in] functionName name of the function being queried. const char8 *const nextStateName);
* @param[in] gamMemPtr the GAM memory where the signals will be read from.
* @return true if the outputBrokers can be successfully configured.
*/
virtual bool GetOutputBrokers(ReferenceContainer &outputBrokers,
const char8* const functionName,
void * const gamMemPtr);
/**
* @brief Loads and verifies the configuration parameters detailed in the
* class description.
* @return true if all the mandatory parameters are correctly specified and if
* the specified optional parameters have valid values.
*/
/** virtual bool Initialise(StructuredDataI &data);
* @brief See StatefulI::PrepareNextState.
* @details NOOP.
* @return true.
*/
virtual bool PrepareNextState(const char8 * const currentStateName,
const char8 * const nextStateName);
/**
* @brief Final verification of all the parameters and setup of the board
* configuration.
* @details This method verifies that all the parameters (e.g. number of
* samples) requested by the GAMs interacting with this DataSource are valid
* and consistent with the board parameters set during the initialisation
* phase. In particular the following conditions shall be met:
* - At least one triggering signal was requested by a GAM (with the property
* Trigger = 1)
* - All the DAC channels have type float32.
* - The number of samples of all the DAC channels is exactly one.
* @return true if all the parameters are valid and consistent with the board
* parameters and if the board can be successfully configured with these
* parameters.
*/
virtual bool SetConfiguredDatabase(StructuredDataI &data);
/** /**
* @brief Loads and verifies the configuration parameters detailed in the class description. * @details Writes the value of all the DAC channels to the board.
* @return true if all the mandatory parameters are correctly specified and if the specified optional parameters have valid values. * @return true if the writing of all the channels is successful.
*/ */
virtual bool Synchronise();
virtual bool Initialise(StructuredDataI & data); private:
/**
* The board device name
*/
StreamString portName;
/**
* The board identifier
*/
uint32 boardId;
/**
* The board file descriptor
*/
// int32 boardFileDescriptor;
/**
* The UART interface.
*/
BasicUART serial;
/**
* Timeout to wait for data to be available.
*/
// uint32 serialTimeout;
/** /**
* @brief Final verification of all the parameters and setup of the board configuration. */
* @details This method verifies that all the parameters (e.g. number of samples) requested by the GAMs interacting with this DataSource uint32 timeout;
* are valid and consistent with the board parameters set during the initialisation phase.
* In particular the following conditions shall be met:
* - At least one triggering signal was requested by a GAM (with the property Trigger = 1)
* - All the DAC channels have type float32.
* - The number of samples of all the DAC channels is exactly one.
* @return true if all the parameters are valid and consistent with the board parameters and if the board can be successfully configured with
* these parameters.
*/
virtual bool SetConfiguredDatabase(StructuredDataI & data);
/**
* DAC values
*/
// int32 dacValues[ATCA_IOP_N_DACs];
/** /**
* @details Writes the value of all the DAC channels to the board. * The signal memory
* @return true if the writing of all the channels is successful. */
*/ float32 channelValue;
virtual bool Synchronise();
/**
* The DACs that are enabled
*/
// bool dacEnabled[ATCA_IOP_MAX_DAC_CHANNELS];
private: /**
/** * The board individual channel output ranges
* The board device name */
*/ float32 outputRange;
StreamString deviceName;
/**
* The board identifier
*/
uint32 boardId;
/**
* The board file descriptor
*/
int32 boardFileDescriptor;
/**
* The UART interface.
*/
BasicUART serial;
/** /**
* Timeout to wait for data to be available. * The number of enabled DACs
*/ */
uint32 serialTimeout; uint32 numberOfDACsEnabled;
/** /**
*/ * Filter to receive the RPC which allows to change the...
uint32 timeout; */
ReferenceT<RegisteredMethodsMessageFilter> filter;
/**
* True if at least one trigger was set.
*/
bool triggerSet;
// int32 SetDacReg(uint32 channel, float32 val) const;
/** };
* DAC values } // namespace MARTe
*/
int32 dacValues[ATCA_IOP_N_DACs];
/**
* The signal memory
*/
float32 channelMemory;
/**
* The DACs that are enabled
*/
// bool dacEnabled[ATCA_IOP_MAX_DAC_CHANNELS];
/**
* The board individual channel output ranges
*/
float32 outputRange;
/**
* The number of enabled DACs
*/
uint32 numberOfDACsEnabled;
/**
* Filter to receive the RPC which allows to change the...
*/
ReferenceT<RegisteredMethodsMessageFilter> filter;
/**
* True if at least one trigger was set.
*/
bool triggerSet;
//int32 SetDacReg(uint32 channel, float32 val) const;
};
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Inline method definitions */ /* Inline method definitions */