mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
[SC64][SW] (#30) Remove usage of CMD23 in SD card sector read/write
This commit is contained in:
parent
c2dc401393
commit
98fa69e4d7
@ -81,6 +81,7 @@ static void test_sd_card (void) {
|
||||
|
||||
if (sc64_sd_read_sectors((void *) (SC64_BUFFERS->BUFFER), 0, 1)) {
|
||||
display_printf("SD card read sector 0 error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pi_dma_read((io32_t *) (SC64_BUFFERS->BUFFER), sector, sizeof(sector));
|
||||
@ -94,7 +95,7 @@ static void test_sd_card (void) {
|
||||
display_printf("%02X ", sector[0x1CE + i]);
|
||||
}
|
||||
display_printf("\n");
|
||||
display_printf(" Boot signature: 0x%02X%02X", sector[510], sector[511]);
|
||||
display_printf(" Boot signature: 0x%02X%02X\n", sector[510], sector[511]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,8 @@
|
||||
#define SWITCH_FUNCTION_GROUP_1_HS (1 << 1)
|
||||
|
||||
#define DAT_BLOCK_MAX_COUNT (256)
|
||||
#define DAT_TIMEOUT_MS (1000)
|
||||
#define DAT_TIMEOUT_INIT_MS (2000)
|
||||
#define DAT_TIMEOUT_DATA_MS (5000)
|
||||
|
||||
|
||||
typedef enum {
|
||||
@ -300,7 +301,7 @@ bool sd_card_init (void) {
|
||||
sd_card_deinit();
|
||||
return true;
|
||||
}
|
||||
sd_dat_wait(DAT_TIMEOUT_MS);
|
||||
sd_dat_wait(DAT_TIMEOUT_INIT_MS);
|
||||
if (sd_did_timeout()) {
|
||||
sd_card_deinit();
|
||||
return true;
|
||||
@ -318,7 +319,7 @@ bool sd_card_init (void) {
|
||||
sd_card_deinit();
|
||||
return true;
|
||||
}
|
||||
sd_dat_wait(DAT_TIMEOUT_MS);
|
||||
sd_dat_wait(DAT_TIMEOUT_INIT_MS);
|
||||
if (sd_did_timeout()) {
|
||||
sd_card_deinit();
|
||||
return true;
|
||||
@ -382,14 +383,11 @@ bool sd_write_sectors (uint32_t address, uint32_t sector, uint32_t count) {
|
||||
while (count > 0) {
|
||||
uint32_t blocks = ((count > DAT_BLOCK_MAX_COUNT) ? DAT_BLOCK_MAX_COUNT : count);
|
||||
led_blink_act();
|
||||
if (sd_cmd(23, blocks, RSP_R1, NULL)) {
|
||||
return true;
|
||||
}
|
||||
if (sd_cmd(25, sector, RSP_R1, NULL)) {
|
||||
return true;
|
||||
}
|
||||
sd_dat_prepare(address, blocks, DAT_WRITE);
|
||||
if (sd_dat_wait(DAT_TIMEOUT_MS)) {
|
||||
if (sd_dat_wait(DAT_TIMEOUT_DATA_MS)) {
|
||||
sd_dat_abort();
|
||||
sd_cmd(12, 0, RSP_R1b, NULL);
|
||||
return true;
|
||||
@ -416,20 +414,17 @@ bool sd_read_sectors (uint32_t address, uint32_t sector, uint32_t count) {
|
||||
uint32_t blocks = ((count > DAT_BLOCK_MAX_COUNT) ? DAT_BLOCK_MAX_COUNT : count);
|
||||
led_blink_act();
|
||||
sd_dat_prepare(address, blocks, DAT_READ);
|
||||
if (sd_cmd(23, blocks, RSP_R1, NULL)) {
|
||||
sd_dat_abort();
|
||||
return true;
|
||||
}
|
||||
if (sd_cmd(18, sector, RSP_R1, NULL)) {
|
||||
sd_dat_abort();
|
||||
return true;
|
||||
}
|
||||
if (sd_dat_wait(DAT_TIMEOUT_MS)) {
|
||||
if (sd_dat_wait(DAT_TIMEOUT_DATA_MS)) {
|
||||
if (sd_did_timeout()) {
|
||||
sd_cmd(12, 0, RSP_R1b, NULL);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sd_cmd(12, 0, RSP_R1b, NULL);
|
||||
address += (blocks * SD_SECTOR_SIZE);
|
||||
sector += (blocks * (p.card_type_block ? 1 : SD_SECTOR_SIZE));
|
||||
count -= blocks;
|
||||
|
@ -338,7 +338,7 @@ class SC64:
|
||||
def __get_int(self, data: bytes) -> int:
|
||||
return int.from_bytes(data[:4], byteorder='big')
|
||||
|
||||
def check_firmware_version(self) -> None:
|
||||
def check_firmware_version(self) -> tuple[str, bool]:
|
||||
try:
|
||||
version = self.__link.execute_cmd(cmd=b'V')
|
||||
major = self.__get_int(version[0:2])
|
||||
@ -347,8 +347,9 @@ class SC64:
|
||||
raise ConnectionException()
|
||||
if (minor < self.__SUPPORTED_MINOR_VERSION):
|
||||
raise ConnectionException()
|
||||
return (f'{major}.{minor}', minor > self.__SUPPORTED_MINOR_VERSION)
|
||||
except ConnectionException:
|
||||
raise ConnectionException(f'Unsupported SC64 version ({major}.{minor}), please update firmware')
|
||||
raise ConnectionException(f'Unsupported SC64 version [{major}.{minor}], please update firmware')
|
||||
|
||||
def __set_config(self, config: __CfgId, value: int) -> None:
|
||||
try:
|
||||
@ -1054,7 +1055,15 @@ if __name__ == '__main__':
|
||||
sc64.update_firmware(f.read(), status_callback)
|
||||
print('done')
|
||||
|
||||
sc64.check_firmware_version()
|
||||
(version, script_outdated) = sc64.check_firmware_version()
|
||||
|
||||
print(f'SC64 firmware version: [{version}]')
|
||||
if (script_outdated):
|
||||
print('\x1b[33m')
|
||||
print('[ SC64 firmware is newer than last known version. ]')
|
||||
print('[ Consider downloading latest script from ]')
|
||||
print('[ https://github.com/Polprzewodnikowy/SummerCart64/releases ]')
|
||||
print('\x1b[0m')
|
||||
|
||||
if (args.reset_state):
|
||||
sc64.reset_state()
|
||||
@ -1142,6 +1151,6 @@ if __name__ == '__main__':
|
||||
f.write(sc64.download_memory(address, length))
|
||||
print('done')
|
||||
except ValueError as e:
|
||||
print(f'\nValue error: {e}')
|
||||
print(f'\n\x1b[31mValue error: {e}\x1b[0m\n')
|
||||
except ConnectionException as e:
|
||||
print(f'\nSC64 error: {e}')
|
||||
print(f'\n\x1b[31mSC64 error: {e}\x1b[0m\n')
|
||||
|
Loading…
Reference in New Issue
Block a user