; ------------------------------------------------- ; Register definitions ; ------------------------------------------------- include "../../../lib/jasm/cregs.inc.jsm" include "xregs.inc.jsm" ; ------------------------------------------------- ; Constants ; ------------------------------------------------- addr_incr: equ 2 addr_msb_max: equ 0xFF ; External RAM/ROM xmem 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 "Verify Failed", 0 dot: dc ".", 0 org 0x80 sdram_data: db 8 ; SDRAM data window at X:0x80 ; Internal RAM cmem 0 round: db 1 ; ------------------------------------------------- ; Program ; ------------------------------------------------- code reset: org 0x000 jmp main ; ------------------------------------------------- ; ISR ; ------------------------------------------------- org 0x001 reti ; ------------------------------------------------- ; Main ; ------------------------------------------------- main: call LCD_init mov R0, 0x00 xout (led_port), R0 ; Clear LCD mov R0, LCD_CMD_CLEAR call LCD_writecmd ; Wait until SDRAM ready poll_bsy_fin: xin R0, (sdram_reg) xout (led_port), R0 and R0, SDRAM_STAT_BUSY jnz poll_bsy_fin ; Print greeting message mov R1, greet_txt call LCD_putsx 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 jmp do_clear ; ---------------------------------------------------------- ; SDRAM clear ; ---------------------------------------------------------- do_clear: ; Clear LCD mov R0, LCD_CMD_CLEAR call LCD_writecmd ; Print Clear message mov R1, msg_txt0 call LCD_putsx ; 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 ; Wait finished last write poll_clear_fin: xin R0, (sdram_reg) xout (led_port), R0 and R0, SDRAM_STAT_WRITE_BUSY jnz poll_clear_fin ; Start SDR write mov R0, sdram_reg xout (R0), SDRAM_CTRL_WRITE_REQUEST ; Advance address counter mov R0, addr_incr call AddrCnt_Adv jmp sdr_clear clear_finished: call AddrCnt_Disp call delay1s ; ---------------------------------------------------------- ; SDRAM Write ; ---------------------------------------------------------- do_write: ; Clear LCD mov R0, LCD_CMD_CLEAR call LCD_writecmd ; Print Write message mov R1, msg_txt1 call LCD_putsx ; 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 ; Fill SDR Buffer 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 ; Wait finished last write poll_write_fin: xin R0, (sdram_reg) xout (led_port), R0 and R0, SDRAM_STAT_WRITE_BUSY jnz poll_write_fin ; Start SDR write mov R0, sdram_reg xout (R0), SDRAM_CTRL_WRITE_REQUEST ; Advance address counter mov R0, addr_incr call AddrCnt_Adv movc R0, (round) inc R0 movc (round), R0 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 ; 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 mov R0, sdram_reg xout (R0), SDRAM_CTRL_READ_REQUEST ; Wait last read poll_read_fin: xin R0, (sdram_reg) xout (led_port), R0 and R0, SDRAM_STAT_READ_BUSY jnz poll_read_fin read_back_mem: ; 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 address counter mov R0, addr_incr call AddrCnt_Adv movc R0, (round) inc R0 movc (round), R0 jmp sdr_read ; ---------------------------------------------------------- read_finished: no_error: mov R0, LCD_CMD_Z2 call LCD_writecmd mov R1, verify_ok call LCD_putsx jmp ende verify_error: mov R0, LCD_CMD_Z2 call LCD_writecmd mov R1, verify_nok call LCD_putsx 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 xin R0, (sdram_addr+2) call PutHexByte xin R0, (sdram_addr+1) call PutHexByte xin R0, (sdram_addr+0) call PutHexByte ret ; ------------------------------------------------- ; PutHexByte ; R0 : Byte value PutHexByte: call bin2hex call LCD_writechar mov R0, R1 call LCD_writechar ret ; ------------------------------------------------- include "../../../lib/jasm/utils.inc.jsm" include "../../../lib/jasm/lcd.inc.jsm" include "../../../lib/jasm/delays.inc.jsm"