Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 117 → Rev 127

/lab/sipmscan/trunk/input/Makefile.in
41,7 → 41,7
$(TARGET): $(FILES) workstation.h daq.h library $(SHLIB)
@echo "Generating dictionary Dict.C..."
rootcint -f GuiDict.C -c $(INC) $(CPPFLAGS) windowed_test.h GuiLinkDef.h
$(CXX) $(INC) -DG__DICTIONARY -fPIC -g -Wall $(FILES) GuiDict.C $(CPPFLAGS) $(VXI_OBJECT) -o $(TARGET) $(SHLIB) $(LIBS1) -lstdc++ -lSpectrum
$(CXX) $(INC) -fPIC -g -Wall $(FILES) GuiDict.C $(CPPFLAGS) $(VXI_OBJECT) -o $(TARGET) $(SHLIB) $(LIBS1) -lstdc++ -lSpectrum
# -----------------------------------------------------------------------------
 
# CAMAC DAQ library rules -----------------------------------------------------
73,7 → 73,7
libdaqusb.so: $(DAQFILE) $(LIBFILE)
@echo "Generating dictionary Dict.C..."
rootcint -f Dict.C -c $(INC) $(CPPFLAGS) $(HEADER) GuiLinkDef.h
$(CXX) -DG__DICTIONARY $(CPPFLAGS) $(INC) -fPIC -g -Wall $(DAQFILE) Dict.C $(CAMLIB) -shared -o $@
$(CXX) $(CPPFLAGS) $(INC) -fPIC -g -Wall $(DAQFILE) Dict.C $(CAMLIB) -shared -o $@
 
# Rule for making the CAMAC DAQ library (libdaqusb.a)
$(LIBFILE): $(OBJ_FILES)
85,7 → 85,7
libvxi11.so: libvxi11.a
@echo "Generating dictionary VxiDict.C..."
rootcint -f VxiDict.C -c $(INC) $(CPPFLAGS) daqscope.h GuiLinkDef.h
$(CXX) -DG__DICTIONARY $(CPPFLAGS) $(INC) -fPIC -g -Wall daqscope.C VxiDict.C -L. libvxi11.a -shared -o $@
$(CXX) $(CPPFLAGS) $(INC) -fPIC -g -Wall daqscope.C VxiDict.C -L. libvxi11.a -shared -o $@
 
libvxi11.a: $(VXI_OBJECT)
ar r $@ $^
95,5 → 95,5
 
# Rule for cleaning the installation
clean:
rm -f Dict.C Dict.h GuiDict.C GuiDict.h windowed_test windowed_test_C.d windowed_test_C.so curpos.txt curvolt.txt workstation.h VxiDict.C VxiDict.h daqscope.C daqusb.C start.sh
rm -f Dict.C Dict.h GuiDict.C GuiDict.h windowed_test windowed_test_C.d windowed_test_C.so curpos.txt curvolt.txt workstation.h VxiDict.C VxiDict.h daqscope.C daqusb.C start.sh usb.h libxxusb.h libdaqusb.a libdaqusb.so libvxi11.a libvxi11.so *.o finish_sig.txt
# -----------------------------------------------------------------------------
/lab/sipmscan/trunk/input/daqscope.C.in
1,16 → 1,58
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "vxi11_user.h"
#include "daqscope.h"
#include "workstation.h"
 
CLINK *clink;
char *savedIP;
const char *allChans[8] = {"CH1","CH2","CH3","CH4","MATH1","MATH2","MATH3","MATH4"};
const char *measType[11] = {"AMP","ARE","DEL","FALL","FREQ","MAX","MEAN","MINI","PK2P","PWI","RIS"};
char *bbq;
 
// Query and command functions to simplify analysis --------------
int vxi11_query(CLINK *clink, const char *mycmd)
{
char buf[WAVE_LEN];
memset(buf, 0, WAVE_LEN);
vxi11_send(clink, mycmd);
int bytes_returned = vxi11_receive(clink, buf, WAVE_LEN);
if (bytes_returned > 0)
{
printf("%s\n", buf);
}
else if (bytes_returned == -15)
printf("*** [ NOTHING RECEIVED ] ***\n");
 
return 0;
}
 
void vxi11_command(CLINK *clink,char *mycmd)
{
char buf[WAVE_LEN];
memset(buf, 0, WAVE_LEN);
vxi11_send(clink, mycmd);
}
// ---------------------------------------------------------------
 
