AlcapDAQ  1
Data Structures | Functions | Variables
dl40x.cpp File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include "midas.h"
#include "crate.h"
#include "vme.h"
#include "dl40x.h"
#include "diag.h"
#include "odb_wrapper.h"

Go to the source code of this file.

Data Structures

struct  dl401
 
struct  dl403
 

Functions

INT dl40x_bor ()
 
INT dl40x_eor ()
 
INT dl40x_read (char *pevent)
 
INT dl401_bor1 (struct dl401 *d)
 
INLINE int dl401_setPedestals (struct dl401 *d, u_short p[], int np)
 
INLINE u_short dl401_getCounts (struct dl401 *d)
 
INLINE u_short dl401_getMode (struct dl401 *d)
 
INLINE void dl401_reset (struct dl401 *d)
 
INLINE void dl401_clear (struct dl401 *d)
 
INLINE void dl401_convert (struct dl401 *d)
 
INLINE int dl401_finished (struct dl401 *d)
 
int dl401_read (struct dl401 *d, u_int *data)
 
INT dl403_init (struct dl403 *d)
 
void dl403_setClockRate (struct dl403 *d, u_short clk1, u_short clk2, u_short clk3)
 
void dl403_setClockCycle (struct dl403 *d, u_short c1, u_short c2, u_short c3)
 
INLINE short dl403_getMode (struct dl403 *d)
 
INLINE void dl403_asyncMode (struct dl403 *d)
 
INLINE void dl403_contMode (struct dl403 *d)
 
INLINE void dl403_steadyMode (struct dl403 *d)
 
INLINE void dl403_start (struct dl403 *d)
 
INLINE void dl403_stop (struct dl403 *d)
 
INLINE void dl403_reset (struct dl403 *d)
 
INLINE short dl403_runBit (struct dl403 *d)
 
INLINE short dl403_running (struct dl403 *d)
 

Variables

struct readout_module dl40x_module
 
static struct dl401 DL401 [DL401_MAXMODULES]
 
static struct dl403 clk
 

Function Documentation

INT dl401_bor1 ( struct dl401 d)
INLINE void dl401_clear ( struct dl401 d)

Definition at line 280 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, DL401_CLIF, and vme_write_d16().

281 {
282  vme_write_d16 (d->a16_handle, d->a16_base | DL401_CLIF, 0xffff);
283 }
INLINE void dl401_convert ( struct dl401 d)

Definition at line 286 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, DL401_ICNV, and vme_read_d16().

287 {
289 }
INLINE int dl401_finished ( struct dl401 d)

Definition at line 292 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, DL401_INTREQ, DL401_MODE, and vme_read_d16().

293 {
294  WORD mode = vme_read_d16 (d->a16_handle, d->a16_base | DL401_MODE);
295  return (mode & DL401_INTREQ);
296 }
INLINE u_short dl401_getCounts ( struct dl401 d)

Definition at line 261 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, DL401_CNTMASK, DL401_RMAD, and vme_read_d16().

262 {
263  WORD rmad = vme_read_d16 (d->a16_handle, d->a16_base | DL401_RMAD);
264  return rmad & DL401_CNTMASK;
265 }
INLINE u_short dl401_getMode ( struct dl401 d)

Definition at line 268 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, DL401_MODE, and vme_read_d16().

269 {
270  return vme_read_d16 (d->a16_handle, d->a16_base | DL401_MODE);
271 }
int dl401_read ( struct dl401 d,
u_int *  data 
)

Definition at line 300 of file dl40x.cpp.

References dl401::a32_base, dl401::a32_handle, diag_print(), DL401_CNTMAX, dl401_getCounts(), i, and vme_read_d32().

301 {
302  register u_int i = 0;
303  register u_int *addr;
304  int counts;
305 
306  counts = dl401_getCounts (d);
307  diag_print (2, "dl401_read: [%d] base=%p counts=%d\n", d, addr, counts);
308 
309  while (i < DL401_CNTMAX - counts)
310  {
311  data[i++] = vme_read_d32 (d->a32_handle, d->a32_base + (i + counts)*4);
312  }
313 
314  i = 0;
315  while (i < counts)
316  {
317  data[DL401_CNTMAX - counts + i] =
318  vme_read_d32 (d->a32_handle, d->a32_base + i*4);
319  i++;
320  }
321  diag_print (2, "--> done\n");
322  return (DL401_CNTMAX);
323 }
INLINE void dl401_reset ( struct dl401 d)

