[Cryptech-Commits] [sw/stm32] 03/09: Write in 4k-chunks, with acks for flow control.

git at cryptech.is git at cryptech.is
Wed May 18 19:16:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

fredrik at thulin.net pushed a commit to branch master
in repository sw/stm32.

commit 18b11939bf24b2f75ea54eb93d7d29273262c476
Author: Fredrik Thulin <fredrik at thulin.net>
AuthorDate: Tue May 17 09:50:38 2016 +0200

    Write in 4k-chunks, with acks for flow control.
---
 projects/cli-test/cli-test.c   | 8 +++++---
 projects/cli-test/filetransfer | 8 +++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c
index 0b54e7e..5d33b27 100644
--- a/projects/cli-test/cli-test.c
+++ b/projects/cli-test/cli-test.c
@@ -49,10 +49,10 @@ extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len);
 
 int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv[], int argc)
 {
-    uint32_t filesize = 0, crc = 0, my_crc = 0, n = 4;
-    uint8_t buf[4];
+    uint32_t filesize = 0, crc = 0, my_crc = 0, n = 4096, counter = 0;
+    uint8_t buf[4096];
 
-    cli_print(cli, "OK, write file size (4 bytes), data, CRC-32 (4 bytes)");
+    cli_print(cli, "OK, write file size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)");
 
     uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, 4, 1000);
     cli_print(cli, "Filesize %li", filesize);
@@ -65,6 +65,8 @@ int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv[], int
 	uart_receive_bytes(STM_UART_MGMT, (void *) &buf, n, 1000);
 	filesize -= n;
 	my_crc = update_crc(my_crc, buf, n);
+	counter++;
+	uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4);
     }
 
     uart_receive_bytes(STM_UART_MGMT, (void *) &crc, 4, 1000);
diff --git a/projects/cli-test/filetransfer b/projects/cli-test/filetransfer
index 451a1d9..3e8e043 100755
--- a/projects/cli-test/filetransfer
+++ b/projects/cli-test/filetransfer
@@ -64,13 +64,19 @@ def send_file(filename, device='/dev/ttyUSB0', initiate=True):
     _read(dst)
     # 2. Write file contents while calculating CRC-32
     crc = 0
+    counter = 0
     while True:
-        data = src.read(1024)
+        data = src.read(4096)
         if not data:
             break
         dst.write(data)
         print("Wrote {!s} bytes".format(len(data)))
         crc = crc32(data, crc) & 0xffffffff
+        new_counter = struct.unpack('<I', dst.read(4))[0]
+        if new_counter != counter + 1:
+            print('ERROR: Did not receive the expected counter as ACK (got {!r}, not {!r})'.format(new_counter, counter))
+            return False
+        counter += 1
     # 3. Write CRC-32 (4 bytes)
     _write(dst, struct.pack('<I', crc))
     _read(dst)



More information about the Commits mailing list