prioritize joybus, cpu_has_uart flag

This commit is contained in:
Polprzewodnikowy 2021-11-16 19:43:59 +01:00
parent 12c3444cab
commit 0ae6aed88f
8 changed files with 68 additions and 45 deletions

View File

@ -72,12 +72,16 @@ module cpu_soc (
.usb_pwren(usb_pwren) .usb_pwren(usb_pwren)
); );
cpu_uart cpu_uart_inst ( generate
.sys(sys), if (sc64::CPU_HAS_UART) begin
.bus(bus.at[sc64::ID_CPU_UART].device), cpu_uart cpu_uart_inst (
.uart_rxd(uart_rxd), .sys(sys),
.uart_txd(uart_txd) .bus(bus.at[sc64::ID_CPU_UART].device),
); .uart_rxd(uart_rxd),
.uart_txd(uart_txd)
);
end
endgenerate
cpu_dma cpu_dma_inst ( cpu_dma cpu_dma_inst (
.sys(sys), .sys(sys),

View File

@ -34,6 +34,8 @@ package sc64;
parameter int CLOCK_FREQUENCY = 32'd100_000_000; parameter int CLOCK_FREQUENCY = 32'd100_000_000;
parameter bit CPU_HAS_UART = 1'b0;
parameter int UART_BAUD_RATE = 32'd1_000_000; parameter int UART_BAUD_RATE = 32'd1_000_000;
endpackage endpackage

View File

@ -19,8 +19,3 @@ void dma_stop (void) {
void dma_init (void) { void dma_init (void) {
dma_stop(); dma_stop();
} }
void process_dma (void) {
}

View File

@ -20,7 +20,6 @@ bool dma_busy (void);
void dma_start (uint32_t memory_address, size_t length, enum dma_id id, enum dma_dir dir); void dma_start (uint32_t memory_address, size_t length, enum dma_id id, enum dma_dir dir);
void dma_stop (void); void dma_stop (void);
void dma_init (void); void dma_init (void);
void process_dma (void);
#endif #endif

View File

@ -14,6 +14,17 @@ enum operation {
}; };
struct process {
bool save_in_progress;
enum operation op;
io32_t *save_pointer;
uint32_t num_words;
uint32_t current_word;
};
static struct process p;
static enum operation get_operation_type (void) { static enum operation get_operation_type (void) {
uint32_t scr = FLASHRAM->SCR; uint32_t scr = FLASHRAM->SCR;
@ -44,26 +55,38 @@ static size_t get_operation_length (enum operation op) {
void flashram_init (void) { void flashram_init (void) {
FLASHRAM->SCR = FLASHRAM_OPERATION_DONE; FLASHRAM->SCR = FLASHRAM_OPERATION_DONE;
p.save_in_progress = false;
} }
void process_flashram (void) { void process_flashram (void) {
enum operation op = get_operation_type(); if (!p.save_in_progress) {
size_t length; p.op = get_operation_type();
io32_t *save_data;
if (op != OP_NONE) { if (p.op != OP_NONE) {
length = get_operation_length(op); uint32_t sdram_address = SDRAM_BASE + CFG->SAVE_OFFSET;
save_data = (io32_t *) (SDRAM_BASE + CFG->SAVE_OFFSET + ((FLASHRAM->SCR >> FLASHRAM_PAGE_BIT) * FLASHRAM_PAGE_SIZE));
for (uint32_t i = 0; i < (length / 4); i++) { p.save_in_progress = true;
if (op == OP_WRITE_PAGE) { if (p.op != OP_ERASE_ALL) {
*save_data++ &= FLASHRAM->BUFFER[i]; sdram_address += (FLASHRAM->SCR >> FLASHRAM_PAGE_BIT) * FLASHRAM_PAGE_SIZE;
} else {
*save_data++ = FLASHRAM_ERASE_VALUE;
} }
p.save_pointer = (io32_t *) (sdram_address);
p.num_words = get_operation_length(p.op) / sizeof(uint32_t);
p.current_word = 0;
}
} else {
if (p.op == OP_WRITE_PAGE) {
*p.save_pointer++ &= FLASHRAM->BUFFER[p.current_word];
} else {
*p.save_pointer++ = FLASHRAM_ERASE_VALUE;
} }
FLASHRAM->SCR = FLASHRAM_OPERATION_DONE; p.current_word += 1;
if (p.current_word >= p.num_words) {
p.save_in_progress = false;
FLASHRAM->SCR = FLASHRAM_OPERATION_DONE;
}
} }
} }

View File

@ -9,7 +9,20 @@
#include "uart.h" #include "uart.h"
void process_init (void) { static const void (*process_table[])(void) = {
process_usb,
process_cfg,
process_rtc,
process_i2c,
process_flashram,
process_uart,
NULL,
};
__attribute__((naked)) void process_loop (void) {
void (**process_func)(void) = process_table;
usb_init(); usb_init();
cfg_init(); cfg_init();
dma_init(); dma_init();
@ -18,18 +31,12 @@ void process_init (void) {
i2c_init(); i2c_init();
flashram_init(); flashram_init();
uart_init(); uart_init();
}
void process_loop (void) {
while (1) { while (1) {
process_usb();
process_cfg();
process_dma();
process_joybus(); process_joybus();
process_rtc(); (*process_func++)();
process_i2c(); if (*process_func == NULL) {
process_flashram(); process_func = process_table;
process_uart(); }
} }
} }

View File

@ -32,12 +32,9 @@ init_bss:
blt a0, a1, 1b blt a0, a1, 1b
2: 2:
run: run_in_ram:
call process_init la ra, process_loop
call process_loop jalr zero, 0(ra)
loop:
j loop
copy_section: copy_section:
bge a1, a2, 2f bge a1, a2, 2f

View File

@ -185,8 +185,4 @@ typedef volatile struct joybus_regs {
#define JOYBUS_SCR_TX_LENGTH_BIT (16) #define JOYBUS_SCR_TX_LENGTH_BIT (16)
void reset_handler (void);
void app_handler (void);
#endif #endif