Files
aqhomecontrol/avr/modules/xram/main.asm
2025-05-28 00:49:07 +02:00

107 lines
2.0 KiB
NASM

; ***************************************************************************
; copyright : (C) 2025 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. *
; ***************************************************************************
; ***************************************************************************
; defines
; ***************************************************************************
; data
.dseg
xramLastAddress: .byte 2
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine XRAM_Init @global
;
XRAM_Init:
clr r16
sts xramLastAddress, r16
sts xramLastAddress+1, r16
inr r16, MCUCR
sbr r16, (1<<SRE)
outr MCUCR, r16
rcall xramWritePattern
rcall xramVerifyPattern
ret
; @end
; ---------------------------------------------------------------------------
; @routine XRAM_Fini @global
;
XRAM_Fini:
ret
; @end
; ---------------------------------------------------------------------------
; @routine xramWritePattern
;
; Write a pattern to memory (high byte of address)
xramWritePattern:
ldi xl, LOW(RAMEND+1)
ldi xh, LOW(RAMEND+1)
xramWritePattern_loop:
mov r16, xh
st X, r16
adiw xh:xl, 1
brne xramWritePattern_loop
ret
; @end
; ---------------------------------------------------------------------------
; @routine xramVerifyPattern
;
; Write a pattern to memory (high byte of address)
xramVerifyPattern:
ldi xl, LOW(RAMEND+1)
ldi xh, LOW(RAMEND+1)
xramVerifyPattern_loop:
mov r16, xh
ld r17, X
cp r16, r17
brne xramVerifyPattern_end
adiw xh:xl, 1
brne xramVerifyPattern_loop
xramVerifyPattern_end:
sbiw xh:xl, 1
sts xramLastAddress, xl
sts xramLastAddress+1, xh
ret
; @end