AP_HAL_ChibiOS: revert to ChibiOS SPI driver model v1

This commit is contained in:
Andy Piper 2023-03-30 12:43:02 +01:00 committed by Andrew Tridgell
parent 10c74f3a44
commit 34411809d3

View File

@ -205,7 +205,7 @@ bool SPIDevice::do_transfer(const uint8_t *send, uint8_t *recv, uint32_t len)
// expect this timeout to trigger unless there is a severe MCU // expect this timeout to trigger unless there is a severe MCU
// error // error
const uint32_t timeout_us = 20000U + len * 32U; const uint32_t timeout_us = 20000U + len * 32U;
msg_t msg = osalThreadSuspendTimeoutS(&spi_devices[device_desc.bus].driver->sync_transfer, TIME_US2I(timeout_us)); msg_t msg = osalThreadSuspendTimeoutS(&spi_devices[device_desc.bus].driver->thread, TIME_US2I(timeout_us));
osalSysUnlock(); osalSysUnlock();
if (msg == MSG_TIMEOUT) { if (msg == MSG_TIMEOUT) {
ret = false; ret = false;
@ -233,7 +233,7 @@ bool SPIDevice::clock_pulse(uint32_t n)
acquire_bus(true, true); acquire_bus(true, true);
osalSysLock(); osalSysLock();
spiStartIgnoreI(spi_devices[device_desc.bus].driver, n); spiStartIgnoreI(spi_devices[device_desc.bus].driver, n);
msg = osalThreadSuspendTimeoutS(&spi_devices[device_desc.bus].driver->sync_transfer, TIME_US2I(timeout_us)); msg = osalThreadSuspendTimeoutS(&spi_devices[device_desc.bus].driver->thread, TIME_US2I(timeout_us));
osalSysUnlock(); osalSysUnlock();
if (msg == MSG_TIMEOUT) { if (msg == MSG_TIMEOUT) {
spiAbort(spi_devices[device_desc.bus].driver); spiAbort(spi_devices[device_desc.bus].driver);
@ -246,7 +246,7 @@ bool SPIDevice::clock_pulse(uint32_t n)
} }
osalSysLock(); osalSysLock();
spiStartIgnoreI(spi_devices[device_desc.bus].driver, n); spiStartIgnoreI(spi_devices[device_desc.bus].driver, n);
msg = osalThreadSuspendTimeoutS(&spi_devices[device_desc.bus].driver->sync_transfer, TIME_US2I(timeout_us)); msg = osalThreadSuspendTimeoutS(&spi_devices[device_desc.bus].driver->thread, TIME_US2I(timeout_us));
osalSysUnlock(); osalSysUnlock();
if (msg == MSG_TIMEOUT) { if (msg == MSG_TIMEOUT) {
spiAbort(spi_devices[device_desc.bus].driver); spiAbort(spi_devices[device_desc.bus].driver);
@ -365,18 +365,16 @@ bool SPIDevice::acquire_bus(bool set, bool skip_cs)
spiAcquireBus(spi_devices[device_desc.bus].driver); /* Acquire ownership of the bus. */ spiAcquireBus(spi_devices[device_desc.bus].driver); /* Acquire ownership of the bus. */
bus.spicfg.ssport = PAL_PORT(device_desc.pal_line); bus.spicfg.ssport = PAL_PORT(device_desc.pal_line);
bus.spicfg.sspad = PAL_PAD(device_desc.pal_line); bus.spicfg.sspad = PAL_PAD(device_desc.pal_line);
bus.spicfg.data_cb = nullptr; bus.spicfg.end_cb = nullptr;
bus.spicfg.error_cb = nullptr;
bus.spicfg.slave = false;
#if defined(STM32H7) #if defined(STM32H7)
bus.spicfg.cfg1 = freq_flag; bus.spicfg.cfg1 = freq_flag;
bus.spicfg.cfg2 = device_desc.mode; bus.spicfg.cfg2 = device_desc.mode;
if (bus.spicfg.txsource == nullptr) { if (bus.spicfg.dummytx == nullptr) {
bus.spicfg.txsource = (uint32_t *)malloc_dma(4); bus.spicfg.dummytx = (uint32_t *)malloc_dma(4);
memset(bus.spicfg.txsource, 0xFF, 4); memset(bus.spicfg.dummytx, 0xFF, 4);
} }
if (bus.spicfg.rxsink == nullptr) { if (bus.spicfg.dummyrx == nullptr) {
bus.spicfg.rxsink = (uint32_t *)malloc_dma(4); bus.spicfg.dummyrx = (uint32_t *)malloc_dma(4);
} }
#else #else
bus.spicfg.cr1 = (uint16_t)(freq_flag | device_desc.mode); bus.spicfg.cr1 = (uint16_t)(freq_flag | device_desc.mode);
@ -502,7 +500,7 @@ void SPIDevice::test_clock_freq(void)
uint32_t t0 = AP_HAL::micros(); uint32_t t0 = AP_HAL::micros();
spiStartExchange(spi_devices[i].driver, len, buf1, buf2); spiStartExchange(spi_devices[i].driver, len, buf1, buf2);
chSysLock(); chSysLock();
msg_t msg = osalThreadSuspendTimeoutS(&spi_devices[i].driver->sync_transfer, chTimeMS2I(100)); msg_t msg = osalThreadSuspendTimeoutS(&spi_devices[i].driver->thread, chTimeMS2I(100));
chSysUnlock(); chSysUnlock();
if (msg == MSG_TIMEOUT) { if (msg == MSG_TIMEOUT) {
spiAbort(spi_devices[i].driver); spiAbort(spi_devices[i].driver);