// Tektronix unit conversion -------------------------------------
double daqscope::tekunit(char *prefix)
{
if (strcmp(prefix,"m")==0) return 0.001;
else if (strcmp(prefix,"u")==0) return 0.000001;
else if (strcmp(prefix,"n")==0) return 0.000000001;
else return 1;
}
// ---------------------------------------------------------------
 
// Connect to a scope through IP address IPaddr ------------------
int daqscope::connect(char *IPaddr)
{
int iTemp;
char buf[WAVE_LEN];
printf("daqscope::connect(%s)\n", IPaddr);
clink = new CLINK;
iTemp = vxi11_open_device(IPaddr, clink);
if(iTemp == 0)
24,17 → 66,319
else
return iTemp;
}
// ---------------------------------------------------------------
 
// Disconnect from scope with IP address IPaddr ------------------
int daqscope::disconnect(char *IPaddr)
{
int iTemp;
printf("daqscope::disconnect(%s)\n", IPaddr);
iTemp = vxi11_close_device(IPaddr, clink);
if(iTemp == 0)
{
printf("Disconnected from device (%s).\n", IPaddr);
delete clink;
delete clink;
}
return iTemp;
}
// ---------------------------------------------------------------
 
// Initialize the scope for waveform or measurement --------------
int daqscope::init()
{
int iTemp;
char cmd[512];
char cTemp[256];
printf("daqscope::init()\n");
 
printf("Measurement type is: %d\n", scopeUseType);
 
// For measurements, only one channel can be used (rise, fall, period,...)
if(scopeUseType == 2) scopeChanNr = 1;
printf("Nr. of channels selected: %d\n", scopeChanNr);
 
// Only use scope if measurement is different than 0
if(scopeUseType == 0)
return 0;
else
{
// Combine all selected channels into a comma separated string
for(int i = 0; i < scopeChanNr; i++)
{
if(i == scopeChanNr-1)
{
if(i == 0) sprintf(scopeChanstring, "%s", allChans[scopeChans[i]]);
else sprintf(cTemp, "%s", allChans[scopeChans[i]]);
}
else
{
if(i == 0) sprintf(scopeChanstring, "%s,", allChans[scopeChans[i]]);
else sprintf(cTemp, "%s,", allChans[scopeChans[i]]);
}
if(i > 0)
strcat(scopeChanstring, cTemp);
}
printf("Selected channels: %s\n", scopeChanstring);
 
// Check scope ID and turn the header display on
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_query(clink, "*IDN?");
vxi11_command(clink,(char*)"HEADER ON");
#else
printf("Identify Tek (*IDN?, HEADER ON)\n");
#endif
 
// Set the scope data sources
sprintf(cmd, "DATA:SOURCE %s", scopeChanstring);
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink,cmd);
#else
printf("Set data source (DATA:SOURCE): %s\n", cmd);
#endif
 
// Set to fast acquisition and set encoding
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink,(char*)"FASTACQ:STATE 0");
vxi11_command(clink,(char*)"DATA:ENCDG SRIBINARY");
vxi11_command(clink,(char*)"WFMO:BYT_N 2");
 
// Set gating (currently not used)
vxi11_command(clink,(char*)"GAT OFF");
#else
printf("Set fastacq, encoding and gating (FASTACQ:STATE 0, DATA:ENCDG SRIBINARY, WFMO:BYT_N 2, MEASU:GAT OFF).\n");
#endif
 
// Check scale on each of selected channels (is this even needed?)
bbq = strtok(scopeChanstring,",");
while(bbq != NULL)
{
sprintf(cmd,"%s:SCALE?",bbq);
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_query(clink,cmd);
#else
printf("Return the scale of channel: %s\n", cmd);
#endif
bbq = strtok(NULL, ",");
}
 
