mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 14:09:16 +01:00
[SC64][SW] Added RTC test, code cleanup
This commit is contained in:
parent
62a5b6a062
commit
1531278379
@ -3,12 +3,10 @@
|
||||
#include "diskio.h"
|
||||
#include "../io.h"
|
||||
#include "../sc64.h"
|
||||
#include "../error.h"
|
||||
|
||||
|
||||
#define SD_SECTOR_SIZE (512)
|
||||
#define BUFFER_BLOCKS_MAX (sizeof(SC64_BUFFERS->BUFFER) / SD_SECTOR_SIZE)
|
||||
#define FROM_BCD(x) ((((x >> 4) & 0x0F) * 10) + (x & 0x0F))
|
||||
|
||||
|
||||
DSTATUS disk_status (BYTE pdrv) {
|
||||
@ -17,7 +15,7 @@ DSTATUS disk_status (BYTE pdrv) {
|
||||
}
|
||||
|
||||
DSTATUS status = 0;
|
||||
sd_card_status_t sd_card_status = sc64_sd_card_get_status();
|
||||
sc64_sd_card_status_t sd_card_status = sc64_sd_card_get_status();
|
||||
|
||||
if (!(sd_card_status & SD_CARD_STATUS_INSERTED)) {
|
||||
status |= STA_NODISK;
|
||||
@ -114,7 +112,7 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void *buff) {
|
||||
}
|
||||
|
||||
DWORD get_fattime(void) {
|
||||
rtc_time_t t;
|
||||
sc64_rtc_time_t t;
|
||||
sc64_get_time(&t);
|
||||
return (
|
||||
((FROM_BCD(t.year) + 20) << 25) |
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
|
||||
void init (void) {
|
||||
uint32_t pifram = si_io_read((io32_t *) (&PIFRAM[0x3C]));
|
||||
si_io_write((io32_t *) (&PIFRAM[0x3C]), pifram | 0x08);
|
||||
uint32_t pifram = si_io_read((io32_t *) (PIFRAM_STATUS));
|
||||
si_io_write((io32_t *) (PIFRAM_STATUS), pifram | PIFRAM_TERMINATE_BOOT);
|
||||
|
||||
exception_install();
|
||||
|
||||
@ -29,7 +29,7 @@ void init (void) {
|
||||
}
|
||||
|
||||
void deinit (void) {
|
||||
sc64_lock();
|
||||
exception_disable_interrupts();
|
||||
exception_disable_watchdog();
|
||||
sc64_lock();
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ typedef volatile uint32_t io32_t;
|
||||
|
||||
#define N64_RAM_SIZE (0x00800000UL)
|
||||
|
||||
#define FROM_BCD(x) ((((x >> 4) & 0x0F) * 10) + (x & 0x0F))
|
||||
|
||||
|
||||
typedef struct {
|
||||
io32_t DMEM[1024];
|
||||
@ -227,6 +229,10 @@ typedef struct {
|
||||
#define PIFRAM_BASE (0x1FC007C0UL)
|
||||
#define PIFRAM ((io8_t *) PIFRAM_BASE)
|
||||
|
||||
#define PIFRAM_STATUS (&PIFRAM[0x3C])
|
||||
|
||||
#define PIFRAM_TERMINATE_BOOT (1 << 3)
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t tv_type;
|
||||
@ -244,6 +250,9 @@ typedef struct {
|
||||
#define OS_INFO_BASE (0x80000300UL)
|
||||
#define OS_INFO ((os_info_t *) OS_INFO_BASE)
|
||||
|
||||
#define OS_INFO_RESET_TYPE_COLD (0)
|
||||
#define OS_INFO_RESET_TYPE_NMI (1)
|
||||
|
||||
|
||||
uint32_t cpu_io_read (io32_t *address);
|
||||
void cpu_io_write (io32_t *address, uint32_t value);
|
||||
|
@ -81,13 +81,13 @@ void menu_load_and_run (void) {
|
||||
size = (size_t) (f_size(&fil) - ROM_CODE_OFFSET);
|
||||
}
|
||||
menu_check_load_address(menu, size);
|
||||
cache_data_hit_writeback_invalidate(menu, size);
|
||||
cache_inst_hit_invalidate(menu, size);
|
||||
FF_CHECK(f_read(&fil, menu, size, &br), "Couldn't read menu file");
|
||||
FF_CHECK((br != size) ? FR_INT_ERR : FR_OK, "Read size is different than expected");
|
||||
FF_CHECK(f_close(&fil), "Couldn't close menu file");
|
||||
FF_CHECK(f_unmount(""), "Couldn't unmount drive");
|
||||
|
||||
cache_inst_hit_invalidate(menu, size);
|
||||
|
||||
deinit();
|
||||
|
||||
menu();
|
||||
|
@ -52,60 +52,50 @@ typedef enum {
|
||||
SD_CARD_OP_GET_INFO = 3,
|
||||
} sd_card_op_t;
|
||||
|
||||
static sc64_pi_io_t pi_io = {
|
||||
.read = pi_io_read,
|
||||
.write = pi_io_write
|
||||
};
|
||||
|
||||
|
||||
static bool sc64_wait_cpu_busy (void) {
|
||||
uint32_t sr;
|
||||
do {
|
||||
sr = pi_io.read(&SC64_REGS->SR_CMD);
|
||||
sr = pi_io_read(&SC64_REGS->SR_CMD);
|
||||
} while (sr & SC64_SR_CPU_BUSY);
|
||||
return (sr & SC64_SR_CMD_ERROR);
|
||||
}
|
||||
|
||||
static bool sc64_execute_cmd (uint8_t cmd, uint32_t *args, uint32_t *result) {
|
||||
if (args != NULL) {
|
||||
pi_io.write(&SC64_REGS->DATA[0], args[0]);
|
||||
pi_io.write(&SC64_REGS->DATA[1], args[1]);
|
||||
pi_io_write(&SC64_REGS->DATA[0], args[0]);
|
||||
pi_io_write(&SC64_REGS->DATA[1], args[1]);
|
||||
}
|
||||
pi_io.write(&SC64_REGS->SR_CMD, ((uint32_t) (cmd)) & 0xFF);
|
||||
pi_io_write(&SC64_REGS->SR_CMD, ((uint32_t) (cmd)) & 0xFF);
|
||||
bool error = sc64_wait_cpu_busy();
|
||||
if (result != NULL) {
|
||||
result[0] = pi_io.read(&SC64_REGS->DATA[0]);
|
||||
result[1] = pi_io.read(&SC64_REGS->DATA[1]);
|
||||
result[0] = pi_io_read(&SC64_REGS->DATA[0]);
|
||||
result[1] = pi_io_read(&SC64_REGS->DATA[1]);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
void sc64_set_pi_io_functions (sc64_pi_io_t functions) {
|
||||
pi_io.read = functions.read;
|
||||
pi_io.write = functions.write;
|
||||
}
|
||||
|
||||
sc64_error_t sc64_get_error (void) {
|
||||
if (pi_io.read(&SC64_REGS->SR_CMD) & SC64_SR_CMD_ERROR) {
|
||||
return (sc64_error_t) (pi_io.read(&SC64_REGS->DATA[0]));
|
||||
if (pi_io_read(&SC64_REGS->SR_CMD) & SC64_SR_CMD_ERROR) {
|
||||
return (sc64_error_t) (pi_io_read(&SC64_REGS->DATA[0]));
|
||||
}
|
||||
return SC64_OK;
|
||||
}
|
||||
|
||||
void sc64_unlock (void) {
|
||||
pi_io.write(&SC64_REGS->KEY, SC64_KEY_RESET);
|
||||
pi_io.write(&SC64_REGS->KEY, SC64_KEY_UNLOCK_1);
|
||||
pi_io.write(&SC64_REGS->KEY, SC64_KEY_UNLOCK_2);
|
||||
pi_io_write(&SC64_REGS->KEY, SC64_KEY_RESET);
|
||||
pi_io_write(&SC64_REGS->KEY, SC64_KEY_UNLOCK_1);
|
||||
pi_io_write(&SC64_REGS->KEY, SC64_KEY_UNLOCK_2);
|
||||
}
|
||||
|
||||
void sc64_lock (void) {
|
||||
pi_io.write(&SC64_REGS->KEY, SC64_KEY_RESET);
|
||||
pi_io.write(&SC64_REGS->KEY, SC64_KEY_LOCK);
|
||||
pi_io_write(&SC64_REGS->KEY, SC64_KEY_RESET);
|
||||
pi_io_write(&SC64_REGS->KEY, SC64_KEY_LOCK);
|
||||
}
|
||||
|
||||
bool sc64_check_presence (void) {
|
||||
uint32_t version = pi_io.read(&SC64_REGS->VERSION);
|
||||
uint32_t version = pi_io_read(&SC64_REGS->VERSION);
|
||||
if (version == SC64_VERSION_2) {
|
||||
sc64_wait_cpu_busy();
|
||||
return true;
|
||||
@ -114,35 +104,35 @@ bool sc64_check_presence (void) {
|
||||
}
|
||||
|
||||
bool sc64_irq_pending (void) {
|
||||
if (pi_io.read(&SC64_REGS->SR_CMD) & SC64_SR_IRQ_PENDING) {
|
||||
if (pi_io_read(&SC64_REGS->SR_CMD) & SC64_SR_IRQ_PENDING) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void sc64_irq_clear (void) {
|
||||
pi_io.write(&SC64_REGS->VERSION, 0);
|
||||
pi_io_write(&SC64_REGS->VERSION, 0);
|
||||
}
|
||||
|
||||
uint32_t sc64_get_config (cfg_id_t id) {
|
||||
uint32_t sc64_get_config (sc64_cfg_id_t id) {
|
||||
uint32_t args[2] = { id, 0 };
|
||||
uint32_t result[2];
|
||||
sc64_execute_cmd(SC64_CMD_CONFIG_GET, args, result);
|
||||
return result[1];
|
||||
}
|
||||
|
||||
void sc64_set_config (cfg_id_t id, uint32_t value) {
|
||||
void sc64_set_config (sc64_cfg_id_t id, uint32_t value) {
|
||||
uint32_t args[2] = { id, value };
|
||||
sc64_execute_cmd(SC64_CMD_CONFIG_SET, args, NULL);
|
||||
}
|
||||
|
||||
void sc64_get_boot_info (sc64_boot_info_t *info) {
|
||||
info->cic_seed = (uint16_t) sc64_get_config(CFG_ID_CIC_SEED);
|
||||
info->tv_type = (tv_type_t) sc64_get_config(CFG_ID_TV_TYPE);
|
||||
info->boot_mode = (boot_mode_t) sc64_get_config(CFG_ID_BOOT_MODE);
|
||||
info->boot_mode = (sc64_boot_mode_t) sc64_get_config(CFG_ID_BOOT_MODE);
|
||||
info->cic_seed = (sc64_cic_seed_t) sc64_get_config(CFG_ID_CIC_SEED);
|
||||
info->tv_type = (sc64_tv_type_t) sc64_get_config(CFG_ID_TV_TYPE);
|
||||
}
|
||||
|
||||
void sc64_get_time (rtc_time_t *t) {
|
||||
void sc64_get_time (sc64_rtc_time_t *t) {
|
||||
uint32_t result[2];
|
||||
sc64_execute_cmd(SC64_CMD_TIME_GET, NULL, result);
|
||||
t->second = (result[0] & 0xFF);
|
||||
@ -154,7 +144,7 @@ void sc64_get_time (rtc_time_t *t) {
|
||||
t->year = ((result[1] >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
void sc64_set_time (rtc_time_t *t) {
|
||||
void sc64_set_time (sc64_rtc_time_t *t) {
|
||||
uint32_t args[2] = {
|
||||
((t->hour << 16) | (t->minute << 8) | t->second),
|
||||
((t->weekday << 24) | (t->year << 16) | (t->month << 8) | t->day),
|
||||
@ -214,13 +204,13 @@ bool sc64_sd_card_deinit (void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sd_card_status_t sc64_sd_card_get_status (void) {
|
||||
sc64_sd_card_status_t sc64_sd_card_get_status (void) {
|
||||
uint32_t args[2] = { (uint32_t) (NULL), SD_CARD_OP_GET_STATUS };
|
||||
uint32_t result[2];
|
||||
if (sc64_execute_cmd(SC64_CMD_SD_CARD_OP, args, result)) {
|
||||
return false;
|
||||
}
|
||||
return (sd_card_status_t) (result[1]);
|
||||
return (sc64_sd_card_status_t) (result[1]);
|
||||
}
|
||||
|
||||
bool sc64_sd_card_get_info (void *address) {
|
||||
|
@ -32,21 +32,21 @@ typedef enum {
|
||||
CFG_ID_BUTTON_STATE,
|
||||
CFG_ID_BUTTON_MODE,
|
||||
CFG_ID_ROM_EXTENDED_ENABLE,
|
||||
} cfg_id_t;
|
||||
} sc64_cfg_id_t;
|
||||
|
||||
typedef enum {
|
||||
DD_MODE_DISABLED = 0,
|
||||
DD_MODE_REGS = 1,
|
||||
DD_MODE_IPL = 2,
|
||||
DD_MODE_FULL = 3
|
||||
} dd_mode_t;
|
||||
} sc64_dd_mode_t;
|
||||
|
||||
typedef enum {
|
||||
BOOT_MODE_MENU = 0,
|
||||
BOOT_MODE_ROM = 1,
|
||||
BOOT_MODE_DDIPL = 2,
|
||||
BOOT_MODE_DIRECT = 3
|
||||
} boot_mode_t;
|
||||
} sc64_boot_mode_t;
|
||||
|
||||
typedef enum {
|
||||
SAVE_TYPE_NONE = 0,
|
||||
@ -55,37 +55,37 @@ typedef enum {
|
||||
SAVE_TYPE_SRAM = 3,
|
||||
SAVE_TYPE_FLASHRAM = 4,
|
||||
SAVE_TYPE_SRAM_BANKED = 5
|
||||
} save_type_t;
|
||||
} sc64_save_type_t;
|
||||
|
||||
typedef enum {
|
||||
CIC_SEED_UNKNOWN = 0xFFFF
|
||||
} cic_seed_t;
|
||||
} sc64_cic_seed_t;
|
||||
|
||||
typedef enum {
|
||||
TV_TYPE_PAL = 0,
|
||||
TV_TYPE_NTSC = 1,
|
||||
TV_TYPE_MPAL = 2,
|
||||
TV_TYPE_UNKNOWN = 3
|
||||
} tv_type_t;
|
||||
} sc64_tv_type_t;
|
||||
|
||||
typedef enum {
|
||||
BUTTON_MODE_NONE,
|
||||
BUTTON_MODE_N64_IRQ,
|
||||
BUTTON_MODE_USB_PACKET,
|
||||
BUTTON_MODE_DD_DISK_SWAP,
|
||||
} button_mode_t;
|
||||
} sc64_button_mode_t;
|
||||
|
||||
typedef enum {
|
||||
SD_CARD_STATUS_INSERTED = (1 << 0),
|
||||
SD_CARD_STATUS_INITIALIZED = (1 << 1),
|
||||
SD_CARD_STATUS_TYPE_BLOCK = (1 << 2),
|
||||
SD_CARD_STATUS_50MHZ_MODE = (1 << 3),
|
||||
} sd_card_status_t;
|
||||
} sc64_sd_card_status_t;
|
||||
|
||||
typedef struct {
|
||||
boot_mode_t boot_mode;
|
||||
uint16_t cic_seed;
|
||||
tv_type_t tv_type;
|
||||
sc64_boot_mode_t boot_mode;
|
||||
sc64_cic_seed_t cic_seed;
|
||||
sc64_tv_type_t tv_type;
|
||||
} sc64_boot_info_t;
|
||||
|
||||
typedef struct {
|
||||
@ -96,7 +96,7 @@ typedef struct {
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
uint8_t year;
|
||||
} rtc_time_t;
|
||||
} sc64_rtc_time_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -109,13 +109,6 @@ typedef struct {
|
||||
#define SC64_BUFFERS_BASE (0x1FFE0000UL)
|
||||
#define SC64_BUFFERS ((sc64_buffers_t *) SC64_BUFFERS_BASE)
|
||||
|
||||
typedef struct {
|
||||
uint32_t (*read)(volatile uint32_t *address);
|
||||
void (*write)(volatile uint32_t *address, uint32_t value);
|
||||
} sc64_pi_io_t;
|
||||
|
||||
|
||||
void sc64_set_pi_io_functions (sc64_pi_io_t functions);
|
||||
|
||||
sc64_error_t sc64_get_error (void);
|
||||
|
||||
@ -126,12 +119,12 @@ bool sc64_check_presence (void);
|
||||
bool sc64_irq_pending (void);
|
||||
void sc64_irq_clear (void);
|
||||
|
||||
uint32_t sc64_get_config (cfg_id_t id);
|
||||
void sc64_set_config (cfg_id_t id, uint32_t value);
|
||||
uint32_t sc64_get_config (sc64_cfg_id_t id);
|
||||
void sc64_set_config (sc64_cfg_id_t id, uint32_t value);
|
||||
void sc64_get_boot_info (sc64_boot_info_t *info);
|
||||
|
||||
void sc64_get_time (rtc_time_t *t);
|
||||
void sc64_set_time (rtc_time_t *t);
|
||||
void sc64_get_time (sc64_rtc_time_t *t);
|
||||
void sc64_set_time (sc64_rtc_time_t *t);
|
||||
|
||||
bool sc64_usb_read_ready (uint8_t *type, uint32_t *length);
|
||||
bool sc64_usb_read (void *address, uint32_t length);
|
||||
@ -140,7 +133,7 @@ bool sc64_usb_write (void *address, uint8_t type, uint32_t length);
|
||||
|
||||
bool sc64_sd_card_init (void);
|
||||
bool sc64_sd_card_deinit (void);
|
||||
sd_card_status_t sc64_sd_card_get_status (void);
|
||||
sc64_sd_card_status_t sc64_sd_card_get_status (void);
|
||||
bool sc64_sd_card_get_info (void *address);
|
||||
bool sc64_sd_write_sectors (void *address, uint32_t sector, uint32_t count);
|
||||
bool sc64_sd_read_sectors (void *address, uint32_t sector, uint32_t count);
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include "vr4300.h"
|
||||
|
||||
|
||||
.section .text.rom_header
|
||||
.section .text.rom_header, "a", %progbits
|
||||
.type rom_header, %object
|
||||
rom_header:
|
||||
|
||||
header_pi_config:
|
||||
.word 0x80371240
|
||||
|
||||
@ -23,12 +26,14 @@ header_text_info:
|
||||
.org 0x40, 0x00
|
||||
|
||||
|
||||
.section .text.ipl3
|
||||
.section .text.ipl3, "a", %progbits
|
||||
.type ipl3, %object
|
||||
ipl3:
|
||||
.incbin "header", 0x40
|
||||
|
||||
|
||||
.section .text.entry_handler
|
||||
.section .text.entry_handler, "ax", %progbits
|
||||
.type entry_handler, %function
|
||||
entry_handler:
|
||||
.global entry_handler
|
||||
|
||||
|
@ -5,21 +5,23 @@
|
||||
#include "test.h"
|
||||
|
||||
|
||||
bool test_check (void) {
|
||||
if (sc64_get_config(CFG_ID_BUTTON_STATE)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
static void test_rtc (void) {
|
||||
sc64_rtc_time_t t;
|
||||
const char *weekdays[8] = { "", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
|
||||
|
||||
sc64_get_time(&t);
|
||||
|
||||
display_printf("RTC current time:\n");
|
||||
display_printf(" %02d:%02d:%02d", FROM_BCD(t.hour), FROM_BCD(t.minute), FROM_BCD(t.second));
|
||||
display_printf(" %s ", weekdays[FROM_BCD(t.weekday)]);
|
||||
display_printf("%d.%02d.%04d", FROM_BCD(t.day), FROM_BCD(t.month), 2000 + FROM_BCD(t.year));
|
||||
display_printf("\n");
|
||||
}
|
||||
|
||||
void test_execute (void) {
|
||||
sd_card_status_t card_status;
|
||||
static void test_sd_card (void) {
|
||||
sc64_sd_card_status_t card_status;
|
||||
uint8_t card_info[32] __attribute__((aligned(8)));
|
||||
|
||||
display_init(NULL);
|
||||
|
||||
display_printf("SC64 Test suite\n\n");
|
||||
|
||||
card_status = sc64_sd_card_get_status();
|
||||
|
||||
if (card_status & SD_CARD_STATUS_INSERTED) {
|
||||
@ -30,7 +32,7 @@ void test_execute (void) {
|
||||
|
||||
if (sc64_sd_card_init()) {
|
||||
display_printf("SD card init error!\n");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
|
||||
card_status = sc64_sd_card_get_status();
|
||||
@ -47,7 +49,7 @@ void test_execute (void) {
|
||||
|
||||
if (sc64_sd_card_get_info((uint32_t *) (SC64_BUFFERS->BUFFER))) {
|
||||
display_printf("SD card get info error!\n");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
|
||||
pi_dma_read((io32_t *) (SC64_BUFFERS->BUFFER), card_info, sizeof(card_info));
|
||||
@ -64,6 +66,27 @@ void test_execute (void) {
|
||||
for (int i = 16; i < 32; i++) {
|
||||
display_printf("%c ", card_info[i] >= ' ' ? card_info[i] : 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool test_check (void) {
|
||||
if (OS_INFO->reset_type != OS_INFO_RESET_TYPE_COLD) {
|
||||
return false;
|
||||
}
|
||||
return sc64_get_config(CFG_ID_BUTTON_STATE);
|
||||
}
|
||||
|
||||
void test_execute (void) {
|
||||
display_init(NULL);
|
||||
display_printf("SC64 Test suite\n\n");
|
||||
|
||||
display_printf("[ RTC tests ]\n");
|
||||
test_rtc();
|
||||
display_printf("\n");
|
||||
|
||||
display_printf("[ SD card tests ]\n");
|
||||
test_sd_card();
|
||||
display_printf("\n");
|
||||
|
||||
while (1);
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ if __name__ == '__main__':
|
||||
Utils.log()
|
||||
|
||||
Utils.warning('[ IMPORTANT ]')
|
||||
Utils.warning('Unplug board from power and reconnect it before proceeding')
|
||||
Utils.warning('Unplug SC64 board from power and reconnect it before proceeding')
|
||||
Utils.log()
|
||||
|
||||
try:
|
||||
|
@ -223,7 +223,7 @@ class SC64:
|
||||
EEPROM_16K = (2 * 1024)
|
||||
SRAM = (32 * 1024)
|
||||
FLASHRAM = (128 * 1024)
|
||||
SRAM_3X = (3 * 32 * 1024)
|
||||
SRAM_BANKED = (3 * 32 * 1024)
|
||||
|
||||
class __CfgId(IntEnum):
|
||||
BOOTLOADER_SWITCH = 0
|
||||
@ -290,7 +290,7 @@ class SC64:
|
||||
EEPROM_16K = 2
|
||||
SRAM = 3
|
||||
FLASHRAM = 4
|
||||
SRAM_3X = 5
|
||||
SRAM_BANKED = 5
|
||||
|
||||
class CICSeed(IntEnum):
|
||||
DEFAULT = 0x3F
|
||||
|
Loading…
Reference in New Issue
Block a user