lrs1190.c

Go to the documentation of this file.
00001 /*********************************************************************
00002   @file
00003   Name:         lrs1190.c
00004   Created by:   Pierre-Andre Amaudruz
00005   Content:      LeCroy 32bit Dual port memory
00006   $Id: lrs1190.c 3763 2007-07-20 23:12:11Z amaudruz $
00007 *********************************************************************/
00008 #include <stdio.h>
00009 #include <string.h>
00010 #if defined(OS_LINUX)
00011 #include <unistd.h>
00012 #endif
00013 #include "lrs1190.h"
00014 
00015 /*****************************************************************/
00016 /*
00017 Reset the LRS1190
00018 */
00019 void lrs1190_Reset(MVME_INTERFACE *mvme, DWORD base)
00020 {
00021   int   cmode, status;
00022 
00023   mvme_get_dmode(mvme, &cmode);
00024   mvme_set_dmode(mvme, MVME_DMODE_D16);
00025 
00026   status = mvme_read_value(mvme, base+LRS1190_RESET_WO);
00027   mvme_set_dmode(mvme, cmode);
00028   return;
00029 }
00030 
00031 /*****************************************************************/
00032 /*
00033 Enable the LRS1190 FPP
00034 */
00035 void lrs1190_Enable(MVME_INTERFACE *mvme, DWORD base)
00036 {
00037   int   cmode;
00038 
00039   mvme_get_dmode(mvme, &cmode);
00040   mvme_set_dmode(mvme, MVME_DMODE_D16);
00041 
00042   mvme_write_value(mvme, base+LRS1190_ENABLE_RW, 0x1);
00043   mvme_set_dmode(mvme, cmode);
00044   return;
00045 }
00046 
00047 /*****************************************************************/
00048 /*
00049 Disable the LRS1190 FPP
00050 */
00051 void lrs1190_Disable(MVME_INTERFACE *mvme, DWORD base)
00052 {
00053   int   cmode;
00054 
00055   mvme_get_dmode(mvme, &cmode);
00056   mvme_set_dmode(mvme, MVME_DMODE_D16);
00057 
00058   mvme_write_value(mvme, base+LRS1190_ENABLE_RW, 0x0);
00059   mvme_set_dmode(mvme, cmode);
00060   return;
00061 }
00062 
00063 /*****************************************************************/
00064 /*
00065 Read the counter
00066 */
00067 int lrs1190_CountRead(MVME_INTERFACE *mvme, DWORD base)
00068 {
00069   int   cmode, count;
00070 
00071   mvme_get_dmode(mvme, &cmode);
00072   mvme_set_dmode(mvme, MVME_DMODE_D16);
00073 
00074   count = mvme_read_value(mvme, base+LRS1190_COUNT_RO);
00075   mvme_set_dmode(mvme, cmode);
00076   return count;
00077 }
00078 
00079 /*****************************************************************/
00080 /*
00081 Read the I4 data
00082 */
00083 int lrs1190_I4Read(MVME_INTERFACE *mvme, DWORD base, DWORD * data, int r)
00084 {
00085   int  cmode, count;
00086   DWORD add;
00087   mvme_get_dmode(mvme, &cmode);
00088   mvme_set_dmode(mvme, MVME_DMODE_D16);
00089   count = mvme_read_value(mvme, base+LRS1190_COUNT_RO);
00090   mvme_write_value(mvme, base+LRS1190_ENABLE_RW, 0x0);
00091   mvme_set_dmode(mvme, MVME_DMODE_D32);
00092   printf("internal count:%d\n", count);
00093   if (r > count) r = count;
00094   add = base+LRS1190_DATA_RO;
00095   while (r > 0) {
00096     *data = mvme_read_value(mvme, add);
00097     add += 4;
00098     printf("data:0x%x\n", *data);
00099     data++;
00100     r--;
00101   }
00102   mvme_set_dmode(mvme, MVME_DMODE_D16);
00103   mvme_write_value(mvme, base+LRS1190_RESET_WO, 0);
00104   mvme_write_value(mvme, base+LRS1190_ENABLE_RW, 0x1);
00105   mvme_set_dmode(mvme, cmode);
00106   return count;
00107 }
00108 
00109 /*****************************************************************/
00110 /*
00111 Read the LowI2 data
00112 */
00113 int lrs1190_L2Read(MVME_INTERFACE *mvme, DWORD base, WORD * data, int r)
00114 {
00115   int  cmode, count;
00116   DWORD local;
00117 
00118   mvme_get_dmode(mvme, &cmode);
00119   mvme_set_dmode(mvme, MVME_DMODE_D16);
00120   count = mvme_read_value(mvme, base+LRS1190_COUNT_RO);
00121   mvme_set_dmode(mvme, MVME_DMODE_D32);
00122   if (r > count) r = count;
00123   while (r > 0) {
00124     local = mvme_read_value(mvme, base+LRS1190_DATA_RO);
00125     *data = *((WORD *)(&local)+0);
00126     data++;
00127     r--;
00128   }
00129   mvme_set_dmode(mvme, cmode);
00130   return count;
00131 }
00132 
00133 /*****************************************************************/
00134 /*
00135 Read the HighI2 data
00136 */
00137 int lrs1190_H2Read(MVME_INTERFACE *mvme, DWORD base, WORD * data, int r)
00138 {
00139   int  cmode, count;
00140   DWORD local;
00141 
00142   mvme_get_dmode(mvme, &cmode);
00143   mvme_set_dmode(mvme, MVME_DMODE_D16);
00144   count = mvme_read_value(mvme, base+LRS1190_COUNT_RO);
00145   mvme_set_dmode(mvme, MVME_DMODE_D32);
00146   if (r > count) r = count;
00147   while (r > 0) {
00148     local = mvme_read_value(mvme, base+LRS1190_DATA_RO);
00149     *data = *((WORD *)(&local)+1);
00150     data++;
00151     r--;
00152   }
00153   mvme_set_dmode(mvme, cmode);
00154   return count;
00155 }
00156 
00157 /*****************************************************************/
00158 /*-PAA- For test purpose only */
00159 #ifdef MAIN_ENABLE
00160 int main (int argc, char* argv[]) {
00161   DWORD localbuf[1000], data[1000];
00162   int status, count, newcount, i;
00163   DWORD LRS1190_BASE = 0x780000;
00164 
00165   MVME_INTERFACE *myvme;
00166 
00167   if (argc>1) {
00168     sscanf(argv[1],"%lx",&LRS1190_BASE);
00169   }
00170 
00171   // Test under vmic
00172   status = mvme_open(&myvme, 0);
00173 
00174   // Set am to A24 non-privileged Data
00175   mvme_set_am(myvme, MVME_AM_A24_ND);
00176 
00177   // Set dmode to D32
00178   mvme_set_dmode(myvme, MVME_DMODE_D32);
00179 
00180   printf("\nReset \n");
00181   
00182   while(1) {
00183     //  lrs1190_Reset(myvme, LRS1190_BASE);
00184   // Test Enable/Disable
00185     usleep(100000);
00186     printf("Enable \n");
00187     //    lrs1190_Enable(myvme, LRS1190_BASE);
00188     usleep(1000000);
00189     printf("Disable \n");
00190     //    lrs1190_Disable(myvme, LRS1190_BASE);
00191     usleep(100000);
00192     count = lrs1190_CountRead(myvme, LRS1190_BASE);
00193     printf("Count : 0x%x\n", count);
00194 
00195 #if 0
00196     if (count > 1000) count = 1000;
00197     if (count > 0) {
00198       if (count == 1) {
00199         lrs1190_I4Read(myvme, LRS1190_BASE, &(data[0]), count);
00200       } else {
00201         lrs1190_I4Read(myvme, LRS1190_BASE, &(localbuf[0]), count);
00202         data[0] = localbuf[0];
00203         newcount = 1;
00204         for (i=1;i<count;i++) {
00205           if (localbuf[i] != localbuf[i-1]) {
00206             data[i] = localbuf[i];
00207             newcount += 1;
00208           }
00209         }
00210       }
00211       for (i=0;i<newcount;i++) {
00212         printf("Data[%i]=0x%x\n", i, data[i]);
00213       }
00214     }
00215 #endif
00216 #if 1
00217     if (count > 1000) count = 1000;
00218     lrs1190_I4Read(myvme, LRS1190_BASE, data, count);
00219     for (i=0;i<count;i++) {
00220       printf("Data[%i]=0x%x\n", i, data[i]);
00221     }
00222 #endif
00223 
00224     }
00225   status = mvme_close(myvme);
00226   return 1;
00227 }
00228 #endif
00229 
00230 /* emacs
00231  * Local Variables:
00232  * mode:C
00233  * mode:font-lock
00234  * tab-width: 8
00235  * c-basic-offset: 2
00236  * End:
00237  */
00238 

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