JLab f1TDC-V2,V3 Library  V2:0x0e,V3:0x15
 All Data Structures Files Functions Variables Typedefs Macros Groups
f1tdcLib.c File Reference

Macros

#define F1LOCK   if(pthread_mutex_lock(&f1Mutex)<0) perror("pthread_mutex_lock");
 
#define F1UNLOCK   if(pthread_mutex_unlock(&f1Mutex)<0) perror("pthread_mutex_unlock");
 
#define TEST_MAX_WORDS   (64*8 + 9)
 

Typedefs

typedef struct chipchannel_struct chipchanInfo
 

Functions

STATUS f1Init (UINT32 addr, UINT32 addr_inc, int ntdc, int iFlag)
 Initialize JLAB F1 TDC Library. More...
 
int f1Slot (unsigned int i)
 Convert an index into a slot number, where the index is the element of an array of F1TDCs in the order in which they were initialized. More...
 
int f1ConfigWrite (int id, int *config_data, int chipMask)
 Write the specified configuration to provided chips of the module in slot id indicated by the chipmask. More...
 
int f1GConfigWrite (int *config_data, int chipMask)
 Write the specified configuration to provided chips of all initialized f1TDCs indicated by the chipmask. More...
 
int f1SetConfig (int id, int iflag, int chipMask)
 Set which preset/user configuration to use for specified slot id for indicated chips in chipmask. More...
 
int f1ConfigRead (int id, unsigned int *config_data, int chipID)
 Read the f1TDC Chip Registers into user specified config_data array. More...
 
int f1ConfigReadFile (char *filename)
 Read in user defined (4) f1TDC chip registers from specified file. More...
 
void f1ConfigShow (int id, int chipMask)
 Print to standard out the configuration of the f1TDC chips specified by the chipmask and module in slot id. More...
 
int f1GetSerialNumber (int id, char **rval)
 Fills 'rval' with a character array containing the fa250 serial number. More...
 
int f1GetFirmwareVersion (int id, int pflag)
 Get the firmware version of the FPGA. More...
 
void f1Status (int id, int sflag)
 Print Status of f1TDC to standard out. More...
 
void f1GStatus (int sFlag)
 Print Status of all initialized f1TDCs to standard out. More...
 
void f1ChipStatus (int id, int pflag)
 Print Status of f1TDC chips to standard out. More...
 
int f1ReadBlock (int id, volatile UINT32 *data, int nwrds, int rflag)
 General Data readout routine. More...
 
int f1PrintEvent (int id, int rflag)
 Readout and print event to standard out. More...
 
int f1FlushEvent (int id)
 Routine to flush a partial event from the FIFO. Read until a valid trailer is found. More...
 
int f1GPrintEvent (int rflag)
 Readout and print event from all initialized f1TDCs to standard out. More...
 
void f1Clear (int id)
 Perform a soft reset on the f1TDC module. More...
 
void f1GClear ()
 Perform a soft reset on all initialized f1TDC modules. More...
 
void f1ClearStatus (int id, unsigned int chipMask)
 Clear the latched error status of specified f1TDC chips in the chipMask. More...
 
void f1GClearStatus (unsigned int chipMask)
 Clear the latched error status of specified f1TDC chips in the chipMask in all initialized f1TDCs. More...
 
unsigned int f1ErrorStatus (int id, int sflag)
 Return the Error status for all the f1TDC chips on the module. More...
 
unsigned int f1GErrorStatus (int sflag)
 Return the Error status for all the f1TDC chips on all initialized modules. More...
 
int f1CheckLock (int id)
 Get Resolution lock status for all chips on the board. More...
 
int f1GCheckLock (int pflag)
 Get Resolution lock status for all chips on all initialized f1TDCs. More...
 
void f1Reset (int id, int iFlag)
 Perform a hard reset of the module. More...
 
void f1SyncReset (int id)
 Perform a software Sync Reset on the module. More...
 
void f1GSyncReset ()
 Perform a software Sync Reset for all initialized modules. More...
 
void f1Trig (int id)
 Issue a software trigger to the module. More...
 
void f1GTrig ()
 Issue a software trigger to all initialized modules. More...
 
void f1Start (int id)
 Issue a software Start signal to the module. More...
 
void f1GStart ()
 Issue a software Start signal to all initialized modules. More...
 
int f1Dready (int id)
 Determine if an event is ready for readout on the module. More...
 
int f1Bready (int id)
 Return block available for readout status of the module. More...
 
