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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/convert.hpp>
#include <uhd/exception.hpp>
#include <uhd/rfnoc/defaults.hpp>
#include <uhd/rfnoc/multichan_register_iface.hpp>
#include <uhd/rfnoc/property.hpp>
#include <uhd/rfnoc/registry.hpp>
#include <uhd/rfnoc/vector_iir_block_control.hpp>
#include <string>
using namespace uhd::rfnoc;
const uint32_t vector_iir_block_control::REG_BLOCK_SIZE = 1 << 4;
const uint32_t vector_iir_block_control::REG_DELAY_OFFSET = 0;
const uint32_t vector_iir_block_control::REG_ALPHA_OFFSET = 4;
const uint32_t vector_iir_block_control::REG_BETA_OFFSET = 8;
constexpr uint32_t DELAY_REG_MAX_DELAY_SHIFT = 16;
constexpr uint32_t DELAY_REG_DELAY_MASK = 0x0000ffff;
// User property names
const char* const PROP_KEY_ALPHA = "alpha";
const char* const PROP_KEY_BETA = "beta";
const char* const PROP_KEY_DELAY = "delay";
const char* const PROP_KEY_MAX_DELAY = "max_delay";
class vector_iir_block_control_impl : public vector_iir_block_control
{
public:
RFNOC_BLOCK_CONSTRUCTOR(vector_iir_block_control),
_vector_iir_reg_iface(*this, 0, REG_BLOCK_SIZE)
{
UHD_ASSERT_THROW(get_num_input_ports() == get_num_output_ports());
_register_props();
}
void set_alpha(const double alpha, const size_t chan)
{
set_property<double>(PROP_KEY_ALPHA, alpha, chan);
}
double get_alpha(const size_t chan) const
{
return _prop_alpha.at(chan).get();
}
void set_beta(const double beta, const size_t chan)
{
set_property<double>(PROP_KEY_BETA, beta, chan);
}
double get_beta(const size_t chan) const
{
return _prop_beta.at(chan).get();
}
void set_delay(const uint16_t delay, const size_t chan)
{
set_property<int>(PROP_KEY_DELAY, delay, chan);
}
uint16_t get_delay(const size_t chan) const
{
return _prop_delay.at(chan).get();
}
uint16_t get_max_delay(const size_t chan) const
{
return _prop_max_delay.at(chan).get();
}
/**************************************************************************
* Initialization
*************************************************************************/
private:
void _register_props()
{
const size_t num_inputs = get_num_input_ports();
_prop_type_in.reserve(num_inputs);
_prop_type_out.reserve(num_inputs);
_prop_alpha.reserve(num_inputs);
_prop_beta.reserve(num_inputs);
_prop_delay.reserve(num_inputs);
_prop_max_delay.reserve(num_inputs);
for (size_t chan = 0; chan < num_inputs; chan++) {
const uint16_t max_delay =
static_cast<uint16_t>(_vector_iir_reg_iface.peek32(REG_DELAY_OFFSET, chan)
>> DELAY_REG_MAX_DELAY_SHIFT);
// register user properties
_prop_alpha.emplace_back(
property_t<double>{PROP_KEY_ALPHA, 0.9, {res_source_info::USER, chan}});
_prop_beta.emplace_back(
property_t<double>{PROP_KEY_BETA, 0.9, {res_source_info::USER, chan}});
_prop_delay.emplace_back(
property_t<int>{PROP_KEY_DELAY, max_delay, {res_source_info::USER, chan}});
_prop_max_delay.emplace_back(
property_t<int>{PROP_KEY_MAX_DELAY, max_delay, {res_source_info::USER, chan}});
register_property(&_prop_alpha.back(), [this, chan]() {
double alpha = _prop_alpha.at(chan).get();
if (alpha < 0.0 || alpha > 1.0) {
throw uhd::value_error("Alpha value must be in [0.0, 1.0]");
}
_vector_iir_reg_iface.poke32(
REG_ALPHA_OFFSET, uint32_t(alpha * pow(2, 31)), chan);
});
register_property(&_prop_beta.back(), [this, chan]() {
double beta = _prop_beta.at(chan).get();
if (beta < 0.0 || beta > 1.0) {
throw uhd::value_error("Beta value must be in [0.0, 1.0]");
}
_vector_iir_reg_iface.poke32(
REG_BETA_OFFSET, uint32_t(beta * pow(2, 31)), chan);
});
register_property(&_prop_delay.back(), [this, chan, max_delay]() {
int length = _prop_delay.at(chan).get();
if (length < 5 || length > static_cast<int>(max_delay)) {
throw uhd::value_error(
"Delay value must be in [5, " + std::to_string(max_delay) + "]");
}
_vector_iir_reg_iface.poke32(
REG_DELAY_OFFSET, uint32_t(length) & DELAY_REG_DELAY_MASK, chan);
});
register_property(&_prop_max_delay.back());
add_property_resolver({&ALWAYS_DIRTY},
{&_prop_max_delay.back()},
[this, chan, max_delay]() { _prop_max_delay.at(chan).set(max_delay); });
// register edge properties
_prop_type_in.emplace_back(property_t<std::string>{
PROP_KEY_TYPE, IO_TYPE_SC16, {res_source_info::INPUT_EDGE, chan}});
_prop_type_out.emplace_back(property_t<std::string>{
PROP_KEY_TYPE, IO_TYPE_SC16, {res_source_info::OUTPUT_EDGE, chan}});
register_property(&_prop_type_in.back());
register_property(&_prop_type_out.back());
// add resolvers for type
add_property_resolver({&_prop_type_in.back()},
{&_prop_type_in.back()},
[this, chan]() { _prop_type_in.at(chan).set(IO_TYPE_SC16); });
add_property_resolver({&_prop_type_out.back()},
{&_prop_type_out.back()},
[this, chan]() { _prop_type_out.at(chan).set(IO_TYPE_SC16); });
}
}
/**************************************************************************
* Attributes
*************************************************************************/
std::vector<property_t<std::string>> _prop_type_in;
std::vector<property_t<std::string>> _prop_type_out;
std::vector<property_t<double>> _prop_alpha;
std::vector<property_t<double>> _prop_beta;
std::vector<property_t<int>> _prop_delay;
std::vector<property_t<int>> _prop_max_delay;
/**************************************************************************
* Register interface
*************************************************************************/
multichan_register_iface _vector_iir_reg_iface;
};
UHD_RFNOC_BLOCK_REGISTER_DIRECT(
vector_iir_block_control, VECTOR_IIR_BLOCK, "VectorIIR", CLOCK_KEY_GRAPH, "bus_clk")
|