/*=================================================== [...SinqHM]SinqHM_def.h ** ** Definition Include file for SinqHM_SRV and its clients. ** **------------------------------------------------------------------------------ */ #define SINQHM_DEF_ID "V02G" /*------------------------------------------------------------------------------ */ #ifndef OffsetOf #define OffsetOf(type, identifier) ((size_t)(&((type*) NULL)->identifier)) #endif /*------------------------------------------------------------------------------ ** Define some defaults. */ #define PORT_BASE 2400 /* The Internet Port for Server Requests */ #define MAX_CLIENTS 8 /* The maximum number of active clients */ #define MAX_TOF_CNTR 1024 /* The maximum number of individual counters .. ** which can be handled in TOF mode */ #define MAX_TOF_NBINS 32768 /* The maximum number of bins in a TOF histog */ #define MAX_TOF_EDGE 16 /* The maximum number of TOF edge arrays */ #define VMIO_BASE_ADDR 0x1900 /* VME address of a (possible) VMIO10 module */ #define uchar unsigned char #define usint unsigned short int #define uint unsigned int /*------------------------------------------------------------------------------ ** Define some status values (similar to VAXeln). */ #define KER__SUCCESS 1 #define KER__BAD_CREATE -2 #define KER__BAD_STATE -4 #define KER__BAD_VALUE -6 #define KER__EXIT_SIGNAL -10 #define KER__BAD_RECV -14 #define KER__BAD_ALLOC -16 #ifndef True #define True 1 #endif #ifndef False #define False 0 #endif #ifndef NIL #define NIL '\0' #endif /*------------------------------------------------------------------------------ ** Define command verbs to SinqHM. */ #define SQHM_CNCT 0x01 #define SQHM_CLOSE 0x02 #define SQHM_CONFIG 0x03 #define SQHM_DAQ 0x04 #define SQHM_DBG 0x05 #define SQHM_DECONFIG 0x06 #define SQHM_EXIT 0x07 #define SQHM_READ 0x08 #define SQHM_SELECT 0x09 #define SQHM_STATUS 0x0a #define SQHM_WRITE 0x0b #define SQHM_ZERO 0x0c /* ** Define the various operation modes */ #define SQHM__TRANS 0x1000 /* Transparent mode */ #define SQHM__HM_DIG 0x2000 /* Hist mode (with digitised read-out) */ #define SQHM__TOF 0x3000 /* Time-of-Flight mode */ #define SQHM__HM_PSD 0x4000 /* Hist mode (with Pos-sens-detect read-out) */ #define SQHM__HRPT 0x5000 /* Histogram mode for HRPT cerca detector */ /* ** Define the various sub-mode bits of the operation modes */ #define SQHM__SUB_MODE_MSK 0xff /* Mask for extracting "sub-mode" bits */ #define SQHM__DEBUG 0x01 /* Debug flag - FILLER will suspend itself .. ** .. after starting to allow debugging */ #define SQHM__UD 0x02 /* Use Up/Down bit information */ #define SQHM__BO_MSK 0x18 /* Mask for extracting "bin-overflow" bits */ #define SQHM__BO_IGN 0x00 /* Ignore bin-overflows (bin-contents wrap) */ #define SQHM__BO_SMAX 0x08 /* On bin-overflow, stop at maximum */ #define SQHM__BO_CNT 0x10 /* Keep counts of overflow bins */ #define SQHM__STROBO 0x20 /* Use strobo-bit information */ #define SQHM__REFLECT 0x40 /* reflect histogram */ /* ** ---------------------------------------------------------- ** SQHM_DAQ sub-function codes */ #define DAQ__EXIT 0xffffffff #define DAQ__CLR 0x01 #define DAQ__GO 0x02 #define DAQ__INH 0x03 #define DAQ__STOP 0x04 #define DAQ__TST 0x05 /* ** ---------------------------------------------------------- ** Definition of bits in of TOF edge-array */ #define FLAG__VAR_BIN 0x01 /* Bin span of histogram is variable */ /* ** ---------------------------------------------------------- */ #define N_HISTS_MAX 64 /* Maximum number of histograms supported */ #define N_BINS_MAX 0x00ffff /* Maximum histogram bin number permitted */ #define N_TOTAL_BYTES 0x400000 /* Maximum total bytes of histogram */ /* **------------------------------------------------------------------------------ ** Definitions for the LWL Datagrams */ #define LWL_HDR_TYPE_MASK (0x1f000000) /* Mask for extracting main dgrm .. ** .. hdr command-type bits */ #define LWL_HDR_PF_MASK (0x80000000) /* Mask for extr Power Fail bit */ #define LWL_HDR_SWC_MASK (0x40000000) /* Mask for extr Status Word Chng bit */ #define LWL_HDR_NRL_MASK (0x20000000) /* Mask for extr Neutron Rate Low bit */ #define LWL_HDR_UD_MASK (0x00200000) /* Mask for extr Up/Down bit */ #define LWL_HDR_BA_MASK (0x00f00000) /* Mask for extr Binning Addr */ #define LWL_HDR_TS_MASK (0x000fffff) /* Mask for extr Time Stamp */ #define LWL_HDR_TYPE_NRL (LWL_HDR_TYPE_MASK | LWL_HDR_NRL_MASK) /* Mask for .. ** .. extracting dgrm type + NRL bit */ #define LWL_TR_C1 (0x00000001) /* Transp. Mode Chan 1 */ #define LWL_TR_C2 (0x00000002) /* Transp. Mode Chan 2 */ #define LWL_TR_C3 (0x00000003) /* Transp. Mode Chan 3 */ #define LWL_TR_C4 (0x00000004) /* Transp. Mode Chan 4 */ #define LWL_TR_C5 (0x00000005) /* Transp. Mode Chan 5 */ #define LWL_TR_C6 (0x00000006) /* Transp. Mode Chan 6 */ #define LWL_TR_C7 (0x00000007) /* Transp. Mode Chan 7 */ #define LWL_TR_C8 (0x00000008) /* Transp. Mode Chan 8 */ #define LWL_TR_C9 (0x00000009) /* Transp. Mode Chan 9 */ #define LWL_HM_NC (0x10000000) /* Hist-Mode/No-Coinc 0 chan dgrm hdr */ #define LWL_HM_NC_C1 (0x11000000) /* Hist-Mode/No-Coinc 1 chan dgrm hdr */ #define LWL_HM_NC_C2 (0x12000000) /* Hist-Mode/No-Coinc 2 chan dgrm hdr */ #define LWL_HM_NC_C3 (0x13000000) /* Hist-Mode/No-Coinc 3 chan dgrm hdr */ #define LWL_HM_NC_C4 (0x14000000) /* Hist-Mode/No-Coinc 4 chan dgrm hdr */ #define LWL_HM_NC_C5 (0x15000000) /* Hist-Mode/No-Coinc 5 chan dgrm hdr */ #define LWL_HM_NC_C6 (0x16000000) /* Hist-Mode/No-Coinc 6 chan dgrm hdr */ #define LWL_HM_NC_C7 (0x17000000) /* Hist-Mode/No-Coinc 7 chan dgrm hdr */ #define LWL_HM_NC_C8 (0x18000000) /* Hist-Mode/No-Coinc 8 chan dgrm hdr */ #define LWL_HM_NC_C9 (0x19000000) /* Hist-Mode/No-Coinc 9 chan dgrm hdr */ #define LWL_HM_CO (0x10000000) /* Hist-Mode+Coinc 0 chan dgrm hdr */ #define LWL_HM_CO_C2 (0x12000000) /* Hist-Mode+Coinc 2 chan dgrm hdr */ #define LWL_HM_CO_C3 (0x13000000) /* Hist-Mode+Coinc 3 chan dgrm hdr */ #define LWL_HM_CO_C4 (0x14000000) /* Hist-Mode+Coinc 4 chan dgrm hdr */ #define LWL_HM_CO_C5 (0x15000000) /* Hist-Mode+Coinc 5 chan dgrm hdr */ #define LWL_HM_CO_C6 (0x16000000) /* Hist-Mode+Coinc 6 chan dgrm hdr */ #define LWL_HM_CO_C7 (0x17000000) /* Hist-Mode+Coinc 7 chan dgrm hdr */ #define LWL_HM_CO_C8 (0x18000000) /* Hist-Mode+Coinc 8 chan dgrm hdr */ #define LWL_HM_CO_C9 (0x19000000) /* Hist-Mode+Coinc 9 chan dgrm hdr */ #define LWL_TOF_C1 (0x01000000) /* TOF-Mode 1 chan dgrm hdr */ #define LWL_TOF_C2 (0x02000000) /* TOF-Mode 2 chan dgrm hdr */ #define LWL_TOF_C3 (0x03000000) /* TOF-Mode 3 chan dgrm hdr */ #define LWL_TOF_C4 (0x04000000) /* TOF-Mode 4 chan dgrm hdr */ #define LWL_TOF_C5 (0x05000000) /* TOF-Mode 5 chan dgrm hdr */ #define LWL_TOF_C6 (0x06000000) /* TOF-Mode 6 chan dgrm hdr */ #define LWL_TOF_C7 (0x07000000) /* TOF-Mode 7 chan dgrm hdr */ #define LWL_TOF_C8 (0x08000000) /* TOF-Mode 8 chan dgrm hdr */ #define LWL_TOF_C9 (0x09000000) /* TOF-Mode 9 chan dgrm hdr */ #define LWL_SM_NC (0x10000000) /* Strobo-Mode/No-Coinc 0 chan dgrm hdr */ #define LWL_SM_NC_C1 (0x11000000) /* Strobo-Mode/No-Coinc 1 chan dgrm hdr */ #define LWL_SM_NC_C2 (0x12000000) /* Strobo-Mode/No-Coinc 2 chan dgrm hdr */ #define LWL_SM_NC_C3 (0x13000000) /* Strobo-Mode/No-Coinc 3 chan dgrm hdr */ #define LWL_SM_NC_C4 (0x14000000) /* Strobo-Mode/No-Coinc 4 chan dgrm hdr */ #define LWL_SM_NC_C5 (0x15000000) /* Strobo-Mode/No-Coinc 5 chan dgrm hdr */ #define LWL_SM_NC_C6 (0x16000000) /* Strobo-Mode/No-Coinc 6 chan dgrm hdr */ #define LWL_SM_NC_C7 (0x17000000) /* Strobo-Mode/No-Coinc 7 chan dgrm hdr */ #define LWL_SM_NC_C8 (0x18000000) /* Strobo-Mode/No-Coinc 8 chan dgrm hdr */ #define LWL_SM_NC_C9 (0x19000000) /* Strobo-Mode/No-Coinc 9 chan dgrm hdr */ #define LWL_SM_CO (0x10000000) /* Strobo-Mode + Coinc 0 chan dgrm hdr */ #define LWL_SM_CO_C1 (0x11000000) /* Strobo-Mode + Coinc 1 chan dgrm hdr */ #define LWL_SM_CO_C2 (0x12000000) /* Strobo-Mode + Coinc 2 chan dgrm hdr */ #define LWL_SM_CO_C3 (0x13000000) /* Strobo-Mode + Coinc 3 chan dgrm hdr */ #define LWL_SM_CO_C4 (0x14000000) /* Strobo-Mode + Coinc 4 chan dgrm hdr */ #define LWL_SM_CO_C5 (0x15000000) /* Strobo-Mode + Coinc 5 chan dgrm hdr */ #define LWL_SM_CO_C6 (0x16000000) /* Strobo-Mode + Coinc 6 chan dgrm hdr */ #define LWL_SM_CO_C7 (0x17000000) /* Strobo-Mode + Coinc 7 chan dgrm hdr */ #define LWL_SM_CO_C8 (0x18000000) /* Strobo-Mode + Coinc 8 chan dgrm hdr */ #define LWL_SM_CO_C9 (0x19000000) /* Strobo-Mode + Coinc 9 chan dgrm hdr */ #define LWL_TS_TR (0x1f000000) /* Transp-Mode Time Status Info */ #define LWL_TS_HM_NC (0x1f000000) /* Hist-Mode/No-Coinc Time Stat Info */ #define LWL_TS_HM_TOF (0x1f000000) /* TOF-Mode Time Status Info */ #define LWL_TS_SM_NC_TOF (0x1f000000) /* Strobo-Mode/No-Coin Time Stat Info */ #define LWL_ETS_TR (0x0e000000) /* Transp-Mode Ext Time Status Info */ #define LWL_ETS_HM_C (0x0e000000) /* Hist-Mode+Coinc Time Status Info */ #define LWL_ETS_SM_C (0x0e000000) /* Strobo-Mode+Coinc Time Status Info */ #define LWL_FIFO_EMPTY (0x1e000000) /* FIFO Empty */ /* **------------------------------------------------------------------------------ ** Define structure of a TOF histogram data item. */ struct tof_histog { int cntr_nmbr; /* Counter number */ uint lo_edge; /* Low edge of first bin (20-bit value) */ uint hi_edge; /* Top edge of last bin (20-bit value) */ usint flag; /* Bit mask giving info on histog -- may be ** used to help optimise the code */ usint bytes_per_bin; /* Number of bytes in each histogram bin */ uint n_bins; /* Number of bins in histogram */ uint cnt_early_up; /* Count of early events (pol'n up) */ uint cnt_late_up; /* Count of late events (pol'n up) */ uint cnt_early_down; /* Count of early events (pol'n down) */ uint cnt_late_down; /* Count of late events (pol'n down) */ uint *bin_edge; /* Pointer to array of bin edges */ union { /* Pointer to histogram array */ uchar *b_bin_data; /* .. pointer if it's 8-bit bins */ usint *w_bin_data; /* .. pointer if it's 16-bit bins */ uint *l_bin_data; /* .. pointer if it's 32-bit bins */ } u; }; /* Define a TOF 'edge-info' structure. This structure is created ** as a result of a TOF 'edge-array' in a SQHM__TOF config cmnd. */ struct tof_edge_info { uint n_bins; /* Number of bins in histogram */ uint flag; /* Flag bits defining type of histo */ uint bin_span; /* Time spanned by a histogram bin (20-bit ** value) if bin width is constant. Otherwise ** it is zero. */ uint hi_edge; /* Top edge of last bin (20-bit value) */ uint edges[2]; /* Array of edge data (20-bit values). There ** are actually (n_bins+1) items in the array ** and give the bottom edges of the bin */ }; /* Define structure of a TOF 'edge-array' in SQHM__TOF config cmnd */ struct tof_edge_arr { uint n_bins; /* Number of bins in histogram */ uint flag; /* Flag (0/1) for fixed/variable bin size */ uint *edges ; /* Array of bottom edges (20-bit values) */ }; /* Define structure of a TOF 'bank' in SQHM__TOF config command */ struct tof_bank { usint first; /* Number of first counter in bank */ usint n_cntrs; /* Number of counters in bank */ usint edge_indx; /* Index of edge array */ usint bytes_per_bin; /* Number of bytes per bin */ }; /* **------------------------------------------------------------------------------ ** Define command structure. */ struct req_buff_struct { /* For messages to SinqHM */ uint bigend; uint cmnd; union { char filler[56]; struct {uint max_pkt, strt_mode;} cnct; struct {uint mode; union { struct { uint n_buffs; uint n_bytes; } trans; struct { uint n_hists; uint lo_bin; uint num_bins; uint bytes_per_bin; uint compress; } hm_dig; struct { uint n_extra_bytes; usint n_edges; usint n_banks; uint preset_delay; struct tof_edge_arr edge_0; struct tof_bank bank_0; } tof; } u; } cnfg; struct {uint level;} dbg; struct {uint sub_code;} decnfg; struct {uint sub_cmnd;} daq; struct {uint hist_no, first_bin, n_bins;} read; struct {uint hist_no;} select; struct {uint hist_no, first_bin, n_bins, bytes_per_bin;} write; struct {uint hist_no, first_bin, n_bins;} zero; } u; }; /* **------------------------------------------------------------------------------ ** Define status response structure. */ struct rply_buff_struct { /* For messages from SinqHM */ uint bigend; uint status, sub_status; union { char message[52]; struct {uint port; uint pkt_size; uint hm_mode; uint n_hists; uint num_bins; uint bytes_per_bin; uint curr_hist; uint max_block; uint total_bytes; uint lo_cntr; uint lo_bin; uint compress;} cnct; struct {usint daq_now; usint daq_was; usint filler_mask; usint server_mask;} daq; struct {uint first_bin; uint n_bins; uint bytes_per_bin; uint cnts_lo; uint cnts_hi;} read; struct {uint cfg_state; usint n_hists; usint curr_hist; uint num_bins; uint max_n_hists; uint max_num_bins; uchar max_srvrs; uchar act_srvrs; uchar bytes_per_bin; uchar compress; usint daq_now; usint filler_mask; uint max_block;} status; } u; }; /* **------------------------------------------------------------------------------ ** Define structure of message to SinqHM-filler. */ struct msg_to_filler_struct { /* For messages to SinqHM-filler */ union { char message[32]; /* Ensure buffer is 32 bytes total */ struct { uint cmnd; uint index; usint new_mask;} uu; } u; }; /*======================================================= End of SinqHM_def.h */