unsigned int f1GBready ()
 Return the mask of all initialized modules with blocks available for readout. More...
 
int f1DataScan (int pflag)
 Return the mask of all initialized modules with events available for readout. More...
 
unsigned int f1ScanMask ()
 Return the mask of all initialized modules. More...
 
int f1GetRez (int id)
 Return the mask of f1TDCs chips on the module that are set in high resolution mode. More...
 
int f1SetWindow (int id, int window, int latency, int chipMask)
 Set the window parameters for specified f1TDC chips in chipMask on the module. More...
 
void f1GSetWindow (int window, int latency, int chipMask)
 Set the window parameters for specified f1TDC chips in chipMask for all initialized modules. More...
 
unsigned int f1ReadCSR (int id)
 Return the value of the CSR register of the module. More...
 
int f1WriteControl (int id, unsigned int val)
 Write provided value to the CTRL register of the module. More...
 
void f1GWriteControl (unsigned int val)
 Write provided value to the CTRL register to all initialized modules. More...
 
int f1Enable (int id)
 Enable f1TDC FPGA data fifo on the module. More...
 
int f1GEnable ()
 Enable f1TDC FPGA data fifo on all initialized modules. More...
 
int f1Disable (int id)
 Disable f1TDC FPGA data fifo on the module. More...
 
int f1GDisable ()
 Disable f1TDC FPGA data fifo on all initialized modules. More...
 
int f1Enabled (int id)
 Return enabled/disabled status of FPGA data fifo. More...
 
int f1EnableData (int id, int chipMask)
 Enable data on f1TDC chips specified in chipMask for the module. More...
 
void f1GEnableData (int chipMask)
 Enable data on f1TDC chips specified in chipMask for all initialized modules. More...
 
int f1DisableData (int id)
 Disable data on all f1TDC chips for the module. More...
 
int f1DisableChannel (int id, int input)
 Disable an individual channel input. More...
 
int f1EnableChannel (int id, int input)
 Enable an individual channel input. More...
 
void f1DisableChannelMask (int id, unsigned long long int mask)
 Disable inputs indicated in channel mask for the module. More...
 
void f1EnableChannelMask (int id, unsigned long long int mask)
 Enable inputs indicated in channel mask for the module. More...
 
void f1EnableClk (int id, int cflag)
 Enable the specified clock source on the module. More...
 
void f1DisableClk (int id)
 Disable the current clock source on the module. More...
 
unsigned int f1EnableLetra (int id, int chipMask)
 Enable lead and trailing edges for the f1TDC chips indicated by the chipMask for the module. More...
 
unsigned int f1DisableLetra (int id, int chipMask)
 Disable lead and trailing edges for the f1TDC chips indicated by the chipMask for the module. More...
 
void f1EnableSoftTrig (int id)
 Enable software triggers on the module. More...
 
void f1GEnableSoftTrig ()
 Enable software triggers for all initialized modules. More...
 
void f1DisableSoftTrig (int id)
 Disable software triggers on the module. More...
 
void f1EnableBusError (int id)
 Enable bus error block termination on the module. More...
 
void f1GEnableBusError ()
 Enable bus error block termination for all initialized modules. More...
 
void f1DisableBusError (int id)
 Disable bus error block termination on the module. More...
 
int f1SetBlockLevel (int id, int level)
 Set the block level (number of events per block) on the module. More...
 
void f1GSetBlockLevel (int level)
 Set the block level (number of events per block) on all initialized modules. More...
 
void f1EnableMultiBlock (int tflag)
 Enable multiblock readout for all initialized modules. More...
 
void f1DisableMultiBlock ()
 Disable multiblock readout for all initialized modules. More...
 
void f1ResetToken (int id)
 Reset the token for the module. More...
 
int f1ResetPulser (int id)
 Reset (initialize) pulser. More...
 
int f1SetPulserTriggerDelay (int id, int delay)
 Set the delay between the output pulse and f1TDC trigger. More...
 
int f1SetPulserDAC (int id, int output, int dac)
 Set the DAC level for the outgoing pulse. More...
 
int f1SoftPulser (int id, int output)
 Trigger the pulser. More...
 
void f1TestSetSystemTestMode (int id, int mode)
 Enable/Disable System test mode. More...
 
void f1TestSetTrigOut (int id, int mode)
 Set the level of Trig Out to the SD. More...
 
void f1TestSetBusyOut (int id, int mode)
 Set the level of Busy Out to the SD. More...
 
void f1TestSetSdLink (int id, int mode)
 Set the level of the SD Link. More...
 
