- FATFS FatFs;
- FIL File;
- unsigned long bytes = 0x80000;
- unsigned long pos= 0;
- unsigned long bytes_read;
- uint32_t addr;
- FRESULT res;
- bool buserr = 0;
- uint32_t timer;
- uint8_t buffer[512];
-
- (void) cmdtp; (void) flag;
-
- if (argc < 3)
- return CMD_RET_USAGE;
-
- addr = strtoul(argv[2], 0, 16);
- if (argc > 3)
- bytes = strtoul(argv[3], 0, 16);
- if (argc > 4)
- pos = strtoul(argv[4], 0, 16);
-
- res = f_mount(&FatFs, argv[1], 0);
- if (!res) {
- res = f_open(&File, argv[1], FA_READ);
-
- if (!res) {
- res = f_lseek(&File, pos);
- if (!res) {
- bytes_read = 0;
- timer = get_timer(0);
- while (bytes) {
- unsigned int cnt, br;
-
- if (bytes >= sizeof buffer) {
- cnt = sizeof buffer;
- bytes -= sizeof buffer;
- } else {
- cnt = bytes; bytes = 0;
- }
- res = f_read(&File, buffer, cnt, &br);
- if (res != FR_OK)
- break;
- if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
- buserr = 1;
- break;
- }
- z80_write_block(buffer, addr, br);
- z80_bus_cmd(Release);
- addr += br;
-
- bytes_read += br;
- if (cnt != br)
- break;
- }
- timer = get_timer(timer);
- printf_P(PSTR("%lu bytes read with %lu bytes/sec.\n"),
- bytes_read, timer ? (bytes_read * 1000 / timer) : 0);
- }
- }
- f_mount(NULL, argv[1], 0);
- }
-
- if (buserr)
- my_puts_P(PSTR("Bus timeout\n"));
- if (res)
- put_rc(res);
- if (buserr || res)
- return CMD_RET_FAILURE;
-
- return CMD_RET_SUCCESS;
-}