From e164eecc55dd96efc98d2c723e96aaaecdcfda13 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 4 Oct 2015 15:39:08 -0400 Subject: off_t => hal_addr_t. --- hal_io_i2c.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'hal_io_i2c.c') diff --git a/hal_io_i2c.c b/hal_io_i2c.c index 9788232..1dbd041 100644 --- a/hal_io_i2c.c +++ b/hal_io_i2c.c @@ -166,14 +166,14 @@ static hal_error_t i2c_read(uint8_t *b) #define UNKNOWN 0xfe #define ERROR 0xfd -static hal_error_t hal_io_send_write_cmd(off_t offset, const uint8_t *data) +static hal_error_t hal_io_send_write_cmd(hal_addr_t offset, const uint8_t *data) { uint8_t buf[9] = { SOC, WRITE_CMD, (offset >> 8) & 0xff, offset & 0xff, data[0], data[1], data[2], data[3], EOC }; return i2c_write(buf, sizeof(buf)); } -static hal_error_t hal_io_send_read_cmd(off_t offset) +static hal_error_t hal_io_send_read_cmd(hal_addr_t offset) { uint8_t buf[5] = { SOC, READ_CMD, (offset >> 8) & 0xff, offset & 0xff, EOC }; return i2c_write(buf, sizeof(buf)); @@ -233,7 +233,7 @@ static hal_error_t hal_io_compare(uint8_t *buf, const uint8_t *expected, size_t return HAL_OK; } -static hal_error_t hal_io_get_write_resp(off_t offset) +static hal_error_t hal_io_get_write_resp(hal_addr_t offset) { uint8_t buf[5]; uint8_t expected[5] = { SOR, WRITE_OK, (offset >> 8) & 0xff, offset & 0xff, EOR }; @@ -245,7 +245,7 @@ static hal_error_t hal_io_get_write_resp(off_t offset) return hal_io_compare(buf, expected, sizeof(expected)); } -static hal_error_t hal_io_get_read_resp(off_t offset, uint8_t *data) +static hal_error_t hal_io_get_read_resp(hal_addr_t offset, uint8_t *data) { uint8_t buf[9]; uint8_t expected[4] = { SOR, READ_OK, (offset >> 8) & 0xff, offset & 0xff }; @@ -266,7 +266,7 @@ static hal_error_t hal_io_get_read_resp(off_t offset, uint8_t *data) return HAL_OK; } -static hal_error_t hal_io_get_read_resp_expected(off_t offset, const uint8_t *data) +static hal_error_t hal_io_get_read_resp_expected(hal_addr_t offset, const uint8_t *data) { uint8_t buf[9]; uint8_t expected[9] = { SOR, READ_OK, (offset >> 8) & 0xff, offset & 0xff, @@ -281,7 +281,7 @@ static hal_error_t hal_io_get_read_resp_expected(off_t offset, const uint8_t *da return hal_io_compare(buf, expected, sizeof(buf)); } -hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len) +hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len) { hal_error_t err; @@ -293,7 +293,7 @@ hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len) +hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len) { hal_error_t err; @@ -305,7 +305,7 @@ hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_expected(off_t offset, const uint8_t *buf, size_t len) +hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *buf, size_t len) { hal_error_t err; @@ -317,19 +317,19 @@ hal_error_t hal_io_expected(off_t offset, const uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_init(off_t offset) +hal_error_t hal_io_init(hal_addr_t offset) { uint8_t buf[4] = { 0, 0, 0, CTRL_INIT }; return hal_io_write(offset, buf, 4); } -hal_error_t hal_io_next(off_t offset) +hal_error_t hal_io_next(hal_addr_t offset) { uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT }; return hal_io_write(offset, buf, 4); } -hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count) +hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count) { hal_error_t err; uint8_t buf[4]; @@ -352,13 +352,13 @@ hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count) } } -hal_error_t hal_io_wait_ready(off_t offset) +hal_error_t hal_io_wait_ready(hal_addr_t offset) { int limit = 10; return hal_io_wait(offset, STATUS_READY, &limit); } -hal_error_t hal_io_wait_valid(off_t offset) +hal_error_t hal_io_wait_valid(hal_addr_t offset) { int limit = 10; return hal_io_wait(offset, STATUS_VALID, &limit); -- cgit v1.2.3 From b3bbd3dbccef8c499e980490203cd5085dd13a98 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 4 Oct 2015 22:31:47 -0400 Subject: Whack libhal API to use current configure_core_selector mechanism. Compiles, not yet tested. --- hal_io_i2c.c | 1 + 1 file changed, 1 insertion(+) (limited to 'hal_io_i2c.c') diff --git a/hal_io_i2c.c b/hal_io_i2c.c index 1dbd041..3e8ac59 100644 --- a/hal_io_i2c.c +++ b/hal_io_i2c.c @@ -41,6 +41,7 @@ #include #include "hal.h" +#include "verilog_constants.h" #define I2C_dev "/dev/i2c-2" #define I2C_addr 0x0f -- cgit v1.2.3 From ff4ff7c8ccf0c5d5c1c363053f0fc84ec5674edf Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 4 Oct 2015 23:23:07 -0400 Subject: Disallow NULL core argument in lowest-level HAL I/O routines. --- hal_io_i2c.c | 57 ++++++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 37 deletions(-) (limited to 'hal_io_i2c.c') diff --git a/hal_io_i2c.c b/hal_io_i2c.c index 3e8ac59..7fb306e 100644 --- a/hal_io_i2c.c +++ b/hal_io_i2c.c @@ -267,24 +267,14 @@ static hal_error_t hal_io_get_read_resp(hal_addr_t offset, uint8_t *data) return HAL_OK; } -static hal_error_t hal_io_get_read_resp_expected(hal_addr_t offset, const uint8_t *data) +hal_error_t hal_io_write(const hal_core_t *core, hal_addr_t offset, const uint8_t *buf, size_t len) { - uint8_t buf[9]; - uint8_t expected[9] = { SOR, READ_OK, (offset >> 8) & 0xff, offset & 0xff, - data[0], data[1], data[2], data[3], EOR }; hal_error_t err; - dump("expect", expected, 9); - - if ((err = hal_io_get_resp(buf, sizeof(buf))) != HAL_OK) - return err; - - return hal_io_compare(buf, expected, sizeof(buf)); -} + if (core == NULL) + return HAL_ERROR_CORE_NOT_FOUND; -hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len) -{ - hal_error_t err; + offset += hal_core_base(core); for (; len > 0; offset++, buf += 4, len -= 4) if ((err = hal_io_send_write_cmd(offset, buf)) != HAL_OK || @@ -294,43 +284,36 @@ hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len) +hal_error_t hal_io_read(const hal_core_t *core, hal_addr_t offset, uint8_t *buf, size_t len) { hal_error_t err; - for (; len > 0; offset++, buf += 4, len -= 4) - if ((err = hal_io_send_read_cmd(offset)) != HAL_OK || - (err = hal_io_get_read_resp(offset, buf)) != HAL_OK) - return err; + if (core == NULL) + return HAL_ERROR_CORE_NOT_FOUND; - return HAL_OK; -} - -hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *buf, size_t len) -{ - hal_error_t err; + offset += hal_core_base(core); for (; len > 0; offset++, buf += 4, len -= 4) - if ((err = hal_io_send_read_cmd(offset)) != HAL_OK || - (err = hal_io_get_read_resp_expected(offset, buf)) != HAL_OK) + if ((err = hal_io_send_read_cmd(offset)) != HAL_OK || + (err = hal_io_get_read_resp(offset, buf)) != HAL_OK) return err; return HAL_OK; } -hal_error_t hal_io_init(hal_addr_t offset) +hal_error_t hal_io_init(const hal_core_t *core) { uint8_t buf[4] = { 0, 0, 0, CTRL_INIT }; - return hal_io_write(offset, buf, 4); + return hal_io_write(core, ADDR_CTRL, buf, 4); } -hal_error_t hal_io_next(hal_addr_t offset) +hal_error_t hal_io_next(const hal_core_t *core) { uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT }; - return hal_io_write(offset, buf, 4); + return hal_io_write(core, ADDR_CTRL, buf, 4); } -hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count) +hal_error_t hal_io_wait(const hal_core_t *core, uint8_t status, int *count) { hal_error_t err; uint8_t buf[4]; @@ -341,7 +324,7 @@ hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count) if (count && (*count > 0) && (i >= *count)) return HAL_ERROR_IO_TIMEOUT; - if ((err = hal_io_read(offset, buf, 4)) != HAL_OK) + if ((err = hal_io_read(core, ADDR_STATUS, buf, 4)) != HAL_OK) return err; if (buf[3] & status) { @@ -353,16 +336,16 @@ hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count) } } -hal_error_t hal_io_wait_ready(hal_addr_t offset) +hal_error_t hal_io_wait_ready(const hal_core_t *core) { int limit = 10; - return hal_io_wait(offset, STATUS_READY, &limit); + return hal_io_wait(core, STATUS_READY, &limit); } -hal_error_t hal_io_wait_valid(hal_addr_t offset) +hal_error_t hal_io_wait_valid(const hal_core_t *core) { int limit = 10; - return hal_io_wait(offset, STATUS_VALID, &limit); + return hal_io_wait(core, STATUS_VALID, &limit); } /* -- cgit v1.2.3