void f1TestSetTokenOut (int id, int mode)
 Set the level of Token Out to the SD. More...
 
int f1TestGetStatBitB (int id)
 Get the level of the StatBitB to the SD. More...
 
int f1TestGetTokenIn (int id)
 Get the level of the Token In from the SD. More...
 
int f1TestGetClockCounterStatus (int id)
 Return the status of the 250Mhz Clock Counter. More...
 
unsigned int f1TestGetClockCounter (int id)
 Return the value of the 250Mhz Clock scaler. More...
 
unsigned int f1TestGetSyncCounter (int id)
 Return the value of the SyncReset scaler. More...
 
unsigned int f1TestGetTrig1Counter (int id)
 Return the value of the trig1 scaler. More...
 
unsigned int f1TestGetTrig2Counter (int id)
 Return the value of the trig2 scaler. More...
 
void f1TestResetClockCounter (int id)
 Reset the counter of the 250MHz Clock scaler. More...
 
void f1TestResetSyncCounter (int id)
 Reset the counter of the SyncReset scaler. More...
 
void f1TestResetTrig1Counter (int id)
 Reset the counter of the trig1 scaler. More...
 
void f1TestResetTrig2Counter (int id)
 Reset the counter of the trig2 scaler. More...
 
void f1TestRead ()
 
void f1ISR (int arg)
 
void f1DataDecode (int id, unsigned int data)
 Decode a data word from an fADC250 and print to standard out. More...
 

Variables

pthread_mutex_t f1Mutex = PTHREAD_MUTEX_INITIALIZER
 
pthread_mutex_t f1sdcMutex = PTHREAD_MUTEX_INITIALIZER
 
BOOL f1tdcIntRunning = FALSE
 
int f1tdcIntID = -1
 
LOCAL VOIDFUNCPTR f1tdcIntRoutine = NULL
 
LOCAL int f1tdcIntArg = 0
 
LOCAL UINT32 f1tdcIntLevel = F1_VME_INT_LEVEL
 
LOCAL UINT32 f1tdcIntVec = F1_VME_INT_VEC
 
LOCAL int f1ConfigData [5][16]
 
int nf1tdc = 0
 
int f1tdcA32Base = 0x08000000
 
int f1tdcA32Offset = 0x08000000
 
int f1tdcA24Offset = 0x0
 
int f1tdcA16Offset = 0x0
 
volatile struct f1tdc_structf1p [(F1_MAX_BOARDS+1)]
 
volatile unsigned int * f1pd [(F1_MAX_BOARDS+1)]
 
volatile unsigned int * f1pmb
 
int f1ID [F1_MAX_BOARDS]
 
unsigned int f1AddrList [F1_MAX_BOARDS]
 
int f1Rev [(F1_MAX_BOARDS+1)]
 
int f1Nchips [(F1_MAX_BOARDS+1)]
 
int f1MaxSlot =0
 
int f1MinSlot =0
 
int f1tdcIntCount = 0
 
unsigned int f1LetraMode = 0
 
unsigned long long int f1ChannelDisable [(F1_MAX_BOARDS+1)]
 
int f1ClockSource =0
 
int f1TestEventCount
 
int f1TestClearCount
 
int f1TestErrorCount
 
unsigned int f1TestData [TEST_MAX_WORDS]
 

Macro Definition Documentation

#define TEST_MAX_WORDS   (64*8 + 9)

Referenced by f1ISR(), and f1TestRead().

Typedef Documentation

typedef struct chipchannel_struct chipchanInfo

Function Documentation

Variable Documentation

unsigned int f1AddrList[F1_MAX_BOARDS]

Referenced by f1Init().

unsigned long long int f1ChannelDisable[(F1_MAX_BOARDS+1)]

Referenced by f1Init().

int f1ClockSource =0

Referenced by f1ConfigShow(), f1Init(), and f1SetWindow().

LOCAL int f1ConfigData[5][16]
Initial value:
= {
{ 0x0180, 0x8000, 0x407F, 0x407F,
0x407F, 0x407F, 0x003F, 0x9CC0,
0x22E2, 0x68A6, 0x1FEB, 0x0000,
0x0000, 0x0000, 0x0000, 0x000C},
{ 0x0180, 0x8000, 0x407F, 0x407F,
0x407F, 0x407F, 0x003F, 0x9C00,
0x22EF, 0x68CE, 0x1FF1, 0x0000,
0x0000, 0x0000, 0x0000, 0x000C},
{ 0x0180, 0x0000, 0x4040, 0x4040,
0x4040, 0x4040, 0x003F, 0xBA00,
0x63A4, 0xCDEC, 0x1FEB, 0x0000,
0x0000, 0x0000, 0x0000, 0x000C},
{ 0x0180, 0x0000, 0x4040, 0x4040,
0x4040, 0x4040, 0x003F, 0xB880,
0x61D1, 0xCE1E, 0x1FF1, 0x0000,
0x0000, 0x0000, 0x0000, 0x000C},
{ 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000}
}

