00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _CESMACROS_H
00024 #define _CESMACROS_H
00025 #ifdef __unix__
00026 #ifndef __CRT_STDIO_H
00027 #include <stdio.h>
00028 #define __CRT_STDIO_H
00029 #endif
00030 #ifndef __CRT_UNISTD_H
00031 #include <unistd.h>
00032 #define __CRT_UNISTD_H
00033 #endif
00034 #endif
00035
00036 #include <camacmap.h>
00037
00038
00039
00040
00041
00042
00043 #define camread16(b,c,n,a,f) (CAMRD16(CBDPTR((b),(c),(n),(a),(f),CAM16)))
00044 #define camread24(b, c, n, a, f) (CAMRD24(CBDPTR((b),(c),(n),(a),(f), CAM24)))
00045
00046 #define camwrite16(b,c,n,a,f,d) (CAMWR16(CBDPTR((b),(c),(n),(a),(f),CAM16),d))
00047 #define camwrite24(b,c,n,a,f,d) (CAMWR24(CBDPTR((b),(c),(n),(a),(f),CAM24),d))
00048 #define camctl(b,c,n,a,f) CAMCTL(CBDPTR((b), (c), (n), (a), (f), CAM16))
00049
00050 #define inhibit(b,c) camctl(b,c,30,9,26);
00051 #define uninhibit(b,c) camctl(b,c,30,9,24);
00052
00053
00054
00055 #define qtst(b) (camread16((b),0,29,0,0) < 0)
00056 #define xtst(b) ((camread16((b),0,29,0,0) & 0X4000) != 0)
00057
00058
00059 extern void CESBranchAccess(int nBranch);
00060
00061 #define branchinit(b) CESBranchAccess(b); \
00062 camwrite16(b,0,29,0,0, MNOX| MTO | MLAM | MIT2 | MIT4);\
00063 camwrite16(b,0,29,0,4, 0); \
00064 camwrite16(b,0,29,0,9, 0); \
00065 sleep(2)
00066
00067 #define crateinit(b, c) while((camread16(b,0,29,0,9) & (1 << c)) == 0) \
00068 { \
00069 fprintf(stderr, "Branch %d Crate %d is offline\n", \
00070 b,c); \
00071 sleep(5); \
00072 } \
00073 camctl(b,c,28,9,26); \
00074 camctl(b,c,28,8,26); \
00075 camctl(b,c,30,9,24)
00076
00077
00078 #define BEGINLAM(br,cr) { \
00079 UINT16 _b,_c; \
00080 INT16 _timout; \
00081 UINT32 _lammsk[br][cr]; \
00082 UINT16 MAXBR = br; \
00083 UINT16 MAXCR = cr; \
00084 \
00085 for(_b = 0; _b<br; _b++) \
00086 for(_c = 0; _c < cr; _c++) _lammsk[_b][_c] = 0;
00087
00088 #define ENDLAM }
00089
00090 #define NEEDLAM(b, c, n) _lammsk[b][c-1] |= (1 << (n-1))
00091
00092 #define IFTIMEOUT(maxloop) _timout = maxloop; \
00093 _b = 0; _c = 0; \
00094 while(_timout >= 0) \
00095 { \
00096 if(_lammsk[_b][_c] == 0) \
00097 { \
00098 _c++; \
00099 if(_c >= MAXCR) \
00100 { \
00101 _c = 0; \
00102 _b++; \
00103 if(_b >= MAXBR) break; \
00104 } \
00105 } else \
00106 { \
00107 _timout--; \
00108 _lammsk[_b][_c] &= ~(_lammsk[_b][_c] & \
00109 camread24(_b,_c+1,30,0,0));\
00110 } \
00111 } \
00112 if(_timout < 0)
00113
00114 #define LAMREAD(b,c) camread24((b), (c), 30, 0, 0)
00115
00116
00117
00118
00119
00120
00121 #endif