avr: reduced code (bootloader now 569 words).
This commit is contained in:
@@ -77,6 +77,11 @@
|
||||
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
||||
|
||||
|
||||
.equ LED_DDR = DDRA
|
||||
.equ LED_PORT = PORTA
|
||||
.equ LED_PIN = PINA
|
||||
.equ LED_PINNUM = PORTA3
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code segment
|
||||
@@ -135,6 +140,7 @@ main:
|
||||
.include "modules/com2/crc.asm"
|
||||
.include "modules/com2/packets.asm"
|
||||
.include "common/crc8.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "modules/flash/bootloader.asm"
|
||||
.include "modules/flash/flash.asm"
|
||||
.include "modules/flash/recv.asm"
|
||||
|
||||
@@ -258,6 +258,7 @@ firmwareStart: rjmp main
|
||||
; includes
|
||||
|
||||
.include "common/utils.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "common/crc8.asm"
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
shared.asm
|
||||
utils.asm
|
||||
utils_wait.asm
|
||||
utils_wait_fixed.asm
|
||||
watchdog.asm
|
||||
</extradist>
|
||||
|
||||
|
||||
24
avr/common/utils_wait_fixed.asm
Normal file
24
avr/common/utils_wait_fixed.asm
Normal file
@@ -0,0 +1,24 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2023 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; wait for 10 microsecs (minus cycles for call and ret).
|
||||
;
|
||||
; IN:
|
||||
; - nothing
|
||||
; OUT:
|
||||
; - nothing
|
||||
; REGS: r22
|
||||
|
||||
Utils_WaitFor10MicroSecs:
|
||||
Utils_WaitNanoSecs 10000, 7, r22 ; wait for 10us (minus RCALL and RET)
|
||||
ret
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user