diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/avr/ffconf.h | 289 | ||||
-rw-r--r-- | include/background.h | 17 | ||||
-rw-r--r-- | include/bcd.h | 13 | ||||
-rw-r--r-- | include/cli.h | 81 | ||||
-rw-r--r-- | include/cli_readline.h | 34 | ||||
-rw-r--r-- | include/cmd_mem.h | 30 | ||||
-rw-r--r-- | include/command.h | 167 | ||||
-rw-r--r-- | include/common.h | 94 | ||||
-rw-r--r-- | include/con-utils.h | 30 | ||||
-rw-r--r-- | include/config.h | 79 | ||||
-rw-r--r-- | include/crc.h | 21 | ||||
-rw-r--r-- | include/debug.h | 50 | ||||
-rw-r--r-- | include/diskio.h | 88 | ||||
-rw-r--r-- | include/env.h | 24 | ||||
-rw-r--r-- | include/eval_arg.h | 19 | ||||
l--------- | include/ff.h | 1 | ||||
-rw-r--r-- | include/ffconf.h | 5 | ||||
-rw-r--r-- | include/getopt-min.h | 12 | ||||
-rw-r--r-- | include/gpio.h | 22 | ||||
-rw-r--r-- | include/i2c.h | 65 | ||||
-rw-r--r-- | include/integer.h | 38 | ||||
-rw-r--r-- | include/print-utils.h | 24 | ||||
-rw-r--r-- | include/ring.h | 79 | ||||
-rw-r--r-- | include/rtc.h | 13 | ||||
-rw-r--r-- | include/serial.h | 15 | ||||
-rw-r--r-- | include/spi.h | 54 | ||||
l--------- | include/time.h | 1 | ||||
-rw-r--r-- | include/timer.h | 14 | ||||
-rw-r--r-- | include/xmalloc.h | 8 | ||||
-rw-r--r-- | include/z180-serv.h | 58 | ||||
-rw-r--r-- | include/z80-if.h | 56 |
31 files changed, 1501 insertions, 0 deletions
diff --git a/include/avr/ffconf.h b/include/avr/ffconf.h new file mode 100644 index 0000000..51a3c23 --- /dev/null +++ b/include/avr/ffconf.h @@ -0,0 +1,289 @@ +/*---------------------------------------------------------------------------/ +/ FatFs - Configuration file +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 63463 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: Basic functions are fully enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 2 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 0 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 0 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 1 +#define FF_MAX_LFN 128 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function +/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. +/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can +/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN +/ specification. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree() in ffsystem.c, need to be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches the character encoding on the API when LFN is enabled. +/ +/ 0: ANSI/OEM in current CP (TCHAR = char) +/ 1: Unicode in UTF-16 (TCHAR = WCHAR) +/ 2: Unicode in UTF-8 (TCHAR = char) +/ 3: Unicode in UTF-32 (TCHAR = DWORD) +/ +/ Also behavior of string I/O functions will be affected by this option. +/ When LFN is not enabled, this option has no effect. */ + + +#define FF_LFN_BUF 128 +#define FF_SFN_BUF 12 +/* This set of options defines size of file name members in the FILINFO structure +/ which is used to read out directory items. These values should be suffcient for +/ the file names to read. The maximum possible length of the read file name depends +/ on character encoding. When LFN is not enabled, these options have no effect. */ + + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM in current CP +/ 1: Unicode in UTF-16LE +/ 2: Unicode in UTF-16BE +/ 3: Unicode in UTF-8 +*/ + + +#define FF_FS_RPATH 2 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 2 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 0 +#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3" +/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. +/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each +/ logical drives. Number of items must not be less than FF_VOLUMES. Valid +/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are +/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is +/ not defined, a user defined volume string table needs to be defined as: +/ +/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... +*/ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 1 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ To enable exFAT, also LFN needs to be enabled. +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 0 +#define FF_NORTC_MON 1 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. Every object modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT 1000 +#define FF_SYNC_t HANDLE +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/* #include <windows.h> // O/S definitions */ + + + +/*--- End of configuration options ---*/ diff --git a/include/background.h b/include/background.h new file mode 100644 index 0000000..87e95e5 --- /dev/null +++ b/include/background.h @@ -0,0 +1,17 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef BACKGROUND_H +#define BACKGROUND_H + +typedef int (*bg_func)(int); + +int bg_register(bg_func f, int initval); +int bg_setstat(int handle, int val); +int bg_getstat(int handle); +void bg_shed(void); + +#endif /* BACKGROUND_H */ 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. <erbl259-lmu@yahoo.de> + * + * 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/include/cli.h b/include/cli.h new file mode 100644 index 0000000..28e92be --- /dev/null +++ b/include/cli.h @@ -0,0 +1,81 @@ +/* + * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de> + * + * (C) Copyright 2014 Google, Inc + * Simon Glass <sjg@chromium.org> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef CLI_H +#define CLI_H + +/** + * Go into the command loop + * + * This will return if we get a timeout waiting for a command, but only for + * the simple parser (not hush). See CONFIG_BOOT_RETRY_TIME. + */ +void cli_loop(void); + +/** + * cli_simple_run_command() - Execute a command with the simple CLI + * + * @cmd: String containing the command to execute + * @flag Flag value - see CMD_FLAG_... + * @return 1 - command executed, repeatable + * 0 - command executed but not repeatable, interrupted commands are + * always considered not repeatable + * -1 - not executed (unrecognized, bootd recursion or too many args) + * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is + * considered unrecognized) + */ +//int cli_simple_run_command(const char *cmd, int flag); + +/** + * cli_simple_run_command_list() - Execute a list of command + * + * The commands should be separated by ; or \n and will be executed + * by the built-in parser. + * + * This function cannot take a const char * for the command, since if it + * finds newlines in the string, it replaces them with \0. + * + * @param cmd String containing list of commands + * @param flag Execution flags (CMD_FLAG_...) + * @return 0 on success, or != 0 on error. + */ +//int cli_simple_run_command_list(char *cmd, int flag); + +/** + * parse_line() - split a command line down into separate arguments + * + * The argv[] array is filled with pointers into @line, and each argument + * is terminated by \0 (i.e. @line is changed in the process unless there + * is only one argument). + * + * #argv is terminated by a NULL after the last argument pointer. + * + * At most CONFIG_SYS_MAXARGS arguments are permited - if there are more + * than that then an error is printed, and this function returns + * CONFIG_SYS_MAXARGS, with argv[] set up to that point. + * + * @line: Command line to parse + * @args: Array to hold arguments + * @return number of arguments + */ +//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); + + +#endif /* CLI_H */ diff --git a/include/cli_readline.h b/include/cli_readline.h new file mode 100644 index 0000000..f326106 --- /dev/null +++ b/include/cli_readline.h @@ -0,0 +1,34 @@ +/* + * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de> + * + * (C) Copyright 2014 Google, Inc + * Simon Glass <sjg@chromium.org> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef CLI_READLINE_H +#define CLI_READLINE_H + +#include "common.h" +#include <stdbool.h> + +extern char console_buffer[]; /* console I/O buffer */ + +/** + * cli_readline() - read a line into the console_buffer + * + * Display the prompt, then read a command line into console_buffer. The + * maximum line length is CONFIG_SYS_CBSIZE including a \0 terminator, which + * will always be added. + * + * The command is echoed as it is typed. Command editing is supported. + * Tab auto-complete is supported if CONFIG_AUTO_COMPLETE is defined. + * + * @prompt: Prompt to display + * @enable_history: Use history buffer if true + * @return command line length excluding terminator, or -ve on error + */ +int cli_readline(const FLASH char *const prompt, bool enable_history); + +#endif /* CLI_READLINE_H */ diff --git a/include/cmd_mem.h b/include/cmd_mem.h new file mode 100644 index 0000000..782c10a --- /dev/null +++ b/include/cmd_mem.h @@ -0,0 +1,30 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef CMD_MEM_H +#define CMD_MEM_H + +#include "command.h" +#include "cmd_mem.h" + + +extern command_ret_t do_mem_md(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_mm(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_nm(cmd_tbl_t *, int, int, char * const []); +extern command_ret_t do_mem_mw(cmd_tbl_t *, int, int, char * const []); +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 []); +extern command_ret_t do_mem_loopw(cmd_tbl_t *, int, int, char * const []); +#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 []); +#endif /* CONFIG_MX_CYCLIC */ + +#endif /* CMD_MEM_H */ diff --git a/include/command.h b/include/command.h new file mode 100644 index 0000000..9ca460d --- /dev/null +++ b/include/command.h @@ -0,0 +1,167 @@ +/* + * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de> + * + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0 + */ + +/* + * Definitions for Command Processor + */ +#ifndef __COMMAND_H +#define __COMMAND_H + +#include "common.h" +#include "config.h" +#include <setjmp.h> + +#ifndef NULL +#define NULL 0 +#endif + +/* Default to a width of 8 characters for help message command width */ +#ifndef CONFIG_SYS_HELP_CMD_WIDTH +#define CONFIG_SYS_HELP_CMD_WIDTH 8 +#endif + +/* + * Error codes that commands return to cmd_process(). We use the standard 0 + * and 1 for success and failure, but add one more case - failure with a + * request to call cmd_usage(). But the cmd_process() function handles + * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1. + * This is just a convenience for commands to avoid them having to call + * cmd_usage() all over the place. + */ +typedef enum { + CMD_RET_SUCCESS = 0, /* Success */ + CMD_RET_FAILURE = 1, /* Failure */ + CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */ +} command_ret_t; + +/* + * Monitor Command Table + */ + +struct cmd_tbl_s { + const FLASH char *name; /* Command Name */ + 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) */ +#ifdef CONFIG_SYS_LONGHELP + const FLASH char *help; /* Help message (long) */ +#endif +#ifdef CONFIG_AUTO_COMPLETE + /* do auto completion on the arguments */ + int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); +#endif +}; + +typedef const FLASH struct cmd_tbl_s cmd_tbl_t; + +/** + * Process a command with arguments. We look up the command and execute it + * if valid. Otherwise we print a usage message. + * + * @param flag Some flags normally 0 (see CMD_FLAG_.. above) + * @param argc Number of arguments (arg 0 must be the command text) + * @param argv Arguments + * @param repeatable This function sets this to 0 if the command is not + * repeatable. If the command is repeatable, the value + * is left unchanged. + * @return 0 if the command succeeded, 1 if it failed + */ +command_ret_t +cmd_process(int flag, int argc, char * const argv[], uint_fast8_t *repeatable); + + +/* command.c */ +command_ret_t _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int + flag, int argc, char * const argv[]); +cmd_tbl_t *find_cmd(const char *cmd); +cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len); + +int cmd_tbl_item_count(void); +command_ret_t cmd_usage(cmd_tbl_t *cmdtp); + +#ifdef CONFIG_AUTO_COMPLETE +extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); +extern int cmd_auto_complete(const FLASH char *const prompt, char *buf, int *np, int *colp); +#endif + +/** + * cmd_process_error() - report and process a possible error + * + * @cmdtp: Command which caused the error + * @err: Error code (0 if none, -ve for error, like -EIO) + * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found + */ +int cmd_process_error(cmd_tbl_t *cmdtp, int err); + +/* + * Monitor Command + * + * All commands use a common argument format: + * + * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + */ + + +#ifdef CONFIG_CMD_BOOTD +extern command_ret_t do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +#endif +#ifdef CONFIG_CMD_BOOTM +extern command_ret_t do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd); +#else +static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) +{ + (void) cmdtp; (void) cmd; + + return 0; +} +#endif + +extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, + char *const argv[]); + +extern command_ret_t do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + +/* + * Command Flags: + */ +#define CMD_FLAG_REPEAT 0x0001 /* repeat last command */ +#define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */ + +#ifdef CONFIG_AUTO_COMPLETE +# define _CMD_COMPLETE(x) x, +#else +# define _CMD_COMPLETE(x) +#endif +#ifdef CONFIG_SYS_LONGHELP +# define _CMD_HELP(x) x, +#else +# define _CMD_HELP(x) +#endif + + +#define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \ + _usage, _help, _comp) \ + { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage), \ + _CMD_HELP(FSTR(_help)) _CMD_COMPLETE(_comp) } + +#define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help) \ + CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \ + _usage, _help, NULL) + +typedef command_ret_t (*do_cmd_t)(cmd_tbl_t *, int, int, char * const []); + +extern cmd_tbl_t cmd_tbl[]; + +extern jmp_buf cmd_jbuf; + + +#endif /* __COMMAND_H */ diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..e22b7a1 --- /dev/null +++ b/include/common.h @@ -0,0 +1,94 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef COMMON_H +#define COMMON_H + +#include <stdio.h> +#include <stdint.h> + +#define GCC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) + +#ifdef __AVR__ +#include <avr/io.h> +#include <avr/pgmspace.h> +#include <util/delay.h> + +#define udelay(n) _delay_us(n) + +struct bits { + uint8_t b0:1; + uint8_t b1:1; + uint8_t b2:1; + uint8_t b3:1; + uint8_t b4:1; + uint8_t b5:1; + uint8_t b6:1; + uint8_t b7:1; +} __attribute__((__packed__)); + +#define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin) + +//GCC bug PR61443 +// Known to work: 4.8.4, 4.9.1 +// Known to fail: 4.8.3, 4.9.0 + +#if (GCC_VERSION < 40804) || (GCC_VERSION == 40900) +#define GCC_BUG_61443 1 +#endif /* PR61443 */ + +#else +// TODO: stm32 +#endif /* __AVR__ */ + +#ifdef __FLASH +#define FLASH __flash +#define MEMX __memx +#else +#define FLASH +#define MEMX +#endif + +#define stringify(s) tostring(s) +#define tostring(s) #s + +#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 +#else +extern volatile uint_least8_t Stat; +#endif /* __AVR__ */ + +#define S_10MS_TO (1<<0) +#define S_MSG_PENDING (1<<1) +#define S_CON_PENDING (1<<2) + +static inline +void my_puts(const char *s) +{ + fputs(s, stdout); +} + +static inline +void my_puts_P(const char *s) +{ +#ifdef __AVR__ + fputs_P(s, stdout); +#else + fputs(s, stdout); +#endif /* __AVR__ */ +} + +#endif /* COMMON_H */ diff --git a/include/con-utils.h b/include/con-utils.h new file mode 100644 index 0000000..86c0df0 --- /dev/null +++ b/include/con-utils.h @@ -0,0 +1,30 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * Console utilities + */ + +#ifndef CON_UTILS_H +#define CON_UTILS_H + +uint_fast8_t tstc(void); + +int my_getchar(uint_fast8_t waitforchar); + +/* test if ctrl-c was pressed */ +uint_fast8_t ctrlc(void); + + +/* pass 1 to disable ctrlc() checking, 0 to enable. + * returns previous state + */ +uint_fast8_t disable_ctrlc(uint_fast8_t disable); + +uint_fast8_t had_ctrlc (void); +void clear_ctrlc(void); + +#endif /* CON_UTILS_H */ diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..8d7f348 --- /dev/null +++ b/include/config.h @@ -0,0 +1,79 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* Version */ +#define VERSION "0.6.8.2" + +/* Environment variables */ + +#define ENV_BAUDRATE "baudrate" +#define ENV_BOOTDELAY "bootdelay" +#define ENV_BOOTCMD "bootcmd" + +#define ENV_CPM3_SYSFILE "cpm3_file" +#define ENV_CPM3_COMMON_BASE "cpm3_commonbase" +#define ENV_CPM3_BANKED_BASE "cpm3_bankedbase" +#define ENV_CPM3_SCB "cpm3_scb" + +#define ENV_PINALIAS "pin_alias" +#define ENV_STARTADDRESS "startaddress" +#define ENV_ESC_CHAR "esc_char" + +#define ENV_SINGLESTEP "singlestep" + +#define CONFIG_ENV_SIZE 1600 +#define CONFIG_ENV_OFFSET 0 +#define CONFIG_ENVVAR_MAX 30 + +#define CONFIG_BAUDRATE 115200L +#define CONFIG_PWRON_DELAY 2000 /* ms to wait after power on */ +#define CONFIG_BOOTDELAY 4 +//#define CONFIG_ZERO_BOOTDELAY_CHECK 1 + +#define CONFIG_CPM3_SYSFILE "0:/cpm3.sys" +#define CONFIG_CPM3_COMMON_BASE 0xF000 +#define CONFIG_CPM3_BANKED_BASE 0x0 +//#define CONFIG_CPM3_COMMON_BASE_STR "F000" +#define CONFIG_CPM3_BANKED_BASE_STR "0" + +#define CONFIG_CPM_MAX_DRIVE 8 +#define CONFIG_CPM_BASE_DRIVE 'A' +#define CONFIG_CPM_BLOCK_SIZE 512 + +#define CONFIG_CMD_MEMTEST +#define CONFIG_MX_CYCLIC +#define CONFIG_SYS_RAMSIZE_MAX (1l<<19) /* max. addressable memory */ + +#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 */ + +#define CONFIG_SYS_CBSIZE 250 +#define CONFIG_SYS_HIST_MAX 20 +#define CONFIG_SYS_MAXARGS 20 +#define CONFIG_SYS_ENV_NAMELEN 16 + +#define CONFIG_SYS_PROMPT "-> " +#define CONFIG_SYS_PROMPT_REPEAT "=> " +#define CONFIG_ESC_CHAR ('^'-0x40) + +#define CONFIG_SYS_FBOOTSIG "Peda" + +/* TODO: */ +//#define CONFIG_AUTO_COMPLETE 1 + +#define CONFIG_SYS_LONGHELP 1 + +#endif /* CONFIG_H */ diff --git a/include/crc.h b/include/crc.h new file mode 100644 index 0000000..89cde1f --- /dev/null +++ b/include/crc.h @@ -0,0 +1,21 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef CRC_H +#define CRC_H + +#ifdef __AVR__ +#include <util/crc16.h> +static inline +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 new file mode 100644 index 0000000..0ee0129 --- /dev/null +++ b/include/debug.h @@ -0,0 +1,50 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0 + */ + + +#ifndef DEBUG_H_ +#define DEBUG_H_ + +#include "common.h" + +#ifdef DEBUG +#define _DEBUG 1 +#else +#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) \ + printf_P(PSTR(fmt), ##args); \ + } while (0) + +#define debug(fmt, args...) \ + debug_cond(_DEBUG, fmt, ##args) + + +#if 1 +#ifdef DEBUG +#define DBG_P(lvl, format, ...) if (DEBUG>=lvl) \ + fprintf_P( stdout, PSTR(format), ##__VA_ARGS__ ) +#else +#define DBG_P(lvl, ...) +#endif +#endif /* 0 */ + + +void printfreelist(const char * title); + + +#endif /* DEBUG_H_ */ diff --git a/include/diskio.h b/include/diskio.h new file mode 100644 index 0000000..fee87a5 --- /dev/null +++ b/include/diskio.h @@ -0,0 +1,88 @@ +/*----------------------------------------------------------------------- +/ Low level disk interface modlue include file R0.07 (C)ChaN, 2009 +/-----------------------------------------------------------------------*/ + +#ifndef _DISKIO_H +#define _DISKIO_H + +#define _USE_WRITE 1 /* 1: Enable disk_write function */ +#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */ + +#include "integer.h" + + +/* Status of Disk Functions */ +typedef BYTE DSTATUS; + +/* Results of Disk Functions */ +typedef enum { + RES_OK = 0, /* 0: Successful */ + RES_ERROR, /* 1: R/W Error */ + RES_WRPRT, /* 2: Write Protected */ + RES_NOTRDY, /* 3: Not Ready */ + RES_PARERR /* 4: Invalid Parameter */ +} DRESULT; + + +/*---------------------------------------*/ +/* Prototypes for disk control functions */ + +DSTATUS disk_initialize (BYTE drv); +DSTATUS disk_status (BYTE drv); +DRESULT disk_read (BYTE drv, BYTE* buff, DWORD sector, UINT count); +#if _USE_WRITE +DRESULT disk_write (BYTE drv, const BYTE* buff, DWORD sector, UINT count); +#endif +#if _USE_IOCTL +DRESULT disk_ioctl (BYTE drv, BYTE cmd, void* buff); +#endif +void disk_timerproc (void); + + + +/* Disk Status Bits (DSTATUS) */ + +#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 */ +#define STAT_MASK (STA_NOINIT | STA_NODISK | STA_PROTECT) + + +/* Command code for disk_ioctrl() */ + +/* Generic command (Used by FatFs) */ +#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ +#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ +#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ +#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ +#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */ + +/* Generic command (Not used by FatFs) */ +#define CTRL_FORMAT 5 /* Create physical format on the media */ +#define CTRL_POWER_IDLE 6 /* Put the device idle state */ +#define CTRL_POWER_OFF 7 /* Put the device off state */ +#define CTRL_LOCK 8 /* Lock media removal */ +#define CTRL_UNLOCK 9 /* Unlock media removal */ +#define CTRL_EJECT 10 /* Eject media */ + +/* MMC/SDC specific command (Not used by FatFs) */ +#define MMC_GET_TYPE 50 /* Get card type */ +#define MMC_GET_CSD 51 /* Get CSD */ +#define MMC_GET_CID 52 /* Get CID */ +#define MMC_GET_OCR 53 /* Get OCR */ +#define MMC_GET_SDSTAT 54 /* Get SD status */ + +/* ATA/CF specific command (Not used by FatFs) */ +#define ATA_GET_REV 60 /* Get F/W revision */ +#define ATA_GET_MODEL 61 /* Get model name */ +#define ATA_GET_SN 62 /* Get serial number */ + +/* MMC card type flags (MMC_GET_TYPE) */ +#define CT_MMC 0x01 /* MMC ver 3 */ +#define CT_SD1 0x02 /* SD ver 1 */ +#define CT_SD2 0x04 /* SD ver 2 */ +#define CT_SDC (CT_SD1|CT_SD2) /* SD */ +#define CT_BLOCK 0x08 /* Block addressing */ + +#endif /* _DISKIO_H */ diff --git a/include/env.h b/include/env.h new file mode 100644 index 0000000..bc44413 --- /dev/null +++ b/include/env.h @@ -0,0 +1,24 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef ENV_H +#define ENV_H + +#include <stdbool.h> + +int env_init(void); + +char *getenv_str(const MEMX char *name); +unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long default_val); +bool getenv_yesno(const MEMX char *name); +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) +int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf); +#endif + +#endif /* ENV_H */ diff --git a/include/eval_arg.h b/include/eval_arg.h new file mode 100644 index 0000000..a86b0d5 --- /dev/null +++ b/include/eval_arg.h @@ -0,0 +1,19 @@ +/* + * (C) Copyright 2016 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef EVAL_ARG_H +#define EVAL_ARG_H + +/** + * eval_arg() - evaluate a command argument expression + * + * @arg: pointer to argument (usually argv[i]) + * @end_ptr: pointer to position, where evaluation stopped. Points to '\0' if no error. + * @return evaluated argument + */ +long eval_arg(char *arg, char **end_ptr); + +#endif /* EVAL_ARG_H */ diff --git a/include/ff.h b/include/ff.h new file mode 120000 index 0000000..7fb6cb1 --- /dev/null +++ b/include/ff.h @@ -0,0 +1 @@ +../fatfs/src/ff.h
\ No newline at end of file diff --git a/include/ffconf.h b/include/ffconf.h new file mode 100644 index 0000000..9841d5b --- /dev/null +++ b/include/ffconf.h @@ -0,0 +1,5 @@ +#ifdef __AVR__ +#include "avr/ffconf.h" +#else + /* TODO */ +#endif diff --git a/include/getopt-min.h b/include/getopt-min.h new file mode 100644 index 0000000..e42aa78 --- /dev/null +++ b/include/getopt-min.h @@ -0,0 +1,12 @@ +#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 */ + const FLASH char * optstring ); /* allowed args, e.g. "ab:c" */ + +extern int optind; +extern char *optarg; + +#endif /* GETOPT_MIN_H */ diff --git a/include/gpio.h b/include/gpio.h new file mode 100644 index 0000000..1e0346d --- /dev/null +++ b/include/gpio.h @@ -0,0 +1,22 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef GPIO_H +#define GPIO_H + +/* Number of user configurable I/O pins */ +#define GPIO_MAX 11 + +typedef enum {NONE, INPUT, INPUT_PULLUP, OUTPUT, OUTPUT_TIMER} gpiomode_t; + +int gpio_config(int pin, gpiomode_t mode); +gpiomode_t gpio_config_get(int pin); +int gpio_read(int pin); +void gpio_write(int pin, uint8_t val); +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 new file mode 100644 index 0000000..f39fa1d --- /dev/null +++ b/include/i2c.h @@ -0,0 +1,65 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net> + * Copyright (C) 2009 - 2013 Heiko Schocher <hs@denx.de> + * Changes for multibus/multiadapter I2C support. + * + * (C) Copyright 2001 + * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. + * + * SPDX-License-Identifier: GPL-2.0+ + * + * The original I2C interface was + * (C) 2000 by Paolo Scaffardi (arsenio@tin.it) + * AIRVENT SAM s.p.a - RIMINI(ITALY) + * but has been changed substantially. + */ + +#ifndef _I2C_H_ +#define _I2C_H_ + +/* + * Configuration items. + */ +/* TODO: config.h? */ +#define I2C_RXTX_LEN 128 /* maximum tx/rx buffer length */ + + +/* + * Initialization, must be called once on start up, may be called + * repeatedly to change the speed. + */ +void i2c_init(uint32_t speed); + +/* + * Probe the given I2C chip address. Returns 0 if a chip responded, + * not 0 on failure. + */ +int i2c_probe(uint8_t chip); + +/* + * Read/Write interface: + * chip: I2C chip address, range 0..127 + * addr: Memory (register) address within the chip + * alen: Number of bytes to use for addr (typically 1, 2 for larger + * memories, 0 for register type devices with only one + * register) + * buffer: Where to read/write the data + * len: How many bytes to read/write + * + * Returns: 0 on success, not 0 on failure + */ +int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen, + uint8_t *buffer, uint_fast8_t len); +int i2c_write(uint8_t chip, unsigned int addr, uint_fast8_t alen, + uint8_t *buffer, uint_fast8_t len); + +/* + * Utility routines to read/write registers. + */ +uint8_t i2c_reg_read(uint8_t addr, uint8_t reg); + +void i2c_reg_write(uint8_t addr, uint8_t reg, uint8_t val); + +#endif /* _I2C_H_*/ diff --git a/include/integer.h b/include/integer.h new file mode 100644 index 0000000..4660ed6 --- /dev/null +++ b/include/integer.h @@ -0,0 +1,38 @@ +/*-------------------------------------------*/
+/* Integer type definitions for FatFs module */
+/*-------------------------------------------*/
+
+#ifndef _FF_INTEGER
+#define _FF_INTEGER
+
+#ifdef _WIN32 /* FatFs development platform */
+
+#include <windows.h>
+#include <tchar.h>
+typedef unsigned __int64 QWORD;
+
+
+#else /* Embedded platform */
+
+/* These types MUST be 16-bit or 32-bit */
+typedef int INT;
+typedef unsigned int UINT;
+
+/* This type MUST be 8-bit */
+typedef unsigned char BYTE;
+
+/* These types MUST be 16-bit */
+typedef short SHORT;
+typedef unsigned short WORD;
+typedef unsigned short WCHAR;
+
+/* These types MUST be 32-bit */
+typedef long LONG;
+typedef unsigned long DWORD;
+
+/* This type MUST be 64-bit (Remove this for C89 compatibility) */
+typedef unsigned long long QWORD;
+
+#endif
+
+#endif
diff --git a/include/print-utils.h b/include/print-utils.h new file mode 100644 index 0000000..ffff039 --- /dev/null +++ b/include/print-utils.h @@ -0,0 +1,24 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef PRINT_UTILS_H +#define PRINT_UTILS_H + +#include "common.h" +#include <avr/eeprom.h> + +void print_blanks(uint_fast8_t count); +int dump_mem(uint32_t address, uint32_t offset, uint32_t len, + int (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title); + +void dump_eep(uint32_t addr, unsigned int len, char *title); +void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title); + +int eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); +int ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); +int flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); + +#endif /* PRINT_UTILS_H */ diff --git a/include/ring.h b/include/ring.h new file mode 100644 index 0000000..b64f462 --- /dev/null +++ b/include/ring.h @@ -0,0 +1,79 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef RING_H +#define RING_H + +struct ring { + uint8_t *data; + uint_fast8_t mask; + volatile uint_fast8_t begin; + volatile uint_fast8_t end; +}; + + +static inline +void ring_init(struct ring *ring, uint8_t *buf, int size) +{ + ring->data = buf; + ring->mask = (size-1) & 0xff; + ring->begin = 0; + ring->end = 0; +} + +static inline +int ring_write_ch(struct ring *ring, uint8_t ch) +{ + uint_fast8_t ep = ring->end; + + ring->data[ep] = ch; + ep = (ep + 1) & ring->mask; + + if ((ep) != ring->begin) { + ring->end = ep; + return 1; + } + + return -1; +} + +#if 0 +static inline +int ring_write(struct ring *ring, uint8_t *data, int size) +{ + int i; + + for (i = 0; i < size; i++) { + if (ring_write_ch(ring, data[i]) < 0) + return -i; + } + + return i; +} +#endif + +static inline +int ring_read_ch(struct ring *ring) +{ + int ret = -1; + uint_fast8_t bp = ring->begin; + + if (bp != ring->end) { + ret = ring->data[bp]; + ring->begin = (bp + 1) & ring->mask; + } + + return ret; +} + + +static inline +int_fast8_t ring_is_empty(struct ring *ring) +{ + return ring->begin == ring->end; +} + +#endif /* RING_H */ diff --git a/include/rtc.h b/include/rtc.h new file mode 100644 index 0000000..ca4c068 --- /dev/null +++ b/include/rtc.h @@ -0,0 +1,13 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _RTC_H_ +#define _RTC_H_ + +int rtc_get (struct tm *); +int rtc_set (struct tm *); + +#endif /* _RTC_H_ */ diff --git a/include/serial.h b/include/serial.h new file mode 100644 index 0000000..54c7211 --- /dev/null +++ b/include/serial.h @@ -0,0 +1,15 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef SERIAL_H +#define SERIAL_H + +void serial_setup(unsigned long baud); +void serial_putc(char); +int serial_getc(void); +uint_fast8_t serial_tstc(void); + +#endif /* SERIAL_H */ diff --git a/include/spi.h b/include/spi.h new file mode 100644 index 0000000..4638476 --- /dev/null +++ b/include/spi.h @@ -0,0 +1,54 @@ +/* + * (C) Copyright 2009,2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef SPI_H_ +#define SPI_H_ + +#define SPI_PORT PORTB /* SPI Connection port */ +#define SPI_DDR DDRB /* SPI Direction port */ +#define SPI_SS 0 +#define SPI_SCK 1 +#define SPI_MOSI 2 +#define SPI_MISO 3 + + +/* SPI macros */ + +#define SPI_SET_SPEED_F_2 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (0<<SPR0); SPSR = (1<<SPI2X); } while(0) +#define SPI_SET_SPEED_F_4 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (0<<SPR0); SPSR = (0<<SPI2X); } while(0) +#define SPI_SET_SPEED_F_8 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (1<<SPR0); SPSR = (1<<SPI2X); } while(0) +#define SPI_SET_SPEED_F_16 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0) +#define SPI_SET_SPEED_F_32 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (0<<SPR0); SPSR = (1<<SPI2X); } while(0) +#define SPI_SET_SPEED_F_64 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (0<<SPR0); SPSR = (0<<SPI2X); } while(0) +#define SPI_SET_SPEED_F_128 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0) + +/** switch to fast SPI Clock */ +#define SPISetFastClock() SPI_SET_SPEED_F_2 +#define SPISetSlowClock() SPI_SET_SPEED_F_8 +#define SPISetMMCInitClock() SPI_SET_SPEED_F_64 + +#define SPI_OFF() do { SPCR = 0; } while(0) + +static inline __attribute__((always_inline)) void spi_wait() { + loop_until_bit_is_set(SPSR,SPIF); +} + +static inline __attribute__((always_inline)) void spi_write(uint8_t a) { + SPDR = a; +} + +static inline void spi_xmit(uint8_t a){ + spi_write(a); + spi_wait(); +} + +static inline uint8_t spi_rcvr(void) { + SPDR = 0xFF; + spi_wait(); + return SPDR; +} + +#endif /* SPI_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/include/timer.h b/include/timer.h new file mode 100644 index 0000000..83bc329 --- /dev/null +++ b/include/timer.h @@ -0,0 +1,14 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef TIMER_H +#define TIMER_H + +#include "common.h" + +uint32_t get_timer(uint32_t); + +#endif /* TIMER_H */ diff --git a/include/xmalloc.h b/include/xmalloc.h new file mode 100644 index 0000000..cb0019f --- /dev/null +++ b/include/xmalloc.h @@ -0,0 +1,8 @@ + +#ifndef XMALLOC_H +#define XMALLOC_H + +void* xmalloc(size_t size); +void* xrealloc(void *p, size_t size); + +#endif /* XMALLOC_H */ diff --git a/include/z180-serv.h b/include/z180-serv.h new file mode 100644 index 0000000..3b4a462 --- /dev/null +++ b/include/z180-serv.h @@ -0,0 +1,58 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef Z180_SERV_H +#define Z180_SERV_H + +#include <stdint.h> +#include <stdbool.h> +#include "ff.h" + +void setup_z180_serv(void); +void restart_z180_serv(void); + + +/* CP/M drive interface */ + +/* TODO: Variable Disk Format */ +#define CONFIG_CPM_DISKSIZE (8*1024*1024L) + +typedef uint8_t drv_opt_t; + +#define DRV_OPT_RO (1<<0) /* Drive is write protected */ +#define DRV_OPT_DEBUG (1<<1) /* Debug this drive */ +#define DRV_OPT_REATTATCH (1<<7) /* Change existing attachment */ + +typedef uint8_t drv_flag_t; +#define DRV_FLG_OPEN (1<<0) /* Drive is logged in from CP/M */ +#define DRV_FLG_DIRTY (2<<0) /* Unwritten data */ + +struct cpm_drive_s { + drv_opt_t opt; + drv_flag_t flags; + uint32_t dph; + char *img_name; + FIL fd; +}; + +/* Return codes */ + +#define AT_OK 0 +#define AT_ERROR 1 +#define AT_RANGE 2 +#define AT_ALREADY 3 +#define AT_NOT 4 +#define AT_NOFILE 5 +#define AT_NOMEM 6 +#define AT_OPEN 7 +#define AT_OTHER 8 + + +int drv_list(void); +int drv_detach(uint8_t drv); +int drv_attach(uint8_t drv, const char *filename, drv_opt_t options); + +#endif /* Z180_SERV_H */ diff --git a/include/z80-if.h b/include/z80-if.h new file mode 100644 index 0000000..ef87e5a --- /dev/null +++ b/include/z80-if.h @@ -0,0 +1,56 @@ +/* + * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0 + */ +#include "common.h" + +#define ZST_ACQUIRED 0x01 +#define ZST_RUNNING 0x02 + +typedef enum { + RESET = 0x00, + RESET_AQRD = ZST_ACQUIRED, + RUNNING = ZST_RUNNING, + RUNNING_AQRD = ZST_RUNNING | ZST_ACQUIRED, +} zstate_t; + +typedef enum { + Reset, + Request, + Release, + Run, + Restart, + M_Cycle +} bus_cmd_t; + +typedef enum {LOW, HIGH} level_t; + +zstate_t z80_bus_state(void); +zstate_t z80_bus_cmd(bus_cmd_t cmd); +void z80_setup_bus(void); +int z80_stat_reset(void); +//void z80_busreq(level_t level); +int z80_stat_halt(void); + + +void z80_write(uint32_t addr, uint8_t data); +uint8_t z80_read(uint32_t addr); +void z80_memset(uint32_t addr, uint8_t data, uint32_t length); +void z80_write_block_P(const FLASH uint8_t *src, uint32_t dest, uint32_t length); +void z80_write_block(const uint8_t *src, uint32_t dest, uint32_t length); +void z80_read_block (uint8_t *dest, uint32_t src, size_t length); + + +typedef enum fifo_t { + fifo_msgin, fifo_msgout, + fifo_conin, fifo_conout, + NUM_FIFOS + } fifo_t; + +void z80_memfifo_init(const fifo_t f, uint32_t adr); +int z80_memfifo_is_empty(const fifo_t f); +int z80_memfifo_is_full(const fifo_t f); +int z80_memfifo_getc(const fifo_t f); +uint8_t z80_memfifo_getc_wait(const fifo_t f); +void z80_memfifo_putc(fifo_t f, uint8_t val); |