Update software to match efinix hw

This commit is contained in:
Byron Lathi
2023-07-19 21:07:17 -07:00
parent 6eeecda368
commit 6706cc502e
14 changed files with 52 additions and 169 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"files.associations": {
"conio.h": "c"
}
}

View File

@@ -15,7 +15,7 @@ LISTS=lists
TESTS=tests TESTS=tests
SRCS=$(wildcard *.s) $(wildcard *.c) 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 %.s,%.o,$(filter %s,$(SRCS)))
OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS))) OBJS+=$(patsubst %.c,%.o,$(filter %c,$(SRCS)))
@@ -33,7 +33,7 @@ $(TEST_BIN): $(OBJS) $(TEST_OBJS)
$(CC) $(CFLAGS) $(TEST_OBJS) -o $@ $(CC) $(CFLAGS) $(TEST_OBJS) -o $@
$(HEX): $(BIN) $(HEX): $(BIN)
objcopy --input-target=binary --output-target=ihex $(BIN) $(HEX) objcopy --input-target=binary --output-target=verilog $(BIN) $(HEX)
$(BIN): $(OBJS) $(BIN): $(OBJS)

View File

@@ -3,12 +3,6 @@
#include <stdint.h> #include <stdint.h>
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(); uint8_t sw_read();
void led_set(uint8_t val); void led_set(uint8_t val);

View File

@@ -2,10 +2,6 @@
.importzp sp, sreg .importzp sp, sreg
.export _hex_set_8
.export _hex_set_16
.export _hex_set_24
.export _hex_enable
.export _sw_read .export _sw_read
.export _led_set .export _led_set
@@ -13,49 +9,6 @@
.code .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 ; @out A: The Value of the switches
; Reads the current values of the switches. ; Reads the current values of the switches.
_sw_read: _sw_read:

View File

@@ -6,7 +6,7 @@
.export _cputc .export _cputc
.export gotoxy .export gotoxy
.export _clrscr .export _clrscr
.export _cgetc ;.export _cgetc
.autoimport on .autoimport on
@@ -53,8 +53,8 @@ _clrscr:
pla pla
rts rts
_cgetc: ;_cgetc:
@2: lda _lastchar ;@2: lda _lastchar
beq @2 ; beq @2
stz _lastchar ; stz _lastchar
rts ; rts

View File

@@ -9,7 +9,6 @@
.import _handle_irq .import _handle_irq
.export _irq_int, _nmi_int .export _irq_int, _nmi_int
.export _irq_get_status, _irq_set_status
.include "io.inc65" .include "io.inc65"
@@ -47,12 +46,3 @@ irq: PLA ; Restore accumulator contents
break: JMP break ; If BRK is detected, something very bad break: JMP break ; If BRK is detected, something very bad
; has happened, so stop running ; has happened, so stop running
_irq_get_status:
lda IRQ_STATUS
ldx #$00
rts
_irq_set_status:
sta IRQ_STATUS
rts

View File

@@ -1,18 +1,12 @@
SEVEN_SEG = $7ff0 UART = $efe6
UART = $7ff4
UART_TXB = UART UART_TXB = UART
UART_RXB = UART UART_RXB = UART
UART_STATUS = UART + 1 UART_STATUS = UART + 1
LED = $7ff6 LED = $efff
SW = LED SW = LED
MM_CTRL = $7ff7 SD_ARG = $efd8
MM_DATA = $7fe0 SD_CMD = $efdc
SD_DATA = $efdd
SD_ARG = $7ff8
SD_CMD = $7ffc
SD_DATA = $7ffd
IRQ_STATUS = $7fff

View File

@@ -1,12 +0,0 @@
#ifndef _MAPPER_H
#define _MAPPER_H
#include <stdint.h>
void mapper_enable(uint8_t en);
uint8_t mapper_read(uint8_t addr);
void mapper_write(uint8_t data, uint8_t addr);
#endif

View File

@@ -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

View File

@@ -5,21 +5,35 @@
void sd_init() { void sd_init() {
uint32_t resp; uint32_t resp;
uint8_t attempts, i;
cputs("In sd_init\n");
sd_card_command(0, 0); sd_card_command(0, 0);
cprintf("Sent Reset\n");
sd_card_command(0x000001aa, 8); sd_card_command(0x000001aa, 8);
sd_card_resp(&resp); sd_card_resp(&resp);
cprintf("CMD8: %lx\n", resp); cprintf("CMD8: %lx\n", resp);
sd_card_command(0, 55); attempts = 0;
sd_card_command(0x40180000, 41); do {
sd_card_resp(&resp); if (attempts > 100) {
cprintf("CMD41: %lx\n", resp); 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); //10ms loop?
sd_card_command(0x40180000, 41); for (i = 0; i < 255; i++);
sd_card_resp(&resp);
cprintf("CMD41: %lx\n", resp); attempts++;
} while (resp != 0);
sd_card_command(0, 2); sd_card_command(0, 2);
sd_card_resp(&resp); sd_card_resp(&resp);

View File

@@ -19,8 +19,8 @@ _uart_txb:
_uart_txb_block: _uart_txb_block:
pha pha
sta UART_TXB ; Write value sta UART_TXB ; Write value
@1: lda UART_STATUS ; Wait for status[0] to be 0 @1: lda UART_STATUS ; Wait for status[1] to be 0
bit #$01 bit #$02
bne @1 bne @1
pla pla
rts rts

View File

@@ -5,20 +5,7 @@
#include "devices/interrupt.h" #include "devices/interrupt.h"
#include "devices/uart.h" #include "devices/uart.h"
char lastchar;
void handle_irq() { 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);
}
} }

View File

@@ -2,7 +2,7 @@ MEMORY
{ {
ZP: start = $0, size = $100, type = rw, define = yes; ZP: start = $0, size = $100, type = rw, define = yes;
SDRAM: start = $200, size = $7cf0, 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 { SEGMENTS {

View File

@@ -5,7 +5,6 @@
#include "devices/board_io.h" #include "devices/board_io.h"
#include "devices/uart.h" #include "devices/uart.h"
#include "devices/mapper.h"
#include "devices/sd_card.h" #include "devices/sd_card.h"
#include "filesystem/fat.h" #include "filesystem/fat.h"
@@ -14,34 +13,21 @@
uint8_t buf[512]; uint8_t buf[512];
int main() { int main() {
int i;
uint16_t rca; uint16_t rca;
char* filename;
uint32_t cluster;
uint8_t* kernel_load;
clrscr(); clrscr();
cprintf("boot\n"); cputs("Starting sd_init\n");
cprintf("And testing cprintf\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);
sd_init(); sd_init();
cprintf("finish sd_init\n");
rca = sd_get_rca(); rca = sd_get_rca();
cprintf("rca: %x\n", rca); cprintf("rca: %x\n", rca);
sd_select_card(rca); sd_select_card(rca);
/*
fat_init(); fat_init();
filename = (char*)malloc(FAT_MAX_FILE_NAME); filename = (char*)malloc(FAT_MAX_FILE_NAME);
@@ -54,8 +40,12 @@ int main() {
cluster = fat_get_chain_value(cluster); cluster = fat_get_chain_value(cluster);
} }
*/
cprintf("Done!\n"); cprintf("Done!\n");
for(;;);
cprintf("Reset vector: %x\n", *((uint16_t*)0xfffc)); cprintf("Reset vector: %x\n", *((uint16_t*)0xfffc));
return 0; return 0;