#ifndef __SRU #define __SRU //#define __DEBUG_READ #define SRU_MAX_ID 3 #define __VERSION "20140424A" #define ERR_NOSUCHFILE -1 #define ERR_NOSRUID -2 #define TCP_SERVER 0 #define UDP_SERVER 1 // SRU fields #define NODESEL_SRU 0x00100000 // Node is SRU itself #define RD_COMMAND 0x80000000 // Read command #define CTYPE_SALTRO 0x40000000 // SALTRO destination // SRU registers // ============= #define SRU_WAIT_WRITE 200 // Wait after a write a commad - allow exec // status regs (Read only) #define SRU_REG_SN 0x01 // serial numner #define SRU_REG_IP 0x02 // IP address #define SRU_REG_FMVER 0x03 // Firmware version #define SRU_REG_SRUST 0x04 // Status #define SRU_REG_DTCERRFLAG1 0x05 // Error flag received from DTC0-19 #define SRU_REG_DTCERRFLAG2 0x06 // Error flag received from DTC0-19 // R/W #define SRU_REG_FPGA_MON 0x07 // FPGA Monitor flag, Addr and Temp #define SRU_REG_READOUT_IP 0x08 // FPGA Monitor flag, Addr and Temp // Write only #define SRU_REG_RESET 0x10 // Reset SRU, CPLD and SALTRO #define SRU_REG_PSSCAN 0x11 // Phase scan command #define SRU_REG_WALIGN 0x12 // DTC deserializer word align command #define SRU_REG_BUSYCLR 0x13 // Clear busy and error flags, clear the data fragments in the buffer, recall all FEE. #define SRU_REG_DDL_INIT 0x14 // Init DLL link. // R/W #define SRU_REG_CFG 0x20 // Configuration register #define SRU_REG_DTC_CLKEN1 0x21 // Clock enable for DTC 0-19 links #define SRU_REG_DTC_CLKEN2 0x22 // Clock enable for DTC 20-39 links #define SRU_REG_DTCRDOMASK1 0x23 // Readout mask of DTC 0-19 links #define SRU_REG_DTCRDOMASK2 0x24 // Readout mask of DTC 20-39 links #define SRU_REG_SALTRO_CFG1 0x27 // Zero suppresion stuff #define SRU_REG_SALTRO_CFG2 0x28 // Other SALTRO config stuff. #define SRU_REG_TRIG_L1_TW 0x29 // Timing window for L1 trigger #define SRU_REG_TRIG_L2_TW 0x2A // Timing window for L2 trigger // Write only #define SRU_REG_FPGA_RELOAD 0x40 // Reload firmware from Flash to FPGA #define SRU_REG_FEE_FAST_CMD 0x41 // Fast Command to FEE #define SRU_REG_STRIG_CMD 0x42 // Send one software trigger, if triggering is set correctly. #define SRU_REG_TRIG_CNT_CLR 0x43 // All trigger counters clear #define SRU_REG_TRIG_ERR_CLK 0x44 // Clear all trigger errors #define SRU_REG_DTC_ERR_TEST 0x45 // DTC Link error tester command. // R/W #define SRU_REG_PTRIG_CFG 0x50 // Periodical trigger configuration #define SRU_REG_TEST_TRIG_CFG0 0x51 // Test trigger configuration 0 #define SRU_REG_TEST_TRIG_CFG1 0x52 // Test trigger configuration 1 #define SRU_REG_TEST_PULSE_CFG 0x53 // Test pulse configuration // Read only #define SRU_REG_RX_L0_CNT 0x60 // #define SRU_REG_RX_L1_CNT 0x61 // #define SRU_REG_RX_L2A_CNT 0x62 // #define SRU_REG_RX_L2R_CNT 0x62 // // To add rest of SRU regs. //#define SRU_REG_ 0x //#define SRU_REG_ 0x //#define SRU_REG_ 0x //#define SRU_REG_ 0x //#define SRU_REG_ 0x //#define SRU_REG_ 0x //#define SRU_REG_ 0x #define SEND_BUFFER_SIZE 66504 #define LOCAL_IP "130.235.185.193" typedef struct { char controlip[64]; struct sockaddr_in si_sru; int scsocket; // socket for slow control int listenport; char readoutip[64]; unsigned int readoutipnb; int status; // status from configfile int linkup; // it it answered ping int active; // status & linkup is set and FMVER could be read } SRUSERVER; typedef struct { struct sockaddr_in si_controlme; struct sockaddr_in si_broadcast; char interface[64]; // interface int controlsocket; // socket for control int readoutsocket; // socket for listen on readout int listenport; // port for listen on control int controlport; // port for sending control int readoutport; // port for listen on readout int roinitport; // port for sending data init command int nbrdpackets; // Number of packets expected back char broadcastip[64]; char localip[64]; unsigned int localipnb; SRUSERVER sruserver[SRU_MAX_ID+1]; } SRU; /* Struct that contains the status of power of FECs status = 0 : unknown status = 1 : read from sru-.cfg status = 2 : read from SRU status = 3 : SRU link is down */ #define POWER_UNKNOWN 0 #define POWER_FROM_FILE 1 #define POWER_FROM_SRU 2 #define POWER_FROM_MCM 3 #define POWER_LINK_DOWN 4 typedef struct { int status; unsigned int nodeserror; // bit pattern of nodes with error unsigned int power; unsigned int readout; unsigned int poweredon; } FECPOWER; typedef struct { int sruid; int power; int readout; /* FEC to readout */ int defacl; /* default ACL */ unsigned int acl[256]; /* actual ACL */ unsigned int zsup[32]; /* actual zerosuppression*/ unsigned int pedsub[32]; /* actual pedestal subtratcion*/ } SRU_SETTINGS; // SALTRO register addresses #define K1_ADDR 0x00 #define K2_ADDR 0x01 #define K3_ADDR 0x02 #define K4_ADDR 0x03 #define L1_ADDR 0x04 #define L2_ADDR 0x05 #define L3_ADDR 0x06 #define L4_ADDR 0x07 #define ZSTHR_ADDR 0x08 // GLOBAL #define BC2THR_ADDR 0x09 // GLOBAL #define TRCFG_ADDR 0x0A // GLOBAL #define DPCFG_ADDR 0x0B // GLOBAL #define BFNPT_ADDR 0x0C // GLOBAL #define PMADD_ADDR 0x0D // GLOBAL #define BC1THR_ADDR 0x0E // GLOBAL #define ERSTR_ADDR 0x10 // GLOBAL #define ADEVL_ADDR 0x11 #define TRCNT_ADDR 0x12 // GLOBAL #define VFPED_ADDR 0x13 #define PMDTA_ADDR 0x14 #define CTE_ADDR 0x15 #define CHREG_ADDR 0x17 // GLOBAL #define WPINC_ADDR 0x18 // GLOBAL #define RPINC_ADDR 0x19 // GLOBAL #define CHRDO_ADDR 0x1A #define SWTRG_ADDR 0x1B // GLOBAL #define TRCLR_ADDR 0x1C // GLOBAL #define ERCLR_ADDR 0x1D // GLOBAL #define ALLRDO_ADDR 0x1E typedef struct { int address; // register address unsigned int value; // register value if write int write; // set if write int read; // set if read } SALTROREG; // MCM CPLD addresses. #define MCM_REG_ADCCLKDIV 0x01 #define MCM_REG_LGSEN 0x02 #define MCM_REG_ADDR 0x03 #define MCM_REG_SALTROCTRL 0x06 #define MCM_REG_SALTROCHMASK0 0x10 #define MCM_REG_SALTROCHMASK1 0x11 #define MCM_REG_SALTROCHMASK2 0x12 #define MCM_REG_SALTROCHMASK3 0x13 #define MCM_REG_SALTROCHMASK4 0x14 #define MCM_REG_SALTROCHMASK5 0x15 #define MCM_REG_SALTROCHMASK6 0x16 #define MCM_REG_SALTROCHMASK7 0x17 #define MCM_REG_FMVER 0x20 // Firmware version // #define MCM_REG_ to be continued int readSruConfig(char *filename, SRU *srv); int chklimits(int value, int minval, int maxval); int readServerConfig( char *filename, SRU *srv); int sruReadFile(char *filename, char *ip, int *port, char *inbuf); int sruSendPacket(char *filename, int myport); void chartohex(char *buffer,int *buf); int sendFileResult(char *filename,char *ip, int port); int nodeconfig(int *mcmnodes1, int *mcmnodes2, int iarg); int validateIpAddress(char *ipaddress); void dumpServerConfig(FILE *fout,SRU *srv); int writeSruActiveFile(char *filename,SRU *srv); int readSruReadoutList(char *filename,SRU_SETTINGS *sru, int rcuid); int sruLoadReadoutList(int handle,SRUSERVER *srv, unsigned int fecpower); int dumpSruReadoutList(SRU_SETTINGS *sr); //int scSruConnect(FILE *flog,SRU *sru); int sruReceivePacket(SRU *srv); int sruWriteRegister(int handle,SRUSERVER *srv,int reg, unsigned int value); int sruReadRegister(int handle,SRUSERVER *srv,int reg, unsigned int *value); int sruWriteRegister(int handle,SRUSERVER *srv,int reg, unsigned int value); int sruReadRegister(int handle,SRUSERVER *srv,int reg, unsigned int *value); int sruReadActiveMcm(int handle,SRUSERVER *srv, unsigned int *fecpower); int sruWriteBlock(int handle,SRUSERVER *srv,int node, unsigned int *inbuf, int length); int mcmWriteRegister(int handle,SRUSERVER *srv, int node, int reg, unsigned int value); int mcmReadRegister(int handle,SRUSERVER *srv,int node, int reg, unsigned int *value); unsigned int mcmRespondCheck(int handle,SRUSERVER *srv,unsigned int *nodesresponding); int mcmReadActiveChannels(int handle,SRUSERVER *srv, int node, unsigned int *acl); int saltroWriteRegister(int handle,SRUSERVER *srv,int broadcast, int node, int chip, int channel, int reg, unsigned int value); int saltroReadRegister(int handle, SRUSERVER *srv, int node, int chip, int channel, int reg, unsigned int *value); int mcmWriteActiveChannels(int handle,SRUSERVER *srv, int node, unsigned int *acl); int mcmLoadPca16(int handle,SRUSERVER *srv,unsigned int nodes, unsigned int pasactrl, unsigned int *error); int mcmVerifyPca16(int handle,SRUSERVER *srv,unsigned int nodes, unsigned int pasactrl, unsigned int *error); int findip(char *interface, char *ipaddress, char *bcaddress); #endif