#include <stdio.h>
#include <ioLib.h>
#include <taskLib.h>
#include <vxWorks.h>
#include <time.h>
#include <string.h>
#include <msgQLib.h>
#include <semLib.h>
#include <wdLib.h>
#include <intLib.h>
#include <sysLib.h>
#include <logLib.h>
#include <hostLib.h>
#include <iv.h>
#include <errno.h>
#include <stdlib.h>
#include "trgStructures.h"
#include "token.h"
/* several shortcut definitions */
#ifndef EXT
#define EXT extern
#endif
#ifndef STATUS
#define STATUS int
#endif
#ifndef PROCEDURE
#define PROCEDURE void
#endif
#ifndef V
#define V volatile
#endif
#ifndef FLAG
#define FLAG int
#endif
#ifndef ERROR
#define ERROR
-1
#endif
#ifndef FATAL_ERROR
#define FATAL_ERROR
-2
#endif
#ifndef SUCCESS
#define SUCCESS
0
#endif
#ifndef SUCCESS_STATUS
#define SUCCESS_STATUS
1234
#endif
/* string definitions */
#define MAX_LINE_LEN 128 /* Maximum length of line allowed in Configuration Files */
/* token definitions */
#define MAX_TOKEN 4095 /* Maximum number of tokens allowed in the system */
#define DC_PMC_MEM_BASE 0x30000000
/* DC extended memory location */
#define L2_PMC_MEM_BASE 0x30000000
/* L2 extended memory location */
/* state definitions */
typedef enum {
DISABLED,
ENABLED,
CONFIGURING,
READY,
RUNNING,
PAUSED,
STOPPING,
STOPPED /* will be removed
later */
} trgState;
/* Data structure for TDI */
typedef struct event_desc {
uint
bunchXing_hi;
uint
bunchXing_lo; /*
Two parts of RHIC bunch crossing number */
short token;
ushort trig_action;
/* Output of TCU INFO FIFO1 */
ushort dsm_data;
ushort dsm_adr;
/* Output of TCU INFO FIFO2 */
BYTE
busy;
BYTE
addbits;
/* Output of TCU INFO FIFO3 - 16 MS bits */
ushort trg_word;
/* Output of TCU INFO FIFO3 - 16 LS bits */
short npre;
short npost;
/* Dummy to bring total size of struct to modulo 8 bytes */
} event_desc;
typedef struct fmt_event_desc {
short byte_count;
/* Byte count for this block */
char blk_type;
/* This will be 'E' */
char format_version;
/* Format version for complete trigger data block */
event_desc raw_event_desc;
/* Now for the Event Descriptor */
} fmt_event_desc;
logmessage.h
/* $Id: logmessage.h,v 1.2 1996/02/18 20:57:29 voli Exp $ */
/* **********************************************************************
* This include file defines everything with
respect to the Trigger
* generic logmessage function
*/
#ifndef _LOGMESSAGE_INCLUDED_
#define _LOGMESSAGE_INCLUDED_
/* changecom - switch off any m4 comment handling
*/
/* divert(11) - discard all further input */
#include <stdio.h>
#include <syslog.h>
#ifndef FLAG
#define FLAG
int
#endif
#ifndef MAX_LOG_MSG
#define MAX_LOG_MSG 512
/* couldn't find it in VL's code, so take a guess - zm */
#endif
#define DEFAULT_LOG_OPTION
LOToConsole /* write to all */
#define MAX_LOG_MSG_LEN 256
/* max. log message len */
#define MAX_LOGWHO
16
/* max len of who id */
#define MAX_LOGSTR
MAX_LOG_MSG-MAX_LOGWHO-16
#ifndef TRUE
#define TRUE 1
/* define pseudo booleans */
#define FALSE 0
/* define pseudo booleans */
#endif
/* divert(0) - end discarding */
/*
* the logmessage options
*/
typedef enum {
LOToHost,
/* write to loghost only */
LOToConsole,
/* write to console only */
LOToHostAndConsole,
/* write to console and host */
LOUnknown
} logopt;
/*
* static control variables
* they are defined once at startup
*/
/* divert(11) - discard all further input */
extern char *logcomponent;
/* component posting */
extern logopt logoptions;
/* static options */
extern LogLevelThreshold;
/* log level threshold */
extern FLAG LogFlushEn;
/* always flush output */
void trgLog( int pri, char *message );
void logmessage(int severity_level, char *who, char *msg);
char *date_str(void);
char *syslogPriNam(int pri);
/* divert(0) - end discarding */
#endif
/* end of file logmessage.h */
trgStructures.h
/* several shortcut definitions */
#ifndef uint
#define uint unsigned int
#endif
#ifndef ushort
#define ushort unsigned short
#endif
#ifndef ulong
#define ulong unsigned long
#endif
typedef unsigned char BYTE;
typedef unsigned int WORD;
#define MAX_RAW_DATA_BLOCKS 11
/* Maximum number of Raw Data Blocks: current + npre + npost */
#define FORMAT_VERSION 0x12
/* Format Version number for trigger data */
#define EVT_HEAD_LEN sizeof(TrgEvtHeader)
/* Trigger Event Header Length */
#define EV_DESC_LEN sizeof(EvtDescData)
/* Number of bytes in event descriptor */
#define L0DSM_DATA_LEN sizeof(L0_DSM_Data)
/* Size of data block in L0 DSM Tree */
#define RAW_DET_DATA_LEN sizeof(RawTrgDet)
/* Size of Raw Detector Data from CTB, MWC with headers */
#define TRG_SUM_LEN sizeof(TrgSumData)
/* Number of bytes in the trigger summary for DAQ with headers */
#define L1_DATA_LEN (EVT_HEAD_LEN+EV_DESC_LEN+TRG_SUM_LEN) /* Size of data passed from L1ANA to L1DC */
#define TRG_EVT_LEN (L1_DATA_LEN+(MAX_RAW_DATA_BLOCKS*RAW_DET_DATA_LEN))
/* Max size of a trigger event */
#define TDI_EVT_LEN (EV_DESC_LEN+TRG_SUM_LEN+(MAX_RAW_DATA_BLOCKS*RAW_DET_DATA_LEN))
/* size of event sent to TDI */
#define CTB_DATA_OFFSET
8 /* Number of bytes CTB Raw data is offset in raw trigger structure
*/
#define RAW_CTB_LEN
256 /* Number of bytes in raw CTB DSMs */
#define MWC_DATA_OFFSET
272 /* Number of bytes MWC Raw data is offset in raw trigger structure
*/
#define RAW_MWC_LEN
128 /* Number of bytes in raw CTB DSMs */
#define BEMC_DATA_OFFSET 408
/* Number of bytes MWC Raw data is offset in raw trigger structure */
#define RAW_BEMC_LEN
128 /* Number of bytes in raw CTB DSMs */
/********** trigger structures ***********/
/*
*
* Trigger Data Headers
*
*/
typedef struct {
unsigned short TrgDataBytes;
unsigned short TrgFiller;
unsigned short TCUdataBytes;
BYTE
TrgDataFmtVer;
char
TCUEvtDesc;
unsigned short TrgSumBytes;
char
TrgSumHeader[2];
unsigned short L0SumBytes;
char
L0SumHeader[2];
unsigned short L1SumBytes;
char
L1SumHeader[2];
unsigned short L2SumBytes;
char
L2SumHeader[2];
unsigned short L0RegBytes;
char
L0RegHeader[2];
unsigned short RawDetBytes;
char
RawDetHeader[2];
unsigned short CTBdataBytes;
char
CTBdataHeader[2];
unsigned short MWCdataBytes;
char
MWCdataHeader[2];
unsigned short EMCdataBytes;
char
EMCdataHeader[2];
} trgDataHeaders;
/* Trigger Event Header */
typedef struct {
unsigned short TrgDataBytes; /* total bytes
in trigger data */
unsigned short TrgFiller;
} TrgEvtHeader; /* 4 Bytes total
*/
/* Event Descriptor Data Structures */
typedef union { /*
The contents of Info Fifo 1 */
struct {
unsigned short TrgToken;
/* Trigger Token */
unsigned short TrgActionWd;
/* Trigger Action Word */
} FIFO1;
unsigned long fifo1;
} Info1;
/* 32 bits total */
typedef union { /* The contents
of Info Fifo 2 */
struct {
unsigned short DSMInput;
/* Last DSM */
unsigned short DSMAddress;
/* DSM address */
} FIFO2;
unsigned long fifo2;
} Info2;
/* 32 bits total */
typedef union { /* The contents
of Info Fifo 3 */
struct {
BYTE
DetectorBusy; /* detector Busy Bits */
BYTE
addBits; /*
filler Bits - bit 0=pileup; bit 1=priority; bit 7=1 is fake data */
unsigned short TriggerWd;
/* Trigger Word */
} FIFO3;
unsigned long fifo3;
} Info3;
/* 32 bits total */
/* Data structure passed from L1CTL to L1ANA */
typedef struct {
unsigned short TCUdataBytes;
char
TCUEvtDesc;
BYTE
TrgDataFmtVer;
uint
bunchXing_hi;
uint
bunchXing_lo; /* Two parts of RHIC bunch crossing number */
Info1
TCU1; /* TCU
Info Fifo's */
Info2
TCU2;
Info3
TCU3;
ushort
npre;
ushort
npost; /* Dummy to
bring total size of struct to modulo 8 bytes */
} EvtDescData;
/* 28 bytes total */
/* Trigger Summary Data Structures */
/* L0 DSM data structures */
typedef struct {
ushort
CPA[32]; /* Contents of 4 CTB+MWC
DSM Input Buffers (IB's) - coarse pixel array*/
ushort
quadDSM[8]; /* Contents of 1 CTB+MWC DSM IB - outputs
of previous 4 */
ushort
lastDSM[8]; /* Contents of last DSM IB - results
of all DSM trees */
BYTE
ZDC[16]; /* Contents of ZDC DSM
IB - raw data from ZDC */
ushort
BCdata[16]; /* Contents of 2 Bunch Crossing DSMs
IB's */
} L0_DSM_Data;
/* 144 bytes total */
/* summary data */
typedef struct {
unsigned short TrgSumBytes;
char
TrgSumHeader[2];
uint
L1Sum[2]; /* L1 Summary */
uint
L2Sum[2]; /* L2 Summary */
unsigned short L0SumBytes;
char
L0SumHeader[2];
L0_DSM_Data DSM;
/* L0 DSM Data from DSM Tree */
unsigned short L1SumBytes;
char
L1SumHeader[2];
uint
L1Result[32]; /* Result from L1 CPU
*/
unsigned short L2SumBytes;
char
L2SumHeader[2];
uint
L2Result[28]; /* Result from L2 CPU
*/
unsigned short L0RegBytes;
char
L0RegHeader[2];
unsigned short Mult_Reg[3];
/* The 3 multiplcity thresholds */
unsigned short ZDC_Reg[2];
/* The 2 ZDC thresholds */
unsigned short Spare_Reg ;
/* A spare, brings total for Reg to 16 bytes */
} TrgSumData;
/* 432 bytes total */
/* Data structure passed between L1ANA and L1DC */
typedef struct {
TrgEvtHeader TrgHead;
EvtDescData EvtDesc;
/* L1 Event Descriptor Data */
TrgSumData TrgSum;
/* summary data */
} L1dataType;
/* 464 bytes */
/* Raw Trigger detector data structures */
typedef struct {
unsigned short RawDetBytes;
char
RawDetHeader[2];
unsigned short CTBdataBytes;
char
CTBdataHeader[2];
BYTE
CTB[256]; /* CTB raw data
*/
unsigned short MWCdataBytes;
char
MWCdataHeader[2];
unsigned long MWCfiller;
/* dummy to bring header to mod 8 */
BYTE
MWC[128]; /* MWC raw data
*/
unsigned short EMCdataBytes;
char
EMCdataHeader[2];
unsigned long EMCfiller;
/* dummy to bring header to mod 8 */
BYTE
BEMC[128]; /* BEMC raw data */
/* NOTE!!!! THIS IS TEMPORARY _ MAY CHANGE */
} RawTrgDet;
/* 536 bytes total */
/* Trigger Event Structure */
typedef struct {
TrgEvtHeader TrgHead;
EvtDescData EvtDesc;
/* L1 Event Descriptor Data */
TrgSumData TrgSum;
/* summary data */
RawTrgDet RAW[MAX_RAW_DATA_BLOCKS];
/* raw Detector Data with pre and post History */
} TrgDataType;
/* 6360 bytes */
trgMsg.h
#define MAXMSGQ 30
/* Number of message queues that will be set up */
#define MSGQLEN 8190
/* Maximum number of messages a queue can hold */
#define MAX_MSG_LEN 64
/* Maximum size of each message in a queue */
#define MAX_MON 300
/* Depth of message monitoring ring buffer */
#define MON_MSG_LEN 3
/* Length (in words) of copy to monitoring buffer */
#define EVB 1
/* Event Builder Task number */
#define TDI 2
/* Trigger Daq Interface Task number */
#define TM 3
/* Token Manager Task number */
#define HI 4
/* Hardware Interface Task number */
#define IO 5
/* IO Task number */
#define SCL1 6
/* Level 1 Software Configuration Task number */
#define L1CTL 7
/* Level 1 Control Task */
#define L1ANA 8
/* Level 1 Analysis */
#define CTBC 11
/* CTB Control DSM read process */
#define MWCC 12
/* MWC Control DSM read process */
#define BEMCC 13
/* BEMC Control DSM read process */
#define L1DCTM 18 /* Level 1 DC Token Manager */
#define DAQ 16 /* DAQ Trigger Daq Interface Task number */
#define L2EB 22
/* Level 2 Event Builder */
#define L2ANA 23
/* Level 2 Analysis */
#define L2TDI 24
/* Level 2 TDI Interface */
#define L2L1I 25
/* Level 2 Level 1 Interface */
#define L2TR 26
/* Level 2 TDI Return */
#define STOP_RUN 0x00
#define START_RUN 0x01
#define ADD_TOKEN 0x02
#define CONFIG
0x03
#define CONFIG_CTB 0x04
#define DONE_CONFIG 0x05
#define RESYNCH
0x06 /* used
to re-synchronize DSM Address Pointers */
#define DONE_RESYNCH 0x07
#define LOAD_TKN
0x10
#define LOAD_ABORT 0x11
#define FIND_TOKEN 0x16
/* token managing command */
#define TOKEN_OK
0x17 /* token
managing command */
#define TOKEN_ERR 0x18
/* token managing command */
#define BUILD_EVT 0x20
#define L1_SEND_EVT 0x21
/* send L1 Event to L2 */
#define L1_ACC
0x22 /* L1CTL
to L1EventBuilder */
#define L1_ABORT
0x23 /* L1CTL
to TM */
#define L1_ANA
0x24 /* Analyze
L1 Event */
#define READ_DSM
0x25 /* Read
DSM's */
#define L2_SEND_EVT 0x30
/* send L1 Event to Analyze */
#define L2_ACC
0x31 /* L2CTL
to TDI */
#define L2_ABORT
0x32 /* L2CTL
to L1 */
#define L2_ANA
0x33 /* Analyze
L2 Event */
#define L3_ABORT
0x34 /* L2CTL
to L1 */
#define SEND_DAQ
0x74 /* Taken
from DAQ protocols */
#define RELEASE
0x85
#define STOP_RUN_W 0x01
#define START_RUN_W 0x02
#define ADD_TOKEN_W 0x02
#define CONFIG_W
0x02
#define CONFIG_CTB_W 0x02
#define DONE_CONFIG_W 0x02
#define RESYNCH_W 0x01
#define DONE_RESYNCH_W 0x01
#define LOAD_TKN_W 0x01
#define LOAD_ABORT_W 0x02
#define FIND_TOKEN_W 0x02
#define TOKEN_OK_W 0x02
#define TOKEN_ERR_W 0x02
#define BUILD_EVT_W 0x04
#define L1_SEND_EVT_W 0x01
#define L1_ACC_W
0x02
#define L1_ABORT_W 0x02
#define L1_ANA_W
0x02
#define READ_DSM_W 0x02
#define L2_SEND_EVT_W 0x01
#define L2_ACC_W
0x02
#define L2_ABORT_W 0x02
#define L2_ANA_W
0x02
#define L3_ABORT_W 0x02
#define SEND_DAQ_W 0x04
#define RELEASE_W 0x01
#define STAT_OK
0
/* Status to L2 of returned tokens: event accepted */
#define STAT_DAQ_REJ 1
/* Event rejected by DAQ TDI */
#define STAT_TM_REJ 2
/* Event rejected by error in TM processing */
#define STAT_GL3_REJ 3
/* Event rejected by GL3 */
#define STAT_SB_REJ 4
/* Event rejected by error in SB processing */
#define STAT_EVB_REJ 5
/* Event rejected by error in EVB processing */
#define STAT_TDI_REJ 16
/* Token NOT sent to DAQ by TDI because of error condition */
extern MSG_Q_ID daqMsgQueIDs[MAXMSGQ]; /* Global message Qs for all trigger tasks */
#define MSG_TIMEOUT 500
/* Message time out 5 secs */
#define TIMEOUT -1
/* Timeout gives error */
typedef struct msg_pkt {
/* ICCP7 layout */
char cmd, dst_task;
unsigned status :4;
unsigned token :12;
unsigned valid :12;
unsigned domain :4;
unsigned short sourceId;
short transaction;
char reserved, src_task;
int payload[13];
} msg_pkt;
typedef struct msg_monitor {
/* Used for message monitoring */
char cmd, dst_task;
unsigned status :4;
unsigned token :12;
unsigned valid :12;
unsigned domain :4;
unsigned short sourceId;
unsigned short targetId;
char reserved, src_task;
} msg_monitor;
static int get_message ( );
static int send_message(int dst, int cmd, int address,
int targetId, int valid_wrds, int stat);
STATUS sciMsgSend(ushort targetId, uint *pMsgPayload);
trgenv.h
#ifndef _TRGENV_INDLUDED_
/*
* Preprocessor constant definitions
*/
#define CFG_DEFAULT_NM
"default" /* startup configuration
nm */
#define CFG_SUBTREE_NM
"cfg" /* generic
config subtree nm */
#define DEF_TRIGGER_ROOT
"/home/startrg/trg/trg_soft_dev"
#define DEF_PRIVATE_ROOT
"."
/* for CTB map file */
#define DEF_MAP_DIR
"/home/startrg/trg/monitor/monfiles"
#define TRGENV_MAIN /* put in 090699 - zm
*/
#ifdef TRGENV_MAIN
#define EXT extern
char *trigger_root = DEF_TRIGGER_ROOT;
char *private_root = DEF_PRIVATE_ROOT;
#else
#define EXT extern
extern char *trigger_root;
extern char *private_root;
#endif
#ifndef MAX_PATH_LEN
#define MAX_PATH_LEN
132
#else
/*#ifeq MAX_PATH_LEN-132
fix your code: MAX_PATH_LEN should be the same
everywhere!!
#endif*/
#endif
/*
* variable definitions
*/
EXT char _trigger_root[MAX_PATH_LEN];
/* /startrg */
EXT char _private_root[MAX_PATH_LEN];
/* $USER/startrg */
/*
* function definitions
*/
int string_id (char *line, char *list[]);
FILE *cnf_open (char *name, char *object, char *path_used);
#undef EXT
#define _TRGENV_INCLUDED_
#endif
/* end of file trgenv.h */