// Check waveform and data options/settings
char buf[WAVE_LEN];
memset(buf, 0, WAVE_LEN);
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_send(clink, "WFMO:WFID?");
iTemp = vxi11_receive(clink, buf, WAVE_LEN);
printf("Init out (length = %d): %s\n", iTemp, buf);
#else
printf("Get acquisition parameters (WFMOUTPRE:WFID?).\n");
sprintf(buf, ":WFMOUTPRE:WFID \"Ch1, DC coupling, 20.0mV/div, 10.0ns/div, 500 points, Sample mode\"");
iTemp = strlen(buf);
#endif
if (iTemp == -15)
printf("\n*** [ NOTHING RECEIVED ] ***\n");
else
{
bbq = strtok(buf,","); // break WFID out into substrings
for (int k = 0; k < 5; k++)
{
// info on voltage per division setting
if (k == 2)
{
memcpy(cTemp, &bbq[1], 5);
cTemp[5] = 0;
bbq[7] = 0;
tekvolt = atoi(cTemp)*tekunit(&bbq[6]);
printf("Voltage per division: %lf\n", tekvolt);
}
// info on time per division setting
if (k == 3)
{
memcpy(cTemp, &bbq[1], 5);
cTemp[5] = 0;
bbq[7] = 0;
tektime = atoi(cTemp)*tekunit(&bbq[6]);
printf("Time per division: %lf\n", tektime);
}
// info on last point to be transfered by CURVE?
if (k == 4)
{
bbq[strlen(bbq)-7] = 0;
sprintf(cmd, "DATA:STOP %d", atoi(bbq));
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink, cmd);
#else
printf("Stop data collection (DATA:STOP): %s\n", cmd);
#endif
}
// printf("bbq = %s\n",bbq);
bbq = strtok (NULL, ",");
}
}
 
// Recheck waveform and data options/settings, turn off header
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_query(clink,"WFMO:WFID?");
vxi11_query(clink,"DATA?");
vxi11_command(clink,(char*)"HEADER OFF");
#else
printf("Data format query (WFMOUTPRE:WFID?, DATA?, HEADER OFF).\n");
#endif
 
// Get the channel y-axis offset (only for one CH so far)
char posoff[WAVE_LEN];
#if WORKSTAT == 'I' || WORKSTAT == 'S'
sprintf(cmd, "%s:POS?", allChans[scopeChans[0]]);
vxi11_command(clink, cmd);
vxi11_receive(clink, posoff, WAVE_LEN);
choffset = (double)atof(posoff);
#else
printf("Check for channel position offset (CHx:POS?)\n");
#endif
 
// If measurements are to be performed
if(scopeUseType == 2)
{
sprintf(cmd, "MEASU:IMM:SOURCE1 %s", scopeChanstring);
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink, cmd);
#else
printf("Set immediate measurement source (MEASU:IMM:SOURCE1): %s\n", cmd);
#endif
 
sprintf(cmd, "MEASU:IMM:TYP %s", measType[scopeMeasSel]);
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink, cmd);
#else
printf("Set immediate measurement type (MEASU:IMM:TYP): %s\n", cmd);
#endif
}
 
return 0;
}
}
// ---------------------------------------------------------------
 
// Send a custom command to the scope ----------------------------
int daqscope::customCommand(char *command, bool query, char *sReturn)
{
if(query)
{
char buf[WAVE_LEN];
memset(buf, 0, WAVE_LEN);
vxi11_send(clink, command);
int bytes_returned = vxi11_receive(clink, buf, WAVE_LEN);
if (bytes_returned > 0)
{
printf("%s\n", buf);
sprintf(sReturn, "%s", buf);
 
// For testing purposes
/* if( strcmp(command, "CURVE?") == 0 )
{
FILE *fp;
char tst[2];
fp = fopen("./curve_return.txt","w");
for(int i = 6; i < bytes_returned; i++)
{
if(i%2 == 1)
{
tst[0] = buf[i];
tst[1] = buf[i-1];
fprintf(fp, "bytes returned = %d\tbyte %d = %d\treturn = %s\n", bytes_returned, i, buf[i], tst);
}
else
fprintf(fp, "bytes returned = %d\tbyte %d = %d\n", bytes_returned, i, buf[i]);
}
fclose(fp);
}*/
}
else if (bytes_returned == -15)
{
printf("*** [ NOTHING RECEIVED ] ***\n");
sprintf(sReturn, "*** [ NOTHING RECEIVED ] ***");
}
}
else
{
vxi11_command(clink, command);
sprintf(sReturn, "*** [ COMMAND NOT QUERY - NO RETURN ] ***");
}
 
return 0;
}
// ---------------------------------------------------------------
 
