cesmacros.h

Go to the documentation of this file.
00001 /*
00002     This software is Copyright by the Board of Trustees of Michigan
00003     State University (c) Copyright 2005.
00004 
00005     You may use this software under the terms of the GNU public license
00006     (GPL).  The terms of this license are described at:
00007 
00008      http://www.gnu.org/licenses/gpl.txt
00009 
00010      Author:
00011              Ron Fox
00012              NSCL
00013              Michigan State University
00014              East Lansing, MI 48824-1321
00015 */
00016 
00017 
00018 /* macros.h     - Macro definitions for data acquisition user programming */
00019 /*                assumed variables: INT16 *buffer -> buffer.           */
00020 /*                assumed include files: camac.h                        */
00021 
00022     /* CAMAC and buffer manipulation. */
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;     /* maxloop in ~10us */      \
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

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