add basic file upload
This commit is contained in:
parent
d4b7d9630b
commit
fbc1b7d204
@ -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.
|
||||
|
||||
19
src/cli.c
19
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 <filename>\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* CLI interface functions */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -435,6 +451,9 @@ void cli_loop(void) {
|
||||
cmd_vmode();
|
||||
break;
|
||||
|
||||
case CMD_PUT:
|
||||
cmd_put();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<count;sec++) {
|
||||
errorcount = 0;
|
||||
while (errorcount < CONFIG_SD_AUTO_RETRIES) {
|
||||
writeled(1);
|
||||
if (cardtype[drv] & CARD_SDHC)
|
||||
res = sendCommand(drv, WRITE_BLOCK, sector+sec, 0);
|
||||
else
|
||||
res = sendCommand(drv, WRITE_BLOCK, (sector+sec)<<9, 0);
|
||||
|
||||
if (res != 0) {
|
||||
set_sd_led(0);
|
||||
writeled(0);
|
||||
disk_state = DISK_ERROR;
|
||||
return RES_ERROR;
|
||||
}
|
||||
@ -680,7 +682,7 @@ DRESULT sd_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count) {
|
||||
|
||||
// Wait for write finish
|
||||
if (!wait_for_response(0)) {
|
||||
set_sd_led(0);
|
||||
writeled(0);
|
||||
disk_state = DISK_ERROR;
|
||||
return RES_ERROR;
|
||||
}
|
||||
@ -694,7 +696,7 @@ DRESULT sd_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
writeled(0);
|
||||
return RES_OK;
|
||||
}
|
||||
DRESULT disk_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count) __attribute__ ((weak, alias("sd_write")));
|
||||
|
||||
14
src/spi.c
14
src/spi.c
@ -36,20 +36,6 @@
|
||||
#define SSP_RFF 3 // Receive FIFO full
|
||||
#define SSP_BSY 4 // Busy
|
||||
|
||||
// #define SSP_REGS LPC_SSP1
|
||||
// #define SSP_PCLKREG PCLKSEL0
|
||||
/* SSP0: PCLKSEL1
|
||||
SSP1: PCLKSEL0 */
|
||||
// #define SSP_PCLKBIT 20
|
||||
/* SSP0: 10
|
||||
SSP1: 20 */
|
||||
// #define SSP_DMAID_TX 2
|
||||
/* SSP0: 0
|
||||
SSP1: 2 */
|
||||
// #define SSP_DMAID_RX 3
|
||||
/* SSP0: 1
|
||||
SSP1: 3 */
|
||||
|
||||
typedef struct {
|
||||
LPC_SSP_TypeDef *SSP_REGS;
|
||||
LPC_GPDMACH_TypeDef *SSP_DMACH;
|
||||
|
||||
42
src/xmodem.c
Normal file
42
src/xmodem.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include <arm/NXP/LPC17xx/LPC17xx.h>
|
||||
#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);
|
||||
}
|
||||
8
src/xmodem.h
Normal file
8
src/xmodem.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef _XMODEM_H
|
||||
#define _XMODEM_H
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
void xmodem_rxfile(FIL* fil);
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user