Definition at line 274 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, DL401_MRST, and vme_write_d16().

275 {
276  vme_write_d16 (d->a16_handle, d->a16_base | DL401_MRST, 0xffff);
277 }
INLINE int dl401_setPedestals ( struct dl401 d,
u_short  p[],
int  np 
)

Definition at line 226 of file dl40x.cpp.

References dl401::a16_base, dl401::a16_handle, diag_print(), DL401_DACWDIS, DL401_DACWENA, DL401_DEFMODE, DL401_MODE, DL401_NCHAN, DL401_PEDBITS, DL401_PEDCHANBITS, DL401_PEDCHANMASK, DL401_PEDMASK, DL401_WDAC, i, SUCCESS, and vme_write_d16().

227 {
228  if (np != DL401_NCHAN)
229  return (-1);
230 
231  // compute word to write to pedestal DAC
232  DWORD parPed = 0;
233  for (int i = 0; i < np; i++) {
234  parPed |= (u_long) (p[i] & DL401_PEDCHANMASK) << (i * DL401_PEDCHANBITS);
235  }
236  parPed &= DL401_PEDMASK;
237  diag_print (2, "dl401_setPedestal: [%d] 0%08lo (", d, parPed);
238 
239  // enable writing to DAC
242 
243  // shift bits into DAC one at a time; it's a serial interface
244  for (int i = 0; i < DL401_PEDBITS; i++)
245  {
246  u_short bit =
247  ((parPed << i) & DL401_PEDBITMASK) >> (DL401_PEDBITS - 1);
248  vme_write_d16 (d->a16_handle, d->a16_base | DL401_WDAC, bit & 0x0001);
249  diag_print (2, "%1x", bit);
250  }
251 
252  // disable writing to DAC
255  diag_print (2, ")\n");
256 
257  return SUCCESS;
258 }
INLINE void dl403_asyncMode ( struct dl403 d)

Definition at line 436 of file dl40x.cpp.

References dl403::a16_base, DL403_ASYNC, DL403_MODE, dl403::vme_handle, and vme_write_d16().

437 {
439 }
INLINE void dl403_contMode ( struct dl403 d)

Definition at line 442 of file dl40x.cpp.

References dl403::a16_base, DL403_CONT, DL403_MODE, dl403::vme_handle, and vme_write_d16().

443 {
445 }
INLINE short dl403_getMode ( struct dl403 d)

Definition at line 430 of file dl40x.cpp.

References dl403::a16_base, DL403_MODE, dl403::vme_handle, and vme_read_d16().

431 {
432  return vme_read_d16 (d->vme_handle, d->a16_base | DL403_MODE);
433 }
INT dl403_init ( struct dl403 d)

Definition at line 352 of file dl40x.cpp.

References dl403::a16_base, crate_number, diag_print(), DL403_100MHZ, DL403_50MHZ, DL403_SELECTED, dl403_setClockCycle(), dl403_setClockRate(), dl403_start(), dl403_steadyMode(), dl403::enabled, FALSE, frontend_name, odb_find_key(), odb_get_int(), odb_get_word(), SUCCESS, TRUE, dl403::vme_handle, vme_open(), VMEMAP_ASPACE_A16, VMEMAP_DWIDTH_32, VMEMAP_PRGDATAAM_DATA, and VMEMAP_SUPUSERAM_SUPER.

