From e7feba4e21e8facf96fa8b00531fb9fce698f2c6 Mon Sep 17 00:00:00 2001 From: 0xc0170 Date: Tue, 9 Jun 2015 09:34:48 +0100 Subject: [PATCH] I2C - costness for tx buffer --- libraries/mbed/api/I2C.h | 2 +- libraries/mbed/common/I2C.cpp | 2 +- libraries/mbed/hal/i2c_api.h | 2 +- .../targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/i2c_api.c | 6 +++--- .../targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/mbed/api/I2C.h b/libraries/mbed/api/I2C.h index f925d2419d..9f4866e3e1 100644 --- a/libraries/mbed/api/I2C.h +++ b/libraries/mbed/api/I2C.h @@ -149,7 +149,7 @@ public: * @param repeated Repeated start, true - do not send stop at end * @return Zero if the transfer has started, or -1 if I2C peripheral is busy */ - int transfer(int address, char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false); + int transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false); /** Abort the on-going I2C transfer */ diff --git a/libraries/mbed/common/I2C.cpp b/libraries/mbed/common/I2C.cpp index 5fe61fd5ac..8806a5e6a3 100644 --- a/libraries/mbed/common/I2C.cpp +++ b/libraries/mbed/common/I2C.cpp @@ -92,7 +92,7 @@ void I2C::stop(void) { #if DEVICE_I2C_ASYNCH -int I2C::transfer(int address, char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event, bool repeated) +int I2C::transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event, bool repeated) { if (i2c_active(&_i2c)) { return -1; // transaction ongoing diff --git a/libraries/mbed/hal/i2c_api.h b/libraries/mbed/hal/i2c_api.h index f1765b82e4..978f242d18 100644 --- a/libraries/mbed/hal/i2c_api.h +++ b/libraries/mbed/hal/i2c_api.h @@ -191,7 +191,7 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask); * @param handler The I2C IRQ handler to be set * @param hint DMA hint usage */ -void i2c_transfer_asynch(i2c_t *obj, void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint); +void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint); /** The asynchronous IRQ handler * @param obj The I2C object which holds the transfer information diff --git a/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/i2c_api.c index e4df159ea5..35b645c08b 100644 --- a/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/i2c_api.c @@ -426,7 +426,7 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) * @param handler The I2C IRQ handler to be set * @param hint DMA hint usage */ -void i2c_transfer_asynch(i2c_t *obj, void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint) +void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint) { I2C_TransferReturn_TypeDef retval; if(i2c_active(obj)) return; @@ -440,7 +440,7 @@ void i2c_transfer_asynch(i2c_t *obj, void *tx, size_t tx_length, void *rx, size_ if((tx_length > 0) && (rx_length == 0)) { obj->i2c.xfer.flags = I2C_FLAG_WRITE; //Store buffer info - obj->i2c.xfer.buf[0].data = tx; + obj->i2c.xfer.buf[0].data = (void *)tx; obj->i2c.xfer.buf[0].len = (uint16_t) tx_length; } else if ((tx_length == 0) && (rx_length > 0)) { obj->i2c.xfer.flags = I2C_FLAG_READ; @@ -450,7 +450,7 @@ void i2c_transfer_asynch(i2c_t *obj, void *tx, size_t tx_length, void *rx, size_ } else if ((tx_length > 0) && (rx_length > 0)) { obj->i2c.xfer.flags = I2C_FLAG_WRITE_READ; //Store buffer info - obj->i2c.xfer.buf[0].data = tx; + obj->i2c.xfer.buf[0].data = (void *)tx; obj->i2c.xfer.buf[0].len = (uint16_t) tx_length; obj->i2c.xfer.buf[1].data = rx; obj->i2c.xfer.buf[1].len = (uint16_t) rx_length; diff --git a/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c b/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c index 7151d64e22..fa5a92974b 100644 --- a/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c @@ -822,7 +822,7 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t true, false, (obj->spi.bits <= 8 ? (void *)&(obj->spi.spi->TXDATA) : (void *)&(obj->spi.spi->TXDOUBLE)), //When frame size > 9, point to TXDOUBLE - (txdata == 0 ? (const void *)&fill_word : txdata), // When there is nothing to transmit, point to static fill word + (txdata == 0 ? &fill_word : (void *)txdata), // When there is nothing to transmit, point to static fill word (obj->spi.bits <= 8 ? tx_length - 1 : (tx_length / 2) - 1)); // When using TXDOUBLE, recalculate transfer length } else { /* Frame size == 9 */ @@ -860,7 +860,7 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t true, false, (void *)&(obj->spi.spi->TXDATAX), //When frame size > 9, point to TXDOUBLE - (txdata == 0 ? (const void *)&fill_word : txdata), // When there is nothing to transmit, point to static fill word + (txdata == 0 ? &fill_word : (void *)txdata), // When there is nothing to transmit, point to static fill word (tx_length / 2) - 1); // When using TXDOUBLE, recalculate transfer length } }