// Get a measuring event (either waveform or measure) ------------
int daqscope::lockunlock(bool lockit)
{
// Lock the scope front panel for measurements
if(lockit)
{
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink,(char*)"LOCK ALL");
return 0;
#else
// printf("Locking the front panel (LOCK ALL).\n");
return -1;
#endif
}
// Unlock the scope front panel after measurements
else
{
#if WORKSTAT == 'I' || WORKSTAT == 'S'
vxi11_command(clink,(char*)"LOCK NONE");
return 0;
#else
// printf("Unlocking the front panel (LOCK ALL).\n");
return -1;
#endif
}
}
// ---------------------------------------------------------------
 
// Get a measuring event (either waveform or measure) ------------
int daqscope::event()
{
int bytes_returned;
 
if(scopeUseType == 0)
return -1;
else if(scopeUseType == 1)
{
#if WORKSTAT == 'I' || WORKSTAT == 'S'
memset(eventbuf, 0, WAVE_LEN);
vxi11_send(clink, "CURVE?");
bytes_returned = vxi11_receive(clink, eventbuf, WAVE_LEN);
#else
printf("Ask to return the waveform (CURVE?)\n");
bytes_returned = 0;
#endif
 
if(bytes_returned > 0) return 0;
else return -1;
}
else if(scopeUseType == 2)
{
#if WORKSTAT == 'I' || WORKSTAT == 'S'
char buf[WAVE_LEN];
memset(buf, 0, WAVE_LEN);
vxi11_send(clink, "MEASU:IMMED:VALUE?");
bytes_returned = vxi11_receive(clink, buf, WAVE_LEN);
measubuf = (double)atof(buf);
#else
// printf("Ask to return the measurement (MEASU:IMMED:VALUE?)\n");
bytes_returned = 0;
measubuf = (double)rand()/(double)RAND_MAX;
#endif
 
if(bytes_returned > 0) return 0;
else return -1;
}
else
return -1;
}
// ---------------------------------------------------------------
 
// daqscope class constructor and destructor ---------------------
daqscope::daqscope() {
fStop=0;
}
42,3 → 386,4
daqscope::~daqscope() {
disconnect(savedIP);
}
// ---------------------------------------------------------------
/lab/sipmscan/trunk/input/daqusb.C.offline
25,7 → 25,7
//#define NADC 2 /* ADC */
//#define NADCCH 8
int ctrlc=0;
char *ccserial="CC0126";
char *ccserial=(char*)"CC0126";
int devDetect; // variable to tell if we detect any devices
 
