DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SIChipSlave.cpp
Go to the documentation of this file.
1
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
20namespace dunedaq {
21namespace timing {
22
23//-----------------------------------------------------------------------------
24SIChipSlave::SIChipSlave(const I2CMasterNode* i2c_master, uint8_t address) // NOLINT(build/unsigned)
25 : I2CSlave(i2c_master, address)
26{}
27//-----------------------------------------------------------------------------
28
29//-----------------------------------------------------------------------------
31//-----------------------------------------------------------------------------
32
33//-----------------------------------------------------------------------------
34uint8_t // NOLINT(build/unsigned)
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//-----------------------------------------------------------------------------
46void
47SIChipSlave::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//-----------------------------------------------------------------------------
58uint32_t // NOLINT(build/unsigned)
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//-----------------------------------------------------------------------------
72uint8_t // NOLINT(build/unsigned)
73SIChipSlave::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//-----------------------------------------------------------------------------
96void
97SIChipSlave::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
uint8_t read_i2c(uint32_t i2c_device_address, uint32_t i2c_reg_address) const
comodity functions
Definition I2CSlave.cpp:46
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:81
SIChipSlave(const I2CMasterNode *i2c_master, uint8_t i2c_device_address)
void switch_page(uint8_t page) const
{ function_description }
void write_clock_register(uint16_t address, uint8_t data) const
Writes a clock register.
uint8_t read_page() const
Reads the current page.
uint8_t read_clock_register(uint16_t address) const
Reads a clock register.
uint32_t read_device_version() const
Reads a device version.
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
std::string format_reg_value(T reg_value, uint32_t base)
Definition toolbox.hxx:117
Including Qt Headers.