avr: reduced code (bootloader now 569 words).

This commit is contained in:
Martin Preuss
2024-09-01 22:29:08 +02:00
parent 8aeb488e2e
commit c2a6d33ff2
8 changed files with 55 additions and 40 deletions

View File

@@ -163,7 +163,7 @@ com2WaitForDataState1ms_loop:
eor r22, r16
andi r22, (1<<COM_PINNUM_DATA)
breq com2WaitForDataState1ms_stateReached
rcall com2WaitFor10MicroSecs ; wait for 10us (R22)
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
dec r17
brne com2WaitForDataState1ms_loop
rjmp com2LowLevelClcRet
@@ -189,7 +189,7 @@ com2WaitForAttnState1ms_loop:
eor r22, r16
andi r22, (1<<COM_PINNUM_ATTN)
breq com2WaitForAttnState1ms_stateReached
rcall com2WaitFor10MicroSecs ; wait for 10us (R22)
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
dec r17
brne com2WaitForAttnState1ms_loop
rjmp com2LowLevelClcRet
@@ -198,20 +198,6 @@ com2WaitForAttnState1ms_stateReached:
; ---------------------------------------------------------------------------
; wait for 10 microsecs (minus cycles for call and ret).
;
; IN:
; - nothing
; OUT:
; - nothing
; REGS: r22
com2WaitFor10MicroSecs:
Utils_WaitNanoSecs 10000, 7, r22 ; wait for 10us (minus RCALL and RET)
ret
com2LowLevelClcRet:
clc
ret

View File

@@ -79,10 +79,8 @@ bootLoader:
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN port as input
sbi DDRA, PORTA3 ; out
cbi PORTA, PORTA3 ; on
cbi DDRA, PORTA2 ; in (debug led)
sbi PORTA, PORTA2 ; pullup on (debug led)
sbi LED_DDR, LED_PINNUM ; out
cbi LED_PORT, LED_PINNUM ; on
rcall flashReadUid
sts flashUid, r18
@@ -101,20 +99,20 @@ bootLoader:
; try to start firmware
bootLoader_startFirmware:
cbi PORTA, PORTA3 ; LED on
cbi LED_PORT, LED_PINNUM ; on
ldi r16, 10
rcall flashWaitForMulti100ms
sbi PORTA, PORTA3 ; LED off
sbi LED_PORT, LED_PINNUM ; off
ldi r16, 3
rcall flashWaitForMulti100ms
cbi PORTA, PORTA3 ; LED on
cbi LED_PORT, LED_PINNUM ; on
ldi r16, 10
rcall flashWaitForMulti100ms
sbi PORTA, PORTA3 ; LED off
sbi LED_PORT, LED_PINNUM ; off
rjmp firmwareStart
bootLoader_waitAndRestartBootLoader:
sbi PORTA, PORTA3 ; LED off
sbi LED_PORT, LED_PINNUM ; off
ldi r16, 20
rcall flashWaitForMulti100ms
rjmp bootLoader

View File

@@ -31,10 +31,10 @@
flashWaitForSpecificMessageWithLed:
mov r2, r16
sbi PORTA, PORTA3 ; LED off
sbi LED_PORT, LED_PINNUM ; off
flashWaitForSpecificMessageWithLed_loop:
sbi PINA, PORTA3 ; toggle LED
sbi LED_PIN, LED_PINNUM ; toggle
mov r16, r2
push r17
ldi r17, 100 ; wait up to 100ms
@@ -43,12 +43,11 @@ flashWaitForSpecificMessageWithLed_loop:
brcs flashWaitForSpecificMessageWithLed_received
dec r17
brne flashWaitForSpecificMessageWithLed_loop
sbi PORTA, PORTA3 ; off
sbi LED_PORT, LED_PINNUM ; off
rjmp flash_recv_clc_ret ; timeout
flashWaitForSpecificMessageWithLed_received:
sbi PORTA, PORTA3 ; off
sec
ret
sbi LED_PORT, LED_PINNUM ; off
rjmp flash_recv_sec_ret
@@ -109,8 +108,7 @@ flashWaitForSpecificMessage_loop2:
flashWaitForSpecificMessage_isHigh:
rjmp flashWaitForSpecificMessage_loop0
flashWaitForSpecificMessage_received: ; R16 contains message type
sec
ret
rjmp flash_recv_sec_ret
@@ -132,19 +130,20 @@ flashWaitForAttnState1ms_loop:
andi r17, (1<<COM_PINNUM_ATTN)
pop r17
breq flashWaitForAttnState1ms_stateReached
Utils_WaitNanoSecs 10000, 0, r22 ; wait for 10us
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
dec r24
brne flashWaitForAttnState1ms_loop
rjmp flash_recv_clc_ret
flashWaitForAttnState1ms_stateReached:
sec
ret
rjmp flash_recv_sec_ret
flash_recv_clc_ret:
clc
flash_recv_ret:
ret
flash_recv_sec_ret:
sec
ret

View File

@@ -89,9 +89,9 @@ flashWaitFor100ms_loop:
; REGS: R24 (R22)
flashWaitFor1ms:
ldi r24, 10
ldi r24, 100
flashWaitFor1ms_loop:
Utils_WaitNanoSecs 100000, 0, r22 ; wait for 100us
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
dec r24
brne flashWaitFor1ms_loop
ret