diff options
Diffstat (limited to 'firmware/st10f269/st10f269.a66')
| -rwxr-xr-x | firmware/st10f269/st10f269.a66 | 422 |
1 files changed, 422 insertions, 0 deletions
diff --git a/firmware/st10f269/st10f269.a66 b/firmware/st10f269/st10f269.a66 new file mode 100755 index 0000000..6bd03d7 --- /dev/null +++ b/firmware/st10f269/st10f269.a66 @@ -0,0 +1,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
\ No newline at end of file |
