Skip to content

Commit a65a591

Browse files
dagaracfloria
authored andcommitted
adis16448: add additional delay after transfer in case of back to back transcations
- add verified register read method
1 parent 01307a4 commit a65a591

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

src/drivers/imu/analog_devices/adis16448/ADIS16448.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ ADIS16448::ADIS16448(I2CSPIBusOption bus_option, int bus, uint32_t device, enum
105105
_px4_gyro(get_device_id(), rotation),
106106
_px4_mag(get_device_id(), rotation)
107107
{
108+
_debug_enabled = true;
109+
110+
if (_drdy_gpio != 0) {
111+
_drdy_missed_perf = perf_alloc(PC_COUNT, MODULE_NAME": DRDY missed");
112+
}
108113
}
109114

110115
ADIS16448::~ADIS16448()
@@ -160,12 +165,12 @@ int ADIS16448::probe()
160165
}
161166

162167
for (int attempt = 0; attempt < 3; attempt++) {
163-
const uint16_t PROD_ID = RegisterRead(Register::PROD_ID);
168+
const uint16_t PROD_ID = RegisterReadVerified(Register::PROD_ID);
164169

165170
if (PROD_ID == Product_identification) {
166-
const uint16_t SERIAL_NUM = RegisterRead(Register::SERIAL_NUM);
167-
const uint16_t LOT_ID1 = RegisterRead(Register::LOT_ID1);
168-
const uint16_t LOT_ID2 = RegisterRead(Register::LOT_ID2);
171+
const uint16_t SERIAL_NUM = RegisterReadVerified(Register::SERIAL_NUM);
172+
const uint16_t LOT_ID1 = RegisterReadVerified(Register::LOT_ID1);
173+
const uint16_t LOT_ID2 = RegisterReadVerified(Register::LOT_ID2);
169174

170175
PX4_INFO("Serial Number: 0x%02x, Lot ID1: 0x%02x ID2: 0x%02x", SERIAL_NUM, LOT_ID1, LOT_ID2);
171176

@@ -197,7 +202,7 @@ void ADIS16448::RunImpl()
197202
case STATE::WAIT_FOR_RESET:
198203

199204
if (_self_test_passed) {
200-
if ((RegisterRead(Register::PROD_ID) == Product_identification)) {
205+
if ((RegisterReadVerified(Register::PROD_ID) == Product_identification)) {
201206
// if reset succeeded then configure
202207
_state = STATE::CONFIGURE;
203208
ScheduleNow();
@@ -224,7 +229,7 @@ void ADIS16448::RunImpl()
224229
break;
225230

226231
case STATE::SELF_TEST_CHECK: {
227-
const uint16_t MSC_CTRL = RegisterRead(Register::MSC_CTRL);
232+
const uint16_t MSC_CTRL = RegisterReadVerified(Register::MSC_CTRL);
228233

229234
if (MSC_CTRL & MSC_CTRL_BIT::Internal_self_test) {
230235
// self test not finished, check again
@@ -244,7 +249,7 @@ void ADIS16448::RunImpl()
244249

245250
bool test_passed = true;
246251

247-
const uint16_t DIAG_STAT = RegisterRead(Register::DIAG_STAT);
252+
const uint16_t DIAG_STAT = RegisterReadVerified(Register::DIAG_STAT);
248253

249254
if (DIAG_STAT & DIAG_STAT_BIT::Self_test_diagnostic_error_flag) {
250255
PX4_ERR("self test failed");
@@ -477,7 +482,7 @@ void ADIS16448::RunImpl()
477482

478483
bool ADIS16448::Configure()
479484
{
480-
const uint16_t LOT_ID1 = RegisterRead(Register::LOT_ID1);
485+
const uint16_t LOT_ID1 = RegisterReadVerified(Register::LOT_ID1);
481486

482487
// Only enable CRC-16 for verified lots (HACK to support older ADIS16448AMLZ with no explicit detection)
483488
if (LOT_ID1 == 0x1824) {
@@ -603,7 +608,7 @@ bool ADIS16448::RegisterCheck(const register_config_t &reg_cfg)
603608
{
604609
bool success = true;
605610

606-
const uint16_t reg_value = RegisterRead(reg_cfg.reg);
611+
const uint16_t reg_value = RegisterReadVerified(reg_cfg.reg);
607612

608613
if (reg_cfg.set_bits && ((reg_value & reg_cfg.set_bits) != reg_cfg.set_bits)) {
609614
PX4_DEBUG("0x%02hhX: 0x%02hhX (0x%02hhX not set)", (uint8_t)reg_cfg.reg, reg_value, reg_cfg.set_bits);
@@ -628,10 +633,27 @@ uint16_t ADIS16448::RegisterRead(Register reg)
628633
transferhword(cmd, nullptr, 1);
629634
px4_udelay(SPI_STALL_PERIOD);
630635
transferhword(nullptr, cmd, 1);
636+
px4_udelay(SPI_STALL_PERIOD);
631637

632638
return cmd[0];
633639
}
634640

641+
uint16_t ADIS16448::RegisterReadVerified(Register reg)
642+
{
643+
// 3 attempts
644+
for (int i = 0; i < 3; i++) {
645+
uint16_t read1 = RegisterRead(reg);
646+
uint16_t read2 = RegisterRead(reg);
647+
648+
if (read1 == read2) {
649+
return read1;
650+
}
651+
}
652+
653+
// failed
654+
return 0;
655+
}
656+
635657
void ADIS16448::RegisterWrite(Register reg, uint16_t value)
636658
{
637659
set_frequency(SPI_SPEED);
@@ -643,11 +665,12 @@ void ADIS16448::RegisterWrite(Register reg, uint16_t value)
643665
transferhword(cmd, nullptr, 1);
644666
px4_udelay(SPI_STALL_PERIOD);
645667
transferhword(cmd + 1, nullptr, 1);
668+
px4_udelay(SPI_STALL_PERIOD);
646669
}
647670

648671
void ADIS16448::RegisterSetAndClearBits(Register reg, uint16_t setbits, uint16_t clearbits)
649672
{
650-
const uint16_t orig_val = RegisterRead(reg);
673+
const uint16_t orig_val = RegisterReadVerified(reg);
651674

652675
uint16_t val = (orig_val & ~clearbits) | setbits;
653676

src/drivers/imu/analog_devices/adis16448/ADIS16448.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ADIS16448 : public device::SPI, public I2CSPIDriver<ADIS16448>
9494
bool RegisterCheck(const register_config_t &reg_cfg);
9595

9696
uint16_t RegisterRead(Register reg);
97+
uint16_t RegisterReadVerified(Register reg);
9798
void RegisterWrite(Register reg, uint16_t value);
9899
void RegisterSetAndClearBits(Register reg, uint16_t setbits, uint16_t clearbits);
99100

src/drivers/imu/analog_devices/adis16448/Analog_Devices_ADIS16448_registers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace Analog_Devices_ADIS16448
6565
static constexpr uint32_t SPI_SPEED = 2 * 1000 * 1000; // 2 MHz SPI serial interface
6666
static constexpr uint32_t SPI_SPEED_BURST = 1 * 1000 * 1000; // 1 MHz SPI serial interface for burst read
6767

68-
static constexpr uint32_t SPI_STALL_PERIOD = 10; // 9 us Stall period between data
68+
static constexpr uint32_t SPI_STALL_PERIOD = 11; // 9 us Stall period between data
6969

7070
static constexpr uint16_t DIR_WRITE = 0x80;
7171

src/drivers/imu/analog_devices/adis16448/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ px4_add_module(
3636
MAIN adis16448
3737
COMPILE_FLAGS
3838
${MAX_CUSTOM_OPT_LEVEL}
39-
#-DDEBUG_BUILD
39+
-DDEBUG_BUILD
4040
SRCS
4141
ADIS16448.cpp
4242
ADIS16448.hpp

0 commit comments

Comments
 (0)