@@ -164,12 +164,12 @@ int ADIS16448::probe()
164
164
}
165
165
166
166
for (int attempt = 0 ; attempt < 3 ; attempt++) {
167
- const uint16_t PROD_ID = RegisterRead (Register::PROD_ID);
167
+ const uint16_t PROD_ID = RegisterReadVerified (Register::PROD_ID);
168
168
169
169
if (PROD_ID == Product_identification) {
170
- const uint16_t SERIAL_NUM = RegisterRead (Register::SERIAL_NUM);
171
- const uint16_t LOT_ID1 = RegisterRead (Register::LOT_ID1);
172
- const uint16_t LOT_ID2 = RegisterRead (Register::LOT_ID2);
170
+ const uint16_t SERIAL_NUM = RegisterReadVerified (Register::SERIAL_NUM);
171
+ const uint16_t LOT_ID1 = RegisterReadVerified (Register::LOT_ID1);
172
+ const uint16_t LOT_ID2 = RegisterReadVerified (Register::LOT_ID2);
173
173
174
174
PX4_INFO (" Serial Number: 0x%02x, Lot ID1: 0x%02x ID2: 0x%02x" , SERIAL_NUM, LOT_ID1, LOT_ID2);
175
175
@@ -201,7 +201,7 @@ void ADIS16448::RunImpl()
201
201
case STATE::WAIT_FOR_RESET:
202
202
203
203
if (_self_test_passed) {
204
- if ((RegisterRead (Register::PROD_ID) == Product_identification)) {
204
+ if ((RegisterReadVerified (Register::PROD_ID) == Product_identification)) {
205
205
// if reset succeeded then configure
206
206
_state = STATE::CONFIGURE;
207
207
ScheduleNow ();
@@ -228,7 +228,7 @@ void ADIS16448::RunImpl()
228
228
break ;
229
229
230
230
case STATE::SELF_TEST_CHECK: {
231
- const uint16_t MSC_CTRL = RegisterRead (Register::MSC_CTRL);
231
+ const uint16_t MSC_CTRL = RegisterReadVerified (Register::MSC_CTRL);
232
232
233
233
if (MSC_CTRL & MSC_CTRL_BIT::Internal_self_test) {
234
234
// self test not finished, check again
@@ -248,7 +248,7 @@ void ADIS16448::RunImpl()
248
248
249
249
bool test_passed = true ;
250
250
251
- const uint16_t DIAG_STAT = RegisterRead (Register::DIAG_STAT);
251
+ const uint16_t DIAG_STAT = RegisterReadVerified (Register::DIAG_STAT);
252
252
253
253
if (DIAG_STAT & DIAG_STAT_BIT::Self_test_diagnostic_error_flag) {
254
254
PX4_ERR (" self test failed" );
@@ -493,7 +493,7 @@ void ADIS16448::RunImpl()
493
493
494
494
bool ADIS16448::Configure ()
495
495
{
496
- const uint16_t LOT_ID1 = RegisterRead (Register::LOT_ID1);
496
+ const uint16_t LOT_ID1 = RegisterReadVerified (Register::LOT_ID1);
497
497
498
498
// Only enable CRC-16 for verified lots (HACK to support older ADIS16448AMLZ with no explicit detection)
499
499
if (LOT_ID1 == 0x1824 ) {
@@ -619,7 +619,7 @@ bool ADIS16448::RegisterCheck(const register_config_t ®_cfg)
619
619
{
620
620
bool success = true ;
621
621
622
- const uint16_t reg_value = RegisterRead (reg_cfg.reg );
622
+ const uint16_t reg_value = RegisterReadVerified (reg_cfg.reg );
623
623
624
624
if (reg_cfg.set_bits && ((reg_value & reg_cfg.set_bits ) != reg_cfg.set_bits )) {
625
625
PX4_DEBUG (" 0x%02hhX: 0x%02hhX (0x%02hhX not set)" , (uint8_t )reg_cfg.reg , reg_value, reg_cfg.set_bits );
@@ -644,10 +644,26 @@ uint16_t ADIS16448::RegisterRead(Register reg)
644
644
transferhword (cmd, nullptr , 1 );
645
645
px4_udelay (SPI_STALL_PERIOD);
646
646
transferhword (nullptr , cmd, 1 );
647
+ px4_udelay (SPI_STALL_PERIOD);
647
648
648
649
return cmd[0 ];
649
650
}
650
651
652
+ uint16_t ADIS16448::RegisterReadVerified (Register reg, int retries)
653
+ {
654
+ for (int attempt = 0 ; attempt < retries; attempt++) {
655
+ uint16_t read1 = RegisterRead (reg);
656
+ uint16_t read2 = RegisterRead (reg);
657
+
658
+ if (read1 == read2) {
659
+ return read1;
660
+ }
661
+ }
662
+
663
+ // failed
664
+ return 0 ;
665
+ }
666
+
651
667
void ADIS16448::RegisterWrite (Register reg, uint16_t value)
652
668
{
653
669
set_frequency (SPI_SPEED);
@@ -659,11 +675,12 @@ void ADIS16448::RegisterWrite(Register reg, uint16_t value)
659
675
transferhword (cmd, nullptr , 1 );
660
676
px4_udelay (SPI_STALL_PERIOD);
661
677
transferhword (cmd + 1 , nullptr , 1 );
678
+ px4_udelay (SPI_STALL_PERIOD);
662
679
}
663
680
664
681
void ADIS16448::RegisterSetAndClearBits (Register reg, uint16_t setbits, uint16_t clearbits)
665
682
{
666
- const uint16_t orig_val = RegisterRead (reg);
683
+ const uint16_t orig_val = RegisterReadVerified (reg);
667
684
668
685
uint16_t val = (orig_val & ~clearbits) | setbits;
669
686
0 commit comments