sidecartridge / atarist-sidecart-raspberry-pico

AtariST cartridge emulator based on Raspberry Pi Pico and RP2040
GNU General Public License v3.0
57 stars 5 forks source link

Implement Checksum Verification for Disk Emulator Data Transfers #92

Closed diegoparrilla closed 1 month ago

diegoparrilla commented 8 months ago

The current implementation of synchronous commands in the disk emulator utilizes a magic number exchange between the Atari ST code and the RP2040 code to confirm message transmission and acknowledgment. While this method ensures the execution of synchronous operations and safe data exchange, it is not foolproof.

Issues can arise during data transfer if bits are misplaced due to bus contention while accessing the network or SD drive. In such cases, although the magic number may be correctly exchanged, the data itself can become corrupted.

To address this, we propose adding a checksum verification mechanism to enhance data integrity during disk transfer operations. This process would involve the following steps:

Reading Data:

  1. The Atari ST requests to read data from the RP2040.
  2. The RP2040 calculates a checksum for the data and appends it to the outgoing data packet.
  3. The Atari ST first checks the magic number. If it matches, it proceeds; if not, it retries from step 1.
  4. The Atari ST then calculates a checksum for the received data and compares it to the RP2040's checksum. If they match, the process continues; otherwise, it retries as in the magic number check.

Writing Data:

  1. The Atari ST calculates a checksum for the data to be written and sends this along with the data to the RP2040.
  2. The RP2040 verifies the received checksum against its calculation. If they match, the data is stored and an acknowledgment is sent; if not, a negative acknowledgment is returned.
  3. The Atari ST first validates the magic number. If correct, it continues; otherwise, it retries from step 1.
  4. The Atari ST checks the acknowledgment from the RP2040. If positive, the operation completes; if negative, it retries from step 1.

This enhancement aims to improve data transfer reliability, especially in conditions where UART and debugging are enabled, which have been identified as scenarios where this issue is more likely to manifest.

diegoparrilla commented 2 months ago

Reading and writing data implemented in the Floppy Emulator in v0.0.18. Writing data implemented in the GEMDRIVE since v0.0.16