From: Leo C Date: Thu, 21 May 2015 15:29:19 +0000 (+0200) Subject: f_sync only, when timout (currently 1s) after last write operation. X-Git-Tag: hexrel-6 X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/refs/tags/hexrel-6 f_sync only, when timout (currently 1s) after last write operation. --- diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 3273093..eb0d84f 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -18,6 +18,9 @@ extern command_ret_t do_env_save(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_loadf(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_loadcpm3(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_loadihex(cmd_tbl_t *, int, int, char * const []); +#if defined(CONFIG_CMD_LOADB) +extern command_ret_t do_load_serial_bin(cmd_tbl_t *, int, int, char * const []); +#endif extern command_ret_t do_go(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_restart(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_console(cmd_tbl_t *, int, int, char * const []); @@ -147,6 +150,27 @@ CMD_TBL_ITEM( "[[-]offset]\n" " - load Intel-Hex-Record file over serial line with offset 'offset'" ), + +#if defined(CONFIG_CMD_LOADB) +CMD_TBL_ITEM( + loadb, 1, 0, do_load_serial_bin, + "load binary file over serial line (kermit mode)", + " - load binary file over serial line" +), + +CMD_TBL_ITEM( + loadx, 1, 0, do_load_serial_bin, + "load binary file over serial line (xmodem mode)", + " - load binary file over serial line" +), + +CMD_TBL_ITEM( + loady, 1, 0, do_load_serial_bin, + "load binary file over serial line (ymodem mode)", + " - load binary file over serial line" +), +#endif /* CONFIG_CMD_LOADB */ + CMD_TBL_ITEM( go, 2, 0, do_go, "start application at address 'addr'", diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 9b4228a..bf49a6c 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -122,11 +122,64 @@ struct cpm_drive_s { uint8_t drv; uint8_t device; char *img_name; + bool dirty; FIL fd; }; static uint8_t disk_buffer[BLOCK_SIZE]; static struct cpm_drive_s drv_table[MAX_DRIVE]; +static int handle_cpm_drv_to; + +#define f_dirty(fp) ((fp)->fs->wflag != 0) + + +int cpm_drv_to(int state) +{ + static uint32_t ts; + + switch(state) { + case 0: + break; + + case 1: + ts = get_timer(0); + state = 2; + break; + + case 2: + if (get_timer(ts) > 1000) { + for (uint_fast8_t i=0; i < MAX_DRIVE; i++) { +// if (&drv_table[i].fd && f_dirty(&drv_table[i].fd)) { + if (drv_table[i].dirty) { + f_sync(&drv_table[i].fd); + drv_table[i].dirty = false; + debug_cpmsd("## %7lu f_sync: %c:\n", get_timer(0), i+'A'); + } + } + state = 0; + } + } + return state; +} + + +void msg_cpm_result(uint8_t subf, uint8_t rc, int res) +{ + uint8_t result_msg[3]; + + if (res) + rc |= 0x80; + + result_msg[0] = rc; + result_msg[1] = res; + result_msg[2] = res >> 8; + + if (rc) { + debug_cpmsd("###%7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); + } + + msg_xmit(2, subf, sizeof(result_msg), result_msg); +} /* db 2 ; disk command @@ -140,16 +193,13 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) { FRESULT res = 0; - uint8_t rc = 0; uint8_t drv; char *np; - uint8_t result_msg[3]; (void)subf; if (len != 5) { /* TODO: check adrv, rdrv */ - rc = 0x01; - goto out; + return msg_cpm_result(subf, 0x01, res); } debug_cpmsd("\n## %7lu login: %c:\n", get_timer(0), msg[0]+'A'); @@ -157,8 +207,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) drv = msg[0]; if ( drv>= MAX_DRIVE) { - rc = 0x02; - goto out; + return msg_cpm_result(subf, 0x02, res); } /* @@ -168,6 +217,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) if (drv_table[drv].img_name != NULL) { debug_cpmsd("## %7lu close: '%s'\n", get_timer(0), drv_table[drv].img_name); f_close(&drv_table[drv].fd); + drv_table[drv].dirty = false; free(drv_table[drv].img_name); drv_table[drv].img_name = NULL; } @@ -176,8 +226,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) disk_buffer[3] = msg[0] + '0'; if (((np = getenv((char*)disk_buffer)) == NULL) || ((drv_table[drv].img_name = strdup(np)) == NULL)) { - rc = 0x03; - goto out; + return msg_cpm_result(subf, 0x03, res); } @@ -187,21 +236,8 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) debug_cpmsd("## %7lu open: '%s', (env: '%s'), res: %d\n", get_timer(0), drv_table[drv].img_name, disk_buffer, res); -out: - - if (res) - rc |= 0x80; - - result_msg[0] = rc; - result_msg[1] = res; - result_msg[2] = res >> 8; - - if (rc) { - debug_cpmsd("## %7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); - }; - /* send result*/ - msg_xmit(2, subf, sizeof(result_msg), result_msg); + msg_cpm_result(subf, 0x00, res); } @@ -233,17 +269,14 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) FRESULT res = 0; uint8_t rc = 0; bool buserr = 0; - uint8_t result_msg[3]; if (len != 10) { /* TODO: check adrv, rdrv */ - rc = 0x01; - goto out; + return msg_cpm_result(subf, 0x01, res); } drv = msg[ADRV]; if ( drv>= MAX_DRIVE) { - rc = 0x02; - goto out; + return msg_cpm_result(subf, 0x02, res); } secs = msg[CNT]; @@ -314,27 +347,20 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) addr += BLOCK_SIZE; } - if (dowrite && !res) - res = f_sync(&drv_table[drv].fd); + if (dowrite && !res) { +// res = f_sync(&drv_table[drv].fd); + drv_table[drv].dirty = true; + bg_setstat(handle_cpm_drv_to, 1); + } + -out: if (buserr) { debug_cpmsd("Bus timeout\n"); rc = 0x03; } - if (res) - rc |= 0x80; - - result_msg[0] = rc; - result_msg[1] = res; - result_msg[2] = res >> 8; - - if (rc) { - debug_cpmsd("###%7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); - } /* send result*/ - msg_xmit(2, subf, sizeof(result_msg), result_msg); + msg_cpm_result(subf, rc, res); } @@ -492,6 +518,7 @@ void setup_z180_serv(void) { handle_msg_handling = bg_register(msg_handling, 0); + handle_cpm_drv_to = bg_register(cpm_drv_to, 0); } void restart_z180_serv(void) diff --git a/include/config.h b/include/config.h index 99e4e78..f8b9d73 100644 --- a/include/config.h +++ b/include/config.h @@ -33,6 +33,10 @@ #define CONFIG_CMD_DATE 1 + +//#define CONFIG_CMD_LOADB + + #define CONFIG_SYS_I2C_RTC_ADDR 0x50 #define CONFIG_SYS_I2C_BUFSIZE 64 #define CONFIG_SYS_I2C_CLOCK 100000L /* SCL clock frequency in Hz */