avr: reduced code (bootloader now 569 words).
This commit is contained in:
@@ -77,6 +77,11 @@
|
|||||||
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
||||||
|
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRA
|
||||||
|
.equ LED_PORT = PORTA
|
||||||
|
.equ LED_PIN = PINA
|
||||||
|
.equ LED_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
; code segment
|
; code segment
|
||||||
@@ -135,6 +140,7 @@ main:
|
|||||||
.include "modules/com2/crc.asm"
|
.include "modules/com2/crc.asm"
|
||||||
.include "modules/com2/packets.asm"
|
.include "modules/com2/packets.asm"
|
||||||
.include "common/crc8.asm"
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
.include "modules/flash/bootloader.asm"
|
.include "modules/flash/bootloader.asm"
|
||||||
.include "modules/flash/flash.asm"
|
.include "modules/flash/flash.asm"
|
||||||
.include "modules/flash/recv.asm"
|
.include "modules/flash/recv.asm"
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ firmwareStart: rjmp main
|
|||||||
; includes
|
; includes
|
||||||
|
|
||||||
.include "common/utils.asm"
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
.include "common/crc8.asm"
|
.include "common/crc8.asm"
|
||||||
|
|
||||||
#ifdef MODULES_TIMER
|
#ifdef MODULES_TIMER
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
shared.asm
|
shared.asm
|
||||||
utils.asm
|
utils.asm
|
||||||
utils_wait.asm
|
utils_wait.asm
|
||||||
|
utils_wait_fixed.asm
|
||||||
watchdog.asm
|
watchdog.asm
|
||||||
</extradist>
|
</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
|
eor r22, r16
|
||||||
andi r22, (1<<COM_PINNUM_DATA)
|
andi r22, (1<<COM_PINNUM_DATA)
|
||||||
breq com2WaitForDataState1ms_stateReached
|
breq com2WaitForDataState1ms_stateReached
|
||||||
rcall com2WaitFor10MicroSecs ; wait for 10us (R22)
|
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
|
||||||
dec r17
|
dec r17
|
||||||
brne com2WaitForDataState1ms_loop
|
brne com2WaitForDataState1ms_loop
|
||||||
rjmp com2LowLevelClcRet
|
rjmp com2LowLevelClcRet
|
||||||
@@ -189,7 +189,7 @@ com2WaitForAttnState1ms_loop:
|
|||||||
eor r22, r16
|
eor r22, r16
|
||||||
andi r22, (1<<COM_PINNUM_ATTN)
|
andi r22, (1<<COM_PINNUM_ATTN)
|
||||||
breq com2WaitForAttnState1ms_stateReached
|
breq com2WaitForAttnState1ms_stateReached
|
||||||
rcall com2WaitFor10MicroSecs ; wait for 10us (R22)
|
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
|
||||||
dec r17
|
dec r17
|
||||||
brne com2WaitForAttnState1ms_loop
|
brne com2WaitForAttnState1ms_loop
|
||||||
rjmp com2LowLevelClcRet
|
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:
|
com2LowLevelClcRet:
|
||||||
clc
|
clc
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -79,10 +79,8 @@ bootLoader:
|
|||||||
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN port as input
|
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN port as input
|
||||||
|
|
||||||
|
|
||||||
sbi DDRA, PORTA3 ; out
|
sbi LED_DDR, LED_PINNUM ; out
|
||||||
cbi PORTA, PORTA3 ; on
|
cbi LED_PORT, LED_PINNUM ; on
|
||||||
cbi DDRA, PORTA2 ; in (debug led)
|
|
||||||
sbi PORTA, PORTA2 ; pullup on (debug led)
|
|
||||||
|
|
||||||
rcall flashReadUid
|
rcall flashReadUid
|
||||||
sts flashUid, r18
|
sts flashUid, r18
|
||||||
@@ -101,20 +99,20 @@ bootLoader:
|
|||||||
|
|
||||||
; try to start firmware
|
; try to start firmware
|
||||||
bootLoader_startFirmware:
|
bootLoader_startFirmware:
|
||||||
cbi PORTA, PORTA3 ; LED on
|
cbi LED_PORT, LED_PINNUM ; on
|
||||||
ldi r16, 10
|
ldi r16, 10
|
||||||
rcall flashWaitForMulti100ms
|
rcall flashWaitForMulti100ms
|
||||||
sbi PORTA, PORTA3 ; LED off
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
ldi r16, 3
|
ldi r16, 3
|
||||||
rcall flashWaitForMulti100ms
|
rcall flashWaitForMulti100ms
|
||||||
cbi PORTA, PORTA3 ; LED on
|
cbi LED_PORT, LED_PINNUM ; on
|
||||||
ldi r16, 10
|
ldi r16, 10
|
||||||
rcall flashWaitForMulti100ms
|
rcall flashWaitForMulti100ms
|
||||||
sbi PORTA, PORTA3 ; LED off
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
rjmp firmwareStart
|
rjmp firmwareStart
|
||||||
|
|
||||||
bootLoader_waitAndRestartBootLoader:
|
bootLoader_waitAndRestartBootLoader:
|
||||||
sbi PORTA, PORTA3 ; LED off
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
ldi r16, 20
|
ldi r16, 20
|
||||||
rcall flashWaitForMulti100ms
|
rcall flashWaitForMulti100ms
|
||||||
rjmp bootLoader
|
rjmp bootLoader
|
||||||
|
|||||||
@@ -31,10 +31,10 @@
|
|||||||
|
|
||||||
flashWaitForSpecificMessageWithLed:
|
flashWaitForSpecificMessageWithLed:
|
||||||
mov r2, r16
|
mov r2, r16
|
||||||
sbi PORTA, PORTA3 ; LED off
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
|
|
||||||
flashWaitForSpecificMessageWithLed_loop:
|
flashWaitForSpecificMessageWithLed_loop:
|
||||||
sbi PINA, PORTA3 ; toggle LED
|
sbi LED_PIN, LED_PINNUM ; toggle
|
||||||
mov r16, r2
|
mov r16, r2
|
||||||
push r17
|
push r17
|
||||||
ldi r17, 100 ; wait up to 100ms
|
ldi r17, 100 ; wait up to 100ms
|
||||||
@@ -43,12 +43,11 @@ flashWaitForSpecificMessageWithLed_loop:
|
|||||||
brcs flashWaitForSpecificMessageWithLed_received
|
brcs flashWaitForSpecificMessageWithLed_received
|
||||||
dec r17
|
dec r17
|
||||||
brne flashWaitForSpecificMessageWithLed_loop
|
brne flashWaitForSpecificMessageWithLed_loop
|
||||||
sbi PORTA, PORTA3 ; off
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
rjmp flash_recv_clc_ret ; timeout
|
rjmp flash_recv_clc_ret ; timeout
|
||||||
flashWaitForSpecificMessageWithLed_received:
|
flashWaitForSpecificMessageWithLed_received:
|
||||||
sbi PORTA, PORTA3 ; off
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
sec
|
rjmp flash_recv_sec_ret
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -109,8 +108,7 @@ flashWaitForSpecificMessage_loop2:
|
|||||||
flashWaitForSpecificMessage_isHigh:
|
flashWaitForSpecificMessage_isHigh:
|
||||||
rjmp flashWaitForSpecificMessage_loop0
|
rjmp flashWaitForSpecificMessage_loop0
|
||||||
flashWaitForSpecificMessage_received: ; R16 contains message type
|
flashWaitForSpecificMessage_received: ; R16 contains message type
|
||||||
sec
|
rjmp flash_recv_sec_ret
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -132,19 +130,20 @@ flashWaitForAttnState1ms_loop:
|
|||||||
andi r17, (1<<COM_PINNUM_ATTN)
|
andi r17, (1<<COM_PINNUM_ATTN)
|
||||||
pop r17
|
pop r17
|
||||||
breq flashWaitForAttnState1ms_stateReached
|
breq flashWaitForAttnState1ms_stateReached
|
||||||
|
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
|
||||||
Utils_WaitNanoSecs 10000, 0, r22 ; wait for 10us
|
|
||||||
dec r24
|
dec r24
|
||||||
brne flashWaitForAttnState1ms_loop
|
brne flashWaitForAttnState1ms_loop
|
||||||
rjmp flash_recv_clc_ret
|
rjmp flash_recv_clc_ret
|
||||||
flashWaitForAttnState1ms_stateReached:
|
flashWaitForAttnState1ms_stateReached:
|
||||||
sec
|
rjmp flash_recv_sec_ret
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
flash_recv_clc_ret:
|
flash_recv_clc_ret:
|
||||||
clc
|
clc
|
||||||
flash_recv_ret:
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
flash_recv_sec_ret:
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ flashWaitFor100ms_loop:
|
|||||||
; REGS: R24 (R22)
|
; REGS: R24 (R22)
|
||||||
|
|
||||||
flashWaitFor1ms:
|
flashWaitFor1ms:
|
||||||
ldi r24, 10
|
ldi r24, 100
|
||||||
flashWaitFor1ms_loop:
|
flashWaitFor1ms_loop:
|
||||||
Utils_WaitNanoSecs 100000, 0, r22 ; wait for 100us
|
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
|
||||||
dec r24
|
dec r24
|
||||||
brne flashWaitFor1ms_loop
|
brne flashWaitFor1ms_loop
|
||||||
ret
|
ret
|
||||||
|
|||||||
Reference in New Issue
Block a user