From 83dde40090e0bbd91c304602cc0e3c365f7878bb Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 26 Sep 2017 18:22:25 -0700 Subject: uhd: Changed mboard_eeprom_t interface, refactored MB EEPROM code - uhd::usrp::mboard_eeprom_t is now simply a map. Its commit() method has no utility being a public API call, because the user never gets access to the appropriate I2C object (Minor API breakage) - The central mboard_eeprom.cpp file was broken up and put into many smaller compilation units in every device's implementation folder. - Renamed some of the constants (e.g. B000_* -> USRP1_*, N100_* -> N200_*) - Removed the N000_* EEPROM code, because, well, you know, there's no such device --- host/lib/utils/CMakeLists.txt | 3 +++ host/lib/utils/eeprom_utils.cpp | 22 ++++++++++++++++++++++ host/lib/utils/eeprom_utils.hpp | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 host/lib/utils/eeprom_utils.cpp create mode 100644 host/lib/utils/eeprom_utils.hpp (limited to 'host/lib/utils') diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 0b163c35f..a9e3ae89a 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -19,6 +19,8 @@ # This file included, use CMake directory variables ######################################################################## +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + ######################################################################## # Setup defines for process scheduling ######################################################################## @@ -168,6 +170,7 @@ SET_SOURCE_FILES_PROPERTIES( ######################################################################## LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/csv.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/eeprom_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gain_group.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ihex.cpp ${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp diff --git a/host/lib/utils/eeprom_utils.cpp b/host/lib/utils/eeprom_utils.cpp new file mode 100644 index 000000000..acf81a1ce --- /dev/null +++ b/host/lib/utils/eeprom_utils.cpp @@ -0,0 +1,22 @@ +// +// Copyright 2017 Ettus Research (National Instruments Corp.) +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include "eeprom_utils.hpp" +#include + +uhd::byte_vector_t string_to_uint16_bytes(const std::string &num_str){ + const uint16_t num = boost::lexical_cast(num_str); + const std::vector lsb_msb = { + uint8_t(num >> 0), + uint8_t(num >> 8) + }; + return lsb_msb; +} + +std::string uint16_bytes_to_string(const uhd::byte_vector_t &bytes){ + const uint16_t num = (uint16_t(bytes.at(0)) << 0) | (uint16_t(bytes.at(1)) << 8); + return (num == 0 or num == 0xffff)? "" : std::to_string(num); +} diff --git a/host/lib/utils/eeprom_utils.hpp b/host/lib/utils/eeprom_utils.hpp new file mode 100644 index 000000000..b6ff264fb --- /dev/null +++ b/host/lib/utils/eeprom_utils.hpp @@ -0,0 +1,20 @@ +// +// Copyright 2017 Ettus Research (National Instruments Corp.) +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include +#include +#include +#include +#include + +static const size_t SERIAL_LEN = 9; +static const size_t NAME_MAX_LEN = 32 - SERIAL_LEN; + +//! convert a string to a byte vector to write to eeprom +uhd::byte_vector_t string_to_uint16_bytes(const std::string &num_str); + +//! convert a byte vector read from eeprom to a string +std::string uint16_bytes_to_string(const uhd::byte_vector_t &bytes); -- cgit v1.2.3