int daq::connect(){
50,8 → 50,8
 
int daq::init(){
 
int i;
long k;
// int i;
// long k;
 
/* DBGFUNI(xxusb_register_write(udev,1,0x0)); // Stop DAQ mode
while (xxusb_usbfifo_read(udev, (int*) stackdump,BUFF_L,100)>0);
119,7 → 119,8
}
 
int daq::event(unsigned int *data, int maxn){
int i,ib,count;
// int i,ib,count;
int count;
/* int events,evsize;
short ret;
 
/lab/sipmscan/trunk/input/daqusb.C.online
25,7 → 25,7
//#define NADC 2 /* ADC */
//#define NADCCH 8
int ctrlc=0;
char *ccserial="CC0126";
char *ccserial=(char*)"CC0126";
int devDetect; // variable to tell if we detect any devices
 
int daq::connect(){
/lab/sipmscan/trunk/input/libxxusb.h.offline
0,0 → 1,111
#include "usb.h"
 
 
#define XXUSB_WIENER_VENDOR_ID 0x16DC /* Wiener, Plein & Baus */
#define XXUSB_VMUSB_PRODUCT_ID 0x000B /* VM-USB */
#define XXUSB_CCUSB_PRODUCT_ID 0x0001 /* CC-USB */
#define XXUSB_ENDPOINT_OUT 2 /* Endpoint 2 Out*/
#define XXUSB_ENDPOINT_IN 0x86 /* Endpoint 6 In */
#define XXUSB_FIRMWARE_REGISTER 0
#define XXUSB_GLOBAL_REGISTER 1
#define XXUSB_ACTION_REGISTER 10
#define XXUSB_DELAYS_REGISTER 2
#define XXUSB_WATCHDOG_REGISTER 3
#define XXUSB_SELLEDA_REGISTER 6
#define XXUSB_SELNIM_REGISTER 7
#define XXUSB_SELLEDB_REGISTER 4
#define XXUSB_SERIAL_REGISTER 15
#define XXUSB_LAMMASK_REGISTER 8
#define XXUSB_LAM_REGISTER 12
#define XXUSB_READOUT_STACK 2
#define XXUSB_SCALER_STACK 3
#define XXUSB_NAF_DIRECT 12
 
struct XXUSB_STACK
{
long Data;
short Hit;
short APatt;
short Num;
short HitMask;
};
 
struct XXUSB_CC_COMMAND_TYPE
{
short Crate;
short F;
short A;
short N;
long Data;
short NoS2;
short LongD;
short HitPatt;
short QStop;
short LAMMode;
short UseHit;
short Repeat;
short AddrScan;
short FastCam;
short NumMod;
short AddrPatt;
long HitMask[4];
long Num;
};
 
struct xxusb_device_typ
{
struct usb_device *usbdev;
char SerialString[7];
};
 
typedef struct xxusb_device_typ xxusb_device_type;
typedef unsigned char UCHAR;
typedef struct usb_bus usb_busx;
 
 
int xxusb_longstack_execute(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
int xxusb_bulk_read(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
int xxusb_bulk_write(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
int xxusb_usbfifo_read(usb_dev_handle *hDev, int *DataBuffer, int lDataLen, int timeout);
 
short xxusb_register_read(usb_dev_handle *hDev, short RegAddr, long *RegData);
short xxusb_stack_read(usb_dev_handle *hDev, short StackAddr, long *StackData);
short xxusb_stack_write(usb_dev_handle *hDev, short StackAddr, long *StackData);
short xxusb_stack_execute(usb_dev_handle *hDev, long *StackData);
short xxusb_register_write(usb_dev_handle *hDev, short RegAddr, long RegData);
short xxusb_reset_toggle(usb_dev_handle *hDev);
 
short xxusb_devices_find(xxusb_device_type *xxusbDev);
short xxusb_device_close(usb_dev_handle *hDev);
usb_dev_handle* xxusb_device_open(struct usb_device *dev);
short xxusb_flash_program(usb_dev_handle *hDev, char *config, short nsect);
short xxusb_flashblock_program(usb_dev_handle *hDev, UCHAR *config);
usb_dev_handle* xxusb_serial_open(char *SerialString);
 
short VME_register_write(usb_dev_handle *hdev, long VME_Address, long Data);
short VME_register_read(usb_dev_handle *hdev, long VME_Address, long *Data);
short VME_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch);
short VME_DGG(usb_dev_handle *hdev, unsigned short channel, unsigned short trigger,unsigned short output, long delay, unsigned short gate, unsigned short invert, unsigned short latch);
 
short VME_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch);
 
short VME_read_16(usb_dev_handle *hdev,short Address_Modifier, long VME_Address, long *Data);
short VME_read_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long *Data);
short VME_BLT_read_32(usb_dev_handle *hdev, short Address_Modifier, int count, long VME_Address, long Data[]);
short VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
short VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
 
short CAMAC_DGG(usb_dev_handle *hdev, short channel, short trigger, short output, int delay, int gate, short invert, short latch);
short CAMAC_register_read(usb_dev_handle *hdev, int A, long *Data);
short CAMAC_register_write(usb_dev_handle *hdev, int A, long Data);
short CAMAC_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch);
short CAMAC_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch);
short CAMAC_read_LAM_mask(usb_dev_handle *hdev, long *Data);
short CAMAC_write_LAM_mask(usb_dev_handle *hdev, long Data);
 
short CAMAC_write(usb_dev_handle *hdev, int N, int A, int F, long Data, int *Q, int *X);
short CAMAC_read(usb_dev_handle *hdev, int N, int A, int F, long *Data, int *Q, int *X);
short CAMAC_Z(usb_dev_handle *hdev);
short CAMAC_C(usb_dev_handle *hdev);
short CAMAC_I(usb_dev_handle *hdev, int inhibit);
 
/lab/sipmscan/trunk/input/libxxusb.h.online
0,0 → 1,111
#include <usb.h>
 
 
#define XXUSB_WIENER_VENDOR_ID 0x16DC /* Wiener, Plein & Baus */
#define XXUSB_VMUSB_PRODUCT_ID 0x000B /* VM-USB */
#define XXUSB_CCUSB_PRODUCT_ID 0x0001 /* CC-USB */
#define XXUSB_ENDPOINT_OUT 2 /* Endpoint 2 Out*/
#define XXUSB_ENDPOINT_IN 0x86 /* Endpoint 6 In */
#define XXUSB_FIRMWARE_REGISTER 0
#define XXUSB_GLOBAL_REGISTER 1
#define XXUSB_ACTION_REGISTER 10
#define XXUSB_DELAYS_REGISTER 2
#define XXUSB_WATCHDOG_REGISTER 3
#define XXUSB_SELLEDA_REGISTER 6
#define XXUSB_SELNIM_REGISTER 7
#define XXUSB_SELLEDB_REGISTER 4
#define XXUSB_SERIAL_REGISTER 15
#define XXUSB_LAMMASK_REGISTER 8
#define XXUSB_LAM_REGISTER 12
#define XXUSB_READOUT_STACK 2
#define XXUSB_SCALER_STACK 3
#define XXUSB_NAF_DIRECT 12
 
struct XXUSB_STACK
{
long Data;
short Hit;
short APatt;
short Num;
short HitMask;
};
 
struct XXUSB_CC_COMMAND_TYPE
{
short Crate;
short F;
short A;
short N;
long Data;
short NoS2;
short LongD;
short HitPatt;
short QStop;
short LAMMode;
short UseHit;
short Repeat;
short AddrScan;
short FastCam;
short NumMod;
short AddrPatt;
long HitMask[4];
long Num;
};
 
struct xxusb_device_typ
{
struct usb_device *usbdev;
char SerialString[7];
};
 
typedef struct xxusb_device_typ xxusb_device_type;
typedef unsigned char UCHAR;
typedef struct usb_bus usb_busx;
 
 
int xxusb_longstack_execute(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
int xxusb_bulk_read(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
int xxusb_bulk_write(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
int xxusb_usbfifo_read(usb_dev_handle *hDev, int *DataBuffer, int lDataLen, int timeout);
 
short xxusb_register_read(usb_dev_handle *hDev, short RegAddr, long *RegData);
short xxusb_stack_read(usb_dev_handle *hDev, short StackAddr, long *StackData);
short xxusb_stack_write(usb_dev_handle *hDev, short StackAddr, long *StackData);
short xxusb_stack_execute(usb_dev_handle *hDev, long *StackData);
short xxusb_register_write(usb_dev_handle *hDev, short RegAddr, long RegData);
short xxusb_reset_toggle(usb_dev_handle *hDev);
 
short xxusb_devices_find(xxusb_device_type *xxusbDev);
short xxusb_device_close(usb_dev_handle *hDev);
usb_dev_handle* xxusb_device_open(struct usb_device *dev);
short xxusb_flash_program(usb_dev_handle *hDev, char *config, short nsect);
short xxusb_flashblock_program(usb_dev_handle *hDev, UCHAR *config);
usb_dev_handle* xxusb_serial_open(char *SerialString);
 
short VME_register_write(usb_dev_handle *hdev, long VME_Address, long Data);
short VME_register_read(usb_dev_handle *hdev, long VME_Address, long *Data);
short VME_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch);
short VME_DGG(usb_dev_handle *hdev, unsigned short channel, unsigned short trigger,unsigned short output, long delay, unsigned short gate, unsigned short invert, unsigned short latch);
 
short VME_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch);
 
short VME_read_16(usb_dev_handle *hdev,short Address_Modifier, long VME_Address, long *Data);
short VME_read_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long *Data);
short VME_BLT_read_32(usb_dev_handle *hdev, short Address_Modifier, int count, long VME_Address, long Data[]);
short VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
short VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
 
short CAMAC_DGG(usb_dev_handle *hdev, short channel, short trigger, short output, int delay, int gate, short invert, short latch);
short CAMAC_register_read(usb_dev_handle *hdev, int A, long *Data);
short CAMAC_register_write(usb_dev_handle *hdev, int A, long Data);
short CAMAC_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch);
short CAMAC_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch);
short CAMAC_read_LAM_mask(usb_dev_handle *hdev, long *Data);
short CAMAC_write_LAM_mask(usb_dev_handle *hdev, long Data);
 
