diff --git a/src/config.c b/src/config.c index c3556ac..9cca87f 100644 --- a/src/config.c +++ b/src/config.c @@ -28,8 +28,8 @@ const struct config config = { .pwm_max = 0xffff, #endif #ifdef HAVE_FPGA - .fpga_config_page = 8, - .fpga_config_count = 504, + .fpga_config_page = 1, + .fpga_config_count = 511, #endif }; diff --git a/src/dose.py b/src/dose.py index 74a830d..ca3b2e1 100755 --- a/src/dose.py +++ b/src/dose.py @@ -220,7 +220,7 @@ class dose_cmd(uart.uart): r.append((dc, self.adc())) return r - def flash(self, op=None, resp=False, poll=False, **aa): + def flash(self, op=None, resp=True, poll=False, **aa): c = "F" if poll: c = "F@" @@ -254,7 +254,6 @@ class dose_cmd(uart.uart): self.wait_for_spi() def wait_for_spi(self): - return while True: r = self.cmd("F")[1] if not r: @@ -299,7 +298,10 @@ class dose_cmd(uart.uart): def flash_status(self, blocking=False): r = (0,0,bytes(2)) while not r[2][0] & 0x80: - r = self.flash("Status", resp=True, what="cmdbuf") + self.flash("Status", what="cmdbuf") + r = self.cmd("F<") + while r[1]: + r = self.cmd("F<") if not blocking: break return tuple(r[2][:2]) @@ -310,10 +312,10 @@ class dose_cmd(uart.uart): self.flash("Program2", page=page) self.flash_status(True) - def write_file2flash(self, page, fn, pages): + def write_file2flash(self, page, fn): n = 0 with open(fn, "rb") as f: - while not pages or n < pages: + while True: b =f.read(512) if not b: break @@ -342,7 +344,7 @@ class dose_cmd(uart.uart): self.flash(op) def flash_Id(self): - r = self.flash("Id", resp=True, what="cmdbuf") + r = self.flash("Id", what="cmdbuf") i = r[2][:5] print(f"FLASH chip {b2hex(i)}", file=sys.stderr) return i @@ -373,7 +375,7 @@ class dose_cmd(uart.uart): FPGA_FLGS = { "ABORT": 0x01, - "DEAD": 0x10, + "ABORTED": 0x10, "BUSY": 0x20, "SUBMITTED": 0x40, "CONFIG": 0x80, diff --git a/src/fpga.c b/src/fpga.c index 9300742..8b7a770 100644 --- a/src/fpga.c +++ b/src/fpga.c @@ -38,15 +38,21 @@ void fpga_cmd(struct fpga_cmd *c) uint8_t n = c->n; uint8_t z = c->z; if (fpga_status() != as_configured) { - n |= fpga_dead; - if (~n & fpga_configure) { - c->n = n; - return; - } + c->n = n | fpga_dead; + return; } - c->n = n & ~fpga_busy | fpga_submitted; + if (n & fpga_abort && spi_abort()) { + c->n = n | fpga_aborted; + return; + } + else if (spi_busy_p()) { + c->n = n | fpga_busy; + return; + } + c->n = n & ~fpga_busy; if (n & fpga_submitted) return; + c->n = n | fpga_submitted; spi_select(n & fpga_configure ? SPI_CONFIG : 0); spi.csize = n &= fpga_size; @@ -56,8 +62,7 @@ void fpga_cmd(struct fpga_cmd *c) if (z & fpga_wait_nonzero) { spi.isize = n + (z>>3 & fpga_size); // ignore cmd ± (z[6:4]) spi.zsize = spi.rsize = z & fpga_size; // read x[3:1] words - // start reading at the first byte with MSB set after cmd - spi.mask = spi.wait = 0x80; + spi.mask = 0xff; // start reading at the first nonzero byte after cmd } else { spi.zsize = z &= 0x7e; // send z zeros/nop after cmd diff --git a/src/fpga.h b/src/fpga.h index 0e24b32..7576d36 100644 --- a/src/fpga.h +++ b/src/fpga.h @@ -8,11 +8,13 @@ struct fpga_cmd { }; enum fpga_flags { + fpga_abort = 0x01, fpga_size = 0x0e, - fpga_dead = 0x10, + fpga_aborted = 0x10, fpga_busy = 0x20, fpga_submitted = 0x40, fpga_configure = 0x80, + fpga_dead = 0x80, fpga_wait_nonzero = 0x01, };