-
Notifications
You must be signed in to change notification settings - Fork 2
/
fee.cc
88 lines (69 loc) · 1.75 KB
/
fee.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "fee.h"
#include <iostream>
Fee::Fee(int id)
{
this->id = id;
pl_open(&this->fd);
for (int i = 0; i < 2; i++) {
sampa.push_back(new Sampa(this, i));
}
this->expected_length = 7*8*1010;
this->sampa_data = new SampaData(this->fd, 7*8, 1010);
pl_register_write(fd, 10, 0xcf400000);
pl_register_write(fd, 0x8, 0xf);
pl_register_write(fd, 0x8, 0x3);
}
Fee::~Fee()
{
pl_close(this->fd);
}
void Fee::setupSampa()
{
for (auto &s : this->sampa) {
std::cout << "BX Count:" << s->getBxCount() << " Trig Count:" << s->getTrigCount() << std::endl;
}
}
int Fee::registerWrite(uint32_t addr, uint16_t data)
{
return fee_register_write(this->fd, addr, data);
}
int Fee::registerRead(uint32_t addr, uint16_t *data)
{
*data = fee_register_read(this->fd, addr);
return 0;
}
int Fee::dma_wait(uint32_t len, uint32_t seed, int chan_expected)
{
pl_register_write(fd, 11, len);
uint32_t data = 0;
while ((seed+chan_expected) != data) {
data = pl_register_read(fd, 7);
}
data = pl_register_read(fd, 10);
return (size_t)data;
}
int Fee::trigger()
{
// Reset DMA controller
pl_register_write(fd, 0x8, 0xb);
pl_register_write(fd, 0x8, 0x7);
pl_register_write(fd, 0x8, 0x3);
// Get current channel counter
uint32_t seed = pl_register_read(fd, 7);
// FEE Trigger
fee_register_write(fd, 0x5, 0x8);
usleep(3000);
fee_register_write(fd, 0x5, 0x0);
usleep(3000);
// Wait until 56 channels recv.
this->data_length = dma_wait(this->expected_length, seed, 56);
return this->data_length;
}
uint32_t *Fee::getRawData()
{
return this->sampa_data->getRawData();
}
size_t Fee::getDataLength()
{
return this->data_length;
}