Subversion Repositories f9daq

Rev

Rev 5 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "CAENV965.h"
  4. #include "CAENV965_DEF.h"
  5. #include "vme.h"
  6.  
  7. static unsigned long ModuleAddress[10];
  8.  
  9. int _VI_FUNC V965_map (int ModuleNumber, unsigned long ModuleOffset, int print)
  10. {
  11.   int i;
  12.   unsigned short geo, fw, ah, al;
  13.         if (print) {
  14.                 printf("CAEN V965_map \n");
  15.         }
  16.   ModuleAddress[ModuleNumber] = ModuleOffset;
  17.   VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_FW, &fw);
  18.   geo = 0;
  19.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_CRN, &geo);
  20.   for (i=0;i<32;i++)
  21.     VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_THM + 2*i, &geo);
  22.   geo = ModuleNumber+1;
  23.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
  24.   geo = 0;
  25.   VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
  26.   VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADH, &ah);
  27.   VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADL, &al);
  28.   if (print) {
  29.     printf("CAEN V965 offset = 0x%08x\n", ModuleOffset);
  30.     printf(" V965_map firmware = %d.%d\n", (fw>>8)&0xff, fw&0xff);
  31.     printf(" V965_map geo      = %d\n", geo&0x1f );
  32.     printf(" V965_map addr       = 0x%04X0000\n", (ah<<8)|(al&0xff));
  33.   }
  34.  
  35.   return 0;
  36. }
  37.  
  38.  
  39. int _VI_FUNC V965_init (int ModuleNumber, unsigned short ped)
  40. {
  41.   unsigned short dum16;
  42.  
  43.   dum16= 0x80;
  44.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS1, &dum16);
  45.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC1, &dum16);
  46.   dum16= ped;
  47.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_PED, &dum16);
  48.   dum16= 0x5000;
  49.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
  50.   dum16= 0x4;
  51.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
  52.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16);
  53.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_ECR, &dum16);
  54.  
  55.   printf ( " V965_init Module %d initialized!\n", ModuleNumber ) ;
  56.   return 0;
  57. }
  58.  
  59. int _VI_FUNC V965_clear (int ModuleNumber)
  60. {
  61.  
  62.   unsigned short dum16;
  63.  
  64.   dum16= 0x4;
  65.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
  66.   VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16);
  67.   printf("V965_clear\n");
  68.   return 0;
  69.  
  70. }
  71.  
  72. int _VI_FUNC V965_status (int ModuleNumber)
  73. {
  74.   unsigned short dum16;
  75.  
  76.   VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR1, &dum16);
  77.   //printf("*%d\n",dum16);
  78.   return (int)dum16;
  79. }
  80.  
  81. int _VI_FUNC V965_status2 (int ModuleNumber)
  82. {
  83.  
  84.   unsigned short dum16;
  85.  
  86.   VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR2, &dum16);
  87.  
  88.   return (int)dum16;
  89. }
  90.  
  91. int _VI_FUNC V965_read (int ModuleNumber, unsigned long whereto[],int len)
  92. {
  93.   int status, ndata, i;
  94.  
  95.   ndata = 0;
  96.  
  97.   do {
  98.     if (ndata>=len) {
  99.           printf("ERROR V965_read: Increase storage size: ndata=%d\n",ndata);
  100.           break;
  101.     }
  102.     VME_A24D32_R(ModuleAddress[ModuleNumber] + CAENV965_OB, &whereto[ndata]);
  103.     i=(whereto[ndata]>>25)&0x3;
  104.     if (i<3) ndata++;
  105.   } while (i<2);
  106.   return ndata;  
  107. }
  108.