00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _WIENERMACROS_H
00015 #define _WIENERMACROS_H
00016
00017
00018 #ifndef __CRT_STDIO_H
00019 #include <stdio.h>
00020 #define __CRT_STDIO_H
00021 #endif
00022
00023 #ifndef __CRT_UNISTD_H
00024 #include <unistd.h>
00025 #define __CRT_UNISTD_H
00026 #endif
00027
00028
00029 #ifndef __CAMAC_H
00030 #include <camac.h>
00031 #endif
00032
00033
00034
00035
00036
00037 #define camread16(b,c,n,a,f) (CAMRD16(CBDPTR((b), (c),(n),(a),(f), CAM16)))
00038 #define camread24(b, c, n, a, f) (CAMRD24(CBDPTR((b), (c),(n),(a),(f), CAM24)))
00039 #define camread32(b, c, n, a, f) (CAMRD32(CBDPTR((b), (c),(n),(a),(f), CAM24)))
00040
00041 #define camwrite16(b,c,n,a,f,d) (CAMWR16(CBDPTR((b), (c),(n),(a),(f), CAM16),d))
00042 #define camwrite24(b,c,n,a,f,d) (CAMWR24(CBDPTR((b), (c),(n),(a),(f), CAM24),d))
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #define camctl(b,c,n,a,f) { \
00056 if(f<16){ \
00057 if( *(volatile INT16 *)CBDPTR((b), (c),(n),(a),(f), CAM16) ){}; \
00058 } else *(volatile INT16 *)CBDPTR((b), (c),(n),(a),(f), CAM16)=0; \
00059 }
00060
00061 #define inhibit(b,c) camctl(b,c,27, 0, 26)
00062 #define uninhibit(b,c) camctl(b,c,27, 1, 24)
00063
00064
00065
00066
00067 #define qtst(c) ((camread16(0,(c),0,0,0) & 0x08) != 0)
00068 #define xtst(c) ((camread16(0,(c),0,0,0) & 0X04) != 0)
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 extern void WIENERBranchAccess(int branch);
00082
00083 #define AR 0x1000
00084 #define ROAK 0x0800
00085 #define VME_LAM_INT 0x0000
00086 #define VME_INT_VEC 0x0000
00087 #define branchinit(b) WIENERBranchAccess(b); \
00088 camwrite16(b,b+1,0,0,3,VME_LAM_INT|VME_INT_VEC); \
00089 camctl(b,b+1,31,0,16); \
00090 sleep(2)
00091
00092
00093
00094 #define crateinit(b, c) while((camread16(b,c,0,0,3) & 0x4000) == 0) \
00095 { \
00096 fprintf(stderr, "Crate %d is offline\n",c); \
00097 sleep(5); \
00098 } \
00099 camwrite24(b,c,28,1,16,0); \
00100 camctl(b,c,0,3,16); \
00101 camctl(b,c,0,2,16)
00102
00103
00104
00105 #define BEGINLAM(br,cr) { \
00106 UINT16 _b,_c; \
00107 INT16 _timout; \
00108 UINT32 _lammsk[br][cr]; \
00109 UINT16 MAXBR = br; \
00110 UINT16 MAXCR = cr; \
00111 \
00112 for(_b = 0; _b<br; _b++) \
00113 for(_c = 0; _c < cr; _c++) _lammsk[_b][_c] = 0;
00114
00115 #define ENDLAM }
00116
00117 #define NEEDLAM(b, c, n) _lammsk[b][c-1] |= (1 << (n-1))
00118
00119 #define IFTIMEOUT(maxloop) _timout = maxloop; \
00120 _b = 0; _c = 0; \
00121 while(_timout >= 0) \
00122 { \
00123 if(_lammsk[_b][_c] == 0) \
00124 { \
00125 _c++; \
00126 if(_c >= MAXCR) \
00127 { \
00128 _c = 0; \
00129 _b++; \
00130 if(_b >= MAXBR) break; \
00131 } \
00132 } else \
00133 { \
00134 _timout--; \
00135 _lammsk[_b][_c] &= ~(_lammsk[_b][_c] & \
00136 camread24(_b,_c+1,28,4,0));\
00137 } \
00138 } \
00139 if(_timout < 0)
00140
00141 #define LAMREAD(b,c) camread24((b), (c), 28, 4, 0)
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 #endif