git-svn-id: http://moon:8086/svn/vhdl/trunk@1414 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2021-03-21 10:47:01 +00:00
parent 32440f7db9
commit ea60299d26
80 changed files with 37322 additions and 0 deletions
+472
View File
@@ -0,0 +1,472 @@
; -------------------------------------------------
; Register definitions
; -------------------------------------------------
include "../../../lib/jasm/cregs.inc.jsm"
include "xregs.inc.jsm"
; -------------------------------------------------
; Constants
; -------------------------------------------------
BURST_LEN: equ 8
SD_CMD_WRITE: equ 0x06
SD_CMD_READ: equ 0x05
addr_msb_max: equ 0xFF
; External RAM/ROM
xmem
crlf: dc 13, 10, 0
greet_txt: dc "SDRAM Test", 0
msg_txt0: dc "Clearing SDRAM", 0
msg_txt1: dc "Writing SDRAM", 0
msg_txt2: dc "Reading SDRAM", 0
verify_ok: dc "Verify OK", 0
verify_nok: dc "Failed at ", 0
dot: dc ".", 0
org 0x80
sdram_data: db 8 ; SDRAM data window at X:0x80
; Internal RAM
cmem 0
round: db 1
bmp_offset: db 4
; -------------------------------------------------
; Program
; -------------------------------------------------
code
reset: org 0x000
jmp main
; -------------------------------------------------
; ISR
; -------------------------------------------------
org 0x001
push R0
xin R0, (ctrl_reg)
or R0, 0x10
xout (ctrl_reg), R0
pop R0
reti
; -------------------------------------------------
; Main
; -------------------------------------------------
main:
call LCD_init
mov R0, 0x00
xout (led_port), R0
mov R0, CTRL_VGA_ENABLE
xout (ctrl_reg), R0
cin R0, (cpu_int_ctrl)
or R0, 0x05
cout (cpu_int_ctrl), R0
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
mov R0, 0
mov R1, 0xC0
xout (reg_color_red), R1
xout (reg_color_grn), R1
xout (reg_color_blu), R1
call cg_wait_rdy
call cg_clr_screen
; Print greeting message
mov R1, greet_txt
call LCD_putsx
mov R1, greet_txt
call cg_puts
mov R1, crlf
call cg_puts_clr
xin R0, (ctrl_reg)
or R0, 0x10
xout (ctrl_reg), R0
call delay100ms
or R0, 0x20
xout (ctrl_reg), R0
call delay100ms
and R0, 0xEF
xout (ctrl_reg), R0
call delay100ms
and R0, 0xCF
xout (ctrl_reg), R0
; ----------------------------------------------------------
; SDRAM clear
; ----------------------------------------------------------
do_clear:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Clear message
mov R1, msg_txt0
call LCD_putsx
mov R1, msg_txt0
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
call AddrCnt_Init
; Fill SDR Buffer with zeros
mov R0, sdram_data
mov R15, 8
buf_clr_loop: movx (R0), 0
inc R0
dec R15
jnz buf_clr_loop
sdr_clear: xin R0, (sdram_addr+2)
cmp R0, addr_msb_max
jeq clear_finished
mov R2, BURST_LEN
poll_clear_full:
xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_WRITE_DATA_FULL
jnz poll_clear_full
; Fill FIFO
mov R0, FIFO_CTRL_IS_WRITE
xout (sdram_reg), R0
sub R2, 2
jnz poll_clear_full
; Start SDR write
call wait_cmd_rdy
mov R0, SD_CMD_WRITE
xout (sdram_reg), R0
; Advance address counter
mov R0, BURST_LEN
call AddrCnt_Adv
jmp sdr_clear
clear_finished:
call AddrCnt_Disp
call delay1s
jmp do_write
; ----------------------------------------------------------
; SDRAM Write
; ----------------------------------------------------------
do_write:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Write message
mov R1, msg_txt1
call LCD_putsx
mov R1, msg_txt1
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
call AddrCnt_Init
mov R0, 0
movc (round), R0
sdr_write: xin R0, (sdram_addr+2)
cmp R0, addr_msb_max
jeq write_finished
mov R2, BURST_LEN
; Fill SDR Buffer
sdr_burst_wr: movc R1, (round)
; xin R0, (sdram_addr+2)
; cmp R0, 0x7F
; jne force_no_err
; inc R1
force_no_err: mov R0, sdram_data
mov R15, 8
write_loop: movx (R0), R1
inc R0
inc R1
dec R15
jnz write_loop
poll_write_full:
xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_WRITE_DATA_FULL
jnz poll_write_full
; Fill FIFO
mov R0, FIFO_CTRL_IS_WRITE
xout (sdram_reg), R0
movc R0, (round)
inc R0
movc (round), R0
sub R2, 2
jnz sdr_burst_wr
; Start SDR write
call wait_cmd_rdy
mov R0, SD_CMD_WRITE
xout (sdram_reg), R0
; Advance address counter
mov R0, BURST_LEN
call AddrCnt_Adv
jmp sdr_write
write_finished: call AddrCnt_Disp
call delay1s
; ----------------------------------------------------------
; SDRAM Verify
; ----------------------------------------------------------
do_read:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Read message
mov R1, msg_txt2
call LCD_putsx
mov R1, msg_txt2
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
call AddrCnt_Init
mov R0, 0
movc (round), R0
sdr_read: xin R0, (sdram_addr+2)
cmp R0, addr_msb_max
jeq read_finished
; Start SDR read
call wait_cmd_rdy
mov R0, SD_CMD_READ
xout (sdram_reg), R0
; mov R0, LCD_CMD_Z1
; call LCD_writecmd
; call print_addr
; mov R0, LCD_CMD_Z2
; call LCD_writecmd
; call print_data
mov R3, BURST_LEN
; Wait last read
poll_read_fin: xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_READ_DATA_EMPTY
jnz poll_read_fin
; Verify SDR Buffer
movc R1, (round)
mov R0, sdram_data
mov R15, 8
read_loop: movx R2, (R0)
cmp R2, R1
jne verify_error
inc R0
inc R1
dec R15
jnz read_loop
; Advance Read-FIFO
mov R0, FIFO_CTRL_IS_READ
xout (sdram_reg), R0
movc R0, (round)
inc R0
movc (round), R0
sub R3, 2
jnz poll_read_fin
; Advance address counter
mov R0, BURST_LEN
call AddrCnt_Adv
jmp sdr_read
; ----------------------------------------------------------
sd_request: push R0
mov R0, SDRAM_CTRL_REQUEST
xout (sdram_reg), R0
wait4grant: xin R0, (sdram_reg)
xout (led_port), R0
and R0, SDRAM_STAT_ACCESS
jz wait4grant
pop R0
ret
; ----------------------------------------------------------
wait_cmd_rdy: call sd_request
push R0
wait4cmd: xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_CMD_FULL
jnz wait4cmd
pop R0
ret
; ----------------------------------------------------------
read_finished:
no_error: mov R0, LCD_CMD_CLEAR
call LCD_writecmd
mov R1, verify_ok
call LCD_putsx
mov R0, LCD_CMD_Z2
call LCD_writecmd
call print_addr
mov R1, verify_ok
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
jmp ende
verify_error: mov R0, LCD_CMD_CLEAR
call LCD_writecmd
mov R1, verify_nok
call LCD_putsx
call print_addr
call print_data
mov R1, verify_nok
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
jmp ende
ende: call delay1s
jmp do_clear
; -------------------------------------------------
AddrCnt_Init: push R0
mov R0, 0x00
xout (sdram_addr+0), R0
xout (sdram_addr+1), R0
xout (sdram_addr+2), R0
pop R0
ret
; -------------------------------------------------
; Parameter
; R0: increment value
AddrCnt_Adv: push R1
push R2
push R3
xin R1, (sdram_addr+0)
xin R2, (sdram_addr+1)
xin R3, (sdram_addr+2)
add R1, R0
addc R2, 0
addc R3, 0
xout (sdram_addr+0), R1
xout (sdram_addr+1), R2
xout (sdram_addr+2), R3
pop R3
pop R2
pop R1
ret
; -------------------------------------------------
; Display Address counter
AddrCnt_Disp: mov R0, LCD_CMD_Z2
call LCD_writecmd
call print_addr
ret
; -------------------------------------------------
; PutHexByte
; R0 : Byte value
PutHexByte: push R1
call bin2hex
call LCD_writechar
mov R0, R1
call LCD_writechar
pop R1
ret
; -------------------------------------------------
print_addr: push R0
xin R0, (sdram_addr+2)
call PutHexByte
xin R0, (sdram_addr+1)
call PutHexByte
xin R0, (sdram_addr+0)
call PutHexByte
pop R0
ret
; -------------------------------------------------
; R1 : ptr to byte array
print_dword: push R0
add R1, 3
movc R0, (R1)
call PutHexByte
dec R1
movc R0, (R1)
call PutHexByte
dec R1
movc R0, (R1)
call PutHexByte
dec R1
movc R0, (R1)
call PutHexByte
pop R0
ret
; -------------------------------------------------
print_data: push R0
mov R0, LCD_CMD_Z2
call LCD_writecmd
movx R0, (sdram_data+7)
call PutHexByte
movx R0, (sdram_data+6)
call PutHexByte
movx R0, (sdram_data+5)
call PutHexByte
movx R0, (sdram_data+4)
call PutHexByte
movx R0, (sdram_data+3)
call PutHexByte
movx R0, (sdram_data+2)
call PutHexByte
movx R0, (sdram_data+1)
call PutHexByte
movx R0, (sdram_data+0)
call PutHexByte
pop R0
ret
; -------------------------------------------------
include "../../../lib/jasm/utils.inc.jsm"
include "../../../lib/jasm/lcd.inc.jsm"
include "../../../lib/jasm/cg.inc.jsm"
include "../../../lib/jasm/delays.inc.jsm"
include "../../../lib/jasm/uart.inc.jsm"