Compare commits
No commits in common. "649887021d1d30b290cc8461933f9da14be36715" and "4ee47d78573bbe4967a757938c5bff96fe20914d" have entirely different histories.
649887021d
...
4ee47d7857
5 changed files with 34 additions and 67 deletions
|
|
@ -204,7 +204,7 @@ void parse_command(const uint8_t *s, uint8_t n)
|
||||||
case 'B':
|
case 'B':
|
||||||
if (cmd_flag('@'))
|
if (cmd_flag('@'))
|
||||||
pipe.valid = 0;
|
pipe.valid = 0;
|
||||||
r = pipe.valid | flash_current_block() << 5;
|
r = pipe.valid;
|
||||||
if (have_b) {
|
if (have_b) {
|
||||||
if (bflg && cmd_flag('!') || ~r & bflg) {
|
if (bflg && cmd_flag('!') || ~r & bflg) {
|
||||||
memcpy(bptr, cmd_buffer, 16);
|
memcpy(bptr, cmd_buffer, 16);
|
||||||
|
|
@ -228,6 +228,7 @@ void parse_command(const uint8_t *s, uint8_t n)
|
||||||
if (~r & bflg)
|
if (~r & bflg)
|
||||||
goto error;
|
goto error;
|
||||||
pipe.valid = r &=~ bflg;
|
pipe.valid = r &=~ bflg;
|
||||||
|
r |= pipe.status << 4;
|
||||||
goto send_buffer;
|
goto send_buffer;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -256,7 +257,7 @@ void parse_command(const uint8_t *s, uint8_t n)
|
||||||
flash_poll(1);
|
flash_poll(1);
|
||||||
if (cmd_flag('!'))
|
if (cmd_flag('!'))
|
||||||
pipe_poll();
|
pipe_poll();
|
||||||
r = pipe.status | flash_current_block();
|
r = pipe.status;
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_FPGA
|
#ifdef HAVE_FPGA
|
||||||
case 'O':
|
case 'O':
|
||||||
|
|
|
||||||
52
src/dose.py
52
src/dose.py
|
|
@ -169,11 +169,6 @@ class dose_cmd(uart.uart):
|
||||||
r += dd[4:4+nn]
|
r += dd[4:4+nn]
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def read_version(self, a="version_str", s=None):
|
|
||||||
r = read_mem(a, s)
|
|
||||||
print(r.decode())
|
|
||||||
return r
|
|
||||||
|
|
||||||
_adc_conf = None
|
_adc_conf = None
|
||||||
_sigrow = None
|
_sigrow = None
|
||||||
|
|
||||||
|
|
@ -569,7 +564,7 @@ class dose_cmd(uart.uart):
|
||||||
def pipe(self, source=None, dest=None,
|
def pipe(self, source=None, dest=None,
|
||||||
fpga_cmd=4, psize=0, n=0,
|
fpga_cmd=4, psize=0, n=0,
|
||||||
page=0, npages=0,
|
page=0, npages=0,
|
||||||
poll=True, stop=False, parity=None):
|
poll=True, stop=False):
|
||||||
astatus = flags2int(self.PIPE, dest)
|
astatus = flags2int(self.PIPE, dest)
|
||||||
astatus |= flags2int(self.PIPE, source)
|
astatus |= flags2int(self.PIPE, source)
|
||||||
astatus >>= 8
|
astatus >>= 8
|
||||||
|
|
@ -604,19 +599,16 @@ class dose_cmd(uart.uart):
|
||||||
if not npages:
|
if not npages:
|
||||||
npages = 1
|
npages = 1
|
||||||
|
|
||||||
if parity == "pipe":
|
|
||||||
status |= 0x30 # PS_BCH
|
|
||||||
|
|
||||||
if source & self.PIPE["FLASH"]:
|
if source & self.PIPE["FLASH"]:
|
||||||
source = self.PIPE["FLASH"]
|
source = self.PIPE["FLASH"]
|
||||||
flash |= 4
|
flash |= 4
|
||||||
status |= 0x10 # PS_528
|
status |= 0x30 # PS_528 | PS_BCH
|
||||||
dest &=~ self.PIPE["FLASH"]
|
dest &=~ self.PIPE["FLASH"]
|
||||||
if dest & self.PIPE["FPGA"] and not n:
|
if dest & self.PIPE["FPGA"] and not n:
|
||||||
n = 512/64 * npages
|
n = 512/64 * npages
|
||||||
if dest & self.PIPE["FLASH"]:
|
if dest & self.PIPE["FLASH"]:
|
||||||
flash |= 8
|
flash |= 8
|
||||||
status |= 0x10 # PS_528
|
status |= 0x30 # PS_528 | PS_BCH
|
||||||
if source == self.PIPE["FPGA"] and not n:
|
if source == self.PIPE["FPGA"] and not n:
|
||||||
n = (512*npages + psize - 1) // psize
|
n = (512*npages + psize - 1) // psize
|
||||||
|
|
||||||
|
|
@ -697,7 +689,7 @@ class dose_cmd(uart.uart):
|
||||||
f.close()
|
f.close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def write_pipe(self, data=[], timeout=2, n=None, parity="pipe", bfill=b'\0', pfill=b'\xff'):
|
def write_pipe(self, data=[], timeout=2, n=None, parity=False, bfill=b'\0', pfill=b'\xff'):
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
f = open(data, "rb")
|
f = open(data, "rb")
|
||||||
data = []
|
data = []
|
||||||
|
|
@ -708,16 +700,6 @@ class dose_cmd(uart.uart):
|
||||||
i = 0
|
i = 0
|
||||||
t = time.time()
|
t = time.time()
|
||||||
s = 1/256
|
s = 1/256
|
||||||
|
|
||||||
# parity="cmd":
|
|
||||||
# calculate the parity with the 'B%' command
|
|
||||||
# parity="data":
|
|
||||||
# calculate the parity with python, or take it from array `data[]`
|
|
||||||
# parity="pipe":
|
|
||||||
# calculate the parity in `pipe_poll()`
|
|
||||||
# !parity:
|
|
||||||
# Do not care about parity (same as "pipe")
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if f:
|
if f:
|
||||||
page = f.read(512)
|
page = f.read(512)
|
||||||
|
|
@ -736,14 +718,13 @@ class dose_cmd(uart.uart):
|
||||||
page += (64-j)*bfill
|
page += (64-j)*bfill
|
||||||
if pfill:
|
if pfill:
|
||||||
page = (page + 512*pfill)[:512]
|
page = (page + 512*pfill)[:512]
|
||||||
if len(page)==512 and parity == "data":
|
if len(page)==512 and parity:
|
||||||
page += bch.page_parity(page)
|
page += bch.page_parity(page)
|
||||||
page = [page[j:j+64] for j in range(0,len(page),64)]
|
page = [page[j:j+64] for j in range(0,len(page),64)]
|
||||||
for b in range(8):
|
for b in range(8):
|
||||||
while True:
|
while True:
|
||||||
cc, nn, dd = self.cmd("B")
|
cc, nn, dd = self.cmd("B")
|
||||||
tt = time.time()
|
tt = time.time()
|
||||||
bb = nn>>5
|
|
||||||
nn &= 0xf
|
nn &= 0xf
|
||||||
if not nn:
|
if not nn:
|
||||||
t = tt
|
t = tt
|
||||||
|
|
@ -759,23 +740,12 @@ class dose_cmd(uart.uart):
|
||||||
s = 1
|
s = 1
|
||||||
if nn:
|
if nn:
|
||||||
break
|
break
|
||||||
if bb != b:
|
if parity and b==7:
|
||||||
raise ValueError(f"block number mismatch {b=} != {bb=}")
|
self.cmd("B@4", page[8])
|
||||||
if b >= len(page):
|
if b >= len(page):
|
||||||
break
|
break
|
||||||
if parity == "data" and b==7:
|
|
||||||
self.cmd("B4@", page[8])
|
|
||||||
for j in range(4):
|
for j in range(4):
|
||||||
B = f"B{j}"
|
self.cmd(f"B{j}", page[b][16*j:16*(j+1)])
|
||||||
if parity == "cmd":
|
|
||||||
B += "%"
|
|
||||||
if not b and not j:
|
|
||||||
B += "@"
|
|
||||||
if b==7 and j==3:
|
|
||||||
B += "!"
|
|
||||||
ccc,nnn,ddd = self.cmd(B, page[b][16*j:16*(j+1)])
|
|
||||||
if self._verbose >= 3:
|
|
||||||
print(f"write_pipe {i=} {b=} {j=} {B=} {nn=}, {ccc=}, {nnn=:#02x}", file=sys.stderr)
|
|
||||||
if self._verbose >= 2:
|
if self._verbose >= 2:
|
||||||
self.peek("pipe", 11)
|
self.peek("pipe", 11)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
@ -804,12 +774,6 @@ class dose_cmd(uart.uart):
|
||||||
raise bch.BCHError("galois module not loaded for Parity Error correction")
|
raise bch.BCHError("galois module not loaded for Parity Error correction")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def write_file2flash(self, filename, page, npages=None, parity="pipe"):
|
|
||||||
if npages is None:
|
|
||||||
npages = (os.stat(filename).st_size + 511) // 512
|
|
||||||
self.pipe("CMD", "FLASH", page=page, npages=npages, parity=parity)
|
|
||||||
return self.write_pipe(filename, parity=parity)
|
|
||||||
|
|
||||||
def flags2int(FLAGS, flags):
|
def flags2int(FLAGS, flags):
|
||||||
r = 0
|
r = 0
|
||||||
if flags is None:
|
if flags is None:
|
||||||
|
|
|
||||||
|
|
@ -253,11 +253,9 @@ uint8_t flash_poll(uint8_t rr)
|
||||||
if (r & FS_Ready)
|
if (r & FS_Ready)
|
||||||
goto ready;
|
goto ready;
|
||||||
|
|
||||||
if (r & FS_StBsy && flash_status_bytes[0] & 0x80) {
|
if (r & FS_StBsy && flash_status_bytes[0] & 0x80)
|
||||||
// flash is done burning
|
// flash is done burning
|
||||||
fs.block &= ~7;
|
|
||||||
goto ready;
|
goto ready;
|
||||||
}
|
|
||||||
if (r & FS_Write && fs.block == 9) {
|
if (r & FS_Write && fs.block == 9) {
|
||||||
// Write or Erase
|
// Write or Erase
|
||||||
r |= FS_StBsy;
|
r |= FS_StBsy;
|
||||||
|
|
|
||||||
38
src/pipe.c
38
src/pipe.c
|
|
@ -69,43 +69,43 @@ uint8_t pipe_poll()
|
||||||
// flash did not finish yet, successfully
|
// flash did not finish yet, successfully
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
// fpga is OUT when the spi is ready.
|
||||||
|
// We are done with this buffer
|
||||||
|
|
||||||
|
r &=~ PS_OUT;
|
||||||
|
|
||||||
// Return if next ADC reading is not yet due.
|
// Return if next ADC reading is not yet due.
|
||||||
// Come back here, until is is.
|
// Come back here, until is is.
|
||||||
|
|
||||||
if (pipe.source == pipe_adc && !adc_poll(pipe.adc))
|
if (pipe.source == pipe_adc && !adc_poll(pipe.adc))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
// fpga is OUT when the spi is ready.
|
|
||||||
// We are done with this buffer
|
|
||||||
|
|
||||||
r &=~ PS_OUT;
|
|
||||||
|
|
||||||
// Continue the flash stream.
|
// Continue the flash stream.
|
||||||
|
// PS_BLK is the 64-Bytes buffer number in the page
|
||||||
|
|
||||||
valid = 0;
|
valid = 0;
|
||||||
if (pipe.source == pipe_flash)
|
if (pipe.source == pipe_flash) {
|
||||||
|
r &= ~ PS_BLK;
|
||||||
|
r |= flash_current_block() & PS_BLK;
|
||||||
flash_poll(1);
|
flash_poll(1);
|
||||||
|
}
|
||||||
#ifdef HAVE_FPGA
|
#ifdef HAVE_FPGA
|
||||||
// Continue the FPGA stream.
|
// Continue the FPGA stream.
|
||||||
|
|
||||||
else if (pipe.source == pipe_fpga && !fpga_start_read())
|
else if (pipe.source == pipe_fpga) {
|
||||||
pipe.source = 0;
|
if (!fpga_start_read())
|
||||||
|
pipe.source = 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waiting for the buffer to fill
|
// Waiting for the buffer to fill
|
||||||
|
|
||||||
// The current block index in the flash page
|
|
||||||
uint8_t b = flash_current_block();
|
|
||||||
if (pipe.source == pipe_flash)
|
|
||||||
// The valid data is from the previous block
|
|
||||||
b -= 1;
|
|
||||||
b &= 7;
|
|
||||||
uint8_t bflgs = 0x0f;
|
|
||||||
// For 528 bytes pages, the last buffer must be 80 Bytes,
|
// For 528 bytes pages, the last buffer must be 80 Bytes,
|
||||||
// i.e., five cmd_buffers á 16 Bytes
|
// i.e., five cmd_buffers á 16 Bytes
|
||||||
if (b==7 && r & PS_528)
|
uint8_t bflgs = 0x0f;
|
||||||
|
if ((r & PS_5) == PS_5)
|
||||||
bflgs = 0x1f;
|
bflgs = 0x1f;
|
||||||
|
|
||||||
// Data from the ADC is in named .bss segments. We send
|
// Data from the ADC is in named .bss segments. We send
|
||||||
|
|
@ -174,12 +174,12 @@ adc_done:
|
||||||
// The buffer shall include BCH Bytes.
|
// The buffer shall include BCH Bytes.
|
||||||
if (r & PS_BCH) {
|
if (r & PS_BCH) {
|
||||||
// First buffer of a page, clear the parity
|
// First buffer of a page, clear the parity
|
||||||
if (!b)
|
if (!(r & PS_BLK))
|
||||||
bch4369_init(config.bch_salt);
|
bch4369_init(config.bch_salt);
|
||||||
// Add the current buffer to the parity
|
// Add the current buffer to the parity
|
||||||
uint8_t *bend = bch4369_stri(flash_buffer, 64);
|
uint8_t *bend = bch4369_stri(flash_buffer, 64);
|
||||||
// Last buffer of the page:
|
// Last buffer of the page:
|
||||||
if (b==7) {
|
if (!(~r & PS_BLK)) {
|
||||||
bch4369_fini();
|
bch4369_fini();
|
||||||
// When the Flash is not the source,
|
// When the Flash is not the source,
|
||||||
// and cmd did not provide the parity
|
// and cmd did not provide the parity
|
||||||
|
|
@ -210,6 +210,8 @@ adc_done:
|
||||||
#endif
|
#endif
|
||||||
// Resume the flash stream
|
// Resume the flash stream
|
||||||
if (dest & pipe_flash) {
|
if (dest & pipe_flash) {
|
||||||
|
r &= ~ PS_BLK;
|
||||||
|
r |= flash_current_block() & PS_BLK;
|
||||||
flash_poll(1);
|
flash_poll(1);
|
||||||
if (flash_stream_done())
|
if (flash_stream_done())
|
||||||
dest &=~ pipe_flash;
|
dest &=~ pipe_flash;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ enum pipe_ports {
|
||||||
PS_ERR = 0x40,
|
PS_ERR = 0x40,
|
||||||
PS_BCH = 0x20,
|
PS_BCH = 0x20,
|
||||||
PS_528 = 0x10,
|
PS_528 = 0x10,
|
||||||
|
PS_BLK = 0x07,
|
||||||
|
PS_5 = PS_BLK | PS_528, // need 16 bytes more
|
||||||
|
|
||||||
AS_CONT = 1,
|
AS_CONT = 1,
|
||||||
AS_CONFIG = SPI_CONFIG, // = 2
|
AS_CONFIG = SPI_CONFIG, // = 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue