You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2018/11/23 16:16:45 UTC
[mynewt-core] 13/26: hw/bus: Use void and const pointers for rw APIs
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 1e6483d78f478bb53b4ec3da148fd98660c7b019
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Nov 15 16:38:48 2018 +0100
hw/bus: Use void and const pointers for rw APIs
---
hw/bus/i2c/src/i2c.c | 4 ++--
hw/bus/include/bus/bus.h | 16 ++++++++--------
hw/bus/include/bus/bus_driver.h | 2 +-
hw/bus/spi/src/spi.c | 5 +++--
hw/bus/src/bus.c | 8 ++++----
5 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/hw/bus/i2c/src/i2c.c b/hw/bus/i2c/src/i2c.c
index bba3a85..8065c1d 100644
--- a/hw/bus/i2c/src/i2c.c
+++ b/hw/bus/i2c/src/i2c.c
@@ -104,7 +104,7 @@ bus_i2c_read(struct bus_dev *bdev, struct bus_node *bnode, uint8_t *buf,
}
static int
-bus_i2c_write(struct bus_dev *bdev, struct bus_node *bnode, uint8_t *buf,
+bus_i2c_write(struct bus_dev *bdev, struct bus_node *bnode, const uint8_t *buf,
uint16_t length, os_time_t timeout, uint16_t flags)
{
struct bus_i2c_dev *dev = (struct bus_i2c_dev *)bdev;
@@ -117,7 +117,7 @@ bus_i2c_write(struct bus_dev *bdev, struct bus_node *bnode, uint8_t *buf,
BUS_DEBUG_VERIFY_NODE(node);
i2c_data.address = node->addr;
- i2c_data.buffer = buf;
+ i2c_data.buffer = (uint8_t *)buf;
i2c_data.len = length;
last_op = !(flags & BUS_F_NOSTOP);
diff --git a/hw/bus/include/bus/bus.h b/hw/bus/include/bus/bus.h
index 7d9c04e..49770b2 100644
--- a/hw/bus/include/bus/bus.h
+++ b/hw/bus/include/bus/bus.h
@@ -53,7 +53,7 @@ extern "C" {
* @return 0 on success, SYS_xxx on error
*/
int
-bus_node_read(struct os_dev *node, uint8_t *buf, uint16_t length,
+bus_node_read(struct os_dev *node, void *buf, uint16_t length,
os_time_t timeout, uint16_t flags);
/**
@@ -74,7 +74,7 @@ bus_node_read(struct os_dev *node, uint8_t *buf, uint16_t length,
* @return 0 on success, SYS_xxx on error
*/
int
-bus_node_write(struct os_dev *node, uint8_t *buf, uint16_t length,
+bus_node_write(struct os_dev *node, const void *buf, uint16_t length,
os_time_t timeout, uint16_t flags);
/**
@@ -98,8 +98,8 @@ bus_node_write(struct os_dev *node, uint8_t *buf, uint16_t length,
* @return 0 on success, SYS_xxx on error
*/
int
-bus_node_write_read_transact(struct os_dev *node, uint8_t *wbuf,
- uint16_t wlength, uint8_t *rbuf, uint16_t rlength,
+bus_node_write_read_transact(struct os_dev *node, const void *wbuf,
+ uint16_t wlength, void *rbuf, uint16_t rlength,
os_time_t timeout, uint16_t flags);
/**
@@ -114,7 +114,7 @@ bus_node_write_read_transact(struct os_dev *node, uint8_t *wbuf,
* @return 0 on success, SYS_xxx on error
*/
static inline int
-bus_node_simple_read(struct os_dev *node, uint8_t *buf, uint16_t length)
+bus_node_simple_read(struct os_dev *node, void *buf, uint16_t length)
{
return bus_node_read(node, buf, length, OS_TIMEOUT_NEVER, BUS_F_NONE);
}
@@ -131,7 +131,7 @@ bus_node_simple_read(struct os_dev *node, uint8_t *buf, uint16_t length)
* @return 0 on success, SYS_xxx on error
*/
static inline int
-bus_node_simple_write(struct os_dev *node, uint8_t *buf, uint16_t length)
+bus_node_simple_write(struct os_dev *node, const void *buf, uint16_t length)
{
return bus_node_write(node, buf, length, OS_TIMEOUT_NEVER, BUS_F_NONE);
}
@@ -151,8 +151,8 @@ bus_node_simple_write(struct os_dev *node, uint8_t *buf, uint16_t length)
* @return 0 on success, SYS_xxx on error
*/
static inline int
-bus_node_simple_write_read_transact(struct os_dev *node, uint8_t *wbuf,
- uint16_t wlength, uint8_t *rbuf,
+bus_node_simple_write_read_transact(struct os_dev *node, const void *wbuf,
+ uint16_t wlength, void *rbuf,
uint16_t rlength)
{
return bus_node_write_read_transact(node, wbuf, wlength, rbuf, rlength,
diff --git a/hw/bus/include/bus/bus_driver.h b/hw/bus/include/bus/bus_driver.h
index a80f400..d3b8302 100644
--- a/hw/bus/include/bus/bus_driver.h
+++ b/hw/bus/include/bus/bus_driver.h
@@ -44,7 +44,7 @@ struct bus_dev_ops {
int (* read)(struct bus_dev *dev, struct bus_node *node, uint8_t *buf,
uint16_t length, os_time_t timeout, uint16_t flags);
/* Write data to node */
- int (* write)(struct bus_dev *dev, struct bus_node *node, uint8_t *buf,
+ int (* write)(struct bus_dev *dev, struct bus_node *node, const uint8_t *buf,
uint16_t length, os_time_t timeout, uint16_t flags);
/* Disable bus device */
int (* disable)(struct bus_dev *bus);
diff --git a/hw/bus/spi/src/spi.c b/hw/bus/spi/src/spi.c
index 7aca7c4..4ec30ee 100644
--- a/hw/bus/spi/src/spi.c
+++ b/hw/bus/spi/src/spi.c
@@ -121,7 +121,7 @@ bus_spi_read(struct bus_dev *bdev, struct bus_node *bnode, uint8_t *buf,
}
static int
-bus_spi_write(struct bus_dev *bdev, struct bus_node *bnode, uint8_t *buf,
+bus_spi_write(struct bus_dev *bdev, struct bus_node *bnode, const uint8_t *buf,
uint16_t length, os_time_t timeout, uint16_t flags)
{
struct bus_spi_dev *dev = (struct bus_spi_dev *)bdev;
@@ -133,7 +133,8 @@ bus_spi_write(struct bus_dev *bdev, struct bus_node *bnode, uint8_t *buf,
hal_gpio_write(node->pin_cs, 0);
- rc = hal_spi_txrx(dev->cfg.spi_num, buf, NULL, length);
+ /* XXX update HAL to accept const instead */
+ rc = hal_spi_txrx(dev->cfg.spi_num, (uint8_t *)buf, NULL, length);
if (!(flags & BUS_F_NOSTOP)) {
hal_gpio_write(node->pin_cs, 1);
diff --git a/hw/bus/src/bus.c b/hw/bus/src/bus.c
index 8f5a451..60ac70c 100644
--- a/hw/bus/src/bus.c
+++ b/hw/bus/src/bus.c
@@ -149,7 +149,7 @@ bus_node_init_func(struct os_dev *odev, void *arg)
}
int
-bus_node_read(struct os_dev *node, uint8_t *buf, uint16_t length,
+bus_node_read(struct os_dev *node, void *buf, uint16_t length,
os_time_t timeout, uint16_t flags)
{
struct bus_node *bnode = (struct bus_node *)node;
@@ -183,7 +183,7 @@ done:
}
int
-bus_node_write(struct os_dev *node, uint8_t *buf, uint16_t length,
+bus_node_write(struct os_dev *node, const void *buf, uint16_t length,
os_time_t timeout, uint16_t flags)
{
struct bus_node *bnode = (struct bus_node *)node;
@@ -217,8 +217,8 @@ done:
}
int
-bus_node_write_read_transact(struct os_dev *node, uint8_t *wbuf,
- uint16_t wlength, uint8_t *rbuf, uint16_t rlength,
+bus_node_write_read_transact(struct os_dev *node, const void *wbuf,
+ uint16_t wlength, void *rbuf, uint16_t rlength,
os_time_t timeout, uint16_t flags)
{
struct bus_node *bnode = (struct bus_node *)node;