Files
aqhomecontrol/avr/modules/xram/main.asm
Martin Preuss 75b602811c added XRAM module.
Module for external SRAM with AtMega8515.
2025-05-17 14:22:49 +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
M_IO_READ r16, MCUCR
sbr r16, (1<<SRE)
M_IO_WRITE 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