aboutsummaryrefslogtreecommitdiff
path: root/hal_io_eim.c
diff options
context:
space:
mode:
Diffstat (limited to 'hal_io_eim.c')
-rw-r--r--hal_io_eim.c50
1 files changed, 15 insertions, 35 deletions
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);
}
/*