aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/mykonos/adi_ctrl.cpp
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2019-01-14 10:35:25 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-01-16 11:40:23 -0800
commit967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch)
tree8a24954b54d1546dc8049a17e485adb0a605f74f /mpm/lib/mykonos/adi_ctrl.cpp
parentaafe4e8b742a0e21d3818f21f34e3c8613132530 (diff)
downloaduhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.gz
uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.bz2
uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.zip
uhd: mpm: apply clang-format to all files
Applying formatting changes to all .cpp and .hpp files in the following directories: ``` find host/examples/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/tests/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/utils/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find mpm/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Also formatted host/include/, except Cpp03 was used as a the language standard instead of Cpp11. ``` sed -i 's/ Cpp11/ Cpp03/g' .clang-format find host/include/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Formatting style was designated by the .clang-format file.
Diffstat (limited to 'mpm/lib/mykonos/adi_ctrl.cpp')
-rw-r--r--mpm/lib/mykonos/adi_ctrl.cpp169
1 files changed, 75 insertions, 94 deletions
diff --git a/mpm/lib/mykonos/adi_ctrl.cpp b/mpm/lib/mykonos/adi_ctrl.cpp
index 2ae0ef663..83e363bc8 100644
--- a/mpm/lib/mykonos/adi_ctrl.cpp
+++ b/mpm/lib/mykonos/adi_ctrl.cpp
@@ -5,32 +5,28 @@
//
#include "adi/common.h"
-
+#include <uhd/exception.hpp>
#include <mpm/ad937x/adi_ctrl.hpp>
#include <mpm/types/log_buf.hpp>
-#include <uhd/exception.hpp>
#include <boost/format.hpp>
-
-#include <iostream>
#include <chrono>
-#include <thread>
+#include <iostream>
#include <sstream>
+#include <thread>
-ad9371_spiSettings_t::ad9371_spiSettings_t(
- mpm::types::regs_iface* spi_iface_
-) :
- spi_iface(spi_iface_)
+ad9371_spiSettings_t::ad9371_spiSettings_t(mpm::types::regs_iface* spi_iface_)
+ : spi_iface(spi_iface_)
{
- spi_settings.chipSelectIndex = 0; // set later
- spi_settings.writeBitPolarity = 1; // unused
+ spi_settings.chipSelectIndex = 0; // set later
+ spi_settings.writeBitPolarity = 1; // unused
spi_settings.longInstructionWord = 1;
- spi_settings.MSBFirst = 1;
- spi_settings.CPHA = 0;
- spi_settings.CPOL = 0;
- spi_settings.enSpiStreaming = 0; // unused
- spi_settings.autoIncAddrUp = 0; // unused
- spi_settings.fourWireMode = 1; // unused
- spi_settings.spiClkFreq_Hz = 250000000; // currently unused
+ spi_settings.MSBFirst = 1;
+ spi_settings.CPHA = 0;
+ spi_settings.CPOL = 0;
+ spi_settings.enSpiStreaming = 0; // unused
+ spi_settings.autoIncAddrUp = 0; // unused
+ spi_settings.fourWireMode = 1; // unused
+ spi_settings.spiClkFreq_Hz = 250000000; // currently unused
}
// TODO: change // not implemented to meaningful errors
@@ -61,7 +57,7 @@ commonErr_t CMB_hardReset(uint8_t spiChipSelectIndex)
//
// allows the platform HAL to work with devices with various SPI settings
-commonErr_t CMB_setSPIOptions(spiSettings_t *spiSettings)
+commonErr_t CMB_setSPIOptions(spiSettings_t* spiSettings)
{
// not implemented
return COMMONERR_OK;
@@ -75,22 +71,21 @@ commonErr_t CMB_setSPIChannel(uint16_t chipSelectIndex)
}
// single SPI byte write function
-commonErr_t CMB_SPIWriteByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t data)
+commonErr_t CMB_SPIWriteByte(spiSettings_t* spiSettings, uint16_t addr, uint8_t data)
{
if (spiSettings == nullptr || spiSettings->MSBFirst == 0) {
return COMMONERR_FAILED;
}
- ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings);
+ ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings);
try {
spi->spi_iface->poke8(addr, data);
return COMMONERR_OK;
- } catch (const std::exception &e) {
+ } catch (const std::exception& e) {
// TODO: spit out a reasonable error here (that will survive the C API transition)
std::stringstream ss;
ss << "Error in CMB_SPIWriteByte: " << e.what();
- CMB_writeToLog(
- ADIHAL_LOG_ERROR,
+ CMB_writeToLog(ADIHAL_LOG_ERROR,
spiSettings->chipSelectIndex,
ad9371_spi_errors_t::SPI_WRITE_ERROR,
ss.str().c_str());
@@ -99,31 +94,27 @@ commonErr_t CMB_SPIWriteByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t
}
// multi SPI byte write function (address, data pairs)
-commonErr_t CMB_SPIWriteBytes(spiSettings_t *spiSettings, uint16_t *addr, uint8_t *data, uint32_t count)
+commonErr_t CMB_SPIWriteBytes(
+ spiSettings_t* spiSettings, uint16_t* addr, uint8_t* data, uint32_t count)
{
- if (spiSettings == nullptr ||
- addr == nullptr ||
- data == nullptr ||
- spiSettings->MSBFirst == 0)
- {
+ if (spiSettings == nullptr || addr == nullptr || data == nullptr
+ || spiSettings->MSBFirst == 0) {
return COMMONERR_FAILED;
}
- ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings);
+ ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings);
try {
- for (size_t i = 0; i < count; ++i)
- {
+ for (size_t i = 0; i < count; ++i) {
uint32_t data_word = (0) | (addr[i] << 8) | (data[i]);
spi->spi_iface->poke8(addr[i], data[i]);
}
return COMMONERR_OK;
- } catch (const std::exception &e) {
+ } catch (const std::exception& e) {
// TODO: spit out a reasonable error here (that will survive the C API transition)
std::stringstream ss;
ss << "Error in CMB_SPIWriteBytes: " << e.what();
- CMB_writeToLog(
- ADIHAL_LOG_ERROR,
+ CMB_writeToLog(ADIHAL_LOG_ERROR,
spiSettings->chipSelectIndex,
ad9371_spi_errors_t::SPI_WRITE_ERROR,
ss.str().c_str());
@@ -132,25 +123,21 @@ commonErr_t CMB_SPIWriteBytes(spiSettings_t *spiSettings, uint16_t *addr, uint8_
}
// single SPI byte read function
-commonErr_t CMB_SPIReadByte (spiSettings_t *spiSettings, uint16_t addr, uint8_t *readdata)
+commonErr_t CMB_SPIReadByte(spiSettings_t* spiSettings, uint16_t addr, uint8_t* readdata)
{
- if (spiSettings == nullptr ||
- readdata == nullptr ||
- spiSettings->MSBFirst == 0)
- {
+ if (spiSettings == nullptr || readdata == nullptr || spiSettings->MSBFirst == 0) {
return COMMONERR_FAILED;
}
- ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings);
+ ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings);
try {
*readdata = spi->spi_iface->peek8(addr);
return COMMONERR_OK;
- } catch (const std::exception &e) {
+ } catch (const std::exception& e) {
// TODO: spit out a reasonable error here (that will survive the C API transition)
std::stringstream ss;
ss << "Error in CMB_SPIReadByte: " << e.what();
- CMB_writeToLog(
- ADIHAL_LOG_ERROR,
+ CMB_writeToLog(ADIHAL_LOG_ERROR,
spiSettings->chipSelectIndex,
ad9371_spi_errors_t::SPI_READ_ERROR,
ss.str().c_str());
@@ -159,24 +146,24 @@ commonErr_t CMB_SPIReadByte (spiSettings_t *spiSettings, uint16_t addr, uint8_t
}
// write a field in a single register
-commonErr_t CMB_SPIWriteField(
- spiSettings_t *spiSettings,
- uint16_t addr, uint8_t field_val,
- uint8_t mask, uint8_t start_bit
-) {
- ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings);
+commonErr_t CMB_SPIWriteField(spiSettings_t* spiSettings,
+ uint16_t addr,
+ uint8_t field_val,
+ uint8_t mask,
+ uint8_t start_bit)
+{
+ ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings);
try {
uint8_t current_value = spi->spi_iface->peek8(addr);
- uint8_t new_value = ((current_value & ~mask) | (field_val << start_bit));
+ uint8_t new_value = ((current_value & ~mask) | (field_val << start_bit));
spi->spi_iface->poke8(addr, new_value);
return COMMONERR_OK;
- } catch (const std::exception &e) {
+ } catch (const std::exception& e) {
// TODO: spit out a reasonable error here (that will survive the C API transition)
std::stringstream ss;
ss << "Error in CMB_SPIWriteField: " << e.what();
- CMB_writeToLog(
- ADIHAL_LOG_ERROR,
+ CMB_writeToLog(ADIHAL_LOG_ERROR,
spiSettings->chipSelectIndex,
ad9371_spi_errors_t::SPI_WRITE_ERROR,
ss.str().c_str());
@@ -186,23 +173,23 @@ commonErr_t CMB_SPIWriteField(
// read a field in a single register
-commonErr_t CMB_SPIReadField(
- spiSettings_t *spiSettings,
- uint16_t addr, uint8_t *field_val,
- uint8_t mask, uint8_t start_bit
-) {
- ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings);
+commonErr_t CMB_SPIReadField(spiSettings_t* spiSettings,
+ uint16_t addr,
+ uint8_t* field_val,
+ uint8_t mask,
+ uint8_t start_bit)
+{
+ ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings);
try {
uint8_t value = spi->spi_iface->peek8(addr);
- *field_val = static_cast<uint8_t>((value & mask) >> start_bit);
+ *field_val = static_cast<uint8_t>((value & mask) >> start_bit);
return COMMONERR_OK;
- } catch (const std::exception &e) {
+ } catch (const std::exception& e) {
// TODO: spit out a reasonable error here (that will survive the C API transition)
std::stringstream ss;
ss << "Error in CMB_SPIReadField: " << e.what();
- CMB_writeToLog(
- ADIHAL_LOG_ERROR,
+ CMB_writeToLog(ADIHAL_LOG_ERROR,
spiSettings->chipSelectIndex,
ad9371_spi_errors_t::SPI_READ_ERROR,
ss.str().c_str());
@@ -223,35 +210,34 @@ commonErr_t CMB_wait_us(uint32_t time_us)
return COMMONERR_OK;
}
-commonErr_t CMB_setTimeout_ms(spiSettings_t *spiSettings, uint32_t timeOut_ms)
+commonErr_t CMB_setTimeout_ms(spiSettings_t* spiSettings, uint32_t timeOut_ms)
{
- ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings);
- mpm_spi->timeout_start = std::chrono::steady_clock::now();
- mpm_spi->timeout_duration = std::chrono::milliseconds(timeOut_ms);
+ ad9371_spiSettings_t* mpm_spi = ad9371_spiSettings_t::make(spiSettings);
+ mpm_spi->timeout_start = std::chrono::steady_clock::now();
+ mpm_spi->timeout_duration = std::chrono::milliseconds(timeOut_ms);
return COMMONERR_OK;
}
-commonErr_t CMB_setTimeout_us(spiSettings_t *spiSettings, uint32_t timeOut_us)
+commonErr_t CMB_setTimeout_us(spiSettings_t* spiSettings, uint32_t timeOut_us)
{
- ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings);
- mpm_spi->timeout_start = std::chrono::steady_clock::now();
- mpm_spi->timeout_duration = std::chrono::microseconds(timeOut_us);
+ ad9371_spiSettings_t* mpm_spi = ad9371_spiSettings_t::make(spiSettings);
+ mpm_spi->timeout_start = std::chrono::steady_clock::now();
+ mpm_spi->timeout_duration = std::chrono::microseconds(timeOut_us);
return COMMONERR_OK;
}
-commonErr_t CMB_hasTimeoutExpired(spiSettings_t *spiSettings)
+commonErr_t CMB_hasTimeoutExpired(spiSettings_t* spiSettings)
{
- ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings);
- auto current_time = std::chrono::steady_clock::now();
- if ((std::chrono::steady_clock::now() - mpm_spi->timeout_start) > mpm_spi->timeout_duration)
- {
+ ad9371_spiSettings_t* mpm_spi = ad9371_spiSettings_t::make(spiSettings);
+ auto current_time = std::chrono::steady_clock::now();
+ if ((std::chrono::steady_clock::now() - mpm_spi->timeout_start)
+ > mpm_spi->timeout_duration) {
return COMMONERR_FAILED;
- }
- else {
+ } else {
return COMMONERR_OK;
}
}
// platform logging functions
-commonErr_t CMB_openLog(const char *filename)
+commonErr_t CMB_openLog(const char* filename)
{
// not implemented
return COMMONERR_FAILED;
@@ -263,22 +249,17 @@ commonErr_t CMB_closeLog(void)
}
commonErr_t CMB_writeToLog(
- ADI_LOGLEVEL level,
- uint8_t deviceIndex,
- uint32_t errorCode,
- const char *comment
-) {
+ ADI_LOGLEVEL level, uint8_t deviceIndex, uint32_t errorCode, const char* comment)
+{
mpm::types::log_level_t mpm_log_level;
if (level & ADIHAL_LOG_ERROR) {
mpm_log_level = mpm::types::log_level_t::ERROR;
- }
- else if (level & ADIHAL_LOG_WARNING) {
+ } else if (level & ADIHAL_LOG_WARNING) {
mpm_log_level = mpm::types::log_level_t::WARNING;
- }
- else {
+ } else {
mpm_log_level = mpm::types::log_level_t::TRACE;
}
- //FIXME: This caused segfault with the async pattern call to c++ from boost python
+ // FIXME: This caused segfault with the async pattern call to c++ from boost python
// mpm::types::log_buf::make_singleton()->post(
// mpm_log_level,
// "AD937X",
@@ -295,7 +276,7 @@ commonErr_t CMB_flushLog(void)
}
/* platform FPGA AXI register read/write functions */
-commonErr_t CMB_regRead(uint32_t offset, uint32_t *data)
+commonErr_t CMB_regRead(uint32_t offset, uint32_t* data)
{
// not implemented
return COMMONERR_FAILED;
@@ -307,12 +288,12 @@ commonErr_t CMB_regWrite(uint32_t offset, uint32_t data)
}
/* platform DDR3 memory read/write functions */
-commonErr_t CMB_memRead(uint32_t offset, uint32_t *data, uint32_t len)
+commonErr_t CMB_memRead(uint32_t offset, uint32_t* data, uint32_t len)
{
// not implemented
return COMMONERR_FAILED;
}
-commonErr_t CMB_memWrite(uint32_t offset, uint32_t *data, uint32_t len)
+commonErr_t CMB_memWrite(uint32_t offset, uint32_t* data, uint32_t len)
{
// not implemented
return COMMONERR_FAILED;