vt2.c

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         vt2.c
00004   Created by:   Pierre-Andre Amaudruz
00005 
00006   Contents:
00007 
00008   $Id: vt2.c 3746 2007-07-10 08:26:11Z amaudruz $
00009 *********************************************************************/
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <stdio.h>
00013 #include "vmicvme.h"
00014 #include "vt2.h"
00015 
00016 #ifndef HAVE_UDELAY
00017 // this is the VMIC version of udelay()
00018 int udelay(int usec)
00019 {
00020   int i, j, k = 0;
00021   for (i=0; i<133; i++)
00022     for (j=0; j<usec; j++)
00023       k += (k+1)*j*k*(j+1);
00024   return k;
00025 }
00026 #endif
00027 
00028 /*****************************************************************/
00029 /*
00030 Read single event, return event length (number of entries)
00031 Uses single vme access! (1us/D32)
00032 */
00033 int vt2_FifoRead(MVME_INTERFACE *mvme, DWORD base, DWORD *pdest, int nentry)
00034 {
00035   int cmode, i;
00036 
00037   mvme_get_dmode(mvme, &cmode);
00038   mvme_set_dmode(mvme, MVME_DMODE_D32);
00039   for (i=0 ; i<nentry ; i++) {
00040     pdest[i] = mvme_read_value(mvme, base+VT2_FIFO_RO);
00041     //    printf("pdest[%i] = %lx\n", i, pdest[i]);
00042   }
00043   mvme_set_dmode(mvme, cmode);
00044   return nentry;
00045 }
00046 
00047 /*****************************************************************/
00048 /**
00049  return the Fifo level which is 64bits x 2048 with Almost full at 2000.
00050  the returned value is on 11 bits. It should be used as 2*level during read
00051  as the data is 64 bit wide.
00052  Data field 20bits : [0eaf][0000 0] 7FF fEmpty, fAlmostFull, Full, level
00053 */
00054 int vt2_FifoLevelRead(MVME_INTERFACE *mvme, DWORD base)
00055 {
00056   int  status, cmode;
00057 
00058   mvme_get_dmode(mvme, &cmode);
00059   mvme_set_dmode(mvme, MVME_DMODE_D32);
00060   status = mvme_read_value(mvme, base+VT2_FIFOSTATUS_RO);
00061   if (status & VT2_FULL_FLAG)
00062     status = -1;
00063   else
00064     status &= 0x7FF;
00065   mvme_set_dmode(mvme, cmode);
00066   return 2*status;
00067 }
00068 
00069 /*****************************************************************/
00070 /**
00071  return the cycle number (10 bit)
00072 */
00073 int vt2_CycleNumberRead(MVME_INTERFACE *mvme, DWORD base)
00074 {
00075   int  status, cmode;
00076 
00077   mvme_get_dmode(mvme, &cmode);
00078   mvme_set_dmode(mvme, MVME_DMODE_D32);
00079   status = mvme_read_value(mvme, base+VT2_CYCLENUMBER_RO);
00080   status &= 0x3FF;
00081   mvme_set_dmode(mvme, cmode);
00082   return status;
00083 }
00084 
00085 /*****************************************************************/
00086 int vt2_CSRRead(MVME_INTERFACE *mvme, DWORD base)
00087 {
00088   int  status, cmode;
00089 
00090   mvme_get_dmode(mvme, &cmode);
00091   mvme_set_dmode(mvme, MVME_DMODE_D32);
00092   status = mvme_read_value(mvme, base+VT2_CSR_RO);
00093   mvme_set_dmode(mvme, cmode);
00094   return status;
00095 }
00096 
00097 /*****************************************************************/
00098 void vt2_ManReset(MVME_INTERFACE *mvme, DWORD base)
00099 {
00100   int cmode;
00101   mvme_get_dmode(mvme, &cmode);
00102   mvme_set_dmode(mvme, MVME_DMODE_D32);
00103   mvme_write_value(mvme, base+VT2_CTL_WO, VT2_MANRESET);
00104   mvme_set_dmode(mvme, cmode);
00105 }
00106 
00107 /*****************************************************************/
00108 void vt2_IntEnable(MVME_INTERFACE *mvme, DWORD base, int flag)
00109 {
00110   int cmode;
00111   mvme_get_dmode(mvme, &cmode);
00112   mvme_set_dmode(mvme, MVME_DMODE_D32);
00113   if (flag == 1)
00114     mvme_write_value(mvme, base+VT2_CTL_WO, VT2_INTENABLE);
00115   else
00116     mvme_write_value(mvme, base+VT2_CTL_WO, VT2_INTENABLE<<16);
00117 
00118   mvme_set_dmode(mvme, cmode);
00119 }
00120 
00121 /*****************************************************************/
00122 void vt2_KeepAlive(MVME_INTERFACE *mvme, DWORD base, int fset)
00123 {
00124   int flag, cmode;
00125   mvme_get_dmode(mvme, &cmode);
00126   mvme_set_dmode(mvme, MVME_DMODE_D32);
00127   if (fset == 0)
00128     flag = (VT2_KEEPALIVE<<16);
00129   else
00130     flag = (VT2_KEEPALIVE);
00131   mvme_write_value(mvme, base+VT2_CTL_WO, flag);
00132   mvme_set_dmode(mvme, cmode);
00133 }
00134 
00135 /*****************************************************************/
00136 void vt2_CycleReset(MVME_INTERFACE *mvme, DWORD base, int fset)
00137 {
00138   int flag, cmode;
00139   mvme_get_dmode(mvme, &cmode);
00140   mvme_set_dmode(mvme, MVME_DMODE_D32);
00141   if (fset == 0)
00142     flag = (VT2_CYCLERESET<<16);
00143   else
00144     flag = VT2_CYCLERESET;
00145   printf("0x%x  flag:0x%x\n", base+VT2_CTL_WO, flag);
00146   mvme_write_value(mvme, base+VT2_CTL_WO, flag);
00147   mvme_set_dmode(mvme, cmode);
00148 }
00149 
00150 /*****************************************************************/
00151 /*-PAA- For test purpose only */
00152 #ifdef MAIN_ENABLE
00153 int main () {
00154 
00155   DWORD VT2_BASE = 0xe00000;
00156   DWORD dest[4000];
00157   int n;
00158 
00159   MVME_INTERFACE *myvme;
00160 
00161   int status, csr, i;
00162 
00163   // Test under vmic
00164   status = mvme_open(&myvme, 0);
00165 
00166   // Set am to A24 non-privileged Data
00167   mvme_set_am(myvme, MVME_AM_A24_ND);
00168 
00169   // Set dmode to D32
00170   mvme_set_dmode(myvme, MVME_DMODE_D32);
00171 
00172   csr = vt2_CSRRead(myvme, VT2_BASE);
00173   printf("CSR: 0x%x\n", csr);
00174 
00175 
00176   if (1) {
00177     printf("Manual Reset\n");
00178     vt2_ManReset(myvme, VT2_BASE);
00179   }
00180 
00181   if (0) {
00182     printf("Set Keep alive\n");
00183     vt2_KeepAlive(myvme, VT2_BASE, 1);
00184   }
00185 
00186   if (0) {
00187     printf("ReSet Keep alive\n");
00188     vt2_KeepAlive(myvme, VT2_BASE, 0);
00189   }
00190 
00191   if (0) {
00192     printf("Set Cycle Reset\n");
00193     vt2_CycleReset(myvme, VT2_BASE, 1);
00194   }
00195 
00196   if (0) {
00197     printf("ReSet Cycle Reset\n");
00198     vt2_CycleReset(myvme, VT2_BASE, 0);
00199   }
00200 
00201   udelay(100000);
00202   if (1) {
00203     printf("Read Fifo status\n");
00204     csr = vt2_CSRRead(myvme, VT2_BASE);
00205     printf("CSR : 0x%x\n", csr);
00206     csr = vt2_CycleNumberRead(myvme, VT2_BASE);
00207     printf("Read Cycle Number: %d\n", csr);
00208     csr = vt2_FifoLevelRead(myvme, VT2_BASE);
00209     printf("Read Fifo Level: %d\n", csr);
00210   }
00211 
00212   if (1) {
00213     printf("Read Fifo (16)\n");
00214     n = 16;
00215     vt2_FifoRead(myvme, VT2_BASE, &(dest[0]), n);
00216     for (i=0;i<n;i+=4) {
00217       printf("Data[%i]=%lx %lx %lx %lx  Diff:%ld (0x%lx)\n", i, dest[i], dest[i+1], dest[i+2], dest[i+3]
00218        , dest[i+3]-dest[i+1], dest[i+3]-dest[i+1]);
00219     }
00220   }
00221 
00222   status = mvme_close(myvme);
00223   return 1;
00224 }
00225 #endif
00226 

Midas DOC Version 2.0.2 ---- 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