short CAMAC_write(usb_dev_handle *hdev, int N, int A, int F, long Data, int *Q, int *X);
short CAMAC_read(usb_dev_handle *hdev, int N, int A, int F, long *Data, int *Q, int *X);
short CAMAC_Z(usb_dev_handle *hdev);
short CAMAC_C(usb_dev_handle *hdev);
short CAMAC_I(usb_dev_handle *hdev, int inhibit);
 
/lab/sipmscan/trunk/input/usb.h.offline
0,0 → 1,344
/*
* Prototypes, structure definitions and macros.
*
* Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
*
* This library is covered by the LGPL, read LICENSE for details.
*
* This file (and only this file) may alternatively be licensed under the
* BSD license as well, read LICENSE for details.
*/
#ifndef __USB_H__
#define __USB_H__
 
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
 
#include <sys/param.h>
#include <dirent.h>
 
/*
* USB spec information
*
* This is all stuff grabbed from various USB specs and is pretty much
* not subject to change
*/
 
/*
* Device and/or Interface Class codes
*/
#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
#define USB_CLASS_AUDIO 1
#define USB_CLASS_COMM 2
#define USB_CLASS_HID 3
#define USB_CLASS_PRINTER 7
#define USB_CLASS_PTP 6
#define USB_CLASS_MASS_STORAGE 8
#define USB_CLASS_HUB 9
#define USB_CLASS_DATA 10
#define USB_CLASS_VENDOR_SPEC 0xff
 
