cescamac.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 /*
00019 *++
00020 **  FACILITY:
00021 **
00022 **      Data acquisition system
00023 **
00024 **  ABSTRACT:
00025 **
00026 **      camac.h - This file contains definitions and MACROS which 
00027 **                can be used to access the CAMAC system 
00028 **
00029 **  AUTHORS:
00030 **
00031 **      Ron Fox
00032 **
00033 **
00034 **  MODIFICATION HISTORY:
00035 **--
00036 **/
00037 #ifndef __CESCAMAC_H
00038 #define __CESCAMAC_H
00039 #ifndef _DAQTYPES_H
00040 #include <daqdatatypes.h>
00041 #endif
00042 
00043 
00044 /* CAMAC 'keywords'              */
00045 
00046 
00047 #define    CSRCRATE    0            /* 'crate' for Branch CSR */
00048 #define    CSRSLOT    29            /* 'slot' for branch CSR  */
00049 #define    CSRSUBAD    0            /* 'subaddress' for branch CSR */
00050 #define    CSRFUN    0              /* 'f code' for branch CSR      */
00051 
00052 
00053 
00054 /* The define below is used in the construction of CAMAC pointers: */
00055 
00056 #define    CAM16    2               /* 16 bit operation */
00057 #define    CAM24    0               /* 24 bit operation */
00058 #define    CAMF    2                /* Shift count to F field. */
00059 #define    CAMA    7                /* Shift count to A field  */
00060 #define    CAMN    11               /* Shift count to N field  */
00061 #define    CAMC    16               /* Shift count to C field  */
00062 #define    CAMB    19               /* Shift count to B field  */
00063                                     /* Base address of CAMAC branches: */
00064 #ifdef __unix__
00065 extern void*  (pBranchBases[]);
00066 #define CAMBAS(b) ((long)pBranchBases[(b)])
00067 #else
00068 #define    CAMBAS(b)  ((int)(camac.busbase + (int)busbases[camac.localaccess]))
00069 #endif
00070 
00071 /* The definitions below are bits in the BRANCH CSR.                 */
00072 
00073 #define    IT4    1                 /* Interrupt 4 pendng.           */
00074 #define    IT2    2                 /* Interrupt 2 pending           */
00075 #define    MIT4   0x4               /* Mask interrupt 4.             */
00076 #define    MIT2   0x8               /* Mask interrupt 2.             */
00077 #define    MLAM   0x10              /* Mask LAM interrupts.          */
00078 #define    MTO    0x20              /* MASK Branch timeout.          */
00079 #define    MNOX   0x800             /* Mask BERR on no x.            */
00080 #define    QMASK  0x8000            /* Q bit in branch CSR.         */
00081 #define    XMASK  0x4000            /* X bit in branch CSR.          */
00082 
00083 
00084 /* The macros below can be used to do accesses to the CAMAC at higher */
00085 /* speed than function calls might allow.                             */
00086 
00087     /*                      CBDPTR                                   */
00088     /* CBDPTR   - Generate a CAMAC pointer for the branch driver at */
00089     /*          - compile time.  To generate a pointer which might  */
00090     /*          - vary at run time, use the lower case version       */
00091     /*          - cbdptr which has the same call sequence.           */
00092     /*          - Both produce a pointer type                        */
00093     /*          - Arguments: b - branch, c - crate, n - slot,           */
00094     /*          -            a - subaddress, f - function           */
00095     /*          -            s - size, one of CAM16 or CAM24        */
00096     /*          By compile time generation, we mean that this macro */
00097     /*          can be used on the right hand side of #define directives */
00098     /*          or variable initializers for example:                */
00099     /* #define READDE1 CBDPTR(0, 1, 1, 0, 0, CAM16)                  */
00100     /* INT16   *readde1 = CBDPTR(0, 1, 1, 0, 0, CAM16);              */
00101     /* produce a macro READDE1 which produces the same pointer that the */
00102     /* variable readde1 is initialized to point to.                  */
00103 
00104 #define CBDPTR(b, c, n, a, f, s) \
00105     ((volatile INT16 *)((char*)CAMBAS(b) + (s) +  ( (c) << CAMC) + \
00106               ( (n) << CAMN ) + ( (a) << CAMA) + ( (f) << CAMF )))
00107 
00108     /*                          CAMCTL                                   */
00109     /* Do a CAMAC control operation (non data transfer)  The argument is */
00110     /* A pointer which has been constructed via either CBDPTR or cbdptr  */
00111     /* the size specified when constructing the pointer must have been   */
00112     /* CAM16 or else this will flop abysmally                            */
00113     /* use in a staement by itself, e.g.    CAMCTL(ADC1RST);             */
00114 
00115 #define    CAMCTL(ptr)    { if(*((volatile INT16 *)(ptr))){} }
00116 #ifndef __unix__
00117 #define    CAMCTLP(ptr)   probew((INT16 *)(ptr))
00118 #endif
00119     /*                          CAMRD16                                  */
00120     /* Do a 16 bit read from CAMAC via a pointer constructed with either */
00121     /* CBDPTR or cbdptr. The macro returns a value (may be treated like a */
00122     /* function) which is the result of the read.   The size argument    */
00123     /* specified when constructing the pointer must have been CAM16      */
00124     /* Sample usage:                                                     */
00125     /* result = (CAMRD16(DE1) * scale) / offset;                         */
00126 
00127 #define    CAMRD16(ptr)    (*(volatile INT16 *)(ptr))
00128 #ifndef __unix__
00129 #define    CAMRD16P(ptr,dest) prbrdw(((INT16 *)(ptr)), ((INT16 *)(&dest)))
00130 #endif
00131 
00132     /*                          CAMRD24                                  */
00133     /* Same as CAMRD16, but a 24 bit read is done, and the pointer must  */
00134     /* have been generated with size CAM24                               */
00135     /* This operation will be quite a bit slower than CAMRD16            */
00136 
00137 #define    CAMRD24(ptr)    (getlong(ptr) & 0xffffff)
00138 #ifndef VME16
00139 #ifndef __unix__
00140 #define    CAMRD24P(ptr,dest) prbrdl(((INT32 *)(ptr)), ((INT32 *)(&dest)))
00141 #endif
00142 #endif
00143     /*                          CAMWR16                                  */
00144     /* Does a 16 bit write CAMAC cycle. Use as a single statment e.g.    */
00145     /* CAMWR16(ptr, value);                                              */
00146     /* Arguments:                                                        */
00147     /*              ptr - Pointer produced by either CBDPTR or cbdptr.   */
00148     /*                     size must have been CAM16                     */
00149     /*              value - Least significant 16 bits of this are written */
00150 
00151 #define    CAMWR16(ptr, val)    (*((volatile INT16 *)(ptr)) = (val))
00152 #ifndef __unix
00153 #define    CAMWR16P(ptr, val)  prbwtw(((volatile INT16 *)(ptr)), ((INT16)(val)))
00154 #endif
00155     /*                          CAMWR24                                  */
00156     /* Just like CAMWR16, but the operation writes the lower 24 bits of  */
00157     /* the data.  The pointer argument must have been constructed with   */
00158     /* size CAM24                                                        */
00159 
00160 #define    CAMWR24(ptr, val)    (putlong( ((val) & 0xFFFFFF), ((volatile INT32 *)ptr)))
00161 #ifndef VME16
00162 #ifndef __unix__
00163 #define    CAMWR24P(ptr, val)  prbwtl(((INT32 *)(ptr)), ((INT32)(val)))
00164 #endif
00165 #endif
00166 
00167 
00168 #include <cesmacros.h>   /* Don't allow mis-match screwups. */
00169 
00170 #endif
00171 
00172 
00173 

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