Merge pull request #1169 from 0xc0170/fix_asynch_constness

Fix asynch methods constness
pull/1173/head
Martin Kojtal 2015-06-10 09:52:36 +01:00
commit 4778e33fa1
12 changed files with 33 additions and 33 deletions

View File

@ -149,7 +149,7 @@ public:
* @param repeated Repeated start, true - do not send stop at end * @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 * @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 /** Abort the on-going I2C transfer
*/ */

View File

@ -123,7 +123,7 @@ public:
* @param event The logical OR of events to modify * @param event The logical OR of events to modify
* @return Zero if the transfer has started, or -1 if SPI peripheral is busy * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
*/ */
virtual int transfer(uint8_t *tx_buffer, int tx_length, uint8_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) { virtual int transfer(const uint8_t *tx_buffer, int tx_length, uint8_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 8, callback, event); return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 8, callback, event);
} }
@ -139,7 +139,7 @@ public:
* @param event The logical OR of events to modify * @param event The logical OR of events to modify
* @return Zero if the transfer has started, or -1 if SPI peripheral is busy * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
*/ */
virtual int transfer(uint16_t *tx_buffer, int tx_length, uint16_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) { virtual int transfer(const uint16_t *tx_buffer, int tx_length, uint16_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 16, callback, event); return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 16, callback, event);
} }
@ -155,7 +155,7 @@ public:
* @param event The logical OR of events to modify * @param event The logical OR of events to modify
* @return Zero if the transfer has started, or -1 if SPI peripheral is busy * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
*/ */
virtual int transfer(uint32_t *tx_buffer, int tx_length, uint32_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) { virtual int transfer(const uint32_t *tx_buffer, int tx_length, uint32_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
return transfer((void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length, 32, callback, event); return transfer((void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length, 32, callback, event);
} }
@ -197,7 +197,7 @@ protected:
* @param event The logical OR of events to modify * @param event The logical OR of events to modify
* @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full * @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full
*/ */
int transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event); int transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
/** /**
* *
@ -212,7 +212,7 @@ protected:
* @param event The logical OR of events to modify * @param event The logical OR of events to modify
* @return Zero if a transfer was added to the queue, or -1 if the queue is full * @return Zero if a transfer was added to the queue, or -1 if the queue is full
*/ */
int queue_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event); int queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
/** Configures a callback, spi peripheral and initiate a new transfer /** Configures a callback, spi peripheral and initiate a new transfer
* *
@ -226,7 +226,7 @@ protected:
* @param callback The event callback function * @param callback The event callback function
* @param event The logical OR of events to modify * @param event The logical OR of events to modify
*/ */
void start_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event); void start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
#if TRANSACTION_QUEUE_SIZE_SPI #if TRANSACTION_QUEUE_SIZE_SPI

View File

@ -135,7 +135,7 @@ public:
* @param callback The event callback function * @param callback The event callback function
* @param event The logical OR of TX events * @param event The logical OR of TX events
*/ */
int write(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE); int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
/** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
* *
@ -144,7 +144,7 @@ public:
* @param callback The event callback function * @param callback The event callback function
* @param event The logical OR of TX events * @param event The logical OR of TX events
*/ */
int write(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE); int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
/** Abort the on-going write transfer /** Abort the on-going write transfer
*/ */
@ -190,7 +190,7 @@ public:
protected: protected:
void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match); void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
void start_write(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event); void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
void interrupt_handler_asynch(void); void interrupt_handler_asynch(void);
#endif #endif

View File

