Subversion Repositories f9daq

Rev

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

#include <ansi_c.h>
#include "CAENV288.h"
#include "CAENV288_DEF.h"


#include "vme.h"
#include <utility.h>

static unsigned long ModuleAddress[10];
static float timeout = 0.01;

void _VI_FUNC  V288_Map (int ModuleNumber, unsigned long ModuleOffset)
{
  ModuleAddress[ModuleNumber] = ModuleOffset;

  return;
}

void _VI_FUNC  V288_Reset(int ModuleNumber)
{    
  uint32_t ultmp=0;

  VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_RST, ultmp);

  return;
};

void _VI_FUNC  V288_Init (int ModuleNumber)
{
  V288_Reset(ModuleNumber);

  return;
}    
 
int _VI_FUNC V288_Send (int ModuleNumber,int slaveid,int nbuf,unsigned short *buf)
{
  int i;
  uint32_t ultmp,ulstat;
   
  ultmp=0x00000001;
  while (1){
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, ultmp);
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
    if (ulstat & 1) Delay(0.1); else break;
  }

  ultmp=slaveid;
  while (1){
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, ultmp);
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
    if (ulstat & 1) Delay(0.1); else break;
  }

  for (i=0;i<nbuf;i++){
    ultmp=buf[i];
    while (1){
      VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, ultmp);
      VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
      if (ulstat & 1) Delay(0.1); else break;
    }
  }

  while (1){
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_TX, ultmp);
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
    if (ulstat & 1) Delay(0.1); else break;
  }

  return 0;
}  

int _VI_FUNC V288_Receive(int ModuleNumber,int nbuf,unsigned short *buf)
{
  int i;
  uint32_t ecode,ulstat;
   
  while (1){
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_BUF, &ecode);
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
    if (ulstat & 1) Delay(0.1); else break;
  }
  if (ecode) return 1;

  i=0;
  while (i<nbuf){
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_BUF, &ecode);
    buf[i]=(unsigned short) ecode;
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
    if (ulstat & 1) break;
    i++;
  }

  return i;
}