diff options
-rw-r--r-- | host/lib/convert/CMakeLists.txt | 5 | ||||
-rw-r--r-- | host/lib/convert/convert_fc32_item32.cpp | 113 | ||||
-rw-r--r-- | host/lib/convert/convert_pack_sc12.cpp | 144 | ||||
-rw-r--r-- | host/lib/convert/convert_unpack_sc12.cpp | 152 |
4 files changed, 413 insertions, 1 deletions
diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt index 28defa8bc..00e129b78 100644 --- a/host/lib/convert/CMakeLists.txt +++ b/host/lib/convert/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2011-2012 Ettus Research LLC +# Copyright 2011-2013 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -121,4 +121,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/convert_with_tables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/convert_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/convert_item32.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/convert_pack_sc12.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/convert_unpack_sc12.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/convert_fc32_item32.cpp ) diff --git a/host/lib/convert/convert_fc32_item32.cpp b/host/lib/convert/convert_fc32_item32.cpp new file mode 100644 index 000000000..29bfefd46 --- /dev/null +++ b/host/lib/convert/convert_fc32_item32.cpp @@ -0,0 +1,113 @@ +// +// Copyright 2013 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include "convert_common.hpp" +#include <uhd/utils/byteswap.hpp> +#include <uhd/utils/msg.hpp> +#include <boost/math/special_functions/round.hpp> +#include <vector> + +using namespace uhd::convert; + +typedef boost::uint32_t (*to32_type)(boost::uint32_t); + +template <typename type, to32_type tohost> +struct convert_fc32_item32_1_to_star_1 : public converter +{ + convert_fc32_item32_1_to_star_1(void) + { + //NOP + } + + void set_scalar(const double scalar) + { + _scalar = scalar; + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps) + { + const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]); + std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]); + + size_t i = 0; + for (size_t o = 0; o < nsamps; o++) + { + const item32_t i32 = tohost(input[i++]); + const item32_t q32 = tohost(input[i++]); + const float i_f32 = reinterpret_cast<const float &>(i32); + const float q_f32 = reinterpret_cast<const float &>(q32); + output[o] = std::complex<type>(type(i_f32*_scalar), type(q_f32*_scalar)); + } + } + + double _scalar; +}; + +template <typename type, to32_type towire> +struct convert_star_1_to_fc32_item32_1 : public converter +{ + convert_star_1_to_fc32_item32_1(void) + { + //NOP + } + + void set_scalar(const double scalar) + { + _scalar = scalar; + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps) + { + const std::complex<type> *input = reinterpret_cast<const std::complex<type> *>(inputs[0]); + item32_t *output = reinterpret_cast<item32_t *>(outputs[0]); + + size_t o = 0; + for (size_t i = 0; i < nsamps; i++) + { + const float i_f32 = type(input[i].real()*_scalar); + const float q_f32 = type(input[i].imag()*_scalar); + const item32_t i32 = towire(reinterpret_cast<const item32_t &>(i_f32)); + const item32_t q32 = towire(reinterpret_cast<const item32_t &>(q_f32)); + output[o++] = i32; output[o++] = q32; + } + } + + double _scalar; +}; + +#define __make_registrations(itype, otype, fcn, type, conv) \ +static converter::sptr make_convert_ ## itype ## _1_ ## otype ## _1(void) \ +{ \ + return converter::sptr(new fcn<type, conv>()); \ +} \ +UHD_STATIC_BLOCK(register_convert_ ## itype ## _1_ ## otype ## _1) \ +{ \ + uhd::convert::id_type id; \ + id.num_inputs = 1; id.num_outputs = 1; \ + id.input_format = #itype; id.output_format = #otype; \ + uhd::convert::register_converter(id, &make_convert_ ## itype ## _1_ ## otype ## _1, PRIORITY_GENERAL); \ +} + +__make_registrations(fc32_item32_le, fc32, convert_fc32_item32_1_to_star_1, float, uhd::wtohx) +__make_registrations(fc32_item32_be, fc32, convert_fc32_item32_1_to_star_1, float, uhd::ntohx) +__make_registrations(fc32_item32_le, fc64, convert_fc32_item32_1_to_star_1, double, uhd::wtohx) +__make_registrations(fc32_item32_be, fc64, convert_fc32_item32_1_to_star_1, double, uhd::ntohx) + +__make_registrations(fc32, fc32_item32_le, convert_star_1_to_fc32_item32_1, float, uhd::wtohx) +__make_registrations(fc32, fc32_item32_be, convert_star_1_to_fc32_item32_1, float, uhd::ntohx) +__make_registrations(fc64, fc32_item32_le, convert_star_1_to_fc32_item32_1, double, uhd::wtohx) +__make_registrations(fc64, fc32_item32_be, convert_star_1_to_fc32_item32_1, double, uhd::ntohx) diff --git a/host/lib/convert/convert_pack_sc12.cpp b/host/lib/convert/convert_pack_sc12.cpp new file mode 100644 index 000000000..680814994 --- /dev/null +++ b/host/lib/convert/convert_pack_sc12.cpp @@ -0,0 +1,144 @@ +// +// Copyright 2013 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include "convert_common.hpp" +#include <uhd/utils/byteswap.hpp> +#include <uhd/utils/msg.hpp> +#include <boost/math/special_functions/round.hpp> +#include <vector> + +using namespace uhd::convert; + +typedef boost::uint32_t (*towire32_type)(boost::uint32_t); + +struct item32_sc12_3x +{ + item32_t line0; + item32_t line1; + item32_t line2; +}; + +template <typename type, towire32_type towire> +void convert_star_4_to_sc12_item32_3 +( + const std::complex<type> &in0, + const std::complex<type> &in1, + const std::complex<type> &in2, + const std::complex<type> &in3, + item32_sc12_3x &output, + const double scalar +) +{ + const item32_t i0 = boost::int32_t(type(in0.real()*scalar)) & 0xfff; + const item32_t q0 = boost::int32_t(type(in0.imag()*scalar)) & 0xfff; + + const item32_t i1 = boost::int32_t(type(in1.real()*scalar)) & 0xfff; + const item32_t q1 = boost::int32_t(type(in1.imag()*scalar)) & 0xfff; + + const item32_t i2 = boost::int32_t(type(in2.real()*scalar)) & 0xfff; + const item32_t q2 = boost::int32_t(type(in2.imag()*scalar)) & 0xfff; + + const item32_t i3 = boost::int32_t(type(in3.real()*scalar)) & 0xfff; + const item32_t q3 = boost::int32_t(type(in3.imag()*scalar)) & 0xfff; + + const item32_t line0 = (i0 << 20) | (q0 << 8) | (i1 >> 4); + const item32_t line1 = (i1 << 28) | (q1 << 16) | (i2 << 4) | (q2 >> 8); + const item32_t line2 = (q2 << 24) | (i3 << 12) | (q3); + + output.line0 = towire(line0); + output.line1 = towire(line1); + output.line2 = towire(line2); +} + +template <typename type, towire32_type towire> +struct convert_star_1_to_sc12_item32_1 : public converter +{ + convert_star_1_to_sc12_item32_1(void) + { + //NOP + } + + void set_scalar(const double scalar) + { + _scalar = scalar; + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps) + { + const std::complex<type> *input = reinterpret_cast<const std::complex<type> *>(inputs[0]); + item32_sc12_3x *output = reinterpret_cast<item32_sc12_3x *>(size_t(outputs[0]) & ~0x3); + + //helper variables + size_t i = 0, o = 0; + + //handle the head case + const size_t head_samps = size_t(outputs[0]) & 0x3; + switch (head_samps) + { + case 0: break; //no head + case 1: convert_star_4_to_sc12_item32_3<type, towire>(0, 0, 0, input[0], output[o++], _scalar); break; + case 2: convert_star_4_to_sc12_item32_3<type, towire>(0, 0, input[0], input[1], output[o++], _scalar); break; + case 3: convert_star_4_to_sc12_item32_3<type, towire>(0, input[0], input[1], input[2], output[o++], _scalar); break; + } + i += head_samps; + + //convert the body + while (i+3 < nsamps) + { + convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], input[i+2], input[i+3], output[o], _scalar); + o++; i += 4; + } + + //handle the tail case + const size_t tail_samps = nsamps - i; + switch (tail_samps) + { + case 0: break; //no tail + case 1: convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], 0, 0, 0, output[o], _scalar); break; + case 2: convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], 0, 0, output[o], _scalar); break; + case 3: convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], input[i+2], 0, output[o], _scalar); break; + } + } + + double _scalar; +}; + +static converter::sptr make_convert_fc32_1_to_sc12_item32_le_1(void) +{ + return converter::sptr(new convert_star_1_to_sc12_item32_1<float, uhd::wtohx>()); +} + +static converter::sptr make_convert_fc32_1_to_sc12_item32_be_1(void) +{ + return converter::sptr(new convert_star_1_to_sc12_item32_1<float, uhd::ntohx>()); +} + +UHD_STATIC_BLOCK(register_convert_pack_sc12) +{ + //uhd::convert::register_bytes_per_item("sc12", 3/*bytes*/); //registered in unpack + + uhd::convert::id_type id; + id.num_inputs = 1; + id.num_outputs = 1; + id.input_format = "fc32"; + + id.output_format = "sc12_item32_le"; + uhd::convert::register_converter(id, &make_convert_fc32_1_to_sc12_item32_le_1, PRIORITY_GENERAL); + + id.output_format = "sc12_item32_be"; + uhd::convert::register_converter(id, &make_convert_fc32_1_to_sc12_item32_be_1, PRIORITY_GENERAL); +} diff --git a/host/lib/convert/convert_unpack_sc12.cpp b/host/lib/convert/convert_unpack_sc12.cpp new file mode 100644 index 000000000..f578b6c95 --- /dev/null +++ b/host/lib/convert/convert_unpack_sc12.cpp @@ -0,0 +1,152 @@ +// +// Copyright 2013 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include "convert_common.hpp" +#include <uhd/utils/byteswap.hpp> +#include <uhd/utils/msg.hpp> +#include <boost/math/special_functions/round.hpp> +#include <vector> + +using namespace uhd::convert; + +typedef boost::uint32_t (*tohost32_type)(boost::uint32_t); + +struct item32_sc12_3x +{ + item32_t line0; + item32_t line1; + item32_t line2; +}; + +template <typename type, tohost32_type tohost> +void convert_sc12_item32_3_to_star_4 +( + const item32_sc12_3x &input, + std::complex<type> &out0, + std::complex<type> &out1, + std::complex<type> &out2, + std::complex<type> &out3, + const double scalar +) +{ + //step 0: extract the lines from the input buffer + const item32_t line0 = tohost(input.line0); + const item32_t line1 = tohost(input.line1); + const item32_t line2 = tohost(input.line2); + const boost::uint64_t line01 = (boost::uint64_t(line0) << 32) | line1; + const boost::uint64_t line12 = (boost::uint64_t(line1) << 32) | line2; + + //step 1: shift out and mask off the individual numbers + const type i0 = type(boost::int16_t(line0 >> 16)*scalar); + const type q0 = type(boost::int16_t(line0 >> 4)*scalar); + + const type i1 = type(boost::int16_t(line01 >> 24)*scalar); + const type q1 = type(boost::int16_t(line1 >> 12)*scalar); + + const type i2 = type(boost::int16_t(line1 >> 0)*scalar); + const type q2 = type(boost::int16_t(line12 >> 20)*scalar); + + const type i3 = type(boost::int16_t(line2 >> 8)*scalar); + const type q3 = type(boost::int16_t(line2 << 4)*scalar); + + //step 2: load the outputs + out0 = std::complex<type>(i0, q0); + out1 = std::complex<type>(i1, q1); + out2 = std::complex<type>(i2, q2); + out3 = std::complex<type>(i3, q3); +} + +template <typename type, tohost32_type tohost> +struct convert_sc12_item32_1_to_star_1 : public converter +{ + convert_sc12_item32_1_to_star_1(void) + { + //NOP + } + + void set_scalar(const double scalar) + { + const int unpack_growth = 16; + _scalar = scalar/unpack_growth; + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps) + { + const item32_sc12_3x *input = reinterpret_cast<const item32_sc12_3x *>(size_t(inputs[0]) & ~0x3); + std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]); + + //helper variables + std::complex<type> dummy0, dummy1, dummy2; + size_t i = 0, o = 0; + + //handle the head case + const size_t head_samps = size_t(inputs[0]) & 0x3; + switch (head_samps) + { + case 0: break; //no head + case 1: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy0, dummy1, dummy2, output[0], _scalar); break; + case 2: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy0, dummy1, output[0], output[1], _scalar); break; + case 3: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy0, output[0], output[1], output[2], _scalar); break; + } + o += head_samps; + + //convert the body + while (o+3 < nsamps) + { + convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], output[o+2], output[o+3], _scalar); + i++; o += 4; + } + + //handle the tail case + const size_t tail_samps = nsamps - o; + switch (tail_samps) + { + case 0: break; //no tail + case 1: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], dummy0, dummy1, dummy2, _scalar); break; + case 2: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], dummy1, dummy2, _scalar); break; + case 3: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], output[o+2], dummy2, _scalar); break; + } + } + + double _scalar; +}; + +static converter::sptr make_convert_sc12_item32_le_1_to_fc32_1(void) +{ + return converter::sptr(new convert_sc12_item32_1_to_star_1<float, uhd::wtohx>()); +} + +static converter::sptr make_convert_sc12_item32_be_1_to_fc32_1(void) +{ + return converter::sptr(new convert_sc12_item32_1_to_star_1<float, uhd::ntohx>()); +} + +UHD_STATIC_BLOCK(register_convert_unpack_sc12) +{ + uhd::convert::register_bytes_per_item("sc12", 3/*bytes*/); + + uhd::convert::id_type id; + id.num_inputs = 1; + id.num_outputs = 1; + id.output_format = "fc32"; + + id.input_format = "sc12_item32_le"; + uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_fc32_1, PRIORITY_GENERAL); + + id.input_format = "sc12_item32_be"; + uhd::convert::register_converter(id, &make_convert_sc12_item32_be_1_to_fc32_1, PRIORITY_GENERAL); +} |