353 {
354  // Do we have an FADC clock?
355  if (odb_find_key("/Equipment/Crate %d/Settings/FADC CLOCK", crate_number)) {
356  d->enabled = TRUE;
357  } else {
358  d->enabled = FALSE;
359  return SUCCESS;
360  }
361 
362  // find base address
363  d->a16_base =
364  odb_get_word ("/Equipment/Crate %d/Settings/FADC CLOCK/a16 base address",
365  crate_number);
366 
367  // Open a VME handle
368  struct vme_mapping_ctrl a16_mapping = {
373  };
374  d->vme_handle = vme_open(d->a16_base, a16_mapping, 0x100, 0);
375 
376  // Set DL403 clock frequency
377  INT fadc_frequency =
378  odb_get_int ("/Equipment/Crate %d/Settings/FADC CLOCK/frequency", crate_number);
379  switch (fadc_frequency)
380  {
381  case 100:
382  dl403_setClockRate (d, DL403_100MHZ, 0x0, 0x0);
383  break;
384  case 50:
385  dl403_setClockRate (d, DL403_50MHZ, 0x0, 0x0);
386  break;
387  case 25:
388  dl403_setClockRate (d, DL403_SELECTED, 0x0, 0x0);
389  break;
390 
391  default:
392  cm_msg (MERROR, frontend_name,
393  "FADC clock frequency must be 25, 50, or 100 MHz (currently %d)\n",
394  fadc_frequency);
395  dl403_setClockRate (d, DL403_50MHZ, 0x0, 0x0);
396  }
397 
398  dl403_setClockCycle (d, 0x800, 0x800, 0x800);
399  dl403_steadyMode (d);
400  dl403_start (d);
401 
402  diag_print (2, "dl403_init 0x%08lx\n", d->a16_base);
403  return SUCCESS;
404 }
INLINE void dl403_reset ( struct dl403 d)

Definition at line 466 of file dl40x.cpp.

References dl403::a16_base, DL403_GO, DL403_RESET, dl403::vme_handle, and vme_write_d16().

467 {
469 }
INLINE short dl403_runBit ( struct dl403 d)

Definition at line 472 of file dl40x.cpp.

References dl403::a16_base, DL403_MODE, DL403_RUN, dl403::vme_handle, and vme_read_d16().

473 {
474  WORD mode = vme_read_d16 (d->vme_handle, d->a16_base | DL403_MODE);
475  return (mode & DL403_RUN);
476 }
INLINE short dl403_running ( struct dl403 d)

Definition at line 479 of file dl40x.cpp.

References dl403::a16_base, DL403_MODE, DL403_RUN, dl403::vme_handle, and vme_read_d16().

480 {
481  WORD mode = vme_read_d16 (d->vme_handle, d->a16_base | DL403_MODE);
482  return !(mode & DL403_RUN);
483 }
void dl403_setClockCycle ( struct dl403 d,
u_short  c1,
u_short  c2,
u_short  c3 
)

Definition at line 417 of file dl40x.cpp.

References dl403::a16_base, diag_print(), DL403_CYCLE1, DL403_CYCLE2, DL403_CYCLE3, dl403::vme_handle, and vme_write_d16().

418 {
422 
423  diag_print (2,
424  "dl403_setClockCycles: [%d] cyc1=0x%04hx cyc2=0x%04hx cyc3=0x%04hx\n",
425  d, c1, c2, c3);
426 
427 }
void dl403_setClockRate ( struct dl403 d,
u_short  clk1,
u_short  clk2,
u_short  clk3 
)

Definition at line 407 of file dl40x.cpp.

References dl403::a16_base, diag_print(), DL403_RATE, dl403::vme_handle, and vme_write_d16().

408 {
409  diag_print (2, "dl403_setClockRate: [%d] rate=0x%02hx\n", d,
410  (clk1 | (clk2 << 2) | (clk3 << 4)));
411 
413  clk1 | (clk2 << 2) | (clk3 << 4));
414 }
INLINE void dl403_start ( struct dl403 d)

Definition at line 454 of file dl40x.cpp.

References dl403::a16_base, DL403_GO, DL403_START, dl403::vme_handle, and vme_write_d16().

455 {
457 }
INLINE void dl403_steadyMode ( struct dl403 d)

Definition at line 448 of file dl40x.cpp.

References dl403::a16_base, DL403_MODE, DL403_STEADY, dl403::vme_handle, and vme_write_d16().

449 {
451 }
INLINE void dl403_stop ( struct dl403 d)

Definition at line 460 of file dl40x.cpp.

References dl403::a16_base, DL403_GO, DL403_STOP, dl403::vme_handle, and vme_write_d16().

461 {
463 }
INT dl40x_bor ( )
INT dl40x_eor ( )
INT dl40x_read ( char *  pevent)

Variable Documentation

struct dl403 clk
static
struct dl401 DL401[DL401_MAXMODULES]
static
struct readout_module dl40x_module
Initial value:
= {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
}

Definition at line 25 of file dl40x.cpp.