AlcapDAQ  1
rpv130_module.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 #include <unistd.h>
5 #include <sys/io.h>
6 #include <sys/time.h>
7 
8 #include "midas.h"
9 
10 #include "crate.h"
11 #include "diag.h"
12 
13 #include "rpv130.h"
14 
15 #define RPV130_BASE 0x8000
16 INT rpv130_init();
17 INT rpv130_start_block();
18 INT rpv130_poll_live();
19 INT rpv130_poll_dead();
20 bool block_sig;
21 struct timespec timer_start;
23 
25  rpv130_init, // init
26  NULL, // exit
27  NULL, // pre_bor
28  NULL, // bor
29  NULL, // eor
30  rpv130_poll_live, // poll_live
31  rpv130_poll_dead, // poll_dead
32  rpv130_start_block, // start_block
33  NULL, // stop_block
34  NULL, // read
35 };
36 
37 /*
38  * rpv130_init
39  *
40  * Called at the beginning of the run
41  */
42 
44 {
45  printf("VME crate init...\n");
46  mvme_open(&myvme,0);
47  return SUCCESS;
48 }
49 
50 /*
51  * rpv130_start_block
52  *
53  */
55 {
56  rpv130_Pulse(myvme, RPV130_BASE, 2);
58  clock_gettime(CLOCK_REALTIME,&timer_start);
59  return SUCCESS;
60 }
61 
62 /*
63  * rpv130_poll_live()
64  *
65  * Called periodically while a block is active; performs active readout.
66  *
67  * Returns:
68  * - ordinarily 0,
69  * - a request for a "soft stop" end-of-block, or
70  * - an error code
71  */
72 
74 {
75  struct timespec timer_now;
76  clock_gettime(CLOCK_REALTIME, &timer_now);
77  unsigned int time_elapse =(timer_now.tv_sec - timer_start.tv_sec)*1000000000 +
78  (timer_now.tv_nsec - timer_start.tv_nsec);
79  printf("time elapse: %ld\n", time_elapse);
80 
81  if (rpv130_IsBusy3(myvme, RPV130_BASE))
82  return FE_END_BLOCK;
83 
84  //if (time_elapse > 2*1000*1000)
85  //{
86  //printf("end of block\n");
87  //return FE_END_BLOCK;
88  //}
89  return SUCCESS;
90 }
91 
93 {
94  return 0;
95 }