DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
timing
src
SIChipSlave.cpp
Go to the documentation of this file.
1
8
9
#include "
timing/SIChipSlave.hpp
"
10
11
// PDT headers
12
#include "
ers/ers.hpp
"
13
#include "
timing/toolbox.hpp
"
14
15
#include <boost/tuple/tuple.hpp>
16
17
#include <fstream>
18
#include <sstream>
19
20
namespace
dunedaq
{
21
namespace
timing
{
22
23
//-----------------------------------------------------------------------------
24
SIChipSlave::SIChipSlave
(
const
I2CMasterNode
* i2c_master, uint8_t
address
)
// NOLINT(build/unsigned)
25
:
I2CSlave
(i2c_master,
address
)
26
{}
27
//-----------------------------------------------------------------------------
28
29
//-----------------------------------------------------------------------------
30
SIChipSlave::~SIChipSlave
() {}
31
//-----------------------------------------------------------------------------
32
33
//-----------------------------------------------------------------------------
34
uint8_t
// NOLINT(build/unsigned)
35
SIChipSlave::read_page
()
const
36
{
37
38
TLOG_DEBUG
(7) <<
"<- Reading page "
;
39
40
// Read from the page address (0x1?)
41
return
read_i2c
(0x1);
42
}
43
//-----------------------------------------------------------------------------
44
45
//-----------------------------------------------------------------------------
46
void
47
SIChipSlave::switch_page
(uint8_t page)
const
// NOLINT(build/unsigned)
48
{
49
50
// Prepare a data block with address and new page
51
// std::vector<uint8_t> lData = {0x1, page};// NOLINT(build/unsigned)
52
TLOG_DEBUG
(7) <<
"-> Switching to page "
<<
format_reg_value
((uint32_t)page);
// NOLINT(build/unsigned)
53
write_i2c
(0x1, page);
54
}
55
//-----------------------------------------------------------------------------
56
57
//-----------------------------------------------------------------------------
58
uint32_t
// NOLINT(build/unsigned)
59
SIChipSlave::read_device_version
()
const
60
{
61
62
// Go to the right page
63
switch_page
(0x0);
64
// Read 2 words from 0x2
65
auto
version
=
read_i2cArray
(0x2, 2);
66
67
return
(((uint32_t)
version
[1] << 8) + (uint32_t)
version
[0]);
// NOLINT(build/unsigned)
68
}
69
//-----------------------------------------------------------------------------
70
71
//-----------------------------------------------------------------------------
72
uint8_t
// NOLINT(build/unsigned)
73
SIChipSlave::read_clock_register
(uint16_t
address
)
const
// NOLINT(build/unsigned)
74
{
75
76
uint8_t reg_address = (
address
& 0xff);
// NOLINT(build/unsigned)
77
uint8_t page_address = (
address
>> 8) & 0xff;
// NOLINT(build/unsigned)
78
std::stringstream debug_stream;
79
debug_stream << std::showbase << std::hex <<
"Read Address "
<< (uint32_t)
address
// NOLINT(build/unsigned)
80
<<
" reg: "
<< (uint32_t)reg_address
// NOLINT(build/unsigned)
81
<<
" page: "
<< (uint32_t)page_address;
// NOLINT(build/unsigned)
82
TLOG_DEBUG
(6) << debug_stream.str();
83
// Change page only when required.
84
// (The SI5344 don't like to have the page register id to be written all the time.)
85
uint8_t current_address =
read_page
();
// NOLINT(build/unsigned)
86
if
(page_address != current_address) {
87
switch_page
(page_address);
88
}
89
90
// Read the register
91
return
read_i2c
(reg_address);
92
}
93
//-----------------------------------------------------------------------------
94
95
//-----------------------------------------------------------------------------
96
void
97
SIChipSlave::write_clock_register
(uint16_t
address
, uint8_t data)
const
// NOLINT(build/unsigned)
98
{
99
100
uint8_t reg_address = (
address
& 0xff);
// NOLINT(build/unsigned)
101
uint8_t page_address = (
address
>> 8) & 0xff;
// NOLINT(build/unsigned)
102
103
std::stringstream debug_stream;
104
debug_stream << std::showbase << std::hex <<
"Write Address "
<< (uint32_t)
address
// NOLINT(build/unsigned)
105
<<
" reg: "
<< (uint32_t)reg_address
// NOLINT(build/unsigned)
106
<<
" page: "
<< (uint32_t)page_address;
// NOLINT(build/unsigned)
107
TLOG_DEBUG
(6) << debug_stream.str();
108
// Change page only when required.
109
// (The SI5344 don't like to have the page register id to be written all the time.)
110
uint8_t current_address =
read_page
();
// NOLINT(build/unsigned)
111
if
(page_address != current_address) {
112
switch_page
(page_address);
113
}
114
115
return
write_i2c
(reg_address, data);
116
}
117
//-----------------------------------------------------------------------------
118
119
}
// namespace timing
120
}
// namespace dunedaq
SIChipSlave.hpp
version
version
Definition
TriggerActivity_serialization.hpp:50
dunedaq::timing::I2CSlave::read_i2c
uint8_t read_i2c(uint32_t i2c_device_address, uint32_t i2c_reg_address) const
comodity functions
Definition
I2CSlave.cpp:46
dunedaq::timing::I2CSlave::read_i2cArray
std::vector< uint8_t > read_i2cArray(uint32_t i2c_device_address, uint32_t i2c_reg_address, uint32_t number_of_words) const
Definition
I2CSlave.cpp:97
dunedaq::timing::I2CSlave::I2CMasterNode
friend class I2CMasterNode
Definition
I2CSlave.hpp:97
dunedaq::timing::I2CSlave::write_i2c
void write_i2c(uint32_t i2c_device_address, uint32_t i2c_reg_address, uint8_t data, bool send_stop=true) const
Definition
I2CSlave.cpp:78
dunedaq::timing::I2CSlave::I2CSlave
I2CSlave(const I2CMasterNode *i2c_master, uint8_t i2c_device_address)
Definition
I2CSlave.cpp:33
dunedaq::timing::SIChipSlave::SIChipSlave
SIChipSlave(const I2CMasterNode *i2c_master, uint8_t i2c_device_address)
Definition
SIChipSlave.cpp:24
dunedaq::timing::SIChipSlave::switch_page
void switch_page(uint8_t page) const
{ function_description }
Definition
SIChipSlave.cpp:47
dunedaq::timing::SIChipSlave::write_clock_register
void write_clock_register(uint16_t address, uint8_t data) const
Writes a clock register.
Definition
SIChipSlave.cpp:97
dunedaq::timing::SIChipSlave::read_page
uint8_t read_page() const
Reads the current page.
Definition
SIChipSlave.cpp:35
dunedaq::timing::SIChipSlave::read_clock_register
uint8_t read_clock_register(uint16_t address) const
Reads a clock register.
Definition
SIChipSlave.cpp:73
dunedaq::timing::SIChipSlave::read_device_version
uint32_t read_device_version() const
Reads a device version.
Definition
SIChipSlave.cpp:59
dunedaq::timing::SIChipSlave::~SIChipSlave
virtual ~SIChipSlave()
Definition
SIChipSlave.cpp:30
ers.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
dunedaq::timing
< Message parameters
Definition
BoreasDesign.hpp:29
dunedaq::timing::format_reg_value
std::string format_reg_value(T reg_value, uint32_t base)
Definition
toolbox.hxx:117
dunedaq
Including Qt Headers.
Definition
module.cpp:16
dunedaq::address
Invalid address
Definition
CommonIssues.hpp:29
toolbox.hpp
Generated on
for DUNE-DAQ by
1.17.0