mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-25 15:16:53 +01:00
small cleanup, rpi testing
This commit is contained in:
parent
cbd7acdc50
commit
6b04dc3f56
@ -18,12 +18,12 @@ void init (void) {
|
|||||||
exception_enable_watchdog();
|
exception_enable_watchdog();
|
||||||
exception_enable_interrupts();
|
exception_enable_interrupts();
|
||||||
|
|
||||||
sc64_init();
|
|
||||||
|
|
||||||
if (test_check()) {
|
if (test_check()) {
|
||||||
exception_disable_watchdog();
|
exception_disable_watchdog();
|
||||||
test_execute();
|
test_execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sc64_set_config(CFG_ID_BOOTLOADER_SWITCH, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit (void) {
|
void deinit (void) {
|
||||||
|
@ -6,15 +6,15 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SC64_CMD_GET_VERSION = 'v',
|
SC64_CMD_VERSION_GET = 'v',
|
||||||
SC64_CMD_CONFIG_QUERY = 'c',
|
SC64_CMD_CONFIG_SET = 'C',
|
||||||
SC64_CMD_CONFIG_CHANGE = 'C',
|
SC64_CMD_CONFIG_GET = 'c',
|
||||||
SC64_CMD_TIME_GET = 't',
|
|
||||||
SC64_CMD_TIME_SET = 'T',
|
SC64_CMD_TIME_SET = 'T',
|
||||||
SC64_CMD_USB_READ = 'm',
|
SC64_CMD_TIME_GET = 't',
|
||||||
|
SC64_CMD_USB_WRITE_STATUS = 'U',
|
||||||
SC64_CMD_USB_WRITE = 'M',
|
SC64_CMD_USB_WRITE = 'M',
|
||||||
SC64_CMD_USB_READ_STATUS = 'u',
|
SC64_CMD_USB_READ_STATUS = 'u',
|
||||||
SC64_CMD_USB_WRITE_STATUS = 'U',
|
SC64_CMD_USB_READ = 'm',
|
||||||
} cmd_id_t;
|
} cmd_id_t;
|
||||||
|
|
||||||
|
|
||||||
@ -45,26 +45,37 @@ bool sc64_check_presence (void) {
|
|||||||
return (version == SC64_VERSION_2);
|
return (version == SC64_VERSION_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc64_init (void) {
|
cmd_error_t sc64_get_error (void) {
|
||||||
sc64_change_config(CFG_ID_BOOTLOADER_SWITCH, false);
|
if (pi_io_read(&SC64_REGS->SR_CMD) & SC64_SR_CMD_ERROR) {
|
||||||
|
return (cmd_error_t) pi_io_read(&SC64_REGS->DATA[0]);
|
||||||
|
}
|
||||||
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sc64_query_config (cfg_id_t id) {
|
void sc64_set_config (cfg_id_t id, uint32_t value) {
|
||||||
|
uint32_t args[2] = { id, value };
|
||||||
|
sc64_execute_cmd(SC64_CMD_CONFIG_SET, args, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sc64_get_config (cfg_id_t id) {
|
||||||
uint32_t args[2] = { id, 0 };
|
uint32_t args[2] = { id, 0 };
|
||||||
uint32_t result[2];
|
uint32_t result[2];
|
||||||
sc64_execute_cmd(SC64_CMD_CONFIG_QUERY, args, result);
|
sc64_execute_cmd(SC64_CMD_CONFIG_GET, args, result);
|
||||||
return result[1];
|
return result[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc64_change_config (cfg_id_t id, uint32_t value) {
|
void sc64_get_boot_info (sc64_boot_info_t *info) {
|
||||||
uint32_t args[2] = { id, value };
|
info->cic_seed = (uint16_t) sc64_get_config(CFG_ID_CIC_SEED);
|
||||||
sc64_execute_cmd(SC64_CMD_CONFIG_CHANGE, args, NULL);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc64_get_boot_info (sc64_boot_info_t *info) {
|
void sc64_set_time (rtc_time_t *t) {
|
||||||
info->cic_seed = (uint16_t) sc64_query_config(CFG_ID_CIC_SEED);
|
uint32_t args[2] = {
|
||||||
info->tv_type = (tv_type_t) sc64_query_config(CFG_ID_TV_TYPE);
|
((t->hour << 16) | (t->minute << 8) | t->second),
|
||||||
info->boot_mode = (boot_mode_t) sc64_query_config(CFG_ID_BOOT_MODE);
|
((t->weekday << 24) | (t->year << 16) | (t->month << 8) | t->day),
|
||||||
|
};
|
||||||
|
sc64_execute_cmd(SC64_CMD_TIME_SET, args, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc64_get_time (rtc_time_t *t) {
|
void sc64_get_time (rtc_time_t *t) {
|
||||||
@ -79,14 +90,6 @@ void sc64_get_time (rtc_time_t *t) {
|
|||||||
t->year = ((result[1] >> 16) & 0xFF);
|
t->year = ((result[1] >> 16) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc64_set_time (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),
|
|
||||||
};
|
|
||||||
sc64_execute_cmd(SC64_CMD_TIME_SET, args, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sc64_usb_write_ready (void) {
|
bool sc64_usb_write_ready (void) {
|
||||||
uint32_t result[2];
|
uint32_t result[2];
|
||||||
sc64_execute_cmd(SC64_CMD_USB_WRITE_STATUS, NULL, result);
|
sc64_execute_cmd(SC64_CMD_USB_WRITE_STATUS, NULL, result);
|
||||||
|
@ -6,6 +6,14 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CMD_OK = 0,
|
||||||
|
CMD_ERROR_BAD_ADDRESS = 1,
|
||||||
|
CMD_ERROR_BAD_CONFIG_ID = 2,
|
||||||
|
CMD_ERROR_TIMEOUT = 3,
|
||||||
|
CMD_ERROR_UNKNOWN_CMD = -1,
|
||||||
|
} cmd_error_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CFG_ID_BOOTLOADER_SWITCH,
|
CFG_ID_BOOTLOADER_SWITCH,
|
||||||
CFG_ID_ROM_WRITE_ENABLE,
|
CFG_ID_ROM_WRITE_ENABLE,
|
||||||
@ -84,14 +92,14 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
bool sc64_check_presence (void);
|
bool sc64_check_presence (void);
|
||||||
void sc64_init (void);
|
cmd_error_t sc64_get_error (void);
|
||||||
uint32_t sc64_query_config (cfg_id_t id);
|
void sc64_set_config (cfg_id_t id, uint32_t value);
|
||||||
void sc64_change_config (cfg_id_t id, uint32_t value);
|
uint32_t sc64_get_config (cfg_id_t id);
|
||||||
void sc64_get_boot_info (sc64_boot_info_t *info);
|
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_set_time (rtc_time_t *t);
|
||||||
bool sc64_write_usb_ready (void);
|
void sc64_get_time (rtc_time_t *t);
|
||||||
bool sc64_write_usb (uint32_t *address, uint32_t length);
|
bool sc64_usb_write_ready (void);
|
||||||
|
bool sc64_usb_write (uint32_t *address, uint32_t length);
|
||||||
bool sc64_usb_read_ready (uint8_t *type, uint32_t *length);
|
bool sc64_usb_read_ready (uint8_t *type, uint32_t *length);
|
||||||
bool sc64_usb_read (uint32_t *address, uint32_t length);
|
bool sc64_usb_read (uint32_t *address, uint32_t length);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
bool test_check (void) {
|
bool test_check (void) {
|
||||||
if (sc64_query_config(CFG_ID_BUTTON_STATE)) {
|
if (sc64_get_config(CFG_ID_BUTTON_STATE)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
0
sw/pc/dd64.py
Normal file → Executable file
0
sw/pc/dd64.py
Normal file → Executable file
17
sw/pc/sc64.py
Normal file → Executable file
17
sw/pc/sc64.py
Normal file → Executable file
@ -31,6 +31,8 @@ class SC64Serial:
|
|||||||
__VID = 0x0403
|
__VID = 0x0403
|
||||||
__PID = 0x6014
|
__PID = 0x6014
|
||||||
|
|
||||||
|
__CHUNK_SIZE = (64 * 1024)
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
ports = list_ports.comports()
|
ports = list_ports.comports()
|
||||||
device_found = False
|
device_found = False
|
||||||
@ -41,7 +43,7 @@ class SC64Serial:
|
|||||||
for p in ports:
|
for p in ports:
|
||||||
if (p.vid == self.__VID and p.pid == self.__PID and p.serial_number.startswith('SC64')):
|
if (p.vid == self.__VID and p.pid == self.__PID and p.serial_number.startswith('SC64')):
|
||||||
try:
|
try:
|
||||||
self.__serial = serial.Serial(p.device, timeout=0.1, write_timeout=5.0)
|
self.__serial = serial.Serial(p.device, timeout=1.0, write_timeout=1.0)
|
||||||
self.__reset_link()
|
self.__reset_link()
|
||||||
except (serial.SerialException, ConnectionException):
|
except (serial.SerialException, ConnectionException):
|
||||||
if (self.__serial):
|
if (self.__serial):
|
||||||
@ -64,7 +66,7 @@ class SC64Serial:
|
|||||||
if (self.__thread_read != None and self.__thread_read.is_alive()):
|
if (self.__thread_read != None and self.__thread_read.is_alive()):
|
||||||
self.__thread_read.join(1)
|
self.__thread_read.join(1)
|
||||||
if (self.__thread_write != None and self.__thread_write.is_alive()):
|
if (self.__thread_write != None and self.__thread_write.is_alive()):
|
||||||
self.__thread_write.join(6)
|
self.__thread_write.join(1)
|
||||||
if (self.__serial != None and self.__serial.is_open):
|
if (self.__serial != None and self.__serial.is_open):
|
||||||
self.__serial.close()
|
self.__serial.close()
|
||||||
|
|
||||||
@ -93,7 +95,8 @@ class SC64Serial:
|
|||||||
try:
|
try:
|
||||||
if (self.__disconnect):
|
if (self.__disconnect):
|
||||||
raise ConnectionException
|
raise ConnectionException
|
||||||
self.__serial.write(data)
|
for offset in range(0, len(data), self.__CHUNK_SIZE):
|
||||||
|
self.__serial.write(data[offset:offset + self.__CHUNK_SIZE])
|
||||||
self.__serial.flush()
|
self.__serial.flush()
|
||||||
except (serial.SerialException, serial.SerialTimeoutException):
|
except (serial.SerialException, serial.SerialTimeoutException):
|
||||||
raise ConnectionException
|
raise ConnectionException
|
||||||
@ -284,7 +287,7 @@ class SC64:
|
|||||||
|
|
||||||
class CICSeed(IntEnum):
|
class CICSeed(IntEnum):
|
||||||
ALECK = 0xAC
|
ALECK = 0xAC
|
||||||
X101 = 0x3F
|
X101 = 0x13F
|
||||||
X102 = 0x3F
|
X102 = 0x3F
|
||||||
X103 = 0x78
|
X103 = 0x78
|
||||||
X105 = 0x91
|
X105 = 0x91
|
||||||
@ -317,11 +320,11 @@ class SC64:
|
|||||||
|
|
||||||
def __write_memory(self, address: int, data: bytes) -> None:
|
def __write_memory(self, address: int, data: bytes) -> None:
|
||||||
if (len(data) > 0):
|
if (len(data) > 0):
|
||||||
self.__link.execute_cmd(cmd=b'M', args=[address, len(data)], data=data, timeout=10.0)
|
self.__link.execute_cmd(cmd=b'M', args=[address, len(data)], data=data, timeout=20.0)
|
||||||
|
|
||||||
def __read_memory(self, address: int, length: int) -> bytes:
|
def __read_memory(self, address: int, length: int) -> bytes:
|
||||||
if (length > 0):
|
if (length > 0):
|
||||||
return self.__link.execute_cmd(cmd=b'm', args=[address, length], timeout=10.0)
|
return self.__link.execute_cmd(cmd=b'm', args=[address, length], timeout=20.0)
|
||||||
return bytes([])
|
return bytes([])
|
||||||
|
|
||||||
def __erase_flash_region(self, address: int, length: int) -> None:
|
def __erase_flash_region(self, address: int, length: int) -> None:
|
||||||
@ -435,7 +438,7 @@ class SC64:
|
|||||||
|
|
||||||
def set_cic_seed(self, seed: int) -> None:
|
def set_cic_seed(self, seed: int) -> None:
|
||||||
if (seed != self.CICSeed.AUTO):
|
if (seed != self.CICSeed.AUTO):
|
||||||
if (seed < 0 or seed > 0xFF):
|
if (seed < 0 or seed > 0x1FF):
|
||||||
raise ValueError('CIC seed outside of allowed values')
|
raise ValueError('CIC seed outside of allowed values')
|
||||||
self.__set_config(self.__CfgId.CIC_SEED, seed)
|
self.__set_config(self.__CfgId.CIC_SEED, seed)
|
||||||
|
|
||||||
|
0
sw/update/update.py
Normal file → Executable file
0
sw/update/update.py
Normal file → Executable file
Loading…
Reference in New Issue
Block a user