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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
$MOD167
$SEGMENTED
$INCLUDE (REG167.INC)
$INCLUDE (COMMON.INC)
NAME FIRMWARE_ST10F269
ASSUME DPP3: SYSTEM
FW_DATA SECTION DATA WORD AT FW2DATA
; Control array of structures {segment, address, length in words} for read and write operations
FLASH_MAPPING:
DW 1,0000h,(16*1024)/2
DW 1,4000h,(8*1024)/2
DW 1,6000h,(8*1024)/2
DW 1,8000h,(32*1024)/2
DW 2,0000h,(64*1024)/2
DW 3,0000h,(64*1024)/2 ; Length is not needed
DW 4,0000h,(64*1024)/2 ; Length is not needed
FW_DATA ENDS
FW_ST10F269 SECTION CODE AT FW2BASE
;-------------------------------------------------------------------------------
; Main procedure
;
; Caka na slovo prikazu, odosle ho naspat pre potvrdenie a to iste musi znovu
; prijat.
;-------------------------------------------------------------------------------
MAIN PROC
; REMAP flash to segment 1 !!! Because of BUG.
BSET ROMS1
; Default register bank
MOV CP,#REGBANK0
; Zapneme serial buffer overrun detection
BSET S0CON.7
; Init stack, size = 128 words, 256 bytes
MOV R0,SYSCON
AND R0,#3FFFh
OR R0,#2000h
MOV SYSCON,R0
MOV STKUN, #STACK_TOP
MOV STKOV, #STACK_BOTTOM
MOV SP, #STACK_TOP
NOP
NOP
MOV DPP0,#0
MOV DPP1,#1
MOV DPP2,#2
MOV DPP3,#3
; Signalize successful initialization
MOV R15,#0
CALL SEND
;-----------------------------------------------------------------------
; Command loop
;-----------------------------------------------------------------------
$INCLUDE (SHELL.INC)
MAIN ENDP
;-------------------------------------------------------------------------------
; Receive config information (1 word)
;-------------------------------------------------------------------------------
REC_CONFIG PROC NEAR
CALL REC_SAFE
RET
REC_CONFIG ENDP
;-------------------------------------------------------------------------------
; Erase chip
;-------------------------------------------------------------------------------
ERASE_CHIP PROC NEAR
SCXT CP,#REGBANK1
; Receive config information
CALL REC_CONFIG
CMP R14,#0
JMPR CC_NE,ERASE_CHIP_ERROR
MOV R0,#1554h
MOV R1,#2AA8h
MOV R2,#0A8h
MOV R3,#54h
MOV R4,#80h
MOV R5,#10h
; Command cycles
EXTS #1,#3
MOV [R0],R2 ; [1554h], 0A80h
MOV [R1],R3 ; [2AA8h], 54h
MOV [R0],R4 ; [1554h], 80h
EXTS #1,#3
MOV [R0],R2 ; [1554h], 0A80h
MOV [R1],R3 ; [2AA8h], 54h
MOV [R0],R5 ; [1554h], 10h
NOP ; For BUG: Last command cycle
NOP
; Pockame na dokoncenie zmazania chipu a detekujeme chyby
MOV R0,#1
MOV R1,#0000h
CALL OP_WAIT
MOV R15,R14
CALL SEND
ERASE_CHIP_ERROR:
POP CP
RET
ERASE_CHIP ENDP
;-------------------------------------------------------------------------------
; Erase blocks
;-------------------------------------------------------------------------------
ERASE_BLOCKS PROC NEAR
SCXT CP,#REGBANK1
; Receive config information
CALL REC_CONFIG
CMP R14,#0
JMPR CC_NE,ERASE_BLOCKS_ERROR
; Receive mask of blocks going to be erased
CALL REC_SAFE
; Store mask
MOV R13,R15
; Exit if there was an error
CMP R14,#0
JMPR CC_NE,ERASE_BLOCKS_ERROR
ERASE_BLOCKS_START:
; Base address of the control structure
MOV R11,#DPP3:FLASH_MAPPING
MOV R0,#1554h
MOV R1,#2AA8h
MOV R2,#0A8h
MOV R3,#54h
MOV R4,#80h
; Command cycles
EXTS #1,#3
MOV [R0],R2 ; [1554h], 0A8h
MOV [R1],R3 ; [2AA8h], 54h
MOV [R0],R4 ; [1554h], 80h
EXTS #1,#2
MOV [R0],R2 ; [1554h], 0A8h
MOV [R1],R3 ; [2AA8h], 54h
MOV R2,#0 ; Block counter
; V R13 mame masku
ERASE_BLOCKS_LOOP:
MOV R0,[R11] ; Get segment, R0
ADD R11,#2
MOV R1,[R11] ; Get start address, R1
ADD R11,#4 ; Skip size
ROR R13,#1
JNB PSW.1,ERASE_BLOCKS_NEXT
; Add command for given block
MOV R4,#30h
EXTS R0,#1
MOV [R1],R4
ERASE_BLOCKS_NEXT:
CMPI1 R2,#5
JMPR CC_UGT,ERASE_BLOCKS_WAIT
JMP ERASE_BLOCKS_LOOP
ERASE_BLOCKS_WAIT:
NOP ; For BUG: Last command cycle
NOP
; Pockame na dokoncenie zmazania chipu a detekujeme chyby
; V R0 a R1 mame segment a adresu platnu pre posledny mazany blok
CALL OP_WAIT
MOV R15,R14
CALL SEND
ERASE_BLOCKS_ERROR:
POP CP
RET
ERASE_BLOCKS ENDP
;-------------------------------------------------------------------------------
; Read
;-------------------------------------------------------------------------------
READ PROC NEAR
SCXT CP,#REGBANK1
; Receive config information
CALL REC_CONFIG
CMP R14,#0
JMPR CC_NE,READ_ERROR
; Prijmeme pocet bajtov pre precitanie
CALL REC_DWORD_SAFE
CMP R14,#0
JMPR CC_NE,READ_ERROR
; Pocitadlo velkosti 1024 bajtoveho bloku
MOV R10,#1024
; Base of the control table
MOV R11,#DPP3:FLASH_MAPPING
; Read/Reset command
MOV R0,#0000h
MOV R1,#00F0h
EXTS #1,#1
MOV [R0],R1 ; zapiseme na lubovolnu adresu
READ_START:
MOV R0,[R11] ; Get segment, R0
ADD R11,#2
MOV R1,[R11] ; Get start address, R1
ADD R11,#2
MOV R2,[R11] ; Get data length to read, R2
ADD R11,#2
READ_LOOP:
; Read word
EXTS R0,#1
MOV R15,[R1]
CALL SEND
CALL CHECK_COUNT
CMP R14,#1
JMPR CC_EQ,READ_DONE
ADD R1,#2 ; Set address of the next word
SUB R2,#1 ; Decrement word counter
JMPR CC_NZ,READ_LOOP
JMP READ_START
READ_ERROR:
READ_DONE:
POP CP
RET
READ ENDP
;-------------------------------------------------------------------------------
; Write
;-------------------------------------------------------------------------------
WRITE PROC NEAR
SCXT CP,#REGBANK1
; Receive config information
CALL REC_CONFIG
CMP R14,#0
JMPR CC_NE,WRITE_ERROR
; Prijmeme pocet bajtov pre zapis
CALL REC_DWORD_SAFE
CMP R14,#0
JMPR CC_NE,WRITE_ERROR
; Pocitadlo velkosti 1024 bajtoveho bloku
MOV R10,#1024
; Base of the control table
MOV R11,#DPP3:FLASH_MAPPING
WRITE_START:
MOV R0,[R11] ; Get segment, R0
ADD R11,#2
MOV R1,[R11] ; Get start address, R1
ADD R11,#2
MOV R3,[R11] ; Get data length to write, R3
ADD R11,#2
WRITE_LOOP:
CALL REC
CMP R14,#0
JMPR CC_NE,WRITE_SEND_ERROR
; Write word in R15 to the FLASH
MOV R5,#1554h
MOV R6,#2AA8h
MOV R2,#0A8h
MOV R12,#54h
MOV R9,#0A0h
; Command cycles
EXTS #1,#3
MOV [R5],R2 ; [1554h], 0A8h
MOV [R6],R12 ; [2AA8h], 54h
MOV [R5],R9 ; [1554h], 0A0h
; 4. cyklus - zapiseme data na cielovu adresu
EXTS R0,#1
MOV [R1],R15
NOP ; For BUG: Last command cycle
NOP
; Pockame na dokoncenie zmazania chipu a detekujeme chyby
; V R0 a R1 mame segment a adresu platnu pre posledny mazany blok
; V R2 mame zapisovane slovo
MOV R2,R15
CALL OP_WAIT
CMP R14,#0
JMPR CC_NE,WRITE_SEND_ERROR
; End of Write word
CALL CHECK_COUNT
CMP R14,#1
JMPR CC_EQ,WRITE_DONE
ADD R1,#2
SUB R3,#1
JMPR CC_NZ,WRITE_LOOP
JMP WRITE_START
WRITE_SEND_ERROR:
MOV R15,R14
CALL SEND
WRITE_ERROR:
WRITE_DONE:
POP CP
RET
WRITE ENDP
;-------------------------------------------------------------------------------
; Helper subroutines
;-------------------------------------------------------------------------------
$INCLUDE (SUBROUTINES.INC)
;OP_WAIT_ERASE PROC NEAR
;; Vstup: R0 segment, R1 adresa
;; Vystup: R14 navratovy kod
;PUSH R0
;PUSH R1
;PUSH R2
;PUSH R3
;PUSH R4
;MOV R14,#0 ; Defaultny navratovy kod
;OP_WAIT_ERASE_LOOP:
;EXTS R0,#1
;MOV R3,[R1]
;MOV R4,R3 ; Make a copy for error bit checking
;; Is operation complete?
;EXTS R0,#1
;MOV R3,[R1]
;XOR R3,R4
;JNB R3.6,OP_WAIT_ERASE_RETURN
;; Has error occured?
;JB R4.5,OP_WAIT_ERASE_ERROR
;JMP OP_WAIT_ERASE_LOOP
;OP_WAIT_ERASE_ERROR:
;; Error, run Read/Reset command, this also resets the error bit .5
;MOV R14,#RET_ERASE_ERROR
;MOV R2,#0F0h
;EXTS R0,#1
;MOV [R1],R2
;OP_WAIT_ERASE_RETURN:
;POP R4
;POP R3
;POP R2
;POP R1
;POP R0
;RET
;OP_WAIT_ERASE ENDP
OP_WAIT PROC NEAR
; Vstup: R0 segment, R1 adresa, R2 bit 7 (hodnota, ktora znaci ukoncenie operacie)
; Vystup: R14 navratovy kod
PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R4
MOV R14,#0 ; Defaultny navratovy kod
OP_WAIT_LOOP:
EXTS R0,#1
MOV R3,[R1]
MOV R4,R3 ; Make a copy for error bit checking
; Is operation complete?
EXTS R0,#1
MOV R3,[R1]
XOR R3,R4
JNB R3.6,OP_WAIT_RETURN
; Has error occured?
JB R4.5,OP_WAIT_ERROR
JMP OP_WAIT_LOOP
OP_WAIT_ERROR:
; Error, run Read/Reset command, this also resets the error bit .5
MOV R14,#RET_WRITE_ERROR
MOV R2,#0F0h
EXTS R0,#1
MOV [R1],R2
OP_WAIT_RETURN:
POP R4
POP R3
POP R2
POP R1
POP R0
RET
OP_WAIT ENDP
;---------------
;OP_DP_WAIT PROC NEAR
;; Vstup: R0 segment, R1 adresa, R2 bit 7 (hodnota, ktora znaci ukoncenie operacie)
;; Vystup: R14 navratovy kod
;PUSH R0
;PUSH R1
;PUSH R2
;PUSH R3
;PUSH R4
;MOV R2,#0FFh
;MOV R14,#0 ; Defaultny navratovy kod
;OP_DP_WAIT_LOOP:
;EXTS R0,#1
;MOV R3,[R1]
;MOV R4,R3 ; Make a copy for error bit checking
;; Is operation complete?
;XOR R3,R2
;JNB R3.7,OP_DP_WAIT_RETURN
;; Has error occured?
;JB R4.5,OP_DP_WAIT_ERROR
;JMP OP_DP_WAIT_LOOP
;OP_DP_WAIT_ERROR:
;; Error, run Read/Reset command, this also resets the error bit .5
;MOV R14,#RET_WRITE_ERROR
;MOV R2,#0F0h
;EXTS R0,#1
;MOV [R1],R2
;OP_DP_WAIT_RETURN:
;POP R4
;POP R3
;POP R2
;POP R1
;POP R0
;RET
;OP_DP_WAIT ENDP
;-------------------------------------------------------------------------------
; End of helper subroutines
;-------------------------------------------------------------------------------
FW_ST10F269 ENDS
END
|