From 6706cc502e7b6d0ce2d6a9af96aca121a2aea317 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Wed, 19 Jul 2023 21:07:17 -0700 Subject: [PATCH] Update software to match efinix hw --- .vscode/settings.json | 5 ++++ sw/bootloader/Makefile | 4 +-- sw/bootloader/devices/board_io.h | 6 ---- sw/bootloader/devices/board_io.s | 47 ------------------------------- sw/bootloader/devices/conio.s | 12 ++++---- sw/bootloader/devices/interrupt.s | 10 ------- sw/bootloader/devices/io.inc65 | 16 ++++------- sw/bootloader/devices/mapper.h | 12 -------- sw/bootloader/devices/mapper.s | 32 --------------------- sw/bootloader/devices/sd_card.c | 30 ++++++++++++++------ sw/bootloader/devices/uart.s | 4 +-- sw/bootloader/irq.c | 13 --------- sw/bootloader/link.ld | 2 +- sw/bootloader/main.c | 28 ++++++------------ 14 files changed, 52 insertions(+), 169 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 sw/bootloader/devices/mapper.h delete mode 100644 sw/bootloader/devices/mapper.s diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cbf8a7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "conio.h": "c" + } +} \ No newline at end of file diff --git a/sw/bootloader/Makefile b/sw/bootloader/Makefile index 6f3db2c..ac2d520 100644 --- a/sw/bootloader/Makefile +++ b/sw/bootloader/Makefile @@ -15,7 +15,7 @@ LISTS=lists TESTS=tests SRCS=$(wildcard *.s) $(wildcard *.c) -SRCS+=$(filter-out $(wildcard tests/*), $(wildcard **/*.s)) $(filter-out $(wildcard tests/*), $(wildcard **/*.c)) +SRCS+=$(filter-out $(wildcard tests/*), $(wildcard **/*.s)) $(filter-out $(wildcard tests/*) $(wildcard filesystem/*), $(wildcard **/*.c)) OBJS+=$(patsubst %.s,%.o,$(filter %s,$(SRCS))) OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) @@ -33,7 +33,7 @@ $(TEST_BIN): $(OBJS) $(TEST_OBJS) $(CC) $(CFLAGS) $(TEST_OBJS) -o $@ $(HEX): $(BIN) - objcopy --input-target=binary --output-target=ihex $(BIN) $(HEX) + objcopy --input-target=binary --output-target=verilog $(BIN) $(HEX) $(BIN): $(OBJS) diff --git a/sw/bootloader/devices/board_io.h b/sw/bootloader/devices/board_io.h index c55c7a5..da8aa51 100644 --- a/sw/bootloader/devices/board_io.h +++ b/sw/bootloader/devices/board_io.h @@ -3,12 +3,6 @@ #include -uint8_t hex_set_8(uint8_t val, uint8_t idx); -uint8_t hex_set_16(uint16_t val); -uint8_t hex_set_24(uint32_t val); - -void hex_enable(uint8_t mask); - uint8_t sw_read(); void led_set(uint8_t val); diff --git a/sw/bootloader/devices/board_io.s b/sw/bootloader/devices/board_io.s index 95656fe..e8999e9 100644 --- a/sw/bootloader/devices/board_io.s +++ b/sw/bootloader/devices/board_io.s @@ -2,10 +2,6 @@ .importzp sp, sreg -.export _hex_set_8 -.export _hex_set_16 -.export _hex_set_24 -.export _hex_enable .export _sw_read .export _led_set @@ -13,49 +9,6 @@ .code -; @in A: idx Stack[0]: val -; @out A: 0 for success, 1 for failure. -; Sets one of the 3 pairs of hex digits. -_hex_set_8: - phx - cmp #$3 ; If idx >= 3 then fail - bcc @1 - plx - lda #$1 - rts -@1: tax ; Move idx into x - jsr popa ; put val into a - sta SEVEN_SEG,x ; write to val - lda #$0 - plx - rts - -; @in A/X: val -; @out A: 0 for success, 1 for failure -; Sets the low 2 pairs of hex digits -_hex_set_16: - sta SEVEN_SEG - stx SEVEN_SEG+1 - lda #$0 - rts - -; @in A/X/sreg: val -; @out A: 0 for success, 1 for failure -; Sets the 3 pairs of hex digits for a 24 bit value -_hex_set_24: - sta SEVEN_SEG - stx SEVEN_SEG+1 - lda sreg - sta SEVEN_SEG+2 - lda #$0 - rts - -; @in A: mask -; Set the mask for seven seg enables -_hex_enable: - sta SEVEN_SEG+3 - rts - ; @out A: The Value of the switches ; Reads the current values of the switches. _sw_read: diff --git a/sw/bootloader/devices/conio.s b/sw/bootloader/devices/conio.s index 30b4d6a..b7ebd46 100644 --- a/sw/bootloader/devices/conio.s +++ b/sw/bootloader/devices/conio.s @@ -6,7 +6,7 @@ .export _cputc .export gotoxy .export _clrscr -.export _cgetc +;.export _cgetc .autoimport on @@ -53,8 +53,8 @@ _clrscr: pla rts -_cgetc: -@2: lda _lastchar - beq @2 - stz _lastchar - rts \ No newline at end of file +;_cgetc: +;@2: lda _lastchar +; beq @2 +; stz _lastchar +; rts \ No newline at end of file diff --git a/sw/bootloader/devices/interrupt.s b/sw/bootloader/devices/interrupt.s index f87f81d..39e6b2a 100644 --- a/sw/bootloader/devices/interrupt.s +++ b/sw/bootloader/devices/interrupt.s @@ -9,7 +9,6 @@ .import _handle_irq .export _irq_int, _nmi_int -.export _irq_get_status, _irq_set_status .include "io.inc65" @@ -47,12 +46,3 @@ irq: PLA ; Restore accumulator contents break: JMP break ; If BRK is detected, something very bad ; has happened, so stop running - -_irq_get_status: - lda IRQ_STATUS - ldx #$00 - rts - -_irq_set_status: - sta IRQ_STATUS - rts \ No newline at end of file diff --git a/sw/bootloader/devices/io.inc65 b/sw/bootloader/devices/io.inc65 index bad732c..9e797f5 100644 --- a/sw/bootloader/devices/io.inc65 +++ b/sw/bootloader/devices/io.inc65 @@ -1,18 +1,12 @@ -SEVEN_SEG = $7ff0 - -UART = $7ff4 +UART = $efe6 UART_TXB = UART UART_RXB = UART UART_STATUS = UART + 1 -LED = $7ff6 +LED = $efff SW = LED -MM_CTRL = $7ff7 -MM_DATA = $7fe0 +SD_ARG = $efd8 +SD_CMD = $efdc +SD_DATA = $efdd -SD_ARG = $7ff8 -SD_CMD = $7ffc -SD_DATA = $7ffd - -IRQ_STATUS = $7fff diff --git a/sw/bootloader/devices/mapper.h b/sw/bootloader/devices/mapper.h deleted file mode 100644 index 8276b60..0000000 --- a/sw/bootloader/devices/mapper.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _MAPPER_H -#define _MAPPER_H - -#include - -void mapper_enable(uint8_t en); - -uint8_t mapper_read(uint8_t addr); -void mapper_write(uint8_t data, uint8_t addr); - -#endif - diff --git a/sw/bootloader/devices/mapper.s b/sw/bootloader/devices/mapper.s deleted file mode 100644 index 2ed1bc0..0000000 --- a/sw/bootloader/devices/mapper.s +++ /dev/null @@ -1,32 +0,0 @@ -.include "io.inc65" - -.importzp sp, sreg - -.export _mapper_enable -.export _mapper_read, _mapper_write - -.autoimport on - -.code - - -; void mapper_enable(uint8_t en) -_mapper_enable: - sta MM_CTRL - rts - -_mapper_read: - phx - tax - lda MM_DATA,x - ldx #$00 - rts - -_mapper_write: - phx - tax - jsr popa - sta MM_DATA,x - plx - rts - diff --git a/sw/bootloader/devices/sd_card.c b/sw/bootloader/devices/sd_card.c index 752cd0e..4e548ba 100644 --- a/sw/bootloader/devices/sd_card.c +++ b/sw/bootloader/devices/sd_card.c @@ -5,21 +5,35 @@ void sd_init() { uint32_t resp; + uint8_t attempts, i; + + cputs("In sd_init\n"); + sd_card_command(0, 0); + cprintf("Sent Reset\n"); + sd_card_command(0x000001aa, 8); sd_card_resp(&resp); cprintf("CMD8: %lx\n", resp); - sd_card_command(0, 55); - sd_card_command(0x40180000, 41); - sd_card_resp(&resp); - cprintf("CMD41: %lx\n", resp); + attempts = 0; + do { + if (attempts > 100) { + cprintf("SD Timed out"); + return; + } + sd_card_command(0, 55); + sd_card_resp(&resp); + sd_card_command(0x40180000, 41); + sd_card_resp(&resp); + cprintf("CMD41: %lx\n", resp); - sd_card_command(0, 55); - sd_card_command(0x40180000, 41); - sd_card_resp(&resp); - cprintf("CMD41: %lx\n", resp); + //10ms loop? + for (i = 0; i < 255; i++); + + attempts++; + } while (resp != 0); sd_card_command(0, 2); sd_card_resp(&resp); diff --git a/sw/bootloader/devices/uart.s b/sw/bootloader/devices/uart.s index c852f7e..c99e0ad 100644 --- a/sw/bootloader/devices/uart.s +++ b/sw/bootloader/devices/uart.s @@ -19,8 +19,8 @@ _uart_txb: _uart_txb_block: pha sta UART_TXB ; Write value -@1: lda UART_STATUS ; Wait for status[0] to be 0 - bit #$01 +@1: lda UART_STATUS ; Wait for status[1] to be 0 + bit #$02 bne @1 pla rts diff --git a/sw/bootloader/irq.c b/sw/bootloader/irq.c index 4d2c0d8..9911f8d 100644 --- a/sw/bootloader/irq.c +++ b/sw/bootloader/irq.c @@ -5,20 +5,7 @@ #include "devices/interrupt.h" #include "devices/uart.h" -char lastchar; void handle_irq() { - uint8_t status; - - status = irq_get_status(); - - if (status & BUTTON) { - cputs("Button Interrupt!\n"); - irq_set_status(status & ~BUTTON); - } - if (status & UART) { - lastchar = uart_rxb(); - irq_set_status(status & ~UART); - } } \ No newline at end of file diff --git a/sw/bootloader/link.ld b/sw/bootloader/link.ld index 46ee428..b1a51cf 100644 --- a/sw/bootloader/link.ld +++ b/sw/bootloader/link.ld @@ -2,7 +2,7 @@ MEMORY { ZP: start = $0, size = $100, type = rw, define = yes; SDRAM: start = $200, size = $7cf0, type = rw, define = yes; - ROM: start = $8000, size = $8000, file = %O; + ROM: start = $F000, size = $1000, file = %O; } SEGMENTS { diff --git a/sw/bootloader/main.c b/sw/bootloader/main.c index e6e8407..97290d3 100644 --- a/sw/bootloader/main.c +++ b/sw/bootloader/main.c @@ -5,7 +5,6 @@ #include "devices/board_io.h" #include "devices/uart.h" -#include "devices/mapper.h" #include "devices/sd_card.h" #include "filesystem/fat.h" @@ -14,34 +13,21 @@ uint8_t buf[512]; int main() { - int i; uint16_t rca; - char* filename; - uint32_t cluster; - uint8_t* kernel_load; - clrscr(); - cprintf("boot\n"); - - for (i = 0; i < 16; i++){ - //cprintf("Mapping %1xxxx to %2xxxx\n", i, i); - mapper_write(i, i); - } - - cprintf("Enabling Mapper\n"); - mapper_enable(1); - - mapper_write(0x10, 0xd); - mapper_write(0x11, 0xe); - mapper_write(0x12, 0xf); + cputs("Starting sd_init\n"); + cprintf("And testing cprintf\n"); sd_init(); + cprintf("finish sd_init\n"); + rca = sd_get_rca(); cprintf("rca: %x\n", rca); sd_select_card(rca); + /* fat_init(); filename = (char*)malloc(FAT_MAX_FILE_NAME); @@ -54,8 +40,12 @@ int main() { cluster = fat_get_chain_value(cluster); } + */ + cprintf("Done!\n"); + for(;;); + cprintf("Reset vector: %x\n", *((uint16_t*)0xfffc)); return 0;