@ -92,7 +92,7 @@ void I2C::stop(void) {
#if DEVICE_I2C_ASYNCH #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)) { if (i2c_active(&_i2c)) {
return -1; // transaction ongoing return -1; // transaction ongoing

View File

@ -68,7 +68,7 @@ int SPI::write(int value) {
#if DEVICE_SPI_ASYNCH #if DEVICE_SPI_ASYNCH
int SPI::transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event) int SPI::transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event)
{ {
if (spi_active(&_spi)) { if (spi_active(&_spi)) {
return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, bit_width, callback, event); return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, bit_width, callback, event);
@ -108,12 +108,12 @@ int SPI::set_dma_usage(DMAUsage usage)
return 0; return 0;
} }
int SPI::queue_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event) int SPI::queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event)
{ {
#if TRANSACTION_QUEUE_SIZE_SPI #if TRANSACTION_QUEUE_SIZE_SPI
transaction_t t; transaction_t t;
t.tx_buffer = tx_buffer; t.tx_buffer = const_cast<void *>(tx_buffer);
t.tx_length = tx_length; t.tx_length = tx_length;
t.rx_buffer = rx_buffer; t.rx_buffer = rx_buffer;
t.rx_length = rx_length; t.rx_length = rx_length;
@ -132,7 +132,7 @@ int SPI::queue_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_
#endif #endif
} }
void SPI::start_transfer(void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event) void SPI::start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event)
{ {
aquire(); aquire();
_callback = callback; _callback = callback;

View File

@ -110,7 +110,7 @@ void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
#if DEVICE_SERIAL_ASYNCH #if DEVICE_SERIAL_ASYNCH
int SerialBase::write(uint8_t *buffer, int length, const event_callback_t& callback, int event) int SerialBase::write(const uint8_t *buffer, int length, const event_callback_t& callback, int event)
{ {
if (serial_tx_active(&_serial)) { if (serial_tx_active(&_serial)) {
return -1; // transaction ongoing return -1; // transaction ongoing
@ -119,7 +119,7 @@ int SerialBase::write(uint8_t *buffer, int length, const event_callback_t& callb
return 0; return 0;
} }
int SerialBase::write(uint16_t *buffer, int length, const event_callback_t& callback, int event) int SerialBase::write(const uint16_t *buffer, int length, const event_callback_t& callback, int event)
{ {
if (serial_tx_active(&_serial)) { if (serial_tx_active(&_serial)) {
return -1; // transaction ongoing return -1; // transaction ongoing
@ -128,7 +128,7 @@ int SerialBase::write(uint16_t *buffer, int length, const event_callback_t& call
return 0; return 0;
} }
void SerialBase::start_write(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event) void SerialBase::start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event)
{ {
_tx_callback = callback; _tx_callback = callback;

View File

@ -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 handler The I2C IRQ handler to be set
* @param hint DMA hint usage * @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 /** The asynchronous IRQ handler
* @param obj The I2C object which holds the transfer information * @param obj The I2C object which holds the transfer information

View File

@ -237,7 +237,7 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
* @param hint A suggestion for how to use DMA with this transfer * @param hint A suggestion for how to use DMA with this transfer
* @return Returns number of data transfered, or 0 otherwise * @return Returns number of data transfered, or 0 otherwise
*/ */
int serial_tx_asynch(serial_t *obj, void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint); int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint);
/** Begin asynchronous RX transfer (enable interrupt for data collecting) /** Begin asynchronous RX transfer (enable interrupt for data collecting)
* The used buffer is specified in the serial object - rx_buff * The used buffer is specified in the serial object - rx_buff

View File

@ -169,7 +169,7 @@ uint8_t spi_get_module(spi_t *obj);
* @param[in] handler SPI interrupt handler * @param[in] handler SPI interrupt handler
* @param[in] hint A suggestion for how to use DMA with this transfer * @param[in] hint A suggestion for how to use DMA with this transfer
*/ */
void spi_master_transfer(spi_t *obj, void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint); void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint);
/** The asynchronous IRQ handler /** The asynchronous IRQ handler
* *

View File

@ -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 handler The I2C IRQ handler to be set
* @param hint DMA hint usage * @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; I2C_TransferReturn_TypeDef retval;
if(i2c_active(obj)) return; 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)) { if((tx_length > 0) && (rx_length == 0)) {
obj->i2c.xfer.flags = I2C_FLAG_WRITE; obj->i2c.xfer.flags = I2C_FLAG_WRITE;
//Store buffer info //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[0].len = (uint16_t) tx_length;
} else if ((tx_length == 0) && (rx_length > 0)) { } else if ((tx_length == 0) && (rx_length > 0)) {
obj->i2c.xfer.flags = I2C_FLAG_READ; 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)) { } else if ((tx_length > 0) && (rx_length > 0)) {
obj->i2c.xfer.flags = I2C_FLAG_WRITE_READ; obj->i2c.xfer.flags = I2C_FLAG_WRITE_READ;
//Store buffer info //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[0].len = (uint16_t) tx_length;
obj->i2c.xfer.buf[1].data = rx; obj->i2c.xfer.buf[1].data = rx;
obj->i2c.xfer.buf[1].len = (uint16_t) rx_length; obj->i2c.xfer.buf[1].len = (uint16_t) rx_length;

View File

@ -1262,14 +1262,14 @@ void serial_set_char_match(serial_t *obj, uint8_t char_match)
* @param hint A suggestion for how to use DMA with this transfer * @param hint A suggestion for how to use DMA with this transfer
* @return Returns number of data transfered, or 0 otherwise * @return Returns number of data transfered, or 0 otherwise
*/ */
int serial_tx_asynch(serial_t *obj, void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint) int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint)
{ {
// Check that a buffer has indeed been set up // Check that a buffer has indeed been set up
MBED_ASSERT(tx != (void*)0); MBED_ASSERT(tx != (void*)0);
if(tx_length == 0) return 0; if(tx_length == 0) return 0;
// Set up buffer // Set up buffer
serial_tx_buffer_set(obj, tx, tx_length, tx_width); serial_tx_buffer_set(obj, (void *)tx, tx_length, tx_width);
// Set up events // Set up events
serial_tx_enable_event(obj, SERIAL_EVENT_TX_ALL, false); serial_tx_enable_event(obj, SERIAL_EVENT_TX_ALL, false);

View File

@ -399,7 +399,7 @@ uint8_t spi_active(spi_t *obj)
} }
} }
void spi_buffer_set(spi_t *obj, void *tx, uint32_t tx_length, void *rx, uint32_t rx_length, uint8_t bit_width) void spi_buffer_set(spi_t *obj, const void *tx, uint32_t tx_length, void *rx, uint32_t rx_length, uint8_t bit_width)
{ {
uint32_t i; uint32_t i;
uint16_t *tx_ptr = (uint16_t *) tx; uint16_t *tx_ptr = (uint16_t *) tx;
@ -407,7 +407,7 @@ void spi_buffer_set(spi_t *obj, void *tx, uint32_t tx_length, void *rx, uint32_t
tx_length *= (bit_width >> 3); tx_length *= (bit_width >> 3);
rx_length *= (bit_width >> 3); rx_length *= (bit_width >> 3);
obj->tx_buff.buffer = tx; obj->tx_buff.buffer = (void *)tx;
obj->rx_buff.buffer = rx; obj->rx_buff.buffer = rx;
obj->tx_buff.length = tx_length; obj->tx_buff.length = tx_length;
obj->rx_buff.length = rx_length; obj->rx_buff.length = rx_length;
@ -761,7 +761,7 @@ static void spi_master_dma_channel_setup(spi_t *obj, void* callback)
* * tx_length: how many bytes will get sent. * * tx_length: how many bytes will get sent.
* * rx_length: how many bytes will get received. If > tx_length, TX will get padded with n lower bits of SPI_FILL_WORD. * * rx_length: how many bytes will get received. If > tx_length, TX will get padded with n lower bits of SPI_FILL_WORD.
******************************************/ ******************************************/
static void spi_activate_dma(spi_t *obj, void* rxdata, void* txdata, int tx_length, int rx_length) static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int tx_length, int rx_length)
{ {
/* DMA descriptors */ /* DMA descriptors */
DMA_CfgDescr_TypeDef rxDescrCfg; DMA_CfgDescr_TypeDef rxDescrCfg;
@ -822,7 +822,7 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, void* txdata, int tx_leng
true, true,
false, false,
(obj->spi.bits <= 8 ? (void *)&(obj->spi.spi->TXDATA) : (void *)&(obj->spi.spi->TXDOUBLE)), //When frame size > 9, point to TXDOUBLE (obj->spi.bits <= 8 ? (void *)&(obj->spi.spi->TXDATA) : (void *)&(obj->spi.spi->TXDOUBLE)), //When frame size > 9, point to TXDOUBLE
(txdata == 0 ? &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 (obj->spi.bits <= 8 ? tx_length - 1 : (tx_length / 2) - 1)); // When using TXDOUBLE, recalculate transfer length
} else { } else {
/* Frame size == 9 */ /* Frame size == 9 */
@ -860,7 +860,7 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, void* txdata, int tx_leng
true, true,
false, false,
(void *)&(obj->spi.spi->TXDATAX), //When frame size > 9, point to TXDOUBLE (void *)&(obj->spi.spi->TXDATAX), //When frame size > 9, point to TXDOUBLE
(txdata == 0 ? &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 (tx_length / 2) - 1); // When using TXDOUBLE, recalculate transfer length
} }
} }
@ -882,7 +882,7 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, void* txdata, int tx_leng
* If the previous transfer has kept the channel, that channel will continue to get used. * If the previous transfer has kept the channel, that channel will continue to get used.
* *
********************************************************************/ ********************************************************************/
void spi_master_transfer_dma(spi_t *obj, void *txdata, void *rxdata, int tx_length, int rx_length, void* cb, DMAUsage hint) void spi_master_transfer_dma(spi_t *obj, const void *txdata, void *rxdata, int tx_length, int rx_length, void* cb, DMAUsage hint)
{ {
/* Init DMA here to include it in the power figure */ /* Init DMA here to include it in the power figure */
dma_init(); dma_init();
@ -930,7 +930,7 @@ void spi_master_transfer_dma(spi_t *obj, void *txdata, void *rxdata, int tx_leng
* @param[in] handler SPI interrupt handler * @param[in] handler SPI interrupt handler
* @param[in] hint A suggestion for how to use DMA with this transfer * @param[in] hint A suggestion for how to use DMA with this transfer
*/ */
void spi_master_transfer(spi_t *obj, void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint) void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint)
{ {
if( spi_active(obj) ) return; if( spi_active(obj) ) return;