AlcapDAQ
1
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
crate3
parport_module.cpp
Go to the documentation of this file.
1
//#define PARALLEL_PORT0 0x4450
2
//#define PARALLEL_PORT1 0x4451
3
//#define PARALLEL_PORT1 0x44c0
4
//#define PARALLEL_PORT1 0x4440 // always reads 4
5
//#define PARALLEL_PORT0 0x1250
6
//#define PARALLEL_PORT1 0x1251
7
#define PARALLEL_PORT0 0x1150
8
#define PARALLEL_PORT1 0x1151
9
10
// #define PARALLEL_PORT0 0x378
11
// #define PARALLEL_PORT1 (0x378+1)
12
#include <stdio.h>
13
#include <stdlib.h>
14
15
#include <unistd.h>
16
#include <sys/io.h>
17
#include <sys/time.h>
18
19
#include "midas.h"
20
21
#include "
crate.h
"
22
#include "
diag.h
"
23
INT
setPP
(
char
,
int
);
24
INT
parport_init
();
25
INT
parport_start_block
();
26
INT
parport_poll_live
();
27
INT
parport_poll_dead
();
28
bool
block_sig
;
29
#if 0
30
struct
timespec
timer_start
;
31
static
timeval t_0;
32
#endif
33
static
unsigned
int
block_nr
;
34
35
struct
readout_module
parport_module
= {
36
parport_init
,
// init
37
NULL,
// exit
38
NULL,
// pre_bor
39
NULL,
// bor
40
NULL,
// eor
41
parport_poll_live
,
// poll_live
42
parport_poll_dead
,
// poll_dead
43
parport_start_block
,
// start_block
44
NULL,
// stop_block
45
NULL,
// read
46
};
47
48
/*
49
* parport_init
50
*
51
* Called at the beginning of the run
52
*/
53
54
INT
setPP
(
char
v,
int
usec) {
55
56
outb(v,
PARALLEL_PORT0
);
57
//outb(v,PARALLEL_PORT1);
58
59
return
0;
60
61
}
62
63
64
INT
parport_init
()
65
{
66
67
printf
(
"Opening parallel port %x\t\n"
,
PARALLEL_PORT0
);
68
if
(ioperm(
PARALLEL_PORT0
,3,1))
69
{
70
perror(
"PArallel POrt opening error\n"
);
71
return
1;
72
}
73
/*
74
int status = iopl( 3 );
75
76
if (status < 0) {
77
diag_print(0, "Unable to get permission to access I/O ports\n");
78
}
79
80
// turn off output
81
outb(0x1d, 0x3f2);
82
*/
83
84
block_nr
= 0;
85
86
#if 0
87
gettimeofday(&t_0,NULL);
88
#endif
89
90
printf
(
"Dummy master crate init\n"
);
91
return
SUCCESS
;
92
}
93
94
/*
95
* parport_start_block
96
*
97
*/
98
INT
parport_start_block
()
99
{
100
101
block_sig
=
true
;
102
#if 0
103
clock_gettime(CLOCK_REALTIME,&
timer_start
);
104
#endif
105
block_nr
++;
106
printf
(
"parport_start_block %i\n"
,
block_nr
);
107
//setPP(255, 1);
108
109
// Send reset
110
setPP
(1<<1, 1);
111
setPP
(0, 1);
112
113
// start new segment
114
setPP
(1, 1);
115
setPP
(0, 1);
116
return
SUCCESS
;
117
}
118
119
/*
120
* parport_poll_live()
121
*
122
* Called periodically while a block is active; performs active readout.
123
*
124
* Returns:
125
* - ordinarily 0,
126
* - a request for a "soft stop" end-of-block, or
127
* - an error code
128
*/
129
130
INT
parport_poll_live
()
131
{
132
#if 0
133
struct
timespec timer_now;
134
clock_gettime(CLOCK_REALTIME, &timer_now);
135
unsigned
int
time_elapse = (timer_now.tv_sec -
timer_start
.tv_sec) * 1000000000 +
136
(timer_now.tv_nsec -
timer_start
.tv_nsec);
137
printf
(
"time elapse: %ld\n"
, time_elapse);
138
if
(time_elapse > 2*1000*1000)
139
{
140
printf
(
"end of block\n"
);
141
return
FE_END_BLOCK
;
142
}
143
#endif
144
145
unsigned
char
p = inb(
PARALLEL_PORT1
);
146
147
148
if
( !(p & 0x40) )
149
{
150
printf
(
"p=%i, 0x%x\n"
,p, p);
151
printf
(
"end of block\n"
);
152
return
FE_END_BLOCK
;
153
}
154
155
156
return
SUCCESS
;
157
}
158
159
INT
parport_poll_dead
()
160
{
161
//printf("Send to start block\n");
162
//return FE_NEED_START;
163
return
0;
164
}
Generated by
1.8.4