caenv792.c

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         v792.c
00004   Created by:   Pierre-Andre Amaudruz
00005 
00006   Contents:     V792 32ch. QDC
00007                 
00008   $Id: caenv792.c 2753 2005-10-07 14:55:31Z ritt $
00009 
00010 *********************************************************************/
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include "vmicvme.h"
00016 #include "caenv792.h"
00017 
00018 /*****************************************************************/
00019 int v792_EventRead(DWORD *pbase, DWORD *pdest, int *nentry)
00020 {
00021   DWORD hdata;
00022   
00023   *nentry = 0;
00024   if (v792_DataReady((WORD *)pbase)) {
00025     do {
00026       hdata = *pbase;
00027     } while (!(hdata & 0x02000000)); // skip up to the header
00028     pdest[*nentry] = hdata;
00029     *nentry += 1;
00030     do {
00031       pdest[*nentry] = *pbase;
00032       *nentry += 1;
00033     } while (!(pdest[*nentry-1] & 0x04000000)); // copy until the trailer
00034 
00035     nentry--;
00036   }
00037   return *nentry;
00038 }
00039 
00040 /*****************************************************************/
00041 int v792_DataRead(DWORD *pbase, DWORD *pdest, int *nentry)
00042 {
00043   int k;
00044 
00045   *nentry = 0;
00046   if (v792_DataReady((WORD *)pbase)) {
00047     for (k=0 ; k<32 ; k++) {
00048       pdest[k] = pbase[k];
00049       *nentry += 1;
00050     }
00051   }
00052   return *nentry;
00053 }
00054 
00055 /*****************************************************************/
00056 int v792_ThresholdWrite(WORD *pbase, WORD *threshold, int *nitems)
00057 {
00058   int k;
00059   
00060   for (k=0; k<V792_MAX_CHANNELS ; k++) {
00061     pbase[V792_THRES_BASE+k] = threshold[k] & 0x1FF;
00062   }
00063   
00064   for (k=0; k<V792_MAX_CHANNELS ; k++) {
00065     threshold[k] = pbase[V792_THRES_BASE+k] & 0x1FF;
00066   }
00067   *nitems = V792_MAX_CHANNELS;
00068   return *nitems;
00069 }
00070 
00071 /*****************************************************************/
00072 void v792_EvtCntRead(WORD *pbase, DWORD *evtcnt)
00073 {
00074   *evtcnt = (pbase[V792_EVT_CNT_L_RO]
00075              + (DWORD) (0x10000 * pbase[V792_EVT_CNT_H_RO]));
00076 }
00077 
00078 /*****************************************************************/
00079 void v792_SingleShotReset(WORD *pbase)
00080 {
00081   pbase[V792_SINGLE_RST_WO] = 1;
00082 }
00083 
00084 /*****************************************************************/
00085 int  v792_DataReady(WORD *pbase)
00086 {
00087   //printf("data ready: 0x%08x\n",pbase[V792_CSR1_RO]);
00088   return (pbase[V792_CSR1_RO] & 0x1);
00089 }
00090 
00091 /*****************************************************************/
00092 void  v792_Status(WORD *pbase)
00093 {
00094   int status;
00095   
00096   printf("v792 Status for %p\n", pbase);
00097   status = pbase[V792_CSR1_RO];
00098   printf("Amnesia: %s, ", status & 0x10 ? "Y" : "N");
00099   printf("Term ON: %s, ", status & 0x40 ? "Y" : "N");
00100   printf("TermOFF: %s\n", status & 0x80 ? "Y" : "N");
00101   status = pbase[V792_FIRM_REV];
00102   printf("Firmware: 0x%x\n",status);
00103 
00104   if (pbase[V792_FIRM_REV] == 0xFFFF)
00105     {
00106       printf("v792 at %p: Invalid firmware revision: 0x%x\n",pbase,pbase[V792_FIRM_REV]);
00107       abort();
00108     }
00109 }
00110 
00111 /*****************************************************************/
00112 int v792_GeoWrite(WORD *pbase, int geo)
00113 {
00114   pbase[V792_GEO_ADDR_RW] = (geo & 0x1F);
00115   return (int) (pbase[V792_GEO_ADDR_RW] & 0x1F); 
00116 }
00117 
00118 /* end */

Midas DOC Version 3.0.0 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk