AlcapDAQ  1
Functions
VME Functions (mvme_xxx)

Functions

int EXPRT mvme_open (MVME_INTERFACE **vme, int idx)
 
int EXPRT mvme_close (MVME_INTERFACE *vme)
 
int EXPRT mvme_sysreset (MVME_INTERFACE *vme)
 
int EXPRT mvme_read (MVME_INTERFACE *vme, void *dst, mvme_addr_t vme_addr, mvme_size_t n_bytes)
 
unsigned int EXPRT mvme_read_value (MVME_INTERFACE *vme, mvme_addr_t vme_addr)
 
int EXPRT mvme_write (MVME_INTERFACE *vme, mvme_addr_t vme_addr, void *src, mvme_size_t n_bytes)
 
int EXPRT mvme_write_value (MVME_INTERFACE *vme, mvme_addr_t vme_addr, unsigned int value)
 
int EXPRT mvme_set_am (MVME_INTERFACE *vme, int am)
 
int EXPRT mvme_get_am (MVME_INTERFACE *vme, int *am)
 
int EXPRT mvme_set_dmode (MVME_INTERFACE *vme, int dmode)
 
int EXPRT mvme_get_dmode (MVME_INTERFACE *vme, int *dmode)
 
int EXPRT mvme_set_blt (MVME_INTERFACE *vme, int mode)
 
int EXPRT mvme_get_blt (MVME_INTERFACE *vme, int *mode)
 
int EXPRT mvme_interrupt_generate (MVME_INTERFACE *mvme, int level, int vector, void *info)
 
int EXPRT mvme_interrupt_attach (MVME_INTERFACE *mvme, int level, int vector, void(*isr)(int, void *, void *), void *info)
 
int EXPRT mvme_interrupt_detach (MVME_INTERFACE *mvme, int level, int vector, void *info)
 
int EXPRT mvme_interrupt_enable (MVME_INTERFACE *mvme, int level, int vector, void *info)
 
int EXPRT mvme_interrupt_disable (MVME_INTERFACE *mvme, int level, int vector, void *info)
 

Detailed Description

dox

Function Documentation

int EXPRT mvme_close ( MVME_INTERFACE vme)

Close and release ALL the opened VME channel. See example in mvme_open()

Parameters
*vmeVME structure.
Returns
MVME_SUCCESS, MVME_ACCESS_ERROR

Definition at line 45 of file bt617.c.

References MVME_INTERFACE::handle, and MVME_SUCCESS.

46 {
47  close(vme->handle);
48  return MVME_SUCCESS;
49 }
int EXPRT mvme_get_am ( MVME_INTERFACE vme,
int *  am 
)

Get Address Modifier.

Parameters
*vmeVME structure
*amreturned address modifier
Returns
MVME_SUCCESS

Definition at line 116 of file bt617.c.

References MVME_INTERFACE::am.

117 {
118  *am = vme->am;
119  return 0;
120 }
int EXPRT mvme_get_blt ( MVME_INTERFACE vme,
int *  mode 
)

Get current Data mode.

Parameters
*vmeVME structure
*modereturned BLT mode
Returns
MVME_SUCCESS

Definition at line 143 of file bt617.c.

References MVME_INTERFACE::blt_mode.

144 {
145  *mode = vme->blt_mode;
146  return 0;
147 }
int EXPRT mvme_get_dmode ( MVME_INTERFACE vme,
int *  dmode 
)
int EXPRT mvme_interrupt_attach ( MVME_INTERFACE mvme,
int  level,
int  vector,
void(*)(int, void *, void *)  isr,
void *  info 
)
int EXPRT mvme_interrupt_detach ( MVME_INTERFACE mvme,
int  level,
int  vector,
void *  info 
)
int EXPRT mvme_interrupt_disable ( MVME_INTERFACE mvme,
int  level,
int  vector,
void *  info 
)
int EXPRT mvme_interrupt_enable ( MVME_INTERFACE mvme,
int  level,
int  vector,
void *  info 
)
int EXPRT mvme_interrupt_generate ( MVME_INTERFACE mvme,
int  level,
int  vector,
void *  info 
)
int EXPRT mvme_open ( MVME_INTERFACE **  vme,
int  idx 
)
VME open

The code below summarize the use of most of the mvme calls included in this interface.

#include "vmicvme.h" // or other VME interface driver.
int main () {
int i, status, vmeio_status, data;
// Open VME channel
status = mvme_open(&myvme, 0);
// Reset VME
// Under VMIC reboot CPU!!
// status = mvme_sysreset(myvme);
// Setup AM
status = mvme_set_am(myvme, MVME_AM_A24_ND);
// Setup Data size
status = mvme_set_dmode(myvme, MVME_DMODE_D32);
// Read VMEIO status
status = mvme_read(myvme, &vmeio_status, 0x78001C, 4);
printf("VMEIO status : 0x%x\n", vmeio_status);
// Write Single value
mvme_write_value(myvme, 0x780010, 0x3);
// Read Single Value
printf("Value : 0x%x\n", mvme_read_value(myvme, 0x780018));
// Write to the VMEIO in latch mode
for (i=0;i<10000;i++) {
data = 0xF;
status = mvme_write(myvme, 0x780010, &data, 4);
data = 0x0;
status = mvme_write(myvme, 0x780010, &data, 4);
}
// Close VME channel
status = mvme_close(myvme);
return 1;
}
Parameters
**vmeuser VME pointer to the interface
indexinterface number should be used to distingush multiple VME interface access within the same program.
Returns
status MVME_SUCCESS, MVME_NO_INTERFACE, MVME_INVALID_PARAM, MVME_ACCESS_ERROR

Definition at line 19 of file bt617.c.

References bt617_SetAccessMode(), DEV_FILE, MVME_AM_A32_ND, MVME_BLT_NONE, MVME_DMODE_D32, MVME_NO_MEM, and MVME_SUCCESS.

Referenced by rpv130_init().

20 {
21  *vme = (MVME_INTERFACE *) malloc(sizeof(MVME_INTERFACE));
22  if (*vme == NULL)
23  return MVME_NO_MEM;
24  memset(*vme, 0, sizeof(MVME_INTERFACE));
25 
26  int fd;
27  if ((fd = open(DEV_FILE, O_RDWR))<0)
28  {
29  perror("ERROR: fd open()");
30  exit(EXIT_FAILURE);
31  }
32 
33  (*vme)->handle = fd;
34  (*vme)->am = MVME_AM_A32_ND;
35  (*vme)->dmode = MVME_DMODE_D32;
36  (*vme)->initialized = 1;
37  bt617_SetAccessMode(*vme);
38 
39  (*vme)->blt_mode = MVME_BLT_NONE;
40  (*vme)->table = NULL;
41 
42  return MVME_SUCCESS;
43 }
int EXPRT mvme_read ( MVME_INTERFACE vme,
void *  dst,
mvme_addr_t  vme_addr,
mvme_size_t  n_bytes 
)

Read from VME bus. Implementation of the read can include automatic DMA transfer based on the size of the data. See example in mvme_open()

Parameters
*vmeVME structure
*dstdestination pointer
vme_addrsource address (VME location).
n_bytesrequested transfer size.
Returns
MVME_SUCCESS

Definition at line 155 of file bt617.c.

References MVME_INTERFACE::handle, and printf().

Referenced by mvme_read_value(), and v1290_DataRead().

157 {
158  int read_size;
159  if(lseek(vme->handle,vme_addr,SEEK_SET) == -1)
160  {
161  printf("lseek err\n");
162  return -1;
163  }
164  read_size = read(vme->handle,dst,n_bytes);
165 
166  if (read_size < 0)
167  {
168  printf("read err\n");
169  return -1;
170  }
171  else
172  return read_size;
173 }
unsigned int EXPRT mvme_read_value ( MVME_INTERFACE vme,
mvme_addr_t  vme_addr 
)

Read single data from VME bus. Useful for register access. See example in mvme_open()

Parameters
*vmeVME structure
vme_addrsource address (VME location).
Returns
MVME_SUCCESS

Definition at line 193 of file bt617.c.

References MVME_INTERFACE::dmode, MVME_DMODE_D16, MVME_DMODE_D32, mvme_read(), and value.

Referenced by rpv130_IsBusy1(), rpv130_IsBusy2(), rpv130_IsBusy3(), v1290_MicroRead(), v1290_MicroWrite(), v1290_Read16(), and v1290_Read32().

194 {
195  int read_size,nbytes;
196  unsigned int value;
197  switch (vme->dmode)
198  {
199  case MVME_DMODE_D32:
200  nbytes = 4;
201  break;
202  case MVME_DMODE_D16:
203  nbytes = 2;
204  break;
205  default:
206  nbytes = 4;
207  break;
208  }
209  read_size = mvme_read(vme,&value,vme_addr,nbytes);
210  return value;
211 }
int EXPRT mvme_set_am ( MVME_INTERFACE vme,
int  am 
)

Set Address Modifier.

Parameters
*vmeVME structure
amaddress modifier
Returns
MVME_SUCCESS

Definition at line 109 of file bt617.c.

References MVME_INTERFACE::am, and bt617_SetAccessMode().

Referenced by rpv130_Clear(), rpv130_ClearBusy1(), rpv130_ClearBusy2(), rpv130_ClearBusy3(), rpv130_IsBusy1(), rpv130_IsBusy2(), rpv130_IsBusy3(), rpv130_Pulse(), v1290_DataRead(), v1290_MicroRead(), v1290_MicroWrite(), v1290_Read16(), v1290_Read32(), and v1290_Write16().

110 {
111  vme->am = am;
112  bt617_SetAccessMode(vme);
113  return 0;
114 }
int EXPRT mvme_set_blt ( MVME_INTERFACE vme,
int  mode 
)

Set Block Transfer mode.

Parameters
*vmeVME structure
modeBLT mode
Returns
MVME_SUCCESS

Definition at line 129 of file bt617.c.

References MVME_INTERFACE::blt_mode, bt617_SetBLT(), and MVME_BLT_NONE.

Referenced by v1290_DataRead().

130 {
131  vme->blt_mode = mode;
132  if (mode == MVME_BLT_NONE)
133  {
134  bt617_SetBLT(vme, false);
135  }
136  else
137  {
138  bt617_SetBLT(vme, true);
139  }
140  return 0;
141 }
int EXPRT mvme_set_dmode ( MVME_INTERFACE vme,
int  dmode 
)
int EXPRT mvme_sysreset ( MVME_INTERFACE vme)

VME bus reset. Effect of the VME bus reset is dependent of the type of VME interface used. See example in mvme_open()

Parameters
*vmeVME structure.
Returns
MVME_SUCCESS, MVME_ACCESS_ERROR
int EXPRT mvme_write ( MVME_INTERFACE vme,
mvme_addr_t  vme_addr,
void *  src,
mvme_size_t  n_bytes 
)

Write data to VME bus. Implementation of the write can include automatic DMA transfer based on the size of the data. See example in mvme_open()

Parameters
*vmeVME structure
vme_addrsource address (VME location).
*srcsource array
n_bytessize of the array in bytes
Returns
MVME_SUCCESS

Definition at line 175 of file bt617.c.

References MVME_INTERFACE::handle, and printf().

Referenced by mvme_write_value().

176 {
177  int write_size;
178  if(lseek(vme->handle,vme_addr,SEEK_SET) == -1)
179  {
180  printf("lseek err\n");
181  return -1;
182  }
183  write_size = write(vme->handle,src,n_bytes);
184  if (write_size < 0)
185  {
186  printf("write err\n");
187  return -1;
188  }
189  else
190  return write_size;
191 }
int EXPRT mvme_write_value ( MVME_INTERFACE vme,
mvme_addr_t  vme_addr,
unsigned int  value 
)

Write single data to VME bus. Useful for register access. See example in mvme_open()

Parameters
*vmeVME structure
vme_addrsource address (VME location).
valueValue to be written to the VME bus
Returns
MVME_SUCCESS

Definition at line 213 of file bt617.c.

References MVME_INTERFACE::dmode, MVME_DMODE_D16, MVME_DMODE_D32, mvme_write(), and printf().

Referenced by rpv130_Clear(), rpv130_ClearBusy1(), rpv130_ClearBusy2(), rpv130_ClearBusy3(), rpv130_Pulse(), v1290_MicroWrite(), and v1290_Write16().

214 {
215  int write_size,nbytes;
216  switch (vme->dmode)
217  {
218  case MVME_DMODE_D32:
219  nbytes = 4;
220  break;
221  case MVME_DMODE_D16:
222  nbytes = 2;
223  break;
224  default:
225  nbytes = 4;
226  break;
227  }
228  write_size = mvme_write(vme,vme_addr,&value,nbytes);
229  if (write_size < 0)
230  {
231  printf("write_value err \n");
232  return -1;
233  }
234  else
235  return 0;
236 }