wienermacros.h

Go to the documentation of this file.
00001 /* This software was contributed by Dave Caussyn of Florida State
00002    University.
00003 */
00004 
00005 /*
00006  * macros_vc32.h  - Macro definitions for data acquisition user programming
00007  *                  assumed variables: INT16 *buffer -> buffer.  Modifications
00008  *                  to macros.h for using Wiener vc32.
00009  */
00010 
00011 
00012     /* CAMAC and buffer manipulation. */
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 /*All definitions referring to CBDPTR are changed from macros.h--ddc */
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 camctl...
00047 unfortunately, the prior version of camctl assumed that a READ was
00048 was always being done.  Even though there is (or should be!) NO data for 
00049 commands that use "camctl", the wiener VC32-CC32 depends on the type of 
00050 access to determine the actual function that it executes (reading for 
00051 F<16, write for F>=16). So, we replace the camctl macro. --ddc
00052 */ 
00053 
00054 /* #define camctl(b,c,n,a,f)        CAMCTL(CBDPTR((b), (c), (n), (a), (f), CAM16)) */
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    /*Wiener cc32 uses NAF of 0,0,0 to get status word --ddc */
00066   /*NOTE! BRANCH is not used any longer,  specify crate */
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 /*Until my next comment... there are no changes from macros.h --ddc*/
00071     
00072 
00073 
00074 /*
00075  * Ok... obviously branchinit and crateinit are largely different.
00076  * The "branchinit" we use to initialize the vc32 interface(s).  The
00077  * branch number is irrelevent, but each vc32 has a "number" same as
00078  * crate number. --ddc
00079  */
00080 
00081  extern void WIENERBranchAccess(int branch);
00082 
00083 #define AR 0x1000             /* turns on autoread ... NORMALLY OFF! */
00084 #define ROAK 0x0800           /* ROAK mode, RORA mode if zero */
00085 #define VME_LAM_INT 0x0000    /* If vme int generated for LAMS (bits8-11) */
00086 #define VME_INT_VEC 0x0000    /* If vme int vector for LAMS (bits0-7) */
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 /* NAF (0,3,16) Z+I, (0,2,16) C+Uninhibit, (28,1,16,0) set lam mask */
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;     /* maxloop in ~10us */      \
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 /* LAM read commands in macros changed to NAF 28,4,0 --ddc */
00144 
00145 
00146 
00147 /*
00148 ** Handle phillips adc/qdc/tdc:
00149 */
00150 
00151        /* I/O macros */
00152 
00153 
00154 /*#endif  * endif for MACROS_H defined */
00155 #endif         /*  _WIENERMACROS_H */

Generated on Wed Sep 17 08:38:09 2008 for NSCL Device support. by  doxygen 1.5.1