AP_Compass: use take_blocking instead of HAL_SEMAPHORE_BLOCK_FOREVER
this makes for cleaner and smaller code as the failure case is not needed
This commit is contained in:
parent
8f867ddb2b
commit
4ee6fb9cdf
@ -104,9 +104,7 @@ AP_Compass_Backend *AP_Compass_AK09916::probe_ICM20948(AP_HAL::OwnPtr<AP_HAL::I2
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return nullptr;
|
||||
}
|
||||
dev->get_semaphore()->take_blocking();
|
||||
|
||||
/* Allow ICM20x48 to shortcut auxiliary bus and host bus */
|
||||
uint8_t rval;
|
||||
@ -192,9 +190,10 @@ bool AP_Compass_AK09916::init()
|
||||
{
|
||||
AP_HAL::Semaphore *bus_sem = _bus->get_semaphore();
|
||||
|
||||
if (!bus_sem || !_bus->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
if (!bus_sem) {
|
||||
return false;
|
||||
}
|
||||
_bus->get_semaphore()->take_blocking();
|
||||
|
||||
if (!_bus->configure()) {
|
||||
hal.console->printf("AK09916: Could not configure the bus\n");
|
||||
|
@ -122,10 +122,11 @@ bool AP_Compass_AK8963::init()
|
||||
{
|
||||
AP_HAL::Semaphore *bus_sem = _bus->get_semaphore();
|
||||
|
||||
if (!bus_sem || !_bus->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
if (!bus_sem) {
|
||||
hal.console->printf("AK8963: Unable to get bus semaphore\n");
|
||||
return false;
|
||||
}
|
||||
_bus->get_semaphore()->take_blocking();
|
||||
|
||||
if (!_bus->configure()) {
|
||||
hal.console->printf("AK8963: Could not configure the bus\n");
|
||||
|
@ -142,10 +142,7 @@ bool AP_Compass_BMM150::init()
|
||||
uint8_t val = 0;
|
||||
bool ret;
|
||||
|
||||
if (!_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
hal.console->printf("BMM150: Unable to get bus semaphore\n");
|
||||
return false;
|
||||
}
|
||||
_dev->get_semaphore()->take_blocking();
|
||||
|
||||
// 10 retries for init
|
||||
_dev->set_retries(10);
|
||||
|
@ -152,10 +152,11 @@ bool AP_Compass_HMC5843::init()
|
||||
{
|
||||
AP_HAL::Semaphore *bus_sem = _bus->get_semaphore();
|
||||
|
||||
if (!bus_sem || !bus_sem->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
if (!bus_sem) {
|
||||
hal.console->printf("HMC5843: Unable to get bus semaphore\n");
|
||||
return false;
|
||||
}
|
||||
bus_sem->take_blocking();
|
||||
|
||||
// high retries for init
|
||||
_bus->set_retries(10);
|
||||
|
@ -109,9 +109,7 @@ bool AP_Compass_IST8308::init()
|
||||
{
|
||||
uint8_t reset_count = 0;
|
||||
|
||||
if (!_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
_dev->get_semaphore()->take_blocking();
|
||||
|
||||
// high retries for init
|
||||
_dev->set_retries(10);
|
||||
|
@ -105,9 +105,7 @@ bool AP_Compass_IST8310::init()
|
||||
{
|
||||
uint8_t reset_count = 0;
|
||||
|
||||
if (!_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
_dev->get_semaphore()->take_blocking();
|
||||
|
||||
// high retries for init
|
||||
_dev->set_retries(10);
|
||||
|
@ -75,9 +75,7 @@ AP_Compass_LIS3MDL::AP_Compass_LIS3MDL(AP_HAL::OwnPtr<AP_HAL::Device> _dev,
|
||||
|
||||
bool AP_Compass_LIS3MDL::init()
|
||||
{
|
||||
if (!dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
dev->get_semaphore()->take_blocking();
|
||||
|
||||
if (dev->bus_type() == AP_HAL::Device::BUS_TYPE_SPI) {
|
||||
dev->set_read_flag(0xC0);
|
||||
|
@ -282,9 +282,7 @@ bool AP_Compass_LSM303D::init(enum Rotation rotation)
|
||||
|
||||
bool AP_Compass_LSM303D::_hardware_init()
|
||||
{
|
||||
if (!_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
AP_HAL::panic("LSM303D: Unable to get semaphore");
|
||||
}
|
||||
_dev->get_semaphore()->take_blocking();
|
||||
|
||||
// initially run the bus at low speed
|
||||
_dev->set_speed(AP_HAL::Device::SPEED_LOW);
|
||||
|
@ -83,10 +83,11 @@ bool AP_Compass_LSM9DS1::init()
|
||||
{
|
||||
AP_HAL::Semaphore *bus_sem = _dev->get_semaphore();
|
||||
|
||||
if (!bus_sem || !bus_sem->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
if (!bus_sem) {
|
||||
hal.console->printf("LSM9DS1: Unable to get bus semaphore\n");
|
||||
return false;
|
||||
}
|
||||
bus_sem->take_blocking();
|
||||
|
||||
if (!_check_id()) {
|
||||
hal.console->printf("LSM9DS1: Could not check id\n");
|
||||
|
@ -135,9 +135,7 @@ bool AP_Compass_MAG3110::_hardware_init()
|
||||
{
|
||||
|
||||
AP_HAL::Semaphore *bus_sem = _dev->get_semaphore();
|
||||
if (!bus_sem->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
AP_HAL::panic("MAG3110: Unable to get semaphore");
|
||||
}
|
||||
bus_sem->take_blocking();
|
||||
|
||||
// initially run the bus at low speed
|
||||
_dev->set_speed(AP_HAL::Device::SPEED_LOW);
|
||||
|
@ -68,9 +68,7 @@ AP_Compass_MMC3416::AP_Compass_MMC3416(AP_HAL::OwnPtr<AP_HAL::Device> _dev,
|
||||
|
||||
bool AP_Compass_MMC3416::init()
|
||||
{
|
||||
if (!dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
dev->get_semaphore()->take_blocking();
|
||||
|
||||
dev->set_retries(10);
|
||||
|
||||
|
@ -85,9 +85,7 @@ AP_Compass_QMC5883L::AP_Compass_QMC5883L(AP_HAL::OwnPtr<AP_HAL::Device> dev,
|
||||
|
||||
bool AP_Compass_QMC5883L::init()
|
||||
{
|
||||
if (!_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
_dev->get_semaphore()->take_blocking();
|
||||
|
||||
_dev->set_retries(10);
|
||||
|
||||
|
@ -93,9 +93,7 @@ AP_Compass_RM3100::AP_Compass_RM3100(AP_HAL::OwnPtr<AP_HAL::Device> _dev,
|
||||
|
||||
bool AP_Compass_RM3100::init()
|
||||
{
|
||||
if (!dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
dev->get_semaphore()->take_blocking();
|
||||
|
||||
if (dev->bus_type() == AP_HAL::Device::BUS_TYPE_SPI) {
|
||||
// read has high bit set for SPI
|
||||
|
Loading…
Reference in New Issue
Block a user