diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/background.h | 12 | ||||
-rw-r--r-- | include/cli.h | 64 | ||||
-rw-r--r-- | include/cli_readline.h | 50 | ||||
-rw-r--r-- | include/cmd_mem.h | 28 | ||||
-rw-r--r-- | include/command.h | 158 | ||||
-rw-r--r-- | include/common.h | 64 | ||||
-rw-r--r-- | include/con-utils.h | 22 | ||||
-rw-r--r-- | include/config.h | 45 | ||||
-rw-r--r-- | include/crc.h | 14 | ||||
-rw-r--r-- | include/debug.h | 39 | ||||
-rw-r--r-- | include/env.h | 16 | ||||
-rw-r--r-- | include/getopt-min.h | 12 | ||||
-rw-r--r-- | include/i2c.h | 63 | ||||
-rw-r--r-- | include/pin.h | 17 | ||||
-rw-r--r-- | include/print-utils.h | 2 | ||||
-rw-r--r-- | include/ring.h | 74 | ||||
-rw-r--r-- | include/rtc.h | 48 | ||||
-rw-r--r-- | include/serial.h | 9 | ||||
-rw-r--r-- | include/timer.h | 7 | ||||
-rw-r--r-- | include/xmalloc.h | 8 | ||||
-rw-r--r-- | include/z180-serv.h | 7 | ||||
-rw-r--r-- | include/z80-if.h | 49 |
22 files changed, 808 insertions, 0 deletions
diff --git a/include/background.h b/include/background.h new file mode 100644 index 0000000..8a430b3 --- /dev/null +++ b/include/background.h @@ -0,0 +1,12 @@ +#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/cli.h b/include/cli.h new file mode 100644 index 0000000..67ff63b --- /dev/null +++ b/include/cli.h @@ -0,0 +1,64 @@ +#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[]); + +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..5b25762 --- /dev/null +++ b/include/cli_readline.h @@ -0,0 +1,50 @@ +/* + * (C) Copyright 2014 Google, Inc + * Simon Glass <sjg@chromium.org> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef CLI_READLINE_H +#define CLI_READLINE_H + +extern char console_buffer[]; /* console I/O buffer */ + +/** + * cli_readline() - read a line into the console_buffer + * + * This is a convenience function which calls cli_readline_into_buffer(). + * + * @prompt: Prompt to display + * @return command line length excluding terminator, or -ve on error + */ +int cli_readline(const FLASH char *const prompt); + +/** + * readline_into_buffer() - read a line into a buffer + * + * Display the prompt, then read a command line into @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 if + * CONFIG_CMDLINE_EDITING is defined. Tab auto-complete is supported if + * CONFIG_AUTO_COMPLETE is defined. If CONFIG_BOOT_RETRY_TIME is defined, + * then a timeout will be applied. + * + * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0, + * time out when time goes past endtime (timebase time in ticks). + * + * @prompt: Prompt to display + * @buffer: Place to put the line that is entered + * @timeout: Timeout in milliseconds, 0 if none + * @return command line length excluding terminator, or -ve on error: of the + * timeout is exceeded (either CONFIG_BOOT_RETRY_TIME or the timeout + * parameter), then -2 is returned. If a break is detected (Ctrl-C) then + * -1 is returned. + */ +//int cli_readline_into_buffer(const char *const prompt, char *buffer, int timeout); + + +#endif /* CLI_READLINE_H */ + diff --git a/include/cmd_mem.h b/include/cmd_mem.h new file mode 100644 index 0000000..1802338 --- /dev/null +++ b/include/cmd_mem.h @@ -0,0 +1,28 @@ +#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 []); +#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/command.h b/include/command.h new file mode 100644 index 0000000..d0933a0 --- /dev/null +++ b/include/command.h @@ -0,0 +1,158 @@ + +/* + * Definitions for Command Processor + */ +#ifndef __COMMAND_H +#define __COMMAND_H + +#include "common.h" +#include "config.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; + +extern command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + +/** + * 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[]; + + +#endif /* __COMMAND_H */ diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..121922f --- /dev/null +++ b/include/common.h @@ -0,0 +1,64 @@ +#ifndef COMMON_H +#define COMMON_H + +#ifdef __AVR__ +#include <avr/io.h> +#include <avr/pgmspace.h> +#include <util/delay.h> + +#define udelay(n) _delay_us(n) + +//TODO: +// Known to work: 4.8.4, 4.9.1 +// Known to fail: 4.8.3, 4.9.0 +#define GCC_BUG_61443 1 + +#else +// TODO: stm32 +#endif /* __AVR__ */ + +#include <stdio.h> + +#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])) + + +#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..15a3ce8 --- /dev/null +++ b/include/con-utils.h @@ -0,0 +1,22 @@ +#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..82dbf81 --- /dev/null +++ b/include/config.h @@ -0,0 +1,45 @@ +#ifndef CONFIG_H +#define CONFIG_H + +/* Environment variables */ + +#define ENV_BAUDRATE "baudrate" +#define ENV_BOOTDELAY "bootdelay" +#define ENV_BOOTCMD "bootcmd" +#define ENV_PINALIAS "pin_alias" + +#define CONFIG_ENV_SIZE 1600 +#define CONFIG_ENV_OFFSET 0 +#define CONFIG_ENVVAR_MAX 20 + +#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_LOOPW +//#define CONFIG_CMD_MEMTEST +//#define CONFIG_MX_CYCLIC + +#define CONFIG_CMD_DATE 1 + +#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_MAXARGS 8 +#define CONFIG_SYS_ENV_NAMELEN 16 + +#define CONFIG_SYS_PROMPT "=> " +#define CONFIG_ESC_CHAR ('^'-0x40) + + +/* TODO: */ +//#define CONFIG_CMDLINE_EDITING 1 +//#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..927b5ff --- /dev/null +++ b/include/crc.h @@ -0,0 +1,14 @@ +#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__ */ +#endif /* __AVR__ */ + +#endif /* CRC_H */ diff --git a/include/debug.h b/include/debug.h new file mode 100644 index 0000000..45a1d50 --- /dev/null +++ b/include/debug.h @@ -0,0 +1,39 @@ + +#ifndef DEBUG_H_ +#define DEBUG_H_ + +#include "common.h" + +#ifdef DEBUG +#define _DEBUG 1 +#else +#define _DEBUG 0 +#endif + +#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 dump_eep(const uint8_t *addr, unsigned int len, char *title); +void dump_ram(const uint8_t *addr, unsigned int len, char *title); +void printfreelist(const char * title); + + +#endif /* DEBUG_H_ */ + diff --git a/include/env.h b/include/env.h new file mode 100644 index 0000000..7c4fee9 --- /dev/null +++ b/include/env.h @@ -0,0 +1,16 @@ +#ifndef ENV_H +#define ENV_H + +int env_init(void); + +char *getenv(const MEMX char *name); +unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long default_val); +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/getopt-min.h b/include/getopt-min.h new file mode 100644 index 0000000..9f7729e --- /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; + +#endif /* GETOPT_MIN_H */ + diff --git a/include/i2c.h b/include/i2c.h new file mode 100644 index 0000000..50b1fd0 --- /dev/null +++ b/include/i2c.h @@ -0,0 +1,63 @@ +/* + * 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/pin.h b/include/pin.h new file mode 100644 index 0000000..5b37587 --- /dev/null +++ b/include/pin.h @@ -0,0 +1,17 @@ +#ifndef PIN_H +#define PIN_H + +/* Number of user configurable I/O pins */ +#define PIN_MAX 11 + +typedef enum {NONE, INPUT, INPUT_PULLUP, OUTPUT, OUTPUT_TIMER} pinmode_t; + +int pin_config(int pin, pinmode_t mode); +pinmode_t pin_config_get(int pin); +int pin_read(int pin); +void pin_write(int pin, uint8_t val); +int pin_clockdiv_set(int pin, unsigned long divider); +long pin_clockdiv_get(int pin); + +#endif /* PIN_H */ + diff --git a/include/print-utils.h b/include/print-utils.h new file mode 100644 index 0000000..bcd9505 --- /dev/null +++ b/include/print-utils.h @@ -0,0 +1,2 @@ +void print_blanks(uint_fast8_t count); + diff --git a/include/ring.h b/include/ring.h new file mode 100644 index 0000000..d57f9aa --- /dev/null +++ b/include/ring.h @@ -0,0 +1,74 @@ +#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..51ee424 --- /dev/null +++ b/include/rtc.h @@ -0,0 +1,48 @@ +/* + * (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); + +#endif /* _RTC_H_ */ diff --git a/include/serial.h b/include/serial.h new file mode 100644 index 0000000..40ac815 --- /dev/null +++ b/include/serial.h @@ -0,0 +1,9 @@ +#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/timer.h b/include/timer.h new file mode 100644 index 0000000..bed3eb0 --- /dev/null +++ b/include/timer.h @@ -0,0 +1,7 @@ +#ifndef TIMER_H +#define TIMER_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..af4b1c0 --- /dev/null +++ b/include/z180-serv.h @@ -0,0 +1,7 @@ +#ifndef Z180_SERV_H +#define Z180_SERV_H + +void setup_z180_serv(void); +void restart_z180_serv(void); + +#endif /* Z180_SERV_H */ diff --git a/include/z80-if.h b/include/z80-if.h new file mode 100644 index 0000000..24fda5d --- /dev/null +++ b/include/z80-if.h @@ -0,0 +1,49 @@ + +#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(const FLASH uint8_t *src, uint32_t dest, uint32_t length); + + +typedef enum fifo_t { + fifo_msgin, fifo_msgout, + fifo_conout, fifo_conin, + 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); + |