From 0bda21a3fc5a73f13df4d63d4f8622706dcec813 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 28 Oct 2013 18:20:20 +1100 Subject: [PATCH] HAL_AVR: changed to 16 byte bulk transfer on SPI0 --- libraries/AP_HAL_AVR/SPIDevice_SPI0.cpp | 13 +++++++------ libraries/AP_HAL_AVR/SPIDevices.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/AP_HAL_AVR/SPIDevice_SPI0.cpp b/libraries/AP_HAL_AVR/SPIDevice_SPI0.cpp index 853c1b024d..e52b95421c 100644 --- a/libraries/AP_HAL_AVR/SPIDevice_SPI0.cpp +++ b/libraries/AP_HAL_AVR/SPIDevice_SPI0.cpp @@ -76,7 +76,7 @@ uint8_t AVRSPI0DeviceDriver::_transfer(uint8_t data) a specialised transfer function for the MPU6k. This saves 2 usec per byte */ -void AVRSPI0DeviceDriver::_transfer15(const uint8_t *tx, uint8_t *rx) +void AVRSPI0DeviceDriver::_transfer16(const uint8_t *tx, uint8_t *rx) { spi0_transferflag = true; #define TRANSFER1(i) do { SPDR = tx[i]; while(!(SPSR & _BV(SPIF))); rx[i] = SPDR; } while(0) @@ -95,6 +95,7 @@ void AVRSPI0DeviceDriver::_transfer15(const uint8_t *tx, uint8_t *rx) TRANSFER1(12); TRANSFER1(13); TRANSFER1(14); + TRANSFER1(15); spi0_transferflag = false; } @@ -112,11 +113,11 @@ void AVRSPI0DeviceDriver::transaction(const uint8_t *tx, uint8_t *rx, _transfer(tx[i]); } } else { - while (len >= 15) { - _transfer15(tx, rx); - tx += 15; - rx += 15; - len -= 15; + while (len >= 16) { + _transfer16(tx, rx); + tx += 16; + rx += 16; + len -= 16; } for (uint16_t i = 0; i < len; i++) { rx[i] = _transfer(tx[i]); diff --git a/libraries/AP_HAL_AVR/SPIDevices.h b/libraries/AP_HAL_AVR/SPIDevices.h index 7eb1ed6e5f..021fd645ce 100644 --- a/libraries/AP_HAL_AVR/SPIDevices.h +++ b/libraries/AP_HAL_AVR/SPIDevices.h @@ -36,7 +36,7 @@ private: void _cs_release(); uint8_t _transfer(uint8_t data); // used for MPU6k - void _transfer15(const uint8_t *tx, uint8_t *rx); + void _transfer16(const uint8_t *tx, uint8_t *rx); static AP_HAL_AVR::AVRSemaphore _semaphore;