aboutsummaryrefslogtreecommitdiff
path: root/sw/tc_eim.c
diff options
context:
space:
mode:
Diffstat (limited to 'sw/tc_eim.c')
-rw-r--r--sw/tc_eim.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/sw/tc_eim.c b/sw/tc_eim.c
index 8ef4f06..76972cd 100644
--- a/sw/tc_eim.c
+++ b/sw/tc_eim.c
@@ -1,11 +1,11 @@
-/*
+/*
* tc_eim.c
* --------
* This module contains common code to talk to the FPGA over the EIM bus.
- *
+ *
* Author: Paul Selkirk
* Copyright (c) 2014-2015, NORDUnet A/S All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
@@ -45,12 +45,13 @@
#include "cryptech.h"
static int debug = 0;
-static int inited = 0;
/* ---------------- EIM low-level code ---------------- */
static int init(void)
{
+ static int inited = 0;
+
if (inited)
return 0;
@@ -84,11 +85,11 @@ void tc_set_debug(int onoff)
debug = onoff;
}
-static void dump(char *label, const uint8_t *buf, size_t len)
+static void dump(char *label, off_t addr, const uint8_t *buf, size_t len)
{
if (debug) {
int i;
- printf("%s [", label);
+ printf("%s %04x [", label, (unsigned int)addr);
for (i = 0; i < len; ++i)
printf(" %02x", buf[i]);
printf(" ]\n");
@@ -100,10 +101,9 @@ int tc_write(off_t offset, const uint8_t *buf, size_t len)
if (init() != 0)
return -1;
- dump("write ", buf, len);
+ dump("write ", offset, buf, len);
- offset = eim_offset(offset);
- for (; len > 0; offset += 4, buf += 4, len -= 4) {
+ for (offset = eim_offset(offset); len > 0; offset += 4, buf += 4, len -= 4) {
uint32_t val;
val = htonl(*(uint32_t *)buf);
eim_write_32(offset, &val);
@@ -114,20 +114,20 @@ int tc_write(off_t offset, const uint8_t *buf, size_t len)
int tc_read(off_t offset, uint8_t *buf, size_t len)
{
+ off_t off;
uint8_t *rbuf = buf;
int rlen = len;
if (init() != 0)
return -1;
- offset = eim_offset(offset);
- for (; rlen > 0; offset += 4, rbuf += 4, rlen -= 4) {
+ for (off = eim_offset(offset); rlen > 0; off += 4, rbuf += 4, rlen -= 4) {
uint32_t val;
- eim_read_32(offset, &val);
+ eim_read_32(off, &val);
*(uint32_t *)rbuf = ntohl(val);
}
- dump("read ", buf, len);
+ dump("read ", offset, buf, len);
return 0;
}
@@ -142,7 +142,7 @@ int tc_expected(off_t offset, const uint8_t *expected, size_t len)
perror("malloc");
return 1;
}
- dump("expect", expected, len);
+ dump("expect", offset, expected, len);
if (tc_read(offset, buf, len) != 0)
goto errout;