Skip to content

Instantly share code, notes, and snippets.

@magik6k
Last active December 23, 2018 13:50
Show Gist options
  • Save magik6k/d1a739a5f032e93aba2742b9fa243a26 to your computer and use it in GitHub Desktop.
Save magik6k/d1a739a5f032e93aba2742b9fa243a26 to your computer and use it in GitHub Desktop.
Ram gate
Memory is split into 32-byte segments, accessible with 1-byte granularity
One gate up to 1MiB (32768 segments), little endian
C I O
T N U
L T
0 0 0 - idle
1 C 0 - start of command, C is the command
...
1 C 0
0 C 0 - submit
0 0 1 - ack (if 0 then mem fault, idle for 128 ticks for safety)
Commands (LSB...MSB):
0 aaaaa - read from address (segAddr+aaaaa)
chunkSize bytes will be read, chunks can cross segment boundary
10 aaaaa (dddd dddd)^cs - write chunkSize bytes
chunks can cross segment boundary
11 00 x^(memLen-1) - set segment (for read/write)
11 01 0 xxxx - set memory len (in segments, log2, up to 32767 (1 MiB))
11 01 1 - set chunk size
00 - 1 byte
01 - 2 bytes
10 - 4 bytes
11 - reserved
11 10 - get memory len
-> llll -> l -mem len in log2 segments
-----
Example communication
C I O
T N U
L T
0 0 0
0 0 0 - idle
1 1 0
1 1 0
1 0 0
1 1 0
1 1 0 - set chunk size
1 1 0
0 0 0 - to 4 bytes, also submit
0 0 1 - ack from memory
Example streams
C starts when CTL goes up
O starts when CTL went down tick before (ack in example before)
Starting memory (2 segments)
00 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
C -> O
// safe setup
11 01 10 -> 1 - set 4 byte chunk
11 10 -> 1 0001 - get memory len (returns 2)
11 01 0 0010 -> 1 - expand memory to 4 segments
11 00 0000 -> 1 - set segment to 0
0 00001 - 1 10101010 00000000 00000000 00000000 - read 4 bytes from address 1 seg 0
11 00 0001 -> 1 - set segment to 1
0 00001 - 1 11111111 11111111 00000000 00000000 - read 4 bytes from address 1 seg 1
10 11110 00010001 00010001 00010001 00010010 -> 1 - write 4 bytes from address 30 seg 1
End memory:
00 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 11
11 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment