From 2a93216346f856b1c6b1ba4fe100c83556f3060e Mon Sep 17 00:00:00 2001 From: cvs Date: Wed, 17 Nov 2004 10:50:17 +0000 Subject: [PATCH] - New batch file management module - New oscillator module - Bug fixes --- buffer.c | 5 +- el734hp.c | 30 ++ el737hpdriv.c | 30 +- make_gen | 2 +- nextrics.c | 2 +- nxamor.c | 8 +- pimotor.c | 3 +- polterwrite.c | 2 + psi.c | 3 + swmotor2.c | 57 +-- tasscan.c | 35 +- tecs/make_gen | 6 +- tricssupport.c | 205 +++++++++ tricssupport.h | 22 + utils/ecb-load.c | 242 ---------- utils/ecb_load_new/ecb_load.c | 100 +++++ utils/ecb_load_new/ecb_load.h | 143 ++++++ utils/ecb_load_new/ecbdriv_els.c | 725 ++++++++++++++++++++++++++++++ utils/ecb_load_new/gpib_els.c | 116 +++++ utils/ecb_load_new/makefile | 101 +++++ utils/ecb_load_new/makefile_EGPIB | 103 +++++ utils/ecb_load_new/makefile_GPIB | 103 +++++ utils/make.ecb | 26 -- 23 files changed, 1731 insertions(+), 338 deletions(-) create mode 100644 tricssupport.c create mode 100644 tricssupport.h delete mode 100644 utils/ecb-load.c create mode 100644 utils/ecb_load_new/ecb_load.c create mode 100644 utils/ecb_load_new/ecb_load.h create mode 100644 utils/ecb_load_new/ecbdriv_els.c create mode 100644 utils/ecb_load_new/gpib_els.c create mode 100644 utils/ecb_load_new/makefile create mode 100644 utils/ecb_load_new/makefile_EGPIB create mode 100644 utils/ecb_load_new/makefile_GPIB delete mode 100644 utils/make.ecb diff --git a/buffer.c b/buffer.c index d785eea..2b25383 100644 --- a/buffer.c +++ b/buffer.c @@ -283,7 +283,10 @@ iInt = InterpExecute(pSics,pCon,pPtr); if(!iInt) { - iRes = 0; + if(SCGetInterrupt(pCon) > eAbortBatch) { + iRes = 0; + break; + } } iRet = LLDnodePtr2Next(self->iLineList); } diff --git a/el734hp.c b/el734hp.c index bfc980c..b0b0755 100644 --- a/el734hp.c +++ b/el734hp.c @@ -55,6 +55,8 @@ float lastValue; int errorCode; int oredMsr; + int posCount; + int runCount; } EL734Driv, *pEL734Driv; /*------------------- error codes ----------------------------------*/ #define BADADR -1 @@ -71,6 +73,7 @@ #define RUNFAULT -12 #define POSFAULT -13 #define BADCUSHION -14 +#define BADCOUNT -15 /*--------------------------------------------------------------------*/ static int checkResponse(pEL734Driv self, char *pReply){ /* @@ -142,11 +145,18 @@ static int EL734Run(void *pData,float fValue){ if(!checkResponse(self,pReply)){ return HWFault; } + self->posCount =0; + self->runCount = 0; return OKOK; } /*-----------------------------------------------------------------------*/ static int decodeMSR(pEL734Driv self, int msr){ if (msr == 0){ + if(self->posCount > 0 || self->runCount > 0){ + self->errorCode = BADCOUNT; + return HWPosFault; + } + /* we are done: check ored_msr for troubles */ @@ -187,6 +197,15 @@ static int decodeMSR(pEL734Driv self, int msr){ /* we are still tugging along ............ */ + if(msr & 0x80){ + self->runCount++; + } else if(msr & 0x200) { + self->posCount++; + } else if(msr & 0x100) { + self->posCount++; + } else if(msr & 0x400) { + self->posCount++; + } return HWBusy; /* inserted above line and commented out lines below M.Zolliker Sep 2004 @@ -250,6 +269,8 @@ static int EL734Status(void *pData){ /*----------------------------------------------------------------------*/ static void EL734Error(void *pData, int *iCode, char *error, int errLen){ pEL734Driv self = NULL; + char pBueffel[132]; + self = (pEL734Driv)pData; assert(self); @@ -297,6 +318,11 @@ static void EL734Error(void *pData, int *iCode, char *error, int errLen){ case BADCUSHION: strncpy(error,"Air cushion problem",errLen); break; + case BADCOUNT: + snprintf(pBueffel,131,"%d RunFaults, %d PosFaults", + self->runCount, self->posCount); + strncpy(error,pBueffel,errLen); + break; default: getRS232Error(*iCode,error,errLen); break; @@ -328,6 +354,10 @@ static int EL734Fix(void *pData, int iCode, float fValue){ case RUNFAULT: case POSFAULT: return MOTREDO; + case BADCOUNT: + self->runCount = 0; + self->posCount = 0; + return MOTOK; } return MOTFAIL; } diff --git a/el737hpdriv.c b/el737hpdriv.c index f952112..2edf273 100644 --- a/el737hpdriv.c +++ b/el737hpdriv.c @@ -36,6 +36,7 @@ typedef struct { int lastStatus; /* need to remember last status, otherwise I get oscillating NoBeam and Counting status if the beam goes off */ + char *badReply; } EL737hp, *pEL737hp; /*--------------------- ERROR CODES -------------------------------------*/ #define OFFLINE -1 @@ -48,6 +49,13 @@ typedef struct { #define BADREPLY -10 #define SELECTFAIL -11 #define TIMEOUT737 -12 +/*---------------------------------------------------------------------*/ +static void setBadReply(pEL737hp self, char *reply){ + if(self->badReply != NULL){ + free(self->badReply); + } + self->badReply = strdup(reply); +} /*----------------------------------------------------------------------- search errors in a reply from the EL737. Returns 1 on success or a negative error code in case of trouble. @@ -136,6 +144,7 @@ static int readRS(pEL737hp pPriv, int *RS){ status = sscanf(reply,"%d",RS); if(status < 1){ pPriv->errorCode = BADREPLY; + setBadReply(pPriv,reply); return 0; } return 1; @@ -196,6 +205,7 @@ static int updateMonitors(struct __COUNTER *self){ status = sscanf(reply,"%d %d %d %d %f",&m1,&m2,&m3,&m4,&fTime); if(status != 5){ pPriv->errorCode = BADREPLY; + setBadReply(pPriv,reply); printf("Bad reply to EL737 RA command: %s\n", reply); return 0; } @@ -399,7 +409,8 @@ static int EL737GetError(struct __COUNTER *self, int *iCode, strncpy(pError,"EL737 has an internal system error",errLen); break; case BADREPLY: - strncpy(pError,"EL737 sent an unexpected reply",errLen); + snprintf(pError,errLen,"EL737 sent an unexpected reply: %s", + pPriv->badReply); break; case SELECTFAIL: strncpy(pError,"select system call failed, network trouble",errLen); @@ -415,13 +426,14 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){ pEL737hp pPriv = NULL; int status; char pReply[50]; + char buffer[256]; + int dataLen = 255; assert(self); pPriv = (pEL737hp)self->pData; switch(iCode){ case TIMEOUT: - case BADREPLY: case BADPARAM: case NOPARAM: case BADRANGE: @@ -429,6 +441,17 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){ case TIMEOUT737: return COREDO; break; + case BADREPLY: + /* + try to read away all the garbage which may still be in the line + */ + if(availableRS232(pPriv->controller) > 0){ + memset(buffer,0,256); + readRS232(pPriv->controller,buffer,&dataLen); + printf("EL737hpdriv dumped %s after bad reply\n", buffer); + } + return COREDO; + break; case OFFLINE: EL737Command(pPriv,"RMT 1\r",pReply,49); EL737Command(pPriv,"echo 2\r",pReply,49); @@ -527,6 +550,9 @@ static void KillHP(pCounterDriver self){ if(pPriv->controller != NULL){ KillRS232(pPriv->controller); } + if(pPriv->badReply != NULL){ + free(pPriv->badReply); + } free(pPriv); } /*-------------------------------------------------------------------*/ diff --git a/make_gen b/make_gen index 2cee481..602ebb7 100644 --- a/make_gen +++ b/make_gen @@ -18,7 +18,7 @@ OBJ=psi.o buffer.o ruli.o dmc.o nxsans.o nextrics.o sps.o pimotor.o \ bruker.o ltc11.o A1931.o dilludriv.o eurodriv.o slsmagnet.o \ el755driv.o amorscan.o serial.o scontroller.o t_update.o \ t_rlp.o t_conv.o el737hpdriv.o dornier2.o el734hp.o \ - el737hpv2driv.o swmotor2.o ipsdriv.o + el737hpv2driv.o swmotor2.o ipsdriv.o tricssupport.o libpsi.a: $(OBJ) rm -f libpsi.a diff --git a/nextrics.c b/nextrics.c index cd9dcca..992abc6 100644 --- a/nextrics.c +++ b/nextrics.c @@ -1373,7 +1373,7 @@ name of hkl object holding crystallographic information } if(iFrame < 0 || iFrame >= self->iFrameNum) { - sprintf(pBueffel,"ERROR: farme %d not yet written",iDetector); + sprintf(pBueffel,"ERROR: frame %d not yet written",iDetector); return 0; } diff --git a/nxamor.c b/nxamor.c index 13c4066..0f2e0d4 100644 --- a/nxamor.c +++ b/nxamor.c @@ -42,8 +42,9 @@ The rough size of each detector chunk to write in TOF mode (currently 16MB) #define TOFBLOCK 8192000 -*/ #define TOFBLOCK 16384000 +*/ +#define TOFBLOCK 65536000 /* a pointer to amor2t which we need for a couple of parameters @@ -354,10 +355,12 @@ static int WriteTOFDetector(char *name, pHistMem pHM, int *iDim, NXhandle hfil, NXdict hdict, SConnection *pCon) { - int iLength, nChunk, chunkSize, iChunk[3], i, iStart[3], nTime, iRet; + int nChunk, chunkSize, iChunk[3], i, iStart[3], nTime, iRet; + long iLength; HistInt *lData = NULL; char pBueffel[132]; const float *fTime; + int start; fTime = GetHistTimeBin(pHM,&nTime); iDim[2] = nTime; @@ -384,6 +387,7 @@ static int WriteTOFDetector(char *name, pHistMem pHM, int *iDim, free(lData); return 0; } + SicsWait(2); NXDputalias(hfil,hdict,name,lData); NXDputalias(hfil,hdict,"detchunk",iDim); NXDaliaslink(hfil,hdict,"dana",name); diff --git a/pimotor.c b/pimotor.c index 5a8ad47..4d26bcd 100644 --- a/pimotor.c +++ b/pimotor.c @@ -416,7 +416,8 @@ KillC804(pNew); return NULL; } - + SerialConfig(&pNew->pSerial,5000); + /* switch on, just to make sure */ iTmo = SerialGetTmo(&pNew->pSerial); SerialConfig(&pNew->pSerial,0); diff --git a/polterwrite.c b/polterwrite.c index ec124cc..2a0ef52 100644 --- a/polterwrite.c +++ b/polterwrite.c @@ -507,6 +507,8 @@ static int PoldiStart(pPolterdi self, SConnection *pCon) NXDputalias(hfil,hdict,"cntime",&fVal); lVal = GetHistMonitor(self->pHist,1,pCon); NXDputalias(hfil,hdict,"cnmon1",&lVal); + lVal = GetHistMonitor(self->pHist,4,pCon); + NXDputalias(hfil,hdict,"cnprot",&lVal); eMode = GetHistCountMode(self->pHist); if(eMode == eTimer) { diff --git a/psi.c b/psi.c index f9b00a5..559a2a7 100644 --- a/psi.c +++ b/psi.c @@ -50,6 +50,7 @@ #include "amorscan.h" #include "serial.h" #include "fomerge.h" +#include "tricssupport.h" static pSite sitePSI = NULL; @@ -59,6 +60,7 @@ static void AddPsiCommands(SicsInterp *pInter){ AddCommand(pInter,"InitDMC",InitDmc,NULL,NULL); AddCommand(pInter,"InitSANS",InitSANS,NULL,NULL); AddCommand(pInter,"MakeTRICSNEXUS",NexTricsFactory,NULL,NULL); + AddCommand(pInter,"MakeTRICSSupport",MakeTricsSupport,NULL,NULL); AddCommand(pInter,"MakeSPS",SPSFactory,NULL,NULL); AddCommand(pInter,"MakePIMotor",PIMotorFactory,NULL,NULL); AddCommand(pInter,"MakeSANSWave",MakeSANSWave,NULL,NULL); @@ -84,6 +86,7 @@ static void RemovePsiCommands(SicsInterp *pSics){ RemoveCommand(pSics,"InitDMC"); RemoveCommand(pSics,"InitSANS"); RemoveCommand(pSics,"MakeTRICSNEXUS"); + RemoveCommand(pSics,"MakeTRICSSupport"); RemoveCommand(pSics,"MakeSPS"); RemoveCommand(pSics,"MakePIMotor"); RemoveCommand(pSics,"MakeSANSWave"); diff --git a/swmotor2.c b/swmotor2.c index f682397..11260d0 100644 --- a/swmotor2.c +++ b/swmotor2.c @@ -11,6 +11,10 @@ motor drivers. Mark Koennecke, August 2003 + + Modified to do all the switching and reference running in Tcl + + Mark Koennecke, August 2004 --------------------------------------------------------------------------*/ #include #include @@ -167,59 +171,6 @@ static long SWSetValue(void *pData, SConnection *pCon, float fVal) } self->selectedMotor[0] = self->myNumber; - /* - switch done! Start a reference run - */ - SicsWait(10); - SCWrite(pCon,"Standby, starting reference run... ", eWarning); - pElli = (EL734Driv *)self->pMaster->pDriver; - sprintf(pCommand,"R %d\r",pElli->iMotor); - setRS232Timeout(pElli->controller,4000); - status = transactRS232(pElli->controller,pCommand,strlen(pCommand), - pError,131); - if(status != 1) - { - getRS232Error(status,pError,131); - sprintf(pCommand,"ERROR: %s while trying to start reference run", - pError); - SCWrite(pCon,pCommand,eError); - self->errCode = -1002; - return HWFault; - } - /* - now loop forever until reference run is done. This is either when the - motors stops being busy or when the user interrupts. - */ - sprintf(pCommand,"SS %d\r",pElli->iMotor); - for( ; ;) - { - status = transactRS232(pElli->controller,pCommand,strlen(pCommand), - pError,131); - if(status != 1) - { - getRS232Error(status,pError,131); - sprintf(pCommand,"ERROR: %s during reference run", - pError); - SCWrite(pCon,pCommand,eError); - self->errCode = -1003; - return HWFault; - } - if(strstr(pError,"?BSY") == NULL) - break; - if(SCGetInterrupt(pCon) != eContinue) - { - self->errCode = -1004; - SCWrite(pCon,"ERROR: user interrupted reference run",eError); - return HWFault; - } - SicsWait(2); - } - - /* - now this is finished. We can really start driving the motor - */ - SCWrite(pCon,"Reference run completed, starting to drive motor..", - eWarning); return self->pMaster->pDrivInt->SetValue(self->pMaster,pCon,fVal); } } diff --git a/tasscan.c b/tasscan.c index acc6e4d..ac89e58 100644 --- a/tasscan.c +++ b/tasscan.c @@ -112,6 +112,22 @@ static void writePolFile(FILE *fd, pTASdata pTAS){ } fclose(fpol); } +/*-----------------------------------------------------------------------*/ +static char *findLastPoint(char *text) +{ + char *pPtr; + int i; + + pPtr = text + strlen(text) - 1; + for(i = strlen(text); i > 0; i--, pPtr--) + { + if(*pPtr == '.') + { + return pPtr; + } + } + return NULL; +} /*------------------------------------------------------------------------- TASHeader writes the header of a TAS data file. The format is an obscure format from ILL ( not ill but Institute Laue Langevin). No @@ -151,14 +167,21 @@ static int TASHeader(pScanData self) extract the file number from the name for entry into the datafile */ - pcPtr = strstr(self->pFile,"."); - pcPtr -= 9; /* four for year, 5 for number */ - for(i = 0; i < 5; i++, pcPtr++) + pcPtr = findLastPoint(self->pFile); + if(pcPtr != NULL) { - pWork[i] = *pcPtr; + pcPtr -= 6; /* 6 digits for number */ + for(i = 0; i < 6; i++, pcPtr++) + { + pWork[i] = *pcPtr; + } + pWork[6] = '\0'; + iFileNO = atoi(pWork); + } + else + { + SCWrite(self->pCon,"WARNING: failed to decode file number",eWarning); } - pWork[5] = '\0'; - iFileNO = atoi(pWork); /* the bizarre R, A, V header */ charLine(pBueffel,'R'); diff --git a/tecs/make_gen b/tecs/make_gen index 6816dba..024fdc8 100644 --- a/tecs/make_gen +++ b/tecs/make_gen @@ -27,14 +27,14 @@ HARDSUPLIB = ../hardsup/libhlib.a libtecsl.a: $(CLI_OBJ) rm -f $@ $(AR) $(ARFLAGS) $@ $Q - ranlib $@ + ranlib libtecsl.a all: libtecsl.a TecsServer TecsClient keep_running six CFGDIR=/afs/psi.ch/project/sinq/common/lib/tecs/cfg/ --include make_crv --include src/make_crv +#-include make_crv +#-include src/make_crv $(SRC)make_crv: make_crv.tcsh inp/lsc.codes $(ALLINP) $(SRC)make_crv.tcsh $(SRC)inp/lsc.codes diff --git a/tricssupport.c b/tricssupport.c new file mode 100644 index 0000000..12fe8db --- /dev/null +++ b/tricssupport.c @@ -0,0 +1,205 @@ +/*------------------------------------------------------------------------ + This is a little helper module for SICS which implements some + status display support functions. + + COPYRIGHT: see file COPYRIGHT + + Extracted from nextrics + + Mark Koennecke, August 2004 +--------------------------------------------------------------------------*/ +#include "tricssupport.h" +#include "../napi.h" +#include "../HistMem.h" + + +#define NEWFRAME 1166 +/*------------------------------------------------------------------------ + a data structure plus support functions + ------------------------------------------------------------------------*/ +typedef struct { + pObjectDescriptor pDes; + pICallBack pCall; +} TricsSupport, *pTricsSupport; +/*----------------------------------------------------------------------*/ +static pTricsSupport CreateTricsSupport(){ + pTricsSupport pNew = NULL; + + pNew = (pTricsSupport)malloc(sizeof(TricsSupport)); + if(pNew == NULL){ + return NULL; + } + memset(pNew,0,sizeof(TricsSupport)); + + pNew->pDes = CreateDescriptor("TricsSupport"); + pNew->pCall = CreateCallBackInterface(); + if(pNew->pDes == NULL || pNew->pCall == NULL){ + free(pNew); + return NULL; + } + return pNew; +} +/*--------------------------------------------------------------------*/ +static void KillTricsSupport(void *pData){ + pTricsSupport pNew = (pTricsSupport)pData; + + if(pNew != NULL){ + if(pNew->pDes != NULL){ + DeleteDescriptor(pNew->pDes); + pNew->pDes = NULL; + } + if(pNew->pCall != NULL){ + DeleteCallBackInterface(pNew->pCall); + pNew->pCall = NULL; + } + } +} +/*=====================================================================*/ +static int FrameSupInterest(int iEvent, void *pEvent, void *pUser){ + SConnection *pCon = NULL; + int *iFrame; + char pBueffel[512]; + + if(iEvent != NEWFRAME){ + return 0; + } + + pCon = (SConnection *)pUser; + iFrame = (int *)pEvent; + assert(pCon); + sprintf(pBueffel,"framenumber = %d",*iFrame); + SCWrite(pCon,pBueffel,eWarning); + return 1; +} +/*====================================================================== + NexusGetFrame opens a TRICS NeXus file and retrieves a frame for the + specified detector from it. This is a special feature for the + status display. + ---------------------------------------------------------------------------*/ +static int NexusGetFrameSup(SConnection *pCon, char *filename, + int iDetector, int iFrame){ + char pBueffel[132]; + int iRet, type, rank, iDim[2]; + NXhandle hfil; + HistInt *lData = NULL; + + /* do a few range checks */ + if(iDetector < 1 || iDetector > 3){ + sprintf(pBueffel,"ERROR: unknown detector %d requested",iDetector); + SCWrite(pCon,pBueffel,eError); + return 0; + } + + /* open file */ + iRet = NXopen(filename,NXACC_READ,&hfil); + if(iRet != NX_OK){ + sprintf(pBueffel,"ERROR: cannot open %s",filename); + SCWrite(pCon,pBueffel,eError); + return 0; + } + + snprintf(pBueffel,131,"/frame%4.4d/detector%1.1d/counts",iFrame, + iDetector); + iRet = NXopenpath(hfil,pBueffel); + if(iRet != NX_OK){ + sprintf(pBueffel,"ERROR: frame %d, detector %d not found in %s", + iFrame, iDetector, + filename); + SCWrite(pCon,pBueffel,eError); + NXclose(&hfil); + return 0; + } + NXgetinfo(hfil,&rank,iDim,&type); + + lData = (HistInt *)malloc(iDim[0]*iDim[1]*sizeof(HistInt)); + if(!lData){ + SCWrite(pCon,"ERROR: out of memory in NexusGetFrame",eError); + NXclose(&hfil); + return 0; + } + memset(lData,0,iDim[0]*iDim[1]*sizeof(HistInt)); + iRet = NXgetdata(hfil,lData); + if(iRet != NX_OK){ + SCWrite(pCon,"ERROR: failed to read data",eError); + NXclose(&hfil); + return 0; + } + + /* send it */ + sprintf(pBueffel,"detector%1.1d",iDetector); + SCWriteZipped(pCon,pBueffel,lData,iDim[0]*iDim[1]*sizeof(HistInt)); + + /* clean up */ + NXclose(&hfil); + free(lData); + return 1; +} +/*----------------------------------------------------------------------*/ +int MakeTricsSupport(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pTricsSupport pNew = NULL; + + pNew = CreateTricsSupport(); + if(!pNew){ + SCWrite(pCon,"ERROR: out of memory creating TricsSupport",eError); + return 0; + } + if(AddCommand(pSics,"tricssupport",TricsSupportAction,KillTricsSupport, + pNew) != 1){ + SCWrite(pCon,"ERROR: duplicate command tricssupport not created",eError); + return 0; + } + SCSendOK(pCon); + return 1; +} +/*-----------------------------------------------------------------------*/ +int TricsSupportAction(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + int iDet, iFrame, iRet; + long lID; + char pBueffel[131]; + pTricsSupport self = (pTricsSupport)pData; + + assert(self); + + /* check for subcommands */ + if(argc < 2){ + snprintf(pBueffel,130,"ERROR: no subcommand found for %s",argv[0]); + SCWrite(pCon,pBueffel,eError); + return 0; + } + + strtolower(argv[1]); + if(strcmp(argv[1],"oldframe") == 0){ + if(argc < 5){ + SCWrite(pCon,"ERROR: insufficient number of arguments to oldframe", + eError); + return 0; + } + iDet = atoi(argv[3]); + iFrame = atoi(argv[4]); + iRet = NexusGetFrameSup(pCon,argv[2],iDet, iFrame); + return 1; + } + else if(strcmp(argv[1],"interest") == 0){ + lID = RegisterCallback(self->pCall, NEWFRAME, FrameSupInterest, + pCon, NULL); + SCRegister(pCon,pSics, self->pCall,lID); + SCSendOK(pCon); + return 1; + } else if(strcmp(argv[1],"newframe") == 0){ + if(argc < 3){ + SCWrite(pCon, + "ERROR: insufficient number of arguments to tricsupport newframe", + eError); + return 0; + } + iFrame = atoi(argv[2]); + InvokeCallBack(self->pCall, NEWFRAME,&iFrame); + SCSendOK(pCon); + return 1; + } +} + + + diff --git a/tricssupport.h b/tricssupport.h new file mode 100644 index 0000000..f8e409f --- /dev/null +++ b/tricssupport.h @@ -0,0 +1,22 @@ +/*------------------------------------------------------------------------ + This is a little helper module for SICS which implements some + status display support functions. + + COPYRIGHT: see file COPYRIGHT + + Extracted from nextrics + + Mark Koennecke, August 2004 + --------------------------------------------------------------------------*/ +#ifndef TRICSSUPPORT +#define TRICSSUPPORT + +#include + +int MakeTricsSupport(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]); +int TricsSupportAction(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]); + + +#endif diff --git a/utils/ecb-load.c b/utils/ecb-load.c deleted file mode 100644 index ec977ef..0000000 --- a/utils/ecb-load.c +++ /dev/null @@ -1,242 +0,0 @@ -/*************************************************************************** -* This file contains the download program the ECB system. -* It reads a Tek-hex formated file and downloads it to the ECB-system. -* The lowest address is used as the start address of the program. -* -* Project: ECB-C -* Filename: ecb_load.c -* -* Author: L. S. Jensen 18. Feb 1993 -* -* Heavily reworked by code transfusions from tascom in order to -* support new ECB file format. -* -* Mark Koennecke, May 2003 -* -* Copyright (C) Risoe National Laboratory, 1993, All rights reserved -****************************************************************************/ -#include -#include -#include "ecb-drv.h" /* The ecb driver interface. */ - -#define MAX_BUFFER_SIZE 32767 /* Max. RAM in ECB system */ -#define LINE_SIZE 128 - -#define LAST_LINE -125 -#define CHECKSUM_ERR -100 -#define FORMAT_ERR -101 -#define FILE_ERR -102 - -#define CSTART_CODE 171 /* The number of ECB function cstart */ - -#define FOREVER 1 /* Used in a loop */ -#define ECB_BYTES 65536L -#define ECB_DOWN_LOAD 178 -#define LOAD_NEXT 1 -/***************************************************************************** -* Local variables in this file. -*****************************************************************************/ -static char buffer[MAX_BUFFER_SIZE]; - -static int debug = 0; - -/******************************************************************************* -* Convert HEX to bin -*******************************************************************************/ -static int look_up[] = {10, 11, 12, 13, 14 ,15}; - -static unsigned long -Hex_to_bin(char c) -{ - - if(isdigit((int) c)) - return (c - '0'); - else - return look_up[c - 'A']; -} - - -/******************************************************************************* -* Convert Bin to HEX -*******************************************************************************/ - -static char -Bin_to_hex (int i) -{ - - if(i <= 9) - return ( (char)(i + (int)('0')) ); - else - return ( (char)( (i - 10) + (int)('A')) ); -} -/*************************************************************************** -* This function creates blocks as large as possible of consecutive data -* bytes from the hex file in order to speed up the data transfer by -* sending blocks of data to the ECB system rather than single lines. -****************************************************************************/ -static Z80_reg x_outreg, x_inreg; - -static long -Send_blocks(FILE *fp, Gpib_dev dev) -{ - char line[LINE_SIZE]; - char *point; - int line_not_output, byte_count, line_no,type, no_bytes,total_bytes; - int load_count = -1, function; - unsigned char x_ecb_data[ECB_BYTES]; /* Array to hold data blocks for ECB */ - unsigned long adrs, old_adrs, total0, total1, total2; - void *line9 = &line[9]; - unsigned short address; - - for (;;) - { - if (line_not_output == 1) - line_not_output = 0; /* Start with old line */ - else - { /* Read a line from file */ - point = fgets (line, LINE_SIZE, fp); - if (point != NULL) - { - byte_count = strlen(line); - byte_count -= 4; /* Remove checksum and \n in the */ - line[byte_count+1] = '\0'; /* line, i.e. the four last characters */ - line[0] = '0'; /* Replace : in line[0] with 0 */ - } - else - { - if (!ferror(fp)) - byte_count = 0; - else - { - fclose (fp); - fp = NULL; - return(FILE_ERR); - } - } - } - line_no += 1; - if (byte_count != 0) - { - if (line_no == 1) - strcpy (x_ecb_data, line); - type = (Hex_to_bin(line[7]) << 4) + Hex_to_bin(line[8]); - if (type != 0) - { - if (line_no > 1) /* Output buffer and mark that */ - line_not_output = 1; /* last input line has not been output */ - } - else - { - no_bytes = (Hex_to_bin(line[1]) << 4) + Hex_to_bin(line[2]); - adrs = (Hex_to_bin(line[3]) << 12) + (Hex_to_bin(line[4]) << 8) + - (Hex_to_bin(line[5]) << 4) + Hex_to_bin(line[6]); - if (line_no == 1) - { - total_bytes = no_bytes; - old_adrs = adrs; - continue; /* Get next input line */ - } - else - { - if (old_adrs + no_bytes == adrs) - { /* Contigious addresses */ - total_bytes += no_bytes; - old_adrs = adrs; - strcat (x_ecb_data, line9); /* Add the new bytes to buffer */ - total0 = total_bytes/256; /* and adjust number of bytes */ - x_ecb_data[0] = Bin_to_hex(total0); - total1 = total_bytes - 256*total0; - total2 = total1/16; - x_ecb_data[1] = Bin_to_hex(total2); - x_ecb_data[2] = Bin_to_hex(total1 - 16*total2); - if (line_no < 20) /* Max 20 lines together */ - continue; /* Get next input line */ - } - } - line_not_output = 0; /* Output buffer, nothing waiting in line[] */ - } - - address = 1; - byte_count = strlen (x_ecb_data); - Ecb_write (dev, x_ecb_data,byte_count,1); /* Write a line to ECB */ - line_no = 0; - - if (load_count == -1) /* Type Loading followed by dots while */ - { /* down loading the file */ - printf ("Loading"); - load_count = 0; - } - load_count += 1; - - if (load_count > 15) - { - printf ("."); - load_count = 0; - } - - - function = ECB_DOWN_LOAD; - Ecb_func (dev, function,x_inreg); /* Call ECB download function */ - if (x_outreg.b != LOAD_NEXT) /* Wait for reply from ECB */ - break; /* If LOAD_NEXT, get next line, else finished */ - } - } - printf("\nLoading completed\n"); -} -/**************************************************************************** -* Handles error in gpib driver. -****************************************************************************/ -void -Exit_code(int status) -{ - if(debug) - printf("exit status %d", status); - exit(status); -} -/**************************************************************************** -* -****************************************************************************/ -int -main(int argc, char *argv[]) -{ - Gpib_dev dev; - int dev_no; - FILE *record_fp; - long start_adr; - Z80_reg z80; - - if (argc < 4|| argc > 5) - { - printf("used: %s Gpib-driver-name ECB-device-number ECB-hex-filename\n", - argv[0]); - exit(GPIB_ERR); - } - if (argc == 5) - { - if ((0 == strcasecmp(argv[4],"DEBUG"))||(0 == strcasecmp(argv[4],"VERBOSE"))) - debug = 1; - } - - record_fp = fopen(argv[3], "rb"); /* Open in read-only mode in binary mode */ - if (record_fp == NULL) - { - printf("used: %s Gpib-driver-name ECB-device-number ECB-hex-filename\n", - argv[0]); - exit(FILE_ERR); - } - - dev = Ecb_unit(argv[1], argv[2]); /* Open the ECB device */ - - start_adr = Send_blocks(record_fp, dev); - if (start_adr < 0) /* An error */ - exit(start_adr); - - z80.d = start_adr; /* Lsb part in Z80 reg. D */ - z80.e = start_adr>>8; /* Msb part in Z80 reg. E */ - - Ecb_func(dev, CSTART_CODE, z80); /* And start the ecb-c program. */ - - return; -} - - diff --git a/utils/ecb_load_new/ecb_load.c b/utils/ecb_load_new/ecb_load.c new file mode 100644 index 0000000..5a74015 --- /dev/null +++ b/utils/ecb_load_new/ecb_load.c @@ -0,0 +1,100 @@ +/*************************************************************************** +* Download program for the ECB system with the new P2701 CPU module. +* +* Filename: ecb_load.c +* +* Author: P.S. May 2004 +* +* +****************************************************************************/ +/******************************************************************************* +*& modificaions: +*& +*& V003.100 P.S. 2-May-2004 +*& Creation. +*& +*&*****************************************************************************/ +#include +#include +#include +#include "ecb_load.h" /* The ecb driver interface. */ + +/******************************************************************************* +* Default path and name for the download file.. +*******************************************************************************/ +#define FILE_NAME "/scratch/users/tascomp/sans2m/tas/symfil/ecb_v501.hex" + +/******************************************************************************* +* External variables defined in this file. +*******************************************************************************/ +int x_tas_error = 0; /* Global error type */ +char *x_error_text = '\0'; /* Error text line*/ +int x_error_int = 0; /* Global error parameter */ + + + +/**************************************************************************** +* If the program is started without arguments, the file ecb_v501.hex is +* downloaded. Another file name may be specified as an argument. +****************************************************************************/ +extern int +main(int argc, char *argv[]) +{ + int ecb_type; + FILE *stream; + char file_name[F_BUFSIZ] = FILE_NAME; + + if (argc == 2) + strcpy (file_name, argv[1]); + if (argc > 2) + exit(0); /* Error exit */ + + stream = fopen(file_name, "r"); /* Open in read-only mode */ + if (stream == NULL) + { + printf("Error: unable to open file %s \n", file_name); + exit(0); + } + + Gpib_init(); + Ecb_init(); + + /* Check communication with the ECB system works and that we are in ROM mode */ + ecb_type = Ecb_type (TYPE_OUT); + if (ecb_type != 0) + { + if (ecb_type == -1) + printf (" old ECB CPU (not P2701a)\n"); + else + { + printf ("\nERROR:- the ECB system is in RAM mode\n"); + printf (" and download of the ECB program is only possible in ROM mode.\n"); + printf (" You must set the ECB system in ROM mode.\n\n"); + } + return; + } + + Ecb_down_load (stream); + +} + + +/******************************************************************************* +* Main error routine. +*******************************************************************************/ + + +extern void +Ecb_load_error() +{ + + printf("\nERROR:-"); + + if ((Ecb_error()) == FOUND) return; + if ((Gpib_error()) == FOUND) return; + + + exit(0); + +} + diff --git a/utils/ecb_load_new/ecb_load.h b/utils/ecb_load_new/ecb_load.h new file mode 100644 index 0000000..644e1fd --- /dev/null +++ b/utils/ecb_load_new/ecb_load.h @@ -0,0 +1,143 @@ +/******************************************************************************* +* This file contains the header defs for the ECB download program +* +* File name: ecb_load.h +* +* Author: P.S. May 2004 +* +*******************************************************************************/ +/******************************************************************************* +/******************************************************************************* +*& 'ecbdriv.h' modifications: +*& +*& +*******************************************************************************/ +/**************************************************************************************** +* Declaration of data types. +****************************************************************************************/ +typedef int Long; /* 32 bits integer */ + +/* GPIB interface */ +/**************************************************************************************** +* Constants. +****************************************************************************************/ +#define TC_FAR +#define F_BUFSIZ 256 /* 256 characters per line */ +#define NUL ('\0') /* Binary null character */ +#define ACKN ('\6') /* Acknowledge character */ +#define FOUND 1 /* Symbol found in Put/Get_variable */ +#define NOT_FOUND 0 /* Symbol not found Put/Get_variable */ +#define GLOBAL 2 /* Sym. used in more Put/Get_variable */ + +#ifndef TRUE +#define TRUE 1 /* Logical true */ +#endif +#ifndef FALSE +#define FALSE 0 /* Logical false */ +#endif + +/******************************************************************************* +* ECB type definitions. +*******************************************************************************/ + +typedef struct /* Z80 registers transferred in function calls */ + { + unsigned char d; /* D register in Z80 */ + unsigned char e; /* E register in Z80 */ + unsigned char b; /* B register in Z80 */ + unsigned char c; /* C register in Z80 */ + } Z80_reg; + +typedef union /* Used to swap bytes in 'address' and 'byte_count' */ + { + unsigned short word; + struct + { + unsigned char msb; /* Most significant byte */ + unsigned char lsb; /* Least significant byte */ + }b; + }Swap; + +typedef union /* Used to read DMA data from the P2701a CPU module */ + { + unsigned char *byte; /* Four 8 bit bytes per 32 bit integer word */ + Long *word; + }Ecb_data; + + +/******************************************************************************* +* ECB basic functions. +*******************************************************************************/ +#define READ_N_BYTES 3 /* ECB function to read n bytes */ +#define WRITE_N_BYTES 4 /* ECB function to write n bytes */ +#define DMA_READ 5 /* ECB function to DMA read n bytes */ + +#define ECB_DOWN_LOAD 178 /* ECB function to download the ECB program */ +#define LOAD_NEXT 1 /* Return code from download function */ +#define ECB_TYPE 157 /* Returns ECB ROM or RAM and version */ + +#define TYPE_OUT 2 /* Returns type from function 157 */ +#define VERS_OUT 3 /* Returns version from function 157 */ + + +/******************************************************************************* +* GPIB and ECB implementation environment. +*******************************************************************************/ +#define GPIB_H "/usr/local/include/ugpib.h" +#define GPIB0 "gpib0" /* Name of adater board No. 0 */ +#define ECB1 "dev5" /* Name of ECB system #1 */ +#define ECBTEXT "ECB SYSTEM" +#define ECB2 "dev4" /* Name of ECB system #2 */ +#define DEFAULT_TIMO T3s /* Default timeout 3 sec. */ +#define ECB_BYTES 65536L /* Max No. of bytes to transfer in each call */ + +/******************************************************************************* +* Error codes +*******************************************************************************/ +#define TAS_ERROR 100 /* General error */ +#define OPEN_FILE 600 /* Could not open file */ +#define FILE_READ 601 /* Could not read file */ +#define WRITE_FILE 602 /* Could not write to file */ +#define GPIB_WRITE_ERROR 700 +#define GPIB_READ_ERROR 701 +#define GPIB_FIND_ERROR 702 /* Could not 'open' device */ +#define GPIB_NO_LISNER_ERROR 703 +#define ECB_ILLEGAL_FUNC 750 /* No such ECB function */ +#define ECB_OVERFLOW 751 /* Byte count exceeds array size */ + +/******************************************************************************* +* Globals +*******************************************************************************/ +extern int x_tas_error; /* Global error type */ +extern char *x_error_text; /* Error text line*/ +extern int x_error_int; /* Global error parameter */ +extern int x_gpib0; /* Unit descriptor for board (adaptor) 0 */ +extern int x_ecb1; /* Unit descriptor of ECB system #1 */ +extern Z80_reg x_inreg; /* Z80 registers b,c,d and e before call */ +extern Z80_reg x_outreg; /* Z80 registers b,c,d and e after call */ +extern unsigned char x_ecb_data[]; /* Array to hold data blocks for ECB */ +extern int x_ecb_error_count; /* Counter for ECB call errors */ +extern Ecb_data x_ecba; /* DMA data from P2701a ECB-CPU */ +extern int x_cpu_typ; /* =0: WP-CPU, =1: P2701 */ + + +/******************************************************************************* +* Functions +*******************************************************************************/ +extern void Gpib_init (void); +extern int Gpib_error(void); + +extern int Ecb_func (int , unsigned char); /* Call ECB function */ +extern void Ecb_read (int, unsigned short, unsigned short); /* Read n bytes */ +extern void Ecb_write (int, unsigned short, unsigned short); /* Write n bytes */ +extern int Ecb_dma_read (int, unsigned short, unsigned short); /* DMA data */ +extern void Ecb_memory_allocate (int size); +extern int Ecb_type (int); + +extern void Ecb_init(void); +extern int Ecb_error(void); + +extern void Ecb_load_error(void); /* Print error messages */ +extern void Error_exit(void); +extern int Base_error(void); + diff --git a/utils/ecb_load_new/ecbdriv_els.c b/utils/ecb_load_new/ecbdriv_els.c new file mode 100644 index 0000000..c363c92 --- /dev/null +++ b/utils/ecb_load_new/ecbdriv_els.c @@ -0,0 +1,725 @@ +/******************************************************************************* +* This file contains the TASCOM ECB driver functions. +* +* +* Project: TASCOM +* File name: ecbdriv_els.c +* +* Author: J. Bundgaard Nov. 1991. +* +* +* +* Copyright (C) Risoe National Laboratory, 1991-1994, All rights reserved +*******************************************************************************/ +/******************************************************************************* +*& modified by: +*& +*& +*& V003.101 P.S. 26-APR-2004 +*& For the ecb_load program only. +*& +*& +*&*****************************************************************************/ + +#include +#include + +#include "ecb_load.h" +#include GPIB_H + +/******************************************************************************* +* Static variables +*******************************************************************************/ +static repete = 1; +static int look_up[] = {10, 11, 12, 13, 14 ,15}; + +/******************************************************************************* +* External variables defined in this file. +*******************************************************************************/ +int x_ecb1 = -1; /* Unit descriptor of ECB system #1 */ +Z80_reg x_inreg; /* Z80 registers b,c,d and e before call */ +Z80_reg x_outreg; /* Z80 registers b,c,d and e after call */ +unsigned char x_ecb_data[ECB_BYTES]; /* Array to hold data blocks for ECB */ +int x_ecb_error_count = 0; /* Counter for ECB call errors */ +int x_cpu_typ = 0; /* =0: WP-CPU, =1: P2701, =2: P2701 + P2501 */ +Ecb_data x_ecba; /* DMA data from P2701a ECB-CPU */ + +/******************************************************************************* +* Prototypes for functions defined in this file. +*******************************************************************************/ +extern void Ecb_init(void); +extern int Ecb_error(void); +extern void Ecb_unit (void); /* Establish unit No. for ECB */ +extern int Ecb_func (int , unsigned char); /* Call ECB function */ +extern void Ecb_read (int, unsigned short, unsigned short); /* Read n bytes */ +extern void Ecb_write (int, unsigned short, unsigned short); /* Write n bytes */ + +static int Ecb_prepare (int, unsigned char, unsigned short, unsigned short); +static int Ecb_send_func (int, unsigned char); /* Send function code */ +static void Ecb_error_func (char *, unsigned char, int); +static void Restart_ecb_func (int unit, unsigned char function); +static int Restart_ecb_prepare(int,unsigned char,unsigned short,unsigned short); +static void Do_reset (void); +extern void Ecb_down_load (FILE *stream); +static unsigned long Hex_to_bin(char c); +static char Bin_to_hex (int i); +extern int Ecb_type (int); + +/******************************************************************************* +* ECB system initialisation +*******************************************************************************/ + +extern void +Ecb_init(void) +{ + + x_cpu_typ = 1; /* New CPU module, P2701 */ + + x_ecb1 = -1; + if (x_gpib0 >= 0) + { + x_ecb1 = ibfind (ECB1); /* Now see if the ECB system is avaiable */ + if (x_ecb1 <= 0) + { + x_ecb1 = -1; + x_error_text =(char *) ECB1; + x_tas_error = GPIB_FIND_ERROR; + Ecb_load_error(); + } + else + { + ibsic (x_gpib0); /* Send interface clear */ + usleep (300000); /* Wait 0.3 sec. */ + ibtmo (x_ecb1, T10s); /* Time out 10 sec. */ + } + } + + x_tas_error = FALSE; + + return; +} +/******************************************************************************* +* Function to call a Z80 function (subroutine) without interrupt. +* This means that the function No. must be greater than or equal to +* 128 (function 0) and less than or equal to 191 (function 63). +* 'Unit' is the address of the ECB system on the GPIB bus. Four Z80 regs. +* are transferred upon the call from the host to the ECB system, and +* again read back to the host upon exit from the ECB function. This +* mechanismen is used to tranfer of arguments and results. Two global +* structures are used for the purpose, x_inreg and x_outreg. +*******************************************************************************/ + +extern int +Ecb_func (int unit, unsigned char function) +{ + int byte_cnt; + short status; + char *ecb_error_text; + void TC_FAR *point_input = &x_inreg; + void TC_FAR *point_output = &x_outreg; + + if (Ecb_send_func (unit, function) == FALSE) + { + if (repete == 1) + Restart_ecb_func (unit, function); /* GPIB error: recall Ecb_func() once */ + return (FALSE); + } + + /* Function accepted. Send the 4 Z80 register values */ + byte_cnt = 4; + status = ibwrt (unit, point_input, byte_cnt); + if (status < 0) + { + if (repete ==1) + { + Restart_ecb_func (unit, function); /* GPIB error: recall Ecb_func() once */ + return; + } + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_WRITE_ERROR; + ecb_error_text = "during write of data bytes at ECB function"; + Ecb_error_func(ecb_error_text, function, unit); + return(FALSE); + } + /* Wait for the function to complete and then receive the 4 Z80 regs. values */ + status = ibrd (unit, point_output, byte_cnt); + if (status < 0) + { + if (repete ==1) + { + Restart_ecb_func (unit, function); /* GPIB error: recall Ecb_func() once */ + return(FALSE); + } + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_READ_ERROR; + ecb_error_text = "during read of data bytes at ECB function"; + Ecb_error_func(ecb_error_text, function, unit); + return(FALSE); + } + return(TRUE); +} + + +/******************************************************************************* +* Function to re-call Ecb_func() in case of a GPIB bus error. +*******************************************************************************/ + +static void +Restart_ecb_func (int unit, unsigned char function) +{ + + Do_reset(); + Ecb_func (unit, function); + repete = 1; /* Reset repete to allow re-calls */ + return; +} + + + + +/******************************************************************************* +* Function to re-call Ecb_send_func() in case of a GPIB bus error. +*******************************************************************************/ + +static int +Restart_ecb_prepare (int unit, unsigned char function, + unsigned short address, unsigned short byte_count) +{ + short status; + + Do_reset(); + status = Ecb_prepare (unit, function, address, byte_count); + repete = 1; /* Reset repete to allow re-calls */ + return(status); +} + + + + +/******************************************************************************* +* Send Interface clear and print a message. +*******************************************************************************/ + +static void +Do_reset (void) +{ + ibsic (x_gpib0); /* Send interface clear */ + usleep (300000); /* Wait 0.3 sec. */ + ibsic (x_gpib0); /* Send interface clear */ + usleep (300000); /* Wait 0.3 sec. */ + repete = 0; /* No more re-calls */ + return; +} + + + +/******************************************************************************* +* Function that transfers 'byte_count' bytes from the ECB system to +* the host. 'Address' specifies source start address in the Z80 me- +* mory space. Destination is the global unsigned character array +* x_ecb_data. +*******************************************************************************/ + +extern void +Ecb_read (int unit, unsigned short address, unsigned short byte_count) +{ + short status; + void TC_FAR *point_data = &x_ecb_data; + + if (Ecb_prepare (unit, READ_N_BYTES, address, byte_count) == FALSE) + return; + + /* Read the requested No. of bytes */ + status = ibrd (unit, point_data, (int) byte_count); + if (status < 0) + { + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_READ_ERROR; + return; + } + return; +} + + +/******************************************************************************* +* Function that transfers 'byte_count' bytes from the host to the ECB +* system. 'Address' specifies destination start address in the Z80 me- +* mory space. Source is the global unsigned character array x_ecb_data. +*******************************************************************************/ + +extern void +Ecb_write (int unit, unsigned short address, unsigned short byte_count) +{ + short status; + char *ecb_error_text; + void TC_FAR *point_data = &x_ecb_data; + + if (Ecb_prepare (unit, WRITE_N_BYTES, address, byte_count) == FALSE) + return; + + /* Write the requested No. of bytes */ + status = ibwrt (unit, point_data, (int) byte_count); + if (status < 0) + { + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_WRITE_ERROR; + ecb_error_text = ""; + Ecb_error_func(ecb_error_text, 0, unit); + return; + } + + /* Receive a dummy byte */ + byte_count = 1; + status = ibrd (unit, point_data, (int) byte_count); + if (status < 0) + { + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_READ_ERROR; + return; + } + + return; +} + + +/******************************************************************************* +* Prepare an ECB read or write n bytes. See Ecb_read() and Ecb_write(). +*******************************************************************************/ +static int +Ecb_prepare (int unit, unsigned char function, + unsigned short address, unsigned short byte_count) +{ + int byte_cnt; + short status; + Swap save, adr, count; + char *ecb_error_text; + void TC_FAR *point_adress = (Swap *) &adr.word; + void TC_FAR *point_count = (Swap *) &count.word; + + if (byte_count > ECB_BYTES) + { + x_error_int = byte_count; + x_tas_error = ECB_OVERFLOW; + ecb_error_text = ""; + Ecb_error_func(ecb_error_text, 0, unit); + return (FALSE); + } + + save.word = address; /* Swap address bytes */ + adr.b.lsb = save.b.msb; + adr.b.msb = save.b.lsb; + save.word = byte_count; /* Swap byte count bytes */ + count.b.lsb = save.b.msb; + count.b.msb = save.b.lsb; + + if (Ecb_send_func (unit, function) == FALSE) + { + if (repete ==1) + { /* GPIB error, Restart Ecb_prepare() once */ + status = Restart_ecb_prepare (unit, function, address, byte_count); + return(status); + } + ecb_error_text = "during write of ECB function code "; + Ecb_error_func(ecb_error_text, function, unit); + return (FALSE); + } + + byte_cnt = 2; /* Function accepted, send the two byte address value */ + status = ibwrt (unit, point_adress, byte_cnt); + if (status < 0) + { + if (repete ==1) + { /* GPIB error, Restart Ecb_prepare() once */ + Restart_ecb_prepare (unit, function, address, byte_count); + return(status); + } + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_WRITE_ERROR; + ecb_error_text = ""; + Ecb_error_func(ecb_error_text, 0, unit); + return (FALSE); + } + /* Send the two byte byte_count value */ + status = ibwrt (unit, point_count, byte_cnt); + if (status < 0) + { + if (repete ==1) + { /* GPIB error, Restart Ecb_prepare() once */ + Restart_ecb_prepare (unit, function, address, byte_count); + return(status); + } + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_WRITE_ERROR; + ecb_error_text = ""; + Ecb_error_func(ecb_error_text, 0, unit); + return (FALSE); + } + return (TRUE); +} + +/******************************************************************************* +* Function to send ECB function code and receive an acknowledge +* character as response. +*******************************************************************************/ + +static int +Ecb_send_func (int unit, unsigned char function) +{ + unsigned char response; + unsigned long byte_cnt; + int error_type; + short status; + char *ecb_error_text; + void TC_FAR *point_func = &function; + void TC_FAR *point_resp = &response; + + byte_cnt = 1; /* Send function code */ + status = ibwrt (unit, point_func, byte_cnt); + error_type = iberr; + if (status < 0) + { + if (repete == 1) + return(FALSE); + if (status | TIMO) + { + if ((error_type == ENOL) || (error_type == EBUS)) + { + x_error_text = ECBTEXT; + x_tas_error = GPIB_NO_LISNER_ERROR; + Ecb_load_error(); + return (FALSE); + } + x_error_text = "Timeout"; + } + else + x_error_text = '\0'; + x_tas_error = GPIB_WRITE_ERROR; + Ecb_load_error(); + return (FALSE); + } + + /* Get acknowledge byte back */ + status = ibrd (unit, point_resp, byte_cnt); + if (status < 0) + { + if (repete == 1) + return(FALSE); + if (status | TIMO) + x_error_text = "Timeout"; + else + x_error_text = '\0'; + x_tas_error = GPIB_READ_ERROR; + ecb_error_text = "during read of ack-byte at ECB function "; + Ecb_error_func(ecb_error_text, function, unit); + return (FALSE); + } + if (response != ACKN) /* Acknowledge ? */ + { + x_error_int = function; + x_tas_error = ECB_ILLEGAL_FUNC; + ecb_error_text = " ECB function code "; + Ecb_error_func(ecb_error_text, function, unit); + return (FALSE); + } + return (TRUE); +} + + + +/******************************************************************************* +* Errors at calls to the ECB system. After two ECB errors TASCOM +* returns to DOS. +*******************************************************************************/ + +static void +Ecb_error_func (char *ecb_error_text, unsigned char function, int unit) +{ + + Ecb_load_error(); + if (function != 0) + { + printf ("%s %d\n",ecb_error_text, function); + fflush (stdout); + exit(0); + } + + return; +} + +/******************************************************************************* +* Errors at calls to the ECB system. After two ECB errors TASCOM +* returns to DOS. +*******************************************************************************/ + +static void +Ecb_error_func1 (char *ecb_error_text, unsigned char function, int unit) +{ + + Ecb_load_error(); + if (function != 0) + { + printf ("%s %d\n",ecb_error_text, function); + fflush (stdout); + exit(0); + } + + return; +} + + + +/****************************************************************************** +* Down load the ECB program. +* Reads lines from the HEX file and add up to 20 data lines together before +* sending them to the ECB system. +******************************************************************************/ + +extern void +Ecb_down_load (FILE *stream) +{ + int ecb_type, unit, function, load_count = -1; + char *point; + unsigned short byte_count, address; + char line[F_BUFSIZ]; + unsigned long type, no_bytes, adrs, total_bytes, old_adrs, total1, total0, total2; + int line_no = 0; + void TC_FAR *point_func = &function; + int line_not_output = 0; /* if =1: data waiting in line[] */ + void TC_FAR *line9 = &line[9]; + + +/* Stop_display(); */ + for (;;) + { + if (line_not_output == 1) + line_not_output = 0; /* Start with old line */ + else + { /* Read a line from file */ + point = fgets (line, F_BUFSIZ, stream); + if (point != NULL) + { + byte_count = strlen(line); + byte_count -= 4; /* Remove checksum and \n in the */ + line[byte_count+1] = NUL; /* line, i.e. the four last characters */ + line[0] = '0'; /* Replace : in line[0] with 0 */ + } + else + { + if (!ferror(stream)) + byte_count = 0; + else + { + fclose (stream); + stream = NULL; + x_tas_error = FILE_READ; + Ecb_load_error (); + printf (" during download of the ECB program\n"); +/* Start_display(); */ + return; + } + } + } + line_no += 1; + if (byte_count != 0) + { + if (line_no == 1) + strcpy (x_ecb_data, line); + type = (Hex_to_bin(line[7]) << 4) + Hex_to_bin(line[8]); + if (type != 0) + { + if (line_no > 1) /* Output buffer and mark that */ + line_not_output = 1; /* last input line has not been output */ + } + else + { + no_bytes = (Hex_to_bin(line[1]) << 4) + Hex_to_bin(line[2]); + adrs = (Hex_to_bin(line[3]) << 12) + (Hex_to_bin(line[4]) << 8) + + (Hex_to_bin(line[5]) << 4) + Hex_to_bin(line[6]); + if (line_no == 1) + { + total_bytes = no_bytes; + old_adrs = adrs; + continue; /* Get next input line */ + } + else + { + if (old_adrs + no_bytes == adrs) + { /* Contigious addresses */ + total_bytes += no_bytes; + old_adrs = adrs; + strcat (x_ecb_data, line9); /* Add the new bytes to buffer */ + total0 = total_bytes/256; /* and adjust number of bytes */ + x_ecb_data[0] = Bin_to_hex(total0); + total1 = total_bytes - 256*total0; + total2 = total1/16; + x_ecb_data[1] = Bin_to_hex(total2); + x_ecb_data[2] = Bin_to_hex(total1 - 16*total2); + if (line_no < 20) /* Max 20 lines together */ + continue; /* Get next input line */ + } + } + line_not_output = 0; /* Output buffer, nothing waiting in line[] */ + } + + unit = x_ecb1; + address = 1; + byte_count = strlen (x_ecb_data); + Ecb_write (unit, address, byte_count); /* Write a line to ECB */ + line_no = 0; + +/* if (Test_ctrl_c()) +/* { +/* Start_display(); +/* return; /* Control(c) hit */ +/* } +*/ + + if (load_count == -1) /* Type Loading followed by dots while */ + { /* down loading the file */ + printf ("\nLoading"); + fflush (stdout); + load_count = 0; + } + load_count += 1; + + if (load_count > 15) + { + printf ("."); + fflush (stdout); + load_count = 0; + } + + + function = ECB_DOWN_LOAD; + Ecb_func (unit, function); /* Call ECB download function */ + if (x_outreg.b != LOAD_NEXT) /* Wait for reply from ECB */ + break; /* If LOAD_NEXT, get next line, else finished */ + } + } + printf ("\nLoading complete\n"); + fflush (stdout); + +/* Start_display(); */ + return; +} + +/******************************************************************************* +* Convert HEX to bin +*******************************************************************************/ + +static unsigned long +Hex_to_bin(char c) +{ + + if(isdigit((int) c)) + return (c - '0'); + else + return look_up[c - 'A']; +} + + +/******************************************************************************* +* Convert Bin to HEX +*******************************************************************************/ + +static char +Bin_to_hex (int i) +{ + + if(i <= 9) + return ( (char)(i + (int)('0')) ); + else + return ( (char)( (i - 10) + (int)('A')) ); +} + + +/****************************************************************************** +* Get type and version of the ECB program. If return_value is TYPE_OUT, the +* type is returned as 1 for RAM and 0 for ROM. If return_value is VERS_OUT, +* the version number * 100 is returned. +* If return_value = 0, type and version are printed. +******************************************************************************/ + +extern int +Ecb_type (int return_value) +{ + int unit, function; + int version, status; + + + /* P2701a CPU: Get ROM/RAM type */ + unit = x_ecb1; + function = ECB_TYPE; + status = Ecb_func (unit, function); + if (status == 0) + exit(0); + + + version = 100*(int)x_outreg.b + 10*(int)x_outreg.c + (int)x_outreg.e; + + if (return_value == TYPE_OUT) + return((int) x_outreg.d); + + if (return_value == VERS_OUT) + return(version); + + printf ("ECB program: "); + if (x_outreg.d == 1) + printf ("RAM"); + else if (x_outreg.d == 0) + printf ("ROM"); + printf (" mode, version %4.2f\n", ((float) version)/100); + fflush (stdout); + + return((int) x_outreg.d); +} + + +/******************************************************************************* +* Ecb option error routine. +*******************************************************************************/ + +extern int +Ecb_error(void) +{ + + switch (x_tas_error) + { + case ECB_OVERFLOW: + printf (" Byte count %d overflows ECB data buffer.", x_error_int); + break; + + case ECB_ILLEGAL_FUNC: + printf (" No such ECB function: %d", x_error_int); + break; + + default: + return(NOT_FOUND); + } + + printf ("\n"); + fflush (stdout); + return(FOUND); + +} diff --git a/utils/ecb_load_new/gpib_els.c b/utils/ecb_load_new/gpib_els.c new file mode 100644 index 0000000..34f06a6 --- /dev/null +++ b/utils/ecb_load_new/gpib_els.c @@ -0,0 +1,116 @@ +/******************************************************************************* +* This file contains the interface for the gpib option +* in the Risoe process control and data acquisition program TASCOM. +* +* +* Project: TASCOM +* File name: gpib_els.c +* +* Author: P.S. May 2004 +* +* +* +*******************************************************************************/ +/******************************************************************************* +*& modificaions: +*& +*& V003.101 P.S. 26-APR-2004 +*& For the ecb_load program only. +*& +*& +*&*****************************************************************************/ + +#include +#include +#include +#include "ecb_load.h" + +#include GPIB_H + +/******************************************************************************* +* Static variables +*******************************************************************************/ + +/******************************************************************************* +* Extern variables defined in this file. +*******************************************************************************/ +int x_gpib0; /* Unit descriptor for board (adaptor) 0 */ + +/******************************************************************************* +* Prototypes for functions defined in this file. +*******************************************************************************/ +extern void Gpib_init (void); +extern int Gpib_error(void); + + +/******************************************************************************* +* Set the GPIB delay and if look_for_board = LOOK_FOR_BOARD, see if we have a +* GPIB module in the computer. +*******************************************************************************/ + +extern void +Gpib_init (void) +{ + + x_gpib0 = -1; + + /* See if the GPIB module is avaiable */ + x_gpib0 = ibfind (GPIB0); + if (x_gpib0 < 0) + { + x_error_text = (char *) GPIB0; + x_tas_error = GPIB_FIND_ERROR; + Ecb_load_error (); + return; + } + + ibconfig (x_gpib0, IbcTIMING, 1); + ibsic (x_gpib0); /* Send interface clear */ + usleep (300000); /* Wait 0.3 sec. */ + + x_tas_error = FALSE; + + + return; +} + + + +/******************************************************************************* +* Gpib option error routine. +*******************************************************************************/ + +extern int +Gpib_error(void) +{ + + switch (x_tas_error) + { + case GPIB_WRITE_ERROR: + printf (" GPIB write error: %s", x_error_text); + break; + + case GPIB_READ_ERROR: + printf (" GPIB read error: %s", x_error_text); + break; + + case GPIB_FIND_ERROR: + printf (" No GPIB module in the computer ?"); + break; + + case GPIB_NO_LISNER_ERROR: + printf (" No Listener. Communication error to the %s.\n", x_error_text); + break; + + default: + return(NOT_FOUND); + } + + printf ("\n"); + fflush (stdout); + return(FOUND); + +} + + + diff --git a/utils/ecb_load_new/makefile b/utils/ecb_load_new/makefile new file mode 100644 index 0000000..9ab41b2 --- /dev/null +++ b/utils/ecb_load_new/makefile @@ -0,0 +1,101 @@ + +# LIBRARY NAMES GIVEN BELOW +LIBRARIES=/usr/local/lib/libgpibenet.a + +# INCLUDE SEARCH PATH GIVEN BELOW +INCLUDES= -Iinclude + +VPATH=.:include + +# LINKER FLAGS GIVEN BELOW +LDFLAGS=-L/usr/local/lib + +# DEFINES +LD=gcc +CC=gcc + +# COMPILER FLAGS GIVEN BELOW +CFLAGS= -c -g +PFLAGS=$(CFLAGS) +FFLAGS=$(CFLAGS) + +.SUFFIXES: .uil .uid .c .o .f .for .F .hpf .mpl + + + + +# SOURCES GIVEN BELOW +SRCS=ecb_load.c ecbdriv_els.c gpib_els.c + +# OBJECTS GIVEN BELOW +OBJS=ecb_load.o ecbdriv_els.o gpib_els.o + +ecb_load : $(OBJS) + $(LD) -g -o $@ $(LDFLAGS) $(OBJS) $(LIBRARIES) -lm -ltermcap + + +# INCLUDE FILE DEPENDENCY GIVEN BELOW + +ecb_load.o: ecb_load.h + +ecbdriv_els.o: ecb_load.h + +gpib_els.o: ecb_load.h + + + +clean: + $(RM) -rf $(OBJS) core tascom + + +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) $< + +.f.o: + $(FC) -c $(FFLAGS) $(INCLUDES) $< + + +.p.o: + $(PC) -c $(PFLAGS) $(INCLUDES) $< + + +.c.a: + $(CC) -c $(CFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +.f.a: + $(FC) -c $(FFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +.p.a: + $(PC) -c $(PFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +lint: + lint $(INCLUDES) $(SRCS) $(LINTLIBS) + + +depend: + @cat < /dev/null > makedep + @for i in ${SRCS}; do \ + ($(CC) -M $(INCLUDES) $$i >> makedep); done + @echo '/^# DO NOT DELETE THIS LINE/+1,$$d' > eddep + @echo '$$r makedep' >> eddep + @echo 'w' >> eddep + @${CP} makefile makefile.bak + @ed - makefile < eddep + @$(RM) -f eddep makedep + @echo '# DO NOT EDIT THIS FILE HERE.' >> makefile + @echo '# USER EDITS MUST PRECEDE THE COMMENT:' >> makefile + @echo '# "# DO NOT DELETE THIS LINE".' >> makefile + @echo '# see make depend above' >> makefile + + +touchsrcs: + touch $(SRCS) + +# DO NOT DELETE THIS LINE -- make depend uses it + diff --git a/utils/ecb_load_new/makefile_EGPIB b/utils/ecb_load_new/makefile_EGPIB new file mode 100644 index 0000000..e7fd6cd --- /dev/null +++ b/utils/ecb_load_new/makefile_EGPIB @@ -0,0 +1,103 @@ + +# LIBRARY NAMES GIVEN BELOW +LIBRARIES=/usr/local/lib/libgpibenet.a + +# INCLUDE SEARCH PATH GIVEN BELOW +INCLUDES= -Iinclude + +VPATH=.:include + +# LINKER FLAGS GIVEN BELOW +LDFLAGS=-L/usr/local/lib + +# DEFINES +LD=gcc +CC=gcc + +# COMPILER FLAGS GIVEN BELOW +CFLAGS= -c -g +PFLAGS=$(CFLAGS) +FFLAGS=$(CFLAGS) + +.SUFFIXES: .uil .uid .c .o .f .for .F .hpf .mpl + + + + +# SOURCES GIVEN BELOW +SRCS=ecb-load.c ecbdriv_els.c gpib_els.c error_els.c + +# OBJECTS GIVEN BELOW +OBJS=ecb-load.o ecbdriv_els.o gpib_els.o error_els.o + +ecb_load : $(OBJS) + $(LD) -o $@ $(LDFLAGS) $(OBJS) $(LIBRARIES) -lm -ltermcap + + +# INCLUDE FILE DEPENDENCY GIVEN BELOW + +ecb_load.o: ecb_load.h + +ecbdriv_els.o: ecb_load.h + +gpib_els.o: ecb_load.h + +error_els.o: ecb_load.h + + + +clean: + $(RM) -rf $(OBJS) core tascom + + +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) $< + +.f.o: + $(FC) -c $(FFLAGS) $(INCLUDES) $< + + +.p.o: + $(PC) -c $(PFLAGS) $(INCLUDES) $< + + +.c.a: + $(CC) -c $(CFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +.f.a: + $(FC) -c $(FFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +.p.a: + $(PC) -c $(PFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +lint: + lint $(INCLUDES) $(SRCS) $(LINTLIBS) + + +depend: + @cat < /dev/null > makedep + @for i in ${SRCS}; do \ + ($(CC) -M $(INCLUDES) $$i >> makedep); done + @echo '/^# DO NOT DELETE THIS LINE/+1,$$d' > eddep + @echo '$$r makedep' >> eddep + @echo 'w' >> eddep + @${CP} makefile makefile.bak + @ed - makefile < eddep + @$(RM) -f eddep makedep + @echo '# DO NOT EDIT THIS FILE HERE.' >> makefile + @echo '# USER EDITS MUST PRECEDE THE COMMENT:' >> makefile + @echo '# "# DO NOT DELETE THIS LINE".' >> makefile + @echo '# see make depend above' >> makefile + + +touchsrcs: + touch $(SRCS) + +# DO NOT DELETE THIS LINE -- make depend uses it + diff --git a/utils/ecb_load_new/makefile_GPIB b/utils/ecb_load_new/makefile_GPIB new file mode 100644 index 0000000..9510772 --- /dev/null +++ b/utils/ecb_load_new/makefile_GPIB @@ -0,0 +1,103 @@ + +# LIBRARY NAMES GIVEN BELOW +LIBRARIES=/usr/local/lib/libgpib.a + +# INCLUDE SEARCH PATH GIVEN BELOW +INCLUDES= -Iinclude + +VPATH=.:include + +# LINKER FLAGS GIVEN BELOW +LDFLAGS=-L/usr/local/lib + +# DEFINES +LD=gcc +CC=gcc + +# COMPILER FLAGS GIVEN BELOW +CFLAGS= -c -g +PFLAGS=$(CFLAGS) +FFLAGS=$(CFLAGS) + +.SUFFIXES: .uil .uid .c .o .f .for .F .hpf .mpl + + + + +# SOURCES GIVEN BELOW +SRCS=ecb-load.c ecbdriv_els.c gpib_els.c error_els.c + +# OBJECTS GIVEN BELOW +OBJS=ecb-load.o ecbdriv_els.o gpib_els.o error_els.o + +ecb_load : $(OBJS) + $(LD) -o $@ $(LDFLAGS) $(OBJS) $(LIBRARIES) -lm -ltermcap + + +# INCLUDE FILE DEPENDENCY GIVEN BELOW + +ecb_load.o: ecb_load.h + +ecbdriv_els.o: ecb_load.h + +gpib_els.o: ecb_load.h + +error_els.o: ecb_load.h + + + +clean: + $(RM) -rf $(OBJS) core tascom + + +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) $< + +.f.o: + $(FC) -c $(FFLAGS) $(INCLUDES) $< + + +.p.o: + $(PC) -c $(PFLAGS) $(INCLUDES) $< + + +.c.a: + $(CC) -c $(CFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +.f.a: + $(FC) -c $(FFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +.p.a: + $(PC) -c $(PFLAGS) $(INCLUDES) $< + $(AR) $(ARFLAGS) $@ $*.o + $(RM) -f $*.o + +lint: + lint $(INCLUDES) $(SRCS) $(LINTLIBS) + + +depend: + @cat < /dev/null > makedep + @for i in ${SRCS}; do \ + ($(CC) -M $(INCLUDES) $$i >> makedep); done + @echo '/^# DO NOT DELETE THIS LINE/+1,$$d' > eddep + @echo '$$r makedep' >> eddep + @echo 'w' >> eddep + @${CP} makefile makefile.bak + @ed - makefile < eddep + @$(RM) -f eddep makedep + @echo '# DO NOT EDIT THIS FILE HERE.' >> makefile + @echo '# USER EDITS MUST PRECEDE THE COMMENT:' >> makefile + @echo '# "# DO NOT DELETE THIS LINE".' >> makefile + @echo '# see make depend above' >> makefile + + +touchsrcs: + touch $(SRCS) + +# DO NOT DELETE THIS LINE -- make depend uses it + diff --git a/utils/make.ecb b/utils/make.ecb deleted file mode 100644 index 7b970cf..0000000 --- a/utils/make.ecb +++ /dev/null @@ -1,26 +0,0 @@ -# -# Makefile for the ECB load program on Linux, PSI setup -CC =cc -CFLAGS = -g -I$(SINQDIR)/linux/include -OBJS = ecb-drv.o ecb-load.o gpib-drv.o -LIBS = $(SINQDIR)/linux/lib/libgpibenet.so - -######################################################################### - -ecb-load: $(OBJS) - $(CC) -g -o ecb-load $(OBJS) $(LIBS) -lfl - -ecb-drv.o: ecb-drv.c ecb-drv.h gpib-drv.h - $(CC) $(CFLAGS) -c ecb-drv.c - -ecb-load.o: ecb-load.c ecb-drv.h gpib-drv.h - $(CC) $(CFLAGS) -c ecb-load.c - -gpib-drv.o: gpib-drv.c gpib-drv.h - $(CC) $(CFLAGS) -c gpib-drv.c - -clean: - -rm *~ - -rm $(OBJS) - -rm ecb-load - -rm core