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

@@ -15,7 +15,7 @@
* 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,
* @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.
@@ -37,42 +37,44 @@
/*---------------------------------------------------------------------------*/
#include "BasicUART.h"
#include "DataSourceI.h"
#include "EventSem.h"
#include "EmbeddedServiceMethodBinderI.h"
#include "SingleThreadService.h"
#include "EventSem.h"
#include "MessageI.h"
#include "RegisteredMethodsMessageFilter.h"
#include "SingleThreadService.h"
/*---------------------------------------------------------------------------*/
/* Class declaration */
/*---------------------------------------------------------------------------*/
namespace MARTe {
/**
* The number of signals
*/
/**
* The number of signals
*/
const uint32 ATCA_IOP_N_DACs = 2u;
const uint32 UART_MAX_CHANNELS = 1u;
// const uint32 ATCA_IOP_N_DACs = 2u;
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):
*
* <pre>
* +AtcaIop_0_DAC = {
* +AtcaIop_UartOut = {
* Class = AtcaIop::UARTOutput
* DeviceName = "/dev/atca_v6_dac_2" //Mandatory
* PortName = "/dev/ttyUSB0" //Name of the UART port
* PortName = "/dev/ttyUSB0" //Name of the UART port, Mandatory
* 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
* Signals = {
* DAC0_0 = {
* Type = float32 //Mandatory. Only type that is supported.
* OutputRange = 10.0 //Mandatory. The channel Module Output Range in volt.
* //OutputPolarity = Bipolar //Optional. Possible values: Bipolar, Unipolar. Default value Unipolar.
* SerialOut = {
* Type = float32//Mandatory. Only type that is supported.
* OutputRange = 10.0 //Mandatory. The channel Module Output Range
in volt.
* //OutputPolarity = Bipolar //Optional. Possible values: Bipolar,
Unipolar. Default value Unipolar.
* }
* Packet = { //Actual data to write
* Type = uint8
@@ -82,180 +84,182 @@ namespace MARTe {
* }
* }
* </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 {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief Default constructor
* @post
* Counter = 0
* Time = 0
*/
UARTOutput ();
class UARTOutput : public DataSourceI, public MessageI {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief Default constructor
* @post
* Counter = 0
* Time = 0
*/
UARTOutput();
/**
* @brief Destructor. Stops the EmbeddedThread.
*/
virtual ~UARTOutput();
/**
* @brief Destructor. Stops the EmbeddedThread.
*/
virtual ~UARTOutput();
/**
* @brief See DataSourceI::AllocateMemory.
* * @return true.
*/
virtual bool AllocateMemory();
/**
* @brief See DataSourceI::AllocateMemory.
* * @return true.
*/
virtual bool AllocateMemory();
/**
gg* @brief See DataSourceI::GetNumberOfMemoryBuffers.
* @return 1.
*/
virtual uint32 GetNumberOfMemoryBuffers();
/**
gg* @brief See DataSourceI::GetNumberOfMemoryBuffers.
* @return 1.
*/
virtual uint32 GetNumberOfMemoryBuffers();
/**
* @brief See DataSourceI::GetSignalMemoryBuffer.
*/
virtual bool GetSignalMemoryBuffer(const uint32 signalIdx,
const uint32 bufferIdx,
void *&signalAddress);
/**
* @brief See DataSourceI::GetSignalMemoryBuffer.
*/
virtual bool GetSignalMemoryBuffer(const uint32 signalIdx,
const uint32 bufferIdx,
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.
* @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::GetInputBrokers.
* @return false.
*/
virtual bool GetInputBrokers(ReferenceContainer &inputBrokers,
const char8 *const functionName,
void *const gamMemPtr);
/**
* @brief See DataSourceI::GetInputBrokers.
* @return false.
*/
virtual bool GetInputBrokers(ReferenceContainer &inputBrokers,
const char8* const functionName,
void * const gamMemPtr);
/**
* @brief See DataSourceI::GetOutputBrokers.
* @details If the functionName is one of the functions which requested a
* Trigger, it adds a MemoryMapSynchronisedOutputBroker instance to the
* outputBrokers, otherwise it adds a MemoryMapOutputBroker instance to the
* outputBrokers.
* @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.
* @details If the functionName is one of the functions which requested a Trigger,
* it adds a MemoryMapSynchronisedOutputBroker instance to the outputBrokers,
* otherwise it adds a MemoryMapOutputBroker instance to the outputBrokers.
* @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 StatefulI::PrepareNextState.
* @details NOOP.
* @return true.
*/
virtual bool PrepareNextState(const char8 *const currentStateName,
const char8 *const nextStateName);
/**
* @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.
*/
/**
* @brief See StatefulI::PrepareNextState.
* @details NOOP.
* @return true.
*/
virtual bool PrepareNextState(const char8 * const currentStateName,
const char8 * const nextStateName);
virtual bool Initialise(StructuredDataI &data);
/**
* @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.
* @return true if all the mandatory parameters are correctly specified and if the specified optional parameters have valid values.
*/
/**
* @details Writes the value of all the DAC channels to the board.
* @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
* 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);
/**
*/
uint32 timeout;
/**
* DAC values
*/
// int32 dacValues[ATCA_IOP_N_DACs];
/**
* @details Writes the value of all the DAC channels to the board.
* @return true if the writing of all the channels is successful.
*/
virtual bool Synchronise();
/**
* The signal memory
*/
float32 channelValue;
/**
* The DACs that are enabled
*/
// bool dacEnabled[ATCA_IOP_MAX_DAC_CHANNELS];
private:
/**
* The board device name
*/
StreamString deviceName;
/**
* The board identifier
*/
uint32 boardId;
/**
* The board file descriptor
*/
int32 boardFileDescriptor;
/**
* The UART interface.
*/
BasicUART serial;
/**
* The board individual channel output ranges
*/
float32 outputRange;
/**
* Timeout to wait for data to be available.
*/
uint32 serialTimeout;
/**
* The number of enabled DACs
*/
uint32 numberOfDACsEnabled;
/**
*/
uint32 timeout;
/**
* Filter to receive the RPC which allows to change the...
*/
ReferenceT<RegisteredMethodsMessageFilter> filter;
/**
* True if at least one trigger was set.
*/
bool triggerSet;
/**
* DAC values
*/
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;
};
}
// int32 SetDacReg(uint32 channel, float32 val) const;
};
} // namespace MARTe
/*---------------------------------------------------------------------------*/
/* Inline method definitions */