Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:52

0001 /*
0002 **  Some standard definitions and typedefs for coding in the
0003 **  PHENIX online system.
0004 **
0005 */
0006 
0007 #ifndef _phenixOnlineIncludeProtection_
0008 #define _phenixOnlineIncludeProtection_
0009 
0010 
0011 
0012 #include "phenixTypes.h"
0013 
0014 #ifdef CONSTANT 
0015 #undef CONSTANT
0016 #endif
0017 #ifdef __cplusplus
0018 #define CONSTANT const
0019 #else
0020 #define CONSTANT static
0021 #endif
0022 
0023 #ifdef VXWORKS
0024 #define INLINE_P inline
0025 #define INLINE_D inline
0026 #else
0027 #define INLINE_P inline
0028 #define INLINE_D inline
0029 #endif
0030 
0031 /*
0032 **  Include malloc for some readback routines 
0033 **  skip for DCM compiler.
0034 */
0035 #if !defined(DCM) && !defined(VXWORKS)
0036 #include <memory.h>
0037 #endif
0038 
0039 #include <assert.h>
0040 #define Debug_Output
0041 
0042 #define DWORD_SIZE sizeof(PHDWORD)
0043 #define SWORD_SIZE sizeof(SWORD)
0044 
0045 CONSTANT UINT DwordSize = DWORD_SIZE;
0046 CONSTANT UINT SwordSize = SWORD_SIZE;
0047 
0048 #define PRDF_BIG_ENDIAN 2
0049 #define PRDF_LITTLE_ENDIAN 1
0050 
0051 /*
0052 **  We need to have all the various systems explicitly tested
0053 **    with ifdef's to define the proper endianism.
0054 */
0055 #define PRDF_LOCAL_ENDIANISM PRDF_LITTLE_ENDIAN
0056 
0057 CONSTANT UINT PRDFbigEndian = PRDF_BIG_ENDIAN;
0058 CONSTANT UINT PRDFlittleEndian = PRDF_LITTLE_ENDIAN;
0059 CONSTANT UINT PRDFlocalEndianism = PRDF_LOCAL_ENDIANISM;
0060 
0061 /*
0062 ** Function return values
0063 */
0064 typedef int LOGIC_ret;
0065 typedef UINT VALUE_ret;
0066 typedef PHDWORD* PTR_ret;
0067 
0068 #ifdef VXWORKS
0069 #define TRUE  1
0070 #define FALSE 0
0071 #else
0072 #ifndef TRUE
0073 CONSTANT LOGIC_ret TRUE = 1;
0074 #endif
0075 #ifndef FALSE
0076 CONSTANT LOGIC_ret FALSE = 0;
0077 #endif
0078 #endif
0079 
0080 /*
0081 **  Other constant definitions
0082 */
0083 CONSTANT VALUE_ret valueFailure = 0xffffffff;
0084 PTR_ret CONSTANT ptrFailure = 0;
0085 CONSTANT LOGIC_ret logicFailure = FALSE;
0086 CONSTANT LOGIC_ret logicSuccess = TRUE;
0087 CONSTANT UINT maxByteValue = 0xff ;
0088 CONSTANT UINT maxSwordValue = 0xffff ;
0089 CONSTANT UINT maxDwordValue = 0xfffffffe ; /* reserve 0xffffffff for errors */
0090 
0091 
0092 #define dwordCopy(out_ptr, in_ptr, numDwords) \
0093 memcpy (out_ptr, in_ptr, 4*(numDwords))
0094 
0095 #define dwordClear(out_ptr, numDwords) \
0096 memset (out_ptr, 0, 4*(numDwords))
0097 
0098 #define byteClear(out_ptr, numBytes) \
0099 memset (out_ptr, 0, numBytes)
0100 
0101 #define byteCopy(out_ptr, in_ptr, numBytes) \
0102 memcpy (out_ptr, in_ptr, numBytes)
0103 
0104 /*
0105 **  Byte-swapping routines. There will likely be compiler or processor-specific
0106 **    implementations of these.
0107 */
0108 /*
0109 **  A generic byte-swapping implementation that will likely work on any
0110 **    machine but is likely to be slow. 
0111 **
0112 **  Note that the swap is not done "in-place".
0113 */
0114 //inline int mlp();
0115 //inline unsigned long singleDwordByteSwap(DWORD);
0116 INLINE_D PHDWORD singleDwordByteSwap(PHDWORD inDword)
0117 {
0118   PHDWORD outDword;
0119 
0120   outDword = (inDword & 0xFF) << 24;
0121   outDword |= (inDword >> 8 & 0xFF) << 16;
0122   outDword |= (inDword >> 16 & 0xFF) << 8;
0123   outDword |= (inDword >> 24 & 0xFF);
0124   return outDword;
0125 }
0126 
0127 /*
0128 **  A routine to byte swap a sequence of dwords.
0129 **
0130 **  Since singleDwordByteSwap does not do an "in-place" swap, this routine
0131 **  can be safely used with in_ptr = out_ptr.
0132 */
0133 inline void dwordByteSwap (PHDWORD* out_ptr, PHDWORD* in_ptr, PHDWORD numDwords)
0134 {
0135   UINT i; 
0136   for (i = 0; i< numDwords; i++) *out_ptr++ = singleDwordByteSwap(*in_ptr++);
0137 }
0138 
0139 /*
0140 ** Define macros to insert/extract bit fields from DWORD
0141 */
0142 
0143 #define getWordMACRO(packet_ptr,offsetOfDWORD) (*((packet_ptr)+(offsetOfDWORD)))
0144 
0145 #define getBitsMACRO(packet_ptr,offsetOfDWORD,offsetInDWORD,mask) \
0146              (((*((packet_ptr)+(offsetOfDWORD)))&(mask))>>offsetInDWORD)
0147 
0148 
0149 #define setWordMACRO(packet_ptr,offsetOfDword,value) \
0150              (*(packet_ptr+offsetOfDword))=value
0151 
0152 
0153 #define setBitsMACRO(packet_ptr,offsetOfDword,offsetInDword,mask,value) \
0154              (*(packet_ptr+offsetOfDword))&=(~mask); \
0155              (*(packet_ptr+offsetOfDword))|=(value<<offsetInDword)
0156 
0157 
0158 #endif 
0159 
0160      /* end of ifndef _phenixOnlineIncludeProtection_ */
0161 
0162 
0163 
0164 
0165 
0166 
0167 
0168 
0169 
0170 
0171 
0172 
0173 
0174 
0175 
0176 
0177 
0178 
0179 
0180 
0181 
0182 
0183 
0184