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_eim.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'hal_io_eim.c') diff --git a/hal_io_eim.c b/hal_io_eim.c index 3687b95..c0f70f4 100644 --- a/hal_io_eim.c +++ b/hal_io_eim.c @@ -72,7 +72,7 @@ static hal_error_t init(void) * * sss ccccc rrrrrrrr => 00001000000000 sss 0 ccccc rrrrrrrr 00 */ -static off_t eim_offset(off_t offset) +static hal_addr_t eim_offset(hal_addr_t offset) { return EIM_BASE_ADDR + ((offset & ~0x1fff) << 3) + ((offset & 0x1fff) << 2); } @@ -93,7 +93,7 @@ static void dump(char *label, const uint8_t *buf, size_t len) } } -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; @@ -115,7 +115,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) { uint8_t *rbuf = buf; int rlen = len; @@ -139,7 +139,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 *expected, size_t len) +hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *expected, size_t len) { hal_error_t err; uint8_t buf[4]; @@ -160,19 +160,19 @@ hal_error_t hal_io_expected(off_t offset, const uint8_t *expected, 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, sizeof(buf)); } -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, sizeof(buf)); } -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]; @@ -194,13 +194,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 = EIM_IO_TIMEOUT; 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 = EIM_IO_TIMEOUT; 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_eim.c | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'hal_io_eim.c') diff --git a/hal_io_eim.c b/hal_io_eim.c index c0f70f4..4f9df65 100644 --- a/hal_io_eim.c +++ b/hal_io_eim.c @@ -43,6 +43,7 @@ #include "novena-eim.h" #include "hal.h" +#include "verilog_constants.h" static int debug = 0; static int inited = 0; @@ -93,7 +94,7 @@ static void dump(char *label, 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 hal_io_write(const hal_core_t *core, hal_addr_t offset, const uint8_t *buf, size_t len) { hal_error_t err; @@ -105,7 +106,7 @@ hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len) dump("write ", buf, len); - offset = eim_offset(offset); + offset = eim_offset(offset + hal_core_base(core)); for (; len > 0; offset += 4, buf += 4, len -= 4) { uint32_t val; val = htonl(*(uint32_t *)buf); @@ -115,7 +116,7 @@ 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) { uint8_t *rbuf = buf; int rlen = len; @@ -127,7 +128,7 @@ hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len) if ((err = init()) != HAL_OK) return err; - offset = eim_offset(offset); + offset = eim_offset(offset + hal_core_base(core)); for (; rlen > 0; offset += 4, rbuf += 4, rlen -= 4) { uint32_t val; eim_read_32(offset, &val); @@ -139,40 +140,19 @@ hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *expected, size_t len) -{ - hal_error_t err; - uint8_t buf[4]; - size_t i; - - if (len % 4 != 0) - return HAL_ERROR_IO_BAD_COUNT; - - dump("expect", expected, len); - - for (i = 0; i < len; i++) { - if ((i & 3) == 0 && (err = hal_io_read(offset + i/4, buf, sizeof(buf))) != HAL_OK) - return err; - if (buf[i & 3] != expected[i]) - return HAL_ERROR_IO_UNEXPECTED; - } - - 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, sizeof(buf)); + return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); } -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, sizeof(buf)); + return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); } -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]; @@ -183,7 +163,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, sizeof(buf))) != HAL_OK) + if ((err = hal_io_read(core, ADDR_STATUS, buf, sizeof(buf))) != HAL_OK) return err; if ((buf[3] & status) != 0) { @@ -194,16 +174,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 = EIM_IO_TIMEOUT; - 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 = EIM_IO_TIMEOUT; - return hal_io_wait(offset, STATUS_VALID, &limit); + return hal_io_wait(core, STATUS_VALID, &limit); } /* -- 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_eim.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'hal_io_eim.c') diff --git a/hal_io_eim.c b/hal_io_eim.c index 4f9df65..7d2e32a 100644 --- a/hal_io_eim.c +++ b/hal_io_eim.c @@ -98,6 +98,9 @@ hal_error_t hal_io_write(const hal_core_t *core, hal_addr_t offset, const uint8_ { hal_error_t err; + if (core == NULL) + return HAL_ERROR_CORE_NOT_FOUND; + if (len % 4 != 0) return HAL_ERROR_IO_BAD_COUNT; @@ -122,6 +125,9 @@ hal_error_t hal_io_read(const hal_core_t *core, hal_addr_t offset, uint8_t *buf, int rlen = len; hal_error_t err; + if (core == NULL) + return HAL_ERROR_CORE_NOT_FOUND; + if (len % 4 != 0) return HAL_ERROR_IO_BAD_COUNT; -- cgit v1.2.3