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