EoWo Datasource running
Signed-off-by: Bernardo Carvalho <bernardo.carvalho@tecnico.ulisboa.pt>
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "AtcaIopADC.h"
|
||||
#include "atca-v6-iop-ioctl.h"
|
||||
|
||||
#define DEBUG_POLL 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Static definitions */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@@ -77,9 +78,9 @@ struct atca_wo_config {
|
||||
/*---------------------------------------------------------------------------*/
|
||||
AtcaIopADC::AtcaIopADC() :
|
||||
DataSourceI(), MessageI(), EmbeddedServiceMethodBinderI(), executor(*this) {
|
||||
//boardId = 2u;
|
||||
deviceName = "";
|
||||
deviceDmaName = "";
|
||||
boardId = 2u;
|
||||
//deviceDmaName = "";
|
||||
boardFileDescriptor = -1;
|
||||
boardDmaDescriptor = -1;
|
||||
mappedDmaBase = NULL;
|
||||
@@ -93,6 +94,8 @@ AtcaIopADC::AtcaIopADC() :
|
||||
counterAndTimer[1] = 0u;
|
||||
sleepNature = Busy;
|
||||
sleepPercentage = 0u;
|
||||
execCounter = 0u;
|
||||
pollTimout = 0u;
|
||||
adcPeriod = 0.;
|
||||
uint32 k;
|
||||
for (k=0u; k<ATCA_IOP_N_ADCs; k++) {
|
||||
@@ -153,12 +156,20 @@ bool AtcaIopADC::Initialise(StructuredDataI& data) {
|
||||
REPORT_ERROR(ErrorManagement::ParametersError, "The DeviceName shall be specified");
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
ok = data.Read("BoardId", boardId);
|
||||
if (!ok) {
|
||||
REPORT_ERROR(ErrorManagement::ParametersError, "The BoardId shall be specified");
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (ok) {
|
||||
ok = data.Read("DeviceDmaName", deviceDmaName);
|
||||
if (!ok) {
|
||||
REPORT_ERROR(ErrorManagement::ParametersError, "The DeviceDmaName shall be specified");
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (ok) {
|
||||
ok = data.Read("NumberOfChannels", numberOfChannels);
|
||||
if (!ok) {
|
||||
@@ -343,7 +354,8 @@ bool AtcaIopADC::SetConfiguredDatabase(StructuredDataI& data) {
|
||||
StreamString fullDeviceName;
|
||||
//Configure the board
|
||||
if (ok) {
|
||||
ok = fullDeviceName.Printf("%s", deviceName.Buffer());
|
||||
ok = fullDeviceName.Printf("%s_%d", deviceName.Buffer(), boardId);
|
||||
//ok = fullDeviceName.Printf("%s", deviceName.Buffer());
|
||||
}
|
||||
if (ok) {
|
||||
ok = fullDeviceName.Seek(0LLU);
|
||||
@@ -359,7 +371,8 @@ bool AtcaIopADC::SetConfiguredDatabase(StructuredDataI& data) {
|
||||
}
|
||||
ok = fullDeviceName.Seek(0LLU);
|
||||
if (ok) {
|
||||
ok = fullDeviceName.Printf("%s", deviceDmaName.Buffer());
|
||||
ok = fullDeviceName.Printf("%s_dmart_%d", deviceName.Buffer(), boardId);
|
||||
//ok = fullDeviceName.Printf("%s", deviceName.Buffer());
|
||||
}
|
||||
if (ok) {
|
||||
ok = fullDeviceName.Seek(0LLU);
|
||||
@@ -538,6 +551,10 @@ bool AtcaIopADC::SetConfiguredDatabase(StructuredDataI& data) {
|
||||
timerPeriodUsecTime = static_cast<uint32>(periodUsec);
|
||||
float64 sleepTimeT = (static_cast<float64>(HighResolutionTimer::Frequency()) / cycleFrequency);
|
||||
sleepTimeTicks = static_cast<uint64>(sleepTimeT);
|
||||
/*
|
||||
* [Information - AtcaIopADC.cpp:548]: The timer will be set using a cycle frequency of 10000.000000 Hz
|
||||
* [Information - AtcaIopADC.cpp:554]: The timer will be set using a sleepTimeTicks of 100000 (ns)
|
||||
*/
|
||||
REPORT_ERROR(ErrorManagement::Information,
|
||||
"The timer will be set using a sleepTimeTicks of %d (ns)", sleepTimeTicks);
|
||||
}
|
||||
@@ -613,6 +630,9 @@ bool AtcaIopADC::PrepareNextState(const char8* const currentStateName, const cha
|
||||
ok = executor.Start();
|
||||
REPORT_ERROR(ErrorManagement::Information, "Executor Start");
|
||||
}
|
||||
if (executor.GetStatus() == EmbeddedThreadI::RunningState) {
|
||||
REPORT_ERROR(ErrorManagement::Information, " ADC currentStateName %s, nextStateName %s", currentStateName, nextStateName);
|
||||
}
|
||||
counterAndTimer[0] = 0u;
|
||||
//counterAndTimer[1] = 0u;
|
||||
return ok;
|
||||
@@ -638,19 +658,32 @@ ErrorManagement::ErrorType AtcaIopADC::Execute(ExecutionInfo& info) {
|
||||
uint64 deltaTicks = sleepTimeTicks - sleepTicksCorrection;
|
||||
//volatile int32 currentDMA = 0u;
|
||||
oldestBufferIdx = GetOldestBufferIdx();
|
||||
float32 totalSleepTime = static_cast<float32>(static_cast<float64>(deltaTicks) * HighResolutionTimer::Period());
|
||||
#ifdef DEBUG_POLL
|
||||
if((execCounter++)%4096 == 0) {
|
||||
REPORT_ERROR(ErrorManagement::Information, "Executor sleepTime: %f pollTimout: %d", totalSleepTime, pollTimout);
|
||||
}
|
||||
#endif
|
||||
if (sleepNature == Busy) {
|
||||
if (sleepPercentage == 0u) {
|
||||
if (sleepPercentage > 0u) {
|
||||
//float32 sleepTime = totalSleepTime * 0.5;
|
||||
float32 sleepTime = totalSleepTime * (static_cast<float32>(sleepPercentage) / 100.F);
|
||||
Sleep::NoMore(sleepTime);
|
||||
//currentDMA =
|
||||
PollDma(startTicks + deltaTicks + 100000u); // TODO check max wait
|
||||
//if(PollDma(startTicks + deltaTicks + 100000u) < 0)
|
||||
//while ((HighResolutionTimer::Counter() - startTicks) < deltaTicks) {
|
||||
//}
|
||||
}
|
||||
if(PollDma(startTicks + deltaTicks + sleepTimeTicks + 10000u) < 0)
|
||||
pollTimout++; // TODO check max wait
|
||||
/*
|
||||
else {
|
||||
float32 totalSleepTime = static_cast<float32>(static_cast<float64>(deltaTicks) * HighResolutionTimer::Period());
|
||||
uint32 busyPercentage = (100u - sleepPercentage);
|
||||
float32 busyTime = totalSleepTime * (static_cast<float32>(busyPercentage) / 100.F);
|
||||
Sleep::SemiBusy(totalSleepTime, busyTime);
|
||||
}
|
||||
*/
|
||||
}
|
||||
else {
|
||||
float32 sleepTime = static_cast<float32>(static_cast<float64>(deltaTicks) * HighResolutionTimer::Period());
|
||||
@@ -691,6 +724,9 @@ uint32 AtcaIopADC::GetStackSize() const {
|
||||
uint32 AtcaIopADC::GetSleepPercentage() const {
|
||||
return sleepPercentage;
|
||||
}
|
||||
/*
|
||||
* waitLimitTicks in ns
|
||||
* */
|
||||
|
||||
int32 AtcaIopADC::PollDma(uint64 waitLimitTicks) const {
|
||||
uint32 buffIdx = oldestBufferIdx;
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace MARTe {
|
||||
/**
|
||||
* The board identifier
|
||||
*/
|
||||
//uint32 boardId;
|
||||
uint32 boardId;
|
||||
/**
|
||||
* The numberOfChannels
|
||||
*/
|
||||
@@ -264,7 +264,7 @@ namespace MARTe {
|
||||
/**
|
||||
* The board device name
|
||||
*/
|
||||
StreamString deviceDmaName;
|
||||
//StreamString deviceDmaName;
|
||||
/**
|
||||
* The board file descriptor
|
||||
*/
|
||||
@@ -294,6 +294,12 @@ namespace MARTe {
|
||||
*/
|
||||
AtcaIopADCSleepNature sleepNature;
|
||||
|
||||
/**
|
||||
* Debugging
|
||||
*/
|
||||
uint32 execCounter;
|
||||
uint32 pollTimout;
|
||||
|
||||
/**
|
||||
* Current counter and timer
|
||||
*/
|
||||
|
||||
@@ -77,7 +77,6 @@ namespace MARTe {
|
||||
AtcaIopConfigEoWo::~AtcaIopConfigEoWo() {
|
||||
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);
|
||||
}
|
||||
@@ -206,6 +205,9 @@ namespace MARTe {
|
||||
/*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 AtcaIopConfigEoWo::PrepareNextState(const char8* const currentStateName, const char8* const nextStateName) {
|
||||
REPORT_ERROR(ErrorManagement::Information, " EoWo currentStateName %s, nextStateName %s", currentStateName, nextStateName);
|
||||
//if (currentStateName == "Idle") {
|
||||
// REPORT_ERROR(ErrorManagement::Information, "OffState");
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -351,7 +353,6 @@ namespace MARTe {
|
||||
}
|
||||
if (ok) {
|
||||
//Allocate memory
|
||||
//channelsMemory = new float32[ATCA_IOP_MAX_DAC_CHANNELS];
|
||||
eoValues = new int32[ATCA_IOP_MAX_ADC_CHANNELS];
|
||||
woValues = new float32[ATCA_IOP_MAX_ADC_CHANNELS];
|
||||
}
|
||||
@@ -362,11 +363,15 @@ namespace MARTe {
|
||||
|
||||
bool AtcaIopConfigEoWo::Synchronise() {
|
||||
uint32 i;
|
||||
int32 w;
|
||||
int32 w = 1;
|
||||
bool ok = true;
|
||||
#ifdef DEBUG_POLL
|
||||
if((synchCounter++)%4096 == 0) {
|
||||
REPORT_ERROR(ErrorManagement::Information, " Synchronise");
|
||||
//i = (synchCounter/4096) & 0xF;
|
||||
REPORT_ERROR(ErrorManagement::Information, "Synchronise eo0:%d wo0%0.3f", eoValues[0], woValues[0]);
|
||||
}
|
||||
#endif
|
||||
//write(boardFileDescriptor, &w, 4);
|
||||
/*
|
||||
if (channelsMemory != NULL_PTR(float32 *)) {
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace MARTe {
|
||||
numberOfDACsEnabled = 0u;
|
||||
//isMaster = 0u;
|
||||
deviceName = "";
|
||||
boardId = 2u;
|
||||
triggerSet = false;
|
||||
uint32 n;
|
||||
for (n = 0u; n < ATCA_IOP_MAX_DAC_CHANNELS; n++) {
|
||||
@@ -198,6 +199,12 @@ namespace MARTe {
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ok = data.Read("BoardId", boardId);
|
||||
if (!ok) {
|
||||
REPORT_ERROR(ErrorManagement::ParametersError, "The BoardId shall be specified");
|
||||
}
|
||||
}
|
||||
//if (!data.Read("IsMaster", isMaster)) {
|
||||
// REPORT_ERROR(ErrorManagement::Warning, "IsMaster not specified. Using default: %d", isMaster);
|
||||
//}
|
||||
@@ -232,7 +239,7 @@ namespace MARTe {
|
||||
}
|
||||
if (ok) {
|
||||
outputRange[i] = range;
|
||||
REPORT_ERROR(ErrorManagement::Information, " Parameter DAC %d Output Range %f", i, range);
|
||||
REPORT_ERROR(ErrorManagement::Information, " Parameter DAC %d Output Range %f", i, range);
|
||||
//dacEnabled[i] = true;
|
||||
numberOfDACsEnabled++;
|
||||
}
|
||||
@@ -303,7 +310,8 @@ namespace MARTe {
|
||||
StreamString fullDeviceName;
|
||||
//Configure the board
|
||||
if (ok) {
|
||||
ok = fullDeviceName.Printf("%s", deviceName.Buffer());
|
||||
ok = fullDeviceName.Printf("%s_dac_%d", deviceName.Buffer(), boardId);
|
||||
//ok = fullDeviceName.Printf("%s", deviceName.Buffer());
|
||||
}
|
||||
if (ok) {
|
||||
ok = fullDeviceName.Seek(0LLU);
|
||||
@@ -332,7 +340,7 @@ namespace MARTe {
|
||||
bool ok = true;
|
||||
if (channelsMemory != NULL_PTR(float32 *)) {
|
||||
|
||||
// value = channelsMemory[0] / DAC_RANGE;
|
||||
// value = channelsMemory[0] / DAC_RANGE;
|
||||
for (i = 0u; (i < 2u) && (ok); i++) {
|
||||
//for (i = 0u; (i < numberOfDACsEnabled ) && (ok); i++) {
|
||||
float32 value = channelsMemory[i] / outputRange[i];
|
||||
@@ -345,12 +353,12 @@ namespace MARTe {
|
||||
// write(boardFileDescriptor, &w, 4);
|
||||
//REPORT_ERROR(ErrorManagement::Information, " Writing DAC 0 0x%x", w);
|
||||
}
|
||||
}
|
||||
/*
|
||||
}
|
||||
/*
|
||||
|
||||
w = dacValues[i];
|
||||
}
|
||||
*/
|
||||
w = dacValues[i];
|
||||
}
|
||||
*/
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,10 @@ namespace MARTe {
|
||||
* The board device name
|
||||
*/
|
||||
StreamString deviceName;
|
||||
/**
|
||||
* The board identifier
|
||||
*/
|
||||
uint32 boardId;
|
||||
/**
|
||||
* The board file descriptor
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user