/*
* Descriptor types
*/
#define USB_DT_DEVICE 0x01
#define USB_DT_CONFIG 0x02
#define USB_DT_STRING 0x03
#define USB_DT_INTERFACE 0x04
#define USB_DT_ENDPOINT 0x05
 
#define USB_DT_HID 0x21
#define USB_DT_REPORT 0x22
#define USB_DT_PHYSICAL 0x23
#define USB_DT_HUB 0x29
 
/*
* Descriptor sizes per descriptor type
*/
#define USB_DT_DEVICE_SIZE 18
#define USB_DT_CONFIG_SIZE 9
#define USB_DT_INTERFACE_SIZE 9
#define USB_DT_ENDPOINT_SIZE 7
#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
#define USB_DT_HUB_NONVAR_SIZE 7
 
/* All standard descriptors have these 2 fields in common */
struct usb_descriptor_header {
uint8_t bLength;
uint8_t bDescriptorType;
} __attribute__ ((packed));
 
/* String descriptor */
struct usb_string_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wData[1];
} __attribute__ ((packed));
 
/* HID descriptor */
struct usb_hid_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdHID;
uint8_t bCountryCode;
uint8_t bNumDescriptors;
/* uint8_t bReportDescriptorType; */
/* uint16_t wDescriptorLength; */
/* ... */
} __attribute__ ((packed));
 
/* Endpoint descriptor */
#define USB_MAXENDPOINTS 32
struct usb_endpoint_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
uint8_t bRefresh;
uint8_t bSynchAddress;
 
unsigned char *extra; /* Extra descriptors */
int extralen;
};
 
#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
#define USB_ENDPOINT_DIR_MASK 0x80
 
#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
#define USB_ENDPOINT_TYPE_CONTROL 0
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
#define USB_ENDPOINT_TYPE_BULK 2
#define USB_ENDPOINT_TYPE_INTERRUPT 3
 
/* Interface descriptor */
#define USB_MAXINTERFACES 32
struct usb_interface_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
 
struct usb_endpoint_descriptor *endpoint;
 
unsigned char *extra; /* Extra descriptors */
int extralen;
};
 
#define USB_MAXALTSETTING 128 /* Hard limit */
struct usb_interface {
struct usb_interface_descriptor *altsetting;
 
int num_altsetting;
};
 
/* Configuration descriptor information.. */
#define USB_MAXCONFIG 8
struct usb_config_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t MaxPower;
 
struct usb_interface *interface;
 
unsigned char *extra; /* Extra descriptors */
int extralen;
};
 
/* Device descriptor */
struct usb_device_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
} __attribute__ ((packed));
 
struct usb_ctrl_setup {
uint8_t bRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} __attribute__ ((packed));
 
