}
}
}
break;
}
}
ocycleParmsLock.unlock();
olock.unlock();
if(!found)
err.set(ErrorParam, BString("There are no Cycle Parameters for cycle type: ") + cycleType);
if(!err && afterCycleStop){
if(oprocessingCycle){
err.set(ErrorCycleNumber, getName() + "The next cycle has already started");
}
}
dprintf(DBG_SETNEXTCYCLE, "Tick: %d\n", ocycleTick);
// Synchronise Module controllers if in simulation mode
if(osimulate)
ocycleTick = 10;
if(osimulateTiming & TimingSigCycleStart){
// Make sure timing simulation is in sync between multiple TmsPuServers when CYCLE_START is simulated
otimer.sync();
if(ocycleTick == 9){
otimer.tick();
}
else {
ocycleTick = 10;
}
}
te = getTime();
if((te - ts) > tmax){
tmax = te - ts;
}
dprintf(DBG_SETNEXTCYCLE, "Control::setNextCycle: Time: %f MaxTime: %f\n", te - ts, tmax);
dprintf(DBG_SETNEXTCYCLE, "%s: End\n", __PRETTY_FUNCTION__);
return err;
}
BError Control::getStatus(PuChannel puChannel, PuStatus& puStatus){
BError err;
BIter i;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
if(puChannel.pupeNum == 0){
for(opupeEngines.start(i); !opupeEngines.isEnd(i); opupeEngines.next(i)){
opupeEngines[i]->getStatus(puChannel, puStatus);
}
}
else {
if(puChannel.pupeNum > opupeEngines.number()){
err.set(ErrorParam, getName() + "No Pupe Engine Numbered: " + opupeEngines.number());
}
else {
opupeEngines[puChannel.pupeNum - 1]->getStatus(puChannel, puStatus);
}
}
opupeEnginesLock.unlock();
return err;
}
BError Control::getCycleInformation(UInt32 cycleNumber, CycleInformation& cycleInformation){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
err = mergeError(opupeEngines[0]->getCycleInformation(cycleNumber, cycleInformation));
opupeEnginesLock.unlock();
return err;
}
BError Control::getData(PuChannel puChannel, DataInfo dataInfo, Data& data, UInt32& orbitNumber){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
// Setup for error return
data.numValues = 0;
data.dataType = 0;
data.numBunches = 0;
data.numChannels = 0;
opupeEnginesLock.rdLock();
#if SINGLE_DMA
opupeLock.lock();
#endif
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
#if SINGLE_DMA
opupeLock.unlock();
#endif
opupeEnginesLock.unlock();
return err.set(ErrorParam, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->getData(puChannel, dataInfo, data, orbitNumber));
#if SINGLE_DMA
opupeLock.unlock();
#endif
opupeEnginesLock.unlock();
return err;
}
BError Control::requestData(PuChannel puChannel, DataInfo dataInfo){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
return err;
}
BError Control::setTestMode(PuChannel puChannel, UInt32 testOutput, UInt32 timingDisableMask){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
opupeEnginesLock.unlock();
return err.set(ErrorMisc, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->setTestMode(puChannel, testOutput, timingDisableMask));
opupeEnginesLock.unlock();
return err;
}
BError Control::setTimingSignals(PuChannel puChannel, UInt32 timingSignals){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
opupeEnginesLock.unlock();
return err.set(ErrorMisc, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->setTimingSignals(puChannel, timingSignals));
opupeEnginesLock.unlock();
return err;
}
BError Control::captureDiagnostics(PuChannel puChannel, TestCaptureInfo captureInfo, BArray<UInt64>& data){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
opupeEnginesLock.unlock();
return err.set(ErrorMisc, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->captureDiagnostics(puChannel, captureInfo, data));
opupeEnginesLock.unlock();
dprintf(DBG_CMD, "%s: End\n", __PRETTY_FUNCTION__);
return err;
}
BError Control::setTestData(PuChannel puChannel, Int32 on, BArray<UInt32> data){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
opupeEnginesLock.unlock();
return err.set(ErrorMisc, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->setTestData(puChannel, on, data));
opupeEnginesLock.unlock();
dprintf(DBG_CMD, "%s: End\n", __PRETTY_FUNCTION__);
return err;
}
BError Control::setPupeConfig(PuChannel puChannel, PupeConfig pupeConfig){
BError err;
dprintf(DBG_CMD, "%s\n", __PRETTY_FUNCTION__);
opupeEnginesLock.rdLock();
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
opupeEnginesLock.unlock();
return err.set(ErrorMisc, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->setPupeConfig(puChannel, pupeConfig));
osimulateTiming = pupeConfig.internalTimingMask;
opupeEnginesLock.unlock();
return err;
}
BError Control::getPupeConfig(PuChannel puChannel, PupeConfig& pupeConfig){
BError err;
dprintf(DBG_CMD, "Control::getPupeConfig: %d.%d.%d\n", puChannel.moduleNum, puChannel.pupeNum, puChannel.pupeChan);
opupeEnginesLock.rdLock();
if((puChannel.pupeNum < 1) || (puChannel.pupeNum > opupeEngines.number())){
opupeEnginesLock.unlock();
return err.set(ErrorMisc, getName() + "PuChannel: PupeNum out of range");
}
err = mergeError(opupeEngines[puChannel.pupeNum - 1]->getPupeConfig(puChannel, pupeConfig));
opupeEnginesLock.unlock();
return err;
}
void Control::run(){
dprintf(DBG_CMD, "Control::run\n");
oboapServer.run();
}
void Control::timer(){
static uint32_t tick = 0;
static int simEnable = 0;
BError err;
BIter i;
// printf("Control::timer: %d\n", ocycleTick);
if(simEnable){
if(++ocycleTick >= 12)
ocycleTick = 0;
//printf("CycleTick: %d\n", ocycleTick);
if(osimulate){
opupeEnginesLock.rdLock();
if(ocycleTick == 0){
for(opupeEngines.start(i); !opupeEngines.isEnd(i); opupeEngines.next(i))
opupeEngines[i]->cycleStart();
}
else if(ocycleTick == 4){
if(opupeEngines.number())
opupeEngines.front()->fpgaTriggerTimingInputs(TimingSigInjection);
}
else if(ocycleTick == 6){
if(opupeEngines.number())
opupeEngines.front()->fpgaTriggerTimingInputs(TimingSigHChange);
}
else if(ocycleTick == 10){
for(opupeEngines.start(i); !opupeEngines.isEnd(i); opupeEngines.next(i))
opupeEngines[i]->cycleStop();
}
opupeEnginesLock.unlock();
}
else {
opupeEnginesLock.rdLock();
if((osimulateTiming & TimingSigCycleStart) && (ocycleTick == 0)){
if(opupeEngines.number())
opupeEngines[omaster]->fpgaTriggerTimingInputs(TimingSigCycleStart);
}
else if((osimulateTiming & TimingSigInjection) && (ocycleTick == 4)){
if(opupeEngines.number())
opupeEngines[omaster]->fpgaTriggerTimingInputs(TimingSigInjection);
}
else if((osimulateTiming & TimingSigHChange) && (ocycleTick == 6)){
if(opupeEngines.number())
opupeEngines[omaster]->fpgaTriggerTimingInputs(TimingSigHChange);
}
else if((osimulateTiming & TimingSigCycleStop) && (ocycleTick == 10)){
if(opupeEngines.number())
opupeEngines[omaster]->fpgaTriggerTimingInputs(TimingSigCycleStop);
}
opupeEnginesLock.unlock();
}
}
if(tick == 30){
simEnable = 1;
}
// Every 1 seconds do some house keeping
if((tick % 10) == 9){
if(!oinitialised){