aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2015-11-16 14:37:51 -0500
committerPaul Selkirk <paul@psgd.org>2015-11-16 14:37:51 -0500
commit0729c5b0e9097f75198b4fe2d62035e4fc598724 (patch)
tree29484fe2d0cdcf9541982ec38930aac8abc7ee16
parent4c6b056b8467bb6513224527ff3120ef905de397 (diff)
sync up with config_core_selector-related API changes
-rw-r--r--hal_io_fmc.c58
1 files changed, 22 insertions, 36 deletions
diff --git a/hal_io_fmc.c b/hal_io_fmc.c
index afbfc6e..fde8775 100644
--- a/hal_io_fmc.c
+++ b/hal_io_fmc.c
@@ -38,6 +38,7 @@
#include "stm-fmc.h"
#include "libhal/hal.h"
+#include "libhal/verilog_constants.h"
static int debug = 0;
static int inited = 0;
@@ -79,7 +80,7 @@ static hal_error_t init(void)
*
* sss ccccc rrrrrrrr => sss 0 ccccc rrrrrrrr 00
*/
-static off_t fmc_offset(off_t offset)
+static hal_addr_t fmc_offset(hal_addr_t offset)
{
return ((offset & ~0x1fff) << 3) + ((offset & 0x1fff) << 2);
}
@@ -100,10 +101,13 @@ 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(const hal_core_t *core, hal_addr_t offset, const uint8_t *buf, size_t len)
{
hal_error_t err;
+ if (core == NULL)
+ return HAL_ERROR_CORE_NOT_FOUND;
+
if (len % 4 != 0)
return HAL_ERROR_IO_BAD_COUNT;
@@ -112,7 +116,7 @@ hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len)
dump("write ", buf, len);
- offset = fmc_offset(offset);
+ offset = fmc_offset(offset + hal_core_base(core));
for (; len > 0; offset += 4, buf += 4, len -= 4) {
uint32_t val;
val = htonl(*(uint32_t *)buf);
@@ -122,19 +126,22 @@ 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(const hal_core_t *core, hal_addr_t offset, uint8_t *buf, size_t len)
{
uint8_t *rbuf = 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;
if ((err = init()) != HAL_OK)
return err;
- offset = fmc_offset(offset);
+ offset = fmc_offset(offset + hal_core_base(core));
for (; rlen > 0; offset += 4, rbuf += 4, rlen -= 4) {
uint32_t val;
fmc_read_32(offset, &val);
@@ -146,40 +153,19 @@ 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 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(off_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(off_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(off_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];
@@ -190,7 +176,7 @@ hal_error_t hal_io_wait(off_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) {
@@ -201,16 +187,16 @@ 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(const hal_core_t *core)
{
int limit = FMC_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(off_t offset)
+hal_error_t hal_io_wait_valid(const hal_core_t *core)
{
int limit = FMC_IO_TIMEOUT;
- return hal_io_wait(offset, STATUS_VALID, &limit);
+ return hal_io_wait(core, STATUS_VALID, &limit);
}
/*