00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <stdint.h>
00016 #include <string.h>
00017 #include "sis3820drv.h"
00018 #include "sis3820.h"
00019 #include "mvmestd.h"
00020
00021
00022
00023
00024
00025 static uint32_t regRead(MVME_INTERFACE *mvme, DWORD base, int offset)
00026 {
00027 mvme_set_am(mvme, MVME_AM_A32);
00028 mvme_set_dmode(mvme, MVME_DMODE_D32);
00029 return mvme_read_value(mvme, base + offset);
00030 }
00031
00032
00033
00034
00035
00036 static void regWrite(MVME_INTERFACE *mvme, DWORD base, int offset, uint32_t value)
00037 {
00038 mvme_set_am(mvme, MVME_AM_A32);
00039 mvme_set_dmode(mvme, MVME_DMODE_D32);
00040 mvme_write_value(mvme, base + offset, value);
00041 }
00042
00043
00044 uint32_t sis3820_RegisterRead(MVME_INTERFACE *mvme, DWORD base, int offset)
00045 {
00046 return regRead(mvme, base, offset);
00047 }
00048
00049
00050 void sis3820_RegisterWrite(MVME_INTERFACE *mvme, DWORD base, int offset, uint32_t value)
00051 {
00052 regWrite(mvme,base,offset,value);
00053 }
00054
00055
00056 uint32_t sis3820_ScalerRead(MVME_INTERFACE *mvme, DWORD base, int ch)
00057 {
00058 if (ch == 0)
00059 return regRead(mvme, base, SIS3820_COUNTER_CH1+ch*4);
00060 else
00061 return regRead(mvme, base, SIS3820_COUNTER_SHADOW_CH1+ch*4);
00062 }
00063
00064
00065
00066
00067
00068
00069 int sis3820_FifoRead(MVME_INTERFACE *mvme, DWORD base, void *pdest, int wcount)
00070 {
00071 int rd;
00072 int save_am;
00073
00074 mvme_get_am(mvme,&save_am);
00075 mvme_set_blt( mvme, MVME_BLT_MBLT64);
00076 mvme_set_am( mvme, MVME_AM_A32_D64);
00077
00078 rd = mvme_read(mvme, pdest, base + SIS3820_FIFO_BASE, wcount*4);
00079
00080 mvme_set_am(mvme, save_am);
00081
00082
00083 return wcount;
00084 }
00085
00086
00087 void sis3820_Reset(MVME_INTERFACE *mvme, DWORD base)
00088 {
00089 regWrite(mvme,base,SIS3820_KEY_RESET,0);
00090 }
00091
00092
00093 int sis3820_DataReady(MVME_INTERFACE *mvme, DWORD base)
00094 {
00095 return regRead(mvme,base,SIS3820_FIFO_WORDCOUNTER);
00096 }
00097
00098
00099 void sis3820_Status(MVME_INTERFACE *mvme, DWORD base)
00100 {
00101 printf("SIS3820 at A32 0x%x\n", (int)base);
00102 printf("ModuleID and Firmware: 0x%x\n", regRead(mvme,base,SIS3820_MODID));
00103 printf("CSR: 0x%x\n", regRead(mvme,base,SIS3820_CONTROL_STATUS));
00104 printf("Operation mode: 0x%x\n", regRead(mvme,base,SIS3820_OPERATION_MODE));
00105 printf("Inhibit/Count disable: 0x%x\n", regRead(mvme, base, SIS3820_COUNTER_INHIBIT));
00106 printf("Counter Overflow: 0x%x\n", regRead(mvme, base, SIS3820_COUNTER_OVERFLOW));
00107 }
00108
00109
00110
00111 #ifdef MAIN_ENABLE
00112 int main (int argc, char* argv[]) {
00113 int i;
00114 uint32_t SIS3820_BASE = 0x38000000;
00115 uint32_t dest[32], scaler;
00116 MVME_INTERFACE *myvme;
00117 int status;
00118
00119 if (argc>1) {
00120 sscanf(argv[1],"%x", &SIS3820_BASE);
00121 }
00122
00123
00124 status = mvme_open(&myvme, 0);
00125
00126 regWrite(myvme, SIS3820_BASE, SIS3820_OPERATION_MODE, 0x1);
00127
00128 regWrite(myvme, SIS3820_BASE, SIS3820_CONTROL_STATUS, 0x00);
00129 sis3820_Reset(myvme, SIS3820_BASE);
00130 for (i=0;i<8;i++) {
00131 scaler = sis3820_ScalerRead(myvme, SIS3820_BASE, i);
00132 printf("scaler[%i] = %d\n", i, scaler);
00133 }
00134 regWrite(myvme, SIS3820_BASE, SIS3820_KEY_OPERATION_ENABLE, 0x00);
00135 sleep(10);
00136 regWrite(myvme, SIS3820_BASE, SIS3820_KEY_OPERATION_DISABLE, 0x00);
00137 sis3820_Status(myvme, SIS3820_BASE);
00138
00139
00140
00141 for (i=0;i<8;i++) {
00142 scaler = sis3820_ScalerRead(myvme, SIS3820_BASE, i);
00143 printf("scaler[%i] = %d\n", i, scaler);
00144 }
00145 return 1;
00146
00147 }
00148 #endif
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159