-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
245 lines (195 loc) · 7.73 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
- both microcontrollers are directly connected to the TX and RX lines of the
USB serial chip.
requesting MCU status:
1. send chip ID (0x31 or 0x32)
2. receive 6-byte report from chip:
a. chip ID
b. acc + 1000 = xxxxhhhh xlllllll (11 significant bits)
c. dat + 1000 = xxxxhhhh xlllllll (11 significant bits)
d. checksum over acc and dat
programming:
- a start byte followed by a chip ID indicates which MCU should receive/respond
- maximum program size: 255
protocol:
1. send start code (0x7F)
2. send chip ID (0x31 or 0x32)
3. send program
4. send checksum (over program)
5. send end code (0x7E)
6. expect 3-byte confirmation from chip:
a. start code (0x7F)
b. chip ID
c. result (0x01 = success, 0x00 = failure)
instruction encoding:
xcccccmp [arg1] [arg2]
^\___/^^
| | |'-plus?
| | '-minus?
| '-operation
'-unused (0)
operations:
1 = nop
2 = mov R/I R
3 = jmp L
4 = slp R/I
5 = slx P
6 = teq R/I R/I
7 = tgt R/I R/I
8 = tlt R/I R/I
9 = tcp R/I R/I
10 = add R/I
11 = sub R/I
12 = mul R/I
13 = not
14 = dgt R/I
15 = dst R/I R/I
16 = lbl L
31 = reserved (so 0x7F and 0x7E remain available as start/end codes)
argument encoding R/I:
x110xxxx xxxxxxxx = dat
x111xxxx xxxxxxxx = acc
x1000xxx xxxxxxxx = x0
x1001xxx xxxxxxxx = x1
x1010xxx xxxxxxxx = p0
x1011xxx xxxxxxxx = p1
x00hhhhh xxllllll = hhhhhllllll - 1000
argument encoding R:
x110xxxx = dat
x111xxxx = acc
x1000xxx = x0
x1001xxx = x1
x1010xxx = p0
x1011xxx = p1
argument encoding L:
llllllll = label number (assigned in order, starting at 0)
argument encoding P:
x1xxxxxx = x0
x0xxxxxx = x1
checksum calculation:
chk(bytes) = - sum(bytes) / 4 (mod 256)
calculate mod 256:
1. add up the input bytes
2. negate
3. divide by 4 (shift right by 2 bits)
result is a 6-bit number.
FIRMWARE STATE MACHINE:
internally defined state names:
- no_prog
- empty_prog
- transmission_start
- line_prog
- prog_ready
the actual state is a pair (state, prev_state), for a total of 25 combinations.
however, most combinations are unreachable.
transitions:
(empty_prog, no_prog) REACHABLE INITIAL
- START_CHAR -> (transmission_start, empty_prog)
- own chip ID -> (empty_prog, no_prog) & report (not programmed)
- other input -> (empty_prog, no_prog)
(transmission_start, empty_prog) REACHABLE
- START_CHAR -> (transmission_start, empty_prog)
- own chip ID -> (line_prog, no_prog)
- other chip ID -> (empty_prog, no_prog)
XXX following program bytes could be interpreted in (empty_prog, no_prog)
(line_prog, no_prog) REACHABLE
- START_CHAR -> (transmission_start, line_prog)
- END_CHAR, nothing received -> (empty_prog, no_prog) & reset/success
- END_CHAR, 1 byte received -> (empty_prog, no_prog) & reset/success
- END_CHAR, 2 bytes received -> (empty_prog, no_prog) & reset/success
- END_CHAR, checksum OK -> (prog_ready, no_prog) & enable/success
- END_CHAR, checksum bad -> (empty_prog, no_prog) & reset/failure
- other input -> (line_prog, no_prog) & store input in buffer
(prog_ready, no_prog) REACHABLE
- START_CHAR -> (transmission_start, prog_ready)
- own chip ID -> (prog_ready, no_prog) & report
- other input -> (prog_ready, no_prog)
- program error -> (empty_prog, no_prog)
(transmission_start, prog_ready) REACHABLE
- START_CHAR -> (transmission_start, prog_ready)
- own chip ID -> (line_prog, no_prog)
- other chip ID -> (prog_ready, no_prog)
XXX following program bytes could be interpreted in (prog_ready, no_prog)
(transmission_start, line_prog) REACHABLE NONSTD
- START_CHAR -> (transmission_start, line_prog)
- own chip ID -> (line_prog, no_prog)
- other chip ID -> (line_prog, no_prog)
XXX this transition lets us write the same program to many chips at once!
START_CHAR, ID1, START_CHAR, ID2, START_CHAR, XX, (program)...
(empty_prog, empty_prog)
- START_CHAR -> (transmission_start, empty_prog)
- own chip ID -> (empty_prog, empty_prog) & report (not programmed)
- other input -> (empty_prog, empty_prog)
(empty_prog, transmission_start)
- START_CHAR -> (transmission_start, transmission_start)
- own chip ID -> (empty_prog, transmission_start) & report (not programmed)
- other input -> (empty_prog, transmission_start)
(empty_prog, line_prog)
- START_CHAR -> (transmission_start, line_prog)
- own chip ID -> (empty_prog, line_prog) & report (not programmed)
- other input -> (empty_prog, line_prog)
(empty_prog, prog_ready)
- START_CHAR -> (transmission_start, prog_ready)
- own chip ID -> (empty_prog, prog_ready) & report (not programmed)
- other input -> (empty_prog, prog_ready)
(transmission_start, no_prog)
- START_CHAR -> (transmission_start, transmission_start)
- own chip ID -> (line_prog, no_prog)
- other chip ID -> (no_prog, no_prog)
(transmission_start, transmission_start)
- START_CHAR -> (transmission_start, transmission_start)
- own chip ID -> (line_prog, no_prog)
- other chip ID -> (transmission_start, no_prog)
(line_prog, empty_prog)
- START_CHAR -> (transmission_start, empty_prog)
- END_CHAR, short input -> (empty_prog, empty_prog) & reset/success
- END_CHAR, checksum OK -> (prog_ready, empty_prog) & enable/success
- END_CHAR, checksum bad -> (empty_prog, empty_prog) & reset/failure
- other input -> (line_prog, empty_prog) & buffer input
(line_prog, transmission_start)
- START_CHAR -> (transmission_start, transmission_start)
- END_CHAR, short input -> (empty_prog, transmission_start) & reset/success
- END_CHAR, checksum OK -> (prog_ready, transmission_start) & enable/success
- END_CHAR, checksum bad -> (empty_prog, transmission_start) & reset/failure
- other input -> (line_prog, transmission_start) & buffer input
(line_prog, line_prog)
- START_CHAR -> (transmission_start, line_prog)
- END_CHAR, short input -> (empty_prog, line_prog) & reset/success
- END_CHAR, checksum OK -> (prog_ready, line_prog) & enable/success
- END_CHAR, checksum bad -> (empty_prog, line_prog) & reset/failure
- other input -> (line_prog, line_prog) & buffer input
(line_prog, prog_ready)
- START_CHAR -> (transmission_start, prog_ready)
- END_CHAR, short input -> (empty_prog, prog_ready) & reset/success
- END_CHAR, checksum OK -> (prog_ready, prog_ready) & enable/success
- END_CHAR, checksum bad -> (empty_prog, prog_ready) & reset/failure
- other input -> (line_prog, prog_ready) & buffer input
(prog_ready, empty_prog)
- START_CHAR -> (transmission_start, empty_prog)
- own chip ID -> (prog_ready, empty_prog) & report
- other input -> (prog_ready, empty_prog)
- program error -> (empty_prog, empty_prog)
(prog_ready, transmission_start)
- START_CHAR -> (transmission_start, transmission_start)
- own chip ID -> (prog_ready, transmission_start) & report
- other input -> (prog_ready, transmission_start)
- program error -> (empty_prog, transmission_start)
(prog_ready, line_prog)
- START_CHAR -> (transmission_start, line_prog)
- own chip ID -> (prog_ready, line_prog) & report
- other input -> (prog_ready, line_prog)
- program error -> (empty_prog, line_prog)
(prog_ready, prog_ready)
- START_CHAR -> (transmission_start, prog_ready)
- own chip ID -> (prog_ready, prog_ready) & report (programmed)
- other input -> (prog_ready, prog_ready)
- program error -> (empty_prog, prog_ready)
(no_prog, no_prog)
- START_CHAR -> (transmission_start, no_prog)
(no_prog, empty_prog)
- START_CHAR -> (transmission_start, empty_prog)
(no_prog, transmission_start)
- START_CHAR -> (transmission_start, transmission_start)
(no_prog, line_prog)
- START_CHAR -> (transmission_start, line_prog)
(no_prog, prog_ready)
- START_CHAR -> (transmission_start, prog_ready)