sis3320.c

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         sis3320.c
00004   Created by:   K.Olchanski
00005 
00006   Contents:     SIS3320 8 ch. 12bit 250Msps
00007                 
00008   $Log$
00009   Revision 1.1  2006/05/25 05:53:42  alpha
00010   First commit
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 Read sis3320 register value
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 Write sis3320 register value
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 Sets all the necessary paramters for a given configuration.
00074 The configuration is provided by the mode argument.
00075 Add your own configuration in the case statement. Let me know
00076 your setting if you want to include it in the distribution.
00077 @param *mvme VME structure
00078 @param  base Module base address
00079 @param mode  Configuration mode number
00080 @param *nentry number of entries requested and returned.
00081 @return MVME_SUCCESS
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);  // 0x200 or 512
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);  // 0x200 or 512
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 /*-PAA- For test purpose only */
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   // Test under vmic
00147   status = mvme_open(&myvme, 0);
00148 
00149   sis3320_Setup(myvme, SIS3320_BASE, 1);
00150 
00151   //  regWrite(myvme, SIS3320_BASE, SIS3320_START_DELAY, 0x20); // PreTrigger
00152     regWrite(myvme, SIS3320_BASE, SIS3320_STOP_DELAY, 0x80); // PostTrigger
00153 
00154   regWrite(myvme, SIS3320_BASE, SIS3320_KEY_ARM, 0x0);  // Arm Sampling
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     //    printf("Armed:%x\n", armed);
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   //  regWrite(myvme, SIS3320_BASE, SIS3320_KEY_DISARM, 0x0);  // DisArm Sampling
00170   
00171   status = mvme_close(myvme);
00172 
00173   return 1;
00174 
00175 }
00176 #endif
00177 
00178 /* emacs
00179  * Local Variables:
00180  * mode:C
00181  * mode:font-lock
00182  * tab-width: 8
00183  * c-basic-offset: 2
00184  * End:
00185  */
00186 
00187 //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