From 4f881b028b8e5f6d41efc430185db4d41cb48caa Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 28 Nov 2014 11:24:23 +0100 Subject: LFN support --- avr/Tupfile | 9 ++++++--- avr/cmd_fat.c | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 11b5802..1c0f7ed 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -1,6 +1,9 @@ include_rules PROG = stamp-monitor + +FATFS = $(TOP)/fatfs/src/ff.c + SRC = main.c SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c @@ -8,7 +11,7 @@ SRC += cmd_sd.c cmd_fat.c SRC += env.c xmalloc.c date.c con-utils.c print-utils.c getopt-min.c SRC += timer.c serial.c i2c.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c -SRC += $(TOP)/fatfs/src/ff.c +SRC += $(FATFS) $(TOP)/fatfs/src/option/unicode.c SRC_Z = ../z180/hdrom.c @@ -59,9 +62,9 @@ CFLAGS += -fno-split-wide-types CFLAGS += -fshort-enums #CFLAGS += -fdiagnostics-color=always - #CFLAGS += -save-temps +CFLAGS_$(FATFS) = -fno-strict-aliasing CFLAGS += $(INCLUDES) @@ -72,7 +75,7 @@ LDFLAGS += -Wl,--gc-sections LDFLAGS += -Wl,--cref -!cc = |> ^ CC %f^ $(CC) $(CFLAGS) $(CPPFLAGS) -c %f -o %o |> %B.o +!cc = |> ^ CC %f^ $(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS_%f) -c %f -o %o |> %B.o !LINK = |> ^ LINK %o^ $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=%O.map %f $(LDLIBS) -o %o |> | %O.map !OBJCOPY= |> ^ OBJCOPY %o^ $(OBJCOPY) -Oihex %f %o |> !OBJDUMP= |> ^ OBJDUMP %o^ $(OBJDUMP) -h -S %f > %o |> %O.lss diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 9222c1b..1c46dd1 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -8,6 +8,7 @@ #include "z80-if.h" #include "print-utils.h" #include "timer.h" +#include "debug.h" DWORD get_fattime (void) @@ -53,7 +54,15 @@ void put_rc (FRESULT rc) /* Work register for fs command */ static DWORD AccSize; static WORD AccFiles, AccDirs; +#if _USE_LFN +char Lfname[_MAX_LFN+1]; +FILINFO Finfo = { + .lfname = Lfname, + .lfsize = sizeof Lfname + }; +#else FILINFO Finfo; +#endif static FRESULT scan_files ( @@ -66,6 +75,7 @@ FRESULT scan_files ( char *fn; res = f_opendir(&dirs, path); + if (res == FR_OK) { i = strlen(path); while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { @@ -100,7 +110,7 @@ FRESULT scan_files ( command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { FATFS FatFs, *fs; - DWORD p1, p2; + DWORD clusters; FRESULT res; char buffer[512]; @@ -108,7 +118,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg res = f_mount(&FatFs, argv[1], 0); if (!res) - res = f_getfree(argv[1], &p2, &fs); + res = f_getfree(argv[1], &clusters, &fs); if (res) { put_rc(res); return CMD_RET_FAILURE; @@ -130,7 +140,8 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg #if _USE_LABEL TCHAR label[12]; - res = f_getlabel(argv[1], label, &p1); + DWORD serial; + res = f_getlabel(argv[1], label, &serial); if (res) { put_rc(res); return CMD_RET_FAILURE; @@ -138,7 +149,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg printf_P(PSTR( "Volume name: %s\n" "Volume S/N: %04X-%04X\n"), - label, (WORD)((DWORD)p1 >> 16), (WORD)(p1 & 0xFFFF)); + label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF)); #endif my_puts_P(PSTR("\n...")); AccSize = AccFiles = AccDirs = 0; @@ -153,7 +164,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n" "%lu KB total disk space.\n%lu KB available.\n"), AccFiles, AccSize, AccDirs, - (fs->n_fatent - 2) * (fs->csize / 2), p2 * (fs->csize / 2) + (fs->n_fatent - 2) * (fs->csize / 2), clusters * (fs->csize / 2) ); res = f_mount(NULL, argv[1], 0); -- cgit v1.2.3 From b0e4f7e5bf9f344a9ef4642a3ce3441ada206941 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 29 Nov 2014 19:50:44 +0100 Subject: Improved command line quoting --- avr/cli.c | 108 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 35 deletions(-) (limited to 'avr') diff --git a/avr/cli.c b/avr/cli.c index b310f79..046859c 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -21,26 +21,75 @@ static int cli_parse_line(char *line, char *argv[]) { - static const FLASH char delim[] = {" \t"}; - - char *ptr; + uint_fast8_t state = 0; uint_fast8_t nargs = 0; + char *inp, *outp; + char c, quote; + + debug_parser("%s: \"%s\"\n", __func__, line); + + for (outp = inp = line, quote = '\0' ; + nargs < CONFIG_SYS_MAXARGS && (c = *inp) != '\0'; + inp++) { + + switch (state) { + case 0: + if (isblank(c)) + continue; + + argv[nargs++] = inp; /* begin of argument string */ + outp = inp; + state = 1; + /* fall thru */ + + case 1: + if (c == '\\') { + ++state; + continue; + } + if (c == '\"' || c == '\'') { + quote = c; + state = 3; + continue; + } + if (isblank(c)) { + c = '\0'; + state = 0; + } + break; + + case 3: + if (c == '\\' && quote == '\"') { + ++state; + continue; + } + if (c == quote) { + state = 1; + continue; + } + break; - debug_parser("parse_line: \"%s\"\n", line); + case 2: + case 4: + --state; + break; - ptr = strtok_P(line, delim); - while(nargs < CONFIG_SYS_MAXARGS && ptr != NULL) { - argv[nargs++] = ptr; - ptr = strtok_P(NULL, delim); + } + *outp++ = c; } - if (ptr != NULL) + if (*inp != '\0') printf_P(PSTR("** Too many args (max. %d) **\n"), CONFIG_SYS_MAXARGS); + *outp = '\0'; argv[nargs] = NULL; - debug_parser("parse_line: nargs=%d\n", nargs); - + debug_parser("%s: nargs=%d\n", __func__, nargs); +#if 0 + for (int i = 0; i < nargs; i++) + debug_parser("%s: arg %d: >%s<\n", __func__, i, argv[i]); +#endif return nargs; + } static @@ -61,7 +110,8 @@ char *process_macros(char *input, char *output) for(uint_fast8_t pass = 0; pass < 2; pass++) { - uint_fast8_t state = 0; /* 0 = waiting for '$' */ + uint_fast8_t state = 0; + /* 0 = waiting for '$' */ /* 1 = waiting for '{' */ /* 2 = waiting for '}' */ /* 3 = waiting for ''' */ @@ -75,22 +125,13 @@ char *process_macros(char *input, char *output) } inp = input; - prev = '\0'; /* previous character */ - debug_parser("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen(inp), - inp); + debug_parser("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", + strlen(inp), inp); + + for (prev = '\0'; (c = *inp++) != '\0'; prev = c) { - while ((c = *inp++) != '\0') { - if (state != 3) { - /* remove one level of escape characters */ - if ((c == '\\') && (prev != '\\')) { - if (*inp == '\0') - break; - prev = c; - c = *inp++; - } - } switch (state) { case 0: /* Waiting for (unescaped) $ */ @@ -98,19 +139,19 @@ char *process_macros(char *input, char *output) state = 3; break; } - if ((c == '$') && (prev != '\\')) + if ((c == '$') && (prev != '\\')) { state++; - else - append_char(pass, &outp, c); + continue; + } break; case 1: /* Waiting for { */ if (c == '{') { state++; varname = inp; + continue; } else { state = 0; append_char(pass, &outp, '$'); - append_char(pass, &outp, c); } break; case 2: /* Waiting for } */ @@ -126,15 +167,13 @@ char *process_macros(char *input, char *output) /* Look for another '$' */ state = 0; } - break; + continue; case 3: /* Waiting for ' */ - if ((c == '\'') && (prev != '\\')) + if (c == '\'') state = 0; - else - append_char(pass, &outp, c); break; } - prev = c; + append_char(pass, &outp, c); } append_char(pass, &outp, 0); @@ -350,4 +389,3 @@ command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } return CMD_RET_SUCCESS; } - -- cgit v1.2.3 From 4565be9a755c4de8ffdbc8b9a7b2d87c87f7a9e1 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Dec 2014 11:12:23 +0100 Subject: merge do_fat_read() and do_fat_write() to do_fat_rw() --- avr/cmd_fat.c | 216 ++++++++++++++++++++++++++++++++++++++++----------- avr/cmd_gpio.c | 2 + avr/command_tbl.c | 31 ++++++-- avr/debug.c | 11 +++ include/avr/ffconf.h | 2 +- 5 files changed, 210 insertions(+), 52 deletions(-) (limited to 'avr') diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 1c46dd1..0232f5d 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -6,13 +6,17 @@ #include "command.h" #include "ff.h" #include "z80-if.h" +#include "con-utils.h" #include "print-utils.h" #include "timer.h" #include "debug.h" +#define MAX_MEMORY (1ul << 20) + DWORD get_fattime (void) { + /* TODO: */ return 0; } @@ -109,65 +113,70 @@ FRESULT scan_files ( */ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - FATFS FatFs, *fs; - DWORD clusters; + FATFS *FatFs, *fs; + DWORD nfreeclst; FRESULT res; - char buffer[512]; + char *buffer; (void) cmdtp; (void) flag; (void) argc; - res = f_mount(&FatFs, argv[1], 0); - if (!res) - res = f_getfree(argv[1], &clusters, &fs); - if (res) { - put_rc(res); + FatFs = (FATFS *) malloc(sizeof (FATFS)); + buffer = (char *) malloc(512); + if (FatFs == NULL || buffer == NULL) { + printf_P(PSTR("fatstat: Out of Memory!\n")); + free(FatFs); + free(buffer); return CMD_RET_FAILURE; } - printf_P(PSTR( - "FAT type: %u\n" - "Bytes/Cluster: %lu\n" - "Number of FATs: %u\n" - "Root DIR entries: %u\n" - "Sectors/FAT: %lu\n" - "Number of clusters: %lu\n" - "FAT start (lba): %lu\n" - "DIR start (lba,cluster): %lu\n" - "Data start (lba): %lu\n"), - fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats, - fs->n_rootdir, fs->fsize, fs->n_fatent - 2, - fs->fatbase, fs->dirbase, fs->database); + res = f_mount(FatFs, argv[1], 0); + if (!res) { + res = f_getfree(argv[1], &nfreeclst, &fs); + if (!res) { + printf_P(PSTR( + "FAT type: %u\n" + "Bytes/Cluster: %lu\n" + "Number of FATs: %u\n" + "Root DIR entries: %u\n" + "Sectors/FAT: %lu\n" + "Number of clusters: %lu\n" + "FAT start (lba): %lu\n" + "DIR start (lba,cluster): %lu\n" + "Data start (lba): %lu\n"), + fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats, + fs->n_rootdir, fs->fsize, fs->n_fatent - 2, + fs->fatbase, fs->dirbase, fs->database); #if _USE_LABEL - TCHAR label[12]; - DWORD serial; - res = f_getlabel(argv[1], label, &serial); - if (res) { - put_rc(res); - return CMD_RET_FAILURE; - } - printf_P(PSTR( - "Volume name: %s\n" - "Volume S/N: %04X-%04X\n"), - label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF)); + TCHAR label[12]; + DWORD serial; + res = f_getlabel(argv[1], label, &serial); + if (!res) { + printf_P(PSTR( + "Volume name: %s\n" + "Volume S/N: %04X-%04X\n"), + label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF)); + } #endif - my_puts_P(PSTR("\n...")); - AccSize = AccFiles = AccDirs = 0; + if (!res) { + my_puts_P(PSTR("\n...")); + AccSize = AccFiles = AccDirs = 0; - strcpy(buffer, argv[1]); + strcpy(buffer, argv[1]); - res = scan_files(buffer); - if (res) { - put_rc(res); - return CMD_RET_FAILURE; + res = scan_files(buffer); + } + if (!res) { + printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n" + "%lu KB total disk space.\n%lu KB available.\n"), + AccFiles, AccSize, AccDirs, + (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2) + ); + } + } } - printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n" - "%lu KB total disk space.\n%lu KB available.\n"), - AccFiles, AccSize, AccDirs, - (fs->n_fatent - 2) * (fs->csize / 2), clusters * (fs->csize / 2) - ); - res = f_mount(NULL, argv[1], 0); + f_mount(NULL, argv[1], 0); if (res) { put_rc(res); return CMD_RET_FAILURE; @@ -396,3 +405,120 @@ command_ret_t do_fat_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const ar return CMD_RET_SUCCESS; } + +/* + * fatread/write - load binary file to/from a dos filesystem + * read [bytes [pos]] + * write + */ +command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + FATFS FatFs; + FIL File; + uint32_t addr; + unsigned long bytes; + unsigned long pos; + unsigned long bytes_rw; + + bool dowrite = (argv[0][3] == 'w'); + FRESULT res; + bool buserr = 0; + uint32_t timer; + uint8_t buffer[512]; + + (void) cmdtp; (void) flag; + + if (argc < (dowrite ? 4 : 3)) + return CMD_RET_USAGE; + + addr = strtoul(argv[2], 0, 16); + if (addr >= MAX_MEMORY) { + printf_P(PSTR("address too high: 0x%0lx\n"), addr); + return CMD_RET_FAILURE; + } + if (argc > 3) + bytes = strtoul(argv[3], 0, 16); + else + bytes = MAX_MEMORY; + if (argc > 4) + pos = strtoul(argv[4], 0, 16); + else + pos = 0; + + if (addr + bytes > MAX_MEMORY) + bytes = MAX_MEMORY - addr; + + res = f_mount(&FatFs, argv[1], 0); + if (!res) { + res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS + : FA_READ ); + + if (!res) { + res = f_lseek(&File, pos); + if (!res) { + bytes_rw = 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; + } + if (dowrite) { + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + buserr = 1; + break; + } + z80_read_block(buffer, addr, cnt); + z80_bus_cmd(Release); + res = f_write(&File, buffer, cnt, &br); + if (res != FR_OK) + break; + } else { + 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_rw += br; + if (cnt != br) { + if (dowrite) + printf_P(PSTR("Disk full?\n")); + break; + } + if (ctrlc()) { + printf_P(PSTR("Abort\n")); + break; + } + } + + FRESULT fr = f_close(&File); + if (!res) + res = fr; + timer = get_timer(timer); + printf_P(PSTR("%lu (0x%lx) bytes read/written with %lu bytes/sec.\n"), + bytes_rw, bytes_rw, timer ? (bytes_rw * 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; +} diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c index 84723d2..f448e36 100644 --- a/avr/cmd_gpio.c +++ b/avr/cmd_gpio.c @@ -29,6 +29,8 @@ static void pinnames_get(void) memset(pin_names, 0, sizeof(pin_names)); pin_names_width = 0; +/* TODO: enters endless loop on wron parameters */ + if ((lp = getenv(PSTR(ENV_PINALIAS))) != NULL) { pin_names[namestr] = strdup(lp); ptr = strtok_P(pin_names[namestr], delim1); diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 02d8ac8..e5c6567 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -24,8 +24,10 @@ extern command_ret_t do_gpio(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_sd(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_fat_stat(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_fat_ls(cmd_tbl_t *, int, int, char * const []); -extern command_ret_t do_fat_read(cmd_tbl_t *, int, int, char * const []); -extern command_ret_t do_fat_write(cmd_tbl_t *, int, int, char * const []); +//extern command_ret_t do_fat_read(cmd_tbl_t *, int, int, char * const []); +//extern command_ret_t do_fat_write(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_fat_rw(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_testarg(cmd_tbl_t *, int, int, char * const []); #ifdef CONFIG_SYS_LONGHELP const FLASH char sd_help_text[] = @@ -46,6 +48,22 @@ CMD_TBL_ITEM( ), #ifdef DEBUG +CMD_TBL_ITEM( + test, CONFIG_SYS_MAXARGS, 1, do_testarg, + "print arguments", + "" +), +CMD_TBL_ITEM( + tst1, CONFIG_SYS_MAXARGS, 1, do_testarg, + "print arguments", + "" +), +CMD_TBL_ITEM( + tst2, CONFIG_SYS_MAXARGS, 1, do_testarg, + "print arguments", + "" +), + CMD_TBL_ITEM( !mdr, 3, 1, do_dump_mem, "RAM dump", @@ -254,7 +272,7 @@ CMD_TBL_ITEM( "path" ), CMD_TBL_ITEM( - fatload, 5, 0, do_fat_read, + fatload, 5, 0, do_fat_rw, "load binary file from a dos filesystem", " [bytes [pos]]\n" " - Load binary file 'path/filename' on logical drive 'd'\n" @@ -265,11 +283,12 @@ CMD_TBL_ITEM( " the load stops on end of file." ), CMD_TBL_ITEM( - fatwrite, 4, 0, do_fat_write, + fatwrite, 4, 0, do_fat_rw, "write file into a dos filesystem", " \n" - " - write file 'filename' from the address 'addr' in RAM\n" - " to 'dev' on 'interface'" + " - Write file to 'path/filename' on logical drive 'd' from RAM\n" + " starting at address 'addr'. 'bytes' gives the size to load.\n" + " If 'bytes' is 0 or omitted, the load stops on end of file." ), CMD_TBL_ITEM( diff --git a/avr/debug.c b/avr/debug.c index 27b5329..796647b 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -112,6 +112,17 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ return CMD_RET_SUCCESS; } + +/*------------------------------------------------------------------------------*/ + +command_ret_t do_testarg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + my_puts_P(cmdtp->name); + printf_P(PSTR("\n%s\n"), argv[0]); + + return CMD_RET_SUCCESS; +} + /*------------------------------------------------------------------------------*/ diff --git a/include/avr/ffconf.h b/include/avr/ffconf.h index cccab26..fadbe3d 100644 --- a/include/avr/ffconf.h +++ b/include/avr/ffconf.h @@ -8,7 +8,7 @@ / Functions and Buffer Configurations /---------------------------------------------------------------------------*/ -#define _FS_TINY 0 +#define _FS_TINY 1 /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) / At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS / bytes. Instead of private sector buffer eliminated from the file object, -- cgit v1.2.3 From c93a1fd4f52e215c7fde5a207fff66015d0c4822 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Dec 2014 11:13:52 +0100 Subject: put weekdays[] in flash, workaround for wrong weekday display --- avr/cmd_date.c | 25 +++++++++++++++---------- avr/date.c | 3 +-- include/config.h | 7 +++---- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'avr') diff --git a/avr/cmd_date.c b/avr/cmd_date.c index ad0d3ac..337d720 100644 --- a/avr/cmd_date.c +++ b/avr/cmd_date.c @@ -15,8 +15,14 @@ #include -static const char * const weekdays[] = { - "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", +static const FLASH char * const FLASH weekdays[] = { + FSTR("Mon"), + FSTR("Tues"), + FSTR("Wednes"), + FSTR("Thurs"), + FSTR("Fri"), + FSTR("Satur"), + FSTR("Sun") }; int mk_date (const char *, struct rtc_time *); @@ -25,7 +31,7 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct rtc_time tm; int rcode = CMD_RET_SUCCESS; - + (void) cmdtp; (void) flag; switch (argc) { @@ -54,14 +60,14 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) my_puts_P(PSTR("## Get date failed\n")); break; } - /* TODO: put weekdays[] in flash */ - printf_P(PSTR("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n"), - tm.tm_year, tm.tm_mon, tm.tm_mday, - (tm.tm_wday<0 || tm.tm_wday>6) ? - "unknown " : weekdays[tm.tm_wday], + printf_P(PSTR("Date: %4d-%02d-%02d ("), + tm.tm_year, tm.tm_mon, tm.tm_mday); + my_puts_P( (tm.tm_wday<0 || tm.tm_wday>6) ? + PSTR("unknown ") : weekdays[tm.tm_wday]); + printf_P(PSTR("day) Time: %2d:%02d:%02d\n"), tm.tm_hour, tm.tm_min, tm.tm_sec); - break; + default: rcode = CMD_RET_USAGE; } @@ -179,4 +185,3 @@ int mk_date (const char *datestr, struct rtc_time *tmp) return (-1); } - diff --git a/avr/date.c b/avr/date.c index c85361f..5caee2f 100644 --- a/avr/date.c +++ b/avr/date.c @@ -23,7 +23,7 @@ #define days_in_month(a) (month_days[(a) - 1]) -static const FLASH int MonthOffset[] = { +static const FLASH int MonthOffset[] = { 0,31,59,90,120,151,181,212,243,273,304,334 }; @@ -136,4 +136,3 @@ mktime (unsigned int year, unsigned int mon, )*60 + min /* now have minutes */ )*60 + sec; /* finally seconds */ } - diff --git a/include/config.h b/include/config.h index 82dbf81..d0749b3 100644 --- a/include/config.h +++ b/include/config.h @@ -1,11 +1,11 @@ -#ifndef CONFIG_H +#ifndef CONFIG_H #define CONFIG_H /* Environment variables */ #define ENV_BAUDRATE "baudrate" #define ENV_BOOTDELAY "bootdelay" -#define ENV_BOOTCMD "bootcmd" +#define ENV_BOOTCMD "bootcmd" #define ENV_PINALIAS "pin_alias" #define CONFIG_ENV_SIZE 1600 @@ -13,7 +13,7 @@ #define CONFIG_ENVVAR_MAX 20 #define CONFIG_BAUDRATE 115200L -#define CONFIG_PWRON_DELAY 2000 /* ms to wait after power on */ +#define CONFIG_PWRON_DELAY 2000 /* ms to wait after power on */ #define CONFIG_BOOTDELAY 4 //#define CONFIG_ZERO_BOOTDELAY_CHECK 1 @@ -42,4 +42,3 @@ #define CONFIG_SYS_LONGHELP 1 #endif /* CONFIG_H */ - -- cgit v1.2.3 From e63b2f75607905fedf00cfd9fe644b26af715ffd Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Dec 2014 23:25:55 +0100 Subject: switch to avr-libc 1.8.1 time library --- avr/Tupfile | 6 +- avr/cmd_date.c | 141 ++++++------- avr/date.c | 138 ------------- avr/pcf8583.c | 21 +- include/rtc.h | 42 +--- include/time.h | 1 + time/Files.am | 77 +++++++ time/Makefile | 529 +++++++++++++++++++++++++++++++++++++++++++++++ time/Makefile.am | 35 ++++ time/Makefile.in | 529 +++++++++++++++++++++++++++++++++++++++++++++++ time/Rules.am | 30 +++ time/asc_store.c | 39 ++++ time/asctime.c | 44 ++++ time/asctime_r.c | 82 ++++++++ time/ctime.c | 47 +++++ time/ctime_r.c | 43 ++++ time/daylight_seconds.c | 72 +++++++ time/difftime.c | 41 ++++ time/dst_pointer.c | 34 +++ time/ephemera_common.h | 44 ++++ time/equation_of_time.c | 86 ++++++++ time/fatfs_time.c | 66 ++++++ time/geo_location.c | 32 +++ time/gm_sidereal.c | 60 ++++++ time/gmtime.c | 45 ++++ time/gmtime_r.c | 144 +++++++++++++ time/isLeap.c | 56 +++++ time/iso_week_date.c | 51 +++++ time/iso_week_date_r.c | 114 ++++++++++ time/isotime.c | 44 ++++ time/isotime_r.c | 70 +++++++ time/lm_sidereal.c | 47 +++++ time/localtime.c | 44 ++++ time/localtime_r.c | 60 ++++++ time/mk_gmtime.c | 113 ++++++++++ time/mktime.c | 61 ++++++ time/month_length.c | 48 +++++ time/moon_phase.c | 65 ++++++ time/print_lz.c | 45 ++++ time/set_dst.c | 44 ++++ time/set_position.c | 44 ++++ time/set_system_time.c | 55 +++++ time/set_zone.c | 41 ++++ time/solar_declination.c | 77 +++++++ time/solar_noon.c | 57 +++++ time/strftime.c | 322 +++++++++++++++++++++++++++++ time/sun_rise.c | 49 +++++ time/sun_set.c | 50 +++++ time/system_tick.S | 60 ++++++ time/system_time.c | 36 ++++ time/time.c | 58 ++++++ time/time.h | 523 ++++++++++++++++++++++++++++++++++++++++++++++ time/tm_store.c | 37 ++++ time/utc_offset.c | 35 ++++ time/week_of_month.c | 62 ++++++ time/week_of_year.c | 58 ++++++ 56 files changed, 4588 insertions(+), 266 deletions(-) delete mode 100644 avr/date.c create mode 120000 include/time.h create mode 100644 time/Files.am create mode 100644 time/Makefile create mode 100644 time/Makefile.am create mode 100644 time/Makefile.in create mode 100644 time/Rules.am create mode 100644 time/asc_store.c create mode 100644 time/asctime.c create mode 100644 time/asctime_r.c create mode 100644 time/ctime.c create mode 100644 time/ctime_r.c create mode 100644 time/daylight_seconds.c create mode 100644 time/difftime.c create mode 100644 time/dst_pointer.c create mode 100644 time/ephemera_common.h create mode 100644 time/equation_of_time.c create mode 100644 time/fatfs_time.c create mode 100644 time/geo_location.c create mode 100644 time/gm_sidereal.c create mode 100644 time/gmtime.c create mode 100644 time/gmtime_r.c create mode 100644 time/isLeap.c create mode 100644 time/iso_week_date.c create mode 100644 time/iso_week_date_r.c create mode 100644 time/isotime.c create mode 100644 time/isotime_r.c create mode 100644 time/lm_sidereal.c create mode 100644 time/localtime.c create mode 100644 time/localtime_r.c create mode 100644 time/mk_gmtime.c create mode 100644 time/mktime.c create mode 100644 time/month_length.c create mode 100644 time/moon_phase.c create mode 100644 time/print_lz.c create mode 100644 time/set_dst.c create mode 100644 time/set_position.c create mode 100644 time/set_system_time.c create mode 100644 time/set_zone.c create mode 100644 time/solar_declination.c create mode 100644 time/solar_noon.c create mode 100644 time/strftime.c create mode 100644 time/sun_rise.c create mode 100644 time/sun_set.c create mode 100644 time/system_tick.S create mode 100644 time/system_time.c create mode 100644 time/time.c create mode 100644 time/time.h create mode 100644 time/tm_store.c create mode 100644 time/utc_offset.c create mode 100644 time/week_of_month.c create mode 100644 time/week_of_year.c (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 1c0f7ed..6c40649 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -8,11 +8,15 @@ SRC = main.c SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c SRC += cmd_sd.c cmd_fat.c -SRC += env.c xmalloc.c date.c con-utils.c print-utils.c getopt-min.c +SRC += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c SRC += timer.c serial.c i2c.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c SRC += $(FATFS) $(TOP)/fatfs/src/option/unicode.c +#TODO: time lib +SRC += ../time/asctime_r.c ../time/gmtime_r.c ../time/mk_gmtime.c +SRC += ../time/print_lz.c ../time/isLeap.c + SRC_Z = ../z180/hdrom.c #TARGETS = $(PROG).elf diff --git a/avr/cmd_date.c b/avr/cmd_date.c index 337d720..3beebee 100644 --- a/avr/cmd_date.c +++ b/avr/cmd_date.c @@ -8,73 +8,13 @@ /* * RTC, Date & Time support: get and set date & time */ -#include +#include "common.h" #include -#include -#include -#include +#include "time.h" +#include "rtc.h" +#include "command.h" -static const FLASH char * const FLASH weekdays[] = { - FSTR("Mon"), - FSTR("Tues"), - FSTR("Wednes"), - FSTR("Thurs"), - FSTR("Fri"), - FSTR("Satur"), - FSTR("Sun") -}; - -int mk_date (const char *, struct rtc_time *); - -command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - struct rtc_time tm; - int rcode = CMD_RET_SUCCESS; - - (void) cmdtp; (void) flag; - - switch (argc) { - case 2: /* set date & time */ - /* initialize tm with current time */ - rcode = rtc_get (&tm); - - if(!rcode) { - /* insert new date & time */ - if (mk_date (argv[1], &tm) != 0) { - my_puts_P(PSTR("## Bad date format\n")); - break; - } - /* and write to RTC */ - rcode = rtc_set (&tm); - if(rcode) - my_puts_P(PSTR("## Set date failed\n")); - } else { - my_puts_P(PSTR("## Get date failed\n")); - } - /* FALL TROUGH */ - case 1: /* get date & time */ - rcode = rtc_get (&tm); - - if (rcode) { - my_puts_P(PSTR("## Get date failed\n")); - break; - } - printf_P(PSTR("Date: %4d-%02d-%02d ("), - tm.tm_year, tm.tm_mon, tm.tm_mday); - my_puts_P( (tm.tm_wday<0 || tm.tm_wday>6) ? - PSTR("unknown ") : weekdays[tm.tm_wday]); - printf_P(PSTR("day) Time: %2d:%02d:%02d\n"), - tm.tm_hour, tm.tm_min, tm.tm_sec); - break; - - default: - rcode = CMD_RET_USAGE; - } - - return rcode; -} - /* * simple conversion of two-digit string with error checking */ @@ -103,7 +43,7 @@ static int cnvrt2 (const char *str, int *valp) * Some basic checking for valid values is done, but this will not catch * all possible error conditions. */ -int mk_date (const char *datestr, struct rtc_time *tmp) +int mk_date (const char *datestr, struct tm *tmp) { int len, val; char *ptr; @@ -129,36 +69,36 @@ int mk_date (const char *datestr, struct rtc_time *tmp) tmp->tm_sec = 0; } - if (len == 12) { /* MMDDhhmmCCYY */ + if (len == 12) { /* MMDDhhmmCCYY */ int year, century; if (cnvrt2 (datestr+ 8, ¢ury) || cnvrt2 (datestr+10, &year) ) { return (-1); } - tmp->tm_year = 100 * century + year; + tmp->tm_year = 100 * century + year - 1900; } else if (len == 10) { /* MMDDhhmmYY */ int year, century; - century = tmp->tm_year / 100; + century = (tmp->tm_year + 1900) / 100; if (cnvrt2 (datestr+ 8, &year)) return (-1); - tmp->tm_year = 100 * century + year; + tmp->tm_year = 100 * century + year -1900; } switch (len) { - case 8: /* MMDDhhmm */ + case 8: /* MMDDhhmm */ /* fall thru */ - case 10: /* MMDDhhmmYY */ + case 10: /* MMDDhhmmYY */ /* fall thru */ - case 12: /* MMDDhhmmCCYY */ + case 12: /* MMDDhhmmCCYY */ if (cnvrt2 (datestr+0, &val) || val > 12) { break; } - tmp->tm_mon = val; + tmp->tm_mon = val - 1; if (cnvrt2 (datestr+2, &val) || - val > ((tmp->tm_mon==2) ? 29 : 31)) { + val > ((tmp->tm_mon==2-1) ? 29 : 31)) { break; } tmp->tm_mday = val; @@ -175,9 +115,6 @@ int mk_date (const char *datestr, struct rtc_time *tmp) } tmp->tm_min = val; - /* calculate day of week */ - GregorianDay (tmp); - return (0); default: break; @@ -185,3 +122,53 @@ int mk_date (const char *datestr, struct rtc_time *tmp) return (-1); } + +command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct tm t; + char buf[30]; + int rcode = CMD_RET_SUCCESS; + + (void) cmdtp; (void) flag; + + switch (argc) { + case 2: /* set date & time */ + /* initialize t with current time */ + rcode = rtc_get (&t); + + if(!rcode) { + /* insert new date & time */ + if (mk_date (argv[1], &t) != 0) { + my_puts_P(PSTR("## Bad date format\n")); + break; + } + + time_t time; + time = mk_gmtime(&t); + gmtime_r(&time, &t); + + /* and write to RTC */ + rcode = rtc_set (&t); + if(rcode) + my_puts_P(PSTR("## Set date failed\n")); + } else { + my_puts_P(PSTR("## Get date failed\n")); + } + /* FALL TROUGH */ + case 1: /* get date & time */ + rcode = rtc_get (&t); + + if (rcode) { + my_puts_P(PSTR("## Get date failed\n")); + break; + } + asctime_r(&t, buf); + printf_P(PSTR("%s\n"), buf); + break; + + default: + rcode = CMD_RET_USAGE; + } + + return rcode; +} diff --git a/avr/date.c b/avr/date.c deleted file mode 100644 index 5caee2f..0000000 --- a/avr/date.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * (C) Copyright 2001 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -/* - * Date & Time support for RTC - */ - -#include -#include -#include - - -#define FEBRUARY 2 -#define STARTOFTIME 1970 -#define SECDAY 86400L -#define SECYR (SECDAY * 365) -#define leapyear(year) ((year) % 4 == 0) -#define days_in_year(a) (leapyear(a) ? 366 : 365) -#define days_in_month(a) (month_days[(a) - 1]) - - -static const FLASH int MonthOffset[] = { - 0,31,59,90,120,151,181,212,243,273,304,334 -}; - -/* - * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) - */ -void GregorianDay(struct rtc_time * tm) -{ - int leapsToDate; - int lastYear; - int day; - - lastYear=tm->tm_year-1; - - /* - * Number of leap corrections to apply up to end of last year - */ - leapsToDate = lastYear/4 - lastYear/100 + lastYear/400; - - /* - * This year is a leap year if it is divisible by 4 except when it is - * divisible by 100 unless it is divisible by 400 - * - * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 will be - */ - if((tm->tm_year%4==0) && - ((tm->tm_year%100!=0) || (tm->tm_year%400==0)) && - (tm->tm_mon>2)) { - /* - * We are past Feb. 29 in a leap year - */ - day=1; - } else { - day=0; - } - - day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + tm->tm_mday; - - tm->tm_wday=day%7; -} - -void to_tm(unsigned long tim, struct rtc_time * tm) -{ - char month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; - register int i; - register long hms, day; - - day = tim / SECDAY; - hms = tim % SECDAY; - - /* Hours, minutes, seconds are easy */ - tm->tm_hour = hms / 3600; - tm->tm_min = (hms % 3600) / 60; - tm->tm_sec = (hms % 3600) % 60; - - /* Number of years in days */ - for (i = STARTOFTIME; day >= days_in_year(i); i++) { - day -= days_in_year(i); - } - tm->tm_year = i; - - /* Number of months in days left */ - if (leapyear(tm->tm_year)) { - days_in_month(FEBRUARY) = 29; - } - for (i = 1; day >= days_in_month(i); i++) { - day -= days_in_month(i); - } - days_in_month(FEBRUARY) = 28; - tm->tm_mon = i; - - /* Days are what is left over (+1) from all that. */ - tm->tm_mday = day + 1; - - /* - * Determine the day of week - */ - GregorianDay(tm); -} - -/* Converts Gregorian date to seconds since 1970-01-01 00:00:00. - * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 - * => year=1980, mon=12, day=31, hour=23, min=59, sec=59. - * - * [For the Julian calendar (which was used in Russia before 1917, - * Britain & colonies before 1752, anywhere else before 1582, - * and is still in use by some communities) leave out the - * -year/100+year/400 terms, and add 10.] - * - * This algorithm was first published by Gauss (I think). - * - * WARNING: this function will overflow on 2106-02-07 06:28:16 on - * machines were long is 32-bit! (However, as time_t is signed, we - * will already get problems at other places on 2038-01-19 03:14:08) - */ -unsigned long -mktime (unsigned int year, unsigned int mon, - unsigned int day, unsigned int hour, - unsigned int min, unsigned int sec) -{ - if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */ - mon += 12; /* Puts Feb last since it has leap day */ - year -= 1; - } - - return ((( - (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) + - year*365 - 719499 - )*24 + hour /* now have hours */ - )*60 + min /* now have minutes */ - )*60 + sec; /* finally seconds */ -} diff --git a/avr/pcf8583.c b/avr/pcf8583.c index af1331d..7e9d749 100644 --- a/avr/pcf8583.c +++ b/avr/pcf8583.c @@ -4,10 +4,11 @@ #include "common.h" #include -#include "debug.h" -#include "command.h" +#include "time.h" #include "rtc.h" #include "i2c.h" +#include "command.h" +#include "debug.h" #define DEBUG_RTC 0 @@ -34,17 +35,17 @@ static uint_fast8_t bcd2bin(uint8_t val) static uint8_t bin2bcd (uint_fast8_t val) { div_t d = div(val, 10); - + return (d.quot << 4) | d.rem; } -int rtc_get (struct rtc_time *tmp) +int rtc_get (struct tm *tmp) { int rel = 0; uint8_t rtcbuf[NR_OF_REGS]; - uint16_t year; - + int16_t year; + i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, rtcbuf, NR_OF_REGS); i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0x10, 1, (uint8_t *) &year, 2); @@ -56,12 +57,12 @@ int rtc_get (struct rtc_time *tmp) tmp->tm_min = bcd2bin (rtcbuf[REG_MIN] & 0x7F); tmp->tm_hour = bcd2bin (rtcbuf[REG_HOUR] & 0x3F); tmp->tm_mday = bcd2bin (rtcbuf[REG_YRDATE] & 0x3F); - tmp->tm_mon = bcd2bin (rtcbuf[REG_WDMON] & 0x1F); + tmp->tm_mon = bcd2bin (rtcbuf[REG_WDMON] & 0x1F) - 1; while (year%4 < (rtcbuf[REG_YRDATE]>>6)) { year++; /* TODO: update RTC ram */ } - tmp->tm_year = year; + tmp->tm_year = year; tmp->tm_wday = rtcbuf[REG_WDMON] >> 5; tmp->tm_yday = 0; tmp->tm_isdst= 0; @@ -74,7 +75,7 @@ int rtc_get (struct rtc_time *tmp) return rel; } -int rtc_set (struct rtc_time *tmp) +int rtc_set (struct tm *tmp) { uint8_t rtcbuf[NR_OF_REGS]; @@ -84,7 +85,7 @@ int rtc_set (struct rtc_time *tmp) rtcbuf[REG_CS] = 0x84; rtcbuf[REG_CSEC] = 0x00; - rtcbuf[REG_WDMON ] = bin2bcd(tmp->tm_mon) | ((tmp->tm_wday) << 5); + rtcbuf[REG_WDMON ] = (bin2bcd(tmp->tm_mon) + 1) | ((tmp->tm_wday) << 5); rtcbuf[REG_YRDATE] = ((tmp->tm_year % 4) << 6) | bin2bcd(tmp->tm_mday); rtcbuf[REG_HOUR ] = bin2bcd(tmp->tm_hour); rtcbuf[REG_MIN ] = bin2bcd(tmp->tm_min); diff --git a/include/rtc.h b/include/rtc.h index 51ee424..6946660 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -1,48 +1,10 @@ -/* - * (C) Copyright 2001 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - /* * Generic RTC interface. */ #ifndef _RTC_H_ #define _RTC_H_ - -/* - * The struct used to pass data from the generic interface code to - * the hardware dependend low-level code ande vice versa. Identical - * to struct rtc_time used by the Linux kernel. - * - * Note that there are small but significant differences to the - * common "struct time": - * - * struct time: struct rtc_time: - * tm_mon 0 ... 11 1 ... 12 - * tm_year years since 1900 years since 0 - */ - -struct rtc_time { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; -}; - -int rtc_get (struct rtc_time *); -int rtc_set (struct rtc_time *); - -void GregorianDay (struct rtc_time *); -void to_tm (unsigned long, struct rtc_time *); -unsigned long mktime (unsigned int, unsigned int, unsigned int, - unsigned int, unsigned int, unsigned int); +int rtc_get (struct tm *); +int rtc_set (struct tm *); #endif /* _RTC_H_ */ diff --git a/include/time.h b/include/time.h new file mode 120000 index 0000000..b9ae22c --- /dev/null +++ b/include/time.h @@ -0,0 +1 @@ +../time/time.h \ No newline at end of file diff --git a/time/Files.am b/time/Files.am new file mode 100644 index 0000000..26bfc62 --- /dev/null +++ b/time/Files.am @@ -0,0 +1,77 @@ + # (C)2012 Michael Duane Rice All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are + # met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions + # and the following disclaimer in the documentation and/or other materials + # provided with the distribution. Neither the name of the copyright holders + # nor the names of contributors may be used to endorse or promote products + # derived from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + # POSSIBILITY OF SUCH DAMAGE. + + # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $ + +time_a_c_sources = \ + asc_store.c \ + asctime.c \ + asctime_r.c \ + ctime.c \ + ctime_r.c \ + daylight_seconds.c \ + difftime.c \ + dst_pointer.c \ + equation_of_time.c \ + fatfs_time.c \ + geo_location.c \ + gm_sidereal.c \ + gmtime.c \ + gmtime_r.c \ + isLeap.c \ + isotime.c \ + iso_week_date.c \ + iso_week_date_r.c \ + isotime_r.c \ + lm_sidereal.c \ + localtime.c \ + localtime_r.c \ + mk_gmtime.c \ + mktime.c \ + month_length.c \ + moon_phase.c \ + print_lz.c \ + set_dst.c \ + set_position.c \ + set_system_time.c \ + set_zone.c \ + solar_declination.c \ + solar_noon.c \ + strftime.c \ + sun_rise.c \ + sun_set.c \ + system_time.c \ + time.c \ + tm_store.c \ + utc_offset.c \ + week_of_month.c \ + week_of_year.c + +time_a_asm_sources = \ + system_tick.S + +time_a_extra_dist = \ + ephemera_common.h diff --git a/time/Makefile b/time/Makefile new file mode 100644 index 0000000..ea8d363 --- /dev/null +++ b/time/Makefile @@ -0,0 +1,529 @@ +# Makefile.in generated by automake 1.14 from Makefile.am. +# libc/time/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2013 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + +# ©2012 Michael Duane Rice All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. Redistributions in binary +# form must reproduce the above copyright notice, this list of conditions +# and the following disclaimer in the documentation and/or other materials +# provided with the distribution. Neither the name of the copyright holders +# nor the names of contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# $Id: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $ + +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/avr-libc +pkgincludedir = $(includedir)/avr-libc +pkglibdir = $(libdir)/avr-libc +pkglibexecdir = $(libexecdir)/avr-libc +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = x86_64-unknown-linux-gnu +host_triplet = avr-unknown-none +DIST_COMMON = $(top_srcdir)/libc/time/Files.am $(srcdir)/Makefile.in \ + $(srcdir)/Makefile.am +subdir = libc/time +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing aclocal-1.14 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AR = avr-ar +AS = avr-as +ASDEBUG = +AUTOCONF = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing autoconf +AUTOHEADER = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing autoheader +AUTOMAKE = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing automake-1.14 +AVR_LIBC_MAJOR = 1 +AVR_LIBC_MINOR = 8 +AVR_LIBC_RELDATE = 20140811 +AVR_LIBC_REVISION = 1 +AVR_LIBC_USER_MANUAL = avr-libc-user-manual-1.8.1 +AVR_LIBC_VERSION = 1.8.1 +AVR_LIBC_VERSION_NUMERIC = 10801 +AWK = gawk +CC = avr-gcc +CCAS = avr-gcc +CCASDEPMODE = depmode=gcc3 +CCASFLAGS = +CCDEPMODE = depmode=gcc3 +CDEBUG = +CFLAGS = +CPPFLAGS = +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +DOCSDIR = +DOC_INST_DIR = ${DESTDIR}${datadir}/doc/avr-libc-$(VERSION) +ECHO_C = +ECHO_N = -n +ECHO_T = +EXEEXT = +FNO_JUMP_TABLES = -fno-jump-tables +HAS_DELAY_CYCLES = 1 +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_DOX_HTML = install-dox-html +INSTALL_DOX_MAN = install-dox-man +INSTALL_DOX_PDF = install-dox-pdf +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +LDFLAGS = +LIBOBJS = +LIBS = +LN_S = ln -s +LTLIBOBJS = +MAKEINFO = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/missing makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = avr-libc +PACKAGE_BUGREPORT = avr-libc-dev@nongnu.org +PACKAGE_NAME = avr-libc +PACKAGE_STRING = avr-libc 1.8.1 +PACKAGE_TARNAME = avr-libc +PACKAGE_URL = +PACKAGE_VERSION = 1.8.1 +PATH_SEPARATOR = : +PNGTOPNM = pngtopnm +PNMTOPNG = pnmtopng +RANLIB = avr-ranlib +SET_MAKE = +SHELL = /bin/bash +STRIP = avr-strip +TARGET_DOX_HTML = dox-html +TARGET_DOX_PDF = dox-pdf +VERSION = 1.8.1 +abs_builddir = /home/leo/src/avr/avr-libc-1.8.1/libc/time +abs_srcdir = /home/leo/src/avr/avr-libc-1.8.1/libc/time +abs_top_builddir = /home/leo/src/avr/avr-libc-1.8.1 +abs_top_srcdir = /home/leo/src/avr/avr-libc-1.8.1 +ac_ct_CC = +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build = x86_64-unknown-linux-gnu +build_alias = x86_64-unknown-linux-gnu +build_cpu = x86_64 +build_os = linux-gnu +build_vendor = unknown +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host = avr-unknown-none +host_alias = avr +host_cpu = avr +host_os = none +host_vendor = unknown +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/leo/src/avr/avr-libc-1.8.1/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../../ +top_builddir = ../.. +top_srcdir = ../.. +time_a_c_sources = \ + asc_store.c \ + asctime.c \ + asctime_r.c \ + ctime.c \ + ctime_r.c \ + daylight_seconds.c \ + difftime.c \ + dst_pointer.c \ + equation_of_time.c \ + fatfs_time.c \ + geo_location.c \ + gm_sidereal.c \ + gmtime.c \ + gmtime_r.c \ + isLeap.c \ + isotime.c \ + iso_week_date.c \ + iso_week_date_r.c \ + isotime_r.c \ + lm_sidereal.c \ + localtime.c \ + localtime_r.c \ + mk_gmtime.c \ + mktime.c \ + month_length.c \ + moon_phase.c \ + print_lz.c \ + set_dst.c \ + set_position.c \ + set_system_time.c \ + set_zone.c \ + solar_declination.c \ + solar_noon.c \ + strftime.c \ + sun_rise.c \ + sun_set.c \ + system_time.c \ + time.c \ + tm_store.c \ + utc_offset.c \ + week_of_month.c \ + week_of_year.c + +time_a_asm_sources = \ + system_tick.S + +time_a_extra_dist = \ + ephemera_common.h + +EXTRA_DIST = \ + $(time_a_c_sources) \ + $(time_a_asm_sources) \ + $(time_a_extra_dist) + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/libc/time/Files.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libc/time/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign libc/time/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; +$(top_srcdir)/libc/time/Files.am: + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +tags TAGS: + +ctags CTAGS: + +cscope cscopelist: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic cscopelist-am \ + ctags-am distclean distclean-generic distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ + pdf-am ps ps-am tags-am uninstall uninstall-am + + # (C)2012 Michael Duane Rice All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are + # met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions + # and the following disclaimer in the documentation and/or other materials + # provided with the distribution. Neither the name of the copyright holders + # nor the names of contributors may be used to endorse or promote products + # derived from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + # POSSIBILITY OF SUCH DAMAGE. + + # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $ + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/time/Makefile.am b/time/Makefile.am new file mode 100644 index 0000000..c8a121f --- /dev/null +++ b/time/Makefile.am @@ -0,0 +1,35 @@ +# ©2012 Michael Duane Rice All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. Redistributions in binary +# form must reproduce the above copyright notice, this list of conditions +# and the following disclaimer in the documentation and/or other materials +# provided with the distribution. Neither the name of the copyright holders +# nor the names of contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# $Id: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $ + +include $(top_srcdir)/libc/time/Files.am + +EXTRA_DIST = \ + $(time_a_c_sources) \ + $(time_a_asm_sources) \ + $(time_a_extra_dist) diff --git a/time/Makefile.in b/time/Makefile.in new file mode 100644 index 0000000..868aa89 --- /dev/null +++ b/time/Makefile.in @@ -0,0 +1,529 @@ +# Makefile.in generated by automake 1.14 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# ©2012 Michael Duane Rice All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. Redistributions in binary +# form must reproduce the above copyright notice, this list of conditions +# and the following disclaimer in the documentation and/or other materials +# provided with the distribution. Neither the name of the copyright holders +# nor the names of contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# $Id: Makefile.am 2379 2013-04-30 16:42:26Z joerg_wunsch $ +VPATH = @srcdir@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +DIST_COMMON = $(top_srcdir)/libc/time/Files.am $(srcdir)/Makefile.in \ + $(srcdir)/Makefile.am +subdir = libc/time +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AS = @AS@ +ASDEBUG = @ASDEBUG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AVR_LIBC_MAJOR = @AVR_LIBC_MAJOR@ +AVR_LIBC_MINOR = @AVR_LIBC_MINOR@ +AVR_LIBC_RELDATE = @AVR_LIBC_RELDATE@ +AVR_LIBC_REVISION = @AVR_LIBC_REVISION@ +AVR_LIBC_USER_MANUAL = @AVR_LIBC_USER_MANUAL@ +AVR_LIBC_VERSION = @AVR_LIBC_VERSION@ +AVR_LIBC_VERSION_NUMERIC = @AVR_LIBC_VERSION_NUMERIC@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASDEPMODE = @CCASDEPMODE@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CDEBUG = @CDEBUG@ +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DOCSDIR = @DOCSDIR@ +DOC_INST_DIR = @DOC_INST_DIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EXEEXT = @EXEEXT@ +FNO_JUMP_TABLES = @FNO_JUMP_TABLES@ +HAS_DELAY_CYCLES = @HAS_DELAY_CYCLES@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_DOX_HTML = @INSTALL_DOX_HTML@ +INSTALL_DOX_MAN = @INSTALL_DOX_MAN@ +INSTALL_DOX_PDF = @INSTALL_DOX_PDF@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PNGTOPNM = @PNGTOPNM@ +PNMTOPNG = @PNMTOPNG@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TARGET_DOX_HTML = @TARGET_DOX_HTML@ +TARGET_DOX_PDF = @TARGET_DOX_PDF@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +time_a_c_sources = \ + asc_store.c \ + asctime.c \ + asctime_r.c \ + ctime.c \ + ctime_r.c \ + daylight_seconds.c \ + difftime.c \ + dst_pointer.c \ + equation_of_time.c \ + fatfs_time.c \ + geo_location.c \ + gm_sidereal.c \ + gmtime.c \ + gmtime_r.c \ + isLeap.c \ + isotime.c \ + iso_week_date.c \ + iso_week_date_r.c \ + isotime_r.c \ + lm_sidereal.c \ + localtime.c \ + localtime_r.c \ + mk_gmtime.c \ + mktime.c \ + month_length.c \ + moon_phase.c \ + print_lz.c \ + set_dst.c \ + set_position.c \ + set_system_time.c \ + set_zone.c \ + solar_declination.c \ + solar_noon.c \ + strftime.c \ + sun_rise.c \ + sun_set.c \ + system_time.c \ + time.c \ + tm_store.c \ + utc_offset.c \ + week_of_month.c \ + week_of_year.c + +time_a_asm_sources = \ + system_tick.S + +time_a_extra_dist = \ + ephemera_common.h + +EXTRA_DIST = \ + $(time_a_c_sources) \ + $(time_a_asm_sources) \ + $(time_a_extra_dist) + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/libc/time/Files.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libc/time/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign libc/time/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; +$(top_srcdir)/libc/time/Files.am: + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +tags TAGS: + +ctags CTAGS: + +cscope cscopelist: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic cscopelist-am \ + ctags-am distclean distclean-generic distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ + pdf-am ps ps-am tags-am uninstall uninstall-am + + # (C)2012 Michael Duane Rice All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are + # met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions + # and the following disclaimer in the documentation and/or other materials + # provided with the distribution. Neither the name of the copyright holders + # nor the names of contributors may be used to endorse or promote products + # derived from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + # POSSIBILITY OF SUCH DAMAGE. + + # $Id: Files.am 2391 2013-05-03 20:53:06Z swfltek $ + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/time/Rules.am b/time/Rules.am new file mode 100644 index 0000000..a2c0929 --- /dev/null +++ b/time/Rules.am @@ -0,0 +1,30 @@ +# ©2012 Michael Duane Rice All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. Redistributions in binary +# form must reproduce the above copyright notice, this list of conditions +# and the following disclaimer in the documentation and/or other materials +# provided with the distribution. Neither the name of the copyright holders +# nor the names of contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# $Id: Rules.am 2321 2013-04-02 00:12:48Z swfltek $ + +include $(top_srcdir)/libc/time/Files.am diff --git a/time/asc_store.c b/time/asc_store.c new file mode 100644 index 0000000..1839ec6 --- /dev/null +++ b/time/asc_store.c @@ -0,0 +1,39 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: asc_store.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */ + +/* + Private allocation, shared between asctime() and isotime() +*/ + +#include + +char __store[26]; + +char *__asc_store = __store; diff --git a/time/asctime.c b/time/asctime.c new file mode 100644 index 0000000..38c6ea9 --- /dev/null +++ b/time/asctime.c @@ -0,0 +1,44 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: asctime.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Standard asctime(), we simply punt to the re-entrant version. +*/ + +#include + +extern char *__asc_store; + +char * +asctime(const struct tm * timeptr) +{ + asctime_r(timeptr, __asc_store); + return __asc_store; +} diff --git a/time/asctime_r.c b/time/asctime_r.c new file mode 100644 index 0000000..f85336d --- /dev/null +++ b/time/asctime_r.c @@ -0,0 +1,82 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: asctime_r.c 2357 2013-04-21 16:25:30Z swfltek $ */ + +/* + Re-entrant version of asctime(). + +*/ +#include +#include + +#ifdef __MEMX +const __memx char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; +const __memx char ascdays[] = "SunMonTueWedThuFriSat"; +#else +const char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; +const char ascdays[] = "SunMonTueWedThuFriSat"; +#endif + +extern void __print_lz(int , char *, char ); + +void +asctime_r(const struct tm * timeptr, char *buffer) +{ + unsigned char i, m, d; + div_t result; + + d = timeptr->tm_wday * 3; + m = timeptr->tm_mon * 3; + for (i = 0; i < 3; i++) { + buffer[i] = ascdays[d++]; + buffer[i+4] = ascmonths[m++]; + } + buffer[3]=buffer[7]=' '; + buffer += 8; + + __print_lz(timeptr->tm_mday,buffer,' '); + buffer += 3; + + __print_lz(timeptr->tm_hour,buffer,':'); + buffer += 3; + + __print_lz(timeptr->tm_min,buffer,':'); + buffer += 3; + + __print_lz(timeptr->tm_sec,buffer,' '); + buffer += 3; + + result = div(timeptr->tm_year + 1900 , 100); + + __print_lz(result.quot,buffer,' '); + buffer += 2; + + __print_lz(result.rem,buffer,0); + +} diff --git a/time/ctime.c b/time/ctime.c new file mode 100644 index 0000000..f17b873 --- /dev/null +++ b/time/ctime.c @@ -0,0 +1,47 @@ +/* + * ©2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: ctime.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Standard ctime(). We have to break down the time stamp, print it into our + private buffer, and return the buffer. +*/ +#include + +extern char *__asc_store; + +char * +ctime(const time_t * timeptr) +{ + struct tm calendar; + + localtime_r(timeptr, &calendar); + asctime_r(&calendar, __asc_store); + return __asc_store; +} diff --git a/time/ctime_r.c b/time/ctime_r.c new file mode 100644 index 0000000..4bb3633 --- /dev/null +++ b/time/ctime_r.c @@ -0,0 +1,43 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: ctime_r.c 2315 2013-03-29 21:24:31Z joerg_wunsch $ */ + +/* + Re entrant version of ctime() +*/ +#include + +void +ctime_r(const time_t * timeptr, char *buffer) +{ + struct tm calendar; + + localtime_r(timeptr, &calendar); + asctime_r(&calendar, buffer); +} diff --git a/time/daylight_seconds.c b/time/daylight_seconds.c new file mode 100644 index 0000000..97df585 --- /dev/null +++ b/time/daylight_seconds.c @@ -0,0 +1,72 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: daylight_seconds.c 2369 2013-04-28 14:19:35Z swfltek $ */ + +/* + Determine the amount of time the sun is above the horizon. At high latitudes, around the + solstices, this can be zero or greater than ONE_DAY. + +*/ + +#include +#include + +extern long __latitude; + +long +daylight_seconds(const time_t * timer) +{ + double l, d; + long n; + + /* convert latitude to radians */ + l = __latitude / 206264.806; + + d = -solar_declination(timer); + + /* partial 'Sunrise Equation' */ + d = tan(l) * tan(d); + + /* magnitude of d may exceed 1.0 at near solstices */ + if (d > 1.0) + d = 1.0; + + if (d < -1.0) + d = -1.0; + + /* derive hour angle */ + d = acos(d); + + /* but for atmospheric refraction, this would be d /= M_PI */ + d /= 3.112505; + + n = ONE_DAY * d; + + return n; +} diff --git a/time/difftime.c b/time/difftime.c new file mode 100644 index 0000000..95b24e9 --- /dev/null +++ b/time/difftime.c @@ -0,0 +1,41 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: difftime.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + The C90 standard specifies this returns a 'double. Since we do not have a true double, + we return a work alike type. +*/ +#include + +int32_t +difftime(time_t t1, time_t t2) +{ + return t1 - t2; +} diff --git a/time/dst_pointer.c b/time/dst_pointer.c new file mode 100644 index 0000000..5eda185 --- /dev/null +++ b/time/dst_pointer.c @@ -0,0 +1,34 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: dst_pointer.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */ + +#include +#include + +int (*__dst_ptr) (const time_t *, int32_t *); diff --git a/time/ephemera_common.h b/time/ephemera_common.h new file mode 100644 index 0000000..9583f89 --- /dev/null +++ b/time/ephemera_common.h @@ -0,0 +1,44 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: ephemera_common.h 2345 2013-04-11 23:58:48Z swfltek $ */ + +#ifndef EPHEMERA_PRIVATE_H +#define EPHEMERA_PRIVATE_H + +#define TROP_YEAR 31556925 +#define ANOM_YEAR 31558433 +#define INCLINATION 0.409105176667471 /* Earths axial tilt at the epoch */ +#define PERIHELION 31316400 /* perihelion of 1999, 03 jan 13:00 UTC */ +#define SOLSTICE 836160 /* winter solstice of 1999, 22 Dec 07:44 UTC */ +#define TWO_PI 6.283185307179586 +#define TROP_CYCLE 5022440.6025 +#define ANOM_CYCLE 5022680.6082 +#define DELTA_V 0.03342044 /* 2x orbital eccentricity */ + +#endif diff --git a/time/equation_of_time.c b/time/equation_of_time.c new file mode 100644 index 0000000..a527c83 --- /dev/null +++ b/time/equation_of_time.c @@ -0,0 +1,86 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: equation_of_time.c 2369 2013-04-28 14:19:35Z swfltek $ */ + +/* + The so called Equation of Time. + + The eccentricity of Earths orbit contributes about 7.7 minutes of variation to the result. It + has a period of 1 anomalous year, with zeroes at perihelion and aphelion. + + The tilt of Earths rotational axis (obliquity) contributes about 9.9 minutes of variation. It + has a period of 1/2 tropical year, with zeroes at solstices and equinoxes. The time of Earths + arrival at these events is influenced by the eccentricity, which causes it to progress along its + orbital path faster as it approaches perihelion, imposing a 'modulation' on the tropical phase. + + The algorithm employed computes the orbital position with respect to perihelion, deriving + from that a 'velocity correction factor'. The orbital position with respect to the winter solstice + is then computed, as modulated by that factor. The individual contributions of the obliquity and the + eccentricity components are then summed, and returned as an integer value in seconds. + +*/ + +#include +#include +#include "ephemera_common.h" + +int +equation_of_time(const time_t * timer) +{ + int32_t s, p; + double pf, sf, dV; + + /* compute orbital position relative to perihelion */ + p = *timer % ANOM_YEAR; + p += PERIHELION; + pf = p; + pf /= ANOM_CYCLE; + pf = sin(pf); + + /* Derive a velocity correction factor from the perihelion angle */ + dV = pf * DELTA_V; + + /* compute approximate position relative to solstice */ + s = *timer % TROP_YEAR; + s += SOLSTICE; + s *= 2; + sf = s; + sf /= TROP_CYCLE; + + /* modulate to derive actual position */ + sf += dV; + sf = sin(sf); + + /* compute contributions */ + sf *= 592.2; + pf *= 459.6; + s = pf + sf; + return -s; + +} diff --git a/time/fatfs_time.c b/time/fatfs_time.c new file mode 100644 index 0000000..9ed49a5 --- /dev/null +++ b/time/fatfs_time.c @@ -0,0 +1,66 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: fatfs_time.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + Return a value suitable for use as a file system time stamp. +*/ + +#include + +uint32_t +fat_time(const struct tm * timeptr) +{ + uint32_t ret; + uint32_t n; + + n = timeptr->tm_year - 80; + n <<= 25; + ret = n; + + n = timeptr->tm_mon + 1; + n <<= 21; + ret |= n; + + n = timeptr->tm_mday; + n <<= 16; + ret |= n; + + n = timeptr->tm_hour; + n <<= 11; + ret |= n; + + n = timeptr->tm_min; + n <<= 5; + ret |= n; + + ret |= (timeptr->tm_sec / 2); + + return ret; +} diff --git a/time/geo_location.c b/time/geo_location.c new file mode 100644 index 0000000..84bd7a8 --- /dev/null +++ b/time/geo_location.c @@ -0,0 +1,32 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: geo_location.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */ + +long __latitude; +long __longitude; diff --git a/time/gm_sidereal.c b/time/gm_sidereal.c new file mode 100644 index 0000000..b0984aa --- /dev/null +++ b/time/gm_sidereal.c @@ -0,0 +1,60 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: gm_sidereal.c 2369 2013-04-28 14:19:35Z swfltek $ */ + +/* + Greenwich Mean Sidereal Time. A sidereal second is somewhat shorter than a standard second, + about 1.002737909350795 sidereal seconds per standard second. + + We resort to fixed point math due to the insufficient resolution of a 'double', using... + + timestamp * ( 1.002737909350795 << 31 ) + --------------------------------------- + Te + 1 << 31 + + Where Te is the sidereal time at the epoch. + +*/ + +#include +#include + +unsigned long +gm_sidereal(const time_t * timer) +{ + uint64_t tmp; + + tmp = *timer; + tmp *= 0x8059B740; + tmp /= 0x80000000; + tmp += (uint64_t) 23991; + + tmp %= ONE_DAY; + return tmp; +} diff --git a/time/gmtime.c b/time/gmtime.c new file mode 100644 index 0000000..f3d0b2e --- /dev/null +++ b/time/gmtime.c @@ -0,0 +1,45 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: gmtime.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Standard gmtime(). We convert binary time into calendar time in our private struct tm object, + returning that object. +*/ + +#include + +extern struct tm __tm_store; + +struct tm * +gmtime(const time_t * timeptr) +{ + gmtime_r(timeptr, &__tm_store); + return &__tm_store; +} diff --git a/time/gmtime_r.c b/time/gmtime_r.c new file mode 100644 index 0000000..22658ea --- /dev/null +++ b/time/gmtime_r.c @@ -0,0 +1,144 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: gmtime_r.c 2369 2013-04-28 14:19:35Z swfltek $ */ + +/* Re entrant version of gmtime(). */ + +#include +#include +#include + +void +gmtime_r(const time_t * timer, struct tm * timeptr) +{ + int32_t fract; + ldiv_t lresult; + div_t result; + uint16_t days, n, leapyear, years; + + /* break down timer into whole and fractional parts of 1 day */ + days = *timer / 86400UL; + fract = *timer % 86400UL; + + /* + Extract hour, minute, and second from the fractional day + */ + lresult = ldiv(fract, 60L); + timeptr->tm_sec = lresult.rem; + result = div(lresult.quot, 60); + timeptr->tm_min = result.rem; + timeptr->tm_hour = result.quot; + + /* Determine day of week ( the epoch was a Saturday ) */ + n = days + SATURDAY; + n %= 7; + timeptr->tm_wday = n; + + /* + * Our epoch year has the property of being at the conjunction of all three 'leap cycles', + * 4, 100, and 400 years ( though we can ignore the 400 year cycle in this library). + * + * Using this property, we can easily 'map' the time stamp into the leap cycles, quickly + * deriving the year and day of year, along with the fact of whether it is a leap year. + */ + + /* map into a 100 year cycle */ + lresult = ldiv((long) days, 36525L); + years = 100 * lresult.quot; + + /* map into a 4 year cycle */ + lresult = ldiv(lresult.rem, 1461L); + years += 4 * lresult.quot; + days = lresult.rem; + if (years > 100) + days++; + + /* + * 'years' is now at the first year of a 4 year leap cycle, which will always be a leap year, + * unless it is 100. 'days' is now an index into that cycle. + */ + leapyear = 1; + if (years == 100) + leapyear = 0; + + /* compute length, in days, of first year of this cycle */ + n = 364 + leapyear; + + /* + * if the number of days remaining is greater than the length of the + * first year, we make one more division. + */ + if (days > n) { + days -= leapyear; + leapyear = 0; + result = div(days, 365); + years += result.quot; + days = result.rem; + } + timeptr->tm_year = 100 + years; + timeptr->tm_yday = days; + + /* + Given the year, day of year, and leap year indicator, we can break down the + month and day of month. If the day of year is less than 59 (or 60 if a leap year), then + we handle the Jan/Feb month pair as an exception. + */ + n = 59 + leapyear; + if (days < n) { + /* special case: Jan/Feb month pair */ + result = div(days, 31); + timeptr->tm_mon = result.quot; + timeptr->tm_mday = result.rem; + } else { + /* + The remaining 10 months form a regular pattern of 31 day months alternating with 30 day + months, with a 'phase change' between July and August (153 days after March 1). + We proceed by mapping our position into either March-July or August-December. + */ + days -= n; + result = div(days, 153); + timeptr->tm_mon = 2 + result.quot * 5; + + /* map into a 61 day pair of months */ + result = div(result.rem, 61); + timeptr->tm_mon += result.quot * 2; + + /* map into a month */ + result = div(result.rem, 31); + timeptr->tm_mon += result.quot; + timeptr->tm_mday = result.rem; + } + + /* + Cleanup and return + */ + timeptr->tm_isdst = 0; /* gmt is never in DST */ + timeptr->tm_mday++; /* tm_mday is 1 based */ + +} diff --git a/time/isLeap.c b/time/isLeap.c new file mode 100644 index 0000000..3c846aa --- /dev/null +++ b/time/isLeap.c @@ -0,0 +1,56 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: isLeap.c 2325 2013-04-02 21:22:16Z swfltek $ */ + +/* + Return 1 if 'year' is a leap year, else 0. +*/ + +#include + +unsigned char +is_leap_year(int year) +{ + div_t d; + + /* year must be divisible by 4 to be a leap year */ + if (year & 3) + return 0; + + /* If theres a remainder after division by 100, year is not divisible by 100 or 400 */ + d = div(year, 100); + if (d.rem) + return 1; + + /* If the quotient is divisible by 4, then year is divisible by 400 */ + if ((d.quot & 3) == 0) + return 1; + + return 0; +} diff --git a/time/iso_week_date.c b/time/iso_week_date.c new file mode 100644 index 0000000..efbf841 --- /dev/null +++ b/time/iso_week_date.c @@ -0,0 +1,51 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: iso_week_date.c 2394 2013-05-04 10:26:24Z swfltek $ */ + +/* + Compute the ISO 8601 week date corresponding to the given year and day of year. + See http://en.wikipedia.org/wiki/ISO_week_date for a full description. + + See iso_week_date_r.c for implementation details. + +*/ + +#include + +extern char *__asc_store; + +struct week_date * +iso_week_date(int y, int yday) +{ + struct week_date *iso; + + iso = (struct week_date *) __asc_store; + iso_week_date_r(y, yday, iso); + return iso; +} diff --git a/time/iso_week_date_r.c b/time/iso_week_date_r.c new file mode 100644 index 0000000..ac1feb4 --- /dev/null +++ b/time/iso_week_date_r.c @@ -0,0 +1,114 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: iso_week_date_r.c 2394 2013-05-04 10:26:24Z swfltek $ */ + +/* + Compute the ISO 8601 week date corresponding to the given year and day of year. + See http://en.wikipedia.org/wiki/ISO_week_date for a full description. To summarize: + + Weeks are numbered from 1 to 53. + Week days are numbered 1 to 7, beginning with Monday as day 1. + + The first week of the year contains the first Thursday in that year. + Dates prior to week 1 belong to the final week of the previous year. + + The final week of the year contains the last Thursday in that year. + Dates after the final week belong to week 1 of the following year. + +*/ + +#include + +void +iso_week_date_r(int y, int yday, struct week_date * iso) +{ + uint16_t years, n, wday; + int weeknum; + int isLeap; + + iso->year = y; + + isLeap = is_leap_year(y); + + /* compute days elapsed since epoch */ + years = y - 2000; + n = 365 * years + yday; + if (years) { + n++; /* epoch was a leap year */ + n += years / 4; + n -= isLeap; + if (years > 100) + n--; + } + + /* compute ISO8601 day of week (1 ... 7, Monday = 1) */ + wday = n + 6; /* epoch was a Saturday */ + wday %= 7; + if (wday == 0) + wday = 7; + + iso->day = wday; + + /* compute tentative week number */ + weeknum = yday + 11 - wday; + weeknum /= 7; + + /* if 53, it could be week 1 of the following year */ + if (weeknum == 53) { + /* + The final week must include its Thursday in the year. We determine the yday of this + weeks Thursday, and test whether it exceeds this years length. + */ + + /* determine final yday of this year, 364 or 365 */ + n = 364 + isLeap; + + /* compute yday of this weeks Thursday */ + wday--; /* convert to zero based week, Monday = 0 */ + yday -= wday; /* yday of this weeks Monday */ + yday += 3; /* yday of this weeks Thursday */ + + /* Is this weeks Thursday included in the year? */ + if (yday > (int) n) { + iso->year++; + weeknum = 1; + } + } + iso->week = weeknum; + + /* + If zero, it is the final week of the previous year. + We determine that by asking for the week number of Dec 31. + */ + if (weeknum == 0) { + y = y - 1; + iso_week_date_r(y, 364 + is_leap_year(y), iso); + iso->day = wday; + } +} diff --git a/time/isotime.c b/time/isotime.c new file mode 100644 index 0000000..a257815 --- /dev/null +++ b/time/isotime.c @@ -0,0 +1,44 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: isotime.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + This function returns ISO8601 formatted time, in our private buffer. +*/ + +#include + +extern char *__asc_store; + +char * +isotime(const struct tm * tmptr) +{ + isotime_r(tmptr, __asc_store); + return __asc_store; +} diff --git a/time/isotime_r.c b/time/isotime_r.c new file mode 100644 index 0000000..5636a7f --- /dev/null +++ b/time/isotime_r.c @@ -0,0 +1,70 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: isotime_r.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + Re entrant version of isotime(), which prints the date and time in ISO 8601 format. +*/ + +#include +#include + +extern void __print_lz(int , char *, char ); + +void +isotime_r(const struct tm * tmptr, char *buffer) +{ + int i; + + i = tmptr->tm_year + 1900; + __print_lz(i/100, buffer, '-'); + buffer+=2; + __print_lz(i%100, buffer,'-'); + buffer+=3; + + i = tmptr->tm_mon + 1; + __print_lz(i, buffer,'-'); + buffer+=3; + + i = tmptr->tm_mday; + __print_lz(i, buffer,' '); + buffer+=3; + + i = tmptr->tm_hour; + __print_lz(i, buffer,':'); + buffer+=3; + + i = tmptr->tm_min; + __print_lz(i, buffer,':'); + buffer+=3; + + i = tmptr->tm_sec; + __print_lz(i, buffer,0); + +} diff --git a/time/lm_sidereal.c b/time/lm_sidereal.c new file mode 100644 index 0000000..ad34fac --- /dev/null +++ b/time/lm_sidereal.c @@ -0,0 +1,47 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: lm_sidereal.c 2326 2013-04-02 21:23:41Z swfltek $ */ + +/* + Local Mean Sidereal Time. See gm_sidereal() for info. +*/ +#include + +extern long __longitude; + +unsigned long +lm_sidereal(const time_t * timer) +{ + long n; + + n = gm_sidereal(timer) + __longitude / 15L; + n += ONE_DAY; + n %= ONE_DAY; + return n; +} diff --git a/time/localtime.c b/time/localtime.c new file mode 100644 index 0000000..0e18967 --- /dev/null +++ b/time/localtime.c @@ -0,0 +1,44 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: localtime.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Standard localtime() function. +*/ + +#include + +extern struct tm __tm_store; + +struct tm * +localtime(const time_t * timer) +{ + localtime_r(timer, &__tm_store); + return &__tm_store; +} diff --git a/time/localtime_r.c b/time/localtime_r.c new file mode 100644 index 0000000..0bd1a02 --- /dev/null +++ b/time/localtime_r.c @@ -0,0 +1,60 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: localtime_r.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Re entrant version of localtime(). Given a binary UTC time stamp, add the time + zone and Daylight savings offset, then break it down into calendar time. +*/ + +#include + +extern long __utc_offset; + +extern int (*__dst_ptr) (const time_t *, int32_t *); + +void +localtime_r(const time_t * timer, struct tm * timeptr) +{ + time_t lt; + int16_t dst; + + dst = -1; + + if (__dst_ptr) + dst = __dst_ptr(timer, &__utc_offset); + + lt = *timer + __utc_offset; + + if (dst > 0) + lt += dst; + + gmtime_r(<, timeptr); + timeptr->tm_isdst = dst; +} diff --git a/time/mk_gmtime.c b/time/mk_gmtime.c new file mode 100644 index 0000000..7f2b9b9 --- /dev/null +++ b/time/mk_gmtime.c @@ -0,0 +1,113 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: mk_gmtime.c 2369 2013-04-28 14:19:35Z swfltek $ */ + +/* + 'Break down' a y2k time stamp into the elements of struct tm. + Unlike mktime(), this function does not 'normalize' the elements of timeptr. + +*/ + +#include + +time_t +mk_gmtime(const struct tm * timeptr) +{ + + time_t ret; + uint32_t tmp; + int n, m, d, leaps; + + /* + Determine elapsed whole days since the epoch to the beginning of this year. Since our epoch is + at a conjunction of the leap cycles, we can do this rather quickly. + */ + n = timeptr->tm_year - 100; + leaps = 0; + if (n) { + m = n - 1; + leaps = m / 4; + leaps -= m / 100; + leaps++; + } + tmp = 365UL * n + leaps; + + /* + Derive the day of year from month and day of month. We use the pattern of 31 day months + followed by 30 day months to our advantage, but we must 'special case' Jan/Feb, and + account for a 'phase change' between July and August (153 days after March 1). + */ + d = timeptr->tm_mday - 1; /* tm_mday is one based */ + + /* handle Jan/Feb as a special case */ + if (timeptr->tm_mon < 2) { + if (timeptr->tm_mon) + d += 31; + + } else { + n = 59 + is_leap_year(timeptr->tm_year + 1900); + d += n; + n = timeptr->tm_mon - MARCH; + + /* account for phase change */ + if (n > (JULY - MARCH)) + d += 153; + n %= 5; + + /* + * n is now an index into a group of alternating 31 and 30 + * day months... 61 day pairs. + */ + m = n / 2; + m *= 61; + d += m; + + /* + * if n is odd, we are in the second half of the + * month pair + */ + if (n & 1) + d += 31; + } + + /* Add day of year to elapsed days, and convert to seconds */ + tmp += d; + tmp *= ONE_DAY; + ret = tmp; + + /* compute 'fractional' day */ + tmp = timeptr->tm_hour; + tmp *= ONE_HOUR; + tmp += timeptr->tm_min * 60UL; + tmp += timeptr->tm_sec; + + ret += tmp; + + return ret; +} diff --git a/time/mktime.c b/time/mktime.c new file mode 100644 index 0000000..1600202 --- /dev/null +++ b/time/mktime.c @@ -0,0 +1,61 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: mktime.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Standard mktime(). The provided broken down Local 'calendar' time is converted into + a binary time stamp. The process is then reversed to 'normalize' timeptr. +*/ + +#include + +extern long __utc_offset; + +extern int (*__dst_ptr) (const time_t *, int32_t *); + +time_t +mktime(struct tm * timeptr) +{ + time_t ret; + + ret = mk_gmtime(timeptr); + + if (timeptr->tm_isdst < 0) { + if (__dst_ptr) + timeptr->tm_isdst = __dst_ptr(&ret, &__utc_offset); + } + if (timeptr->tm_isdst > 0) + ret -= timeptr->tm_isdst; + + ret -= __utc_offset; + + localtime_r(&ret, timeptr); + + return ret; +} diff --git a/time/month_length.c b/time/month_length.c new file mode 100644 index 0000000..0f2f091 --- /dev/null +++ b/time/month_length.c @@ -0,0 +1,48 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: month_length.c 2358 2013-04-23 22:30:20Z swfltek $ */ + +/* + Return the length of a month in days, given the year and month in question. + The month parameter must be '1 based', ranging from 1 to 12. +*/ + +#include + +uint8_t +month_length(int year, uint8_t month) +{ + if (month == 2) + return 28 + is_leap_year(year); + + /* 'knuckles' algorithm */ + if (month > 7) + month++; + return 30 + (month & 1); +} diff --git a/time/moon_phase.c b/time/moon_phase.c new file mode 100644 index 0000000..5fb5826 --- /dev/null +++ b/time/moon_phase.c @@ -0,0 +1,65 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: moon_phase.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + Return an approximation to the phase of the moon. Since no attempt is made to account for + Sol, Jupiter or Venus, it will often be off by several hours. +*/ + +#include +#include + +int8_t +moon_phase(const time_t * timestamp) +{ + uint32_t t; + int32_t n; + double mc; + + /* refer to first new moon of the epoch */ + t = *timestamp - 1744800UL; + + /* constrain to 1 lunar cycle */ + n = t % 2551443UL; + + /* offset by 1/2 lunar cycle */ + n -= 1275721L; + mc = n; + mc /= 1275721.0; + mc *= M_PI; + mc = cos(mc) * sin(mc); + mc *= 12.5; + + /* scale to range - 100...+ 100 */ + n /= 12757L; + n -= mc; + + return n; +} diff --git a/time/print_lz.c b/time/print_lz.c new file mode 100644 index 0000000..95c81bd --- /dev/null +++ b/time/print_lz.c @@ -0,0 +1,45 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: print_lz.c 2357 2013-04-21 16:25:30Z swfltek $ */ + +/* print 2 digit integer with leading zero: auxillary function for isotime and asctime */ + +#include + +void +__print_lz(int i, char *buffer, char s) +{ + div_t result; + + result = div(i, 10); + + *buffer++ = result.quot + '0'; + *buffer++ = result.rem + '0'; + *buffer = s; +} diff --git a/time/set_dst.c b/time/set_dst.c new file mode 100644 index 0000000..9ba0964 --- /dev/null +++ b/time/set_dst.c @@ -0,0 +1,44 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: set_dst.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Set the dst function pointer. +*/ + +#include +#include + +extern int (*__dst_ptr) (const time_t *, int32_t *); + +void +set_dst(int (*d) (const time_t *, int32_t *)) +{ + __dst_ptr = d; +} diff --git a/time/set_position.c b/time/set_position.c new file mode 100644 index 0000000..e268316 --- /dev/null +++ b/time/set_position.c @@ -0,0 +1,44 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: set_position.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Set the geographic position of the observer. Both parameters are in seconds, with + North latitude and East longitude being positive values. +*/ + +extern long __latitude; +extern long __longitude; + +void +set_position(long lat, long lon) +{ + __latitude = lat; + __longitude = lon; +} diff --git a/time/set_system_time.c b/time/set_system_time.c new file mode 100644 index 0000000..334790e --- /dev/null +++ b/time/set_system_time.c @@ -0,0 +1,55 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: set_system_time.c 2356 2013-04-21 16:20:01Z swfltek $ */ + +/* + * Set the system time. The values passed are assumed to represent local + * standard time, such as would be obtained from the typical Real Time Clock + * integrated circuit. It is necessary for this to be atomic, as the value may be + * incremented at interrupt time. + */ + +#include +extern volatile time_t __system_time; + +void +set_system_time(time_t timestamp) +{ + + asm volatile( + "in __tmp_reg__, __SREG__" "\n\t" + "cli" "\n\t" + :: + ); + __system_time = timestamp; + asm volatile( + "out __SREG__, __tmp_reg__" "\n\t" + :: + ); +} diff --git a/time/set_zone.c b/time/set_zone.c new file mode 100644 index 0000000..eb0f11b --- /dev/null +++ b/time/set_zone.c @@ -0,0 +1,41 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: set_zone.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Set the system time zone. The parameter is seconds offset from UTC. +*/ + +extern long __utc_offset; + +void +set_zone(long z) +{ + __utc_offset = z; +} diff --git a/time/solar_declination.c b/time/solar_declination.c new file mode 100644 index 0000000..dd89028 --- /dev/null +++ b/time/solar_declination.c @@ -0,0 +1,77 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: solar_declination.c 2369 2013-04-28 14:19:35Z swfltek $ */ + +/* + Were it not for the eccentricity of Earths orbit, this would be a trivial function. + + We compute the Earths orbital position with respect to perihelion, from which we derive a + 'velocity correction factor'. We then compute the orbital angle with respect to the + December solstice, as 'modulated' by that correction factor. + + Due to the accumulation of rounding errors, the computed December solstice of 2135 will lag + the actual solstice by many hours. A fudge factor, 'LAG', distributes the error across + the 136 year range of this library. +*/ + +#include +#include +#include "ephemera_common.h" + +#define LAG 38520 + +double +solar_declination(const time_t * timer) +{ + + uint32_t fT, oV; + double dV, dT; + + /* Determine orbital angle relative to perihelion of January 1999 */ + oV = *timer % ANOM_YEAR; + oV += PERIHELION; + dV = oV; + dV /= ANOM_CYCLE; + + /* Derive velocity correction factor from the perihelion angle */ + dV = sin(dV); + dV *= DELTA_V; + + /* Determine orbital angle relative to solstice of December 1999 */ + fT = *timer % TROP_YEAR; + fT += SOLSTICE + LAG; + dT = fT; + dT /= TROP_CYCLE; + dT += dV; + + /* Finally having the solstice angle, we can compute the declination */ + dT = cos(dT) * INCLINATION; + + return -dT; +} diff --git a/time/solar_noon.c b/time/solar_noon.c new file mode 100644 index 0000000..65bafcc --- /dev/null +++ b/time/solar_noon.c @@ -0,0 +1,57 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: solar_noon.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + Return the time of solar noon at the observers position +*/ + +#include + +extern long __longitude; + +time_t +solar_noon(const time_t * timer) +{ + time_t t; + long n; + + /* determine time of solar noon at the prime meridian */ + t = *timer % ONE_DAY; + t = *timer - t; + t += 43200L; + t -= equation_of_time(timer); + + /* rotate to observers longitude */ + n = __longitude / 15L; + t -= n; + + return t; + +} diff --git a/time/strftime.c b/time/strftime.c new file mode 100644 index 0000000..4dcfd30 --- /dev/null +++ b/time/strftime.c @@ -0,0 +1,322 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: strftime.c 2391 2013-05-03 20:53:06Z swfltek $ */ + +/* + Standard strftime(). This is a memory hungry monster. +*/ + +#include +#include +#include + +extern long __utc_offset; + +#ifdef __MEMX + +const __memx char strfwkdays[] = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday "; +const __memx char strfmonths[] = "January February March April May June July August September October November December "; + +#else + +const char strfwkdays[] = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday "; +const char strfmonths[] = "January February March April May June July August September October November December "; + +#endif + +#ifdef __MEMX + +unsigned char +pgm_copystring(const char __memx * p, unsigned char i, char *b, unsigned char l) +{ + +#else + +unsigned char +pgm_copystring(const char *p, unsigned char i, char *b, unsigned char l) +{ + +#endif + + unsigned char ret, c; + + ret = 0; + while (i) { + c = *p++; + if (c == ' ') + i--; + } + + c = *p++; + while (c != ' ' && l--) { + *b++ = c; + ret++; + c = *p++; + } + *b = 0; + return ret; +} + +size_t +strftime(char *buffer, size_t limit, const char *pattern, const struct tm * timeptr) +{ + unsigned int count, length; + int d, w; + char c; + char _store[26]; + struct week_date wd; + + count = length = 0; + while (count < limit) { + c = *pattern++; + if (c == '%') { + c = *pattern++; + if (c == 'E' || c == 'O') + c = *pattern++; + switch (c) { + case ('%'): + _store[0] = c; + length = 1; + break; + + case ('a'): + length = pgm_copystring(strfwkdays, timeptr->tm_wday, _store, 3); + break; + + case ('A'): + length = pgm_copystring(strfwkdays, timeptr->tm_wday, _store, 255); + break; + + case ('b'): + case ('h'): + length = pgm_copystring(strfmonths, timeptr->tm_mon, _store, 3); + break; + + case ('B'): + length = pgm_copystring(strfmonths, timeptr->tm_mon, _store, 255); + break; + + case ('c'): + asctime_r(timeptr, _store); + length = 0; + while (_store[length]) + length++; + break; + + case ('C'): + d = timeptr->tm_year + 1900; + d /= 100; + length = sprintf(_store, "%.2d", d); + break; + + case ('d'): + length = sprintf(_store, "%.2u", timeptr->tm_mday); + break; + + case ('D'): + length = sprintf(_store, "%.2u/%.2u/%.2u", \ + timeptr->tm_mon + 1, \ + timeptr->tm_mday, \ + timeptr->tm_year % 100 \ + ); + break; + + case ('e'): + length = sprintf(_store, "%2d", timeptr->tm_mday); + break; + + case ('F'): + length = sprintf(_store, "%d-%.2d-%.2d", \ + timeptr->tm_year + 1900, \ + timeptr->tm_mon + 1, \ + timeptr->tm_mday \ + ); + break; + + case ('g'): + case ('G'): + iso_week_date_r(timeptr->tm_year + 1900, timeptr->tm_yday, &wd); + if (c == 'g') { + length = sprintf(_store, "%.2d", wd.year % 100); + } else { + length = sprintf(_store, "%.4d", wd.year); + } + + break; + + case ('H'): + length = sprintf(_store, "%.2u", timeptr->tm_hour); + break; + + case ('I'): + d = timeptr->tm_hour % 12; + if (d == 0) + d = 12; + length = sprintf(_store, "%.2u", d); + break; + + case ('j'): + length = sprintf(_store, "%.3u", timeptr->tm_yday + 1); + break; + + case ('m'): + length = sprintf(_store, "%.2u", timeptr->tm_mon + 1); + break; + + case ('M'): + length = sprintf(_store, "%.2u", timeptr->tm_min); + break; + + case ('n'): + _store[0] = 10; + length = 1; + break; + + case ('p'): + length = 2; + _store[0] = 'A'; + if (timeptr->tm_hour > 11) + _store[0] = 'P'; + _store[1] = 'M'; + _store[2] = 0; + break; + + case ('r'): + d = timeptr->tm_hour % 12; + if (d == 0) + d = 12; + length = sprintf(_store, "%2d:%.2d:%.2d AM", \ + d, \ + timeptr->tm_min, \ + timeptr->tm_sec \ + ); + if (timeptr->tm_hour > 11) + _store[10] = 'P'; + break; + + case ('R'): + length = sprintf(_store, "%.2d:%.2d", timeptr->tm_hour, timeptr->tm_min); + break; + + case ('S'): + length = sprintf(_store, "%.2u", timeptr->tm_sec); + break; + + case ('t'): + length = sprintf(_store, "\t"); + break; + + case ('T'): + length = sprintf(_store, "%.2d:%.2d:%.2d", \ + timeptr->tm_hour, \ + timeptr->tm_min, \ + timeptr->tm_sec \ + ); + break; + + case ('u'): + w = timeptr->tm_wday; + if (w == 0) + w = 7; + length = sprintf(_store, "%d", w); + break; + + case ('U'): + length = sprintf(_store, "%.2u", week_of_year(timeptr, 0)); + break; + + case ('V'): + iso_week_date_r(timeptr->tm_year + 1900, timeptr->tm_yday, &wd); + length = sprintf(_store, "%.2u", wd.week); + break; + + case ('w'): + length = sprintf(_store, "%u", timeptr->tm_wday); + break; + + case ('W'): + w = week_of_year(timeptr, 1); + length = sprintf(_store, "%.2u", w); + break; + + case ('x'): + length = sprintf(_store, "%.2u/%.2u/%.2u", timeptr->tm_mon + 1, timeptr->tm_mday, timeptr->tm_year % 100); + break; + + case ('X'): + length = sprintf(_store, "%.2u:%.2u:%.2u", timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); + break; + + case ('y'): + length = sprintf(_store, "%.2u", timeptr->tm_year % 100); + break; + + case ('Y'): + length = sprintf(_store, "%u", timeptr->tm_year + 1900); + break; + + case ('z'): + d = __utc_offset / 60; + w = timeptr->tm_isdst / 60; + if (w > 0) + d += w; + w = abs(d % 60); + d = d / 60; + length = sprintf(_store, "%+.2d%.2d", d, w); + break; + + default: + length = 1; + _store[0] = '?'; + _store[1] = 0; + break; + } + + if ((length + count) < limit) { + count += length; + for (d = 0; d < (int) length; d++) { + *buffer++ = _store[d]; + } + } else { + *buffer = 0; + return count; + } + + } else { /* copy a literal */ + *buffer = c; + buffer++; + count++; + if (c == 0) + return count; + } + } + + *buffer = 0; + return count; +} diff --git a/time/sun_rise.c b/time/sun_rise.c new file mode 100644 index 0000000..b2ff62c --- /dev/null +++ b/time/sun_rise.c @@ -0,0 +1,49 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: sun_rise.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + Return the approximate time of sun rise. +*/ + +#include + +time_t +sun_rise(const time_t * timer) +{ + long n; + time_t t; + + /* sunrise is 1/2 'day' before solar noon */ + t = solar_noon(timer); + n = daylight_seconds(timer) / 2L; + t -= n; + + return t; +} diff --git a/time/sun_set.c b/time/sun_set.c new file mode 100644 index 0000000..338e35f --- /dev/null +++ b/time/sun_set.c @@ -0,0 +1,50 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: sun_set.c 2365 2013-04-27 15:32:59Z swfltek $ */ + +/* + Return the approximate time of sun set. +*/ + +#include + +time_t +sun_set(const time_t * timer) +{ + long n; + time_t t; + + /* sunset is 1/2 'day' after solar noon */ + t = solar_noon(timer); + n = daylight_seconds(timer) / 2L; + t += n; + + return t; + +} diff --git a/time/system_tick.S b/time/system_tick.S new file mode 100644 index 0000000..c1f90fd --- /dev/null +++ b/time/system_tick.S @@ -0,0 +1,60 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: system_tick.S 2348 2013-04-16 23:42:05Z swfltek $ */ + +/* + Impoved system_tick Credit to Wouter van Gulik. +*/ + +#include + + .global system_tick + .type system_tick, @function +system_tick: + push r24 + in r24,_SFR_IO_ADDR(SREG) + push r24 + cli + lds r24,__system_time+0 + subi r24, (-1) + sts __system_time+0,r24 + lds r24,__system_time+1 + sbci r24, (-1) + sts __system_time+1,r24 + lds r24,__system_time+2 + sbci r24, (-1) + sts __system_time+2,r24 + lds r24,__system_time+3 + sbci r24, (-1) + sts __system_time+3,r24 + pop r24 + out _SFR_IO_ADDR(SREG),r24 + pop r24 + ret + .size system_tick, .-system_tick diff --git a/time/system_time.c b/time/system_time.c new file mode 100644 index 0000000..64bdac7 --- /dev/null +++ b/time/system_time.c @@ -0,0 +1,36 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: system_time.c 2321 2013-04-02 00:12:48Z swfltek $ */ + +/* + The system time stamp. +*/ +#include + +volatile time_t __system_time; diff --git a/time/time.c b/time/time.c new file mode 100644 index 0000000..e794322 --- /dev/null +++ b/time/time.c @@ -0,0 +1,58 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: time.c 2318 2013-03-30 11:59:28Z swfltek $ */ + +/* + Standard time() function. Copying from __system_time must be atomic, since it + may be incremented at interrupt time. +*/ +#include +#include + +extern volatile time_t __system_time; + +time_t +time(time_t * timer) +{ + time_t ret; + + asm volatile( + "in __tmp_reg__, __SREG__" "\n\t" + "cli" "\n\t" + :: + ); + ret = __system_time; + asm volatile( + "out __SREG__, __tmp_reg__" "\n\t" + :: + ); + if (timer) + *timer = ret; + return ret; +} diff --git a/time/time.h b/time/time.h new file mode 100644 index 0000000..21d86e9 --- /dev/null +++ b/time/time.h @@ -0,0 +1,523 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: time.h 2427 2014-05-01 14:06:03Z amylaar $ */ + +/** \file */ + +/** \defgroup avr_time : Time + \code #include \endcode +

Introduction to the Time functions

+ This file declares the time functions implemented in \c avr-libc. + + The implementation aspires to conform with ISO/IEC 9899 (C90). However, due to limitations of the + target processor and the nature of its development environment, a practical implementation must + of necessity deviate from the standard. + + + + Section 7.23.2.1 clock() + The type clock_t, the macro CLOCKS_PER_SEC, and the function clock() are not implemented. We + consider these items belong to operating system code, or to application code when no operating + system is present. + + Section 7.23.2.3 mktime() + The standard specifies that mktime() should return (time_t) -1, if the time cannot be represented. + This implementation always returns a 'best effort' representation. + + Section 7.23.2.4 time() + The standard specifies that time() should return (time_t) -1, if the time is not available. + Since the application must initialize the time system, this functionality is not implemented. + + Section 7.23.2.2, difftime() + Due to the lack of a 64 bit double, the function difftime() returns a long integer. In most cases + this change will be invisible to the user, handled automatically by the compiler. + + Section 7.23.1.4 struct tm + Per the standard, struct tm->tm_isdst is greater than zero when Daylight Saving time is in effect. + This implementation further specifies that, when positive, the value of tm_isdst represents + the amount time is advanced during Daylight Saving time. + + Section 7.23.3.5 strftime() + Only the 'C' locale is supported, therefore the modifiers 'E' and 'O' are ignored. + The 'Z' conversion is also ignored, due to the lack of time zone name. + + In addition to the above departures from the standard, there are some behaviors which are different + from what is often expected, though allowed under the standard. + + There is no 'platform standard' method to obtain the current time, time zone, or + daylight savings 'rules' in the AVR environment. Therefore the application must initialize + the time system with this information. The functions set_zone(), set_dst(), and + set_system_time() are provided for initialization. Once initialized, system time is maintained by + calling the function system_tick() at one second intervals. + + Though not specified in the standard, it is often expected that time_t is a signed integer + representing an offset in seconds from Midnight Jan 1 1970... i.e. 'Unix time'. This implementation + uses an unsigned 32 bit integer offset from Midnight Jan 1 2000. The use of this 'epoch' helps to + simplify the conversion functions, while the 32 bit value allows time to be properly represented + until Tue Feb 7 06:28:15 2136 UTC. The macros UNIX_OFFSET and NTP_OFFSET are defined to assist in + converting to and from Unix and NTP time stamps. + + Unlike desktop counterparts, it is impractical to implement or maintain the 'zoneinfo' database. + Therefore no attempt is made to account for time zone, daylight saving, or leap seconds in past dates. + All calculations are made according to the currently configured time zone and daylight saving 'rule'. + + In addition to C standard functions, re-entrant versions of ctime(), asctime(), gmtime() and + localtime() are provided which, in addition to being re-entrant, have the property of claiming + less permanent storage in RAM. An additional time conversion, isotime() and its re-entrant version, + uses far less storage than either ctime() or asctime(). + + Along with the usual smattering of utility functions, such as is_leap_year(), this library includes + a set of functions related the sun and moon, as well as sidereal time functions. +*/ + +#ifndef TIME_H +#define TIME_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + /** \ingroup avr_time */ + /* @{ */ + + /** + time_t represents seconds elapsed from Midnight, Jan 1 2000 UTC (the Y2K 'epoch'). + Its range allows this implementation to represent time up to Tue Feb 7 06:28:15 2136 UTC. + */ + typedef uint32_t time_t; + + /** + The time function returns the systems current time stamp. + If timer is not a null pointer, the return value is also assigned to the object it points to. + */ + time_t time(time_t *timer); + + /** + The difftime function returns the difference between two binary time stamps, + time1 - time0. + */ + int32_t difftime(time_t time1, time_t time0); + + + /** + The tm structure contains a representation of time 'broken down' into components of the + Gregorian calendar. + + The normal ranges of the elements are.. + + \code + tm_sec seconds after the minute - [ 0 to 59 ] + tm_min minutes after the hour - [ 0 to 59 ] + tm_hour hours since midnight - [ 0 to 23 ] + tm_mday day of the month - [ 1 to 31 ] + tm_wday days since Sunday - [ 0 to 6 ] + tm_mon months since January - [ 0 to 11 ] + tm_year years since 1900 + tm_yday days since January 1 - [ 0 to 365 ] + tm_isdst Daylight Saving Time flag * + + \endcode + + *The value of tm_isdst is zero if Daylight Saving Time is not in effect, and is negative if + the information is not available. + + When Daylight Saving Time is in effect, the value represents the number of + seconds the clock is advanced. + + See the set_dst() function for more information about Daylight Saving. + + */ + struct tm { + int8_t tm_sec; + int8_t tm_min; + int8_t tm_hour; + int8_t tm_mday; + int8_t tm_wday; + int8_t tm_mon; + int16_t tm_year; + int16_t tm_yday; + int16_t tm_isdst; + }; + + + /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can + be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_ + so that the user can provide the value on the link line, which should + result in little or no run-time overhead compared with a constant. */ + typedef unsigned long clock_t; + extern char *_CLOCKS_PER_SEC_; +#define CLOCKS_PER_SEC ((clock_t) _CLOCKS_PER_SEC_) + extern clock_t clock(void); + + /** + This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp. + The elements of timeptr are interpreted as representing Local Time. + + The original values of the tm_wday and tm_yday elements of the structure are ignored, + and the original values of the other elements are not restricted to the ranges stated for struct tm. + + On successful completion, the values of all elements of timeptr are set to the appropriate range. + */ + time_t mktime(struct tm * timeptr); + + /** + This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp. + The elements of timeptr are interpreted as representing UTC. + + The original values of the tm_wday and tm_yday elements of the structure are ignored, + and the original values of the other elements are not restricted to the ranges stated for struct tm. + + Unlike mktime(), this function DOES NOT modify the elements of timeptr. + */ + time_t mk_gmtime(const struct tm * timeptr); + + /** + The gmtime function converts the time stamp pointed to by timer into broken-down time, + expressed as UTC. + */ + struct tm *gmtime(const time_t * timer); + + /** + Re entrant version of gmtime(). + */ + void gmtime_r(const time_t * timer, struct tm * timeptr); + + /** + The localtime function converts the time stamp pointed to by timer into broken-down time, + expressed as Local time. + */ + struct tm *localtime(const time_t * timer); + + /** + Re entrant version of localtime(). + */ + void localtime_r(const time_t * timer, struct tm * timeptr); + + /** + The asctime function converts the broken-down time of timeptr, into an ascii string in the form + + Sun Mar 23 01:03:52 2013 + */ + char *asctime(const struct tm * timeptr); + + /** + Re entrant version of asctime(). + */ + void asctime_r(const struct tm * timeptr, char *buf); + + /** + The ctime function is equivalent to asctime(localtime(timer)) + */ + char *ctime(const time_t * timer); + + /** + Re entrant version of ctime(). + */ + void ctime_r(const time_t * timer, char *buf); + + /** + The isotime function constructs an ascii string in the form + \code2013-03-23 01:03:52\endcode + */ + char *isotime(const struct tm * tmptr); + + /** + Re entrant version of isotime() + */ + void isotime_r(const struct tm *, char *); + + /** + A complete description of strftime() is beyond the pale of this document. + Refer to ISO/IEC document 9899 for details. + + All conversions are made using the 'C Locale', ignoring the E or O modifiers. Due to the lack of + a time zone 'name', the 'Z' conversion is also ignored. + */ + size_t strftime(char *s, size_t maxsize, const char *format, const struct tm * timeptr); + + /** + Specify the Daylight Saving function. + + The Daylight Saving function should examine its parameters to determine whether + Daylight Saving is in effect, and return a value appropriate for tm_isdst. + + Working examples for the USA and the EU are available.. + + \code #include \endcode + for the European Union, and + \code #include \endcode + for the United States + + If a Daylight Saving function is not specified, the system will ignore Daylight Saving. + */ + void set_dst(int (*) (const time_t *, int32_t *)); + + /** + Set the 'time zone'. The parameter is given in seconds East of the Prime Meridian. + Example for New York City: + \code set_zone(-5 * ONE_HOUR);\endcode + + If the time zone is not set, the time system will operate in UTC only. + */ + void set_zone(int32_t); + + /** + Initialize the system time. Examples are... + + From a Clock / Calendar type RTC: + \code + struct tm rtc_time; + + read_rtc(&rtc_time); + rtc_time.tm_isdst = 0; + set_system_time( mktime(&rtc_time) ); + \endcode + + From a Network Time Protocol time stamp: + \code + set_system_time(ntp_timestamp - NTP_OFFSET); + \endcode + + From a UNIX time stamp: + \code + set_system_time(unix_timestamp - UNIX_OFFSET); + \endcode + + */ + void set_system_time(time_t timestamp); + + /** + Maintain the system time by calling this function at a rate of 1 Hertz. + + It is anticipated that this function will typically be called from within an + Interrupt Service Routine, (though that is not required). It therefore includes code which + makes it simple to use from within a 'Naked' ISR, avoiding the cost of saving and restoring + all the cpu registers. + + Such an ISR may resemble the following example... + \code + ISR(RTC_OVF_vect, ISR_NAKED) + { + system_tick(); + reti(); + } + \endcode + */ + void system_tick(void); + + /** + Enumerated labels for the days of the week. + */ + enum _WEEK_DAYS_ { + SUNDAY, + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY + }; + + /** + Enumerated labels for the months. + */ + enum _MONTHS_ { + JANUARY, + FEBRUARY, + MARCH, + APRIL, + MAY, + JUNE, + JULY, + AUGUST, + SEPTEMBER, + OCTOBER, + NOVEMBER, + DECEMBER + }; + + /** + Return 1 if year is a leap year, zero if it is not. + */ + uint8_t is_leap_year(int16_t year); + + /** + Return the length of month, given the year and month, where month is in the range 1 to 12. + */ + uint8_t month_length(int16_t year, uint8_t month); + + /** + Return the calendar week of year, where week 1 is considered to begin on the + day of week specified by 'start'. The returned value may range from zero to 52. + */ + uint8_t week_of_year(const struct tm * timeptr, uint8_t start); + + /** + Return the calendar week of month, where the first week is considered to begin on the + day of week specified by 'start'. The returned value may range from zero to 5. + */ + uint8_t week_of_month(const struct tm * timeptr, uint8_t start); + + /** + Structure which represents a date as a year, week number of that year, and day of week. + See http://en.wikipedia.org/wiki/ISO_week_date for more information. + */ + struct week_date{ + int year; + int week; + int day; + }; + + /** + Return a week_date structure with the ISO_8601 week based date corresponding to the given + year and day of year. See http://en.wikipedia.org/wiki/ISO_week_date for more + information. + */ + struct week_date * iso_week_date( int year, int yday); + + /** + Re-entrant version of iso-week_date. + */ + void iso_week_date_r( int year, int yday, struct week_date *); + + /** + Convert a Y2K time stamp into a FAT file system time stamp. + */ + uint32_t fatfs_time(const struct tm * timeptr); + + /** One hour, expressed in seconds */ +#define ONE_HOUR 3600 + + /** Angular degree, expressed in arc seconds */ +#define ONE_DEGREE 3600 + + /** One day, expressed in seconds */ +#define ONE_DAY 86400 + + /** Difference between the Y2K and the UNIX epochs, in seconds. To convert a Y2K + timestamp to UNIX... + \code + long unix; + time_t y2k; + + y2k = time(NULL); + unix = y2k + UNIX_OFFSET; + \endcode + */ +#define UNIX_OFFSET 946684800 + + /** Difference between the Y2K and the NTP epochs, in seconds. To convert a Y2K + timestamp to NTP... + \code + unsigned long ntp; + time_t y2k; + + y2k = time(NULL); + ntp = y2k + NTP_OFFSET; + \endcode + */ +#define NTP_OFFSET 3155673600 + + /* + * =================================================================== + * Ephemera + */ + + /** + Set the geographic coordinates of the 'observer', for use with several of the + following functions. Parameters are passed as seconds of North Latitude, and seconds + of East Longitude. + + For New York City... + \code set_position( 40.7142 * ONE_DEGREE, -74.0064 * ONE_DEGREE); \endcode + */ + void set_position(int32_t latitude, int32_t longitude); + + /** + Computes the difference between apparent solar time and mean solar time. + The returned value is in seconds. + */ + int16_t equation_of_time(const time_t * timer); + + /** + Computes the amount of time the sun is above the horizon, at the location of the observer. + + NOTE: At observer locations inside a polar circle, this value can be zero during the winter, + and can exceed ONE_DAY during the summer. + + The returned value is in seconds. + */ + int32_t daylight_seconds(const time_t * timer); + + /** + Computes the time of solar noon, at the location of the observer. + */ + time_t solar_noon(const time_t * timer); + + /** + Return the time of sunrise, at the location of the observer. See the note about daylight_seconds(). + */ + time_t sun_rise(const time_t * timer); + + /** + Return the time of sunset, at the location of the observer. See the note about daylight_seconds(). + */ + time_t sun_set(const time_t * timer); + + /** Returns the declination of the sun in radians. */ + double solar_declination(const time_t * timer); + + /** + Returns an approximation to the phase of the moon. + The sign of the returned value indicates a waning or waxing phase. + The magnitude of the returned value indicates the percentage illumination. + */ + int8_t moon_phase(const time_t * timer); + + /** + Returns Greenwich Mean Sidereal Time, as seconds into the sidereal day. + The returned value will range from 0 through 86399 seconds. + */ + unsigned long gm_sidereal(const time_t * timer); + + /** + Returns Local Mean Sidereal Time, as seconds into the sidereal day. + The returned value will range from 0 through 86399 seconds. + */ + unsigned long lm_sidereal(const time_t * timer); + + /* @} */ +#ifdef __cplusplus +} +#endif + +#endif /* TIME_H */ diff --git a/time/tm_store.c b/time/tm_store.c new file mode 100644 index 0000000..af8229b --- /dev/null +++ b/time/tm_store.c @@ -0,0 +1,37 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: tm_store.c 2379 2013-04-30 16:42:26Z joerg_wunsch $ */ + +/* + Private allocation, used by gmtime() and localtime() +*/ + +#include + +struct tm __tm_store; diff --git a/time/utc_offset.c b/time/utc_offset.c new file mode 100644 index 0000000..14c8180 --- /dev/null +++ b/time/utc_offset.c @@ -0,0 +1,35 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: utc_offset.c 2321 2013-04-02 00:12:48Z swfltek $ */ + +/* + UTC offset in seconds East +*/ + +long __utc_offset; diff --git a/time/week_of_month.c b/time/week_of_month.c new file mode 100644 index 0000000..6eca94f --- /dev/null +++ b/time/week_of_month.c @@ -0,0 +1,62 @@ +/* + * (c)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: week_of_month.c 2362 2013-04-26 22:22:46Z swfltek $ */ + +/* + Return the week of month, where 'base' represents the starting day. + In the USA, the week is generally considered to start on Sunday (base = 0), + while in Europe it is generally considered to be Monday (base = 1). + + Return value ranges from 0 to 5. +*/ + +#include + +uint8_t +week_of_month(const struct tm * timestruct, uint8_t base) +{ + int first, n; + + /* zero base the day of month */ + n = timestruct->tm_mday - 1; + + /* find the first base day of the month (start of week 1) */ + first = 7 + n - timestruct->tm_wday + base; + first %= 7; + + /* find days since the first week began */ + n = n - first; + + /* if negative, we are in week 0 */ + if (n < 0) + return 0; + + return n / 7 + 1; + +} diff --git a/time/week_of_year.c b/time/week_of_year.c new file mode 100644 index 0000000..ad06f62 --- /dev/null +++ b/time/week_of_year.c @@ -0,0 +1,58 @@ +/* + * (C)2012 Michael Duane Rice All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. Neither the name of the copyright holders + * nor the names of contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $Id: week_of_year.c 2362 2013-04-26 22:22:46Z swfltek $ */ + +/* + Return the week of year, where 'base' represents the first day of the week. + In the USA, the week is generally considered to start on Sunday (base = 0), + while in Europe it is generally considered to be Monday (base = 1). + + Return value ranges from 0 to 52. +*/ + +#include + +uint8_t +week_of_year(const struct tm * timestruct, uint8_t base) +{ + int first, n; + + /* find the first base day of the year (start of week 1) */ + first = 7 + timestruct->tm_yday - timestruct->tm_wday + base; + first %= 7; + + /* find days since that first base day*/ + n = timestruct->tm_yday - first; + + /* if negative, we are in week 0 */ + if (n < 0) + return 0; + + return n / 7 + 1; +} -- cgit v1.2.3 From be5cfb4b00c91be32cb736369a452faef8c24760 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 2 Dec 2014 11:45:40 +0100 Subject: System time: Init from rtc on startup, update in timer inerrupt. --- avr/Tupfile | 12 ++++++++++++ avr/main.c | 13 +++++++++++++ avr/timer.c | 13 +++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 6c40649..9fc0739 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -16,6 +16,9 @@ SRC += $(FATFS) $(TOP)/fatfs/src/option/unicode.c #TODO: time lib SRC += ../time/asctime_r.c ../time/gmtime_r.c ../time/mk_gmtime.c SRC += ../time/print_lz.c ../time/isLeap.c +SRC += ../time/system_time.c ../time/set_system_time.c + +ASRC += ../time/system_tick.S SRC_Z = ../z180/hdrom.c @@ -74,17 +77,26 @@ CFLAGS += $(INCLUDES) CPPFLAGS += $(DEFS) +#ASFLAGS += -Wa,-adhlns=$(<:.S=.lst),-gstabs +ASFLAGS += -mmcu=$(MCU_TARGET) -x assembler-with-cpp $(ASFLAGS) + # Linker flags LDFLAGS += -Wl,--gc-sections LDFLAGS += -Wl,--cref +# Assemble: create object files from assembler source files. +#.S.o: +# $(CC) -c $(ALL_ASFLAGS) $< -o $@ + +!as = |> ^ AS %f^ $(CC) $(ASFLAGS) -c %f -o %o |> %B.o !cc = |> ^ CC %f^ $(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS_%f) -c %f -o %o |> %B.o !LINK = |> ^ LINK %o^ $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=%O.map %f $(LDLIBS) -o %o |> | %O.map !OBJCOPY= |> ^ OBJCOPY %o^ $(OBJCOPY) -Oihex %f %o |> !OBJDUMP= |> ^ OBJDUMP %o^ $(OBJDUMP) -h -S %f > %o |> %O.lss !SIZE = |> ^ SIZE^ $(SIZE) %f |> +: foreach $(ASRC) |> !as |> {objs} : foreach $(SRC) | ../z180/hdrom.h |> !cc |> {objs} : $(SRC_Z) |> !cc -D'const=const __flash' |> {objs} diff --git a/avr/main.c b/avr/main.c index 7e832bf..8acf265 100644 --- a/avr/main.c +++ b/avr/main.c @@ -20,6 +20,8 @@ #include "z180-serv.h" #include "spi.h" #include "gpio.h" +#include "time.h" +#include "rtc.h" static uint8_t mcusr; @@ -132,6 +134,16 @@ int reset_reason_is_power_on(void) return (mcusr & _BV(PORF)) != 0; } +static +void setup_system_time(void) +{ + struct tm rtc_time; + + rtc_get(&rtc_time); + rtc_time.tm_isdst = 0; + set_system_time(mk_gmtime(&rtc_time) ); +} + /*--------------------------------------------------------------------------*/ /* Stored value of bootdelay, used by autoboot_command() */ @@ -252,6 +264,7 @@ int main(void) #else i2c_init(CONFIG_SYS_I2C_CLOCK); #endif + setup_system_time(); printf_P(PSTR("\nATMEGA1281+Z8S180 Stamp Monitor\n\n")); diff --git a/avr/timer.c b/avr/timer.c index 7907bba..e222e68 100644 --- a/avr/timer.c +++ b/avr/timer.c @@ -4,6 +4,7 @@ #include "common.h" #include #include +#include "time.h" #include "timer.h" /* timer interrupt/overflow counter */ @@ -18,7 +19,8 @@ uint32_t timestamp; ISR(TIMER3_COMPA_vect) { static int_fast8_t tick_10ms; - int_fast8_t i; + static int_fast8_t tick_1s; + int_fast8_t i, j; extern void disk_timerproc(void); @@ -26,11 +28,18 @@ ISR(TIMER3_COMPA_vect) i = tick_10ms + 1; if (i == 10) { - i = 0; Stat |= S_10MS_TO; /* Drive timer procedure of low level disk I/O module */ disk_timerproc(); + + j = tick_1s - 1; + if (j == 0) { + system_tick(); + j = 100; + } + tick_1s = j; + i = 0; } tick_10ms = i; } -- cgit v1.2.3 From 19b9a7d8cafc823b90081479fb485bb05b7c52c5 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 2 Dec 2014 16:15:16 +0100 Subject: Add get_fattime(), move buffers from stack to heap --- avr/Tupfile | 1 + avr/cmd_fat.c | 203 ++++++++++-------------------------------------------- time/fatfs_time.c | 2 +- 3 files changed, 38 insertions(+), 168 deletions(-) (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 9fc0739..78e9744 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -16,6 +16,7 @@ SRC += $(FATFS) $(TOP)/fatfs/src/option/unicode.c #TODO: time lib SRC += ../time/asctime_r.c ../time/gmtime_r.c ../time/mk_gmtime.c SRC += ../time/print_lz.c ../time/isLeap.c +SRC += ../time/time.c ../time/fatfs_time.c SRC += ../time/system_time.c ../time/set_system_time.c ASRC += ../time/system_tick.S diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 0232f5d..9db3b0a 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -8,16 +8,24 @@ #include "z80-if.h" #include "con-utils.h" #include "print-utils.h" +#include "time.h" #include "timer.h" #include "debug.h" #define MAX_MEMORY (1ul << 20) +#define BUFFER_SIZE 512 + DWORD get_fattime (void) { - /* TODO: */ - return 0; + time_t timer; + struct tm tm_timer; + + time(&timer); + gmtime_r(&timer, &tm_timer); + + return fatfs_time(&tm_timer); } @@ -121,11 +129,11 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg (void) cmdtp; (void) flag; (void) argc; FatFs = (FATFS *) malloc(sizeof (FATFS)); - buffer = (char *) malloc(512); + buffer = (char *) malloc(BUFFER_SIZE); if (FatFs == NULL || buffer == NULL) { printf_P(PSTR("fatstat: Out of Memory!\n")); - free(FatFs); free(buffer); + free(FatFs); return CMD_RET_FAILURE; } @@ -177,6 +185,8 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg } f_mount(NULL, argv[1], 0); + free(buffer); + free(FatFs); if (res) { put_rc(res); return CMD_RET_FAILURE; @@ -223,21 +233,18 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } else { s1++; p1 += Finfo.fsize; } - printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s"), + printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu "), (Finfo.fattrib & AM_DIR) ? 'D' : '-', (Finfo.fattrib & AM_RDO) ? 'R' : '-', (Finfo.fattrib & AM_HID) ? 'H' : '-', (Finfo.fattrib & AM_SYS) ? 'S' : '-', (Finfo.fattrib & AM_ARC) ? 'A' : '-', (Finfo.fdate >> 9) + 1980, (Finfo.fdate >> 5) & 15, Finfo.fdate & 31, - (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63, - Finfo.fsize, &(Finfo.fname[0])); + (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63, Finfo.fsize); #if _USE_LFN - for (int i = strlen(Finfo.fname); i < 14; i++) - putchar(' '); - printf_P(PSTR("%s\n"), Lfname); + printf_P(PSTR("%s\n"), *Lfname ? Lfname : Finfo.fname); #else - putchar('\n'); + printf_P(PSTR("%s\n"), Finfo.fname); #endif } @@ -256,156 +263,6 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } -/* - * fatread - load binary file from a dos filesystem - * [bytes [pos]] - */ -command_ret_t do_fat_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - 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; -} - -/* - * fatwrite - write file into a dos filesystem - * - */ -command_ret_t do_fat_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - FATFS FatFs; - FIL File; - unsigned long bytes; - unsigned long bytes_written; - uint32_t addr; - FRESULT res; - bool buserr = 0; - uint32_t timer; - uint8_t buffer[512]; - - (void) cmdtp; (void) flag; - - if (argc < 4) - return CMD_RET_USAGE; - - addr = strtoul(argv[2], 0, 16); - bytes = strtoul(argv[3], 0, 16); - - res = f_mount(&FatFs, argv[1], 0); - if (!res) { - res = f_open(&File, argv[1], FA_CREATE_ALWAYS | FA_WRITE); - if (!res) { - bytes_written = 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; - } - if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { - buserr = 1; - break; - } - z80_read_block(buffer, addr, cnt); - z80_bus_cmd(Release); - res = f_write(&File, buffer, cnt, &br); - if (res != FR_OK) - break; - addr += br; - bytes_written += br; - if (cnt != br) - break; - } - res = f_close(&File); - timer = get_timer(timer); - printf_P(PSTR("%lu bytes written with %lu bytes/sec.\n"), - bytes_written, timer ? (bytes_written * 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; -} - /* * fatread/write - load binary file to/from a dos filesystem * read [bytes [pos]] @@ -413,7 +270,7 @@ command_ret_t do_fat_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const ar */ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - FATFS FatFs; + FATFS *FatFs; FIL File; uint32_t addr; unsigned long bytes; @@ -424,7 +281,7 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ FRESULT res; bool buserr = 0; uint32_t timer; - uint8_t buffer[512]; + uint8_t *buffer; (void) cmdtp; (void) flag; @@ -448,7 +305,16 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ if (addr + bytes > MAX_MEMORY) bytes = MAX_MEMORY - addr; - res = f_mount(&FatFs, argv[1], 0); + FatFs = (FATFS *) malloc(sizeof (FATFS)); + buffer = (uint8_t *) malloc(BUFFER_SIZE); + if (FatFs == NULL || buffer == NULL) { + printf_P(PSTR("fatstat: Out of Memory!\n")); + free(FatFs); + free(buffer); + return CMD_RET_FAILURE; + } + + res = f_mount(FatFs, argv[1], 0); if (!res) { res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS : FA_READ ); @@ -461,9 +327,9 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ while (bytes) { unsigned int cnt, br; - if (bytes >= sizeof buffer) { - cnt = sizeof buffer; - bytes -= sizeof buffer; + if (bytes >= BUFFER_SIZE) { + cnt = BUFFER_SIZE; + bytes -= BUFFER_SIZE; } else { cnt = bytes; bytes = 0; } @@ -513,6 +379,9 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ f_mount(NULL, argv[1], 0); } + free(buffer); + free(FatFs); + if (buserr) my_puts_P(PSTR("Bus timeout\n")); if (res) diff --git a/time/fatfs_time.c b/time/fatfs_time.c index 9ed49a5..e38decb 100644 --- a/time/fatfs_time.c +++ b/time/fatfs_time.c @@ -35,7 +35,7 @@ #include uint32_t -fat_time(const struct tm * timeptr) +fatfs_time(const struct tm * timeptr) { uint32_t ret; uint32_t n; -- cgit v1.2.3 From b15d22a4e43f86058b3b053096ab885a4cef6603 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 3 Dec 2014 15:52:39 +0100 Subject: Make do_fat_stat() and do_fat_ls() interruptible --- avr/cmd_fat.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'avr') diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 9db3b0a..16a5157 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -29,6 +29,17 @@ DWORD get_fattime (void) } +static bool check_abort(void) +{ + bool ret = ctrlc(); + + if (ret) + printf_P(PSTR("Abort\n")); + + return ret; +} + + static const FLASH char * const FLASH rc_names[] = { FSTR("OK"), FSTR("DISK_ERR"), @@ -54,13 +65,15 @@ static const FLASH char * const FLASH rc_names[] = { static void put_rc (FRESULT rc) { + if (rc < ARRAY_SIZE(rc_names)) { #if GCC_BUG_61443 - printf_P(PSTR("rc=%u FR_"), rc); - my_puts_P(rc_names[rc]); - my_puts_P(PSTR("\n")); + printf_P(PSTR("rc=%u FR_"), rc); + my_puts_P(rc_names[rc]); + my_puts_P(PSTR("\n")); #else - printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]); + printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]); #endif + } } /* Work register for fs command */ @@ -76,6 +89,20 @@ FILINFO Finfo = { FILINFO Finfo; #endif +static const FLASH char swirlchar[] = { '-','\\','|','/' }; + +static void swirl(void) +{ + static uint_fast8_t cnt; + static uint32_t tstamp; + + if (get_timer(0) > tstamp) { + printf_P(PSTR("\b%c"), swirlchar[cnt]); + cnt = (cnt+1) % ARRAY_SIZE(swirlchar); + tstamp = get_timer(0) + 300; + } +} + static FRESULT scan_files ( char* path /* Pointer to the working buffer with start path */ @@ -87,7 +114,7 @@ FRESULT scan_files ( char *fn; res = f_opendir(&dirs, path); - + swirl(); if (res == FR_OK) { i = strlen(path); while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { @@ -108,6 +135,10 @@ FRESULT scan_files ( AccFiles++; AccSize += Finfo.fsize; } + if (check_abort()) { + res = 255; + break; + } } } @@ -167,7 +198,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg } #endif if (!res) { - my_puts_P(PSTR("\n...")); + my_puts_P(PSTR("\nCounting... ")); AccSize = AccFiles = AccDirs = 0; strcpy(buffer, argv[1]); @@ -246,6 +277,8 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ #else printf_P(PSTR("%s\n"), Finfo.fname); #endif + if (check_abort()) + break; } if (res == FR_OK) { @@ -362,10 +395,8 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ printf_P(PSTR("Disk full?\n")); break; } - if (ctrlc()) { - printf_P(PSTR("Abort\n")); + if (check_abort()) break; - } } FRESULT fr = f_close(&File); -- cgit v1.2.3 From 6204987c3539b71856b4456f218511530af12c6f Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 3 Dec 2014 18:34:54 +0100 Subject: Put static work area on heap. LFN buffer not needed for stat function --- avr/cmd_fat.c | 79 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 42 deletions(-) (limited to 'avr') diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 16a5157..df2ae69 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -76,36 +76,31 @@ void put_rc (FRESULT rc) } } -/* Work register for fs command */ -static DWORD AccSize; -static WORD AccFiles, AccDirs; -#if _USE_LFN -char Lfname[_MAX_LFN+1]; -FILINFO Finfo = { - .lfname = Lfname, - .lfsize = sizeof Lfname - }; -#else -FILINFO Finfo; -#endif - -static const FLASH char swirlchar[] = { '-','\\','|','/' }; static void swirl(void) { + static const FLASH char swirlchar[] = { '-','\\','|','/' }; static uint_fast8_t cnt; static uint32_t tstamp; if (get_timer(0) > tstamp) { printf_P(PSTR("\b%c"), swirlchar[cnt]); cnt = (cnt+1) % ARRAY_SIZE(swirlchar); - tstamp = get_timer(0) + 300; + tstamp = get_timer(0) + 250; } } +/* Work register for fs command */ +struct stat_dat_s { + DWORD AccSize; + WORD AccFiles, AccDirs; + FILINFO Finfo; +}; + static FRESULT scan_files ( - char* path /* Pointer to the working buffer with start path */ + char *path, /* Pointer to the working buffer with start path */ + struct stat_dat_s *statp ) { DIR dirs; @@ -117,23 +112,23 @@ FRESULT scan_files ( swirl(); if (res == FR_OK) { i = strlen(path); - while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { - if (_FS_RPATH && Finfo.fname[0] == '.') continue; -#if _USE_LFN - fn = *Finfo.lfname ? Finfo.lfname : Finfo.fname; -#else - fn = Finfo.fname; -#endif - if (Finfo.fattrib & AM_DIR) { - AccDirs++; - path[i] = '/'; strcpy(path+i+1, fn); - res = scan_files(path); + while (((res = f_readdir(&dirs, &statp->Finfo)) == FR_OK) && + statp->Finfo.fname[0]) { + if (_FS_RPATH && statp->Finfo.fname[0] == '.') + continue; + fn = statp->Finfo.fname; + if (statp->Finfo.fattrib & AM_DIR) { + statp->AccDirs++; + path[i] = '/'; + strcpy(path+i+1, fn); + res = scan_files(path, statp); path[i] = '\0'; - if (res != FR_OK) break; + if (res != FR_OK) + break; } else { -// printf_P(PSTR("%s/%s\n"), path, fn); - AccFiles++; - AccSize += Finfo.fsize; + //printf_P(PSTR("%s/%s\n"), path, fn); + statp->AccFiles++; + statp->AccSize += statp->Finfo.fsize; } if (check_abort()) { res = 255; @@ -155,15 +150,16 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg FATFS *FatFs, *fs; DWORD nfreeclst; FRESULT res; - char *buffer; + char *path; + struct stat_dat_s statp; (void) cmdtp; (void) flag; (void) argc; FatFs = (FATFS *) malloc(sizeof (FATFS)); - buffer = (char *) malloc(BUFFER_SIZE); - if (FatFs == NULL || buffer == NULL) { + path = (char *) malloc(BUFFER_SIZE); + if (FatFs == NULL || path == NULL) { printf_P(PSTR("fatstat: Out of Memory!\n")); - free(buffer); + free(path); free(FatFs); return CMD_RET_FAILURE; } @@ -199,25 +195,24 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg #endif if (!res) { my_puts_P(PSTR("\nCounting... ")); - AccSize = AccFiles = AccDirs = 0; + statp.AccSize = statp.AccFiles = statp.AccDirs = 0; + strcpy(path, argv[1]); - strcpy(buffer, argv[1]); - - res = scan_files(buffer); + res = scan_files(path, &statp); } if (!res) { printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n" "%lu KB total disk space.\n%lu KB available.\n"), - AccFiles, AccSize, AccDirs, + statp.AccFiles, statp.AccSize, statp.AccDirs, (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2) ); } } } - f_mount(NULL, argv[1], 0); - free(buffer); + free(path); free(FatFs); + f_mount(NULL, argv[1], 0); if (res) { put_rc(res); return CMD_RET_FAILURE; -- cgit v1.2.3 From a870134af740aa65f57aa7edeb2f566a749d06a0 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 4 Dec 2014 03:21:36 +0100 Subject: Card detect over cs pin. (initial) --- avr/mmc.c | 99 +++++++++++++++++++++++++++++++++++++++----------------- include/diskio.h | 1 + include/spi.h | 7 ++-- 3 files changed, 75 insertions(+), 32 deletions(-) (limited to 'avr') diff --git a/avr/mmc.c b/avr/mmc.c index d780fef..8c30c97 100644 --- a/avr/mmc.c +++ b/avr/mmc.c @@ -10,7 +10,7 @@ #include "timer.h" #include "spi.h" #include "diskio.h" -//#include "debug.h" +#include "debug.h" #define MAX_DRV 2 @@ -42,9 +42,8 @@ #define SD_CS_1_DDR SBIT(DDRG,4) -#define FCLK_SLOW() SPISetMMCInitClock() /* Set slow clock (100k-400k) */ -#define FCLK_FAST() SPISetFastClock() /* Set fast clock (depends on the CSD) */ - +#define SPI_CLK_SLOW() SPISetMMCInitClock() /* Set slow clock (100k-400k) */ +#define SPI_CLK_FAST() SPISetFastClock() /* Set fast clock (depends on the CSD) */ /*-------------------------------------------------------------------------- Definitions for MMC/SDC command @@ -113,14 +112,32 @@ int wait_ready (void) /* 1:OK, 0:Timeout */ static void deselect(BYTE drv) { -// debug("*** enter deselect()\n"); + debug("*** enter deselect()\n"); if (drv == 0) SD_CS_0 = 1; - else + else { SD_CS_1 = 1; + } + /* Dummy clock (TODO: force DO hi-z for multiple slave SPI) */ + if (socket[drv].stat & STA_FAST) + SPI_CLK_FAST(); + else + SPI_CLK_SLOW(); spi_rcvr(); -// debug("*** exit deselect()\n"); + SPI_OFF(); + + if (drv == 0) { +#ifndef SD_CD_0 + // SD_CS_0 = 1; +#endif + } else { +#ifndef SD_CD_1 + SD_CS_1_DDR = 0; + SD_CS_1 = 0; +#endif + } + debug("*** exit deselect()\n"); } /*-----------------------------------------------------------------------*/ @@ -130,20 +147,31 @@ void deselect(BYTE drv) static int select(BYTE drv) /* 1:Successful, 0:Timeout */ { -// debug("*** enter select()\n"); + debug("*** enter select()\n"); if (drv == 0) SD_CS_0 = 0; - else + else { +#ifndef SD_CD_1 + SD_CS_1 = 1; + SD_CS_1_DDR = 1; +#endif SD_CS_1 = 0; + } + + if (socket[drv].stat & STA_FAST) + SPI_CLK_FAST(); + else + SPI_CLK_SLOW(); + /* Dummy clock (force DO enabled) */ spi_rcvr(); if (wait_ready()) { -// debug("*** exit select() == 1\n"); + debug("*** exit select() == 1\n"); return 1; /* OK */ } deselect(drv); -// debug("*** exit select() == 0\n"); + debug("*** exit select() == 0\n"); return 0; /* Timeout */ } @@ -157,7 +185,7 @@ int select(BYTE drv) /* 1:Successful, 0:Timeout */ static void power_on(BYTE drv) { -// debug("*** enter power_on()\n"); + debug("*** enter power_on()\n"); if (drv == 0) { #ifdef SD_PWR_0 @@ -168,14 +196,14 @@ void power_on(BYTE drv) ; /* Wait for 30ms */ #endif +#ifdef SD_WP_0 + SD_WP_0_DDR = 0; + SD_WP_0 = 1; +#endif #ifdef SD_CD_0 /* Card detect, input with pullup */ SD_CD_0_DDR = 0; SD_CD_0 = 1; -#endif -#ifdef SD_WP_0 - SD_WP_0_DDR = 0; - SD_WP_0 = 1; #endif SD_CS_0 = 1; SD_CS_0_DDR = 1; @@ -188,26 +216,30 @@ void power_on(BYTE drv) ; /* Wait for 30ms */ #endif -#ifdef SD_CD_1 - /* Card detect, input with pullup */ - SD_CD_1_DDR = 0; - SD_CD_1 = 1; -#endif #ifdef SD_WP_1 SD_WP_1_DDR = 0; SD_WP_1 = 1; #endif +#ifdef SD_CD_1 + /* Card detect, input with pullup */ + SD_CD_1_DDR = 0; + SD_CD_1 = 1; SD_CS_1 = 1; SD_CS_1_DDR = 1; +#else + /* Input, no pullup */ + SD_CS_1 = 0; + SD_CS_1_DDR = 0; +#endif } -// debug("*** exit power_on()\n"); + debug("*** exit power_on()\n"); } static void power_off(BYTE drv) { -// debug("*** enter power_off()\n"); + debug("*** enter power_off()\n"); select(drv); /* Wait for card ready */ deselect(drv); @@ -221,7 +253,7 @@ void power_off(BYTE drv) #endif } socket[drv].stat |= STA_NOINIT; -// debug("*** exit power_off()\n"); + debug("*** exit power_off()\n"); } #if 0 @@ -330,7 +362,7 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */ } argtmp; BYTE n, res; -// debug("*** send_cmd( %.2x )\n", cmd); + debug("*** send_cmd( %.2x )\n", cmd); if (cmd & 0x80) { /* ACMD is the command sequense of CMD55-CMD */ cmd &= 0x7F; @@ -396,7 +428,8 @@ DSTATUS disk_initialize ( return socket[drv].stat; /* No card in the socket */ power_on(drv); /* Force socket power on */ - FCLK_SLOW(); + socket[drv].stat &= ~STA_FAST; + SPI_CLK_SLOW(); for (n = 10; n; n--) spi_rcvr(); /* 80 dummy clocks */ @@ -483,7 +516,7 @@ DRESULT disk_read ( /* Convert to byte address if needed */ if (!(socket[drv].CardType & CT_BLOCK)) sector *= 512; - FCLK_FAST(); + socket[drv].stat |= STA_FAST; /* READ_MULTIPLE_BLOCK : READ_SINGLE_BLOCK */ cmd = count > 1 ? CMD18 : CMD17; @@ -523,7 +556,7 @@ DRESULT disk_write ( /* Convert to byte address if needed */ if (!(socket[drv].CardType & CT_BLOCK)) sector *= 512; - FCLK_FAST(); + socket[drv].stat |= STA_FAST; if (count == 1) { /* Single block write */ @@ -574,7 +607,8 @@ DRESULT disk_ioctl ( if (socket[drv].stat & STA_NOINIT) return RES_NOTRDY; - FCLK_FAST(); + /* TODO: SPI clock? */ + switch (cmd) { case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */ if (select(drv)) @@ -705,6 +739,13 @@ void disk_timerproc (void) s &= ~STA_NODISK; else /* Socket empty */ s |= (STA_NODISK | STA_NOINIT); +#else + if (SD_CS_1_DDR == 0) { + if (SD_CS_1_IN == 1) /* Card inserted */ + s &= ~STA_NODISK; + else /* Socket empty */ + s |= (STA_NODISK | STA_NOINIT); + } #endif socket[1].stat = s; /* Update MMC status */ } diff --git a/include/diskio.h b/include/diskio.h index f5ba3e0..f7a764c 100644 --- a/include/diskio.h +++ b/include/diskio.h @@ -45,6 +45,7 @@ void disk_timerproc (void); #define STA_NOINIT 0x01 /* Drive not initialized */ #define STA_NODISK 0x02 /* No medium in the drive */ #define STA_PROTECT 0x04 /* Write protected */ +#define STA_FAST 0x08 /* Fast SPI clock */ /* Command code for disk_ioctrl() */ diff --git a/include/spi.h b/include/spi.h index 04ea726..6358f62 100644 --- a/include/spi.h +++ b/include/spi.h @@ -27,10 +27,11 @@ #define SPI_SET_SPEED_F_128 do {SPCR = (1< - Initialize disk + * status - Show socket status * */ static -command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { DSTATUS res; BYTE dev; @@ -25,26 +25,50 @@ command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) dev = (BYTE) strtoul(argv[1], 0, 10); res = disk_status(dev); - printf_P(PSTR("disk_status=%.2x\n"), res); + printf_P(PSTR("Socket status: %02x\n"), res); + + return CMD_RET_SUCCESS; +} + +/* + * init - Initialize disk + * + */ +static +command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + DSTATUS res; + BYTE dev; - if ((res & STA_NODISK) == 0) { - res = disk_initialize(dev); + (void) cmdtp; (void) flag; + + if (argc < 2) + return CMD_RET_USAGE; + + dev = (BYTE) strtoul(argv[1], 0, 10); + + if (disk_status(dev) & STA_NODISK) { + printf_P(PSTR("No Disk\n")); + return CMD_RET_FAILURE; } + + res = disk_initialize(dev); printf_P(PSTR("rc=%.2x\n"), res); - if (res) { + + if (res & (STA_NODISK | STA_NOINIT)) return CMD_RET_FAILURE; - } return CMD_RET_SUCCESS; } /* - * ds - Show disk status + * info - Show disk info * */ static -command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +command_ret_t do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { + DSTATUS res; BYTE dev; union { @@ -60,6 +84,12 @@ command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ dev = (BYTE) strtoul(argv[1], 0, 10); + res = disk_status(dev); + if (res & (STA_NODISK | STA_NOINIT)) { + printf_P(res & STA_NODISK ? + PSTR("No disk\n") : PSTR("Not initialized\n")); + return CMD_RET_FAILURE; + } if (disk_ioctl(dev, GET_SECTOR_COUNT, &dat.ul) == RES_OK) printf_P(PSTR("Drive size: %lu sectors\n"), dat.ul); @@ -259,7 +289,7 @@ command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] /* * Disk ioctl - * dcs - CTRL_SYNC + * sync - CTRL_SYNC * */ static @@ -283,14 +313,19 @@ static command_ret_t do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); cmd_tbl_t cmd_sd_sub[] = { +CMD_TBL_ITEM( + status, 2, 1, do_status, + "Socket staus", + "" +), CMD_TBL_ITEM( init, 2, 1, do_init, "Initialize disk", "" ), CMD_TBL_ITEM( - status, 2, 1, do_status, - "Disk status", + info, 2, 1, do_info, + "Disk info", "" ), CMD_TBL_ITEM( @@ -300,12 +335,12 @@ CMD_TBL_ITEM( ), CMD_TBL_ITEM( read, 2, 1, do_read, - "read disk sector(s) into meomory", + "Read disk sector(s) into meomory", "drive [sector [count [memaddr]]]" ), CMD_TBL_ITEM( write, 2, 1, do_write, - "write sector(s) from meomory to disk", + "Write sector(s) from meomory to disk", "drive [sector [count [memaddr]]]" ), CMD_TBL_ITEM( @@ -316,7 +351,7 @@ CMD_TBL_ITEM( CMD_TBL_ITEM( help, CONFIG_SYS_MAXARGS, 1, do_help, - "print sub command description/usage", + "Print sub command description/usage", "\n" " - print brief description of all sub commands\n" "sd help command ...\n" @@ -325,7 +360,7 @@ CMD_TBL_ITEM( /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */ {FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help, - FSTR("alias for 'help'"), + FSTR("Alias for 'help'"), #ifdef CONFIG_SYS_LONGHELP FSTR(""), #endif /* CONFIG_SYS_LONGHELP */ diff --git a/avr/mmc.c b/avr/mmc.c index 8c30c97..afb1473 100644 --- a/avr/mmc.c +++ b/avr/mmc.c @@ -29,9 +29,9 @@ #define SD_CS_0_IN SBIT(PINB,0) #define SD_CS_0_DDR SBIT(DDRB,0) -#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */ -#define SD_CD_1_IN SBIT(PING,3) -#define SD_CD_1_DDR SBIT(DDRG,3) +//#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */ +//#define SD_CD_1_IN SBIT(PING,3) +//#define SD_CD_1_DDR SBIT(DDRG,3) //#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */ #define SD_WP_1_IN SBIT(PING,5) @@ -112,7 +112,7 @@ int wait_ready (void) /* 1:OK, 0:Timeout */ static void deselect(BYTE drv) { - debug("*** enter deselect()\n"); + //debug("*** enter deselect()\n"); if (drv == 0) SD_CS_0 = 1; else { @@ -137,7 +137,7 @@ void deselect(BYTE drv) SD_CS_1 = 0; #endif } - debug("*** exit deselect()\n"); + //debug("*** exit deselect()\n"); } /*-----------------------------------------------------------------------*/ @@ -147,7 +147,7 @@ void deselect(BYTE drv) static int select(BYTE drv) /* 1:Successful, 0:Timeout */ { - debug("*** enter select()\n"); + //debug("*** enter select()\n"); if (drv == 0) SD_CS_0 = 0; else { @@ -167,11 +167,11 @@ int select(BYTE drv) /* 1:Successful, 0:Timeout */ spi_rcvr(); if (wait_ready()) { - debug("*** exit select() == 1\n"); + //debug("*** exit select() == 1\n"); return 1; /* OK */ } deselect(drv); - debug("*** exit select() == 0\n"); + //debug("*** exit select() == 0\n"); return 0; /* Timeout */ } @@ -185,7 +185,7 @@ int select(BYTE drv) /* 1:Successful, 0:Timeout */ static void power_on(BYTE drv) { - debug("*** enter power_on()\n"); + //debug("*** enter power_on()\n"); if (drv == 0) { #ifdef SD_PWR_0 @@ -233,13 +233,13 @@ void power_on(BYTE drv) #endif } - debug("*** exit power_on()\n"); + //debug("*** exit power_on()\n"); } static void power_off(BYTE drv) { - debug("*** enter power_off()\n"); + //debug("*** enter power_off()\n"); select(drv); /* Wait for card ready */ deselect(drv); @@ -253,7 +253,7 @@ void power_off(BYTE drv) #endif } socket[drv].stat |= STA_NOINIT; - debug("*** exit power_off()\n"); + //debug("*** exit power_off()\n"); } #if 0 @@ -362,7 +362,7 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */ } argtmp; BYTE n, res; - debug("*** send_cmd( %.2x )\n", cmd); + //debug("*** send_cmd( %.2x )\n", cmd); if (cmd & 0x80) { /* ACMD is the command sequense of CMD55-CMD */ cmd &= 0x7F; @@ -474,7 +474,8 @@ DSTATUS disk_initialize ( deselect(drv); if (ty) { /* Initialization succeded */ - socket[drv].stat &= ~STA_NOINIT; /* Clear STA_NOINIT */ + /* Clear STA_NOINIT */ + socket[drv].stat = (socket[drv].stat & ~STA_NOINIT) | STA_FAST; } else { /* Initialization failed */ power_off(drv); } @@ -516,7 +517,6 @@ DRESULT disk_read ( /* Convert to byte address if needed */ if (!(socket[drv].CardType & CT_BLOCK)) sector *= 512; - socket[drv].stat |= STA_FAST; /* READ_MULTIPLE_BLOCK : READ_SINGLE_BLOCK */ cmd = count > 1 ? CMD18 : CMD17; @@ -556,7 +556,6 @@ DRESULT disk_write ( /* Convert to byte address if needed */ if (!(socket[drv].CardType & CT_BLOCK)) sector *= 512; - socket[drv].stat |= STA_FAST; if (count == 1) { /* Single block write */ -- cgit v1.2.3 From 15e476bc8dcadb88cad1e593e22cbeca62d05edb Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 5 Dec 2014 00:09:29 +0100 Subject: Card detect over cs pin: clean initialisation/power up --- avr/cmd_sd.c | 8 ++-- avr/gpio.c | 55 ++++++++++++------------ avr/main.c | 15 +++---- avr/mmc.c | 135 ++++++++++++++++++++++++++++++++++++----------------------- 4 files changed, 118 insertions(+), 95 deletions(-) (limited to 'avr') diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c index f43725a..46dbcfd 100644 --- a/avr/cmd_sd.c +++ b/avr/cmd_sd.c @@ -330,18 +330,18 @@ CMD_TBL_ITEM( ), CMD_TBL_ITEM( dump, CONFIG_SYS_MAXARGS, 1, do_dump, - "Dump sector", - "" + "Dump sector(s)", + " [sector [count ]]" ), CMD_TBL_ITEM( read, 2, 1, do_read, "Read disk sector(s) into meomory", - "drive [sector [count [memaddr]]]" + " [sector [count [memaddr]]]" ), CMD_TBL_ITEM( write, 2, 1, do_write, "Write sector(s) from meomory to disk", - "drive [sector [count [memaddr]]]" + " [sector [count [memaddr]]]" ), CMD_TBL_ITEM( sync, 2, 1, do_ioctl_sync, diff --git a/avr/gpio.c b/avr/gpio.c index 3c47247..31dbc21 100644 --- a/avr/gpio.c +++ b/avr/gpio.c @@ -7,36 +7,35 @@ /* -Pin Name Port Timer Mode max div max div min f [Hz] ----------------------------------------------------------------------------------- -0 PG5 OC0B PWM (2**8)*1024 262144 70.31 -1 PG4 -2 CLK2 PB4 OC2A Toggle (2**8)*1024*2 524288 35.16 -3 ZCLK PB5 OC1A PWM (2**16)*1024 67108864 0.2746 -4 PB6 OC1B PWM (2**16)*1024 67108864 0.2746 -5 PB7 OC0A Toggle (2**8)*1024*2 524288 35.16 -6 PG3 -7 PG2 -8 PG1 -9 PG0 -10 CLKO PE7 - - -pre Timer0 Timer1 Timer2 +Pin Name Port Timer Mode max div max div min f [Hz] +-------------------------------------------------------------------------------- +0 PG5 OC0B PWM (2**8)*1024 262144 70.31 +1 PG4 +2 CLK2 PB4 OC2A Toggle (2**8)*1024*2 524288 35.16 +3 ZCLK PB5 OC1A PWM (2**16)*1024 67108864 0.2746 +4 PB6 OC1B PWM (2**16)*1024 67108864 0.2746 +5 PB7 OC0A Toggle (2**8)*1024*2 524288 35.16 +6 PG3 +7 PG2 +8 PG1 +9 PG0 +10 CLKO PE7 +-------------------------------------------------------------------------------- + + +pre Timer0 Timer1 Timer2 -------------------------------------------------- -0 0 0 0 -1 1 1 1 -2 8 x8 8 x8 8 x8 -3 64 x8 64 x8 32 x4 -4 256 x4 256 x4 64 x2 -5 1024 x4 1024 x4 128 x2 -6 256 x2 -7 1024 x4 +0 0 0 0 +1 1 1 1 +2 8 x8 8 x8 8 x8 +3 64 x8 64 x8 32 x4 +4 256 x4 256 x4 64 x2 +5 1024 x4 1024 x4 128 x2 +6 256 x2 +7 1024 x4 -------------------------------------------------- - */ - #define PWMTOGGLE 0b01 #define PWMPOS 0b10 #define PWMNEG 0b11 @@ -312,7 +311,7 @@ int gpio_clockdiv_set(int pin, unsigned long divider) top = ltop - 1; - PING |= _BV(0); /* Debug */ +// PING |= _BV(0); /* Debug */ switch (timertype & TIMER) { case TIMER0: @@ -363,7 +362,7 @@ int gpio_clockdiv_set(int pin, unsigned long divider) break; } - PING |= _BV(0); /* Debug */ +// PING |= _BV(0); /* Debug */ gpio_config(pin, OUTPUT_TIMER); diff --git a/avr/main.c b/avr/main.c index 8acf265..f601736 100644 --- a/avr/main.c +++ b/avr/main.c @@ -18,7 +18,6 @@ #include "cli.h" #include "env.h" #include "z180-serv.h" -#include "spi.h" #include "gpio.h" #include "time.h" #include "rtc.h" @@ -112,13 +111,6 @@ void setup_avr(void) TCCR3B = (0b01< + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/TODO b/TODO new file mode 100644 index 0000000..7b8d92f --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +TODO: eliminate xmalloc diff --git a/avr/background.c b/avr/background.c index 0e1ca40..9c8b5a6 100644 --- a/avr/background.c +++ b/avr/background.c @@ -1,10 +1,16 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include "background.h" #define BG_FUNC_MAX 5 -static struct { +static struct { bg_func fct; int param; } func_tab[BG_FUNC_MAX]; @@ -13,7 +19,7 @@ static int_fast8_t fcount; int bg_register(bg_func f, int initval) { - if (fcount < BG_FUNC_MAX) { + if (fcount < BG_FUNC_MAX) { func_tab[fcount].fct = f; func_tab[fcount].param = initval; return ++fcount - 1; @@ -27,7 +33,7 @@ int bg_setstat(int handle, int val) func_tab[handle].param = val; return 1; } - + return 0; } @@ -44,7 +50,7 @@ int bg_getstat(int handle) void bg_shed(void) { static int_fast8_t current; - + if (func_tab[current].fct) { int v = func_tab[current].fct(func_tab[current].param); func_tab[current].param = v; @@ -52,5 +58,3 @@ void bg_shed(void) if (++current >= fcount) current = 0; } - - diff --git a/avr/cli.c b/avr/cli.c index 046859c..52c85db 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -1,3 +1,16 @@ +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2000 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * Add to readline cmdline-editing by + * (C) Copyright 2005 + * JinHua Luo, GuangDong Linux Center, + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include diff --git a/avr/cli_readline.c b/avr/cli_readline.c index 1dbc73b..04d32b1 100644 --- a/avr/cli_readline.c +++ b/avr/cli_readline.c @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * (C) Copyright 2000 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * @@ -591,4 +593,3 @@ int cli_readline(const FLASH char *const prompt) return cli_readline_into_buffer(prompt, console_buffer); } - diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index 4775b6e..301f4f5 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -1,3 +1,11 @@ +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2000-2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ /* * Misc boot support diff --git a/avr/cmd_date.c b/avr/cmd_date.c index 3beebee..efba858 100644 --- a/avr/cmd_date.c +++ b/avr/cmd_date.c @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * (C) Copyright 2001 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index df2ae69..8ed7ae3 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -1,3 +1,13 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * FAT filesystem commands + */ + #include "common.h" #include #include @@ -290,6 +300,39 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ return CMD_RET_SUCCESS; } +static +FRESULT mkpath(TCHAR *path) +{ + /* TODO: */ + (void) path; +#if 0 + FILINFO fd + TCHAR *p, *q; + FRESULT ret; + +#if _USE_LFN + fd.lfname = 0; +#endif + + + res = f_stat (path, &fd) + + p = strchr(path, ':'); + if (p == NULL || *++p == '\0' || *p++ != '/') + return FR_OK; + + while ((q = strchr(p, '/')) != NULL) { + *q = '\0'; + ret = f_mkdir(path); + *q = '/'; + if (ret != FR_OK && ret != FR_EXIST) + return ret; + p = q + 1; + } +#endif + + return FR_OK; +} /* * fatread/write - load binary file to/from a dos filesystem @@ -343,6 +386,12 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } res = f_mount(FatFs, argv[1], 0); + + if (!res) { + if (dowrite) { + res = mkpath(argv[1]); + } + } if (!res) { res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS : FA_READ ); diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c index f448e36..e0d9b06 100644 --- a/avr/cmd_gpio.c +++ b/avr/cmd_gpio.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include #include diff --git a/avr/cmd_help.c b/avr/cmd_help.c index 8f81b2d..010339d 100644 --- a/avr/cmd_help.c +++ b/avr/cmd_help.c @@ -1,3 +1,11 @@ +/* + * (C) Copyright 2014 Leo C. + * + * Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ #include "common.h" #include "command.h" diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index 0bc5742..20a4412 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * (C) Copyright 2000 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c index 315b959..b29aedd 100644 --- a/avr/cmd_misc.c +++ b/avr/cmd_misc.c @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * @@ -88,4 +90,3 @@ command_ret_t do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] return CMD_RET_SUCCESS; } - diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c index 46dbcfd..6b75d6e 100644 --- a/avr/cmd_sd.c +++ b/avr/cmd_sd.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include diff --git a/avr/command.c b/avr/command.c index c080527..b6fa418 100644 --- a/avr/command.c +++ b/avr/command.c @@ -1,3 +1,12 @@ +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + /* * Command Processor Table */ diff --git a/avr/command_tbl.c b/avr/command_tbl.c index e5c6567..b70c711 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -1,10 +1,13 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ #include "common.h" - #include "command.h" #include "cmd_mem.h" - extern command_ret_t do_help(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_echo(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_sleep(cmd_tbl_t *, int, int, char * const []); diff --git a/avr/con-utils.c b/avr/con-utils.c index f4023ff..f20dbfe 100644 --- a/avr/con-utils.c +++ b/avr/con-utils.c @@ -1,3 +1,8 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ #include #include "common.h" diff --git a/avr/debug.c b/avr/debug.c index 796647b..5096d59 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include #include @@ -7,6 +13,7 @@ #include "command.h" #include "print-utils.h" #include "debug.h" + /* * Debugging */ diff --git a/avr/env.c b/avr/env.c index 017053c..7be7d03 100644 --- a/avr/env.c +++ b/avr/env.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include #include @@ -8,7 +14,6 @@ #include "xmalloc.h" #include "crc.h" #include "command.h" - #include "env.h" diff --git a/avr/getopt-min.c b/avr/getopt-min.c index 8e5dd6c..f5ad912 100644 --- a/avr/getopt-min.c +++ b/avr/getopt-min.c @@ -1,6 +1,3 @@ -#include "common.h" - - /* * Minimum getopt, original version was: */ @@ -13,7 +10,8 @@ */ /* $Id: getopt.c,v 1.2 1992/12/07 11:12:52 nickc Exp $ */ -#include +#include "common.h" /* definition of FLASH */ +#include int optind = 1; /* next argv[] index */ char *optarg; /* option parameter if any */ @@ -40,7 +38,7 @@ getopt( /* returns letter, '?', EOF */ ) return -1; } - + c = argv[optind][sp]; /* option letter */ osp = sp++; /* get ready for next letter */ @@ -72,4 +70,3 @@ getopt( /* returns letter, '?', EOF */ return c; } - diff --git a/avr/gpio.c b/avr/gpio.c index 31dbc21..73e9c39 100644 --- a/avr/gpio.c +++ b/avr/gpio.c @@ -1,10 +1,15 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include #include #include "debug.h" #include "gpio.h" - /* Pin Name Port Timer Mode max div max div min f [Hz] diff --git a/avr/i2c.c b/avr/i2c.c index d181ff6..ae2f8da 100644 --- a/avr/i2c.c +++ b/avr/i2c.c @@ -1,3 +1,8 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ /* * I2C (TWI) master interface. @@ -371,6 +376,3 @@ int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen, return !((rc & (XMIT_DONE|DATA_ACK)) == (XMIT_DONE|DATA_ACK)); } - - - diff --git a/avr/main.c b/avr/main.c index f601736..8bffef9 100644 --- a/avr/main.c +++ b/avr/main.c @@ -1,9 +1,11 @@ /* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ */ #include "common.h" - #include #include #include diff --git a/avr/pcf8583.c b/avr/pcf8583.c index 7e9d749..169e4e9 100644 --- a/avr/pcf8583.c +++ b/avr/pcf8583.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + /* * Date & Time support for Philips PCF8583 RTC */ diff --git a/avr/print-utils.c b/avr/print-utils.c index 4205a90..3f48620 100644 --- a/avr/print-utils.c +++ b/avr/print-utils.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include #include diff --git a/avr/serial.c b/avr/serial.c index e897c84..adbc3c4 100644 --- a/avr/serial.c +++ b/avr/serial.c @@ -1,4 +1,7 @@ /* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -12,7 +15,7 @@ static int _write(char c, FILE *stream); -static FILE mystdout = FDEV_SETUP_STREAM(_write, +static FILE mystdout = FDEV_SETUP_STREAM(_write, NULL, _FDEV_SETUP_WRITE); @@ -24,7 +27,7 @@ static FILE mystdout = FDEV_SETUP_STREAM(_write, #endif #if ((BUFFER_SIZE) > 256) -# error: BUFFER_SIZE +# error: BUFFER_SIZE #endif struct ring rx_ring; @@ -119,5 +122,3 @@ uint_fast8_t serial_tstc(void) { return !ring_is_empty(&rx_ring); } - - diff --git a/avr/timer.c b/avr/timer.c index e222e68..f45f267 100644 --- a/avr/timer.c +++ b/avr/timer.c @@ -1,4 +1,7 @@ /* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ */ #include "common.h" @@ -12,10 +15,9 @@ static volatile uint32_t timestamp; -/*---------------------------------------------------------*/ -/* 1000Hz timer interrupt generated by OC3A */ -/*---------------------------------------------------------*/ - +/* + * 1000Hz timer interrupt generated by OC3A + */ ISR(TIMER3_COMPA_vect) { static int_fast8_t tick_10ms; diff --git a/avr/xmalloc.c b/avr/xmalloc.c index 9bf2684..d42d5c9 100644 --- a/avr/xmalloc.c +++ b/avr/xmalloc.c @@ -1,5 +1,10 @@ -#include +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ +#include #include "debug.h" #include "xmalloc.h" @@ -11,7 +16,7 @@ void* xmalloc(size_t size) if (p == NULL) debug("*** Out of memory!\n"); - + return p; } @@ -22,6 +27,6 @@ void* xrealloc(void *p, size_t size) if (p == NULL) debug("*** Out of memory!\n"); - + return p; } diff --git a/avr/z180-serv.c b/avr/z180-serv.c index e3bca16..e0b763f 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include @@ -7,8 +13,6 @@ #include "debug.h" #include "z180-serv.h" - - /*--------------------------------------------------------------------------*/ diff --git a/avr/z180-stamp-avr.c b/avr/z180-stamp-avr.c deleted file mode 100644 index e6edb33..0000000 --- a/avr/z180-stamp-avr.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - */ - - -#include -//#include -//#include -#include -//#include -//#include -//#include - -#include - - -#include "debug.h" -#include "serial.h" -#include "z80-if.h" - -#define const const __flash -#include "../z180/hdrom.h" -#undef const - -#define FLASH __flash -//#define FLASH - -#define ESCCHAR ('^'-0x40) - -#define S_10MS_TO (1<<0) - - -volatile int_fast8_t timeout_1s; -//volatile uint_least8_t Stat; -#define Stat GPIOR0 - -unsigned int to_counter; - -/****************************************************************/ - -#define P_ADL PORTA -#define P_ADH PORTC -#define P_ADB PORTE -#define PIN_ADB PINE - -#define ADB_WIDTH 3 -#define ADB_SHIFT 2 -//#define ADB_PORT GPIOE - -#define MASK(n) ((1<<(n))-1) -#define SMASK(w,s) (MASK(w) << (s)) - -typedef union { - uint32_t l; - uint16_t w[2]; - uint8_t b[4]; -} addr_t; - - - -/*--------------------------------------------------------------------------*/ - -/*---------------------------------------------------------*/ -/* 1000Hz timer interrupt generated by OC1A */ -/*---------------------------------------------------------*/ - -ISR(TIMER1_COMPA_vect) -{ - static int_fast8_t tick_10ms; -// static int_fast16_t count_ms; - - int_fast8_t i; - - - i = tick_10ms + 1; - if (i == 10) { - i = 0; - Stat |= S_10MS_TO; - - /* Drive timer procedure of low level disk I/O module */ - //disk_timerproc(); - } - tick_10ms = i; - -#if 0 - count_ms++; - if (count_ms == 1000) { - count_ms = 0; - - i = timeout_1s; - if (i) - timeout_1s = i - 1; - } -#endif -} - - -/*--------------------------------------------------------------------------*/ - -static uint32_t z80_sram_cmp(uint32_t addr, uint32_t length, uint8_t wval, int inc) -{ - uint8_t rval; - int_fast8_t errors = 0; - - DBG_P(1, "SRAM: Check 0x%.5lx byte... ", length); - while (length--) { - if ((rval = z80_read(addr)) != wval) { - if (errors == 0) { - DBG_P(1, "\nSRAM: Address W R\n" \ - " ------------------\n"); - } - errors++; - if (errors > 20) { - DBG_P(1, " ...\n"); - break; - } - DBG_P(1, " 0x%.5lx 0x%.2x 0x%.2x\n", addr, wval, rval); - } - addr++; - wval += inc; - } - DBG_P(1, "Done.\n"); - - return addr; -} - -static void z80_sram_fill(uint32_t addr, uint32_t length, uint8_t startval, int inc) -{ - printf("SRAM: Write 0x%.5lx byte... ", length); - while (length--) { - z80_write(addr, startval); - ++addr; - startval += inc; - } - printf("Done.\n"); -} - - -#if 0 -void z80_sram_fill_string(uint32_t addr, int length, const char *text) -{ - char c; - const char *p = text; - - while (length--) { - z80_write(addr++, c = *p++); - if (c == 0) - p = text; - } -} - - -uint32_t z80_sram_cmp_string(uint32_t addr, int length, const char *text) -{ - char c; - const char *p = text; - - while (length--) { - c = *p++; - if (z80_read(addr) != c) - break; - ++addr; - if (c == 0) - p = text; - } - return addr; -} - -const char * const qbfox = "Zhe quick brown fox jumps over the lazy dog!"; -const char * const qbcat = "Zhe quick brown fox jumps over the lazy cat!"; - -#endif - -uint8_t z80_get_byte(uint32_t adr) -{ - uint8_t data; - - z80_request_bus(); - data = z80_read(adr), - z80_release_bus(); - - return data; -} - - -/*--------------------------------------------------------------------------*/ - -static void do_10ms(void) -{ - if (to_counter) - to_counter--; -} - -/*--------------------------------------------------------------------------*/ - -struct msg_item { - uint8_t fct; - uint8_t sub_min, sub_max; - void (*func)(uint8_t, int, uint8_t *); -}; - -uint32_t msg_to_addr(uint8_t *msg) -{ - union { - uint32_t as32; - uint8_t as8[4]; - } addr; - - addr.as8[0] = msg[0]; - addr.as8[1] = msg[1]; - addr.as8[2] = msg[2]; - addr.as8[3] = 0; - - return addr.as32; -} - -void do_msg_ini_msgfifo(uint8_t subf, int len, uint8_t * msg) -{ - (void)subf; (void)len; - - z80_init_msg_fifo(msg_to_addr(msg)); -} - - -void do_msg_ini_memfifo(uint8_t subf, int len, uint8_t * msg) -{ - (void)len; - - z80_memfifo_init(subf - 1, msg_to_addr(msg)); -} - - -void do_msg_char_out(uint8_t subf, int len, uint8_t * msg) -{ - (void)subf; - - while (len--) - putchar(*msg++); -} - - -const FLASH struct msg_item z80_messages[] = -{ - { 0, /* fct nr. */ - 0, 0, /* sub fct nr. from, to */ - do_msg_ini_msgfifo}, - { 0, - 1, 2, - do_msg_ini_memfifo}, - { 1, - 1, 1, - do_msg_char_out}, - { 0xff, /* end mark */ - 0, 0, - 0}, - -}; - - - - -void do_message(int len, uint8_t *msg) -{ - uint8_t fct, sub_fct; - int_fast8_t i = 0; - - if (len >= 2) { - fct = *msg++; - sub_fct = *msg++; - len -= 2; - - while (fct != z80_messages[i].fct) - ++i; - - if (z80_messages[i].fct == 0xff) { - DBG_P(1, "do_message: Unknown function: %i, %i\n", - fct, sub_fct); - return; /* TODO: unknown message # */ - } - - while (fct == z80_messages[i].fct) { - if (sub_fct >= z80_messages[i].sub_min && sub_fct <= z80_messages[i].sub_max ) - break; - ++i; - } - - if (z80_messages[i].fct != fct) { - DBG_P(1, "do_message: Unknown sub function: %i, %i\n", - fct, sub_fct); - return; /* TODO: unknown message sub# */ - } - - (z80_messages[i].func)(sub_fct, len, msg); - - - } else { - /* TODO: error */ - DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len); - } -} - - - -#define CTRBUF_LEN 256 - -void check_msg_fifo(void) -{ - int ch; - static int_fast8_t state; - static int msglen,idx; - static uint8_t buffer[CTRBUF_LEN]; - - while (state != 3 && (ch = z80_msg_fifo_getc()) >= 0) { - switch (state) { - case 0: /* wait for start of message */ - if (ch == 0x81) { - msglen = 0; - idx = 0; - state = 1; - } - break; - case 1: /* get msg len */ - if (ch > 0 && ch <= CTRBUF_LEN) { - msglen = ch; - state = 2; - } else - state = 0; - break; - case 2: /* get message */ - buffer[idx++] = ch; - if (idx == msglen) - state = 3; - break; - } - } - - if (state == 3) { - do_message(msglen, buffer); - state = 0; - } -} - - -/*--------------------------------------------------------------------------*/ - -void dump_mem(const __flash uint8_t *addr, uint32_t len) -{ - DBG_P(1, "hdrom dump:"); - while (len) { - DBG_P(1, "\n %.5x:", addr); - for (unsigned i = 0; i<16; i++) - DBG_P(1, " %.2x", *addr++); - len -= len > 16 ? 16 : len; - } - DBG_P(1, "\n"); -} - -/*--------------------------------------------------------------------------*/ - -void z80_load_mem(void) -{ - unsigned sec = 0; - uint32_t sec_base = hdrom_start; - - DBG_P(1, "Loading z80 memory... \n"); - - while (sec < hdrom_sections) { - DBG_P(2, " From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n", - hdrom_address[sec], - hdrom_address[sec]+hdrom_length_of_sections[sec] - 1, - hdrom_length_of_sections[sec]); - - z80_write_block((const __flash unsigned char *) &hdrom[sec_base], /* src */ - hdrom_address[sec], /* dest */ - hdrom_length_of_sections[sec]); /* len */ - sec_base+=hdrom_length_of_sections[sec]; - sec++; - } -} - -/*--------------------------------------------------------------------------*/ - -void z80_dump_mem(uint32_t addr, uint32_t len) -{ - DBG_P(1, "Memory dump:"); - while (len) { - DBG_P(1, "\n %.5lx:", addr); - for (unsigned i = 0; i<16; i++) - DBG_P(1, " %.2x", z80_read(addr++)); - len -= len > 16 ? 16 : len; - } - DBG_P(1, "\n"); -} - -/*--------------------------------------------------------------------------*/ - -void setup_rtc(void) -{ - /* TODO: */ -} - -void setup_avr(void) -{ - /* WD */ - - /* CPU */ - - /* Disable JTAG Interface regardless of the JTAGEN fuse setting. */ - MCUCR = _BV(JTD); - MCUCR = _BV(JTD); - - /* disable unused periphels */ - PRR0 = _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRADC); - PRR1 = _BV(PRTIM5) | _BV(PRTIM4) | _BV(PRTIM3) | - _BV(PRUSART3) | _BV(PRUSART2) | _BV(PRUSART1); - - /* disable analog comparator */ - ACSR = _BV(ACD); - /* Ports */ - - /* Clock */ - CLKPR = _BV(CLKPCE); - CLKPR = 0; - - /* Timer */ - - OCR1A = F_CPU / 8 / 1000 - 1; // Timer1: 1000Hz interval (OC1A) - TCCR1B = 0b00001010; - TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt -} - -const __flash uint8_t iniprog[] = { - 0xAF, // xor a - 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh - 0x3E, 0x30, // ld a,030h - 0xED, 0x39, 0x32 //out0 (dcntl),a ;0 mem, max i/0 wait states -}; - -const __flash uint8_t sertest[] = { - 0xAF, // xor a - 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh - 0x3E, 0x30, // ld a,030h - 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states - 0x3E, 0x80, // ld a,M_MPBT ;no MP, PS=10, DR=16, SS=0 - 0xED, 0x39, 0x03, // out0 (cntlb1),a - 0x3E, 0x64, // ld a,M_RE + M_TE + M_MOD2 ; - 0xED, 0x39, 0x01, // out0 (cntla1),a - 0x3E, 0x00, // ld a,0 - 0xED, 0x39, 0x05, // out0 (stat1),a ;Enable rx interrupts - 0xED, 0x38, 0x05, //l0:in0 a,(stat1) - 0xE6, 0x80, // and 80h - 0x28, 0xF9, // jr z,l0 - 0xED, 0x00, 0x09, // in0 b,(rdr1) - 0xED, 0x38, 0x05, //l1:in0 a,(stat1) - 0xE6, 0x02, // and 02h - 0x28, 0xF9, // jr z,l1 - 0xED, 0x01, 0x07, // out0 (tdr1),b - 0x18, 0xEA, // jr l0 -}; - -const __flash uint8_t test1[] = { - 0xAF, // xor a - 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh - 0x3E, 0x30, // ld a,030h - 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states - 0x21, 0x1E, 0x00, // ld hl,dmclrt ;load DMA registers - 0x06, 0x08, // ld b,dmct_e-dmclrt - 0x0E, 0x20, // ld c,sar0l - 0xED, 0x93, // otimr - 0x3E, 0xC3, // ld a,0c3h ;dst +1, src +1, burst - 0xED, 0x39, 0x31, // out0 (dmode),a ; - 0x3E, 0x62, // ld a,062h ;enable dma0, - 0xED, 0x39, 0x30, //cl_1: out0 (dstat),a ;copy 64k - 0x18, 0xFB, // jr cl_1 ; - 0x00, 0x00, //dmclrt: dw 0 ;src (inc) - 0x00, // db 0 ;src - 0x00, 0x00, // dw 0 ;dst (inc), - 0x00, // db 0 ;dst - 0x00, 0x00, // dw 0 ;count (64k) -}; - - -int main(void) -{ - int_fast8_t state = 0; - int ch; - - setup_avr(); - serial_setup(); - setup_rtc(); - sei(); - - printf_P(PSTR("\n(ATMEGA1281+HD64180)_stamp Tester\n")); - - DBG_P(1, "z80_setup_bus... "); - z80_setup_msg_fifo(); - z80_setup_bus(); - DBG_P(1, "done.\n"); - - DBG_P(1, "Get bus... "); -/* Now done via S_Z180_RUNNING - z80_busreq(LOW); - z80_reset(HIGH); -*/ - z80_request_bus(); - DBG_P(1, "got it!\n"); - -// z80_sram_fill(0, (uint32_t)512 * 1024, 0x00, 3); -// z80_sram_cmp(0, (uint32_t)512 * 1024, 0x00, 3); -// z80_dump_mem(0, 0x400); - - z80_memset(0, 0x76, 0x80000); -// z80_memset(0, 0x00, 0x80000); -// z80_write_block(test1, 0, sizeof(test1)); - -// z80_dump_mem(0, 0x100); - -// z80_sram_cmp(0, (uint32_t)512 * 1024, 0x76, 0); - - z80_load_mem(); -// z80_write(0, 0x76); -// z80_dump_mem(0, 0x200); - - -/* Now done via S_Z180_RUNNING - z80_reset(LOW); -*/ - z80_release_bus(); - DBG_P(1, "Bus released!\n"); - z80_reset(HIGH); - DBG_P(1, "Reset released!\n"); - - to_counter = 200; - - while (1) { - - if (Stat & S_10MS_TO) { - Stat &= ~S_10MS_TO; - do_10ms(); - } - - - if ((ch = serial_getc()) >= 0) { - switch (state) { - case 0: - if (ch == ESCCHAR) { - state = 1; - /* TODO: Timer starten */ - } else { -// z80_memfifo_putc(fifo_out, ch); - serial_putc(ch); - if (ch == '\r') - serial_putc('\n'); - } - break; - case 1: - switch (ch) { - - case 'r': - z80_reset_pulse(); - break; - - case 'b': - z80_request_bus(); - z80_dump_mem(0, 0x2d20); - z80_release_bus(); - break; - - case 'e': - z80_request_bus(); - z80_dump_mem(0x80000-0x4000, 0x800); - z80_dump_mem(0x80000-0x200, 0x200); - z80_release_bus(); - break; - - case ESCCHAR: - default: -// z80_memfifo_putc(fifo_out, ch); - serial_putc(ch); - if (ch == '\r') - serial_putc('\n'); - } - state = 0; - break; - } - } - -// check_msg_fifo(); - } - - return 0; -} diff --git a/avr/z80-if.c b/avr/z80-if.c index cc0bab1..b64e755 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + /** * * Pin assignments @@ -50,7 +56,6 @@ * | | P | | af1 OSC32 | * | | P | | af1 OSC32 | - */ diff --git a/include/background.h b/include/background.h index 8a430b3..87e95e5 100644 --- a/include/background.h +++ b/include/background.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef BACKGROUND_H #define BACKGROUND_H @@ -9,4 +15,3 @@ int bg_getstat(int handle); void bg_shed(void); #endif /* BACKGROUND_H */ - diff --git a/include/cli.h b/include/cli.h index 67ff63b..f6fb2ab 100644 --- a/include/cli.h +++ b/include/cli.h @@ -1,4 +1,13 @@ -#ifndef CLI_H +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2014 Google, Inc + * Simon Glass + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef CLI_H #define CLI_H /** @@ -61,4 +70,3 @@ int run_command_list(const char *cmd, int len); #endif /* CLI_H */ - diff --git a/include/cli_readline.h b/include/cli_readline.h index 5b25762..b7dc938 100644 --- a/include/cli_readline.h +++ b/include/cli_readline.h @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * (C) Copyright 2014 Google, Inc * Simon Glass * @@ -47,4 +49,3 @@ int cli_readline(const FLASH char *const prompt); #endif /* CLI_READLINE_H */ - diff --git a/include/cmd_mem.h b/include/cmd_mem.h index 1802338..05227cc 100644 --- a/include/cmd_mem.h +++ b/include/cmd_mem.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef CMD_MEM_H #define CMD_MEM_H @@ -25,4 +31,3 @@ extern command_ret_t do_mem_mwc(cmd_tbl_t *, int, int, char * const []); #endif /* CONFIG_MX_CYCLIC */ #endif /* CMD_MEM_H */ - diff --git a/include/command.h b/include/command.h index d0933a0..5582fa5 100644 --- a/include/command.h +++ b/include/command.h @@ -1,3 +1,11 @@ +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ /* * Definitions for Command Processor @@ -37,11 +45,11 @@ typedef enum { struct cmd_tbl_s { const FLASH char *name; /* Command Name */ - int maxargs; /* maximum number of arguments */ - int repeatable; /* autorepeat allowed? */ - /* Implementation function */ + int maxargs; /* maximum number of arguments */ + int repeatable; /* autorepeat allowed? */ + /* Implementation function */ command_ret_t (*cmd)(const FLASH struct cmd_tbl_s *, int, int, char * const []); - const FLASH char *usage; /* Usage message (short) */ + const FLASH char *usage; /* Usage message (short) */ #ifdef CONFIG_SYS_LONGHELP const FLASH char *help; /* Help message (long) */ #endif diff --git a/include/common.h b/include/common.h index b0dd038..cfbbae5 100644 --- a/include/common.h +++ b/include/common.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef COMMON_H #define COMMON_H @@ -53,7 +59,7 @@ struct bits { extern volatile uint_least8_t Stat; #endif /* __AVR__ */ -#define S_10MS_TO (1<<0) +#define S_10MS_TO (1<<0) #define S_MSG_PENDING (1<<1) #define S_CON_PENDING (1<<2) diff --git a/include/con-utils.h b/include/con-utils.h index 15a3ce8..86c0df0 100644 --- a/include/con-utils.h +++ b/include/con-utils.h @@ -1,4 +1,14 @@ -#ifndef CON_UTILS_H +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * Console utilities + */ + +#ifndef CON_UTILS_H #define CON_UTILS_H uint_fast8_t tstc(void); @@ -18,5 +28,3 @@ uint_fast8_t had_ctrlc (void); void clear_ctrlc(void); #endif /* CON_UTILS_H */ - - diff --git a/include/config.h b/include/config.h index d0749b3..f51ebe9 100644 --- a/include/config.h +++ b/include/config.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef CONFIG_H #define CONFIG_H diff --git a/include/crc.h b/include/crc.h index 927b5ff..89cde1f 100644 --- a/include/crc.h +++ b/include/crc.h @@ -1,14 +1,21 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef CRC_H #define CRC_H #ifdef __AVR__ #include static inline -uint16_t crc16(uint16_t crc, uint8_t data) +uint16_t crc16(uint16_t crc, uint8_t data) { return _crc_ccitt_update(crc, data); } #else /* !__AVR__ */ + /* TODO */ #endif /* __AVR__ */ #endif /* CRC_H */ diff --git a/include/debug.h b/include/debug.h index da8e9a0..39c15b0 100644 --- a/include/debug.h +++ b/include/debug.h @@ -1,3 +1,12 @@ +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef DEBUG_H_ #define DEBUG_H_ @@ -10,6 +19,11 @@ #define _DEBUG 0 #endif +/* + * Output a debug text when condition "cond" is met. The "cond" should be + * computed by a preprocessor in the best case, allowing for the best + * optimization. + */ #define debug_cond(cond, fmt, args...) \ do { \ if (cond) \ diff --git a/include/env.h b/include/env.h index 7c4fee9..da38c54 100644 --- a/include/env.h +++ b/include/env.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef ENV_H #define ENV_H @@ -8,9 +14,8 @@ unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long defaul int setenv_ulong(const MEMX char *varname, unsigned long value); int setenv_hex(const MEMX char *varname, unsigned long value); -#if defined(CONFIG_AUTO_COMPLETE) +#if defined(CONFIG_AUTO_COMPLETE) int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf); #endif #endif /* ENV_H */ - diff --git a/include/ffconf.h b/include/ffconf.h index 1399dc2..9841d5b 100644 --- a/include/ffconf.h +++ b/include/ffconf.h @@ -1,4 +1,5 @@ #ifdef __AVR__ #include "avr/ffconf.h" #else + /* TODO */ #endif diff --git a/include/getopt-min.h b/include/getopt-min.h index 9f7729e..6495ebf 100644 --- a/include/getopt-min.h +++ b/include/getopt-min.h @@ -1,12 +1,11 @@ #ifndef GETOPT_MIN_H #define GETOPT_MIN_H -int getopt( /* returns letter, '?', EOF */ - int argc, /* argument count from main */ - char *const argv[], /* argument vector from main */ +int getopt( /* returns letter, '?', EOF */ + int argc, /* argument count from main */ + char *const argv[], /* argument vector from main */ const FLASH char * optstring ); /* allowed args, e.g. "ab:c" */ extern int optind; #endif /* GETOPT_MIN_H */ - diff --git a/include/gpio.h b/include/gpio.h index ac48045..1e0346d 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef GPIO_H #define GPIO_H @@ -14,4 +20,3 @@ int gpio_clockdiv_set(int pin, unsigned long divider); long gpio_clockdiv_get(int pin); #endif /* GPIO_H */ - diff --git a/include/i2c.h b/include/i2c.h index 50b1fd0..f39fa1d 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * Copyright (C) 2009 Sergey Kubushyn * Copyright (C) 2009 - 2013 Heiko Schocher * Changes for multibus/multiadapter I2C support. diff --git a/include/print-utils.h b/include/print-utils.h index 5604d3b..8acf975 100644 --- a/include/print-utils.h +++ b/include/print-utils.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef PRINT_UTILS_H #define PRINT_UTILS_H diff --git a/include/ring.h b/include/ring.h index d57f9aa..b64f462 100644 --- a/include/ring.h +++ b/include/ring.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef RING_H #define RING_H @@ -71,4 +77,3 @@ int_fast8_t ring_is_empty(struct ring *ring) } #endif /* RING_H */ - diff --git a/include/rtc.h b/include/rtc.h index 6946660..ca4c068 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -1,6 +1,9 @@ /* - * Generic RTC interface. + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ */ + #ifndef _RTC_H_ #define _RTC_H_ diff --git a/include/serial.h b/include/serial.h index 40ac815..54c7211 100644 --- a/include/serial.h +++ b/include/serial.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef SERIAL_H #define SERIAL_H diff --git a/include/spi.h b/include/spi.h index 6358f62..1052569 100644 --- a/include/spi.h +++ b/include/spi.h @@ -1,8 +1,7 @@ /* - * spi.h + * (C) Copyright 2009,2014 Leo C. * - * Created on: 17.04.2009 - * Author: leo + * SPDX-License-Identifier: GPL-2.0+ */ #ifndef SPI_H_ diff --git a/include/timer.h b/include/timer.h index bed3eb0..c6d6053 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,7 +1,12 @@ -#ifndef TIMER_H +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef TIMER_H #define TIMER_H uint32_t get_timer(uint32_t); #endif /* TIMER_H */ - diff --git a/include/z180-serv.h b/include/z180-serv.h index af4b1c0..424318f 100644 --- a/include/z180-serv.h +++ b/include/z180-serv.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef Z180_SERV_H #define Z180_SERV_H diff --git a/include/z80-if.h b/include/z80-if.h index d4ee57b..58790bd 100644 --- a/include/z80-if.h +++ b/include/z80-if.h @@ -1,3 +1,8 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ #define ZST_ACQUIRED 0x01 #define ZST_RUNNING 0x02 diff --git a/stm32/debug.h b/stm32/debug.h index d542317..692c879 100644 --- a/stm32/debug.h +++ b/stm32/debug.h @@ -1,3 +1,8 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ #ifndef DEBUG_H_ #define DEBUG_H_ diff --git a/stm32/serial.c b/stm32/serial.c index 9193005..d2f1a93 100644 --- a/stm32/serial.c +++ b/stm32/serial.c @@ -1,8 +1,7 @@ /* - * serial.c + * (C) Copyright 2014 Leo C. * - * Created on: 04.05.2014 - * Author: leo + * SPDX-License-Identifier: GPL-2.0+ */ #include diff --git a/stm32/serial.h b/stm32/serial.h index 1a0f510..62d95e2 100644 --- a/stm32/serial.h +++ b/stm32/serial.h @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef SERIAL_H #define SERIAL_H diff --git a/stm32/z180-stamp-stm32.c b/stm32/z180-stamp-stm32.c index 15d732d..7000c53 100644 --- a/stm32/z180-stamp-stm32.c +++ b/stm32/z180-stamp-stm32.c @@ -1,4 +1,7 @@ /* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -86,26 +89,26 @@ static void clock_setup(void) /* Enable clocks for: GPIO port A (for GPIO_USART1_TX and Button) - GPIO port C (LEDs) + GPIO port C (LEDs) USART1 - TIM16 (RST-Pin) + TIM16 (RST-Pin) TIM1 (IOCS1) */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, - RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN - | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN + rcc_peripheral_enable_clock(&RCC_APB2ENR, + RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN + | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_USART1EN | RCC_APB2ENR_AFIOEN | RCC_APB2ENR_TIM1EN | RCC_APB2ENR_TIM16EN); /* Enable clocks for: TIM3 */ - rcc_peripheral_enable_clock(&RCC_APB1ENR, + rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN); /* Enable clocks for: DMA1 */ - rcc_peripheral_enable_clock(&RCC_AHBENR, + rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_DMA1EN); } @@ -129,19 +132,19 @@ static void nvic_setup(void) static void tim3_setup(void) { TIM3_CR1 = TIM_CR1_CMS_EDGE | TIM_CR1_DIR_UP; - + TIM3_CCMR2 = 0 - | TIM_CCMR2_OC4M_FORCE_LOW + | TIM_CCMR2_OC4M_FORCE_LOW /* | TIM_CCMR2_OC4M_FORCE_HIGH */ /* | TIM_CCMR2_OC4M_PWM2 */ - + /* | TIM_CCMR2_OC4PE */ /* | TIM_CCMR2_OC4FE */ | TIM_CCMR2_CC4S_OUT; - + TIM3_CCER = TIM_CCER_CC4E | TIM_CCER_CC4P; - + TIM3_ARR = 48; /* default */ TIM3_CCR4 = 1; /* */ } @@ -154,7 +157,7 @@ static void gpio_setup(void) Remap TIM3 (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9) Port D0/Port D1 mapping on OSC_IN/OSC_OUT */ - gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, + gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, AFIO_MAPR_SPI1_REMAP | AFIO_MAPR_TIM3_REMAP_FULL_REMAP | AFIO_MAPR_PD01_REMAP); @@ -174,7 +177,7 @@ static void gpio_setup(void) void delay_systicks(int ticks) { int start, stop, now; - + start = STK_CVR; stop = start - ticks; if (stop < 0) { @@ -298,13 +301,13 @@ static void key_timerproc() { // key_state = key_state & key_in | (key_state | key_in) & key_in_last; key_state = c | ((key_in_last | key_in) & key_state); - + // key_state = (key_state&key_in_last) | (key_state&key_in) | (key_in_last&key_in); key_press |= c; - + key_in_last = key_in; - + if ((key_state & REPEAT_MASK) == 0) // check repeat function rpt = REPEAT_START; @@ -330,7 +333,7 @@ void sys_tick_handler(void) Stat |= S_10MS_TO; tick_10ms = 0; - + i = led_timer[0]; if (i) led_timer[0] = i - 1; @@ -339,11 +342,11 @@ void sys_tick_handler(void) led_timer[1] = i - 1; key_timerproc(); - + /* Drive timer procedure of low level disk I/O module */ //disk_timerproc(); } - + count_ms++; if (count_ms == 1000) { count_ms = 0; @@ -366,7 +369,7 @@ void rtc_isr(void) void tim3_set(int mode) { uint16_t cc_mode; - + cc_mode = TIM_CCMR2_CC4S_OUT; TIM3_CR1 = TIM_CR1_CMS_EDGE | TIM_CR1_DIR_UP /*| TIM_CR1_OPM */ ; @@ -380,9 +383,9 @@ void tim3_set(int mode) TIM3_CCR4 = mode/2; cc_mode |= TIM_CCMR2_OC4M_PWM2; } - + TIM3_CCMR2 = cc_mode; - + if (mode > 0) TIM3_CR1 |= TIM_CR1_CEN; } @@ -393,17 +396,17 @@ static uint32_t z80_sram_cmp(uint32_t addr, uint32_t length, uint8_t wval, int i { uint8_t rval; int_fast8_t errors = 0; - + DBG_P(1, "SRAM: Check %#.5x byte... ", length); while (length--) { if ((rval = z80_read(addr)) != wval) { - if (errors == 0) { + if (errors == 0) { printf("\nSRAM: Address W R\n" \ " -------------\n"); // 12345 00 11 } printf(" %.5lx %.2x %.2x\n", addr, wval, rval); - + if (++errors > 16 ) break; } @@ -421,7 +424,7 @@ static void z80_sram_fill(uint32_t addr, int length, uint8_t startval, int inc) printf("SRAM: Write %#.5x byte... ", length); //fflush(stdout); while (length--) { z80_write(addr, startval); - ++addr; + ++addr; startval += inc; } printf("Done.\n"); @@ -465,18 +468,18 @@ const char * const qbcat = "Zhe quick brown fox jumps over the lazy cat!"; uint8_t z80_get_byte(uint32_t adr) { uint8_t data; - + z80_request_bus(); data = z80_read(adr), z80_release_bus(); - + return data; } /*--------------------------------------------------------------------------*/ -static void do_10ms(void) +static void do_10ms(void) { for (uint_fast8_t i = 0; i < 2; i++) { switch (led_stat[i].mode) { @@ -696,19 +699,19 @@ int main(void) z80_reset(HIGH); z80_request_bus(); DBG_P(1, "got it!\n"); - + z80_memset(0, 0x76, 0x80000); //z80_sram_fill(0, 512 * 1024, 0x76, 0); z80_sram_cmp(0, (uint32_t)512 * 1024, 0x76, 0); - + z80_load_mem(); z80_reset(LOW); DBG_P(1, "Bus released!\n"); z80_release_bus(); z80_reset(HIGH); DBG_P(1, "Reset released!\n"); - - + + ledset(0, BLINK1, 50); while (1) { diff --git a/stm32/z80-if.c b/stm32/z80-if.c index 171fea9..6c415d1 100644 --- a/stm32/z80-if.c +++ b/stm32/z80-if.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + /** * * Pin assignments @@ -111,8 +117,8 @@ AFIO_MAPR_SPI1_REMAP AFIO_MAPR2 = -AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON (frees -AFIO_MAPR_SPI1_REMAP +AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON (frees +AFIO_MAPR_SPI1_REMAP */ @@ -220,7 +226,7 @@ AFIO_MAPR_SPI1_REMAP #define IOFIELD_GET(src, width, shift) \ ((src>>shift) & MASK(width)) - + #define CNF_MODE_I_F (GPIO_CNF_INPUT_FLOAT<<2 |GPIO_MODE_INPUT) #define CNF_MODE_O_PP (GPIO_CNF_OUTPUT_PUSHPULL<<2 | GPIO_MODE_OUTPUT_10_MHZ) @@ -249,16 +255,16 @@ static void tim16_setup(void) { RCC_APB2RSTR |= RCC_APB2RSTR_TIM16RST; RCC_APB2RSTR &= ~RCC_APB2RSTR_TIM16RST; - + TIM16_BDTR = TIM_BDTR_MOE; - + TIM16_CCMR1 = 0 - | TIM_CCMR1_OC1M_FORCE_LOW + | TIM_CCMR1_OC1M_FORCE_LOW | TIM_CCMR1_CC1S_OUT; - + TIM16_CCER = TIM_CCER_CC1NE | TIM_CCER_CC1NP; - + TIM16_ARR = 48; /* default */ TIM16_CCR1 = 1; /* */ } @@ -268,7 +274,7 @@ static void tim16_setup(void) static void tim16_set(int mode) { uint16_t cc_mode; - + cc_mode = TIM_CCMR1_CC1S_OUT; TIM16_CR1 = TIM_CR1_OPM; @@ -281,9 +287,9 @@ static void tim16_set(int mode) TIM16_ARR = mode; cc_mode |= TIM_CCMR1_OC1M_PWM2; } - + TIM16_CCMR1 = cc_mode; - + if (mode > 0) TIM16_CR1 |= TIM_CR1_CEN; } @@ -292,44 +298,44 @@ static void tim16_set(int mode) -/* +/* * A0..A6, A8..A13 are buffered. No need to disable. * A7, A14..A18: set to input. */ - + static void z80_setup_adrbus_tristate(void) { #if 0 gpio_set_mode(ADunbuff1_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, MASK(ADunbuff1_WIDTH) << ADunbuff1_SHIFT); - gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, + gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, (MASK(ADunbuff2_WIDTH) << ADunbuff2_SHIFT) | (MASK(ADunbuff3_WIDTH) << ADunbuff3_SHIFT)); #else - GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0))) + GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0))) | (CNF_MODE_I_F << (4 * 0)); GPIO_CRL(GPIOC) = (GPIO_CRL(GPIOC) & ~((0x0f << (4 * 6)) | (0x0f << (4 * 7)))) | ((CNF_MODE_I_F << (4 * 6)) | (CNF_MODE_I_F << (4 * 7))); GPIO_CRH(GPIOC) = (GPIO_CRH(GPIOC) & ~((0x0f << (4*2)) | (0x0f << (4*3)) | (0x0f << (4*4)))) | ((CNF_MODE_I_F << (4*2)) | (CNF_MODE_I_F << (4*3)) | (CNF_MODE_I_F << (4*4))); -#endif +#endif } - + static void z80_setup_adrbus_active(void) { #if 0 gpio_set_mode(ADunbuff1_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, MASK(ADunbuff1_WIDTH) << ADunbuff1_SHIFT); - gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, + gpio_set_mode(ADunbuff2_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, (MASK(ADunbuff2_WIDTH) << ADunbuff2_SHIFT) | (MASK(ADunbuff3_WIDTH) << ADunbuff3_SHIFT)); #else - GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0))) + GPIO_CRH(GPIOA) = (GPIO_CRH(GPIOA) & ~(0x0f << (4 * 0))) | (CNF_MODE_O_PP << (4 * 0)); GPIO_CRL(GPIOC) = (GPIO_CRL(GPIOC) & ~((0x0f << (4 * 6)) | (0x0f << (4 * 7)))) | ((CNF_MODE_O_PP << (4 * 6)) | (CNF_MODE_O_PP << (4 * 7))); GPIO_CRH(GPIOC) = (GPIO_CRH(GPIOC) & ~((0x0f << (4*2)) | (0x0f << (4*3)) | (0x0f << (4*4)))) | ((CNF_MODE_O_PP << (4*2)) | (CNF_MODE_O_PP << (4*3)) | (CNF_MODE_O_PP << (4*4))); -#endif +#endif } @@ -402,9 +408,9 @@ void z80_release_bus(void) void z80_reset(level_t level) { int x = level ? -1 : 0; - + tim16_set(x); - + // Z80_O_RST = level; } @@ -469,7 +475,7 @@ void z80_memset(uint32_t addr, uint8_t data, int length) void z80_write_block(uint8_t *src, uint32_t dest, uint32_t length) { uint8_t data; - + z80_setup_dbus_out(); Z80_O_ME = 0; while(length--) { @@ -488,7 +494,7 @@ void z80_write_block(uint8_t *src, uint32_t dest, uint32_t length) 017B' rx.out_idx: ds 1 ; 017C' rx.buf: ds rx.buf_len ; 018B' rx.buf_end equ $-1 ; last byte (start+len-1) - + 018C' tx.bs_mask: ds 1 ; (buf_len - 1) 018D' tx.in_idx: ds 1 ; 018E' tx.out_idx: ds 1 ; @@ -517,7 +523,7 @@ static struct { idx_in, mask; } fifo_dsc[NUM_FIFOS]; - + void z80_memfifo_init(const fifo_t f, uint32_t adr) { @@ -557,7 +563,7 @@ int z80_memfifo_is_empty(const fifo_t f) int z80_memfifo_is_full(const fifo_t f) { int rc = 1; - + if (fifo_dsc[f].base != 0) { z80_request_bus(); rc = ((fifo_dsc[f].idx_in + 1) & fifo_dsc[f].mask) @@ -570,7 +576,7 @@ int z80_memfifo_is_full(const fifo_t f) uint8_t z80_memfifo_getc(const fifo_t f) { uint8_t rc, idx; - + while (z80_memfifo_is_empty(f)) ; @@ -580,7 +586,7 @@ uint8_t z80_memfifo_getc(const fifo_t f) fifo_dsc[f].idx_out = ++idx & fifo_dsc[f].mask; z80_write(fifo_dsc[f].base+FIFO_INDEX_OUT, fifo_dsc[f].idx_out); z80_release_bus(); - + return rc; } @@ -588,7 +594,7 @@ uint8_t z80_memfifo_getc(const fifo_t f) void z80_memfifo_putc(fifo_t f, uint8_t val) { int idx; - + while (z80_memfifo_is_full(f)) ; @@ -714,7 +720,7 @@ DBG_P(1, "z80_init_msg_fifo: %lx\n", addr); int z80_msg_fifo_getc(void) { int c = -1; - + if (msg_fifo.count != (NELEMS(msg_fifo.buf) - DMA1_CNDTR4)) { c = msg_fifo.buf[msg_fifo.count]; if (++msg_fifo.count == NELEMS(msg_fifo.buf)) diff --git a/stm32/z80-if.h b/stm32/z80-if.h index d7c030d..e65f160 100644 --- a/stm32/z80-if.h +++ b/stm32/z80-if.h @@ -1,3 +1,8 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ typedef enum {LOW, HIGH} level_t; -- cgit v1.2.3 From 2d7d4d213db500871d6869ba470d7751545636f2 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 18 Dec 2014 23:37:42 +0100 Subject: Remove obsolete debug code --- TODO | 1 - TODO.md | 5 +++++ avr/command_tbl.c | 16 ---------------- avr/debug.c | 11 ----------- 4 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 TODO create mode 100644 TODO.md (limited to 'avr') diff --git a/TODO b/TODO deleted file mode 100644 index 7b8d92f..0000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -TODO: eliminate xmalloc diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..8e0686d --- /dev/null +++ b/TODO.md @@ -0,0 +1,5 @@ +TODO List +========= + +- TODO: eliminate xmalloc +- TODO: build time directory as lib diff --git a/avr/command_tbl.c b/avr/command_tbl.c index b70c711..a2f99da 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -30,7 +30,6 @@ extern command_ret_t do_fat_ls(cmd_tbl_t *, int, int, char * const []); //extern command_ret_t do_fat_read(cmd_tbl_t *, int, int, char * const []); //extern command_ret_t do_fat_write(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_fat_rw(cmd_tbl_t *, int, int, char * const []); -extern command_ret_t do_testarg(cmd_tbl_t *, int, int, char * const []); #ifdef CONFIG_SYS_LONGHELP const FLASH char sd_help_text[] = @@ -51,21 +50,6 @@ CMD_TBL_ITEM( ), #ifdef DEBUG -CMD_TBL_ITEM( - test, CONFIG_SYS_MAXARGS, 1, do_testarg, - "print arguments", - "" -), -CMD_TBL_ITEM( - tst1, CONFIG_SYS_MAXARGS, 1, do_testarg, - "print arguments", - "" -), -CMD_TBL_ITEM( - tst2, CONFIG_SYS_MAXARGS, 1, do_testarg, - "print arguments", - "" -), CMD_TBL_ITEM( !mdr, 3, 1, do_dump_mem, diff --git a/avr/debug.c b/avr/debug.c index 5096d59..251ef26 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -122,17 +122,6 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ /*------------------------------------------------------------------------------*/ -command_ret_t do_testarg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - my_puts_P(cmdtp->name); - printf_P(PSTR("\n%s\n"), argv[0]); - - return CMD_RET_SUCCESS; -} - -/*------------------------------------------------------------------------------*/ - - #if 1 struct __freelist { -- cgit v1.2.3 From 2fe283161b59ea1cb419b3711731ea0db343afed Mon Sep 17 00:00:00 2001 From: Leo C Date: Sun, 21 Dec 2014 15:45:29 +0100 Subject: SD slot 0: Enable card detection --- avr/mmc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'avr') diff --git a/avr/mmc.c b/avr/mmc.c index 12f58f3..80152f8 100644 --- a/avr/mmc.c +++ b/avr/mmc.c @@ -131,11 +131,12 @@ void deselect(BYTE drv) SPI_OFF(); if (drv == 0) { -#ifndef SD_CD_0 - // SD_CS_0 = 1; +#ifdef SD_CS_0_IN + SD_CS_0_DDR = 0; + SD_CS_0 = 0; #endif } else { -#ifndef SD_CD_1 +#ifdef SD_CS_1_IN SD_CS_1_DDR = 0; SD_CS_1 = 0; #endif @@ -151,10 +152,14 @@ static int select(BYTE drv) /* 1:Successful, 0:Timeout */ { //debug("*** enter select()\n"); - if (drv == 0) + if (drv == 0) { +#ifdef SD_CS_0_IN + SD_CS_0 = 1; + SD_CS_0_DDR = 1; +#endif SD_CS_0 = 0; - else { -#ifndef SD_CD_1 + } else { +#ifdef SD_CS_1_IN SD_CS_1 = 1; SD_CS_1_DDR = 1; #endif -- cgit v1.2.3 From a036b05f04dd8e3f32c46971b137cf8a8c2aa210 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 23 Dec 2014 10:46:59 +0100 Subject: Correct command date help. command has no reset argument. --- avr/command_tbl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'avr') diff --git a/avr/command_tbl.c b/avr/command_tbl.c index a2f99da..d4ff6f2 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -42,11 +42,10 @@ cmd_tbl_t cmd_tbl[] = { CMD_TBL_ITEM( date, 2, 1, do_date, - "get/set/reset date & time", + "get/set date & time", "[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n" " - without arguments: print date & time\n" " - with numeric argument: set the system date & time\n" - " - with 'reset' argument: reset the RTC" ), #ifdef DEBUG -- cgit v1.2.3 From 11b53d3fc2bf5346bfd2d87191e20b22c5651013 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 23 Dec 2014 10:48:33 +0100 Subject: Don't expose mmc status flag 'STAT_FAST'. (Module private implemantation detail) --- avr/mmc.c | 6 +++--- include/diskio.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'avr') diff --git a/avr/mmc.c b/avr/mmc.c index 80152f8..7c4da24 100644 --- a/avr/mmc.c +++ b/avr/mmc.c @@ -450,7 +450,7 @@ DSTATUS disk_initialize ( if (drv >= MAX_DRV) return STA_NOINIT; /* Supports only single drive */ if (socket[drv].stat & STA_NODISK) - return socket[drv].stat; /* No card in the socket */ + return socket[drv].stat & STAT_MASK; /* No card in the socket */ power_on(drv); /* Force socket power on */ socket[drv].stat &= ~STA_FAST; @@ -505,7 +505,7 @@ DSTATUS disk_initialize ( power_off(drv); } - return socket[drv].stat; + return socket[drv].stat & STAT_MASK; } /*-----------------------------------------------------------------------*/ @@ -518,7 +518,7 @@ DSTATUS disk_status ( { if (drv >= MAX_DRV) return STA_NOINIT; - return socket[drv].stat; + return socket[drv].stat & STAT_MASK; } /*-----------------------------------------------------------------------*/ diff --git a/include/diskio.h b/include/diskio.h index f7a764c..fee87a5 100644 --- a/include/diskio.h +++ b/include/diskio.h @@ -46,6 +46,7 @@ void disk_timerproc (void); #define STA_NODISK 0x02 /* No medium in the drive */ #define STA_PROTECT 0x04 /* Write protected */ #define STA_FAST 0x08 /* Fast SPI clock */ +#define STAT_MASK (STA_NOINIT | STA_NODISK | STA_PROTECT) /* Command code for disk_ioctrl() */ -- cgit v1.2.3 From ce47d431da8ca00d52caffebaafd7ddb817d7b26 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 15 Jan 2015 00:06:03 +0100 Subject: Don't wait forever, if memfifo for console out is not initialized. --- TODO.md | 1 + avr/z80-if.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'avr') diff --git a/TODO.md b/TODO.md index 8e0686d..b952c9d 100644 --- a/TODO.md +++ b/TODO.md @@ -3,3 +3,4 @@ TODO List - TODO: eliminate xmalloc - TODO: build time directory as lib +- TODO: command 'help ' should return success diff --git a/avr/z80-if.c b/avr/z80-if.c index b64e755..d5dc2d7 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -593,7 +593,7 @@ int z80_memfifo_is_empty(const fifo_t f) int z80_memfifo_is_full(const fifo_t f) { - int rc = 1; + int rc = 0; if (fifo_dsc[f].base != 0) { z80_bus_cmd(Request); -- cgit v1.2.3 From c748023ede9e7d8bdbf81ce8c8be2a437607a9e4 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 21 Jan 2015 04:07:19 +0100 Subject: Support for Peter Danneggers fboot. --- avr/command_tbl.c | 5 +++++ avr/con-utils.c | 29 ++++++++++++++++++++++++++++- avr/debug.c | 13 ++++++++++--- avr/main.c | 27 +++++++++++++++++---------- avr/print-utils.c | 7 +++++++ include/config.h | 2 ++ include/print-utils.h | 1 + 7 files changed, 70 insertions(+), 14 deletions(-) (limited to 'avr') diff --git a/avr/command_tbl.c b/avr/command_tbl.c index d4ff6f2..cbd2382 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -60,6 +60,11 @@ CMD_TBL_ITEM( "EEPROM dump", "address [count]" ), +CMD_TBL_ITEM( + !mdf, 3, 1, do_dump_mem, + "FLASH dump", + "address [count]" +), CMD_TBL_ITEM( !cpe, 4, 0, do_eep_cp, "EEPROM copy", diff --git a/avr/con-utils.c b/avr/con-utils.c index f20dbfe..5ee1ff1 100644 --- a/avr/con-utils.c +++ b/avr/con-utils.c @@ -4,9 +4,11 @@ * SPDX-License-Identifier: GPL-2.0+ */ -#include #include "common.h" +#include +#include +#include "config.h" #include "serial.h" #include "background.h" #include "con-utils.h" @@ -26,6 +28,31 @@ int my_getchar(uint_fast8_t waitforchar) c = serial_getc(); } while ((c < 0) && waitforchar); +#ifdef CONFIG_SYS_FBOOTSIG + if (c < 0) + return c; + + static const FLASH unsigned char bootsig[] = {CONFIG_SYS_FBOOTSIG}; + static uint8_t pb; + unsigned char uc = c; + + + if (bootsig[pb] == 0) { + if (uc == 0xff) { + wdt_enable(WDTO_15MS); + for(;;) + ; + } else + pb = 0; + + } else { + if (bootsig[pb] == uc) + pb++; + else + pb = 0; + } +#endif + return c; } diff --git a/avr/debug.c b/avr/debug.c index 251ef26..d4ae1f4 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -49,12 +49,19 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg uint32_t addr; uint32_t length = 128; - if (strchr(argv[0],'r') != NULL) + switch (argv[0][3]) { + case 'r': readhow = ram_read_buf; - else if (strchr(argv[0],'e') != NULL) + break; + case 'e': readhow = eeprom_read_buf; - else + break; + case 'f': + readhow = flash_read_buf; + break; + default: return CMD_RET_USAGE; + } /* Address is specified since argc > 1 */ addr = strtoul(argv[1], NULL, 16); diff --git a/avr/main.c b/avr/main.c index 8bffef9..f4d4c6f 100644 --- a/avr/main.c +++ b/avr/main.c @@ -7,6 +7,7 @@ #include "common.h" #include +#include #include #include @@ -24,11 +25,9 @@ #include "time.h" #include "rtc.h" -static uint8_t mcusr; +uint8_t mcusr __attribute__ ((section (".noinit"))); -/*--------------------------------------------------------------------------*/ #if DEBUG - __attribute__ ((naked)) __attribute__ ((section (".init3"))) void preset_ram (void) { @@ -36,6 +35,21 @@ void preset_ram (void) *p = 0xdd; } +#endif + +__attribute__ ((naked)) __attribute__ ((section (".init3"))) +void get_mcusr (void) +{ + /* save and clear reset reason(s) */ + /* TODO: move to init section? */ + mcusr = MCUSR; + MCUSR = 0; + + wdt_disable(); +} + +/*--------------------------------------------------------------------------*/ +#if DEBUG static const FLASH char * const FLASH rreasons[] = { FSTR("Power on"), @@ -77,13 +91,6 @@ ISR(INT6_vect) static void setup_avr(void) { - /* save and clear reset reason(s) */ - /* TODO: move to init section? */ - mcusr = MCUSR; - MCUSR = 0; - - /* WD */ - /* CPU */ /* Disable JTAG Interface regardless of the JTAGEN fuse setting. */ diff --git a/avr/print-utils.c b/avr/print-utils.c index 3f48620..9ce3e50 100644 --- a/avr/print-utils.c +++ b/avr/print-utils.c @@ -5,6 +5,7 @@ */ #include "common.h" +#include #include #include #include "con-utils.h" @@ -28,6 +29,12 @@ void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count) *buf++ = *(uint8_t *) (size_t) addr++; } +void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count) +{ + while (count--) + *buf++ = *(const __memx uint8_t *) (__uint24) addr++; +} + int dump_mem(uint32_t address, uint32_t offset, uint32_t len, void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title) { diff --git a/include/config.h b/include/config.h index f51ebe9..e40d016 100644 --- a/include/config.h +++ b/include/config.h @@ -40,6 +40,8 @@ #define CONFIG_SYS_PROMPT "=> " #define CONFIG_ESC_CHAR ('^'-0x40) +#define CONFIG_SYS_FBOOTSIG "Peda" + /* TODO: */ //#define CONFIG_CMDLINE_EDITING 1 diff --git a/include/print-utils.h b/include/print-utils.h index 8acf975..7d48287 100644 --- a/include/print-utils.h +++ b/include/print-utils.h @@ -19,5 +19,6 @@ void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title); void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); +void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); #endif /* PRINT_UTILS_H */ -- cgit v1.2.3 From cb52e1e0dbfdf6c6defe20b3711e0c50285748f5 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 21 Jan 2015 14:37:08 +0100 Subject: cli_readline_into_buffer: remove unneeded buf[] --- avr/cli_readline.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'avr') diff --git a/avr/cli_readline.c b/avr/cli_readline.c index 04d32b1..93a0355 100644 --- a/avr/cli_readline.c +++ b/avr/cli_readline.c @@ -12,7 +12,6 @@ */ #include "common.h" - #include #include @@ -562,16 +561,8 @@ static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer my_puts_P(tab_seq + (col & 07)); col += 8 - (col & 07); } else { - char buf[2]; - - /* - * Echo input using puts() to force an - * LCD flush if we are using an LCD - */ ++col; - buf[0] = c; - buf[1] = '\0'; - my_puts(buf); + putchar(c); } *p++ = c; ++n; -- cgit v1.2.3 From 179bc6099854fc3772517d781052b0d9aabc7329 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 18 Apr 2015 02:10:01 +0200 Subject: Add command loadi (load intel hex file) --- avr/Tupfile | 2 +- avr/command_tbl.c | 6 ++ avr/ihex.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 avr/ihex.c (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 78e9744..87eca70 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -7,7 +7,7 @@ FATFS = $(TOP)/fatfs/src/ff.c SRC = main.c SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c -SRC += cmd_sd.c cmd_fat.c +SRC += ihex.c cmd_sd.c cmd_fat.c SRC += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c SRC += timer.c serial.c i2c.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c diff --git a/avr/command_tbl.c b/avr/command_tbl.c index d4ff6f2..2163526 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -16,6 +16,7 @@ extern command_ret_t do_env_default(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_env_set(cmd_tbl_t *, int, int, char * const []); 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_loadihex(cmd_tbl_t *, int, int, char * const []); 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 []); @@ -125,6 +126,11 @@ CMD_TBL_ITEM( "load srec_cat prepared image from controller flash", "" ), +CMD_TBL_ITEM( + loadi, 2, 0, do_loadihex, + "load intel hex file", + "[[-]offset]" +), CMD_TBL_ITEM( go, 2, 0, do_go, "start application at address 'addr'", diff --git a/avr/ihex.c b/avr/ihex.c new file mode 100644 index 0000000..2a9f033 --- /dev/null +++ b/avr/ihex.c @@ -0,0 +1,199 @@ +/* + * (C) Copyright 2015 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "common.h" +#include +#include +#include + +#include "command.h" +#include "con-utils.h" +#include "z80-if.h" +//#include "debug.h" + + +typedef enum { + IHX_OK, + IHX_BROKEN, + IHX_CHKSUMERR +} ihx_rstat_t; + +typedef struct { + ihx_rstat_t status; + int8_t type; + uint8_t len; + uint16_t address; + uint8_t *data; +} ihex_t; + + +static +int get_hexdigit(void) { + + int c; + c = toupper(my_getchar(1)); + if (isxdigit(c)) { + c -= '0'; + if (c > 9) + c -= ('A' - '0' - 10); + return c; + } else + return -1; +} + +static +int get_hexbyte(void) { + + uint8_t i,j; + + if ((i = (uint8_t) get_hexdigit()) < 0x10) + if ((j = (uint8_t) get_hexdigit()) < 0x10) { + return (i<<4) + j; + } + + return -1; +} + +static +ihex_t ihex_get_record() { + + int i; + uint8_t sum, c; + ihex_t rec = { IHX_BROKEN, 0, 0, 0, 0 }; + + + while ((c = my_getchar(0)) != ':') + if (c == 0x03) + return rec; + + if ((i = get_hexbyte()) < 0) /* Start code */ + return rec; + sum = i; + rec.len = i; + if ((i = get_hexbyte()) < 0) /* Byte Count */ + return rec; + sum += i; + rec.address = i * 256; + if ((i = get_hexbyte()) < 0) /* Address */ + return rec; + sum += i; + rec.address += i; + if ((i = get_hexbyte()) < 0) /* Record type */ + return rec; + sum += i; + rec.type = i; + + if (rec.len) { /* Record Data */ + uint8_t *p; int k; + if ((rec.data = malloc(rec.len)) == 0) + return rec; + for (p=rec.data, k=rec.len; k; k--) { + if ((i = get_hexbyte()) < 0) + break; + sum += i; + *p++ = i; + } + if (k) { + free(rec.data); rec.data = 0; + return rec; + } + } + if ((i = get_hexbyte()) < 0) /* Check sum */ + return rec; + sum += i; + if (sum) { + free(rec.data); rec.data = 0; + rec.status = IHX_CHKSUMERR; + } else + rec.status = IHX_OK; + + return rec; +} + + +command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + long offset = 0; + uint32_t base_address = 0; + uint32_t address_low = 0xffffffff; + uint32_t address_high = 0; + bool done = false; + command_ret_t rcode = CMD_RET_FAILURE; + ihex_t rec; + + (void) cmdtp; + (void) flag; + + if (argc > 1) + offset = strtol(argv[1], NULL, 16); + + while (!done) { + rec = ihex_get_record(); + + if (rec.status == IHX_OK) { + switch (rec.type) { + case 0: /* Data record */ + if (rec.len) { + uint32_t addr = base_address + rec.address + offset; + if (addr < address_low) + address_low = addr; + if (addr+rec.len > address_high) + address_high = addr + rec.len; + + z80_bus_cmd(Request); + z80_write_block(rec.data, /* src */ + addr, /* dest */ + rec.len); /* len */ + z80_bus_cmd(Release); + } + continue; + break; + + case 1: /* EOF record */ + + done = true; + break; + + case 2: /* Extended Segment Address Record */ + base_address = ((rec.data[0] << 8) + rec.data[1]) << 4; + continue; + break; + + case 4: /* Extended Linear Address Record */ + base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 16; + continue; + break; + + case 3: /* Start Segment Address Record (ignored)*/ + case 5: /* Start Linear Address Record (ignored)*/ + continue; + break; + + } + + } else + done = true; + } + + switch (rec.status) { + case IHX_OK: + rcode = CMD_RET_SUCCESS; + break; + + case IHX_BROKEN: + case IHX_CHKSUMERR: + printf_P(PSTR("Broken Hex Record or loading interrupted!\n")); + break; + } + + printf_P(PSTR("Data loaded - ")); + if (address_low >= address_high) + printf_P(PSTR("None.\n")); + else + printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, address_high); + + return rcode; +} -- cgit v1.2.3 From ae017d4ce71be2ca45891ff6709f74f4fc963644 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 18 Apr 2015 11:49:04 +0200 Subject: ihex.c fix memory alloc --- avr/ihex.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'avr') diff --git a/avr/ihex.c b/avr/ihex.c index 2a9f033..4e7b1a8 100644 --- a/avr/ihex.c +++ b/avr/ihex.c @@ -90,25 +90,34 @@ ihex_t ihex_get_record() { uint8_t *p; int k; if ((rec.data = malloc(rec.len)) == 0) return rec; + for (p=rec.data, k=rec.len; k; k--) { if ((i = get_hexbyte()) < 0) break; sum += i; *p++ = i; } + if (k) { free(rec.data); rec.data = 0; return rec; } } - if ((i = get_hexbyte()) < 0) /* Check sum */ - return rec; - sum += i; - if (sum) { - free(rec.data); rec.data = 0; - rec.status = IHX_CHKSUMERR; - } else - rec.status = IHX_OK; + + i = get_hexbyte(); /* Check sum */ + + if (i >= 0) { + sum += i; + if (sum == 0) + rec.status = IHX_OK; + else + rec.status = IHX_CHKSUMERR; + } + + if (rec.status != IHX_OK) { + free(rec.data); + rec.data = 0; + } return rec; } @@ -176,6 +185,10 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg } else done = true; + + free(rec.data); + rec.data = 0; + } switch (rec.status) { -- cgit v1.2.3 From 5480dc651411edc6fdeca04ce38749a6d04245a5 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 22 Apr 2015 21:59:58 +0200 Subject: New memory test commands, loadi updates. Needs testing - rename loop to mloop - + mloopw - + mtest - + mdc - + mwc --- avr/cmd_mem.c | 371 +++++++++++++++++++++--------------------------------- avr/command.c | 4 +- avr/command_tbl.c | 12 +- avr/ihex.c | 202 ++++++++++++++++++++++------- include/cmd_mem.h | 3 - include/config.h | 6 +- 6 files changed, 306 insertions(+), 292 deletions(-) (limited to 'avr') diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index 20a4412..53b1842 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -16,13 +16,15 @@ #include "common.h" #include #include +#include #include "command.h" #include "cli_readline.h" #include "print-utils.h" #include "con-utils.h" +#include "timer.h" #include "z80-if.h" -//#include "debug.h" +#include "debug.h" #ifndef CONFIG_SYS_MEMTEST_SCRATCH @@ -222,55 +224,35 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ #ifdef CONFIG_MX_CYCLIC command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - int i; uint32_t count; + uint32_t ts; + + (void) cmdtp; + (void) flag; if (argc < 4) return CMD_RET_USAGE; count = strtoul(argv[3], NULL, 10); + clear_ctrlc(); /* forget any previous Control C */ for (;;) { - do_mem_md (NULL, 0, 3, argv); - - /* delay for ms... */ -/* TODO: use timer */ - for (i=0; i ms... */ -/* TODO: use timer */ - for (i=0; i 0) z80_read(p++); } - z80_bus_cmd(Release); return CMD_RET_SUCCESS; } -#ifdef CONFIG_LOOPW command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { uint32_t addr, length; @@ -457,7 +438,8 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a data = strtoul(argv[3], NULL, 16); - /* We want to optimize the loops to run as fast as possible. + /* + * We want to optimize the loops to run as fast as possible. * If we have only one object, just run infinite loops. */ if (length == 1) { @@ -465,6 +447,7 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a my_puts_P(PSTR("Bus timeout\n")); return CMD_RET_FAILURE; } + cli(); for (;;) z80_write(addr, data); } @@ -473,6 +456,7 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a my_puts_P(PSTR("Bus timeout\n")); return CMD_RET_FAILURE; } + cli(); for (;;) { uint32_t i = length; uint32_t p = addr; @@ -480,35 +464,33 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a z80_write(p++, data); } } -#endif /* CONFIG_LOOPW */ + +//#define CONFIG_SYS_ALT_MEMTEST #ifdef CONFIG_CMD_MEMTEST -static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_addr, - vu_long *dummy) +static uint32_t mem_test_alt(uint32_t start_addr, uint32_t end_addr) { - vu_long *addr; + uint32_t addr; + uint32_t dummy; uint32_t errs = 0; - uint32_t val, readback; - int j; - vu_long offset; - vu_long test_offset; - vu_long pattern; - vu_long temp; - vu_long anti_pattern; - vu_long num_words; - static const FLASH uint32_t bitpattern[] = { - 0x00000001, /* single bit */ - 0x00000003, /* two adjacent bits */ - 0x00000007, /* three adjacent bits */ - 0x0000000F, /* four adjacent bits */ - 0x00000005, /* two non-adjacent bits */ - 0x00000015, /* three non-adjacent bits */ - 0x00000055, /* four non-adjacent bits */ - 0xaaaaaaaa, /* alternating 1/0 */ + uint32_t offset; + uint32_t test_offset; + uint8_t pattern; + uint8_t anti_pattern; + uint8_t temp; + uint32_t num_bytes; + + static const FLASH uint8_t bitpattern[] = { + 0x01, /* single bit */ + 0x03, /* two adjacent bits */ + 0x07, /* three adjacent bits */ + 0x0F, /* four adjacent bits */ + 0x05, /* two non-adjacent bits */ + 0x15, /* three non-adjacent bits */ + 0x55, /* four non-adjacent bits */ + 0xaa, /* alternating 1/0 */ }; - num_words = (end_addr - start_addr) / sizeof(vu_long); - /* * Data line test: write a pattern to the first * location, write the 1's complement to a 'parking' @@ -526,35 +508,39 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add * '0's and '0' bits through a field of '1's (i.e. * pattern and ~pattern). */ - addr = buf; - for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { - val = bitpattern[j]; - for (; val != 0; val <<= 1) { - *addr = val; - *dummy = ~val; /* clear the test data off the bus */ - readback = *addr; - if (readback != val) { + addr = start_addr; + dummy = start_addr+1; + for (unsigned int j = 0; j < ARRAY_SIZE(bitpattern); j++) { + pattern = bitpattern[j]; + for (; pattern != 0; pattern <<= 1) { + anti_pattern = ~pattern; + z80_write(addr, pattern); + z80_write(dummy, anti_pattern); /* clear the test data off the bus */ + temp = z80_read(addr); + if (temp != pattern) { printf_P(PSTR("FAILURE (data line): " - "expected %05lx, actual %05lx\n"), - val, readback); + "expected %02x, actual %02x\n"), + pattern, temp); errs++; - if (ctrlc()) - return -1; } - *addr = ~val; - *dummy = val; - readback = *addr; - if (readback != ~val) { + z80_write(addr, anti_pattern); + z80_write(dummy, pattern); /* clear the test data off the bus */ + temp = z80_read(addr); + if (temp != anti_pattern) { printf_P(PSTR("FAILURE (data line): " - "Is %05lx, should be %05lx\n"), - readback, ~val); + "Is %02x, should be %02x\n"), + temp, anti_pattern); errs++; - if (ctrlc()) - return -1; } } + + if (ctrlc()) + return -1; } + if (errs) + return errs; + /* * Based on code whose Original Author and Copyright * information follows: Copyright (c) 1998 by Michael @@ -589,59 +575,61 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add * * Returns: 0 if the test succeeds, 1 if the test fails. */ - pattern = (vu_long) 0xaaaaaaaa; - anti_pattern = (vu_long) 0x55555555; - debug("%s:%d: length = 0x%.5lx\n", __func__, __LINE__, num_words); + num_bytes = (end_addr - start_addr) / sizeof(uint8_t); + + pattern = 0xaa; + anti_pattern = 0x55; + +// debug("## %s:%d: length = 0x%.5lx\n", __func__, __LINE__, num_bytes); /* * Write the default pattern at each of the * power-of-two offsets. */ - for (offset = 1; offset < num_words; offset <<= 1) - addr[offset] = pattern; + for (offset = 1; offset < num_bytes; offset <<= 1) + z80_write(addr+offset, pattern); /* * Check for address bits stuck high. */ - test_offset = 0; - addr[test_offset] = anti_pattern; + z80_write(start_addr, anti_pattern); - for (offset = 1; offset < num_words; offset <<= 1) { - temp = addr[offset]; + for (offset = 1; offset < num_bytes; offset <<= 1) { + temp = z80_read(start_addr + offset); if (temp != pattern) { - printf_P(PSTR("\nFAILURE: Address bit stuck high @ 0x%.5lx:" - " expected 0x%.5lx, actual 0x%.5lx\n"), - start_addr + offset*sizeof(vu_long), - pattern, temp); + printf_P(PSTR("FAILURE: Address bit stuck high @ 0x%.5lx:" + " expected 0x%.2x, actual 0x%.2x\n"), + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } } - addr[test_offset] = pattern; + z80_write(start_addr, pattern); /* * Check for addr bits stuck low or shorted. */ - for (test_offset = 1; test_offset < num_words; test_offset <<= 1) { - addr[test_offset] = anti_pattern; + for (test_offset = 1; test_offset < num_bytes; test_offset <<= 1) { + z80_write(start_addr + test_offset, anti_pattern); - for (offset = 1; offset < num_words; offset <<= 1) { - temp = addr[offset]; + for (offset = 1; offset < num_bytes; offset <<= 1) { + temp = z80_read(start_addr + offset); if ((temp != pattern) && (offset != test_offset)) { - printf_P(PSTR("\nFAILURE: Address bit stuck low or" - " shorted @ 0x%.5lx: expected 0x%.5lx," - " actual 0x%.5lx\n"), - start_addr + offset*sizeof(vu_long), - pattern, temp); + printf_P(PSTR("FAILURE: Address bit stuck low or shorted" + " @ 0x%.5lx: expected 0x%.2x, actual 0x%.2x\n"), + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } } - addr[test_offset] = pattern; + z80_write(start_addr + test_offset, pattern); } + if (errs) + return errs; + /* * Description: Test the integrity of a physical * memory device by performing an @@ -654,111 +642,50 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add * * Returns: 0 if the test succeeds, 1 if the test fails. */ - num_words++; + num_bytes++; /* * Fill memory with a known pattern. */ - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { - addr[offset] = pattern; - } + for (pattern = 1, addr = start_addr; addr <= end_addr; pattern++, addr++) + z80_write(addr, pattern); /* * Check each location and invert it for the second pass. */ - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { - temp = addr[offset]; + for (pattern = 1, addr = start_addr; addr <= end_addr; pattern++, addr++) { + temp = z80_read(addr); if (temp != pattern) { - printf_P(PSTR("\nFAILURE (read/write) @ 0x%.5lx:" - " expected 0x%.5lx, actual 0x%.5lx)\n"), - start_addr + offset*sizeof(vu_long), - pattern, temp); + printf_P(PSTR("FAILURE (read/write) @ 0x%.5lx:" + " expected 0x%.2x, actual 0x%.2x)\n"), + addr, pattern, temp); errs++; if (ctrlc()) return -1; } anti_pattern = ~pattern; - addr[offset] = anti_pattern; + z80_write(addr, anti_pattern); } /* * Check each location for the inverted pattern and zero it. */ - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { - WATCHDOG_RESET(); + for (pattern = 1, addr = start_addr; addr <= end_addr; pattern++, addr++) { anti_pattern = ~pattern; - temp = addr[offset]; + temp = z80_read(addr); if (temp != anti_pattern) { - printf_P(PSTR("\nFAILURE (read/write): @ 0x%.5lx:" - " expected 0x%.5lx, actual 0x%.5lx)\n"), - start_addr + offset*sizeof(vu_long), - anti_pattern, temp); + printf_P(PSTR("FAILURE (read/write) @ 0x%.5lx:" + " expected 0x%.2x, actual 0x%.2x)\n"), + start_addr, anti_pattern, temp); errs++; if (ctrlc()) return -1; } - addr[offset] = 0; + z80_write(addr, 0); } - return 0; -} - -static uint32_t mem_test_quick(vu_long *buf, uint32_t start_addr, uint32_t end_addr, - vu_long pattern, int iteration) -{ - vu_long *end; - vu_long *addr; - uint32_t errs = 0; - uint32_t incr, length; - uint32_t val, readback; - - /* Alternate the pattern */ - incr = 1; - if (iteration & 1) { - incr = -incr; - /* - * Flip the pattern each time to make lots of zeros and - * then, the next time, lots of ones. We decrement - * the "negative" patterns and increment the "positive" - * patterns to preserve this feature. - */ - if (pattern & 0x80000000) - pattern = -pattern; /* complement & increment */ - else - pattern = ~pattern; - } - length = (end_addr - start_addr) / sizeof(uint32_t); - end = buf + length; - printf_P(PSTR("\rPattern %08lX Writing..." - "%12s" - "\b\b\b\b\b\b\b\b\b\b"), - pattern, ""); - - for (addr = buf, val = pattern; addr < end; addr++) { - *addr = val; - val += incr; - } - - my_puts_P(PSTR("Reading...")); - - for (addr = buf, val = pattern; addr < end; addr++) { - readback = *addr; - if (readback != val) { - uint32_t offset = addr - buf; - - printf_P(PSTR("\nMem error @ 0x%08X: " - "found %08lX, expected %08lX\n"), - (unsigned int)(uintptr_t)(start_addr + offset*sizeof(vu_long)), - readback, val); - errs++; - if (ctrlc()) - return -1; - } - val += incr; - } - - return 0; + return errs; } /* @@ -769,77 +696,61 @@ static uint32_t mem_test_quick(vu_long *buf, uint32_t start_addr, uint32_t end_a command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - uint32_t start, end; - vu_long *buf, *dummy; - int iteration_limit; -/* TODO: command_ret_t */ + uint32_t start = 0; + uint32_t end; + unsigned int iteration_limit = 0; + unsigned int iteration; + uint32_t errs = 0; /* number of errors */ int ret; - uint32_t errs = 0; /* number of errors, or -1 if interrupted */ - uint32_t pattern; - int iteration; -#if defined(CONFIG_SYS_ALT_MEMTEST) - const int alt_test = 1; -#else - const int alt_test = 0; -#endif + + (void) cmdtp; + (void) flag; if (argc > 1) start = strtoul(argv[1], NULL, 16); - else - start = CONFIG_SYS_MEMTEST_START; if (argc > 2) end = strtoul(argv[2], NULL, 16); else - end = CONFIG_SYS_MEMTEST_END; + end = CONFIG_SYS_RAMSIZE_MAX - 1; if (argc > 3) - pattern = (uint32_t)strtoul(argv[3], NULL, 16); - else - pattern = 0; + iteration_limit = (unsigned int) strtoul(argv[3], NULL, 16); - if (argc > 4) - iteration_limit = (uint32_t)strtoul(argv[4], NULL, 16); - else - iteration_limit = 0; + printf_P(PSTR("Testing %05lx ... %05lx:\n"), start, end); +// debug("## %s:%d: start %#05lx end %#05lx\n", __func__, __LINE__, start, end); - printf_P(PSTR("Testing %08x ... %08x:\n"), (unsigned int)start, (unsigned int)end); - debug("%s:%d: start %#05lx end %#05lx\n", __func__, __LINE__, - start, end); + clear_ctrlc(); /* forget any previous Control C */ -/* TODO: */ -// buf = map_sysmem(start, end - start); -// dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); for (iteration = 0; !iteration_limit || iteration < iteration_limit; iteration++) { - if (ctrlc()) { - errs = -1UL; - break; - } printf_P(PSTR("Iteration: %6d\r"), iteration + 1); - debug("\n"); - if (alt_test) { - errs = mem_test_alt(buf, start, end, dummy); - } else { - errs = mem_test_quick(buf, start, end, pattern, - iteration); +// debug("\n"); + + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return CMD_RET_FAILURE; } - if (errs == -1UL) + errs += mem_test_alt(start, end); + z80_bus_cmd(Release); + + if (had_ctrlc() || ctrlc()) { break; + } } - if (errs == -1UL) { + if (had_ctrlc()) { /* Memory test was aborted - write a newline to finish off */ - putc('\n'); - ret = 1; + putchar('\n'); + ret = CMD_RET_FAILURE; } else { printf_P(PSTR("Tested %d iteration(s) with %lu errors.\n"), iteration, errs); - ret = errs != 0; + ret = errs ? CMD_RET_FAILURE : CMD_RET_SUCCESS; } - return ret; /* not reached */ + return ret; } #endif /* CONFIG_CMD_MEMTEST */ diff --git a/avr/command.c b/avr/command.c index b6fa418..46e3a8a 100644 --- a/avr/command.c +++ b/avr/command.c @@ -149,8 +149,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) for (cmdtp = table; cmdtp != table + table_len; cmdtp++) { - if (strncmp_P (cmd, cmdtp->name, len) == 0) { - if (len == strlen (cmdtp->name)) + if (strncmp_P(cmd, cmdtp->name, len) == 0) { + if (len == strlen_P(cmdtp->name)) return cmdtp; /* full match */ cmdtp_temp = cmdtp; /* abbreviated command ? */ diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 2163526..6c1c10d 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -212,23 +212,21 @@ CMD_TBL_ITEM( " - set address offset for memory commands to 'offset'" ), CMD_TBL_ITEM( - loop, 3, 1, do_mem_loop, + mloop, 3, 1, do_mem_loop, "infinite loop on address range", "address number_of_bytes" ), -#ifdef CONFIG_LOOPW CMD_TBL_ITEM( - loopw, 4, 1, do_mem_loopw, + mloopw, 4, 1, do_mem_loopw, "infinite write loop on address range", "address number_of_bytes data_to_write" ), -#endif /* CONFIG_LOOPW */ #ifdef CONFIG_CMD_MEMTEST CMD_TBL_ITEM( - mtest, 5, 1, do_mem_mtest, + mtest, 4, 1, do_mem_mtest, "simple RAM read/write test", - "[start [end [pattern [iterations]]]]" + "[start [end [iterations]]]" ), #endif /* CONFIG_CMD_MEMTEST */ @@ -239,7 +237,7 @@ CMD_TBL_ITEM( "address count delay(ms)" ), CMD_TBL_ITEM( - mwc, 4, 1, do_mem_mwc, + mwc, 4, 1, do_mem_mdc, "memory write cyclic", "address value delay(ms)" ), diff --git a/avr/ihex.c b/avr/ihex.c index 4e7b1a8..01fb6b0 100644 --- a/avr/ihex.c +++ b/avr/ihex.c @@ -15,6 +15,42 @@ //#include "debug.h" +uint32_t detect_ramsize(void) +{ + uint32_t addr; + uint8_t save_addr, save_0; + const uint8_t PATTERN_1 = 0x55; + const uint8_t PATTERN_2 = ~PATTERN_1; + + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return 0; + } + + save_0 = z80_read(0); + z80_write(0, PATTERN_1); + + for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) { + save_addr = z80_read(addr); + z80_write(addr, PATTERN_2); + if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2) + break; + z80_write(addr, save_addr); + } + z80_write(0, save_0); + z80_bus_cmd(Release); + + return addr; +} + +static uint32_t min(uint32_t a, uint32_t b) +{ + if (a < b) + return a; + return b; +} + + typedef enum { IHX_OK, IHX_BROKEN, @@ -26,7 +62,7 @@ typedef struct { int8_t type; uint8_t len; uint16_t address; - uint8_t *data; + uint8_t data[256]; } ihex_t; @@ -57,6 +93,8 @@ int get_hexbyte(void) { return -1; } +#if 0 + static ihex_t ihex_get_record() { @@ -122,73 +160,138 @@ ihex_t ihex_get_record() { return rec; } +#else + +static +int ihex_get_record(ihex_t *rec) { + + int c; + uint8_t sum; + + rec->status = IHX_BROKEN; + + + while ((c = my_getchar(0)) != ':') + if (c == 0x03) + return -1; + + if ((c = get_hexbyte()) < 0) /* Start code */ + return -1; + sum = c; + rec->len = c; + if ((c = get_hexbyte()) < 0) /* Byte Count */ + return -1; + sum += c; + rec->address = c * 256; + if ((c = get_hexbyte()) < 0) /* Address */ + return -1; + sum += c; + rec->address += c; + if ((c = get_hexbyte()) < 0) /* Record type */ + return -1; + sum += c; + rec->type = c; + + if (rec->len) { /* Record Data */ + uint8_t n; + + for (n = 0; n < rec->len; n++) { + if ((c = get_hexbyte()) < 0) + break; + sum += c; + rec->data[n] = c; + } + + if (n < rec->len) { + return -1; + } + } + + c = get_hexbyte(); /* Check sum */ + + if (c >= 0) { + sum += c; + if (sum == 0) + rec->status = IHX_OK; + else + rec->status = IHX_CHKSUMERR; + } + + return rec->len; +} + +#endif command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { long offset = 0; uint32_t base_address = 0; - uint32_t address_low = 0xffffffff; + uint32_t address_max = detect_ramsize(); uint32_t address_high = 0; - bool done = false; + uint32_t address_low = address_max; command_ret_t rcode = CMD_RET_FAILURE; ihex_t rec; - (void) cmdtp; - (void) flag; + (void) cmdtp; (void) flag; + + + printf_P(PSTR("RAM Size: 0x%.5lX\n"), address_max); + if (argc > 1) offset = strtol(argv[1], NULL, 16); - while (!done) { - rec = ihex_get_record(); + while (ihex_get_record(&rec) > 0 && + rec.status == IHX_OK && + rec.type != 1 ) { + + switch (rec.type) { + case 0: /* Data record */ + if (rec.len) { + uint32_t addr = base_address + rec.address + offset; + if (addr < address_low) + address_low = addr; + if (addr+rec.len > address_high) + address_high = addr + rec.len; - if (rec.status == IHX_OK) { - switch (rec.type) { - case 0: /* Data record */ - if (rec.len) { - uint32_t addr = base_address + rec.address + offset; - if (addr < address_low) - address_low = addr; - if (addr+rec.len > address_high) - address_high = addr + rec.len; - z80_bus_cmd(Request); +printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n"), + address_low, address_high, address_max, addr, rec.len); + + if (addr < address_max) { + uint32_t tmplen = address_max - addr; + if (rec.len > tmplen) + rec.len = tmplen; + + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return CMD_RET_FAILURE; + } z80_write_block(rec.data, /* src */ addr, /* dest */ rec.len); /* len */ z80_bus_cmd(Release); } - continue; - break; - - case 1: /* EOF record */ - - done = true; - break; - - case 2: /* Extended Segment Address Record */ - base_address = ((rec.data[0] << 8) + rec.data[1]) << 4; - continue; - break; - - case 4: /* Extended Linear Address Record */ - base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 16; - continue; - break; - - case 3: /* Start Segment Address Record (ignored)*/ - case 5: /* Start Linear Address Record (ignored)*/ - continue; - break; - } + break; - } else - done = true; +#if 0 + case 1: /* EOF record */ + break; +#endif + case 2: /* Extended Segment Address Record */ + base_address = ((rec.data[0] << 8) + rec.data[1]) << 4; + break; - free(rec.data); - rec.data = 0; + case 4: /* Extended Linear Address Record */ + base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 16; + break; + case 3: /* Start Segment Address Record (ignored)*/ + case 5: /* Start Linear Address Record (ignored)*/ + break; + + } } switch (rec.status) { @@ -202,11 +305,16 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg break; } - printf_P(PSTR("Data loaded - ")); - if (address_low >= address_high) + printf_P(PSTR("Data loaded: ")); + if (address_low >= min(address_high, address_max)) printf_P(PSTR("None.\n")); else - printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, address_high); + printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, + min(address_high, address_max) - 1); + + if (address_high > address_max) + printf_P(PSTR("Data above highest RAM address " + "(Range 0x%.5lX...0x%.5lX) ignored!\n"), address_max, address_high - 1); return rcode; } diff --git a/include/cmd_mem.h b/include/cmd_mem.h index 05227cc..782c10a 100644 --- a/include/cmd_mem.h +++ b/include/cmd_mem.h @@ -19,15 +19,12 @@ extern command_ret_t do_mem_cp(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_mem_cmp(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_mem_base(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_mem_loop(cmd_tbl_t *, int, int, char * const []); -#ifdef CONFIG_LOOPW extern command_ret_t do_mem_loopw(cmd_tbl_t *, int, int, char * const []); -#endif #ifdef CONFIG_CMD_MEMTEST extern command_ret_t do_mem_mtest(cmd_tbl_t *, int, int, char * const []); #endif #ifdef CONFIG_MX_CYCLIC extern command_ret_t do_mem_mdc(cmd_tbl_t *, int, int, char * const []); -extern command_ret_t do_mem_mwc(cmd_tbl_t *, int, int, char * const []); #endif /* CONFIG_MX_CYCLIC */ #endif /* CMD_MEM_H */ diff --git a/include/config.h b/include/config.h index f51ebe9..646835d 100644 --- a/include/config.h +++ b/include/config.h @@ -23,9 +23,9 @@ #define CONFIG_BOOTDELAY 4 //#define CONFIG_ZERO_BOOTDELAY_CHECK 1 -//#define CONFIG_LOOPW -//#define CONFIG_CMD_MEMTEST -//#define CONFIG_MX_CYCLIC +#define CONFIG_CMD_MEMTEST +#define CONFIG_MX_CYCLIC +#define CONFIG_SYS_RAMSIZE_MAX (1l<<19) /* max. addressable memory */ #define CONFIG_CMD_DATE 1 -- cgit v1.2.3 From 31033ab3f82c4d00e12fb72a65c2ba614da8ad2f Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 22 Apr 2015 23:30:19 +0200 Subject: Rename ihex.c to cmd_loadihex.c --- avr/Tupfile | 2 +- avr/cmd_loadihex.c | 320 +++++++++++++++++++++++++++++++++++++++++++++++++++++ avr/ihex.c | 320 ----------------------------------------------------- 3 files changed, 321 insertions(+), 321 deletions(-) create mode 100644 avr/cmd_loadihex.c delete mode 100644 avr/ihex.c (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 87eca70..6be8d79 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -7,7 +7,7 @@ FATFS = $(TOP)/fatfs/src/ff.c SRC = main.c SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c -SRC += ihex.c cmd_sd.c cmd_fat.c +SRC += cmd_loadihex.c cmd_sd.c cmd_fat.c SRC += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c SRC += timer.c serial.c i2c.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c new file mode 100644 index 0000000..01fb6b0 --- /dev/null +++ b/avr/cmd_loadihex.c @@ -0,0 +1,320 @@ +/* + * (C) Copyright 2015 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "common.h" +#include +#include +#include + +#include "command.h" +#include "con-utils.h" +#include "z80-if.h" +//#include "debug.h" + + +uint32_t detect_ramsize(void) +{ + uint32_t addr; + uint8_t save_addr, save_0; + const uint8_t PATTERN_1 = 0x55; + const uint8_t PATTERN_2 = ~PATTERN_1; + + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return 0; + } + + save_0 = z80_read(0); + z80_write(0, PATTERN_1); + + for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) { + save_addr = z80_read(addr); + z80_write(addr, PATTERN_2); + if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2) + break; + z80_write(addr, save_addr); + } + z80_write(0, save_0); + z80_bus_cmd(Release); + + return addr; +} + +static uint32_t min(uint32_t a, uint32_t b) +{ + if (a < b) + return a; + return b; +} + + +typedef enum { + IHX_OK, + IHX_BROKEN, + IHX_CHKSUMERR +} ihx_rstat_t; + +typedef struct { + ihx_rstat_t status; + int8_t type; + uint8_t len; + uint16_t address; + uint8_t data[256]; +} ihex_t; + + +static +int get_hexdigit(void) { + + int c; + c = toupper(my_getchar(1)); + if (isxdigit(c)) { + c -= '0'; + if (c > 9) + c -= ('A' - '0' - 10); + return c; + } else + return -1; +} + +static +int get_hexbyte(void) { + + uint8_t i,j; + + if ((i = (uint8_t) get_hexdigit()) < 0x10) + if ((j = (uint8_t) get_hexdigit()) < 0x10) { + return (i<<4) + j; + } + + return -1; +} + +#if 0 + +static +ihex_t ihex_get_record() { + + int i; + uint8_t sum, c; + ihex_t rec = { IHX_BROKEN, 0, 0, 0, 0 }; + + + while ((c = my_getchar(0)) != ':') + if (c == 0x03) + return rec; + + if ((i = get_hexbyte()) < 0) /* Start code */ + return rec; + sum = i; + rec.len = i; + if ((i = get_hexbyte()) < 0) /* Byte Count */ + return rec; + sum += i; + rec.address = i * 256; + if ((i = get_hexbyte()) < 0) /* Address */ + return rec; + sum += i; + rec.address += i; + if ((i = get_hexbyte()) < 0) /* Record type */ + return rec; + sum += i; + rec.type = i; + + if (rec.len) { /* Record Data */ + uint8_t *p; int k; + if ((rec.data = malloc(rec.len)) == 0) + return rec; + + for (p=rec.data, k=rec.len; k; k--) { + if ((i = get_hexbyte()) < 0) + break; + sum += i; + *p++ = i; + } + + if (k) { + free(rec.data); rec.data = 0; + return rec; + } + } + + i = get_hexbyte(); /* Check sum */ + + if (i >= 0) { + sum += i; + if (sum == 0) + rec.status = IHX_OK; + else + rec.status = IHX_CHKSUMERR; + } + + if (rec.status != IHX_OK) { + free(rec.data); + rec.data = 0; + } + + return rec; +} + +#else + +static +int ihex_get_record(ihex_t *rec) { + + int c; + uint8_t sum; + + rec->status = IHX_BROKEN; + + + while ((c = my_getchar(0)) != ':') + if (c == 0x03) + return -1; + + if ((c = get_hexbyte()) < 0) /* Start code */ + return -1; + sum = c; + rec->len = c; + if ((c = get_hexbyte()) < 0) /* Byte Count */ + return -1; + sum += c; + rec->address = c * 256; + if ((c = get_hexbyte()) < 0) /* Address */ + return -1; + sum += c; + rec->address += c; + if ((c = get_hexbyte()) < 0) /* Record type */ + return -1; + sum += c; + rec->type = c; + + if (rec->len) { /* Record Data */ + uint8_t n; + + for (n = 0; n < rec->len; n++) { + if ((c = get_hexbyte()) < 0) + break; + sum += c; + rec->data[n] = c; + } + + if (n < rec->len) { + return -1; + } + } + + c = get_hexbyte(); /* Check sum */ + + if (c >= 0) { + sum += c; + if (sum == 0) + rec->status = IHX_OK; + else + rec->status = IHX_CHKSUMERR; + } + + return rec->len; +} + +#endif + +command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + long offset = 0; + uint32_t base_address = 0; + uint32_t address_max = detect_ramsize(); + uint32_t address_high = 0; + uint32_t address_low = address_max; + command_ret_t rcode = CMD_RET_FAILURE; + ihex_t rec; + + (void) cmdtp; (void) flag; + + + printf_P(PSTR("RAM Size: 0x%.5lX\n"), address_max); + + + if (argc > 1) + offset = strtol(argv[1], NULL, 16); + + while (ihex_get_record(&rec) > 0 && + rec.status == IHX_OK && + rec.type != 1 ) { + + switch (rec.type) { + case 0: /* Data record */ + if (rec.len) { + uint32_t addr = base_address + rec.address + offset; + if (addr < address_low) + address_low = addr; + if (addr+rec.len > address_high) + address_high = addr + rec.len; + + +printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n"), + address_low, address_high, address_max, addr, rec.len); + + if (addr < address_max) { + uint32_t tmplen = address_max - addr; + if (rec.len > tmplen) + rec.len = tmplen; + + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return CMD_RET_FAILURE; + } + z80_write_block(rec.data, /* src */ + addr, /* dest */ + rec.len); /* len */ + z80_bus_cmd(Release); + } + } + break; + +#if 0 + case 1: /* EOF record */ + break; +#endif + case 2: /* Extended Segment Address Record */ + base_address = ((rec.data[0] << 8) + rec.data[1]) << 4; + break; + + case 4: /* Extended Linear Address Record */ + base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 16; + break; + + case 3: /* Start Segment Address Record (ignored)*/ + case 5: /* Start Linear Address Record (ignored)*/ + break; + + } + } + + switch (rec.status) { + case IHX_OK: + rcode = CMD_RET_SUCCESS; + break; + + case IHX_BROKEN: + case IHX_CHKSUMERR: + printf_P(PSTR("Broken Hex Record or loading interrupted!\n")); + break; + } + + printf_P(PSTR("Data loaded: ")); + if (address_low >= min(address_high, address_max)) + printf_P(PSTR("None.\n")); + else + printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, + min(address_high, address_max) - 1); + + if (address_high > address_max) + printf_P(PSTR("Data above highest RAM address " + "(Range 0x%.5lX...0x%.5lX) ignored!\n"), address_max, address_high - 1); + + return rcode; +} diff --git a/avr/ihex.c b/avr/ihex.c deleted file mode 100644 index 01fb6b0..0000000 --- a/avr/ihex.c +++ /dev/null @@ -1,320 +0,0 @@ -/* - * (C) Copyright 2015 Leo C. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include "common.h" -#include -#include -#include - -#include "command.h" -#include "con-utils.h" -#include "z80-if.h" -//#include "debug.h" - - -uint32_t detect_ramsize(void) -{ - uint32_t addr; - uint8_t save_addr, save_0; - const uint8_t PATTERN_1 = 0x55; - const uint8_t PATTERN_2 = ~PATTERN_1; - - if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { - my_puts_P(PSTR("Bus timeout\n")); - return 0; - } - - save_0 = z80_read(0); - z80_write(0, PATTERN_1); - - for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) { - save_addr = z80_read(addr); - z80_write(addr, PATTERN_2); - if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2) - break; - z80_write(addr, save_addr); - } - z80_write(0, save_0); - z80_bus_cmd(Release); - - return addr; -} - -static uint32_t min(uint32_t a, uint32_t b) -{ - if (a < b) - return a; - return b; -} - - -typedef enum { - IHX_OK, - IHX_BROKEN, - IHX_CHKSUMERR -} ihx_rstat_t; - -typedef struct { - ihx_rstat_t status; - int8_t type; - uint8_t len; - uint16_t address; - uint8_t data[256]; -} ihex_t; - - -static -int get_hexdigit(void) { - - int c; - c = toupper(my_getchar(1)); - if (isxdigit(c)) { - c -= '0'; - if (c > 9) - c -= ('A' - '0' - 10); - return c; - } else - return -1; -} - -static -int get_hexbyte(void) { - - uint8_t i,j; - - if ((i = (uint8_t) get_hexdigit()) < 0x10) - if ((j = (uint8_t) get_hexdigit()) < 0x10) { - return (i<<4) + j; - } - - return -1; -} - -#if 0 - -static -ihex_t ihex_get_record() { - - int i; - uint8_t sum, c; - ihex_t rec = { IHX_BROKEN, 0, 0, 0, 0 }; - - - while ((c = my_getchar(0)) != ':') - if (c == 0x03) - return rec; - - if ((i = get_hexbyte()) < 0) /* Start code */ - return rec; - sum = i; - rec.len = i; - if ((i = get_hexbyte()) < 0) /* Byte Count */ - return rec; - sum += i; - rec.address = i * 256; - if ((i = get_hexbyte()) < 0) /* Address */ - return rec; - sum += i; - rec.address += i; - if ((i = get_hexbyte()) < 0) /* Record type */ - return rec; - sum += i; - rec.type = i; - - if (rec.len) { /* Record Data */ - uint8_t *p; int k; - if ((rec.data = malloc(rec.len)) == 0) - return rec; - - for (p=rec.data, k=rec.len; k; k--) { - if ((i = get_hexbyte()) < 0) - break; - sum += i; - *p++ = i; - } - - if (k) { - free(rec.data); rec.data = 0; - return rec; - } - } - - i = get_hexbyte(); /* Check sum */ - - if (i >= 0) { - sum += i; - if (sum == 0) - rec.status = IHX_OK; - else - rec.status = IHX_CHKSUMERR; - } - - if (rec.status != IHX_OK) { - free(rec.data); - rec.data = 0; - } - - return rec; -} - -#else - -static -int ihex_get_record(ihex_t *rec) { - - int c; - uint8_t sum; - - rec->status = IHX_BROKEN; - - - while ((c = my_getchar(0)) != ':') - if (c == 0x03) - return -1; - - if ((c = get_hexbyte()) < 0) /* Start code */ - return -1; - sum = c; - rec->len = c; - if ((c = get_hexbyte()) < 0) /* Byte Count */ - return -1; - sum += c; - rec->address = c * 256; - if ((c = get_hexbyte()) < 0) /* Address */ - return -1; - sum += c; - rec->address += c; - if ((c = get_hexbyte()) < 0) /* Record type */ - return -1; - sum += c; - rec->type = c; - - if (rec->len) { /* Record Data */ - uint8_t n; - - for (n = 0; n < rec->len; n++) { - if ((c = get_hexbyte()) < 0) - break; - sum += c; - rec->data[n] = c; - } - - if (n < rec->len) { - return -1; - } - } - - c = get_hexbyte(); /* Check sum */ - - if (c >= 0) { - sum += c; - if (sum == 0) - rec->status = IHX_OK; - else - rec->status = IHX_CHKSUMERR; - } - - return rec->len; -} - -#endif - -command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - long offset = 0; - uint32_t base_address = 0; - uint32_t address_max = detect_ramsize(); - uint32_t address_high = 0; - uint32_t address_low = address_max; - command_ret_t rcode = CMD_RET_FAILURE; - ihex_t rec; - - (void) cmdtp; (void) flag; - - - printf_P(PSTR("RAM Size: 0x%.5lX\n"), address_max); - - - if (argc > 1) - offset = strtol(argv[1], NULL, 16); - - while (ihex_get_record(&rec) > 0 && - rec.status == IHX_OK && - rec.type != 1 ) { - - switch (rec.type) { - case 0: /* Data record */ - if (rec.len) { - uint32_t addr = base_address + rec.address + offset; - if (addr < address_low) - address_low = addr; - if (addr+rec.len > address_high) - address_high = addr + rec.len; - - -printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n"), - address_low, address_high, address_max, addr, rec.len); - - if (addr < address_max) { - uint32_t tmplen = address_max - addr; - if (rec.len > tmplen) - rec.len = tmplen; - - if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { - my_puts_P(PSTR("Bus timeout\n")); - return CMD_RET_FAILURE; - } - z80_write_block(rec.data, /* src */ - addr, /* dest */ - rec.len); /* len */ - z80_bus_cmd(Release); - } - } - break; - -#if 0 - case 1: /* EOF record */ - break; -#endif - case 2: /* Extended Segment Address Record */ - base_address = ((rec.data[0] << 8) + rec.data[1]) << 4; - break; - - case 4: /* Extended Linear Address Record */ - base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 16; - break; - - case 3: /* Start Segment Address Record (ignored)*/ - case 5: /* Start Linear Address Record (ignored)*/ - break; - - } - } - - switch (rec.status) { - case IHX_OK: - rcode = CMD_RET_SUCCESS; - break; - - case IHX_BROKEN: - case IHX_CHKSUMERR: - printf_P(PSTR("Broken Hex Record or loading interrupted!\n")); - break; - } - - printf_P(PSTR("Data loaded: ")); - if (address_low >= min(address_high, address_max)) - printf_P(PSTR("None.\n")); - else - printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, - min(address_high, address_max) - 1); - - if (address_high > address_max) - printf_P(PSTR("Data above highest RAM address " - "(Range 0x%.5lX...0x%.5lX) ignored!\n"), address_max, address_high - 1); - - return rcode; -} -- cgit v1.2.3 From d264541a3e7fe756695f811136d7a89e8e7ec478 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 23 Apr 2015 02:28:53 +0200 Subject: loadi seems to work now. --- avr/cmd_loadihex.c | 95 ++++-------------------------------------------------- include/common.h | 6 ++++ 2 files changed, 13 insertions(+), 88 deletions(-) (limited to 'avr') diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c index 01fb6b0..debccd7 100644 --- a/avr/cmd_loadihex.c +++ b/avr/cmd_loadihex.c @@ -12,7 +12,7 @@ #include "command.h" #include "con-utils.h" #include "z80-if.h" -//#include "debug.h" +#include "debug.h" uint32_t detect_ramsize(void) @@ -43,14 +43,6 @@ uint32_t detect_ramsize(void) return addr; } -static uint32_t min(uint32_t a, uint32_t b) -{ - if (a < b) - return a; - return b; -} - - typedef enum { IHX_OK, IHX_BROKEN, @@ -93,74 +85,6 @@ int get_hexbyte(void) { return -1; } -#if 0 - -static -ihex_t ihex_get_record() { - - int i; - uint8_t sum, c; - ihex_t rec = { IHX_BROKEN, 0, 0, 0, 0 }; - - - while ((c = my_getchar(0)) != ':') - if (c == 0x03) - return rec; - - if ((i = get_hexbyte()) < 0) /* Start code */ - return rec; - sum = i; - rec.len = i; - if ((i = get_hexbyte()) < 0) /* Byte Count */ - return rec; - sum += i; - rec.address = i * 256; - if ((i = get_hexbyte()) < 0) /* Address */ - return rec; - sum += i; - rec.address += i; - if ((i = get_hexbyte()) < 0) /* Record type */ - return rec; - sum += i; - rec.type = i; - - if (rec.len) { /* Record Data */ - uint8_t *p; int k; - if ((rec.data = malloc(rec.len)) == 0) - return rec; - - for (p=rec.data, k=rec.len; k; k--) { - if ((i = get_hexbyte()) < 0) - break; - sum += i; - *p++ = i; - } - - if (k) { - free(rec.data); rec.data = 0; - return rec; - } - } - - i = get_hexbyte(); /* Check sum */ - - if (i >= 0) { - sum += i; - if (sum == 0) - rec.status = IHX_OK; - else - rec.status = IHX_CHKSUMERR; - } - - if (rec.status != IHX_OK) { - free(rec.data); - rec.data = 0; - } - - return rec; -} - -#else static int ihex_get_record(ihex_t *rec) { @@ -220,7 +144,6 @@ int ihex_get_record(ihex_t *rec) { return rec->len; } -#endif command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -235,9 +158,6 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg (void) cmdtp; (void) flag; - printf_P(PSTR("RAM Size: 0x%.5lX\n"), address_max); - - if (argc > 1) offset = strtol(argv[1], NULL, 16); @@ -254,9 +174,8 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg if (addr+rec.len > address_high) address_high = addr + rec.len; - -printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n"), - address_low, address_high, address_max, addr, rec.len); +// debug("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n", +// address_low, address_high, address_max, addr, rec.len); if (addr < address_max) { uint32_t tmplen = address_max - addr; @@ -280,7 +199,7 @@ printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d break; #endif case 2: /* Extended Segment Address Record */ - base_address = ((rec.data[0] << 8) + rec.data[1]) << 4; + base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 4; break; case 4: /* Extended Linear Address Record */ @@ -306,15 +225,15 @@ printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d } printf_P(PSTR("Data loaded: ")); - if (address_low >= min(address_high, address_max)) + if (address_low >= MIN(address_high, address_max)) printf_P(PSTR("None.\n")); else printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, - min(address_high, address_max) - 1); + MIN(address_high, address_max) - 1); if (address_high > address_max) printf_P(PSTR("Data above highest RAM address " - "(Range 0x%.5lX...0x%.5lX) ignored!\n"), address_max, address_high - 1); + "(in range 0x%.5lX - 0x%.5lX) ignored!\n"), address_max, address_high - 1); return rcode; } diff --git a/include/common.h b/include/common.h index cfbbae5..10c4417 100644 --- a/include/common.h +++ b/include/common.h @@ -52,6 +52,12 @@ struct bits { #define FSTR(X) ((const FLASH char[]) { X } ) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define MIN(a,b) ({ typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a < _b ? _a : _b; }) +#define MAX(a,b) ({ typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a > _b ? _a : _b; }) #ifdef __AVR__ #define Stat GPIOR0 -- cgit v1.2.3 From 4cbc8d3ed4e0d5624872ead9f8519b1cea8cf5ac Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 28 Apr 2015 19:14:23 +0200 Subject: intel hex: flush input buffer after loading --- avr/cmd_loadihex.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'avr') diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c index debccd7..aaee064 100644 --- a/avr/cmd_loadihex.c +++ b/avr/cmd_loadihex.c @@ -224,6 +224,10 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg break; } + /* flush input buffer */ + while (my_getchar(0) > 0) + ; + printf_P(PSTR("Data loaded: ")); if (address_low >= MIN(address_high, address_max)) printf_P(PSTR("None.\n")); -- cgit v1.2.3 From 2fe441224da6410ec112322abf78524589b15498 Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 1 May 2015 20:43:26 +0200 Subject: Add polling driver for ASCI0/1 --- avr/command_tbl.c | 2 +- z180/Tupfile | 4 +- z180/asci-p.180 | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ z180/bioscio.180 | 2 +- z180/chario.180 | 29 ++++++++---- z180/init.180 | 66 ++++++++++++++++++++++----- z180/z180reg.inc | 7 +++ 7 files changed, 218 insertions(+), 25 deletions(-) create mode 100644 z180/asci-p.180 (limited to 'avr') diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 6c1c10d..b3c401c 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -150,7 +150,7 @@ CMD_TBL_ITEM( "" ), CMD_TBL_ITEM( - connect, 1, 1, do_console, + connect, 1, 0, do_console, "Connect to CPU console i/o", "" ), diff --git a/z180/Tupfile b/z180/Tupfile index 46aae4e..23855f8 100644 --- a/z180/Tupfile +++ b/z180/Tupfile @@ -4,8 +4,8 @@ PROG = hdrom SRC = init.180 SRC += ddtz.180 -#SRC += fifoio.180 msgbuf.180 asci1-i.180 console.180 -SRC += msgbuf-a.180 conbuf-a.180 asci1-i.180 bioscio.180 chario.180 +#SRC += fifoio.180 msgbuf.180 asci-p.180 console.180 +SRC += msgbuf-a.180 conbuf-a.180 asci-p.180 bioscio.180 chario.180 # serial (asci1) console only: #SRC += asci1-i.180 console.180 SRC += romend.180 diff --git a/z180/asci-p.180 b/z180/asci-p.180 new file mode 100644 index 0000000..956faf1 --- /dev/null +++ b/z180/asci-p.180 @@ -0,0 +1,133 @@ + page 200 + + extrn ioiniml + + global as0init + global as0ista,as0inp + global as0osta,as0out + global as1init + global as1ista,as1inp + global as1osta,as1out + + include config.inc + include z180reg.inc + + +;----------------------------------------------------- +; +; +; TC = (f PHI /(2*baudrate*Clock_mode)) - 2 +; +; TC = (f PHI / (32 * baudrate)) - 2 +; + + cseg +; +; Init Serial I/O for console input and output (ASCI1) +; + + + +as0init: + ld hl,initab0 + jp ioiniml + +as1init: + ld hl,initab1 + jp ioiniml + + + ld a,M_MPBT + out0 (cntlb1),a + ld a,M_RE + M_TE + M_MOD2 ;Rx/Tx enable + out0 (cntla1),a + ld a,M_RIE + out0 (stat1),a ;Enable rx interrupts + + ret ; + + +initab0: + db 1,stat0,0 ;Disable rx/tx interrupts + ;Enable baud rate generator + db 1,asext0,M_BRGMOD+M_DCD0DIS+M_CTS0DIS + db 2,astc0l,low 28, high 28 + db 1,cntlb0,M_MPBT ;No MP Mode, X16 + db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1 + db 0 + +initab1: + db 1,stat1,0 ;Disable rx/tx ints, disable CTS1 + db 1,asext1,M_BRGMOD ;Enable baud rate generator + db 2,astc1l,low 3, high 3 + db 1,cntlb1,M_MPBT ;No MP Mode, X16 + db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1 + db 0 + + + +as0ista: + in0 a,(stat0) + and M_RDRF + ret z + or 0ffh + ret + +as1ista: + in0 a,(stat1) + and M_RDRF + ret z + or 0ffh + ret + + +as0inp: + in0 a,(stat0) + rlca + jr nc,as0inp + in0 a,rdr0 + ret + +as1inp: + in0 a,(stat1) + rlca + jr nc,as1inp + in0 a,rdr1 + ret + + + +as0osta: + in0 a,(stat0) + and M_TDRE + ret z + or 0ffh + ret + +as1osta: + in0 a,(stat1) + and M_TDRE + ret z + or 0ffh + ret + + +as0out: + in0 a,(stat0) + and M_TDRE + jr z,as0out + out0 (tdr0),c + ld a,c + ret + +as1out: + in0 a,(stat1) + and M_TDRE + jr z,as1out + out0 (tdr1),c + ld a,c + ret + + end + + diff --git a/z180/bioscio.180 b/z180/bioscio.180 index b0fd4da..2d8e5e0 100644 --- a/z180/bioscio.180 +++ b/z180/bioscio.180 @@ -66,7 +66,7 @@ c$init$loop: jp p,c$init$loop ; ld hl,1000000000000000b ; assign console to HOST - ld hl,0100000000000000b ; assign console to ASCI1 + ld hl,0010000000000000b ; assign console to ASCI1 ld (@civec),hl ld (@covec),hl ld hl,0000000000000000b ; assign auxiliary to nothing diff --git a/z180/chario.180 b/z180/chario.180 index 6632690..8313658 100644 --- a/z180/chario.180 +++ b/z180/chario.180 @@ -8,14 +8,15 @@ public @ctbl extrn ff.init,ff.i.st,ff.in,ff.o.st,ff.out - extrn ser.init,ser.ist,ser.in,ser.ost,ser.out + extrn as0init,as0ista,as0inp,as0osta,as0out + extrn as1init,as1ista,as1inp,as1osta,as1out include config.inc include z180reg.inc include modebaud.inc ; define mode bits and baud eqautes -max$device equ 2 +max$device equ 3 cseg @@ -25,7 +26,8 @@ max$device equ 2 ld b,c call vector$io dw ff.init - dw ser.init + dw as0init + dw as1init dw rret ; b = device, c = output char, a = input char @@ -33,25 +35,29 @@ max$device equ 2 ?ci: ; character input call vector$io dw ff.in - dw ser.in + dw as0inp + dw as1inp dw null$input ?cist: ; character input status call vector$io dw ff.i.st - dw ser.ist + dw as0ista + dw as1ista dw null$status ?co: ; character output call vector$io dw ff.out - dw ser.out + dw as0out + dw as1out dw rret ?cost: ; character output status call vector$io dw ff.o.st - dw ser.ost + dw as0osta + dw as1osta dw ret$true vector$io: @@ -89,10 +95,15 @@ null$status: @ctbl: db 'HOST ' ; device 0 - db mb$output + db mb$in$out db baud$none - db 'ASCI1 ' ; device 0 + db 'ASCI1 ' ; device 1 + db mb$in$out+mb$serial+mb$soft$baud +ser0$baud: + db baud$19200 + + db 'ASCI1 ' ; device 2 db mb$in$out+mb$serial+mb$soft$baud ser1$baud: db baud$19200 diff --git a/z180/init.180 b/z180/init.180 index 0bd37c1..39b03fc 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -5,7 +5,6 @@ extrn $stack extrn charini,?const,?conin extrn ?cono,?conos - extrn romend @@ -75,14 +74,12 @@ start: hwini0: if CPU_Z180 - db 3 ;count db rcr,CREFSH ;configure DRAM refresh db dcntl,INIWAITS ;wait states db cbar,SYS$CBAR - else - db 0 endif + db 0 if CPU_Z180 dmclrt: ;clear ram per dma @@ -95,6 +92,7 @@ nullbyte: db 00h ;dst dw 0-romend ;count (64k) dmct_e: + db 0 endif @@ -165,7 +163,7 @@ kstart: if 0 ld hl,dmclrt ;load DMA registers - call io.ini.m + call ioiniml ld a,0cbh ;01ef dst +1, src fixed, burst out0 (dmode),a ;01f1 @@ -434,7 +432,7 @@ prt0_init: inc hl ld (hl),high iprt0 ld hl,prt0itab - call io.ini.m + call ioiniml ret prt0itab: @@ -444,6 +442,7 @@ prt0itab: dw PRT_TC10MS db M_TIE0+M_TDE0 ;enable timer 0 interrupt and down count. prt0it_e: + db 0 endif @@ -451,24 +450,55 @@ prt0it_e: ;---------------------------------------------------------------------- ; + if CPU_Z180 io.ini: + if 0 push bc - if CPU_Z180 - ld b,0 ;high byte port adress +ioi_nxt: ld a,(hl) ;count inc hl or a jr z,ioi_e -ioi_1: + ld c,(hl) ;port address inc hl +ioi_r: outi inc b ;outi decrements b dec a - jr nz,ioi_1 + jr nz,ioi_r + jr ioi_nxt ioi_e: + pop bc + ret + + else ;(if 1/0) + + push bc + jr ioi_nxt +ioi_l: + ld c,(hl) ;port address + inc hl + inc c +ioi_r: + dec c ;otim increments c + otim + jr z,ioi_r +ioi_nxt: + ld b,(hl) ;count + inc hl + inc b ;stop if count == 0 + djnz ioi_l + pop bc + ret + + endif ;(1/0) + else + +io.ini: + push bc jr ioi_nxt ioi_l: ld c,(hl) ;port address @@ -483,16 +513,28 @@ ioi_nxt: pop bc ret +;---------------------------------------------------------------------- + if CPU_Z180 -io.ini.m: + + global ioiniml + +ioiniml: push bc + xor a +ioml_lp: ld b,(hl) inc hl + cp b + jr z,ioml_e + ld c,(hl) inc hl otimr + jr ioml_lp +ioml_e: pop bc - ret + ret z endif io.ini.l: diff --git a/z180/z180reg.inc b/z180/z180reg.inc index 5bbd088..271a446 100644 --- a/z180/z180reg.inc +++ b/z180/z180reg.inc @@ -76,6 +76,13 @@ tcr equ IOBASE+10h ;Timer Control Register asext0 equ IOBASE+12h ;ASCI Extension Control Register asext1 equ IOBASE+13h ;ASCI Extension Control Register + b2m DCD0DIS,6 ;DCD0 Disable + b2m CTS0DIS,5 ;CTS0 Disable + b2m X1,4 ;CKA * 1 Clock/Samle Rate Divider + b2m BRGMOD,3 ;BRG Mode (Baud rate generator) + b2m BREAKEN,2 ;Break Enable + b2m BREAK,1 ;Break detected + b2m SENDBREAK,0 ;Send Break tmdr1l equ IOBASE+14h ;Timer Data Register Channel 1 tmdr1h equ IOBASE+15h ; -- cgit v1.2.3 From bf5870430d2d1903b6dcdf1431d80b261f9a5d45 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 5 May 2015 15:41:33 +0200 Subject: loadi cosmetic changes --- avr/cmd_loadihex.c | 34 ++++++++++++++++++++++++++-------- avr/command_tbl.c | 5 +++-- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'avr') diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c index aaee064..18d5331 100644 --- a/avr/cmd_loadihex.c +++ b/avr/cmd_loadihex.c @@ -93,11 +93,17 @@ int ihex_get_record(ihex_t *rec) { uint8_t sum; rec->status = IHX_BROKEN; + rec->len = 0; + rec->type = 0xff; - - while ((c = my_getchar(0)) != ':') + while ((c = my_getchar(0)) != ':') { if (c == 0x03) - return -1; + return -1; /* Control-C */ + if (c == 0x04) { + rec->status = IHX_OK; + return 0; /*Control-D, EOF */ + } + } if ((c = get_hexbyte()) < 0) /* Start code */ return -1; @@ -154,6 +160,7 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg uint32_t address_low = address_max; command_ret_t rcode = CMD_RET_FAILURE; ihex_t rec; + bool firstrec = true; (void) cmdtp; (void) flag; @@ -161,12 +168,18 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg if (argc > 1) offset = strtol(argv[1], NULL, 16); + printf_P(PSTR("Waiting for Intel Hex Records...\n")); + while (ihex_get_record(&rec) > 0 && rec.status == IHX_OK && rec.type != 1 ) { switch (rec.type) { case 0: /* Data record */ + if (firstrec) { + printf_P(PSTR("Loading: 0x.....")); + firstrec = false; + } if (rec.len) { uint32_t addr = base_address + rec.address + offset; if (addr < address_low) @@ -176,7 +189,7 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg // debug("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n", // address_low, address_high, address_max, addr, rec.len); - + printf_P(PSTR("\b\b\b\b\b%.5lX"), addr); if (addr < address_max) { uint32_t tmplen = address_max - addr; if (rec.len > tmplen) @@ -224,11 +237,16 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg break; } - /* flush input buffer */ - while (my_getchar(0) > 0) - ; - printf_P(PSTR("Data loaded: ")); + for (uint_fast8_t i=0; i<100; ++i) { + /* flush input buffer */ + while (my_getchar(0) > 0) + ; + udelay(1000); + } + + + printf_P(PSTR("\nData loaded: ")); if (address_low >= MIN(address_high, address_max)) printf_P(PSTR("None.\n")); else diff --git a/avr/command_tbl.c b/avr/command_tbl.c index b3c401c..23d0803 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -128,8 +128,9 @@ CMD_TBL_ITEM( ), CMD_TBL_ITEM( loadi, 2, 0, do_loadihex, - "load intel hex file", - "[[-]offset]" + "load intel hex file over serial line", + "[[-]offset]\n" + " - load Intel-Hex-Record file over serial line with offset 'offset'" ), CMD_TBL_ITEM( go, 2, 0, do_go, -- cgit v1.2.3 From c0abd68b350ffd9852923a66f3ee6c315c94813a Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 6 May 2015 12:18:39 +0200 Subject: New command 'loadcpm3' - load 'CPM3.SYS' file. setenv() bugfix Arg 1 of function setenv() is a __MEMX pointer on AVR. --- TODO.md | 1 + avr/Tupfile | 2 +- avr/cmd_loadcpm3.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++ avr/command_tbl.c | 9 ++++ avr/env.c | 39 +++++++++++--- include/config.h | 4 ++ 6 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 avr/cmd_loadcpm3.c (limited to 'avr') diff --git a/TODO.md b/TODO.md index b952c9d..625dd16 100644 --- a/TODO.md +++ b/TODO.md @@ -4,3 +4,4 @@ TODO List - TODO: eliminate xmalloc - TODO: build time directory as lib - TODO: command 'help ' should return success +- TODO: file search path. 'cd' command? diff --git a/avr/Tupfile b/avr/Tupfile index 6be8d79..0c35de4 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -7,7 +7,7 @@ FATFS = $(TOP)/fatfs/src/ff.c SRC = main.c SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c -SRC += cmd_loadihex.c cmd_sd.c cmd_fat.c +SRC += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c SRC += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c SRC += timer.c serial.c i2c.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c new file mode 100644 index 0000000..267cad8 --- /dev/null +++ b/avr/cmd_loadcpm3.c @@ -0,0 +1,155 @@ +/* + * (C) Copyright 2015 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "common.h" +#include +#include +#include +#include + +#include "command.h" +#include "env.h" +#include "ff.h" +#include "con-utils.h" +#include "z80-if.h" +#include "debug.h" + + +#define RS 128 /* CP/M record size */ + +/* + * Load Routine + * + * Input: addr = Page Address of load top + * len = Length in pages of module to read + * + */ +int load(FIL *File, uint16_t addr, uint8_t len) +{ + uint8_t buffer[RS]; + unsigned int br; /* bytes read */ + int res; + + len *= 2; /* length in records of module */ + //debug("## load: addr: 0x%.4X, records: 0x%.4X, (%u)\n", addr, len, len); + + for (; len; len--) { + addr -= RS; + res = f_read(File, buffer, RS, &br); + if (res || br != RS) { + return 1; + } + + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return 2; + } + z80_write_block(buffer, addr, RS); + z80_bus_cmd(Release); + //debug("## written: 0x%.4X\n", addr); + } + + return 0; +} + + +command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + uint16_t mem_top; + uint8_t res_len; + uint16_t bank_top; + uint8_t bank_len; + uint16_t osentry_adr = 0; + long offset = 0; + char *fname; + FATFS FatFs; + FIL File; + char default_fname[] = CONFIG_PATH_CPM3SYS; + unsigned int br; /* bytes read */ + uint8_t buffer[RS]; + int res; + + (void) cmdtp; (void) flag; + + + if (argc > 1) + offset = strtoul(argv[1], NULL, 16); + + fname = getenv(PSTR(ENV_PATH_CPM3SYS)); + + if (argc > 2) { + fname = argv[2]; + } + + if (fname == NULL || *fname == '\0') + fname = default_fname; + + res = f_mount(&FatFs, fname, 0); + if (!res) + res = f_open(&File, fname, FA_READ ); + if (res) { + printf_P(PSTR("Error: failed to open '%s'\n"), fname); + f_mount(NULL, fname, 0); + return CMD_RET_FAILURE; + } + + printf_P(PSTR("Loading: '%s'...\n"), fname); + + /* read the load record */ + res = f_read(&File, buffer, RS, &br); + if (res || br != RS) + goto out; + + mem_top = buffer[0] << 8; + res_len = buffer[1]; + bank_top = buffer[2] << 8; + bank_len = buffer[3]; + osentry_adr = buffer[4] + (buffer[5] << 8); + + /* read display info */ + res = f_read(&File, buffer, RS, &br); + if (res || br != RS) + goto out; + + /* print the info */ + buffer[RS-1] = '$'; + uint8_t *p = memchr(buffer, '$', RS); + *p = '\0'; + my_puts((char *)buffer); + + /* Main System Load */ + + /* Load Common Portion of System */ + if ((res = load(&File, mem_top, res_len)) != 0) + goto out; + + /* Load Banked Portion of System */ + res = load(&File, bank_top, bank_len); + +out: + f_close(&File); + f_mount(NULL, fname, 0); + + if (res) { + printf_P(PSTR("Error: failed to read '%s'\n"), fname); + return CMD_RET_FAILURE; + } else { + if (res_len != 0) + setenv_hex(PSTR(ENV_STARTADDRESS), osentry_adr); + printf_P(PSTR("Loaded: Resident: ")); + if (res_len != 0) + printf_P(PSTR("0x%.4X-0x%.4X, "), mem_top-res_len*256, mem_top-1); + else + printf_P(PSTR(" - ")); + printf_P(PSTR("Banked: ")); + if (bank_len != 0) + printf_P(PSTR("0x%.4X-0x%.4X\n"), bank_top-bank_len*256, bank_top-1); + else + printf_P(PSTR(" - \n")); + + return CMD_RET_SUCCESS; + } +} diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 23d0803..238f132 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -16,6 +16,7 @@ extern command_ret_t do_env_default(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_env_set(cmd_tbl_t *, int, int, char * const []); 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 []); 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 []); @@ -126,6 +127,14 @@ CMD_TBL_ITEM( "load srec_cat prepared image from controller flash", "" ), +CMD_TBL_ITEM( + loadcpm3, 3, 0, do_loadcpm3, + "load CPM3.SYS file", + "[offset] [filename]\n" + " - Load CP/M 3 system file from FAT filesystem. This command makes\n" + " CPMLDR superfluous. Default filename is '"CONFIG_PATH_CPM3SYS"', but\n" + " uses environment variable '"ENV_PATH_CPM3SYS"', if set." +), CMD_TBL_ITEM( loadi, 2, 0, do_loadihex, "load intel hex file over serial line", diff --git a/avr/env.c b/avr/env.c index 7be7d03..a947583 100644 --- a/avr/env.c +++ b/avr/env.c @@ -31,13 +31,17 @@ #define DELIM "\0" const FLASH char default_env[] = { - "bootdelay=" "3" DELIM - "bootcmd=" "reset; loadf; go ${startaddr}" DELIM - "baudrate=" "115200" DELIM - "startaddr=" "0" DELIM + ENV_BAUDRATE "=" "115200" DELIM + ENV_BOOTDELAY "=" "3" DELIM + ENV_BOOTCMD "=" "reset; loadf; go ${startaddr}" DELIM + ENV_PATH_CPM3SYS "=" CONFIG_PATH_CPM3SYS DELIM + ENV_PINALIAS "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7," + "6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM + ENV_STARTADDRESS "=" "0" DELIM DELIM }; + /* EEPROM storage */ typedef struct environment_s { uint16_t crc; /* CRC16 over data bytes */ @@ -452,7 +456,6 @@ command_ret_t _do_env_set(int flag, int argc, char * const argv[]) env_item_t e, *ep; (void) flag; - debug("Initial value for argc=%d\n", argc); name = argv[1]; value = argv[2]; @@ -519,15 +522,35 @@ command_ret_t _do_env_set(int flag, int argc, char * const argv[]) * @return 0 if ok, 1 on error */ static -int setenv(const char *varname, const char *varvalue) +int setenv(const MEMX char *varname, const char *varvalue) { - const char * const argv[3] = { NULL, varname, varvalue }; + int rc; + +#ifdef __MEMX + char *tmpname = NULL; + if (__builtin_avr_flash_segment(varname) != -1) { + tmpname = malloc(strlen_P(varname)+1); + if (tmpname == NULL) { + printf_P(PSTR("setenv: Out of Memory!\n")); + return 1; + } + strcpy_P(tmpname, varname); + } else + tmpname = (char *) varname; +#endif + + const char * const argv[3] = { NULL, tmpname, varvalue }; int argc = 3; if (varvalue == NULL || varvalue[0] == '\0') --argc; - return (int) _do_env_set(0, argc, (char * const *)argv); + rc = (int) _do_env_set(0, argc, (char * const *)argv); + +#ifdef __MEMX + free(tmpname); +#endif + return rc; } /** diff --git a/include/config.h b/include/config.h index 646835d..7c46b31 100644 --- a/include/config.h +++ b/include/config.h @@ -12,7 +12,11 @@ #define ENV_BAUDRATE "baudrate" #define ENV_BOOTDELAY "bootdelay" #define ENV_BOOTCMD "bootcmd" +#define ENV_PATH_CPM3SYS "cpm3_file" #define ENV_PINALIAS "pin_alias" +#define ENV_STARTADDRESS "startaddress" + +#define CONFIG_PATH_CPM3SYS "1:/cpm3.sys" #define CONFIG_ENV_SIZE 1600 #define CONFIG_ENV_OFFSET 0 -- cgit v1.2.3 From 3ad4143bb11dd98f47c80e0b93d39b59c2f8e329 Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 8 May 2015 18:45:36 +0200 Subject: connect command: check serial input, even if Z180 sends really fast. --- avr/cmd_boot.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'avr') diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index 301f4f5..f9f8f90 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -194,9 +194,11 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv pending = (Stat & S_CON_PENDING) != 0; Stat &= ~S_CON_PENDING; } - if (pending) - while ((ch = z80_memfifo_getc(fifo_conout)) >= 0) + if (pending) { + uint8_t count = 100; + while ((ch = z80_memfifo_getc(fifo_conout)) >= 0 && --count) putchar(ch); + } if ((ch = my_getchar(0)) >= 0) { switch (state) { -- cgit v1.2.3 From 3f858d9f4836decae37d5a61f221bddf7a2f1e61 Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 8 May 2015 22:50:22 +0200 Subject: command 'help ' should return success --- TODO.md | 5 ++++- avr/command.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'avr') diff --git a/TODO.md b/TODO.md index 625dd16..3ccd0d7 100644 --- a/TODO.md +++ b/TODO.md @@ -3,5 +3,8 @@ TODO List - TODO: eliminate xmalloc - TODO: build time directory as lib -- TODO: command 'help ' should return success - TODO: file search path. 'cd' command? + +---------------------------------------------------- +- Done: + - command 'help ' should return success diff --git a/avr/command.c b/avr/command.c index 46e3a8a..ed25dee 100644 --- a/avr/command.c +++ b/avr/command.c @@ -120,7 +120,7 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, */ for (i = 1; i < argc; ++i) { if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) { - rcode = cmd_usage(cmdtp); + cmd_usage(cmdtp); } else { printf_P(PSTR("Unknown command '%s' - try 'help'" " without arguments.\n\n"), argv[i] -- cgit v1.2.3 From 1a2460dcd3bed50d5f2b7ba53e6e21a12935639b Mon Sep 17 00:00:00 2001 From: Leo C Date: Sun, 10 May 2015 12:47:59 +0200 Subject: Server: add echo command and response --- avr/z180-serv.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index e0b763f..ce264ae 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -52,6 +52,25 @@ uint32_t msg_to_addr(uint8_t *msg) } +static int msg_xmit_header(uint8_t func, uint8_t subf, int len) +{ + z80_memfifo_putc(fifo_msgout, 0xAE); + z80_memfifo_putc(fifo_msgout, len+2); + z80_memfifo_putc(fifo_msgout, func); + z80_memfifo_putc(fifo_msgout, subf); + + return 0; +} + +int msg_xmit(uint8_t func, uint8_t subf, int len, uint8_t *msg) +{ + msg_xmit_header(func, subf, len); + while (len--) + z80_memfifo_putc(fifo_msgout, *msg++); + + return 0; +} + void do_msg_ini_memfifo(uint8_t subf, int len, uint8_t * msg) { (void)len; @@ -68,6 +87,15 @@ void do_msg_char_out(uint8_t subf, int len, uint8_t * msg) putchar(*msg++); } +/* echo message */ +void do_msg_echo(uint8_t subf, int len, uint8_t * msg) +{ + (void)subf; + + /* send re-echo */ + msg_xmit(1, 3, len, msg); +} + const FLASH struct msg_item z80_messages[] = { @@ -77,6 +105,9 @@ const FLASH struct msg_item z80_messages[] = { 1, 1, 1, do_msg_char_out}, + { 1, + 2, 2, + do_msg_echo}, { 0xff, /* end mark */ 0, 0, 0}, @@ -178,7 +209,7 @@ int msg_handling(int state) if (pending) { switch (state) { - case 0: + case 0: /* need init */ z80_bus_cmd(Request); uint32_t addr = z80_read(0x40) + ((uint16_t) z80_read(0x41) << 8) + @@ -189,7 +220,7 @@ int msg_handling(int state) state = 1; } break; - case 1: + case 1: /* awaiting messages */ check_msg_fifo(); break; } -- cgit v1.2.3 From cdc4625b124f725fbc9462d5592d1d3be2aa613a Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 11 May 2015 08:32:57 +0200 Subject: phys. address 0x00040 points to fifo_list --- avr/z180-serv.c | 17 +++++++++--- z180/config.inc | 12 ++++---- z180/ddtz.180 | 9 +++--- z180/init.180 | 83 ++++++++++++++++++++++++++++++++++++++++--------------- z180/msgbuf-a.180 | 6 ++-- 5 files changed, 88 insertions(+), 39 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index ce264ae..9860175 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -210,14 +210,23 @@ int msg_handling(int state) if (pending) { switch (state) { case 0: /* need init */ + /* Get address of fifo_list */ z80_bus_cmd(Request); - uint32_t addr = z80_read(0x40) + + uint32_t fifo_list = z80_read(0x40) + ((uint16_t) z80_read(0x41) << 8) + ((uint32_t) z80_read(0x42) << 16); z80_bus_cmd(Release); - if (addr != 0) { - z80_memfifo_init(fifo_msgin, addr); - state = 1; + if (fifo_list != 0) { + /* Get address of fifo 0 */ + z80_bus_cmd(Request); + uint32_t fifo_addr = z80_read(fifo_list) + + ((uint16_t) z80_read(fifo_list+1) << 8) + + ((uint32_t) z80_read(fifo_list+2) << 16); + z80_bus_cmd(Release); + if (fifo_addr != 0) { + z80_memfifo_init(fifo_msgin, fifo_addr); + state = 1; + } } break; case 1: /* awaiting messages */ diff --git a/z180/config.inc b/z180/config.inc index 0c945ae..dfb41cd 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -34,7 +34,7 @@ PRT_TC10MS equ PHI / (PRT_PRE/10) ;----------------------------------------------------- ; MMU -COMMON_SIZE equ 4*1024 ;Common Area size in bytes +COMMON_SIZE equ 16*1024 ;Common Area size in bytes ;must be multiple of 4K if (COMMON_SIZE mod 1000h) @@ -106,13 +106,15 @@ CWAITROM equ 2 shl MWI0 endif -DRSTNUM equ 30h ;DDTZ Restart vector (breakpoints) +DDTZRSTVEC equ 030h ;DDTZ Restart vector (breakpoints) +INIDONE equ 03Fh ;CP/M skip hw init, if this address +INIDONEVAL equ 080h ; is set to this value. -mtx.fifo_len equ 32 ;Message transfer fifos -mtx.fifo_id equ 0 ; This *must* have #0 +mtx.fifo_len equ 32 ;Message transfer fifos +mtx.fifo_id equ 0 ; This *must* have #0 mrx.fifo_len equ 32 -mrx.fifo_id equ 1 +mrx.fifo_id equ 1 ci.fifo_len equ 32 ;AVRCON Character I/O via AVR ci.fifo_id equ 2 diff --git a/z180/ddtz.180 b/z180/ddtz.180 index e5d48e1..e8a26fd 100644 --- a/z180/ddtz.180 +++ b/z180/ddtz.180 @@ -1796,7 +1796,7 @@ l10c5h: jr z,l10e7h ld l,(ix+002h) ld h,(ix+003h) - ld a,(ddtrst) + ld a,(ddtzrst) comst cp (hl) comend @@ -1859,7 +1859,7 @@ l1144h: ld h,(ix+003h) - ld a,(ddtrst) + ld a,(ddtzrst) comst ld e,(hl) ld (hl),a @@ -5944,7 +5944,7 @@ l27dah: ret x27ea: - ld a,(ddtrst) + ld a,(ddtzrst) comst cp (iy+000h) comend @@ -6137,7 +6137,8 @@ ddtram: ; The following 2 params are changeable by user. ; Should these moved to top ram? ; -ddtrst: rst DRSTNUM ;rst used by ddtz +ddtzrst: + rst DDTZRSTVEC ;rst used by ddtz ddtei: ei ;ints enabled/disabled while ddtz is running ret ; offs.pc: diff --git a/z180/init.180 b/z180/init.180 index f43aaeb..c3db6a1 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -163,7 +163,7 @@ kstart: if CPU_Z180 if 0 - + ld hl,dmclrt ;load DMA registers call ioiniml ld a,0cbh ;01ef dst +1, src fixed, burst @@ -174,7 +174,7 @@ kstart: ??cl_1: out0 (dstat),a ;01f9 clear (up to) 64k djnz ??cl_1 ; end of RAM? - + endif endif @@ -185,10 +185,10 @@ kstart: ; -- wstart -- wstart: - call sysram_init ;027f + call sysram_init call ivtab_init if CPU_Z180 - call prt0_init +; call prt0_init endif call charini @@ -199,20 +199,23 @@ wstart: call selbnk endif - im 2 ;?030e - ei ;0282 + ld a,INIDONEVAL ;tell others (CP/M) that hardware and fifos + ld (INIDONE),a ; are allready initialized + + im 2 + ei - call ?const ;0284 - call ?const ;0287 - or a ;028a - call nz,?conin ;028d + call ?const + call ?const + or a + call nz,?conin if CPU_Z180 ld e,0 ;Sys$Bank else ; TODO: endif - jp ddtz ;0290 + jp ddtz if CPU_Z180 @@ -224,16 +227,51 @@ syscbr: db 1 ;---------------------------------------------------------------------- ; -;TODO: Make a ringbuffer module. - global buf.init buf.init: ld (ix+o.in_idx),0 ld (ix+o.out_idx),0 ld (ix+o.mask),a + + ld a,(ix+o.id) + cp 4 + ret nc + + push de + push hl + ld hl,fifo_list + push hl ;save fifo_list + ld e,a + ld d,0 + add hl,de + add hl,de + add hl,de + push ix + pop de +; TODO: address transation + ld (hl),e + inc hl + ld (hl),d + pop hl ;get fifo_list back + or a + jr nz,bufi_ex + + ld (040h),hl + ld (040h+2),a +bufi_ex: + pop hl + pop de + ret + +fifo_list: + rept 4 + dw 0 + db 0 + endm + ;---------------------------------------------------------------------- extrn msginit,msg.sout @@ -259,11 +297,11 @@ bfi_1: or a jr nz,bfi_2 - call hwl2phy - ld (40h+0),hl - ld (40h+2),a +; call hwl2phy +; ld (40h+0),hl +; ld (40h+2),a out (AVRINT5),a - jr bfi_3 + jr bfi_3 bfi_2: call hwl2phy ld (bufdat+1),hl @@ -426,12 +464,12 @@ ioi_r: dec a jr nz,ioi_r jr ioi_nxt -ioi_e: +ioi_e: pop bc ret - + else ;(if 1/0) - + push bc jr ioi_nxt ioi_l: @@ -449,7 +487,7 @@ ioi_nxt: djnz ioi_l pop bc ret - + endif ;(1/0) else @@ -484,7 +522,7 @@ ioml_lp: inc hl cp b jr z,ioml_e - + ld c,(hl) inc hl otimr @@ -909,4 +947,3 @@ mark_55AA equ 0 - 2 - 4 ;2 byte for trap stack end - diff --git a/z180/msgbuf-a.180 b/z180/msgbuf-a.180 index ff2a657..7e8c9cc 100644 --- a/z180/msgbuf-a.180 +++ b/z180/msgbuf-a.180 @@ -29,11 +29,11 @@ ; msginit: - ld ix,mrx.fifo - ld a,mrx.fifo.mask - call buf.init ld ix,mtx.fifo ld a,mtx.fifo.mask + call buf.init + ld ix,mrx.fifo + ld a,mrx.fifo.mask jp buf.init ;-------------------------------------------------------------- -- cgit v1.2.3 From 5f7f3586b0444116d5c1340465ecae8d6daa2461 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 14 May 2015 19:32:16 +0200 Subject: Add CP/M 3 file i/o (initial version) --- TODO.md | 2 +- avr/cmd_fat.c | 4 +- avr/cmd_loadcpm3.c | 1 + avr/z180-serv.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++++++++ z180/init.180 | 7 +- 5 files changed, 244 insertions(+), 6 deletions(-) (limited to 'avr') diff --git a/TODO.md b/TODO.md index 3ccd0d7..75c9679 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,7 @@ TODO List - TODO: eliminate xmalloc - TODO: build time directory as lib - TODO: file search path. 'cd' command? - +- TODO: increase __malloc_margin to ? (now 0x20) ---------------------------------------------------- - Done: - command 'help ' should return success diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 8ed7ae3..c5791e5 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -22,8 +22,8 @@ #include "timer.h" #include "debug.h" - -#define MAX_MEMORY (1ul << 20) +/* TODO: use memory size test function (cmd_mem.c) */ +#define MAX_MEMORY (1ul << 19) #define BUFFER_SIZE 512 diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c index 267cad8..f2a30f1 100644 --- a/avr/cmd_loadcpm3.c +++ b/avr/cmd_loadcpm3.c @@ -67,6 +67,7 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg char *fname; FATFS FatFs; FIL File; + /* TODO: put CONFIG_PATH_CPM3SYS in flash */ char default_fname[] = CONFIG_PATH_CPM3SYS; unsigned int br; /* bytes read */ uint8_t buffer[RS]; diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 9860175..c80daeb 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -5,12 +5,18 @@ */ #include "common.h" +#include +#include +#include #include #include "background.h" +#include "env.h" +#include "ff.h" #include "serial.h" #include "z80-if.h" #include "debug.h" +#include "print-utils.h" #include "z180-serv.h" /*--------------------------------------------------------------------------*/ @@ -96,6 +102,224 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg) msg_xmit(1, 3, len, msg); } +/* ---------------------------------------------------------------------------*/ + +#define MAX_DEVICE 2 +#define MAX_DRIVE 2 +#define BLOCK_SIZE 512 + +struct fat_device_s { + FATFS dd; + bool active; +}; + + +struct cpm_drive_s { + uint8_t drv; + uint8_t device; + char *img_name; + FIL fd; +}; + +static uint8_t disk_buffer[BLOCK_SIZE]; +static struct fat_device_s device_table[MAX_DEVICE]; +static struct cpm_drive_s drv_table[MAX_DRIVE]; + +/* + db 2 ; disk command + ds 1 ; subcommand (login/read/write) + ds 1 ; @adrv (8 bits) +0 + ds 1 ; @rdrv (8 bits) +1 + ds 3 ; @xdph (24 bits) +2 +*/ + +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; + } + + debug("\n## login: %c:\n", msg[0]+'A'); + + + drv = msg[0]; + if ( drv>= MAX_DRIVE) { + rc = 0x02; + goto out; + } + + /* TODO: this has to be done somewhere globaly */ + + if (!device_table[0].active) { + f_mount(&device_table[0].dd, "0:", 0); + device_table[0].active = true; + } + if (!device_table[1].active) { + f_mount(&device_table[1].dd, "1:", 0); + device_table[1].active = true; + } + +/* + uint32_t dph = ((uint32_t)msg[4] << 16) + ((uint16_t)msg[3] << 8) + msg[2]; +*/ + + if (drv_table[drv].img_name != NULL) { + debug("## close: '%s'\n", drv_table[drv].img_name); + f_close(&drv_table[drv].fd); + free(drv_table[drv].img_name); + drv_table[drv].img_name = NULL; + } + + strcpy_P((char *)disk_buffer, PSTR("dsk0")); + 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; + } + + + res = f_open(&drv_table[drv].fd, drv_table[drv].img_name, + FA_WRITE | FA_READ); + + debug("## open: '%s', (env: '%s'), res: %d\n", + 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("## error rc: %.02x, res: %d\n", rc, res); + }; + + /* send result*/ + msg_xmit(2, subf, sizeof(result_msg), result_msg); +} + + +/* + db 2 ; disk command + ds 1 ; subcommand (login/read/write) + ds 1 ; @adrv (8 bits) +0 + ds 1 ; @rdrv (8 bits) +1 + ds 1 ; @cnt (8 bits) +2 + ds 2 ; @trk (16 bits) +3 + ds 2 ; @sect(16 bits) +5 + ds 3 ; phys. transfer addr +7 +*/ + +void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) +{ + uint8_t drv; + uint32_t addr; + uint32_t pos; + + bool dowrite = (subf == 2); + 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; + } + + drv = msg[0]; + if ( drv>= MAX_DRIVE) { + rc = 0x02; + goto out; + } + + addr = ((uint32_t)msg[9] << 16) + ((uint16_t)msg[8] << 8) + msg[7]; + + /* bytes = BLOCK_SIZE; */ /* TODO: multi sector count */ + pos = (((uint16_t)(msg[4] << 8) + msg[3]) * 8 + + ((uint32_t)(msg[6] << 8) + msg[5])) * BLOCK_SIZE; + + + debug("## cpm_rw: %s %c: trk: %4d, sec: %d, pos: 0x%.5lx, addr: 0x%.5lx\n", + dowrite ? "write" : " read", msg[0]+'A', + ((uint16_t)(msg[4] << 8) + msg[3]), msg[5], pos, addr); + + + + /* TODO: check bank boundary crossing */ + /* + if (addr + BLOCK_SIZE > MAX_MEMORY) + ... = MAX_MEMORY - addr; + */ + + + res = f_lseek(&drv_table[drv].fd, pos); + if (!res) { + unsigned int br; + + if (dowrite) { + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + buserr = 1; + } else { + z80_read_block(disk_buffer, addr, BLOCK_SIZE); + z80_bus_cmd(Release); + res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); + if (!res) + res = f_sync(&drv_table[drv].fd); + } + } else { + res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); + if (res == FR_OK) { + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + buserr = 1; + } else { + z80_write_block(disk_buffer, addr, br); + z80_bus_cmd(Release); + } + } + } + + if (br != BLOCK_SIZE) { + debug("## f_read res: %d, bytes rd/wr: %u\n", res, br); + dump_ram(disk_buffer, 0, 64, "Read Data"); + res = -1; + } + } + +out: + if (buserr) { + debug("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("#### error rc: %.02x, res: %d\n", rc, res); + } + + /* send result*/ + msg_xmit(2, subf, sizeof(result_msg), result_msg); +} + const FLASH struct msg_item z80_messages[] = { @@ -108,6 +332,12 @@ const FLASH struct msg_item z80_messages[] = { 1, 2, 2, do_msg_echo}, + { 2, + 0, 0, + do_msg_cpm_login}, + { 2, + 1, 2, + do_msg_cpm_rw}, { 0xff, /* end mark */ 0, 0, 0}, @@ -258,6 +488,12 @@ void restart_z180_serv(void) for (int i = 0; i < NUM_FIFOS; i++) z80_memfifo_init(i, 0); bg_setstat(handle_msg_handling, 0); + + f_mount(NULL, "0:", 0); + device_table[0].active = false; + f_mount(NULL, "1:", 0); + device_table[1].active = false; + } /*--------------------------------------------------------------------------*/ diff --git a/z180/init.180 b/z180/init.180 index b1f835b..11f45ec 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -79,6 +79,7 @@ hwini0: db 3 ;count db rcr,CREFSH ;configure DRAM refresh db dcntl,INIWAITS ;wait states + db cbr,SYS$CBR db cbar,SYS$CBAR endif db 0 @@ -151,10 +152,10 @@ hw_reset: kstart: if CPU_Z180 - ld a,SYS$CBAR - out0 (cbar),a ld a,SYS$CBR out0 (cbr),a + ld a,SYS$CBAR + out0 (cbar),a endif ld sp,$stack ;01e1 @@ -220,7 +221,7 @@ wstart: if CPU_Z180 ; TODO: SYS$CBR -syscbr: db 1 +syscbr: db 0 endif ; -- cgit v1.2.3 From bbd45c46a75edd930486980c0d6a94c52d8cf403 Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 15 May 2015 14:59:49 +0200 Subject: fatfs f_mount now allways done globally at start up --- avr/cli.c | 18 ++++++---- avr/cmd_fat.c | 102 ++++++++++++++++++++++------------------------------- avr/cmd_loadcpm3.c | 7 +--- avr/cmd_misc.c | 45 +++++++++++------------ avr/command_tbl.c | 7 ++-- avr/main.c | 21 +++++++---- avr/z180-serv.c | 23 ------------ avr/z80-if.c | 3 +- 8 files changed, 94 insertions(+), 132 deletions(-) (limited to 'avr') diff --git a/avr/cli.c b/avr/cli.c index 52c85db..6b26b6f 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -27,6 +27,9 @@ #include "con-utils.h" #include "cli.h" + +/* FIXME: Quoting problems */ + #define DEBUG_PARSER 0 /* set to 1 to debug */ #define debug_parser(fmt, args...) \ @@ -46,7 +49,7 @@ static int cli_parse_line(char *line, char *argv[]) inp++) { switch (state) { - case 0: + case 0: /* before arg string, waiting for arg start */ if (isblank(c)) continue; @@ -55,7 +58,7 @@ static int cli_parse_line(char *line, char *argv[]) state = 1; /* fall thru */ - case 1: + case 1: /* in arg string, waiting for end of arg string */ if (c == '\\') { ++state; continue; @@ -71,7 +74,7 @@ static int cli_parse_line(char *line, char *argv[]) } break; - case 3: + case 3: /* in quote */ if (c == '\\' && quote == '\"') { ++state; continue; @@ -82,7 +85,7 @@ static int cli_parse_line(char *line, char *argv[]) } break; - case 2: + case 2: /* waiting for next char */ case 4: --state; break; @@ -252,12 +255,13 @@ static int cli_run_command(const char *cmd, int flag) */ for (inquotes = 0, sep = str; *sep; sep++) { if ((*sep == '\'') && - (*(sep - 1) != '\\')) + (sep != str) && /* past string start */ + (*(sep - 1) != '\\')) /* and NOT escaped */ inquotes = !inquotes; if (!inquotes && - (*sep == ';' || *sep == '\n') && /* separator */ - (sep != str) && /* past string start */ + (*sep == ';' || *sep == '\n') && /* separator */ + (sep != str) && /* past string start */ (*(sep - 1) != '\\')) /* and NOT escaped */ break; } diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index c5791e5..af2f772 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -157,7 +157,7 @@ FRESULT scan_files ( */ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - FATFS *FatFs, *fs; + FATFS *fs; DWORD nfreeclst; FRESULT res; char *path; @@ -165,64 +165,57 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg (void) cmdtp; (void) flag; (void) argc; - FatFs = (FATFS *) malloc(sizeof (FATFS)); path = (char *) malloc(BUFFER_SIZE); - if (FatFs == NULL || path == NULL) { + if (path == NULL) { printf_P(PSTR("fatstat: Out of Memory!\n")); free(path); - free(FatFs); return CMD_RET_FAILURE; } - res = f_mount(FatFs, argv[1], 0); + res = f_getfree(argv[1], &nfreeclst, &fs); if (!res) { - res = f_getfree(argv[1], &nfreeclst, &fs); - if (!res) { - printf_P(PSTR( - "FAT type: %u\n" - "Bytes/Cluster: %lu\n" - "Number of FATs: %u\n" - "Root DIR entries: %u\n" - "Sectors/FAT: %lu\n" - "Number of clusters: %lu\n" - "FAT start (lba): %lu\n" - "DIR start (lba,cluster): %lu\n" - "Data start (lba): %lu\n"), - fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats, - fs->n_rootdir, fs->fsize, fs->n_fatent - 2, - fs->fatbase, fs->dirbase, fs->database); + printf_P(PSTR( + "FAT type: %u\n" + "Bytes/Cluster: %lu\n" + "Number of FATs: %u\n" + "Root DIR entries: %u\n" + "Sectors/FAT: %lu\n" + "Number of clusters: %lu\n" + "FAT start (lba): %lu\n" + "DIR start (lba,cluster): %lu\n" + "Data start (lba): %lu\n"), + fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats, + fs->n_rootdir, fs->fsize, fs->n_fatent - 2, + fs->fatbase, fs->dirbase, fs->database); #if _USE_LABEL - TCHAR label[12]; - DWORD serial; - res = f_getlabel(argv[1], label, &serial); - if (!res) { - printf_P(PSTR( - "Volume name: %s\n" - "Volume S/N: %04X-%04X\n"), - label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF)); - } + TCHAR label[12]; + DWORD serial; + res = f_getlabel(argv[1], label, &serial); + if (!res) { + printf_P(PSTR( + "Volume name: %s\n" + "Volume S/N: %04X-%04X\n"), + label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF)); + } #endif - if (!res) { - my_puts_P(PSTR("\nCounting... ")); - statp.AccSize = statp.AccFiles = statp.AccDirs = 0; - strcpy(path, argv[1]); + if (!res) { + my_puts_P(PSTR("\nCounting... ")); + statp.AccSize = statp.AccFiles = statp.AccDirs = 0; + strcpy(path, argv[1]); - res = scan_files(path, &statp); - } - if (!res) { - printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n" - "%lu KB total disk space.\n%lu KB available.\n"), - statp.AccFiles, statp.AccSize, statp.AccDirs, - (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2) - ); - } + res = scan_files(path, &statp); + } + if (!res) { + printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n" + "%lu KB total disk space.\n%lu KB available.\n"), + statp.AccFiles, statp.AccSize, statp.AccDirs, + (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2) + ); } } free(path); - free(FatFs); - f_mount(NULL, argv[1], 0); if (res) { put_rc(res); return CMD_RET_FAILURE; @@ -237,7 +230,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg */ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - FATFS FatFs, *fs; + FATFS *fs; DIR Dir; /* Directory object */ FILINFO Finfo; unsigned long p1; @@ -251,9 +244,7 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ (void) cmdtp; (void) flag; (void) argc; - res = f_mount(&FatFs, argv[1], 0); - if (!res) - res = f_opendir(&Dir, argv[1]); + res = f_opendir(&Dir, argv[1]); if (res) { put_rc(res); return CMD_RET_FAILURE; @@ -341,7 +332,6 @@ FRESULT mkpath(TCHAR *path) */ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - FATFS *FatFs; FIL File; uint32_t addr; unsigned long bytes; @@ -376,21 +366,15 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ if (addr + bytes > MAX_MEMORY) bytes = MAX_MEMORY - addr; - FatFs = (FATFS *) malloc(sizeof (FATFS)); buffer = (uint8_t *) malloc(BUFFER_SIZE); - if (FatFs == NULL || buffer == NULL) { + if (buffer == NULL) { printf_P(PSTR("fatstat: Out of Memory!\n")); - free(FatFs); free(buffer); return CMD_RET_FAILURE; } - res = f_mount(FatFs, argv[1], 0); - - if (!res) { - if (dowrite) { - res = mkpath(argv[1]); - } + if (dowrite) { + res = mkpath(argv[1]); } if (!res) { res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS @@ -451,11 +435,9 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ bytes_rw, bytes_rw, timer ? (bytes_rw * 1000 / timer) : 0); } } - f_mount(NULL, argv[1], 0); } free(buffer); - free(FatFs); if (buserr) my_puts_P(PSTR("Bus timeout\n")); diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c index f2a30f1..fd685b2 100644 --- a/avr/cmd_loadcpm3.c +++ b/avr/cmd_loadcpm3.c @@ -65,7 +65,6 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg uint16_t osentry_adr = 0; long offset = 0; char *fname; - FATFS FatFs; FIL File; /* TODO: put CONFIG_PATH_CPM3SYS in flash */ char default_fname[] = CONFIG_PATH_CPM3SYS; @@ -88,12 +87,9 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg if (fname == NULL || *fname == '\0') fname = default_fname; - res = f_mount(&FatFs, fname, 0); - if (!res) - res = f_open(&File, fname, FA_READ ); + res = f_open(&File, fname, FA_READ ); if (res) { printf_P(PSTR("Error: failed to open '%s'\n"), fname); - f_mount(NULL, fname, 0); return CMD_RET_FAILURE; } @@ -132,7 +128,6 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg out: f_close(&File); - f_mount(NULL, fname, 0); if (res) { printf_P(PSTR("Error: failed to read '%s'\n"), fname); diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c index b29aedd..c9a3c45 100644 --- a/avr/cmd_misc.c +++ b/avr/cmd_misc.c @@ -9,46 +9,43 @@ #include "common.h" #include +#include #include "command.h" #include "timer.h" #include "con-utils.h" +#include "getopt-min.h" command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - uint_fast8_t putnl = 1; + bool put_newline = true; (void) cmdtp; (void) flag; - for (uint_fast8_t i = 1; i < argc; i++) { + /* reset getopt() */ + optind = 1; + + int opt; + while ((opt = getopt(argc, argv, PSTR("n"))) != -1) { + switch (opt) { + case 'n': + put_newline = false; + break; + default: /* '?' */ + return CMD_RET_USAGE; + } + } - uint_fast8_t backslash = 0; - char *p = argv[i]; - char c; + for (uint_fast8_t i = optind; i < argc; i++) { - if (i != 1) + if (i != optind) putchar(' '); - while ((c = *p++) != '\0') { - - if(backslash) { - backslash = 0; - if (c == 'c') { - putnl = 0; - continue; - } else - putchar('\\'); - } else { - if (c == '\\') { - backslash = 1; - continue; - } - } - putchar(c); - } + + my_puts(argv[i]); } - if (putnl) + if (put_newline) putchar('\n'); return CMD_RET_SUCCESS; diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 238f132..f030b54 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -76,9 +76,10 @@ CMD_TBL_ITEM( ), CMD_TBL_ITEM( echo, CONFIG_SYS_MAXARGS, 1, do_echo, - "echo args to console", - "[args..]\n" - " - echo args to console; \\c suppresses newline" + "display a line of text", + "[-n] [argument ...]\n" + " - echo the argument(s) to console.\n" + " -n do not output the trailing newline" ), CMD_TBL_ITEM( sleep , 2, 1, do_sleep, diff --git a/avr/main.c b/avr/main.c index 8bffef9..5a0d792 100644 --- a/avr/main.c +++ b/avr/main.c @@ -11,7 +11,7 @@ #include #include "config.h" -#include "debug.h" +#include "ff.h" #include "z80-if.h" #include "i2c.h" #include "con-utils.h" @@ -23,6 +23,7 @@ #include "gpio.h" #include "time.h" #include "rtc.h" +#include "debug.h" static uint8_t mcusr; @@ -138,6 +139,17 @@ void setup_system_time(void) set_system_time(mk_gmtime(&rtc_time) ); } + + +static void setup_fatfs(void) +{ + static FATFS FatFs0; + static FATFS FatFs1; + + f_mount(&FatFs0, "0:", 0); + f_mount(&FatFs1, "1:", 0); +} + /*--------------------------------------------------------------------------*/ /* Stored value of bootdelay, used by autoboot_command() */ @@ -254,14 +266,9 @@ int main(void) print_reset_reason(); #endif -#if DEBUG - unsigned long i_speed = getenv_ulong(PSTR("i2c_clock"), 10, CONFIG_SYS_I2C_CLOCK); - debug("### Setting I2C clock Frequency to %lu Hz.\n", i_speed); - i2c_init(i_speed); -#else i2c_init(CONFIG_SYS_I2C_CLOCK); -#endif setup_system_time(); + setup_fatfs(); printf_P(PSTR("\nATMEGA1281+Z8S180 Stamp Monitor\n\n")); diff --git a/avr/z180-serv.c b/avr/z180-serv.c index c80daeb..22dafe1 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -104,15 +104,9 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg) /* ---------------------------------------------------------------------------*/ -#define MAX_DEVICE 2 #define MAX_DRIVE 2 #define BLOCK_SIZE 512 -struct fat_device_s { - FATFS dd; - bool active; -}; - struct cpm_drive_s { uint8_t drv; @@ -122,7 +116,6 @@ struct cpm_drive_s { }; static uint8_t disk_buffer[BLOCK_SIZE]; -static struct fat_device_s device_table[MAX_DEVICE]; static struct cpm_drive_s drv_table[MAX_DRIVE]; /* @@ -158,17 +151,6 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) goto out; } - /* TODO: this has to be done somewhere globaly */ - - if (!device_table[0].active) { - f_mount(&device_table[0].dd, "0:", 0); - device_table[0].active = true; - } - if (!device_table[1].active) { - f_mount(&device_table[1].dd, "1:", 0); - device_table[1].active = true; - } - /* uint32_t dph = ((uint32_t)msg[4] << 16) + ((uint16_t)msg[3] << 8) + msg[2]; */ @@ -489,11 +471,6 @@ void restart_z180_serv(void) z80_memfifo_init(i, 0); bg_setstat(handle_msg_handling, 0); - f_mount(NULL, "0:", 0); - device_table[0].active = false; - f_mount(NULL, "1:", 0); - device_table[1].active = false; - } /*--------------------------------------------------------------------------*/ diff --git a/avr/z80-if.c b/avr/z80-if.c index d5dc2d7..21ffeac 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -560,10 +560,9 @@ void z80_memfifo_init(const fifo_t f, uint32_t addr) { fifo_dsc[f].base = addr; - if (addr != 0) { - DBG_P(2, "z80_memfifo_init: %i, %lx\n", f, addr); + if (addr != 0) { z80_bus_cmd(Request); fifo_dsc[f].mask = z80_read(addr + FIFO_BUFSIZE_MASK); fifo_dsc[f].idx_in = z80_read(addr + FIFO_INDEX_IN); -- cgit v1.2.3 From 014840952dc85c55989a23a79b90d4d3f51de15c Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 16 May 2015 12:49:59 +0200 Subject: set MAX_DRIVE (number of CP/M disks) from 2 to 4 --- avr/z180-serv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 22dafe1..dfdb022 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -104,7 +104,7 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg) /* ---------------------------------------------------------------------------*/ -#define MAX_DRIVE 2 +#define MAX_DRIVE 4 #define BLOCK_SIZE 512 -- cgit v1.2.3 From daacc6f9a7aed67a0a40264e55595a4091a2293b Mon Sep 17 00:00:00 2001 From: Leo C Date: Sun, 17 May 2015 17:22:31 +0200 Subject: workaround for bank/common border crossing problem. Initial multi sector transfer. --- avr/z180-serv.c | 99 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 34 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index dfdb022..d6ab106 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -18,6 +18,7 @@ #include "debug.h" #include "print-utils.h" #include "z180-serv.h" +#include "timer.h" /*--------------------------------------------------------------------------*/ @@ -106,7 +107,8 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg) #define MAX_DRIVE 4 #define BLOCK_SIZE 512 - +#define TPA_BASE 0x10000 +#define COMMON_BASE 0xC000 struct cpm_drive_s { uint8_t drv; @@ -142,7 +144,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) goto out; } - debug("\n## login: %c:\n", msg[0]+'A'); + debug("\n## %7lu login: %c:\n", get_timer(0), msg[0]+'A'); drv = msg[0]; @@ -156,7 +158,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) */ if (drv_table[drv].img_name != NULL) { - debug("## close: '%s'\n", drv_table[drv].img_name); + debug("## %7lu close: '%s'\n", get_timer(0), drv_table[drv].img_name); f_close(&drv_table[drv].fd); free(drv_table[drv].img_name); drv_table[drv].img_name = NULL; @@ -174,7 +176,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) res = f_open(&drv_table[drv].fd, drv_table[drv].img_name, FA_WRITE | FA_READ); - debug("## open: '%s', (env: '%s'), res: %d\n", + debug("## %7lu open: '%s', (env: '%s'), res: %d\n", get_timer(0), drv_table[drv].img_name, disk_buffer, res); out: @@ -187,7 +189,7 @@ out: result_msg[2] = res >> 8; if (rc) { - debug("## error rc: %.02x, res: %d\n", rc, res); + debug("## %7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); }; /* send result*/ @@ -198,21 +200,29 @@ out: /* db 2 ; disk command ds 1 ; subcommand (login/read/write) - ds 1 ; @adrv (8 bits) +0 - ds 1 ; @rdrv (8 bits) +1 - ds 1 ; @cnt (8 bits) +2 - ds 2 ; @trk (16 bits) +3 - ds 2 ; @sect(16 bits) +5 + ds 1 ; @adrv (8 bits) +0 + ds 1 ; @rdrv (8 bits) +1 + ds 2 ; @trk (16 bits) +2 + ds 2 ; @sect(16 bits) +4 + ds 1 ; @cnt (8 bits) +6 ds 3 ; phys. transfer addr +7 */ +#define ADRV 0 +#define RDRV 1 +#define TRK 2 +#define SEC 4 +#define CNT 6 +#define ADDR 7 + void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) { uint8_t drv; uint32_t addr; uint32_t pos; - + unsigned int bytes; bool dowrite = (subf == 2); + bool hightpa = false; FRESULT res = 0; uint8_t rc = 0; bool buserr = 0; @@ -223,48 +233,59 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) goto out; } - drv = msg[0]; + drv = msg[ADRV]; if ( drv>= MAX_DRIVE) { rc = 0x02; goto out; } - addr = ((uint32_t)msg[9] << 16) + ((uint16_t)msg[8] << 8) + msg[7]; + bytes = msg[CNT] * BLOCK_SIZE; + addr = ((uint32_t)msg[ADDR+2] << 16) + ((uint16_t)msg[ADDR+1] << 8) + msg[ADDR]; - /* bytes = BLOCK_SIZE; */ /* TODO: multi sector count */ - pos = (((uint16_t)(msg[4] << 8) + msg[3]) * 8 - + ((uint32_t)(msg[6] << 8) + msg[5])) * BLOCK_SIZE; + /* TODO: tracks per sector from dpb */ + pos = (((uint16_t)(msg[TRK+1] << 8) + msg[TRK]) * 8 + + ((uint32_t)(msg[SEC+1] << 8) + msg[SEC])) * BLOCK_SIZE; - debug("## cpm_rw: %s %c: trk: %4d, sec: %d, pos: 0x%.5lx, addr: 0x%.5lx\n", - dowrite ? "write" : " read", msg[0]+'A', - ((uint16_t)(msg[4] << 8) + msg[3]), msg[5], pos, addr); + debug("## %7lu cpm_rw: %s %c: trk: %4d, sec: %d, pos: 0x%.8lx, secs: %2d\n", + get_timer(0), dowrite ? "write" : " read", msg[ADRV]+'A', + ((uint16_t)(msg[TRK+1] << 8) + msg[TRK]), msg[SEC], pos, msg[CNT]); /* TODO: check bank boundary crossing */ - /* - if (addr + BLOCK_SIZE > MAX_MEMORY) - ... = MAX_MEMORY - addr; - */ - res = f_lseek(&drv_table[drv].fd, pos); - if (!res) { - unsigned int br; + while (!res && bytes) { + unsigned int cnt, br; + + if (bytes >= BLOCK_SIZE) + cnt = BLOCK_SIZE; + else + cnt = bytes; + + if (addr < (TPA_BASE + COMMON_BASE) && + (addr + cnt) > (TPA_BASE + COMMON_BASE)) { + cnt = (TPA_BASE + COMMON_BASE) - addr; + hightpa = true; + } + + bytes -= cnt; + + debug("## %7lu " + " addr: 0x%.5lx, cnt: %3d\n", + get_timer(0), addr, cnt); if (dowrite) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; } else { - z80_read_block(disk_buffer, addr, BLOCK_SIZE); + z80_read_block(disk_buffer, addr, cnt); z80_bus_cmd(Release); - res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); - if (!res) - res = f_sync(&drv_table[drv].fd); + res = f_write(&drv_table[drv].fd, disk_buffer, cnt, &br); } } else { - res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); + res = f_read(&drv_table[drv].fd, disk_buffer, cnt, &br); if (res == FR_OK) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; @@ -275,13 +296,23 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) } } - if (br != BLOCK_SIZE) { - debug("## f_read res: %d, bytes rd/wr: %u\n", res, br); + addr += br; + if (hightpa) { + addr -= TPA_BASE; + hightpa = false; + } + + if (br != cnt) { + debug("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, br); dump_ram(disk_buffer, 0, 64, "Read Data"); res = -1; } + } + if (dowrite && !res) + res = f_sync(&drv_table[drv].fd); + out: if (buserr) { debug("Bus timeout\n"); @@ -295,7 +326,7 @@ out: result_msg[2] = res >> 8; if (rc) { - debug("#### error rc: %.02x, res: %d\n", rc, res); + debug("###%7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); } /* send result*/ -- cgit v1.2.3 From 7d60b20bb8d675edafdb14638fee5001987c78c1 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 18 May 2015 08:44:21 +0200 Subject: debug_cpmsd macro --- avr/z180-serv.c | 88 ++++++++++++++++++++++++++++++--------------------------- z180/config.inc | 17 +++++++++++ 2 files changed, 63 insertions(+), 42 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index d6ab106..9b4228a 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -20,6 +20,14 @@ #include "z180-serv.h" #include "timer.h" + +#define DEBUG_CPM_SDIO 0 /* set to 1 to debug */ + +#define debug_cpmsd(fmt, args...) \ + debug_cond(DEBUG_CPM_SDIO, fmt, ##args) + + + /*--------------------------------------------------------------------------*/ @@ -144,7 +152,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) goto out; } - debug("\n## %7lu login: %c:\n", get_timer(0), msg[0]+'A'); + debug_cpmsd("\n## %7lu login: %c:\n", get_timer(0), msg[0]+'A'); drv = msg[0]; @@ -158,7 +166,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) */ if (drv_table[drv].img_name != NULL) { - debug("## %7lu close: '%s'\n", get_timer(0), drv_table[drv].img_name); + debug_cpmsd("## %7lu close: '%s'\n", get_timer(0), drv_table[drv].img_name); f_close(&drv_table[drv].fd); free(drv_table[drv].img_name); drv_table[drv].img_name = NULL; @@ -176,7 +184,7 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) res = f_open(&drv_table[drv].fd, drv_table[drv].img_name, FA_WRITE | FA_READ); - debug("## %7lu open: '%s', (env: '%s'), res: %d\n", get_timer(0), + debug_cpmsd("## %7lu open: '%s', (env: '%s'), res: %d\n", get_timer(0), drv_table[drv].img_name, disk_buffer, res); out: @@ -189,7 +197,7 @@ out: result_msg[2] = res >> 8; if (rc) { - debug("## %7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); + debug_cpmsd("## %7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); }; /* send result*/ @@ -220,9 +228,8 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) uint8_t drv; uint32_t addr; uint32_t pos; - unsigned int bytes; + uint8_t secs; bool dowrite = (subf == 2); - bool hightpa = false; FRESULT res = 0; uint8_t rc = 0; bool buserr = 0; @@ -239,7 +246,7 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) goto out; } - bytes = msg[CNT] * BLOCK_SIZE; + secs = msg[CNT]; addr = ((uint32_t)msg[ADDR+2] << 16) + ((uint16_t)msg[ADDR+1] << 8) + msg[ADDR]; @@ -247,67 +254,64 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) pos = (((uint16_t)(msg[TRK+1] << 8) + msg[TRK]) * 8 + ((uint32_t)(msg[SEC+1] << 8) + msg[SEC])) * BLOCK_SIZE; - debug("## %7lu cpm_rw: %s %c: trk: %4d, sec: %d, pos: 0x%.8lx, secs: %2d\n", - get_timer(0), dowrite ? "write" : " read", msg[ADRV]+'A', - ((uint16_t)(msg[TRK+1] << 8) + msg[TRK]), msg[SEC], pos, msg[CNT]); - - - - /* TODO: check bank boundary crossing */ + debug_cpmsd("## %7lu cpm_rw: %s %c: trk:%4d, sec: %d, pos: %.8lx, secs: %2d, " + "addr: %.5lx\n", get_timer(0), dowrite ? "write" : " read", + msg[ADRV]+'A', ((uint16_t)(msg[TRK+1] << 8) + msg[TRK]), msg[SEC], + pos, msg[CNT], addr); res = f_lseek(&drv_table[drv].fd, pos); - while (!res && bytes) { + while (!res && secs--) { unsigned int cnt, br; - if (bytes >= BLOCK_SIZE) - cnt = BLOCK_SIZE; - else - cnt = bytes; - + /* check bank boundary crossing */ + cnt = 0; if (addr < (TPA_BASE + COMMON_BASE) && - (addr + cnt) > (TPA_BASE + COMMON_BASE)) { + (addr + BLOCK_SIZE) > (TPA_BASE + COMMON_BASE)) { cnt = (TPA_BASE + COMMON_BASE) - addr; - hightpa = true; } - bytes -= cnt; - - debug("## %7lu " - " addr: 0x%.5lx, cnt: %3d\n", - get_timer(0), addr, cnt); + if (cnt) { + debug_cpmsd("## %67c addr: %.5lx, cnt: %3d\n", ' ', addr, cnt); + debug_cpmsd("## %67c addr: %.5lx, cnt: %3d\n", ' ', addr+cnt-TPA_BASE, BLOCK_SIZE-cnt); + } if (dowrite) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; + break; } else { - z80_read_block(disk_buffer, addr, cnt); + if (cnt) { + z80_read_block(disk_buffer, addr, cnt); + addr = addr + cnt - TPA_BASE; + } + z80_read_block(disk_buffer+cnt, addr, BLOCK_SIZE - cnt); z80_bus_cmd(Release); - res = f_write(&drv_table[drv].fd, disk_buffer, cnt, &br); } + res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); } else { - res = f_read(&drv_table[drv].fd, disk_buffer, cnt, &br); - if (res == FR_OK) { + res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); + if (res == FR_OK && br == BLOCK_SIZE) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; + break; } else { - z80_write_block(disk_buffer, addr, br); + if (cnt) { + z80_write_block(disk_buffer, addr, cnt); + addr = addr + cnt - TPA_BASE; + } + z80_write_block(disk_buffer+cnt, addr, BLOCK_SIZE - cnt); z80_bus_cmd(Release); } } } - addr += br; - if (hightpa) { - addr -= TPA_BASE; - hightpa = false; - } - - if (br != cnt) { - debug("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, br); + if (br != BLOCK_SIZE) { + debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, br); dump_ram(disk_buffer, 0, 64, "Read Data"); res = -1; } + addr += BLOCK_SIZE; } if (dowrite && !res) @@ -315,7 +319,7 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) out: if (buserr) { - debug("Bus timeout\n"); + debug_cpmsd("Bus timeout\n"); rc = 0x03; } if (res) @@ -326,7 +330,7 @@ out: result_msg[2] = res >> 8; if (rc) { - debug("###%7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); + debug_cpmsd("###%7lu error rc: %.02x, res: %d\n", get_timer(0), rc, res); } /* send result*/ diff --git a/z180/config.inc b/z180/config.inc index dfb41cd..7b6d7ac 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -2,6 +2,9 @@ FALSE equ 0 TRUE equ NOT FALSE + +DEBUG equ true + banked equ true ;----------------------------------------------------- @@ -21,6 +24,20 @@ AVRCLK equ 18432 ;[KHz] FOSC equ AVRCLK/2 ;Oscillator frequency [KHz] PHI equ FOSC*2 ;CPU frequency (clock doubler enabled) +;---------------------------------------------------------------------- +; Baudrate Generator for x16 clock mode: +; TC = (f PHI / (32 * baudrate)) - 2 +; +; PHI [MHz]: 9.216 18.432 +; baudrate TC TC +; ---------------------- +; 115200 - 3 +; 57600 3 8 +; 38400 - 13 +; 19200 13 28 +; 9600 28 58 + + ;----------------------------------------------------- ; Programmable Reload Timer (PRT) -- cgit v1.2.3 From 393b1897603fddeb4f16170880ddd9414b3726e0 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 21 May 2015 17:29:19 +0200 Subject: f_sync only, when timout (currently 1s) after last write operation. --- avr/command_tbl.c | 24 ++++++++++++ avr/z180-serv.c | 109 ++++++++++++++++++++++++++++++++++-------------------- include/config.h | 4 ++ 3 files changed, 96 insertions(+), 41 deletions(-) (limited to 'avr') 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 */ -- cgit v1.2.3 From 8590a76bcc7cbe1443abf37498f824a0eab0c8d7 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 28 May 2015 22:56:55 +0200 Subject: Server: get_time command/response --- avr/z180-serv.c | 13 + z180/ddtz.180 | 1074 +++++++++++++++++++++++++++--------------------------- z180/z180reg.inc | 2 +- 3 files changed, 552 insertions(+), 537 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index bf49a6c..c7869a6 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -111,6 +111,16 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg) msg_xmit(1, 3, len, msg); } +/* get timer */ +void do_msg_get_timer(uint8_t subf, int len, uint8_t * msg) +{ + (void)len; (void)msg; + + uint32_t time_ms = get_timer(0); + + msg_xmit(3, subf, sizeof(time_ms), (uint8_t *) &time_ms); +} + /* ---------------------------------------------------------------------------*/ #define MAX_DRIVE 4 @@ -381,6 +391,9 @@ const FLASH struct msg_item z80_messages[] = { 2, 1, 2, do_msg_cpm_rw}, + { 3, + 1, 1, + do_msg_get_timer}, { 0xff, /* end mark */ 0, 0, 0}, diff --git a/z180/ddtz.180 b/z180/ddtz.180 index e8a26fd..aa4e977 100644 --- a/z180/ddtz.180 +++ b/z180/ddtz.180 @@ -957,449 +957,450 @@ do_op_mod: ex de,hl jr l0b58h +; divide x/y +; x: hl +; y: de +; return: +; x/y: hl +; rem: de + DIV_HL_DE: - push bc - ex de,hl - ld b,h - ld c,l - ld hl,0 - ld a,16 + push bc + ex de,hl ;de = x, hl = y + ld b,h ;bc = y + ld c,l + ld hl,0 ;r = 0 + ld a,16 ;count l0b89h: - push af - add hl,hl - ex de,hl - xor a - add hl,hl - ex de,hl - adc a,l - sub c - ld l,a - ld a,h - sbc a,b - ld h,a - inc de - jr nc,l0b9ah - add hl,bc - dec de -l0b9ah: - pop af - dec a - jr nz,l0b89h - ex de,hl - pop bc + ex de,hl ;x + add hl,hl ;x <<= 1 + ex de,hl ;r + adc hl,hl ;r <<= 1 + + or a + sbc hl,bc + inc de + jr nc,div_no_restore + add hl,bc + dec de +div_no_restore: + dec a + jr nz,l0b89h + ex de,hl + pop bc ret do_op_and: - ld a,h - and d - ld h,a - ld a,l - and e - ld l,a - jr l0b58h + ld a,h + and d + ld h,a + ld a,l + and e + ld l,a + jr l0b58h do_op_or: - ld a,h - or d - ld h,a - ld a,l - or e - ld l,a - jr l0b58h + ld a,h + or d + ld h,a + ld a,l + or e + ld l,a + jr l0b58h do_op_xor: - ld a,h - xor d - ld h,a - ld a,l - xor e - ld l,a - jr l0b58h + ld a,h + xor d + ld h,a + ld a,l + xor e + ld l,a + jr l0b58h do_binary_op: - push hl - ld hl,tab_op_a - call lookupch - ld a,b - ld hl,tab_func_opa - add a,a - call ADD_HL_A - ld c,(hl) - inc hl - ld b,(hl) - pop hl + push hl + ld hl,tab_op_a + call lookupch + ld a,b + ld hl,tab_func_opa + add a,a + call ADD_HL_A + ld c,(hl) + inc hl + ld b,(hl) + pop hl ret tab_op_a: DB '+-*/%&!#',0 tab_func_opa: - defw do_op_add - defw do_op_sub - defw do_op_mlt - defw do_op_div - defw do_op_mod - defw do_op_and - defw do_op_or - defw do_op_xor - defw 0 + defw do_op_add + defw do_op_sub + defw do_op_mlt + defw do_op_div + defw do_op_mod + defw do_op_and + defw do_op_or + defw do_op_xor + defw 0 fact_factor: - call do_factor - ret nc - jp ERROR + call do_factor + ret nc + jp ERROR do_factor: - call chk.sp - call get.number - ret nc - inc de - ld hl,TOPRAM - cp 'T' - ret z - ld hl,(HILOD) - cp 'H' - ret z - ld hl,(MAXLOD) - cp 'M' - ret z - ld hl,TPA - cp 'L' - ret z - ld hl,(offs.@) - cp '@' - ret z - ld hl,(OFFS.pc) - cp '$' - ret z - cp '-' - jr z,fact_factneg - cp '~' - jr z,fact_factinv - cp '+' - jr z,fact_factor - cp '^' - jr z,fact_reg.CPU - cp 'Y' - jr z,fact_reg.Y - cp '(' - jr z,fact_mem - cp '[' - jp z,EXPR_BRCKT ;0c35 [ expression ] - cp '''' - jr z,fact_factstring - dec de + call chk.sp + call get.number + ret nc + inc de + ld hl,TOPRAM + cp 'T' + ret z + ld hl,(HILOD) + cp 'H' + ret z + ld hl,(MAXLOD) + cp 'M' + ret z + ld hl,TPA + cp 'L' + ret z + ld hl,(offs.@) + cp '@' + ret z + ld hl,(OFFS.pc) + cp '$' + ret z + cp '-' + jr z,fact_factneg + cp '~' + jr z,fact_factinv + cp '+' + jr z,fact_factor + cp '^' + jr z,fact_reg.CPU + cp 'Y' + jr z,fact_reg.Y + cp '(' + jr z,fact_mem + cp '[' + jp z,EXPR_BRCKT ;0c35 [ expression ] + cp '''' + jr z,fact_factstring + dec de scf ret fact_reg.Y: - call get.decdigit - jp c,ERROR - inc de - add a,a - ld hl,reg.Y - call ADD_HL_A - ld a,(hl) - inc hl - ld h,(hl) - ld l,a - and a + call get.decdigit + jp c,ERROR + inc de + add a,a + ld hl,reg.Y + call ADD_HL_A + ld a,(hl) + inc hl + ld h,(hl) + ld l,a + and a ret fact_factstring: - ld hl,0 + ld hl,0 l0c56h: - ld a,(de) - cp '''' - jr z,l0c62h - and a - ret z + ld a,(de) + cp '''' + jr z,l0c62h + and a + ret z l0c5dh: - ld h,l - ld l,a - inc de - jr l0c56h + ld h,l + ld l,a + inc de + jr l0c56h l0c62h: - inc de - ld a,(de) - cp '''' - jr z,l0c5dh - sub '.' - or a - ret nz - inc de - set 7,l + inc de + ld a,(de) + cp '''' + jr z,l0c5dh + sub '.' + or a + ret nz + inc de + set 7,l ret fact_reg.CPU: - call sub_1315h - jr nc,l0cbbh - ld a,(hl) - inc hl - ld h,(hl) - ld l,a - and a - bit 0,c - ret nz - ld h,000h + call sub_1315h + jr nc,l0cbbh + ld a,(hl) + inc hl + ld h,(hl) + ld l,a + and a + bit 0,c + ret nz + ld h,000h ret fact_factneg: - call fact_factor - dec hl + call fact_factor + dec hl cpl.hl: - ld a,h + ld a,h cpl - ld h,a - ld a,l + ld h,a + ld a,l cpl - ld l,a + ld l,a ret fact_factinv: - call fact_factor - jr cpl.hl + call fact_factor + jr cpl.hl fact_mem: - call EXPR1 - jr c,l0cbbh - ld a,(de) - cp ')' - jr nz,l0cbbh - inc de + call EXPR1 + jr c,l0cbbh + ld a,(de) + cp ')' + jr nz,l0cbbh + inc de comst - ld a,(hl) - inc hl ; - ld h,(hl) ; + ld a,(hl) + inc hl ; + ld h,(hl) ; comend - ld l,a - ld a,(de) - inc de - cp '.' - ret z - dec de - xor a - ld h,a + ld l,a + ld a,(de) + inc de + cp '.' + ret z + dec de + xor a + ld h,a ret EXPR_BRCKT: - call EXPR1 - jr c,l0cbbh - ld a,(de) - cp ']' - inc de - ret z + call EXPR1 + jr c,l0cbbh + ld a,(de) + cp ']' + inc de + ret z l0cbbh: - jp ERROR + jp ERROR get.number: - call get.hexdigit - ret c - push de + call get.hexdigit + ret c + push de l0cc3h: - inc de - call get.hexdigit - jr nc,l0cc3h - pop de - cp '.' - jr z,l0d04h - cp '"' - jr z,l0ce9h - ld hl,0 + inc de + call get.hexdigit + jr nc,l0cc3h + pop de + cp '.' + jr z,l0d04h + cp '"' + jr z,l0ce9h + ld hl,0 l0cd5h: - call get.hexdigit - jr c,l0ce4h - add hl,hl - add hl,hl - add hl,hl - add hl,hl - call ADD_HL_A - inc de - jr l0cd5h + call get.hexdigit + jr c,l0ce4h + add hl,hl + add hl,hl + add hl,hl + add hl,hl + call ADD_HL_A + inc de + jr l0cd5h l0ce4h: - xor 'H' - ret nz - inc de + xor 'H' + ret nz + inc de ret l0ce9h: - ld hl,0 + ld hl,0 l0cech: - call get.decdigit + call get.decdigit l0cefh: - inc de - jr c,l0cf8h - add hl,hl - call ADD_HL_A - jr l0cech + inc de + jr c,l0cf8h + add hl,hl + call ADD_HL_A + jr l0cech l0cf8h: - cp '"' - jp nz,ERROR - call get.decdigit - jr nc,l0cefh - or a + cp '"' + jp nz,ERROR + call get.decdigit + jr nc,l0cefh + or a ret l0d04h: - ld hl,0 + ld hl,0 l0d07h: - call get.decdigit - inc de - jr c,l0d1ah - push bc - add hl,hl ;0d0e hl *= 10 - ld b,h - ld c,l - add hl,hl - add hl,hl - add hl,bc - pop bc - call ADD_HL_A - jr l0d07h + call get.decdigit + inc de + jr c,l0d1ah + push bc + add hl,hl ;0d0e hl *= 10 + ld b,h + ld c,l + add hl,hl + add hl,hl + add hl,bc + pop bc + call ADD_HL_A + jr l0d07h l0d1ah: - cp '.' - ret z - jp ERROR + cp '.' + ret z + jp ERROR sub_0d20h: - ld a,(de) - cp 05bh - jr l0d28h + ld a,(de) + cp 05bh + jr l0d28h get.hexdigit: - ld a,(de) + ld a,(de) sub_0d26h: - cp 'F'+1 + cp 'F'+1 l0d28h: ccf - ret c - cp 'A' - jr c,l0d32h - sub 'A'-10 + ret c + cp 'A' + jr c,l0d32h + sub 'A'-10 ret get.decdigit: - ld a,(de) + ld a,(de) l0d32h: - cp '9'+1 - jr l0d39h + cp '9'+1 + jr l0d39h get.bindigit: - ld a,(de) - cp '1'+1 + ld a,(de) + cp '1'+1 l0d39h: ccf - ret c - cp '0' - ret c - sub '0' + ret c + cp '0' + ret c + sub '0' ret l0d41h: - call assert_eol + call assert_eol prnt_cpustat: - call prnt_f - call outbl2 - ld hl,b_0x0DFD_start - ld de,b_0x0E1D_start - ld b,006h + call prnt_f + call outbl2 + ld hl,b_0x0DFD_start + ld de,b_0x0E1D_start + ld b,006h l0d52h: - call prnt_regs - djnz l0d52h - push hl - push de - ld iy,(REG.PC) - call sub_1f77h + call prnt_regs + djnz l0d52h + push hl + push de + ld iy,(REG.PC) + call sub_1f77h exx - ex af,af' - call CRLF - call prnt_f2 - call outbl2 - pop de - pop hl - ld b,007h + ex af,af' + call CRLF + call prnt_f2 + call outbl2 + pop de + pop hl + ld b,007h l0d6fh: - call prnt_regs - djnz l0d6fh + call prnt_regs + djnz l0d6fh exx - ex af,af' - and a - jr z,l0d7fh - call outbl6 - call sub_1f5bh + ex af,af' + and a + jr z,l0d7fh + call outbl6 + call sub_1f5bh l0d7fh: - jp crlf + jp crlf prnt_f: - ld a,(reg.f) - call prnt_flags - ld a,(reg.iff) - cp 0f3h - jp z,outbl - ld a,'E' - jp outchar + ld a,(reg.f) + call prnt_flags + ld a,(reg.iff) + cp 0f3h + jp z,outbl + ld a,'E' + jp outchar prnt_f2: - ld a,(reg.f2) - call prnt_flags - jp outbl + ld a,(reg.f2) + call prnt_flags + jp outbl prnt_flags: - ld b,a - ld a,'S' - call sub_0dbeh - ld a,'Z' - call sub_0dbeh - rl b - ld a,'H' - call sub_0dbeh - rl b - ld a,'V' - call sub_0dbeh - ld a,'N' - call sub_0dbeh - ld a,'C' + ld b,a + ld a,'S' + call sub_0dbeh + ld a,'Z' + call sub_0dbeh + rl b + ld a,'H' + call sub_0dbeh + rl b + ld a,'V' + call sub_0dbeh + ld a,'N' + call sub_0dbeh + ld a,'C' sub_0dbeh: - rl b - jp c,OUTCHAR - jp OUTBL + rl b + jp c,OUTCHAR + jp OUTBL prnt_regs: - push bc - push de - call PSTR - ld a,'=' - call OUTCHAR - ex (sp),hl - ld e,(hl) - inc hl - ld d,(hl) - inc hl - ld a,(hl) - inc hl - push hl - and a - jr z,l0df2h - push af - ld a,(de) - ld l,a - inc de - ld a,(de) - ld h,a - pop af - dec a - jr z,l0dedh - call out.hl.@ - call z,outbl6 - jr l0df6h + push bc + push de + call PSTR + ld a,'=' + call OUTCHAR + ex (sp),hl + ld e,(hl) + inc hl + ld d,(hl) + inc hl + ld a,(hl) + inc hl + push hl + and a + jr z,l0df2h + push af + ld a,(de) + ld l,a + inc de + ld a,(de) + ld h,a + pop af + dec a + jr z,l0dedh + call out.hl.@ + call z,outbl6 + jr l0df6h l0dedh: - call out.hl - jr l0df6h + call out.hl + jr l0df6h l0df2h: - ld a,(de) - call out.hex + ld a,(de) + call out.hex l0df6h: - call OUTBL - pop de - pop hl - pop bc + call OUTBL + pop de + pop hl + pop bc ret b_0x0DFD_start: @@ -1419,234 +1420,234 @@ b_0x0DFD_start: DB 0 b_0x0E1D_start: - defw reg.a - defb 000h - defw reg.c - defb 001h - defw reg.e - defb 001h - defw reg.l - defb 001h - defw reg.sp - defb 001h - defw reg.pc - defb 002h - defw reg.a2 - defb 000h - defw reg.c2 - defb 001h - defw reg.e2 - defb 001h - defw reg.l2 - defb 001h - defw reg.ix - defb 001h - defw reg.iy - defb 001h - defw reg.i + defw reg.a + defb 000h + defw reg.c + defb 001h + defw reg.e + defb 001h + defw reg.l + defb 001h + defw reg.sp + defb 001h + defw reg.pc + defb 002h + defw reg.a2 + defb 000h + defw reg.c2 + defb 001h + defw reg.e2 + defb 001h + defw reg.l2 + defb 001h + defw reg.ix + defb 001h + defw reg.iy + defb 001h + defw reg.i dw 0 CMD.G: - sub a - ld (TCFLG),a - ld (XA747),a - call EXPR - jr c,l0e54h - ld (REG.PC),hl + sub a + ld (TCFLG),a + ld (XA747),a + call EXPR + jr c,l0e54h + ld (REG.PC),hl l0e54h: - call SKIPBL - jp z,l1183h - cp ';' - jp nz,ERROR - inc de - ld a,002h - call sub_0f24h - jp l1183h + call SKIPBL + jp z,l1183h + cp ';' + jp nz,ERROR + inc de + ld a,002h + call sub_0f24h + jp l1183h sub_0e68h: - ld b,BP_CNT - ld ix,bp_tab + ld b,BP_CNT + ld ix,bp_tab l0e6eh: - ld a,(ix+000h) - and 0f1h - ld (ix+000h),a - call sub_11c5h - ld de,BP_SIZE - add ix,de - djnz l0e6eh + ld a,(ix+000h) + and 0f1h + ld (ix+000h),a + call sub_11c5h + ld de,BP_SIZE + add ix,de + djnz l0e6eh ret CMD.B: - call SKIPBL - jr z,l0ecbh - inc de - cp 'X' - jr z,l0e91h - dec de - ld a,001h - jp sub_0f24h + call SKIPBL + jr z,l0ecbh + inc de + cp 'X' + jr z,l0e91h + dec de + ld a,001h + jp sub_0f24h l0e91h: - call SKIPBL - jr z,l0ea6h + call SKIPBL + jr z,l0ea6h l0e96h: - call EXPR - jp c,assert_eol - push de - call sub_0ea7h - pop de - call skip_to_nextarg - jr l0e96h + call EXPR + jp c,assert_eol + push de + call sub_0ea7h + pop de + call skip_to_nextarg + jr l0e96h l0ea6h: scf sub_0ea7h: - ld b,BP_CNT - ld ix,bp_tab + ld b,BP_CNT + ld ix,bp_tab l0eadh: - push af - jr c,l0ebbh - ld e,(ix+002h) - ld d,(ix+003h) - call CP.HL.DE - jr nz,l0ec2h + push af + jr c,l0ebbh + ld e,(ix+002h) + ld d,(ix+003h) + call CP.HL.DE + jr nz,l0ec2h l0ebbh: - ld (ix+000h),000h - call sub_11c5h + ld (ix+000h),000h + call sub_11c5h l0ec2h: - ld de,BP_SIZE - add ix,de - pop af - djnz l0eadh + ld de,BP_SIZE + add ix,de + pop af + djnz l0eadh ret l0ecbh: - ld b,BP_CNT - ld ix,bp_tab + ld b,BP_CNT + ld ix,bp_tab l0ed1h: - bit 0,(ix+000h) - jr z,l0f1ch - ld a,'R' - bit 4,(ix+000h) - jr nz,l0ee1h - ld a,' ' + bit 0,(ix+000h) + jr z,l0f1ch + ld a,'R' + bit 4,(ix+000h) + jr nz,l0ee1h + ld a,' ' l0ee1h: - call OUTCHAR - call OUTBL - ld l,(ix+002h) - ld h,(ix+003h) - call out.hl.@ - call outbl2 - ld a,':' - call OUTCHAR - ld l,(ix+004h) - ld h,(ix+005h) - call out.hl - ld l,(ix+006h) - ld h,(ix+007h) - ld a,h - or l - jr z,l0f19h - call outbl4 - ld a,'I' - call OUTCHAR - call outbl2 - call PSTR + call OUTCHAR + call OUTBL + ld l,(ix+002h) + ld h,(ix+003h) + call out.hl.@ + call outbl2 + ld a,':' + call OUTCHAR + ld l,(ix+004h) + ld h,(ix+005h) + call out.hl + ld l,(ix+006h) + ld h,(ix+007h) + ld a,h + or l + jr z,l0f19h + call outbl4 + ld a,'I' + call OUTCHAR + call outbl2 + call PSTR l0f19h: - call CRLF + call CRLF l0f1ch: - ld de,BP_SIZE - add ix,de - djnz l0ed1h + ld de,BP_SIZE + add ix,de + djnz l0ed1h ret sub_0f24h: - ld b,a - call SKIPBL - ret z - cp 'R' - jr nz,l0f30h - inc de - set 4,b + ld b,a + call SKIPBL + ret z + cp 'R' + jr nz,l0f30h + inc de + set 4,b l0f30h: - push bc - call EXPR - jp c,ERROR - pop bc - bit 0,b - push bc - push de - push hl - call nz,sub_0ea7h - pop hl - call sub_0f68h - pop de - ld (ix+002h),l - ld (ix+003h),h - call sub_0f80h - ld (ix+004h),l - ld (ix+005h),h - call sub_0f91h - ld (ix+006h),l - ld (ix+007h),h - call skip_to_nextarg - pop af - ld (ix+000h),a - and 00fh - jr sub_0f24h + push bc + call EXPR + jp c,ERROR + pop bc + bit 0,b + push bc + push de + push hl + call nz,sub_0ea7h + pop hl + call sub_0f68h + pop de + ld (ix+002h),l + ld (ix+003h),h + call sub_0f80h + ld (ix+004h),l + ld (ix+005h),h + call sub_0f91h + ld (ix+006h),l + ld (ix+007h),h + call skip_to_nextarg + pop af + ld (ix+000h),a + and 00fh + jr sub_0f24h sub_0f68h: - ld b,BP_CNT - ld ix,bp_tab + ld b,BP_CNT + ld ix,bp_tab l0f6eh: - ld a,(ix+000h) - and 00fh - ret z - push bc - ld bc,BP_SIZE - add ix,bc - pop bc - djnz l0f6eh - jp ERROR + ld a,(ix+000h) + and 00fh + ret z + push bc + ld bc,BP_SIZE + add ix,bc + pop bc + djnz l0f6eh + jp ERROR sub_0f80h: - call SKIPBL - ld hl,1 - cp 03ah - ret nz - inc de - call EXPR - jp c,ERROR + call SKIPBL + ld hl,1 + cp 03ah + ret nz + inc de + call EXPR + jp c,ERROR ret sub_0f91h: - call SKIPBL - cp 049h - ld hl,0 - ret nz - inc de - call SKIPBL - push de - call EXPR - jp c,ERROR - ex de,hl - pop de - push de - sbc hl,de - ld b,h - ld c,l - ld hl,(sexp1) - push hl - add hl,bc - ld de,sexpbufe - call CP.HL.DE - jp nc,ERROR - pop hl - ld (sexp2),hl - pop de - ex de,hl + call SKIPBL + cp 049h + ld hl,0 + ret nz + inc de + call SKIPBL + push de + call EXPR + jp c,ERROR + ex de,hl + pop de + push de + sbc hl,de + ld b,h + ld c,l + ld hl,(sexp1) + push hl + add hl,bc + ld de,sexpbufe + call CP.HL.DE + jp nc,ERROR + pop hl + ld (sexp2),hl + pop de + ex de,hl ldir - xor a - ld (de),a - inc de - ex de,hl - ld (sexp1),hl - ld hl,(sexp2) + xor a + ld (de),a + inc de + ex de,hl + ld (sexp1),hl + ld hl,(sexp2) ret bpddtz: @@ -4752,6 +4753,7 @@ b_0x2108_start: ; 1 byte opcodes defb 029h defw l254bh + defb 0c7h ;216c inc r defb 004h defb 041h diff --git a/z180/z180reg.inc b/z180/z180reg.inc index 271a446..a248f5f 100644 --- a/z180/z180reg.inc +++ b/z180/z180reg.inc @@ -24,7 +24,7 @@ cntla1 equ IOBASE+01h ;ASCI Control Register A Channel 1 b2m MPBR, 3 ;Multiprocessor Bit Receive (Read) b2m EFR, 3 ;Error Flag Reset (Write) b2m MOD2, 2 ;Data Format Mode 1 = 8-Bit data - b2m NOD1, 1 ;1 = Parity enabled + b2m MOD1, 1 ;1 = Parity enabled b2m MOD0, 0 ;1 = 2 stop bits cntlb0 equ IOBASE+02h ;ASCI Control Register B Channel 0 -- cgit v1.2.3 From a8eb521f94848a627a3fe470e34f62b13c157d34 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 30 May 2015 11:47:03 +0200 Subject: return timestamp diff --- avr/z180-serv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index c7869a6..af1d8e0 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -114,10 +114,9 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg) /* get timer */ void do_msg_get_timer(uint8_t subf, int len, uint8_t * msg) { - (void)len; (void)msg; - - uint32_t time_ms = get_timer(0); + uint32_t time_ms = (len >= 4) ? *(uint32_t *) msg : 0; + time_ms = get_timer(time_ms); msg_xmit(3, subf, sizeof(time_ms), (uint8_t *) &time_ms); } -- cgit v1.2.3 From ad9bc17c8ecab1f0bbd26f2270d4d396f4bc5e52 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Jun 2015 23:29:55 +0200 Subject: switch fifos conin,conout --- avr/cmd_loadcpm3.c | 1 + avr/cmd_mem.c | 4 +-- avr/command_tbl.c | 12 ++++++++ avr/debug.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++---- avr/z180-serv.c | 3 ++ include/z80-if.h | 2 +- z180/conbuf-a.180 | 2 +- z180/config.inc | 9 +++++- z180/ddtz.180 | 19 +++++++----- z180/init.180 | 4 +-- 10 files changed, 125 insertions(+), 19 deletions(-) (limited to 'avr') diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c index fd685b2..3f1bbe1 100644 --- a/avr/cmd_loadcpm3.c +++ b/avr/cmd_loadcpm3.c @@ -55,6 +55,7 @@ int load(FIL *File, uint16_t addr, uint8_t len) return 0; } +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index 53b1842..101b912 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -152,8 +152,8 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) if (incrflag) addr += nbytes ? -1 : 1; nbytes = 1; - } - else { + + } else { char *endp; data = strtoul(console_buffer, &endp, 16); nbytes = endp - console_buffer; diff --git a/avr/command_tbl.c b/avr/command_tbl.c index eb0d84f..a9cc2bd 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -25,6 +25,8 @@ 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 []); extern command_ret_t do_dump_mem(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_mm_avr(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_nm_avr(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_eep_cp(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_busreq_pulse(cmd_tbl_t *, int, int, char * const []); extern command_ret_t do_date(cmd_tbl_t *, int, int, char * const []); @@ -75,6 +77,16 @@ CMD_TBL_ITEM( "EEPROM copy", "source target count" ), +CMD_TBL_ITEM( + !mm, 2, 1, do_mem_mm_avr, + "avr memory modify (auto-incrementing address)", + "address" +), +CMD_TBL_ITEM( + !nm, 2, 1, do_mem_nm_avr, + "avr memory modify (constant address)", + "address" +), #endif CMD_TBL_ITEM( mstep, 2, 1, do_busreq_pulse, diff --git a/avr/debug.c b/avr/debug.c index d4ae1f4..f3632c2 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -11,6 +11,7 @@ #include #include "command.h" +#include "cli_readline.h" #include "print-utils.h" #include "debug.h" @@ -39,7 +40,7 @@ void dump_heap(void) */ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count); + void (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count); (void) cmdtp; (void) flag; @@ -51,13 +52,13 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg switch (argv[0][3]) { case 'r': - readhow = ram_read_buf; + readwhat = ram_read_buf; break; case 'e': - readhow = eeprom_read_buf; + readwhat = eeprom_read_buf; break; case 'f': - readhow = flash_read_buf; + readwhat = flash_read_buf; break; default: return CMD_RET_USAGE; @@ -71,7 +72,7 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg length = (uint16_t) strtoul(argv[2], NULL, 16); /* Print the lines. */ - dump_mem(addr, addr, length, readhow, NULL); + dump_mem(addr, addr, length, readwhat, NULL); return CMD_RET_SUCCESS; } @@ -127,6 +128,83 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } +/* Modify memory. + * + * Syntax: + * !mm {addr} + * !nm {addr} + */ + + static uint8_t *mm_last_addr; + +static command_ret_t +mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) +{ + uint8_t *addr; + uint8_t data; + int nbytes; + + (void) cmdtp; + + if (argc != 2) + return CMD_RET_USAGE; + + /* We use the last specified parameters, unless new ones are + * entered. + */ + addr = mm_last_addr; + + if ((flag & CMD_FLAG_REPEAT) == 0) { + /* New command specified. + */ + + /* Address is specified since argc > 1 + */ + addr = (uint8_t *) (size_t) strtoul(argv[1], NULL, 16); + } + + /* Print the address, followed by value. Then accept input for + * the next value. A non-converted value exits. + */ + do { + data = *addr; + printf_P(PSTR("%04x: %02x"), addr, data); + + nbytes = cli_readline(PSTR(" ? ")); + if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { + /* pressed as only input, don't modify current + * location and move to next. "-" pressed will go back. + */ + if (incrflag) + addr += nbytes ? -1 : 1; + nbytes = 1; + + } else { + char *endp; + data = strtoul(console_buffer, &endp, 16); + nbytes = endp - console_buffer; + if (nbytes) { + *addr = data; + if (incrflag) + addr++; + } + } + } while (nbytes); + + mm_last_addr = addr; + return CMD_RET_SUCCESS; +} + + +command_ret_t do_mem_mm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + return mod_mem_avr (cmdtp, 1, flag, argc, argv); +} +command_ret_t do_mem_nm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + return mod_mem_avr (cmdtp, 0, flag, argc, argv); +} + /*------------------------------------------------------------------------------*/ #if 1 diff --git a/avr/z180-serv.c b/avr/z180-serv.c index af1d8e0..7193495 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -491,6 +491,9 @@ int msg_handling(int state) pending = (Stat & S_MSG_PENDING) != 0; Stat &= ~S_MSG_PENDING; } +/* + * TODO: if pending but no message chr --> special condition. ie init,... + */ if (pending) { switch (state) { diff --git a/include/z80-if.h b/include/z80-if.h index 58790bd..676d37d 100644 --- a/include/z80-if.h +++ b/include/z80-if.h @@ -43,7 +43,7 @@ void z80_read_block (uint8_t *dest, uint32_t src, size_t length); typedef enum fifo_t { fifo_msgin, fifo_msgout, - fifo_conout, fifo_conin, + fifo_conin, fifo_conout, NUM_FIFOS } fifo_t; diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180 index e86b8b2..0a35195 100644 --- a/z180/conbuf-a.180 +++ b/z180/conbuf-a.180 @@ -19,8 +19,8 @@ dseg - mkbuf co.fifo_id, co.fifo, co.fifo_len mkbuf ci.fifo_id, ci.fifo, ci.fifo_len + mkbuf co.fifo_id, co.fifo, co.fifo_len ;-------------------------------------------------------------- diff --git a/z180/config.inc b/z180/config.inc index 7b6d7ac..2a8a842 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -151,7 +151,7 @@ AVRINT6 equ 5Fh ; Definition of (logical) top 2 memory pages sysram_start equ 0FE00h -stacksize equ 80 +bs$stack$size equ 80 isvsw_loc equ 0FEE0h @@ -198,3 +198,10 @@ inidate macro dseg ds ??ps.len endm + +;----------------------------------------------------- + +b0call macro address + call _b0call + dw address + endm diff --git a/z180/ddtz.180 b/z180/ddtz.180 index aa4e977..4411549 100644 --- a/z180/ddtz.180 +++ b/z180/ddtz.180 @@ -958,11 +958,11 @@ do_op_mod: jr l0b58h ; divide x/y -; x: hl -; y: de +; hl: x +; de: y ; return: -; x/y: hl -; rem: de +; hl: q (x/y) +; de: r (x%y) DIV_HL_DE: push bc @@ -971,6 +971,11 @@ DIV_HL_DE: ld c,l ld hl,0 ;r = 0 ld a,16 ;count + +; de: x (x shifted out, q shifted in) +; bc: y +; hl: r (initially 0) + l0b89h: ex de,hl ;x add hl,hl ;x <<= 1 @@ -986,7 +991,7 @@ l0b89h: div_no_restore: dec a jr nz,l0b89h - ex de,hl + ex de,hl ;hl: q de: r pop bc ret @@ -6240,9 +6245,9 @@ vartabe: ;------------------------------------------ - .phase sysram_start+stacksize + .phase sysram_start+bs$stack$size $stack: -$stcka equ $ - stacksize +$stcka equ $ - bs$stack$size curphse defl $ .dephase diff --git a/z180/init.180 b/z180/init.180 index 11f45ec..b0b4b21 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -361,9 +361,9 @@ buffers: db 1 dw mrx.fifo db 2 - dw co.fifo - db 3 dw ci.fifo + db 3 + dw co.fifo buftablen equ ($ - buffers)/3 inimsg: -- cgit v1.2.3 From 845cbdbdd011f875219542dc5916f390cd952514 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 3 Jun 2015 08:44:45 +0200 Subject: Server: Time and Date support --- avr/Tupfile | 2 +- avr/bcd.c | 21 +++++++++++ avr/z180-serv.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- include/bcd.h | 13 +++++++ z180/config.inc | 9 +---- z180/init.180 | 6 +++ 6 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 avr/bcd.c create mode 100644 include/bcd.h (limited to 'avr') diff --git a/avr/Tupfile b/avr/Tupfile index 0c35de4..d73db12 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -9,7 +9,7 @@ SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c SRC += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c SRC += env.c xmalloc.c con-utils.c print-utils.c getopt-min.c -SRC += timer.c serial.c i2c.c pcf8583.c mmc.c +SRC += timer.c serial.c i2c.c bcd.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c SRC += $(FATFS) $(TOP)/fatfs/src/option/unicode.c diff --git a/avr/bcd.c b/avr/bcd.c new file mode 100644 index 0000000..5154852 --- /dev/null +++ b/avr/bcd.c @@ -0,0 +1,21 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "stdlib.h" +#include "stdint.h" +#include "bcd.h" + +uint_fast8_t bcd2bin(uint8_t val) +{ + return (val >> 4) * 10 + (val & 0x0f); +} + +uint8_t bin2bcd (uint_fast8_t val) +{ + div_t d = div(val, 10); + + return (d.quot << 4) | d.rem; +} diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 7193495..0712d8d 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -19,7 +19,9 @@ #include "print-utils.h" #include "z180-serv.h" #include "timer.h" - +#include "time.h" +#include "bcd.h" +#include "rtc.h" #define DEBUG_CPM_SDIO 0 /* set to 1 to debug */ @@ -122,6 +124,110 @@ void do_msg_get_timer(uint8_t subf, int len, uint8_t * msg) /* ---------------------------------------------------------------------------*/ +#define CPM_DAY_OFFSET ((1978-1900) * 365 + 19) /* 19 leap years */ + +/* + * Convert CP/M time stamp to a broken-down time structure + * + */ +int mk_date_time (int len, uint8_t *msg, struct tm *tmp) +{ + time_t stamp; + + if (len != 5) + return -1; + + /* days since 2000-01-01 */ + long days = msg[3] + (msg[4] << 8) - 8036; + + if (days < 0) + return -1; + + stamp = days * ONE_DAY; + stamp += bcd2bin(msg[0]); + stamp += bcd2bin(msg[1]) * 60 ; + stamp += bcd2bin(msg[2]) * 3600; + gmtime_r(&stamp, tmp); + return 0; +} + +void mk_cpm_time(struct tm *tmp, uint8_t cpm_time[5]) +{ + uint16_t days = 1; + uint_fast8_t leap=2; + + for (int year=78; year < tmp->tm_year; year++) { + days = days + 365 + (leap == 0); + leap = (leap+1)%4; + } + days += tmp->tm_yday; + + cpm_time[0] = bin2bcd(tmp->tm_sec); + cpm_time[1] = bin2bcd(tmp->tm_min); + cpm_time[2] = bin2bcd(tmp->tm_hour); + cpm_time[3] = days; + cpm_time[4] = days >> 8; + + debug("## mk_cpmtime: tm_year: %d, tm_yday: %d, days: %d\n", + tmp->tm_year, tmp->tm_yday, days); +} + +/* get/set cp/m time */ +void do_msg_get_set_time(uint8_t subf, int len, uint8_t * msg) +{ + struct tm t; + uint8_t cpm_time[5]; + int rc; + + memset(cpm_time, 0, ARRAY_SIZE(cpm_time)); + + switch (subf) { + case 3: /* set date & time */ + /* initialize t with current time */ + rc = rtc_get (&t); + + if (rc == 0) { + /* insert new date & time */ + if (mk_date_time (len, msg, &t) != 0) { + my_puts_P(PSTR("## set_time: Bad date format\n")); + break; + } + + time_t time; + time = mk_gmtime(&t); + gmtime_r(&time, &t); + + /* and write to RTC */ + rc = rtc_set (&t); + if(rc) + my_puts_P(PSTR("## set_time: Set date failed\n")); + } else { + my_puts_P(PSTR("## set_time: Get date failed\n")); + } + /* FALL TROUGH */ + case 2: /* get date & time */ + rc = rtc_get (&t); + + if (rc) { + my_puts_P(PSTR("## get_time: Get date failed\n")); + break; + } + + time_t time; + time = mk_gmtime(&t); + //mktime(&t); + gmtime_r(&time, &t); + + + mk_cpm_time(&t, cpm_time); + break; + } + + msg_xmit(3, subf, sizeof(cpm_time), cpm_time); +} + +/* ---------------------------------------------------------------------------*/ + #define MAX_DRIVE 4 #define BLOCK_SIZE 512 #define TPA_BASE 0x10000 @@ -393,6 +499,9 @@ const FLASH struct msg_item z80_messages[] = { 3, 1, 1, do_msg_get_timer}, + { 3, + 2, 3, /* 2: get, 3: set time and date */ + do_msg_get_set_time}, { 0xff, /* end mark */ 0, 0, 0}, @@ -550,6 +659,7 @@ void restart_z180_serv(void) } +#if 0 /*--------------------------------------------------------------------------*/ const FLASH uint8_t iniprog[] = { @@ -601,3 +711,4 @@ const FLASH uint8_t test1[] = { 0x00, // db 0 ;dst 0x00, 0x00, // dw 0 ;count (64k) }; +#endif diff --git a/include/bcd.h b/include/bcd.h new file mode 100644 index 0000000..efbebcc --- /dev/null +++ b/include/bcd.h @@ -0,0 +1,13 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef BCD_H +#define BCD_H + +uint_fast8_t bcd2bin(uint8_t val); +uint8_t bin2bcd (uint_fast8_t val); + +#endif /* BCD_H */ diff --git a/z180/config.inc b/z180/config.inc index 2a8a842..034febe 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -21,8 +21,8 @@ AVRCLK equ 18432 ;[KHz] if CPU_Z180 ;----------------------------------------------------- -FOSC equ AVRCLK/2 ;Oscillator frequency [KHz] -PHI equ FOSC*2 ;CPU frequency (clock doubler enabled) +;FOSC equ AVRCLK/2 ;Oscillator frequency [KHz] +;PHI equ FOSC*2 ;CPU frequency (clock doubler enabled) ;---------------------------------------------------------------------- ; Baudrate Generator for x16 clock mode: @@ -43,11 +43,6 @@ PHI equ FOSC*2 ;CPU frequency (clock doubler enabled) PRT_PRE equ 20 ;PRT prescaler -; Reload value for 10 ms Int. (0.1KHz): -; tc10ms = phi/prescale/0.1KHz = phi / (prescale/10) - -PRT_TC10MS equ PHI / (PRT_PRE/10) - ;----------------------------------------------------- ; MMU diff --git a/z180/init.180 b/z180/init.180 index b0b4b21..d56975e 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -416,6 +416,12 @@ ivt_i1: ;---------------------------------------------------------------------- +; Reload value for 10 ms Int. (0.1KHz): +; tc10ms = phi/prescale/0.1KHz = phi / (prescale/10) + +PRT_TC10MS equ 18432 / (PRT_PRE/10) + + if CPU_Z180 prt0_init: ld a,i -- cgit v1.2.3 From 8d0fad4c149a3283eb2a6840f6eeeb7158aad9ca Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 3 Jun 2015 14:02:01 +0200 Subject: bugfix integer promotion. increase size of message fifos to 64 --- avr/z180-serv.c | 5 +---- z180/config.inc | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 0712d8d..3814650 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -146,7 +146,7 @@ int mk_date_time (int len, uint8_t *msg, struct tm *tmp) stamp = days * ONE_DAY; stamp += bcd2bin(msg[0]); stamp += bcd2bin(msg[1]) * 60 ; - stamp += bcd2bin(msg[2]) * 3600; + stamp += bcd2bin(msg[2]) * 3600L; gmtime_r(&stamp, tmp); return 0; } @@ -167,9 +167,6 @@ void mk_cpm_time(struct tm *tmp, uint8_t cpm_time[5]) cpm_time[2] = bin2bcd(tmp->tm_hour); cpm_time[3] = days; cpm_time[4] = days >> 8; - - debug("## mk_cpmtime: tm_year: %d, tm_yday: %d, days: %d\n", - tmp->tm_year, tmp->tm_yday, days); } /* get/set cp/m time */ diff --git a/z180/config.inc b/z180/config.inc index 034febe..b5a5319 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -123,9 +123,9 @@ DDTZRSTVEC equ 030h ;DDTZ Restart vector (breakpoints) INIDONE equ 03Fh ;CP/M skip hw init, if this address INIDONEVAL equ 080h ; is set to this value. -mtx.fifo_len equ 32 ;Message transfer fifos +mtx.fifo_len equ 64 ;Message transfer fifos mtx.fifo_id equ 0 ; This *must* have #0 -mrx.fifo_len equ 32 +mrx.fifo_len equ 64 mrx.fifo_id equ 1 ci.fifo_len equ 32 ;AVRCON Character I/O via AVR -- cgit v1.2.3 From 50939dece93115ee500261129f311a840ca21a81 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 4 Jun 2015 22:46:54 +0200 Subject: delete unused function z80_get_byte() --- avr/z180-serv.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 3814650..929cd97 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -29,22 +29,6 @@ debug_cond(DEBUG_CPM_SDIO, fmt, ##args) - -/*--------------------------------------------------------------------------*/ - - -uint8_t z80_get_byte(uint32_t adr) -{ - uint8_t data; - - z80_bus_cmd(Request); - data = z80_read(adr); - z80_bus_cmd(Release); - - return data; -} - - /*--------------------------------------------------------------------------*/ struct msg_item { @@ -591,7 +575,7 @@ void check_msg_fifo(void) int msg_handling(int state) { - uint8_t pending; + bool pending; ATOMIC_BLOCK(ATOMIC_FORCEON) { pending = (Stat & S_MSG_PENDING) != 0; -- cgit v1.2.3 From 215ec4b2e6066ba845bfb4d3c95c7b01cd4492ce Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 5 Jun 2015 08:46:35 +0200 Subject: change message buffer initialization --- avr/z180-serv.c | 47 ++++++++++++++++++++++++----------------------- z180/config.inc | 3 ++- z180/init.180 | 4 ---- 3 files changed, 26 insertions(+), 28 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index 929cd97..b5d8140 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -581,35 +581,38 @@ int msg_handling(int state) pending = (Stat & S_MSG_PENDING) != 0; Stat &= ~S_MSG_PENDING; } -/* - * TODO: if pending but no message chr --> special condition. ie init,... - */ if (pending) { - switch (state) { - case 0: /* need init */ + uint8_t init_request; + z80_bus_cmd(Request); + init_request = z80_read(0x43); + z80_bus_cmd(Release); + if ( init_request != 0) { /* Get address of fifo_list */ + uint32_t fifo_addr = 0; z80_bus_cmd(Request); uint32_t fifo_list = z80_read(0x40) + - ((uint16_t) z80_read(0x41) << 8) + - ((uint32_t) z80_read(0x42) << 16); - z80_bus_cmd(Release); + ((uint16_t) z80_read(0x41) << 8) + + ((uint32_t) z80_read(0x42) << 16); if (fifo_list != 0) { /* Get address of fifo 0 */ - z80_bus_cmd(Request); - uint32_t fifo_addr = z80_read(fifo_list) + - ((uint16_t) z80_read(fifo_list+1) << 8) + - ((uint32_t) z80_read(fifo_list+2) << 16); - z80_bus_cmd(Release); - if (fifo_addr != 0) { - z80_memfifo_init(fifo_msgin, fifo_addr); - state = 1; - } + fifo_addr = z80_read(fifo_list) + + ((uint16_t) z80_read(fifo_list+1) << 8); + /* TODO: log to phys addr translation + ((uint32_t) z80_read(fifo_list+2) << 16); + */ } - break; - case 1: /* awaiting messages */ + z80_write(0x43, 0); + z80_bus_cmd(Release); + + if (fifo_addr != 0) { + z80_memfifo_init(fifo_msgin, fifo_addr); + state = 1; + } else + state = 0; + + } else { check_msg_fifo(); - break; } } @@ -629,9 +632,7 @@ void setup_z180_serv(void) void restart_z180_serv(void) { z80_bus_cmd(Request); - z80_write(0x40, 0); - z80_write(0x41, 0); - z80_write(0x42, 0); + z80_memset(0x40, 0, 4); z80_bus_cmd(Release); for (int i = 0; i < NUM_FIFOS; i++) diff --git a/z180/config.inc b/z180/config.inc index b5a5319..ffab6e6 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -170,7 +170,8 @@ mkbuf macro id,name,size name&.mask equ ;wrong size error else db id - ds 3 + db size-1 + ds 2 name:: ds size name&.mask equ low (size-1) if size ne 0 diff --git a/z180/init.180 b/z180/init.180 index d56975e..4c7bd77 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -233,7 +233,6 @@ syscbr: db 0 buf.init: ld (ix+o.in_idx),0 ld (ix+o.out_idx),0 - ld (ix+o.mask),a ld a,(ix+o.id) cp 4 @@ -247,10 +246,8 @@ buf.init: ld d,0 add hl,de add hl,de - add hl,de push ix pop de -; TODO: address translation ld (hl),e inc hl ld (hl),d @@ -270,7 +267,6 @@ bufi_ex: fifo_list: rept 4 dw 0 - db 0 endm ;---------------------------------------------------------------------- -- cgit v1.2.3 From 612a69655af9bed89a1ad9e7e9225dfb3ed3ff42 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 6 Jun 2015 02:32:29 +0200 Subject: esc_char environment variable --- avr/cmd_boot.c | 31 +++++++++++++++++-------------- avr/cmd_gpio.c | 2 +- include/config.h | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'avr') diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index f9f8f90..448ed48 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -16,6 +16,7 @@ #include #include "command.h" +#include "env.h" #include "con-utils.h" #include "z80-if.h" #include "z180-serv.h" @@ -41,11 +42,9 @@ static void z80_load_mem(void) hdrom_address[sec]+hdrom_length_of_sections[sec] - 1, hdrom_length_of_sections[sec]); - z80_bus_cmd(Request); z80_write_block_P((const FLASH unsigned char *) &hdrom[sec_base], /* src */ hdrom_address[sec], /* dest */ hdrom_length_of_sections[sec]); /* len */ - z80_bus_cmd(Release); sec_base+=hdrom_length_of_sections[sec]; sec++; } @@ -56,11 +55,15 @@ command_ret_t do_loadf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] (void) cmdtp; (void) flag; (void) argc; (void) argv; if (z80_bus_state() & ZST_RUNNING) { - printf_P(PSTR("## Can't load while CPU is running!\n")); + my_puts_P(PSTR("Can't load while CPU is running!\n")); return CMD_RET_FAILURE; } - + if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { + my_puts_P(PSTR("Bus timeout\n")); + return CMD_RET_FAILURE; + } z80_load_mem(); + z80_bus_cmd(Release); return CMD_RET_SUCCESS; } @@ -147,7 +150,7 @@ command_ret_t do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] { (void) cmdtp; (void) flag; (void) argc; (void) argv; - printf_P(PSTR("## CPU now in reset state.\n")); + printf_P(PSTR("CPU now in reset state.\n")); reset_cpu(Reset); return CMD_RET_SUCCESS; @@ -169,10 +172,10 @@ void print_con_usage(char esc) " ?,H - This Help\n" " R - Reset (Restart) CPU\n" " Q,X - Return to command line\n" - " \\ - code input:\n" - " \\nnn 3 decimal digits character code\n" - " \\Xhh 2 hexadecimal digits character code\n" - " ^%c - (Escape char) Type again to send itself\n" + " \\ - code input:\n" + " \\nnn 3 decimal digits character code\n" + " \\Xhh 2 hexadecimal digits character code\n" + " ^%c - (Escape char) Type again to send itself\n" "key>" ), esc + 0x40); } @@ -184,6 +187,7 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv // uint8_t help_prompt = 0; uint8_t code = 0; uint8_t state = 0; + char esc_char = (char) getenv_ulong(PSTR(ENV_ESC_CHAR), 16, CONFIG_ESC_CHAR); (void) cmdtp; (void) flag; (void) argc; (void) argv; @@ -203,7 +207,7 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv if ((ch = my_getchar(0)) >= 0) { switch (state) { case 0: - if (ch == CONFIG_ESC_CHAR) { + if (ch == esc_char) { state = 1; /* TODO: Timer starten */ } else { @@ -219,7 +223,7 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv case '?': case 'H': - print_con_usage(CONFIG_ESC_CHAR); + print_con_usage(esc_char); state = 2; break; @@ -238,10 +242,9 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv state = 3; break; - case CONFIG_ESC_CHAR: - z80_memfifo_putc(fifo_conin, ch); - break; default: + if (ch == esc_char) + z80_memfifo_putc(fifo_conin, ch); break; } break; diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c index e0d9b06..5589381 100644 --- a/avr/cmd_gpio.c +++ b/avr/cmd_gpio.c @@ -35,7 +35,7 @@ static void pinnames_get(void) memset(pin_names, 0, sizeof(pin_names)); pin_names_width = 0; -/* TODO: enters endless loop on wron parameters */ +/* TODO: enters endless loop on wrong parameters */ if ((lp = getenv(PSTR(ENV_PINALIAS))) != NULL) { pin_names[namestr] = strdup(lp); diff --git a/include/config.h b/include/config.h index f8b9d73..a403520 100644 --- a/include/config.h +++ b/include/config.h @@ -15,6 +15,7 @@ #define ENV_PATH_CPM3SYS "cpm3_file" #define ENV_PINALIAS "pin_alias" #define ENV_STARTADDRESS "startaddress" +#define ENV_ESC_CHAR "esc_char" #define CONFIG_PATH_CPM3SYS "1:/cpm3.sys" -- cgit v1.2.3 From b08e079d1541c80028e3a11affec3f863eb9129d Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 6 Jun 2015 10:58:34 +0200 Subject: connect command 'esc \' enhancement, new 'esc :' subcommand --- avr/cli.c | 2 +- avr/cmd_boot.c | 24 +++++++++++++++++++++++- include/cli.h | 9 +++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'avr') diff --git a/avr/cli.c b/avr/cli.c index 6b26b6f..43b5be0 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -313,7 +313,7 @@ static int cli_run_command_list(const char *cmd) /* - * Run a command using the selected parser. + * Run a command. * * @param cmd Command to run * @param flag Execution flags (CMD_FLAG_...) diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index 448ed48..b8799aa 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -16,6 +16,8 @@ #include #include "command.h" +#include "cli_readline.h" +#include "cli.h" #include "env.h" #include "con-utils.h" #include "z80-if.h" @@ -170,8 +172,9 @@ void print_con_usage(char esc) { printf_P(PSTR("\n" "------------------------------------------------\n" " ?,H - This Help\n" - " R - Reset (Restart) CPU\n" " Q,X - Return to command line\n" + " R - Reset (Restart) CPU\n" + " : - Execute monitor command\n" " \\ - code input:\n" " \\nnn 3 decimal digits character code\n" " \\Xhh 2 hexadecimal digits character code\n" @@ -191,6 +194,8 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv (void) cmdtp; (void) flag; (void) argc; (void) argv; + printf_P(PSTR("Connecting to CPU. Escape character is '^%c'.\n"), + esc_char + 0x40); while (1) { @@ -237,6 +242,13 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv goto quit; break; + case ':': + putchar('\n'); + int cmdlen = cli_readline(PSTR(": ")); + if (cmdlen > 0) + run_command(console_buffer, 0); + break; + case '\\': code = 0; state = 3; @@ -259,6 +271,11 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv if (isdigit(ch)) { code = code * 10 + ch - '0'; state++; + } else { + if (state > 3) + z80_memfifo_putc(fifo_conin, code); + z80_memfifo_putc(fifo_conin, ch); + state = 0; } if (state > 5) { z80_memfifo_putc(fifo_conin, code); @@ -273,6 +290,11 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv ch -= 'A' - 10; code = code * 16 + ch - '0'; state++; + }else { + if (state > 6) + z80_memfifo_putc(fifo_conin, code); + z80_memfifo_putc(fifo_conin, ch); + state = 0; } if (state > 7) { z80_memfifo_putc(fifo_conin, code); diff --git a/include/cli.h b/include/cli.h index f6fb2ab..4920cc4 100644 --- a/include/cli.h +++ b/include/cli.h @@ -66,6 +66,15 @@ void cli_loop(void); */ //int cli_simple_parse_line(char *line, char *argv[]); +/* + * Run a command. + * + * @param cmd Command to run + * @param flag Execution flags (CMD_FLAG_...) + * @return 0 on success, or != 0 on error. + */ +int run_command(const char *cmd, int flag); + int run_command_list(const char *cmd, int len); -- cgit v1.2.3 From 8bbf185ed81c12534c0ad9b26f0049035fde8df4 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 9 Jun 2015 09:31:33 +0200 Subject: message buffer init changes. cp/m r/w for new memory map --- avr/z180-serv.c | 58 ++----- z180/conbuf-a.180 | 8 +- z180/config.inc | 22 ++- z180/ddtz.180 | 480 +++++++++++++++++++++++++++--------------------------- z180/init.180 | 113 +++++-------- z180/msgbuf-a.180 | 84 +++++++++- 6 files changed, 386 insertions(+), 379 deletions(-) (limited to 'avr') diff --git a/avr/z180-serv.c b/avr/z180-serv.c index b5d8140..69bcd9c 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -211,8 +211,8 @@ void do_msg_get_set_time(uint8_t subf, int len, uint8_t * msg) #define MAX_DRIVE 4 #define BLOCK_SIZE 512 -#define TPA_BASE 0x10000 -#define COMMON_BASE 0xC000 +//#define TPA_BASE 0x10000 +//#define COMMON_BASE 0xC000 struct cpm_drive_s { uint8_t drv; @@ -390,52 +390,31 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) res = f_lseek(&drv_table[drv].fd, pos); while (!res && secs--) { - unsigned int cnt, br; - - /* check bank boundary crossing */ - cnt = 0; - if (addr < (TPA_BASE + COMMON_BASE) && - (addr + BLOCK_SIZE) > (TPA_BASE + COMMON_BASE)) { - cnt = (TPA_BASE + COMMON_BASE) - addr; - } - - if (cnt) { - debug_cpmsd("## %67c addr: %.5lx, cnt: %3d\n", ' ', addr, cnt); - debug_cpmsd("## %67c addr: %.5lx, cnt: %3d\n", ' ', addr+cnt-TPA_BASE, BLOCK_SIZE-cnt); - } - + unsigned int brw; if (dowrite) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; break; } else { - if (cnt) { - z80_read_block(disk_buffer, addr, cnt); - addr = addr + cnt - TPA_BASE; - } - z80_read_block(disk_buffer+cnt, addr, BLOCK_SIZE - cnt); + z80_read_block(disk_buffer, addr, BLOCK_SIZE); z80_bus_cmd(Release); } - res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); + res = f_write(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &brw); } else { - res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &br); - if (res == FR_OK && br == BLOCK_SIZE) { + res = f_read(&drv_table[drv].fd, disk_buffer, BLOCK_SIZE, &brw); + if (res == FR_OK && brw == BLOCK_SIZE) { if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { buserr = 1; break; } else { - if (cnt) { - z80_write_block(disk_buffer, addr, cnt); - addr = addr + cnt - TPA_BASE; - } - z80_write_block(disk_buffer+cnt, addr, BLOCK_SIZE - cnt); + z80_write_block(disk_buffer, addr, BLOCK_SIZE); z80_bus_cmd(Release); } } } - if (br != BLOCK_SIZE) { - debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, br); + if (brw != BLOCK_SIZE) { + debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, brw); dump_ram(disk_buffer, 0, 64, "Read Data"); res = -1; } @@ -588,20 +567,11 @@ int msg_handling(int state) init_request = z80_read(0x43); z80_bus_cmd(Release); if ( init_request != 0) { - /* Get address of fifo_list */ - uint32_t fifo_addr = 0; + /* Get address of fifo 0 */ z80_bus_cmd(Request); - uint32_t fifo_list = z80_read(0x40) + - ((uint16_t) z80_read(0x41) << 8) + - ((uint32_t) z80_read(0x42) << 16); - if (fifo_list != 0) { - /* Get address of fifo 0 */ - fifo_addr = z80_read(fifo_list) + - ((uint16_t) z80_read(fifo_list+1) << 8); - /* TODO: log to phys addr translation - ((uint32_t) z80_read(fifo_list+2) << 16); - */ - } + uint32_t fifo_addr = z80_read(0x40) + + ((uint16_t) z80_read(0x40+1) << 8) + + ((uint32_t) z80_read(0x40+2) << 16); z80_write(0x43, 0); z80_bus_cmd(Release); diff --git a/z180/conbuf-a.180 b/z180/conbuf-a.180 index 0a35195..f69b86d 100644 --- a/z180/conbuf-a.180 +++ b/z180/conbuf-a.180 @@ -6,7 +6,7 @@ ; global ff.init,ff.in,ff.out,ff.i.st,ff.o.st - extrn buf.init + extrn bufinit include config.inc if CPU_Z180 @@ -32,11 +32,9 @@ ff.init: ld ix,ci.fifo - ld a,ci.fifo.mask - call buf.init + call bufinit ld ix,co.fifo - ld a,co.fifo.mask - jp buf.init + jp bufinit ff.i.st: diff --git a/z180/config.inc b/z180/config.inc index ffab6e6..1d0709d 100644 --- a/z180/config.inc +++ b/z180/config.inc @@ -48,22 +48,34 @@ PRT_PRE equ 20 ;PRT prescaler COMMON_SIZE equ 16*1024 ;Common Area size in bytes ;must be multiple of 4K - if (COMMON_SIZE mod 1000h) .printx COMMON_SIZE not multiple of 4K! end ;stop assembly endif +CMN_SIZE equ COMMON_SIZE/1000h ;4K units +BNK_SIZE equ 64/4 - CMN_SIZE ;bank size (4K units) +BANKS equ (512/4 - CMN_SIZE)/BNK_SIZE ;max nr. of banks + +; Logical address space, CBAR values -CSK equ COMMON_SIZE/1000h ; -CA equ 10h - CSK ;common area start -BA equ 0 ;banked area start +CA equ 10h - CMN_SIZE ;common area start (64K - common size) +BA equ 0 ;banked area start + + if 0 SYS$CBR equ 0 SYS$CBAR equ CA*16 + CA ;CBAR in system mode USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M) + endif + if 1 + +SYS$CBR equ BNK_SIZE +SYS$CBAR equ CA*16 + CA ;CBAR in system mode +USR$CBAR equ CA*16 + BA ;CBAR in user mode (CP/M) + + endif -BANKS equ 18 ;max nr. of banks ;----------------------------------------------------- diff --git a/z180/ddtz.180 b/z180/ddtz.180 index 4411549..d5b921b 100644 --- a/z180/ddtz.180 +++ b/z180/ddtz.180 @@ -2197,294 +2197,294 @@ b_0x132A_start: DC 'F' DB 0 b_0x136C_start: - if ROMSYS - defb 000h - defw uromen + if ROMSYS + defb 000h + defw uromen endif if CPU_Z180 - defb 000h - defw ucbar - defb 000h - defw ubbr + defb 000h + defw ucbar + defb 000h + defw ubbr else - defb 000h - defw ubnk + defb 000h + defw ubnk endif - defb 003h - defw reg.c2 - defb 003h - defw reg.e2 - defb 003h - defw reg.l2 - defb 003h - defw reg.c - defb 003h - defw reg.e - defb 003h - defw reg.l - defb 000h - defw reg.a2 - defb 000h - defw reg.b2 - defb 000h - defw reg.c2 - defb 000h - defw reg.d2 - defb 000h - defw reg.e2 - defb 000h - defw reg.h2 - defb 000h - defw reg.l2 - defb 000h - defw reg.a - defb 000h - defw reg.b - defb 000h - defw reg.c - defb 000h - defw reg.d - defb 000h - defw reg.e - defb 000h - defw reg.h - defb 000h - defw reg.l - defb 003h - defw reg.ix - defb 003h - defw reg.iy - defb 003h - defw reg.sp - defb 003h - defw reg.pc - defb 003h - defw reg.ix - defb 003h - defw reg.iy - defb 003h - defw reg.sp - defb 003h - defw reg.pc - defb 000h - defw reg.i - defb 000h - defw reg.f2 - defb 000h - defw reg.f + defb 003h + defw reg.c2 + defb 003h + defw reg.e2 + defb 003h + defw reg.l2 + defb 003h + defw reg.c + defb 003h + defw reg.e + defb 003h + defw reg.l + defb 000h + defw reg.a2 + defb 000h + defw reg.b2 + defb 000h + defw reg.c2 + defb 000h + defw reg.d2 + defb 000h + defw reg.e2 + defb 000h + defw reg.h2 + defb 000h + defw reg.l2 + defb 000h + defw reg.a + defb 000h + defw reg.b + defb 000h + defw reg.c + defb 000h + defw reg.d + defb 000h + defw reg.e + defb 000h + defw reg.h + defb 000h + defw reg.l + defb 003h + defw reg.ix + defb 003h + defw reg.iy + defb 003h + defw reg.sp + defb 003h + defw reg.pc + defb 003h + defw reg.ix + defb 003h + defw reg.iy + defb 003h + defw reg.sp + defb 003h + defw reg.pc + defb 000h + defw reg.i + defb 000h + defw reg.f2 + defb 000h + defw reg.f CMD.S: - ld hl,(lst.S) - call get_lastarg_def + ld hl,(lst.S) + call get_lastarg_def l13d8h: - ld (lst.S),hl - call out.hl.@ - call OUTBL + ld (lst.S),hl + call out.hl.@ + call OUTBL comst - ld a,(hl) + ld a,(hl) comend - call out.hex - call outbl2 - call INLINE - call SKIPBL - inc hl - jr z,l13d8h - dec hl - inc de - cp '.' - jp z,assert_eol - cp '-' - jr nz,l1406h - ld a,(de) - or a - dec hl - jr z,l13d8h - inc hl + call out.hex + call outbl2 + call INLINE + call SKIPBL + inc hl + jr z,l13d8h + dec hl + inc de + cp '.' + jp z,assert_eol + cp '-' + jr nz,l1406h + ld a,(de) + or a + dec hl + jr z,l13d8h + inc hl l1406h: - dec de - call get_bytes_m - jr l13d8h + dec de + call get_bytes_m + jr l13d8h CMD.@: - call assert_eol - ld hl,MSG_at - ld de,offs.@ - ld c,001h - jp l1279h + call assert_eol + ld hl,MSG_at + ld de,offs.@ + ld c,001h + jp l1279h MSG_at: dc '@' CMD.I: - ld hl,CMD.I - ld (CMD_RPT),hl - ld hl,(lst.IP) - call get_lastarg_def - ld (lst.IP),hl - ld b,h - ld c,l + ld hl,CMD.I + ld (CMD_RPT),hl + ld hl,(lst.IP) + call get_lastarg_def + ld (lst.IP),hl + ld b,h + ld c,l if CPU_Z180 - ld a,b - or a - jr nz,l1442h - ld a,c - ld hl,ucbar - cp cbar - jr z,l143fh - ld hl,ubbr - cp bbr - jr nz,l1442h + ld a,b + or a + jr nz,l1442h + ld a,c + ld hl,ucbar + cp cbar + jr z,l143fh + ld hl,ubbr + cp bbr + jr nz,l1442h l143fh: - ld a,(hl) - jr l1444h + ld a,(hl) + jr l1444h l1442h: endif - in a,(c) + in a,(c) l1444h: - push af - call out.hex - call outbl4 - pop af - call out.bin.b - jp CRLF + push af + call out.hex + call outbl4 + pop af + call out.bin.b + jp CRLF CMD.O: - ld hl,CMD.O - ld (CMD_RPT),hl - ld hl,(lst.OD) - call get_arg_def - ld a,l - ld (lst.OD),a - push af - call skip_to_nextarg - ld hl,(lst.OP) - call get_lastarg_def - ld (lst.OP),hl - ld b,h - ld c,l + ld hl,CMD.O + ld (CMD_RPT),hl + ld hl,(lst.OD) + call get_arg_def + ld a,l + ld (lst.OD),a + push af + call skip_to_nextarg + ld hl,(lst.OP) + call get_lastarg_def + ld (lst.OP),hl + ld b,h + ld c,l if CPU_Z180 - ld a,b - or a - jr nz,l1489h - ld a,c - ld hl,ucbar - cp cbar - jr z,l148dh - ld hl,ubbr - cp bbr - jr z,l148dh - cp cbr - jp z,ERROR + ld a,b + or a + jr nz,l1489h + ld a,c + ld hl,ucbar + cp cbar + jr z,l148dh + ld hl,ubbr + cp bbr + jr z,l148dh + cp cbr + jp z,ERROR l1489h: endif - pop af - out (c),a + pop af + out (c),a ret if CPU_Z180 l148dh: - pop af - ld (hl),a - ret + pop af + ld (hl),a + ret endif CMD.V: - call get_arg3 ;1490 get from, size, to + call get_arg3 ;1490 get from, size, to cmp_mem: - push bc + push bc comst - ld a,(de) - ld b,(hl) + ld a,(de) + ld b,(hl) comend - cp b - jr z,l14bah - ld c,a - call out.hl.@ - call OUTBL - ld a,b - call out.hex - call outbl2 - ld a,c - call out.hex - call OUTBL - ex de,hl - call out.hl.@ - ex de,hl - call CRLF + cp b + jr z,l14bah + ld c,a + call out.hl.@ + call OUTBL + ld a,b + call out.hex + call outbl2 + ld a,c + call out.hex + call OUTBL + ex de,hl + call out.hl.@ + ex de,hl + call CRLF l14bah: - pop bc - inc hl - inc de - dec bc - ld a,b - or c - jr nz,cmp_mem + pop bc + inc hl + inc de + dec bc + ld a,b + or c + jr nz,cmp_mem ret CMD.M: - ld a,(de) - cp 'V' - jr nz,bm_nv - inc de + ld a,(de) + cp 'V' + jr nz,bm_nv + inc de bm_nv: - push af ;14c9 save 'V' flag - call get_arg3 - push hl - push de - push bc - call CP.HL.DE - jr nc,bm_mvdown - add hl,bc - ex de,hl - add hl,bc - ex de,hl - dec hl - dec de + push af ;14c9 save 'V' flag + call get_arg3 + push hl + push de + push bc + call CP.HL.DE + jr nc,bm_mvdown + add hl,bc + ex de,hl + add hl,bc + ex de,hl + dec hl + dec de comst - lddr + lddr comend - jr bm_done + jr bm_done bm_mvdown: comst ldir comend bm_done: - pop bc - pop de - pop hl - pop af - jr z,cmp_mem ;14ed validate? + pop bc + pop de + pop hl + pop af + jr z,cmp_mem ;14ed validate? ret CMD.H: - call EXPR - jp c,l173ch - call skip_to_nextarg - push hl - call EXPR - push af - call assert_eol - pop af - ex de,hl - pop hl - jr c,l1511h - push hl - push de - add hl,de - call l1511h - pop de - pop hl - and a - sbc hl,de + call EXPR + jp c,l173ch + call skip_to_nextarg + push hl + call EXPR + push af + call assert_eol + pop af + ex de,hl + pop hl + jr c,l1511h + push hl + push de + add hl,de + call l1511h + pop de + pop hl + and a + sbc hl,de l1511h: - call out.hl ;1511 val - call outbl2 - call sub_0928h ;1517 -val - call outbl4 - call out.hl.dec ;151d dec - call outbl2 - call out.hl.decm ;1523 -dec - call outbl4 - call out.bin.w ;1529 bin - call outbl2 - ld a,l - call out.ascii - jp CRLF + call out.hl ;1511 val + call outbl2 + call sub_0928h ;1517 -val + call outbl4 + call out.hl.dec ;151d dec + call outbl2 + call out.hl.decm ;1523 -dec + call outbl4 + call out.bin.w ;1529 bin + call outbl2 + ld a,l + call out.ascii + jp CRLF CMD.Q: ld a,(de) diff --git a/z180/init.180 b/z180/init.180 index 4c7bd77..05c24ff 100644 --- a/z180/init.180 +++ b/z180/init.180 @@ -76,7 +76,7 @@ start: hwini0: if CPU_Z180 - db 3 ;count + db ;count db rcr,CREFSH ;configure DRAM refresh db dcntl,INIWAITS ;wait states db cbr,SYS$CBR @@ -152,7 +152,7 @@ hw_reset: kstart: if CPU_Z180 - ld a,SYS$CBR + ld a,SYS$CBR ;TODO: out0 (cbr),a ld a,SYS$CBAR out0 (cbar),a @@ -192,8 +192,8 @@ wstart: ; call prt0_init endif + call msginit call charini - call bufferinit if CPU_Z80 ld a,0 @@ -228,86 +228,66 @@ syscbr: db 0 ;---------------------------------------------------------------------- ; - global buf.init + global bufinit -buf.init: - ld (ix+o.in_idx),0 +bufinit: + ld (ix+o.in_idx),0 ;reset pointers (empty fifo) ld (ix+o.out_idx),0 - ld a,(ix+o.id) - cp 4 - ret nc - - push de - push hl - ld hl,fifo_list - push hl ;save fifo_list + ld hl,fifolst ld e,a ld d,0 add hl,de add hl,de push ix pop de + cp 4 + jr nc,bfi_skip + ld (hl),e inc hl ld (hl),d - pop hl ;get fifo_list back - or a - jr nz,bufi_ex - ld (040h),hl - ld (040h+2),a -bufi_ex: - pop hl - pop de +bfi_skip: + ex de,hl + call hwl2phy ;get phys. address of fifo + ld c,a + ld a,(ix+o.id) ;fifo id + or a ;test if fifo 0 + ret z + ld b,a + push bc ;c: bank-addr, b: ignored + push hl ;address + ld c,0 + push bc ;c: function, b:subf + ld b,5 + ld h,c + ld l,c + add hl,sp + call msg.sm + pop hl + pop hl + pop hl ret - -fifo_list: + public fifolst +fifolst : rept 4 dw 0 endm ;---------------------------------------------------------------------- + extrn msg.sm extrn msginit,msg.sout extrn mtx.fifo,mrx.fifo - extrn co.fifo,ci.fifo + extrn ff.init,co.fifo,ci.fifo -bufferinit: +fifoinit: if CPU_Z180 - call msginit - - ld hl,buffers - ld b,buftablen -bfi_1: - ld a,(hl) - inc hl - ld (bufdat+0),a - ld e,(hl) - inc hl - ld d,(hl) - inc hl - ex de,hl - or a - jr nz,bfi_2 -; call hwl2phy -; ld (40h+0),hl -; ld (40h+2),a - out (AVRINT5),a - jr bfi_3 -bfi_2: - call hwl2phy - ld (bufdat+1),hl - ld (bufdat+3),a - ld hl,inimsg - call msg.sout -bfi_3: - ex de,hl - djnz bfi_1 ret else ;CPU_Z180 @@ -351,27 +331,7 @@ bfi_3: ret endif -buffers: - db 0 - dw mtx.fifo - db 1 - dw mrx.fifo - db 2 - dw ci.fifo - db 3 - dw co.fifo -buftablen equ ($ - buffers)/3 - -inimsg: - db inimsg_e - $ -1 - db 0AEh - db inimsg_e - $ -1 - db 0 -bufdat: - db 0 - dw 0 - db 0 -inimsg_e: + ; @@ -612,6 +572,7 @@ l2p_i: ; ;out ahl: Phys. (linear) Address + public hwl2phy hwl2phy: push bc ; diff --git a/z180/msgbuf-a.180 b/z180/msgbuf-a.180 index 7e8c9cc..3575569 100644 --- a/z180/msgbuf-a.180 +++ b/z180/msgbuf-a.180 @@ -1,12 +1,13 @@ page 255 .z80 - global mrx.fifo,mtx.fifo + public mrx.fifo,mtx.fifo - global msginit,msgi.st,msg.in,msgo.st,msg.out - global msg.sout + public msginit,msgi.st,msg.in,msgo.st + public msg.sm,msg.sout - extrn buf.init + extrn bufinit,hwl2phy + extrn fifolst include config.inc if CPU_Z180 @@ -29,12 +30,25 @@ ; msginit: + ld a,(043h) +;TODO: value should be 0 ld ix,mtx.fifo - ld a,mtx.fifo.mask - call buf.init + call bufinit + push ix + pop hl + call hwl2phy + ld (040h),hl + ld (040h+2),a + ld a,0ffh + ld (043h),a + out (AVRINT5),a +wait: + ld a,(043h) + or a + jr nz,wait + ld ix,mrx.fifo - ld a,mrx.fifo.mask - jp buf.init + jp bufinit ;-------------------------------------------------------------- @@ -136,7 +150,7 @@ bp.wait: ;-------------------------------------------------------------- - + if 0 msg.out: push ix @@ -165,6 +179,36 @@ bp.wait: pop ix ret + endif + +;---------------------------------------------------------------------- +; +; Put char in message buffer: +; ix: buffer to put into +; c: char + +buf.put: + push ix ;15 + push bc ;11 + ld a,(ix+o.in_idx) ;19 + ld c,a ;4 + ld b,0 ;7 + add ix,bc ;11 + pop bc ;10 + ld (ix),c ;7 + pop ix ;14 + + inc a ;4 + and (ix+o.mask) ;19 =121 +bufp.wait: + cp (ix+o.out_idx) ;19 + jr z,bufp.wait ;12/7 + ld (ix+o.in_idx),a ;19 + + out (AVRINT5),a ;11 + ld a,c ;4 + ret ;10 =191 + ;-------------------------------------------------------------- @@ -305,4 +349,26 @@ buf_end: ;---------------------------------------------------------------------- +;---------------------------------------------------------------------- +; Send message MEMORY +; +; hl: pointer to message (netto) +; b: msg length + +msg.sm: + push ix + ld ix,mtx.fifo + ld c,0AEh + call buf.put + ld c,b + call buf.put +msm_l: + ld c,(hl) + inc hl + call buf.put + djnz msm_l + pop ix + ret + + end -- cgit v1.2.3 From 057817cb1dc71416bc798b5cd592acfcea87efaa Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 9 Jun 2015 17:20:01 +0200 Subject: loadcpm3 for new memory map --- avr/cmd_loadcpm3.c | 52 ++++++++++++++++++++++++++++++++++++---------------- avr/command_tbl.c | 10 ++++++---- avr/env.c | 2 +- include/config.h | 22 +++++++++++++++------- z180/z180reg.inc | 5 ++--- 5 files changed, 60 insertions(+), 31 deletions(-) (limited to 'avr') diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c index 3f1bbe1..da1be37 100644 --- a/avr/cmd_loadcpm3.c +++ b/avr/cmd_loadcpm3.c @@ -27,7 +27,7 @@ * len = Length in pages of module to read * */ -int load(FIL *File, uint16_t addr, uint8_t len) +int load(FIL *File, uint32_t addr, uint8_t len) { uint8_t buffer[RS]; unsigned int br; /* bytes read */ @@ -63,12 +63,12 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg uint8_t res_len; uint16_t bank_top; uint8_t bank_len; - uint16_t osentry_adr = 0; - long offset = 0; + uint16_t osentry_addr = 0; + uint32_t common_base, banked_base; char *fname; FIL File; - /* TODO: put CONFIG_PATH_CPM3SYS in flash */ - char default_fname[] = CONFIG_PATH_CPM3SYS; + /* TODO: put CONFIG_CPM3_SYSFILE in flash */ + char default_fname[] = CONFIG_CPM3_SYSFILE; unsigned int br; /* bytes read */ uint8_t buffer[RS]; int res; @@ -76,15 +76,20 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg (void) cmdtp; (void) flag; - if (argc > 1) - offset = strtoul(argv[1], NULL, 16); + common_base = getenv_ulong(PSTR(ENV_CPM3_COMMON_BASE), 16, + CONFIG_CPM3_COMMON_BASE); + banked_base = getenv_ulong(PSTR(ENV_CPM3_BANKED_BASE), 16, + CONFIG_CPM3_BANKED_BASE); - fname = getenv(PSTR(ENV_PATH_CPM3SYS)); + if (argc > 3) + banked_base = strtoul(argv[3], NULL, 16); + if (argc > 2) + banked_base = strtoul(argv[2], NULL, 16); + fname = getenv(PSTR(ENV_CPM3_SYSFILE)); if (argc > 2) { fname = argv[2]; } - if (fname == NULL || *fname == '\0') fname = default_fname; @@ -105,7 +110,7 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg res_len = buffer[1]; bank_top = buffer[2] << 8; bank_len = buffer[3]; - osentry_adr = buffer[4] + (buffer[5] << 8); + osentry_addr = buffer[4] + (buffer[5] << 8); /* read display info */ res = f_read(&File, buffer, RS, &br); @@ -121,11 +126,11 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg /* Main System Load */ /* Load Common Portion of System */ - if ((res = load(&File, mem_top, res_len)) != 0) + if ((res = load(&File, common_base + mem_top, res_len)) != 0) goto out; /* Load Banked Portion of System */ - res = load(&File, bank_top, bank_len); + res = load(&File, banked_base + bank_top, bank_len); out: f_close(&File); @@ -134,16 +139,31 @@ out: printf_P(PSTR("Error: failed to read '%s'\n"), fname); return CMD_RET_FAILURE; } else { - if (res_len != 0) - setenv_hex(PSTR(ENV_STARTADDRESS), osentry_adr); + if (res_len != 0) { + if (osentry_addr + common_base > 0xffff) { + z80_bus_cmd(Request); + if (z80_read(osentry_addr + common_base) == 0xc3) { + osentry_addr = z80_read(osentry_addr+common_base+1) + + (z80_read(osentry_addr + common_base+2) << 8); + } + z80_bus_cmd(Release); + if (banked_base + osentry_addr > 0xffff) + osentry_addr = 0; + } + setenv_hex(PSTR(ENV_STARTADDRESS), osentry_addr); + } printf_P(PSTR("Loaded: Resident: ")); if (res_len != 0) - printf_P(PSTR("0x%.4X-0x%.4X, "), mem_top-res_len*256, mem_top-1); + printf_P(PSTR("0x%.5lX-0x%.5lX, "), + (common_base + mem_top) - res_len*256, + (common_base + mem_top) - 1); else printf_P(PSTR(" - ")); printf_P(PSTR("Banked: ")); if (bank_len != 0) - printf_P(PSTR("0x%.4X-0x%.4X\n"), bank_top-bank_len*256, bank_top-1); + printf_P(PSTR("0x%.5lX-0x%.5lX\n"), + (banked_base + bank_top) - bank_len*256, + (banked_base + bank_top) - 1); else printf_P(PSTR(" - \n")); diff --git a/avr/command_tbl.c b/avr/command_tbl.c index a9cc2bd..72a87b9 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -151,10 +151,12 @@ CMD_TBL_ITEM( CMD_TBL_ITEM( loadcpm3, 3, 0, do_loadcpm3, "load CPM3.SYS file", - "[offset] [filename]\n" - " - Load CP/M 3 system file from FAT filesystem. This command makes\n" - " CPMLDR superfluous. Default filename is '"CONFIG_PATH_CPM3SYS"', but\n" - " uses environment variable '"ENV_PATH_CPM3SYS"', if set." + "[filename] [common base] [banked base]] \n" + " Load CP/M 3 system file from FAT filesystem. This command makes\n" + " CPMLDR superfluous. Uses the following environment variable if set:\n" + " '"ENV_CPM3_SYSFILE"' File to load. Default is '"CONFIG_CPM3_SYSFILE"'.\n" + " '"ENV_CPM3_COMMON_BASE"' Default is '"CONFIG_CPM3_COMMON_BASE_STR"'.\n" + " '"ENV_CPM3_BANKED_BASE"' Default is '"CONFIG_CPM3_BANKED_BASE_STR"'.\n" ), CMD_TBL_ITEM( loadi, 2, 0, do_loadihex, diff --git a/avr/env.c b/avr/env.c index a947583..9ea355f 100644 --- a/avr/env.c +++ b/avr/env.c @@ -34,7 +34,7 @@ const FLASH char default_env[] = { ENV_BAUDRATE "=" "115200" DELIM ENV_BOOTDELAY "=" "3" DELIM ENV_BOOTCMD "=" "reset; loadf; go ${startaddr}" DELIM - ENV_PATH_CPM3SYS "=" CONFIG_PATH_CPM3SYS DELIM + ENV_CPM3_SYSFILE "=" CONFIG_CPM3_SYSFILE DELIM ENV_PINALIAS "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7," "6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM ENV_STARTADDRESS "=" "0" DELIM diff --git a/include/config.h b/include/config.h index a403520..c7c4511 100644 --- a/include/config.h +++ b/include/config.h @@ -9,15 +9,17 @@ /* Environment variables */ -#define ENV_BAUDRATE "baudrate" -#define ENV_BOOTDELAY "bootdelay" +#define ENV_BAUDRATE "baudrate" +#define ENV_BOOTDELAY "bootdelay" #define ENV_BOOTCMD "bootcmd" -#define ENV_PATH_CPM3SYS "cpm3_file" -#define ENV_PINALIAS "pin_alias" -#define ENV_STARTADDRESS "startaddress" -#define ENV_ESC_CHAR "esc_char" -#define CONFIG_PATH_CPM3SYS "1:/cpm3.sys" +#define ENV_CPM3_SYSFILE "cpm3_file" +#define ENV_CPM3_COMMON_BASE "cpm3_commonbase" +#define ENV_CPM3_BANKED_BASE "cpm3_bankedbase" + +#define ENV_PINALIAS "pin_alias" +#define ENV_STARTADDRESS "startaddress" +#define ENV_ESC_CHAR "esc_char" #define CONFIG_ENV_SIZE 1600 #define CONFIG_ENV_OFFSET 0 @@ -28,6 +30,12 @@ #define CONFIG_BOOTDELAY 4 //#define CONFIG_ZERO_BOOTDELAY_CHECK 1 +#define CONFIG_CPM3_SYSFILE "1:/cpm3.sys" +#define CONFIG_CPM3_COMMON_BASE 0xC000 +#define CONFIG_CPM3_BANKED_BASE 0x0 +#define CONFIG_CPM3_COMMON_BASE_STR "C000" +#define CONFIG_CPM3_BANKED_BASE_STR "0" + #define CONFIG_CMD_MEMTEST #define CONFIG_MX_CYCLIC #define CONFIG_SYS_RAMSIZE_MAX (1l<<19) /* max. addressable memory */ diff --git a/z180/z180reg.inc b/z180/z180reg.inc index a248f5f..2666867 100644 --- a/z180/z180reg.inc +++ b/z180/z180reg.inc @@ -130,8 +130,8 @@ bcr1h equ IOBASE+2Fh ; dstat equ IOBASE+30h ;DMA Status Register b2m DE1,7 ;DMA enable ch 1,0 b2m DE0,6 ; - b2m DWE1,5 ;DMA Enable Bit Write Enable 1,0 - b2m DWE0,4 ; + b2m NDWE1,5 ;DMA Enable Bit Write Enable 1,0 + b2m NDWE0,4 ; b2m DIE1,3 ;DMA Interrupt Enable 1,0 b2m DIE0,2 ; b2m DME,0 ;DMA Master enable @@ -195,4 +195,3 @@ IV$ASCI0 equ 14 ;ASCI channel 0 IV$ASCI1 equ 16 ;ASCI channel 1 (lowest priority) .list - -- cgit v1.2.3