/*
* Standard requests
*/
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
/* 0x02 is reserved */
#define USB_REQ_SET_FEATURE 0x03
/* 0x04 is reserved */
#define USB_REQ_SET_ADDRESS 0x05
#define USB_REQ_GET_DESCRIPTOR 0x06
#define USB_REQ_SET_DESCRIPTOR 0x07
#define USB_REQ_GET_CONFIGURATION 0x08
#define USB_REQ_SET_CONFIGURATION 0x09
#define USB_REQ_GET_INTERFACE 0x0A
#define USB_REQ_SET_INTERFACE 0x0B
#define USB_REQ_SYNCH_FRAME 0x0C
 
#define USB_TYPE_STANDARD (0x00 << 5)
#define USB_TYPE_CLASS (0x01 << 5)
#define USB_TYPE_VENDOR (0x02 << 5)
#define USB_TYPE_RESERVED (0x03 << 5)
 
#define USB_RECIP_DEVICE 0x00
#define USB_RECIP_INTERFACE 0x01
#define USB_RECIP_ENDPOINT 0x02
#define USB_RECIP_OTHER 0x03
 
/*
* Various libusb API related stuff
*/
 
#define USB_ENDPOINT_IN 0x80
#define USB_ENDPOINT_OUT 0x00
 
/* Error codes */
#define USB_ERROR_BEGIN 500000
 
/*
* This is supposed to look weird. This file is generated from autoconf
* and I didn't want to make this too complicated.
*/
#if 0
#define USB_LE16_TO_CPU(x) do { x = ((x & 0xff) << 8) | ((x & 0xff00) >> 8); } while(0)
#else
#define USB_LE16_TO_CPU(x)
#endif
 
/* Data types */
struct usb_device;
struct usb_bus;
 
/*
* To maintain compatibility with applications already built with libusb,
* we must only add entries to the end of this structure. NEVER delete or
* move members and only change types if you really know what you're doing.
*/
#ifdef PATH_MAX
#define LIBUSB_PATH_MAX PATH_MAX
#else
#define LIBUSB_PATH_MAX 4096
#endif
struct usb_device {
struct usb_device *next, *prev;
 
char filename[LIBUSB_PATH_MAX + 1];
 
struct usb_bus *bus;
 
struct usb_device_descriptor descriptor;
struct usb_config_descriptor *config;
 
void *dev; /* Darwin support */
 
uint8_t devnum;
 
unsigned char num_children;
struct usb_device **children;
};
 
struct usb_bus {
struct usb_bus *next, *prev;
 
char dirname[LIBUSB_PATH_MAX + 1];
 
struct usb_device *devices;
uint32_t location;
 
struct usb_device *root_dev;
};
 
struct usb_dev_handle;
typedef struct usb_dev_handle usb_dev_handle;
 
/* Variables */
extern struct usb_bus *usb_busses;
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* Function prototypes */
 
/* usb.c */
usb_dev_handle *usb_open(struct usb_device *dev);
int usb_close(usb_dev_handle *dev);
int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
size_t buflen);
int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
size_t buflen);
 
/* descriptors.c */
int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
unsigned char type, unsigned char index, void *buf, int size);
int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
unsigned char index, void *buf, int size);
 
/* <arch>.c */
int usb_bulk_write(usb_dev_handle *dev, int ep, const char *bytes, int size,
int timeout);
int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
int timeout);
int usb_interrupt_write(usb_dev_handle *dev, int ep, const char *bytes, int size,
int timeout);
int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
int timeout);
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
int value, int index, char *bytes, int size, int timeout);
int usb_set_configuration(usb_dev_handle *dev, int configuration);
int usb_claim_interface(usb_dev_handle *dev, int interface);
int usb_release_interface(usb_dev_handle *dev, int interface);
int usb_set_altinterface(usb_dev_handle *dev, int alternate);
int usb_resetep(usb_dev_handle *dev, unsigned int ep);
int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
int usb_reset(usb_dev_handle *dev);
 
#if 1
#define LIBUSB_HAS_GET_DRIVER_NP 1
int usb_get_driver_np(usb_dev_handle *dev, int interface, char *name,
unsigned int namelen);
#define LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 1
int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface);
#endif
 
char *usb_strerror(void);
 
void usb_init(void);
void usb_set_debug(int level);
int usb_find_busses(void);
int usb_find_devices(void);
struct usb_device *usb_device(usb_dev_handle *dev);
struct usb_bus *usb_get_busses(void);
 
#ifdef __cplusplus
}
#endif
 
#endif /* __USB_H__ */