Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions agent/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ static void handle_write(const uint8_t *data, uint32_t len) {
uint32_t chunk = pkt_len - 2;
for (uint32_t i = 0; i < chunk && received < size; i++)
dest[received++] = pkt[2 + i];
/* Backpressure: COBS-framed ACK after each DATA packet.
* Host waits for this before sending next packet. */
proto_send_ack(ACK_OK);
/* No per-packet ACK — streaming mode. COBS CRC32 per packet
* catches any corruption. D-cache makes processing fast
* enough to keep up with 921600 baud. */
} else if (cmd == 0) {
uint8_t err[5];
err[0] = ACK_FLASH_ERROR;
Expand Down Expand Up @@ -333,8 +333,6 @@ static void handle_flash_write(const uint8_t *data, uint32_t len) {
uint32_t chunk = pkt_len - 2;
for (uint32_t i = 0; i < chunk && received < size; i++)
staging[received++] = pkt[2 + i];
/* Backpressure ACK */
proto_send_ack(ACK_OK);
} else if (cmd == 0) {
uint8_t err[5];
err[0] = ACK_FLASH_ERROR;
Expand Down Expand Up @@ -540,8 +538,7 @@ static void handle_selfupdate(const uint8_t *data, uint32_t len) {
uint32_t chunk = pkt_len - 2;
for (uint32_t i = 0; i < chunk && received < size; i++)
dest[received++] = pkt[2 + i];
/* Backpressure ACK — host must wait before sending next */
proto_send_ack(ACK_OK);
/* Streaming mode — no per-packet ACK */
} else if (cmd == 0) {
proto_send_ack(ACK_FLASH_ERROR);
return;
Expand Down
19 changes: 4 additions & 15 deletions src/defib/agent/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ async def _write_block(self, addr: int, data: bytes) -> bool:
if cmd != RSP_ACK or resp[0] != ACK_OK:
return False

# Send data packets with backpressure: agent sends a COBS-framed
# ACK after each DATA packet. Host waits for it before sending
# next. Guarantees zero data loss at any speed.
# Stream all DATA packets without per-packet ACK.
# With COBS bug fixed + D-cache, the agent processes fast
# enough to keep up at 921600 baud.
offset = 0
seq = 0
while offset < len(data):
Expand All @@ -335,11 +335,6 @@ async def _write_block(self, addr: int, data: bytes) -> bool:
offset += chunk
seq += 1

# Wait for per-packet ACK
cmd, resp = await recv_response(self._transport, timeout=10.0)
if cmd != RSP_ACK or resp[0] != ACK_OK:
return False

# Final CRC verification ACK — may take seconds for large transfers
crc_timeout = max(60.0, len(data) / 50000) # ~20µs/byte for CRC32
cmd, resp = await recv_response(self._transport, timeout=crc_timeout)
Expand Down Expand Up @@ -603,7 +598,7 @@ async def selfupdate(
if cmd != RSP_ACK or resp[0] != ACK_OK:
return False

# Send data with per-packet backpressure
# Stream all data packets
offset = 0
seq = 0
while offset < len(firmware):
Expand All @@ -613,12 +608,6 @@ async def selfupdate(
offset += chunk
seq += 1

# Wait for per-packet ACK
cmd, resp = await recv_response(self._transport, timeout=10.0)
if cmd != RSP_ACK or resp[0] != ACK_OK:
logger.error("Selfupdate packet %d failed: 0x%02x", seq, resp[0])
return False

# Wait for CRC verification ACK (agent verifies before jumping)
cmd, resp = await recv_response(self._transport, timeout=30.0)
if cmd != RSP_ACK or resp[0] != ACK_OK:
Expand Down
Loading