@@ -105,6 +105,7 @@ ADIS16448::ADIS16448(I2CSPIBusOption bus_option, int bus, uint32_t device, enum
105
105
_px4_gyro(get_device_id(), rotation),
106
106
_px4_mag(get_device_id(), rotation)
107
107
{
108
+ _debug_enabled = true ;
108
109
}
109
110
110
111
ADIS16448::~ADIS16448 ()
@@ -160,12 +161,12 @@ int ADIS16448::probe()
160
161
}
161
162
162
163
for (int attempt = 0 ; attempt < 3 ; attempt++) {
163
- const uint16_t PROD_ID = RegisterRead (Register::PROD_ID);
164
+ const uint16_t PROD_ID = RegisterReadVerified (Register::PROD_ID);
164
165
165
166
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);
167
+ const uint16_t SERIAL_NUM = RegisterReadVerified (Register::SERIAL_NUM);
168
+ const uint16_t LOT_ID1 = RegisterReadVerified (Register::LOT_ID1);
169
+ const uint16_t LOT_ID2 = RegisterReadVerified (Register::LOT_ID2);
169
170
170
171
PX4_INFO (" Serial Number: 0x%02x, Lot ID1: 0x%02x ID2: 0x%02x" , SERIAL_NUM, LOT_ID1, LOT_ID2);
171
172
@@ -197,7 +198,7 @@ void ADIS16448::RunImpl()
197
198
case STATE::WAIT_FOR_RESET:
198
199
199
200
if (_self_test_passed) {
200
- if ((RegisterRead (Register::PROD_ID) == Product_identification)) {
201
+ if ((RegisterReadVerified (Register::PROD_ID) == Product_identification)) {
201
202
// if reset succeeded then configure
202
203
_state = STATE::CONFIGURE;
203
204
ScheduleNow ();
@@ -224,7 +225,7 @@ void ADIS16448::RunImpl()
224
225
break ;
225
226
226
227
case STATE::SELF_TEST_CHECK: {
227
- const uint16_t MSC_CTRL = RegisterRead (Register::MSC_CTRL);
228
+ const uint16_t MSC_CTRL = RegisterReadVerified (Register::MSC_CTRL);
228
229
229
230
if (MSC_CTRL & MSC_CTRL_BIT::Internal_self_test) {
230
231
// self test not finished, check again
@@ -244,7 +245,7 @@ void ADIS16448::RunImpl()
244
245
245
246
bool test_passed = true ;
246
247
247
- const uint16_t DIAG_STAT = RegisterRead (Register::DIAG_STAT);
248
+ const uint16_t DIAG_STAT = RegisterReadVerified (Register::DIAG_STAT);
248
249
249
250
if (DIAG_STAT & DIAG_STAT_BIT::Self_test_diagnostic_error_flag) {
250
251
PX4_ERR (" self test failed" );
@@ -477,7 +478,7 @@ void ADIS16448::RunImpl()
477
478
478
479
bool ADIS16448::Configure ()
479
480
{
480
- const uint16_t LOT_ID1 = RegisterRead (Register::LOT_ID1);
481
+ const uint16_t LOT_ID1 = RegisterReadVerified (Register::LOT_ID1);
481
482
482
483
// Only enable CRC-16 for verified lots (HACK to support older ADIS16448AMLZ with no explicit detection)
483
484
if (LOT_ID1 == 0x1824 ) {
@@ -603,7 +604,7 @@ bool ADIS16448::RegisterCheck(const register_config_t ®_cfg)
603
604
{
604
605
bool success = true ;
605
606
606
- const uint16_t reg_value = RegisterRead (reg_cfg.reg );
607
+ const uint16_t reg_value = RegisterReadVerified (reg_cfg.reg );
607
608
608
609
if (reg_cfg.set_bits && ((reg_value & reg_cfg.set_bits ) != reg_cfg.set_bits )) {
609
610
PX4_DEBUG (" 0x%02hhX: 0x%02hhX (0x%02hhX not set)" , (uint8_t )reg_cfg.reg , reg_value, reg_cfg.set_bits );
@@ -628,10 +629,27 @@ uint16_t ADIS16448::RegisterRead(Register reg)
628
629
transferhword (cmd, nullptr , 1 );
629
630
px4_udelay (SPI_STALL_PERIOD);
630
631
transferhword (nullptr , cmd, 1 );
632
+ px4_udelay (SPI_STALL_PERIOD);
631
633
632
634
return cmd[0 ];
633
635
}
634
636
637
+ uint16_t ADIS16448::RegisterReadVerified (Register reg)
638
+ {
639
+ // 3 attempts
640
+ for (int i = 0 ; i < 3 ; i++) {
641
+ uint16_t read1 = RegisterRead (reg);
642
+ uint16_t read2 = RegisterRead (reg);
643
+
644
+ if (read1 == read2) {
645
+ return read1;
646
+ }
647
+ }
648
+
649
+ // failed
650
+ return 0 ;
651
+ }
652
+
635
653
void ADIS16448::RegisterWrite (Register reg, uint16_t value)
636
654
{
637
655
set_frequency (SPI_SPEED);
@@ -643,11 +661,12 @@ void ADIS16448::RegisterWrite(Register reg, uint16_t value)
643
661
transferhword (cmd, nullptr , 1 );
644
662
px4_udelay (SPI_STALL_PERIOD);
645
663
transferhword (cmd + 1 , nullptr , 1 );
664
+ px4_udelay (SPI_STALL_PERIOD);
646
665
}
647
666
648
667
void ADIS16448::RegisterSetAndClearBits (Register reg, uint16_t setbits, uint16_t clearbits)
649
668
{
650
- const uint16_t orig_val = RegisterRead (reg);
669
+ const uint16_t orig_val = RegisterReadVerified (reg);
651
670
652
671
uint16_t val = (orig_val & ~clearbits) | setbits;
653
672
0 commit comments