[Cryptech-Commits] [sw/stm32] 08/11: sync up with config_core_selector-related API changes

git at cryptech.is git at cryptech.is
Mon Nov 16 21:43:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository sw/stm32.

commit 0729c5b0e9097f75198b4fe2d62035e4fc598724
Author: Paul Selkirk <paul at psgd.org>
Date:   Mon Nov 16 14:37:51 2015 -0500

    sync up with config_core_selector-related API changes
---
 hal_io_fmc.c | 58 ++++++++++++++++++++++------------------------------------
 1 file 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);
 }
 
 /*



More information about the Commits mailing list