Skip to content

Commit

Permalink
Fixed a bug where setting the state of P digital pins, actually tried…
Browse files Browse the repository at this point in the history
… to set the value of N digital pins. Added a startup parameter to set the trigger polling interval. This way we can free the CPU while waiting for a trigger.
  • Loading branch information
Andraz Pozar committed May 22, 2019
1 parent 488d2eb commit 1e8aa6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
27 changes: 18 additions & 9 deletions RedPitayaSup/src/drvRedPitaya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//
#define ARRAY_LENGTH(xx) ((int) (sizeof (xx) /sizeof (xx [0])))

#define REDPITAYA_DRIVER_VERSION "2.1"
#define REDPITAYA_DRIVER_VERSION "2.2"

#define MAX_NUMBER_OF_ADDRESSES 8 // 0 to 8

Expand Down Expand Up @@ -260,7 +260,7 @@ void dataAcquisition(void *drvPvt) {

//------------------------------------------------------------------------------
//
RedPitayaDriver::RedPitayaDriver(const char* port_name) :
RedPitayaDriver::RedPitayaDriver(const char* port_name, const double pollingInterval) :
asynPortDriver(port_name, //
MAX_NUMBER_OF_ADDRESSES,//
NUMBER_QUALIFIERS, //
Expand Down Expand Up @@ -291,6 +291,13 @@ RedPitayaDriver::RedPitayaDriver(const char* port_name) :

snprintf(this->full_name, sizeof(this->full_name), "%s", port_name);

if (pollingInterval < 0.0) {
ERROR("Trigger polling interval needs to be a positive number\n", 0);
return;
}

triggerPollingInterval = pollingInterval;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Set up asyn parameters.
//
Expand Down Expand Up @@ -400,6 +407,7 @@ void RedPitayaDriver::dataAcquisition() {
rp_AcqGetTriggerSrc(&currentTriggerSource);
while (currentTriggerSource != 0 && this->acquiring &&
inTriggerSource == currentTriggerSource) {
epicsThreadSleep(triggerPollingInterval);
rp_AcqGetTriggerSrc(&currentTriggerSource);
}

Expand Down Expand Up @@ -554,10 +562,10 @@ asynStatus RedPitayaDriver::writeInt32(asynUser* pasynUser, epicsInt32 value) {
rpStatus = rp_DpinSetDirection(rp_dpin_t(N_PIN_OFFSET + addr), rp_pinDirection_t(value));
break;
case PDigPinState:
rpStatus = rp_DpinSetState(rp_dpin_t(N_PIN_OFFSET + addr), rp_pinState_t(value));
rpStatus = rp_DpinSetState(rp_dpin_t(P_PIN_OFFSET + addr), rp_pinState_t(value));
break;
case NDigPinState:
rpStatus = rp_DpinSetState(rp_dpin_t(P_PIN_OFFSET + addr), rp_pinState_t(value));
rpStatus = rp_DpinSetState(rp_dpin_t(N_PIN_OFFSET + addr), rp_pinState_t(value));
break;
case LedState:
rpStatus = rp_DpinSetState(rp_dpin_t(addr), rp_pinState_t(value));
Expand Down Expand Up @@ -1241,8 +1249,9 @@ asynStatus RedPitayaDriver::readFloat32Array(asynUser *pasynUser, epicsFloat32 *

// Define argument kinds
//
static const iocshArg verbosity_arg = { "Verbosity (0 .. 4)", iocshArgInt };
static const iocshArg port_name_arg = { "ASYN port name", iocshArgString };
static const iocshArg verbosity_arg = { "Verbosity (0 .. 4)", iocshArgInt };
static const iocshArg port_name_arg = { "ASYN port name", iocshArgString };
static const iocshArg polling_interval_arg = { "Trigger polling interval", iocshArgDouble };

//------------------------------------------------------------------------------
//
Expand All @@ -1256,12 +1265,12 @@ static void Call_RedPitaya_Initialise(const iocshArgBuf* args) {

//------------------------------------------------------------------------------
//
static const iocshArg * const RedPitaya_Configure_Args[1] = { &port_name_arg, };
static const iocshArg * const RedPitaya_Configure_Args[2] = { &port_name_arg, &polling_interval_arg};

static const iocshFuncDef RedPitaya_Configure_Func_Def = { "RedPitaya_Configure", 1, RedPitaya_Configure_Args };
static const iocshFuncDef RedPitaya_Configure_Func_Def = { "RedPitaya_Configure", 2, RedPitaya_Configure_Args };

static void Call_RedPitaya_Configure(const iocshArgBuf* args) {
new RedPitayaDriver(args[0].sval);
new RedPitayaDriver(args[0].sval, args[1].dval);
}

//------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions RedPitayaSup/src/drvRedPitaya.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

class epicsShareFunc RedPitayaDriver : public asynPortDriver {
public:
explicit RedPitayaDriver (const char* port_name);
explicit RedPitayaDriver (const char* port_name, const double pollingInterval = 0.01);
~RedPitayaDriver ();

/**
Expand All @@ -58,10 +58,10 @@ class epicsShareFunc RedPitayaDriver : public asynPortDriver {
// General info
//
DriverVersion = 0, // EPICS driver version
NDigPinDir, // Direction of N digital pins

// Digital pins and LEDs
//
NDigPinDir, // Direction of N digital pins
PDigPinDir, // Direction of P digital pins
NDigPinState, // State of N digital pins
PDigPinState, // State of P digital pins
Expand Down Expand Up @@ -154,9 +154,9 @@ class epicsShareFunc RedPitayaDriver : public asynPortDriver {
bool acquiring; // Is acquiring data
double acquisitionSleep; // Continuous data acquisition rate
epicsInt32 ssChannelSelected; // Selected channels to be triggered as a single shot
//int inTriggerSource; // Trigger source set in the EPICS database
int out1TriggerSource; // Trigger source for output 1
int out2TriggerSource; // Trigger source for output 2
double triggerPollingInterval; // Interval at which we poll for new trigger status

};

Expand Down
4 changes: 3 additions & 1 deletion iocBoot/iocRedPitayaTest/st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ dbLoadDatabase("dbd/RedPitayaTest.dbd",0,0)
RedPitayaTest_registerRecordDeviceDriver(pdbbase)

RedPitaya_Initialise (4)
RedPitaya_Configure ("RP")

# RedPitaya_Configure (portName, triggerPollingInterval in seconds)
RedPitaya_Configure ("RP", 0.1)

## Load record instances
dbLoadTemplate("db/redpitaya.substitutions")
Expand Down

0 comments on commit 1e8aa6d

Please sign in to comment.