HAL_ChibiOS: check bus owner on all SPI transfers

This commit is contained in:
Andrew Tridgell 2021-04-15 18:04:58 +10:00 committed by Peter Barker
parent 6a12b612b1
commit 4118a3eb03

View File

@ -229,7 +229,9 @@ bool SPIDevice::clock_pulse(uint32_t n)
acquire_bus(false, true); acquire_bus(false, true);
bus.semaphore.give(); bus.semaphore.give();
} else { } else {
bus.semaphore.assert_owner(); if (!bus.semaphore.check_owner()) {
return false;
}
spiIgnore(spi_devices[device_desc.bus].driver, n); spiIgnore(spi_devices[device_desc.bus].driver, n);
} }
return true; return true;
@ -269,7 +271,6 @@ bool SPIDevice::transfer(const uint8_t *send, uint32_t send_len,
uint8_t *recv, uint32_t recv_len) uint8_t *recv, uint32_t recv_len)
{ {
if (!bus.semaphore.check_owner()) { if (!bus.semaphore.check_owner()) {
hal.console->printf("SPI: not owner of 0x%x\n", unsigned(get_bus_id()));
return false; return false;
} }
if ((send_len == recv_len && send == recv) || !send || !recv) { if ((send_len == recv_len && send == recv) || !send || !recv) {
@ -292,7 +293,9 @@ bool SPIDevice::transfer(const uint8_t *send, uint32_t send_len,
bool SPIDevice::transfer_fullduplex(const uint8_t *send, uint8_t *recv, uint32_t len) bool SPIDevice::transfer_fullduplex(const uint8_t *send, uint8_t *recv, uint32_t len)
{ {
bus.semaphore.assert_owner(); if (!bus.semaphore.check_owner()) {
return false;
}
uint8_t buf[len]; uint8_t buf[len];
memcpy(buf, send, len); memcpy(buf, send, len);
bool ret = do_transfer(buf, buf, len); bool ret = do_transfer(buf, buf, len);
@ -323,7 +326,9 @@ bool SPIDevice::adjust_periodic_callback(AP_HAL::Device::PeriodicHandle h, uint3
*/ */
bool SPIDevice::acquire_bus(bool set, bool skip_cs) bool SPIDevice::acquire_bus(bool set, bool skip_cs)
{ {
bus.semaphore.assert_owner(); if (!bus.semaphore.check_owner()) {
return false;
}
if (set && cs_forced) { if (set && cs_forced) {
return true; return true;
} }