Referenced by f1ConfigReadFile(), f1Init(), f1Reset(), and f1SetConfig().

int f1ID[F1_MAX_BOARDS]

Referenced by f1Bready(), f1CheckLock(), f1ChipStatus(), f1Clear(), f1ClearStatus(), f1ConfigRead(), f1ConfigShow(), f1ConfigWrite(), f1DataScan(), f1Disable(), f1DisableBusError(), f1DisableClk(), f1DisableData(), f1DisableLetra(), f1DisableMultiBlock(), f1DisableSoftTrig(), f1Dready(), f1Enable(), f1EnableBusError(), f1EnableClk(), f1Enabled(), f1EnableData(), f1EnableLetra(), f1EnableMultiBlock(), f1EnableSoftTrig(), f1ErrorStatus(), f1FlushEvent(), f1GBready(), f1GCheckLock(), f1GClear(), f1GClearStatus(), f1GConfigWrite(), f1GDisable(), f1GEnable(), f1GEnableBusError(), f1GEnableData(), f1GEnableSoftTrig(), f1GErrorStatus(), f1GetFirmwareVersion(), f1GetRez(), f1GetSerialNumber(), f1GPrintEvent(), f1GSetBlockLevel(), f1GSetWindow(), f1GStart(), f1GStatus(), f1GSyncReset(), f1GTrig(), f1GWriteControl(), f1Init(), f1ISR(), f1PrintEvent(), f1ReadBlock(), f1ReadCSR(), f1Reset(), f1ResetPulser(), f1ResetToken(), f1ScanMask(), f1SetBlockLevel(), f1SetConfig(), f1SetPulserDAC(), f1SetPulserTriggerDelay(), f1SetWindow(), f1Slot(), f1SoftPulser(), f1Start(), f1Status(), f1SyncReset(), f1TestGetClockCounter(), f1TestGetClockCounterStatus(), f1TestGetStatBitB(), f1TestGetSyncCounter(), f1TestGetTokenIn(), f1TestGetTrig1Counter(), f1TestGetTrig2Counter(), f1TestRead(), f1TestResetClockCounter(), f1TestResetSyncCounter(), f1TestResetTrig1Counter(), f1TestResetTrig2Counter(), f1TestSetBusyOut(), f1TestSetSdLink(), f1TestSetSystemTestMode(), f1TestSetTokenOut(), f1TestSetTrigOut(), f1Trig(), and f1WriteControl().

unsigned int f1LetraMode = 0

Referenced by f1DisableLetra(), and f1EnableLetra().

int f1MaxSlot =0
int f1MinSlot =0
pthread_mutex_t f1Mutex = PTHREAD_MUTEX_INITIALIZER
volatile unsigned int* f1pd[(F1_MAX_BOARDS+1)]
volatile unsigned int* f1pmb

Referenced by f1Init(), and f1ReadBlock().

pthread_mutex_t f1sdcMutex = PTHREAD_MUTEX_INITIALIZER
int f1tdcA16Offset = 0x0
int f1tdcA24Offset = 0x0

Referenced by f1Init(), and f1Status().

int f1tdcA32Base = 0x08000000

Referenced by f1Init().

int f1tdcA32Offset = 0x08000000

Referenced by f1Init(), and f1ReadBlock().

LOCAL int f1tdcIntArg = 0

Referenced by f1Init().

int f1tdcIntCount = 0
int f1tdcIntID = -1

Referenced by f1Init().

LOCAL UINT32 f1tdcIntLevel = F1_VME_INT_LEVEL

Referenced by f1Init().

LOCAL VOIDFUNCPTR f1tdcIntRoutine = NULL

Referenced by f1Init().

BOOL f1tdcIntRunning = FALSE

Referenced by f1Init().

LOCAL UINT32 f1tdcIntVec = F1_VME_INT_VEC

Referenced by f1Init().

int f1TestClearCount
unsigned int f1TestData[TEST_MAX_WORDS]
int f1TestErrorCount
int f1TestEventCount