DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
WIB_spybuffer.cpp
Go to the documentation of this file.
1#include "wibmod/WIB1/WIB.hh"
3
4std::vector<data_8b10b_t>
6{
7 if (Read("FEMB_SPY.FIFO_EMPTY")) {
8 BUException::WIB_ERROR e;
9 e.Append("CD Spy fifo is empty!");
10 throw e;
11 }
12
13 std::vector<data_8b10b_t> data;
14 while (!Read("FEMB_SPY.FIFO_EMPTY")) {
15 uint32_t val = Read("FEMB_SPY.DATA");
16 data.push_back(data_8b10b_t((val >> 8) & 0x1, uint8_t(val & 0xff)));
17 }
18 return data;
19}
20
21std::vector<data_8b10b_t>
22WIB::ReadDAQLinkSpyBuffer(uint8_t iDAQLink, uint8_t trigger_mode)
23{
24 // TODO read DAQ link count
25 std::string base("DAQ_LINK_");
26 base.push_back(GetDAQLinkChar(iDAQLink));
27 base.append(".SPY_BUFFER.");
28
29 // Check if there is an active capture
30 if (ReadWithRetry(base + "CAPTURING_DATA")) {
31 BUException::WIB_BUSY e;
32 e.Append(base);
33 e.Append(" is busy\n");
34 throw e;
35 }
36 // The spy buffer isn't busy, so let's make sure the fifo is empty
37 while (!ReadWithRetry(base + "EMPTY")) {
38 // Read out a workd from the fifo
39 WriteWithRetry(base + "DATA", 0x0);
40 }
41
42 // write trigger mode
43 WriteWithRetry(base + "TRIGGER_MODE", trigger_mode & 0x1);
44
45 // Start the capture
46 Write(base + "START", 0x1);
47
48 // Wait for capture to finish
49 while (ReadWithRetry(base + "CAPTURING_DATA")) {
50 }
51
52 // Read out the data
53 std::vector<data_8b10b_t> ret;
54
55 while (!ReadWithRetry(base + "EMPTY")) {
56 // read out the k-chars
57 uint32_t k_data = ReadWithRetry(base + "K_DATA");
58 // read out the data
59 uint32_t data = ReadWithRetry(base + "DATA");
60
61 // printf("0x%08X 0x%08X\n",k_data,data);
62
63 for (size_t iWord = 0; iWord < 4; iWord++) {
64 ret.push_back(data_8b10b_t((k_data >> iWord) & 0x1, (data >> (iWord * 8) & 0xFF)));
65 }
66 // mark word as read
67 Write(base + "DATA", 0x0);
68 }
69 return ret;
70}
void WriteWithRetry(uint16_t address, uint32_t value)
Definition WIBBase.cpp:163
uint32_t ReadWithRetry(uint16_t address)
Definition WIBBase.cpp:142
uint32_t Read(uint16_t address)
Definition WIBBase.cpp:147
void Write(uint16_t address, uint32_t value)
Definition WIBBase.cpp:168
std::vector< data_8b10b_t > ReadOutCDLinkSpyBuffer()
char GetDAQLinkChar(uint8_t iDAQLink)
Definition WIB.cpp:532
std::vector< data_8b10b_t > ReadDAQLinkSpyBuffer(uint8_t iDAQLink, uint8_t trigger_mode=0)
data_8b10b_t(uint8_t _k, uint8_t _d)
Definition WIB.hh:21