diff --git a/src/Makefile b/src/Makefile index f1c65dc..61a299f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -55,7 +55,7 @@ TARGET = $(OBJDIR)/sd2snes # List C source files here. (C dependencies are automatically generated.) -SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c sdcard.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c +SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c sdcard.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c xmodem.c # List Assembler source files here. diff --git a/src/cli.c b/src/cli.c index 8fce0e4..b5ef53d 100644 --- a/src/cli.c +++ b/src/cli.c @@ -44,6 +44,7 @@ #include "snes.h" #include "fpga.h" #include "cic.h" +#include "xmodem.h" #include "cli.h" @@ -341,6 +342,21 @@ static void cmd_vmode(void) { free(buf); #endif +void cmd_put(void) { + if(*curchar != 0) { + file_open((uint8_t*)curchar, FA_CREATE_ALWAYS | FA_WRITE); + if(file_res) { + printf("FAIL: error opening file %s\n", curchar); + } else { + printf("OK, start xmodem transfer now.\n"); + xmodem_rxfile(&file_handle); + } + file_close(); + } else { + printf("Usage: put \n"); + } +} + /* ------------------------------------------------------------------------- */ /* CLI interface functions */ /* ------------------------------------------------------------------------- */ @@ -435,6 +451,9 @@ void cli_loop(void) { cmd_vmode(); break; + case CMD_PUT: + cmd_put(); + break; } } } diff --git a/src/sdcard.c b/src/sdcard.c index f50242e..e360f46 100644 --- a/src/sdcard.c +++ b/src/sdcard.c @@ -65,6 +65,7 @@ #include "timer.h" #include "uart.h" #include "sdcard.h" +#include "led.h" // FIXME: Move, make configurable static void set_sd_led(uint8_t state) { @@ -641,13 +642,14 @@ DRESULT sd_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count) { for (sec=0;sec +#include "config.h" +#include "timer.h" +#include "uart.h" +#include "ff.h" +#include "xmodem.h" + +#define ASC_ACK (0x06) +#define ASC_NAK (0x15) +#define ASC_SOH (0x01) +#define ASC_EOT (0x04) + +void xmodem_rxfile(FIL* fil) { + uint8_t rxbuf[128], sum=0, sender_sum; + uint8_t blknum, blknum2; + uint8_t count; + uint32_t totalbytes = 0; + uint32_t totalwritten = 0; + UINT written; + FRESULT res; + uart_flush(); + do { + sleep_ms(10000); + uart_putc(ASC_NAK); + } while (uart_getc() != ASC_SOH); + do { + blknum=uart_getc(); + blknum2=uart_getc(); + for(count=0; count<128; count++) { + sum += rxbuf[count] = uart_getc(); + totalbytes++; + } + sender_sum = uart_getc(); + res=f_write(fil, rxbuf, 128, &written); + totalwritten += written; + uart_putc(ASC_ACK); + } while (uart_getc() != ASC_EOT); + uart_putc(ASC_ACK); + uart_flush(); + sleep_ms(1000); + printf("received %ld bytes, wrote %ld bytes. last res = %d\n", totalbytes, totalwritten, res); +} diff --git a/src/xmodem.h b/src/xmodem.h new file mode 100644 index 0000000..9a1c31f --- /dev/null +++ b/src/xmodem.h @@ -0,0 +1,8 @@ +#ifndef _XMODEM_H +#define _XMODEM_H + +#include "ff.h" + +void xmodem_rxfile(FIL* fil); + +#endif