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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/exception.hpp>
#include <uhd/rfnoc/defaults.hpp>
#include <uhd/rfnoc/fft_block_control.hpp>
#include <uhd/rfnoc/registry.hpp>
#include <string>
using namespace uhd::rfnoc;
namespace {
constexpr int DEFAULT_LENGTH = 256;
constexpr fft_shift DEFAULT_SHIFT = fft_shift::NORMAL;
constexpr fft_direction DEFAULT_DIRECTION = fft_direction::FORWARD;
constexpr fft_magnitude DEFAULT_MAGNITUDE = fft_magnitude::COMPLEX;
constexpr int DEFAULT_FFT_SCALING = 1706; // Conservative 1/N scaling
// FFT IP constraints
constexpr int MIN_FFT_LENGTH = 8;
constexpr int MAX_FFT_LENGTH = 1024;
const uhd::rfnoc::io_type_t DEFAULT_TYPE = uhd::rfnoc::IO_TYPE_SC16;
} // namespace
const uint32_t fft_block_control::REG_RESET_ADDR = 131 * 8;
const uint32_t fft_block_control::REG_LENGTH_LOG2_ADDR = 132 * 8;
const uint32_t fft_block_control::REG_MAGNITUDE_OUT_ADDR = 133 * 8;
const uint32_t fft_block_control::REG_DIRECTION_ADDR = 134 * 8;
const uint32_t fft_block_control::REG_SCALING_ADDR = 135 * 8;
const uint32_t fft_block_control::REG_SHIFT_CONFIG_ADDR = 136 * 8;
class fft_block_control_impl : public fft_block_control
{
public:
RFNOC_BLOCK_CONSTRUCTOR(fft_block_control)
{
set_prop_forwarding_policy(forwarding_policy_t::ONE_TO_ONE);
set_action_forwarding_policy(forwarding_policy_t::ONE_TO_ONE);
_reset();
_register_props();
}
void set_direction(const fft_direction direction) override
{
set_property<int>(PROP_KEY_DIRECTION, static_cast<int>(direction));
}
fft_direction get_direction() const override
{
return static_cast<fft_direction>(_direction.get());
}
void set_magnitude(const fft_magnitude magnitude) override
{
set_property<int>(PROP_KEY_MAGNITUDE, static_cast<int>(magnitude));
}
fft_magnitude get_magnitude() const override
{
return static_cast<fft_magnitude>(_magnitude.get());
}
void set_shift_config(const fft_shift shift) override
{
set_property<int>(PROP_KEY_SHIFT_CONFIG, static_cast<int>(shift));
}
fft_shift get_shift_config() const override
{
return static_cast<fft_shift>(_shift.get());
}
void set_scaling(const uint16_t scaling) override
{
set_property<int>(PROP_KEY_FFT_SCALING, scaling);
}
uint16_t get_scaling() const override
{
return static_cast<uint16_t>(_scaling.get());
}
void set_length(const size_t size) override
{
set_property<int>(PROP_KEY_LENGTH, size);
}
size_t get_length() const override
{
return static_cast<size_t>(_length.get());
}
private:
void _reset()
{
regs().poke32(REG_RESET_ADDR, uint32_t(1));
regs().poke32(REG_RESET_ADDR, uint32_t(0));
}
/**************************************************************************
* Initialization
*************************************************************************/
void _register_props()
{
// register block specific properties
register_property(&_length);
add_property_resolver({&_length}, {&_length}, [this]() {
size_t length = this->_length.get();
if (length < MIN_FFT_LENGTH || length > MAX_FFT_LENGTH) {
throw uhd::value_error("Size value must be in ["
+ std::to_string(MIN_FFT_LENGTH) + ", "
+ std::to_string(MAX_FFT_LENGTH) + "]");
}
// Find the log2(length) via highest bit set
size_t length_log2 = 0;
size_t old_length = length;
while ((length >>= 1) != 0) {
length_log2++;
}
size_t coerced_length = (1 << length_log2);
if (old_length != coerced_length) {
RFNOC_LOG_WARNING("Length "
<< old_length
<< " not an integral power of two; coercing to "
<< coerced_length);
this->_length.set(coerced_length);
}
this->regs().poke32(REG_LENGTH_LOG2_ADDR, uint32_t(length_log2));
});
register_property(&_magnitude, [this]() {
int mag = this->_magnitude.get();
if (mag < static_cast<int>(fft_magnitude::COMPLEX)
|| mag > static_cast<int>(fft_magnitude::MAGNITUDE_SQUARED)) {
throw uhd::value_error("Magnitude value must be [0, 2]");
}
this->regs().poke32(REG_MAGNITUDE_OUT_ADDR, uint32_t(mag));
});
register_property(&_direction, [this]() {
int dir = _direction.get();
if (dir < static_cast<int>(fft_direction::REVERSE)
|| dir > static_cast<int>(fft_direction::FORWARD)) {
throw uhd::value_error("Direction value must be in [0, 1]");
}
this->regs().poke32(REG_DIRECTION_ADDR, uint32_t(dir));
});
register_property(&_scaling, [this]() {
int scale = _scaling.get();
if (scale < 0 || scale > (1 << 12) - 1) {
throw uhd::value_error("Scale value must be in [0, 4095]");
}
this->regs().poke32(REG_SCALING_ADDR, uint32_t(scale));
});
register_property(&_shift, [this]() {
int shift = this->_shift.get();
if (shift < static_cast<int>(fft_shift::NORMAL)
|| shift > static_cast<int>(fft_shift::NATURAL)) {
throw uhd::value_error("Shift value must be [0, 2]");
}
this->regs().poke32(REG_SHIFT_CONFIG_ADDR, uint32_t(shift));
});
// register edge properties
register_property(&_type_in);
register_property(&_type_out);
// add resolvers for type (keeps it constant)
add_property_resolver({&_type_in}, {&_type_in}, [& type_in = _type_in]() {
type_in.set(IO_TYPE_SC16);
});
add_property_resolver({&_type_out}, {&_type_out}, [& type_out = _type_out]() {
type_out.set(IO_TYPE_SC16);
});
}
property_t<int> _length{PROP_KEY_LENGTH, DEFAULT_LENGTH, {res_source_info::USER}};
property_t<int> _magnitude = property_t<int>{
PROP_KEY_MAGNITUDE, static_cast<int>(DEFAULT_MAGNITUDE), {res_source_info::USER}};
property_t<int> _direction = property_t<int>{
PROP_KEY_DIRECTION, static_cast<int>(DEFAULT_DIRECTION), {res_source_info::USER}};
property_t<int> _scaling = property_t<int>{
PROP_KEY_FFT_SCALING, DEFAULT_FFT_SCALING, {res_source_info::USER}};
property_t<int> _shift = property_t<int>{
PROP_KEY_SHIFT_CONFIG, static_cast<int>(DEFAULT_SHIFT), {res_source_info::USER}};
property_t<std::string> _type_in = property_t<std::string>{
PROP_KEY_TYPE, IO_TYPE_SC16, {res_source_info::INPUT_EDGE}};
property_t<std::string> _type_out = property_t<std::string>{
PROP_KEY_TYPE, IO_TYPE_SC16, {res_source_info::OUTPUT_EDGE}};
};
UHD_RFNOC_BLOCK_REGISTER_DIRECT(
fft_block_control, FFT_BLOCK, "FFT", CLOCK_KEY_GRAPH, "bus_clk")
|