summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2022-06-05 00:45:42 -0700
committerH. Peter Anvin <hpa@zytor.com>2022-06-05 00:47:50 -0700
commit1b4255df8e36818aa1433607b4e827c280b2078b (patch)
treea73bcf85836f2474efd234a8dc9971406b658058
parent9129544a417aaeb500e22f5f6cf330f272ce1c1f (diff)
downloadblinktest-1b4255df8e36818aa1433607b4e827c280b2078b.tar.gz
blinktest-1b4255df8e36818aa1433607b4e827c280b2078b.tar.xz
blinktest-1b4255df8e36818aa1433607b4e827c280b2078b.zip
esplink: add ring buffer read/write functions to rv32 side
Add functions to read and write ring buffer data to/from the rv32 side. These are unconditionally atomic, at least for now, since there is no task scheduler on the rv32 side.
-rw-r--r--esp32/max80/esplink.h1
-rw-r--r--esp32/output/max80.ino.binbin774368 -> 774352 bytes
-rw-r--r--fpga/max80.qpf4
-rw-r--r--fpga/output/bypass.jicbin16777443 -> 16777443 bytes
-rw-r--r--fpga/output/v1.fwbin735692 -> 735823 bytes
-rw-r--r--fpga/output/v1.jicbin16777443 -> 16777443 bytes
-rw-r--r--fpga/output/v1.rbf.gzbin160736 -> 160737 bytes
-rw-r--r--fpga/output/v1.rpd.gzbin217795 -> 217857 bytes
-rw-r--r--fpga/output/v1.sofbin509098 -> 509098 bytes
-rw-r--r--fpga/output/v1.svf.gzbin183573 -> 183565 bytes
-rw-r--r--fpga/output/v1.xsvf.gzbin165017 -> 165027 bytes
-rw-r--r--fpga/output/v2.fwbin735066 -> 735211 bytes
-rw-r--r--fpga/output/v2.jicbin16777443 -> 16777443 bytes
-rw-r--r--fpga/output/v2.rbf.gzbin160588 -> 160563 bytes
-rw-r--r--fpga/output/v2.rpd.gzbin217799 -> 217787 bytes
-rw-r--r--fpga/output/v2.sofbin509098 -> 509098 bytes
-rw-r--r--fpga/output/v2.svf.gzbin183325 -> 183313 bytes
-rw-r--r--fpga/output/v2.xsvf.gzbin164659 -> 164647 bytes
-rw-r--r--rv32/checksum.h2
-rw-r--r--rv32/common.h5
-rw-r--r--rv32/esp.c101
-rw-r--r--rv32/esplink.h13
-rw-r--r--rv32/system.c1
23 files changed, 118 insertions, 9 deletions
diff --git a/esp32/max80/esplink.h b/esp32/max80/esplink.h
index 7b24911..e0cb242 100644
--- a/esp32/max80/esplink.h
+++ b/esp32/max80/esplink.h
@@ -38,7 +38,6 @@ struct esplink_ptrs_dstr {
size_t head;
};
-
struct esplink_timesync {
struct esplink_timesync_buf {
uint16_t update;
diff --git a/esp32/output/max80.ino.bin b/esp32/output/max80.ino.bin
index ea611d7..ed218b5 100644
--- a/esp32/output/max80.ino.bin
+++ b/esp32/output/max80.ino.bin
Binary files differ
diff --git a/fpga/max80.qpf b/fpga/max80.qpf
index c98ca45..867d0c8 100644
--- a/fpga/max80.qpf
+++ b/fpga/max80.qpf
@@ -19,12 +19,12 @@
#
# Quartus Prime
# Version 21.1.0 Build 842 10/21/2021 SJ Lite Edition
-# Date created = 18:01:47 May 25, 2022
+# Date created = 00:47:37 June 05, 2022
#
# -------------------------------------------------------------------------- #
QUARTUS_VERSION = "21.1"
-DATE = "18:01:47 May 25, 2022"
+DATE = "00:47:37 June 05, 2022"
# Revisions
diff --git a/fpga/output/bypass.jic b/fpga/output/bypass.jic
index 2aba4c3..8a3274d 100644
--- a/fpga/output/bypass.jic
+++ b/fpga/output/bypass.jic
Binary files differ
diff --git a/fpga/output/v1.fw b/fpga/output/v1.fw
index 5c2828f..39dc305 100644
--- a/fpga/output/v1.fw
+++ b/fpga/output/v1.fw
Binary files differ
diff --git a/fpga/output/v1.jic b/fpga/output/v1.jic
index ea463e6..2530dab 100644
--- a/fpga/output/v1.jic
+++ b/fpga/output/v1.jic
Binary files differ
diff --git a/fpga/output/v1.rbf.gz b/fpga/output/v1.rbf.gz
index d75b0fc..7118627 100644
--- a/fpga/output/v1.rbf.gz
+++ b/fpga/output/v1.rbf.gz
Binary files differ
diff --git a/fpga/output/v1.rpd.gz b/fpga/output/v1.rpd.gz
index 9a9858e..3de5695 100644
--- a/fpga/output/v1.rpd.gz
+++ b/fpga/output/v1.rpd.gz
Binary files differ
diff --git a/fpga/output/v1.sof b/fpga/output/v1.sof
index 0c7a458..0db7bd7 100644
--- a/fpga/output/v1.sof
+++ b/fpga/output/v1.sof
Binary files differ
diff --git a/fpga/output/v1.svf.gz b/fpga/output/v1.svf.gz
index c178a62..6131cd2 100644
--- a/fpga/output/v1.svf.gz
+++ b/fpga/output/v1.svf.gz
Binary files differ
diff --git a/fpga/output/v1.xsvf.gz b/fpga/output/v1.xsvf.gz
index e6691d4..fe316d2 100644
--- a/fpga/output/v1.xsvf.gz
+++ b/fpga/output/v1.xsvf.gz
Binary files differ
diff --git a/fpga/output/v2.fw b/fpga/output/v2.fw
index 8aeb2da..7071281 100644
--- a/fpga/output/v2.fw
+++ b/fpga/output/v2.fw
Binary files differ
diff --git a/fpga/output/v2.jic b/fpga/output/v2.jic
index 9bd14d9..7c07c5b 100644
--- a/fpga/output/v2.jic
+++ b/fpga/output/v2.jic
Binary files differ
diff --git a/fpga/output/v2.rbf.gz b/fpga/output/v2.rbf.gz
index 9e8139f..2410ead 100644
--- a/fpga/output/v2.rbf.gz
+++ b/fpga/output/v2.rbf.gz
Binary files differ
diff --git a/fpga/output/v2.rpd.gz b/fpga/output/v2.rpd.gz
index 5664cd0..cc631cf 100644
--- a/fpga/output/v2.rpd.gz
+++ b/fpga/output/v2.rpd.gz
Binary files differ
diff --git a/fpga/output/v2.sof b/fpga/output/v2.sof
index 55ff370..75390f4 100644
--- a/fpga/output/v2.sof
+++ b/fpga/output/v2.sof
Binary files differ
diff --git a/fpga/output/v2.svf.gz b/fpga/output/v2.svf.gz
index 0708c84..e2ed4a9 100644
--- a/fpga/output/v2.svf.gz
+++ b/fpga/output/v2.svf.gz
Binary files differ
diff --git a/fpga/output/v2.xsvf.gz b/fpga/output/v2.xsvf.gz
index 9eaf9d4..a2e9614 100644
--- a/fpga/output/v2.xsvf.gz
+++ b/fpga/output/v2.xsvf.gz
Binary files differ
diff --git a/rv32/checksum.h b/rv32/checksum.h
index d3463d5..00f6169 100644
--- a/rv32/checksum.h
+++ b/rv32/checksum.h
@@ -1,4 +1,4 @@
#ifndef CHECKSUM_H
#define CHECKSUM_H
-#define SDRAM_SUM 0xbd6632a6
+#define SDRAM_SUM 0xa53dbdef
#endif
diff --git a/rv32/common.h b/rv32/common.h
index 44a41b2..1012539 100644
--- a/rv32/common.h
+++ b/rv32/common.h
@@ -90,7 +90,4 @@ extern void run_test_image(void);
extern void rom_flash_from_memory(void *, size_t);
extern void rom_flash_from_sdcard(void);
-extern void esp_init(void);
-extern void esp_ota(const void *, size_t);
-
-#endif /* FW_H */
+#endif /* COMMON_H */
diff --git a/rv32/esp.c b/rv32/esp.c
index 09bd10e..f070490 100644
--- a/rv32/esp.c
+++ b/rv32/esp.c
@@ -51,7 +51,7 @@ IRQHANDLER(esp,0)
void esp_ota(const void *data, size_t len)
{
mask_irq(ESP_IRQ);
-
+
ota.data = data;
ota.len = len;
ESP_SPI_IRQ_SET = 1 << EL_UIRQ_OTA;
@@ -62,6 +62,103 @@ void esp_ota(const void *data, size_t len)
waitfor(ESP_IRQ);
}
+#define RINGBUF_BUF_SIZE 4096 /* Must be a power of 2 */
+
+static __esplink uint8_t rb_buf[EL_RB_COUNT][2][RINGBUF_BUF_SIZE];
+
+static __esplink struct esplink_ringbuf_desc rb_desc[EL_RB_COUNT];
+static volatile __esplink struct esplink_ptrs_dstr rb_dstr[EL_RB_COUNT];
+static volatile __esplink struct esplink_ptrs_ustr rb_ustr[EL_RB_COUNT];
+
+static void esplink_rb_init(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < EL_RB_COUNT; i++) {
+ rb_desc[i].dstr.start = rb_buf[i][0];
+ rb_desc[i].dstr.size = RINGBUF_BUF_SIZE;
+ rb_desc[i].ustr.start = rb_buf[i][1];
+ rb_desc[i].ustr.size = RINGBUF_BUF_SIZE;
+ }
+
+ esplink_head.rb.desc = rb_desc;
+ esplink_head.rb.dstr = (void *)rb_dstr;
+ esplink_head.rb.ustr = (void *)rb_ustr;
+ esplink_head.rb.count = EL_RB_COUNT;
+}
+
+/*
+ * Read and write from ring buffers. These are atomic only; on failure
+ * returns the amount of data/space available, but does NOT advance
+ * any pointers nor copy any data.
+ */
+size_t esp_rb_read(enum esplink_ringbuf_user ring, void *data, size_t len)
+{
+ const size_t size = rb_desc[ring].dstr.size;
+ const size_t sizemask = size - 1;
+ const uint8_t * const base = rb_desc[ring].dstr.start;
+ size_t head = rb_ustr[ring].head;
+ size_t tail = rb_dstr[ring].tail;
+ size_t avail = (head - tail) & sizemask;
+ uint8_t *p = data;
+ size_t xlen = len;
+
+ if (!len)
+ return 0;
+
+ if (avail < xlen)
+ return avail;
+
+ if (tail + xlen > size) {
+ size_t left = size - tail;
+ memcpy(p, base + tail, left);
+ p += left;
+ xlen -= left;
+ tail = 0;
+ }
+ memcpy(p, base + tail, xlen);
+ tail = (tail + xlen) & sizemask;
+
+ rb_dstr[ring].tail = tail;
+ ESP_SPI_IRQ_SET = 1 << EL_UIRQ_RINGBUF;
+
+ return len;
+}
+
+size_t esp_rb_write(enum esplink_ringbuf_user ring,
+ const void *data, size_t len)
+{
+ const size_t size = rb_desc[ring].ustr.size;
+ const size_t sizemask = size - 1;
+ uint8_t * const base = rb_desc[ring].ustr.start;
+ size_t tail = rb_ustr[ring].tail;
+ size_t head = rb_dstr[ring].head;
+ size_t avail = (tail - head - 1) & sizemask;
+ const uint8_t *p = data;
+ size_t xlen = len;
+
+ if (!len)
+ return 0;
+
+ if (avail < xlen)
+ return avail;
+
+ if (head + xlen > size) {
+ size_t left = size - head;
+ memcpy(base + head, p, left);
+ p += left;
+ xlen -= left;
+ head = 0;
+ }
+ memcpy(base + head, p, xlen);
+ head = (head + xlen) & sizemask;
+
+ rb_dstr[ring].head = head;
+ ESP_SPI_IRQ_SET = 1 << EL_UIRQ_RINGBUF;
+
+ return len;
+}
+
void esp_init(void)
{
static char __dram_data esp_signature[] = "Hej tomtebuggar slÄ i glasen!";
@@ -78,6 +175,8 @@ void esp_init(void)
esplink_head.tsync = &tsync;
esplink_head.ota = &ota;
+ esplink_rb_init();
+
esplink_head.magic = ESPLINK_HEAD_MAGIC;
ESP_SPI_IRQ = (1 << EL_UIRQ_READY);
diff --git a/rv32/esplink.h b/rv32/esplink.h
index d543de6..3c78318 100644
--- a/rv32/esplink.h
+++ b/rv32/esplink.h
@@ -1 +1,14 @@
+#ifndef RV32_ESPLINK_H
+#define RV32_ESPLINK_H
+
+#include "compiler.h"
#include "../esp32/max80/esplink.h"
+
+extern void esp_init(void);
+extern void esp_ota(const void *, size_t);
+extern size_t esp_rb_read(enum esplink_ringbuf_user ring,
+ void *data, size_t len);
+extern size_t esp_rb_write(enum esplink_ringbuf_user ring,
+ const void *data, size_t len);
+
+#endif /* RV32_ESPLINK_H */
diff --git a/rv32/system.c b/rv32/system.c
index 13e331b..1cd4385 100644
--- a/rv32/system.c
+++ b/rv32/system.c
@@ -4,6 +4,7 @@
#include "abcio.h"
#include "sys.h"
#include "console.h"
+#include "esplink.h"
#define DEBUG 0
#define MINITESTS 1