00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <stdio.h>
00014 #include <stdint.h>
00015 #include <string.h>
00016 #include "sis3320drv.h"
00017 #include "sis3320.h"
00018 #include "mvmestd.h"
00019
00020
00021
00022
00023
00024 static uint32_t regRead(MVME_INTERFACE *mvme, uint32_t base, int offset)
00025 {
00026 mvme_set_am(mvme, MVME_AM_A32);
00027 mvme_set_dmode(mvme, MVME_DMODE_D32);
00028 return mvme_read_value(mvme, base + offset);
00029 }
00030
00031
00032
00033
00034
00035 static void regWrite(MVME_INTERFACE *mvme, uint32_t base, int offset, uint32_t value)
00036 {
00037 mvme_set_am(mvme, MVME_AM_A32);
00038 mvme_set_dmode(mvme, MVME_DMODE_D32);
00039 mvme_write_value(mvme, base + offset, value);
00040 }
00041
00042
00043 uint32_t sis3320_RegisterRead(MVME_INTERFACE *mvme, uint32_t base, int offset)
00044 {
00045 return regRead(mvme,base,offset);
00046 }
00047
00048
00049 void sis3320_RegisterWrite(MVME_INTERFACE *mvme, uint32_t base, int offset, uint32_t value)
00050 {
00051 regWrite(mvme, base, offset, value);
00052 }
00053
00054
00055 void sis3320_Reset(MVME_INTERFACE *mvme, uint32_t base)
00056 {
00057 regWrite(mvme, base, SIS3320_KEY_RESET, 0);
00058 }
00059
00060
00061 void sis3320_Status(MVME_INTERFACE *mvme, uint32_t base)
00062 {
00063 printf("================================================\n");
00064 printf("SIS3320 at A32 0x%x\n", (int)base);
00065 printf("CSR : 0x%8.8x\n", regRead(mvme, base, SIS3320_CONTROL_STATUS));
00066 printf("ModuleID and Firmware: 0x%x\n", regRead(mvme, base, SIS3320_MODID));
00067 printf("Max Event Counter : %d\n", regRead(mvme, base, SIS3320_MAX_NOF_EVENT));
00068 printf("================================================\n");
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 int sis3320_Setup(MVME_INTERFACE *mvme, uint32_t base, int mode)
00084 {
00085 switch (mode) {
00086 case 0x1:
00087 printf("--------------------------------------------\n");
00088 printf("200Msps 1evt (mode:%d)\n", mode);
00089 printf("Sample Length Stop, Sample Length 256\n");
00090 printf("Sample Start Address 0x0\n");
00091 printf("ADC input mode 32bits\n");
00092 printf("Trigger from LEMO\n");
00093 printf("--------------------------------------------\n");
00094
00095 regWrite(mvme, base, SIS3320_MAX_NOF_EVENT, 1);
00096 regWrite(mvme, base, SIS3320_EVENT_CONFIG_ALL_ADC, EVENT_CONF_ENABLE_SAMPLE_LENGTH_STOP);
00097 regWrite(mvme, base, SIS3320_SAMPLE_LENGTH_ALL_ADC, 0x1FC);
00098 regWrite(mvme, base, SIS3320_SAMPLE_START_ADDRESS_ALL_ADC, 0x0);
00099 regWrite(mvme, base, SIS3320_ADC_INPUT_MODE_ALL_ADC, 0x20000);
00100 regWrite(mvme, base, SIS3320_ACQUISTION_CONTROL
00101 , SIS3320_ACQ_SET_CLOCK_TO_200MHZ | SIS3320_ACQ_ENABLE_LEMO_START_STOP);
00102 printf("\n");
00103 break;
00104 case 0x2:
00105 printf("--------------------------------------------\n");
00106 printf("50Msps 1evt (mode:%d)\n", mode);
00107 printf("Sample Length Stop, Sample Length 256\n");
00108 printf("Sample Start Address 0x0\n");
00109 printf("ADC input mode 32bits\n");
00110 printf("Trigger from LEMO\n");
00111 printf("--------------------------------------------\n");
00112
00113 regWrite(mvme, base, SIS3320_MAX_NOF_EVENT, 1);
00114 regWrite(mvme, base, SIS3320_EVENT_CONFIG_ALL_ADC, EVENT_CONF_ENABLE_SAMPLE_LENGTH_STOP);
00115 regWrite(mvme, base, SIS3320_SAMPLE_LENGTH_ALL_ADC, 0x1FC);
00116 regWrite(mvme, base, SIS3320_SAMPLE_START_ADDRESS_ALL_ADC, 0x0);
00117 regWrite(mvme, base, SIS3320_ADC_INPUT_MODE_ALL_ADC, 0x20000);
00118 regWrite(mvme, base, SIS3320_ACQUISTION_CONTROL
00119 , SIS3320_ACQ_SET_CLOCK_TO_50MHZ | SIS3320_ACQ_ENABLE_LEMO_START_STOP);
00120 printf("\n");
00121 break;
00122 default:
00123 printf("Unknown setup mode\n");
00124 return -1;
00125 }
00126 sis3320_Status(mvme, base);
00127 return 0;
00128 }
00129
00130
00131
00132 #ifdef MAIN_ENABLE
00133 int main (int argc, char* argv[]) {
00134
00135 DWORD SIS3320_BASE = 0x30000000;
00136
00137 MVME_INTERFACE *myvme;
00138
00139 uint32_t data, armed;
00140 int status, i;
00141
00142 if (argc>1) {
00143 sscanf(argv[1],"%lx",&SIS3320_BASE);
00144 }
00145
00146
00147 status = mvme_open(&myvme, 0);
00148
00149 sis3320_Setup(myvme, SIS3320_BASE, 1);
00150
00151
00152 regWrite(myvme, SIS3320_BASE, SIS3320_STOP_DELAY, 0x80);
00153
00154 regWrite(myvme, SIS3320_BASE, SIS3320_KEY_ARM, 0x0);
00155
00156 armed = regRead(myvme, SIS3320_BASE, SIS3320_ACQUISTION_CONTROL);
00157 armed &= 0x10000;
00158 printf("Armed:%x\n", armed);
00159 while (armed) {
00160 armed = regRead(myvme, SIS3320_BASE, SIS3320_ACQUISTION_CONTROL);
00161 armed &= 0x10000;
00162
00163 };
00164
00165 for (i=0;i<256;i++) {
00166 data = regRead(myvme, SIS3320_BASE, SIS3320_ADC1_OFFSET + (i<<2));
00167 printf("Data[0x%8.8x]=0x%x\n", SIS3320_BASE+SIS3320_ADC1_OFFSET+(i<<2), data);
00168 }
00169
00170
00171 status = mvme_close(myvme);
00172
00173 return 1;
00174
00175 }
00176 #endif
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187