AP_HAL: remember details of register check fails

this allows for logging of register resets
This commit is contained in:
Andrew Tridgell 2021-02-24 09:39:38 +11:00 committed by Peter Barker
parent 85ef6b7ac6
commit 7010eae9e8
2 changed files with 34 additions and 10 deletions

View File

@ -109,6 +109,7 @@ bool AP_HAL::Device::check_next_register(void)
(unsigned)get_bus_id(),
(unsigned)reg.bank);
#endif
_checked.last_reg_fail = reg;
return false;
}
}
@ -123,8 +124,22 @@ bool AP_HAL::Device::check_next_register(void)
(unsigned)reg.regnum, (unsigned)v, (unsigned)reg.value);
#endif
write_register(reg.regnum, reg.value);
_checked.last_reg_fail = reg;
_checked.last_reg_fail.value = v;
return false;
}
_checked.next = (_checked.next+1) % _checked.n_set;
return true;
}
/*
check one register value, returning information on the failure
*/
bool AP_HAL::Device::check_next_register(struct checkreg &fail)
{
if (check_next_register()) {
return true;
}
fail = _checked.last_reg_fail;
return false;
}

View File

@ -201,6 +201,20 @@ public:
*/
bool check_next_register(void);
// checked registers
struct checkreg {
uint8_t bank;
uint8_t regnum;
uint8_t value;
};
/**
* check next register value for correctness, with return of
* failure value. Return false if value is incorrect or register
* checking has not been setup
*/
bool check_next_register(struct checkreg &fail);
/**
* Wrapper function over #transfer() to read a sequence of bytes from
* device. No value is written, differently from the #read_registers()
@ -390,18 +404,13 @@ protected:
private:
BankSelectCb _bank_select;
// checked registers
struct checkreg {
uint8_t bank;
uint8_t regnum;
uint8_t value;
};
struct {
uint8_t n_allocated;
uint8_t n_set;
uint8_t next;
uint8_t frequency;
uint8_t counter;
struct checkreg last_reg_fail;
struct checkreg *regs;
} _checked;
};