scsi_accel.pio 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ; RP2040 PIO program for accelerating SCSI communication
  2. ; Run "pioasm scsi_accel.pio scsi_accel.pio.h" to regenerate the C header from this.
  3. ; GPIO mapping:
  4. ; - 0-7: DB0-DB7
  5. ; - 8: DBP
  6. ; Side set is REQ pin
  7. .define REQ 17 ; was 9
  8. .define ACK 26 ; was 10
  9. ; Delay from data setup to REQ assertion.
  10. ; deskew delay + cable skew delay = 55 ns minimum
  11. ; One clock cycle is 8 ns => delay 7 clocks
  12. .define REQ_DLY 7
  13. ; Write to SCSI bus using asynchronous handshake.
  14. ; Data is written as 16-bit words that contain the 8 data bits + 1 parity bit.
  15. ; 7 bits in each word are discarded.
  16. ; Number of bytes to send must be multiple of 2.
  17. .program scsi_accel_async_write
  18. .side_set 1
  19. pull ifempty block side 1 ; Get data from TX FIFO
  20. out pins, 9 side 1 ; Write data and parity bit
  21. out null, 7 [REQ_DLY-2] side 1 ; Discard unused bits, wait for data preset time
  22. wait 1 gpio ACK side 1 ; Wait for ACK to be inactive
  23. wait 0 gpio ACK side 0 ; Assert REQ, wait for ACK low
  24. ; Read from SCSI bus using asynchronous handshake.
  25. ; Also works for synchronous mode down to 50 ns transfer period.
  26. ; Data is returned as 16-bit words that contain the 8 data bits + 1 parity bit.
  27. ; Number of bytes to receive minus 1 should be written to TX fifo.
  28. ; Number of bytes to receive must be divisible by 2.
  29. .program scsi_accel_async_read
  30. .side_set 1
  31. pull block side 1 ; Get number of bytes to receive
  32. mov x, osr side 1 ; Store to counter X
  33. start:
  34. wait 1 gpio ACK side 1 ; Wait for ACK high
  35. wait 0 gpio ACK side 0 ; Assert REQ, wait for ACK low
  36. in pins, 9 side 1 ; Deassert REQ, read GPIO
  37. in null, 7 side 1 ; Padding bits
  38. jmp x-- start side 1 ; Decrement byte count and jump to start
  39. ; Data state machine for synchronous writes.
  40. ; Takes the lowest 9 bits of each 16 bit word and writes them to bus with REQ pulse.
  41. ; The delay times will be rewritten by C code to match the negotiated SCSI sync speed.
  42. ;
  43. ; Shifts one bit to ISR per every byte transmitted. This is used to control the transfer
  44. ; pace, the RX fifo acts as a counter to keep track of unacknowledged bytes. The C code
  45. ; can set the syncOffset by changing autopush threshold, e.g. threshold 3 = 12 bytes offset.
  46. .program scsi_sync_write
  47. .side_set 1
  48. out pins, 9 [0] side 1 ; Write data and parity bit, wait for deskew delay
  49. out null, 7 [0] side 0 ; Assert REQ, wait for assert time
  50. in null, 1 [0] side 1 ; Deassert REQ, wait for transfer period, wait for space in ACK buffer
  51. ; Data pacing state machine for synchronous writes.
  52. ; Takes one bit from ISR on every falling edge of ACK.
  53. ; The C code should set autopull threshold to match scsi_sync_write autopush threshold.
  54. ; System DMA will then move words from scsi_sync_write RX fifo to scsi_sync_write_pacer TX fifo.
  55. .program scsi_sync_write_pacer
  56. wait 1 gpio ACK
  57. wait 0 gpio ACK ; Wait for falling edge on ACK
  58. out null, 1 ; Let scsi_sync_write send one more byte