First push after merge, split and enhance both zOS and zputa

This commit is contained in:
Philip Smart
2020-04-25 22:48:39 +01:00
commit 25466f1db8
5072 changed files with 2191180 additions and 0 deletions

139
include/fat.h Normal file
View File

@@ -0,0 +1,139 @@
#ifndef _FAT16_H_INCLUDED
#define _FAT16_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#define MAXDIRENTRIES 8
// FIXME - derive CHS address from FAT boot sector for card and partition mount modes.
typedef struct
{
unsigned int sector;
unsigned int index;
} entryTYPE;
typedef struct
{
char name[11]; /* name of file */
unsigned char attributes; /* file attributes */
entryTYPE entry; /* file entry location */
unsigned int sector; /* sector index in file */
unsigned int size; /* file size */
unsigned int cluster; /* current cluster */
unsigned int start_cluster; /* first cluster of file */
char long_name[261];
} fileTYPE;
struct PartitionEntry
{
unsigned char geometry[8]; // ignored
unsigned long startlba;
unsigned long sectors;
};
struct MasterBootRecord
{
unsigned char bootcode[446]; // ignored
struct PartitionEntry Partition[4]; // We copy these (and byteswap if need be)
unsigned short Signature; // This lets us detect an MBR (and the need for byteswapping).
} __attribute__ ((packed));
extern struct PartitionEntry partitions[4]; // FirstBlock and LastBlock will be byteswapped as necessary
extern int partitioncount;
typedef struct
{
unsigned char Name[8]; /* filename, blank filled */
#define SLOT_EMPTY 0x00 /* slot has never been used */
#define SLOT_E5 0x05 /* the real value is 0xe5 */
#define SLOT_DELETED 0xe5 /* file in this slot deleted */
unsigned char Extension[3]; /* extension, blank filled */
unsigned char Attributes; /* file attributes */
#define ATTR_NORMAL 0x00 /* normal file */
#define ATTR_READONLY 0x01 /* file is readonly */
#define ATTR_HIDDEN 0x02 /* file is hidden */
#define ATTR_SYSTEM 0x04 /* file is a system file */
#define ATTR_VOLUME 0x08 /* entry is a volume label */
#define ATTR_DIRECTORY 0x10 /* entry is a directory name */
#define ATTR_ARCHIVE 0x20 /* file is new or modified */
#define ATTR_LFN 0x0F /* long file name entry */
unsigned char LowerCase; /* NT VFAT lower case flags */
#define LCASE_BASE 0x08 /* filename base in lower case */
#define LCASE_EXT 0x10 /* filename extension in lower case */
unsigned char CreateHundredth; /* hundredth of seconds in CTime */
unsigned short CreateTime; /* create time */
unsigned short CreateDate; /* create date */
unsigned short AccessDate; /* access date */
unsigned short HighCluster; /* high bytes of cluster number */
unsigned short ModifyTime; /* last update time */
unsigned short ModifyDate; /* last update date */
unsigned short StartCluster; /* starting cluster of file */
unsigned long FileSize; /* size of file in bytes */
} __attribute__ ((packed)) DIRENTRY;
typedef union {
unsigned short fat16[256];
unsigned long fat32[128];
} FATBUFFER;
#define FILETIME(h,m,s) (((h<<11)&0xF800)|((m<<5)&0x7E0)|((s/2)&0x1F))
#define FILEDATE(y,m,d) ((((y-1980)<<9)&0xFE00)|((m<<5)&0x1E0)|(d&0x1F))
// global sector buffer, data for read/write actions is stored here.
// BEWARE, this buffer is also used and thus trashed by all other functions
extern unsigned char sector_buffer[1024]; // sector buffer - room for 2 sectors, to ease reading data not sector-aligned...
extern char longfilename[260];
extern unsigned char cluster_size;
extern unsigned long cluster_mask;
extern unsigned char fat32;
// constants
#define DIRECTORY_ROOT 0
// file seeking
#define SEEK_SET 0
#define SEEK_CUR 1
// scanning flags
#define SCAN_INIT 0 // start search from beginning of directory
#define SCAN_NEXT 1 // find next file in directory
#define SCAN_PREV -1 // find previous file in directory
#define SCAN_NEXT_PAGE 2 // find next 8 files in directory
#define SCAN_PREV_PAGE -2 // find previous 8 files in directory
#define SCAN_INIT_FIRST 3 // search for an entry with given cluster number
#define SCAN_INIT_NEXT 4 // search for entries higher than the first one
// options flags
#define SCAN_DIR 1 // include subdirectories
#define SCAN_LFN 2 // include long file names
#define FIND_DIR 4 // find first directory beginning with given charater
#define FIND_FILE 8 // find first file entry beginning with given charater
// functions
unsigned int FindDrive(void);
unsigned long GetFATLink(unsigned long cluster);
unsigned int FileNextSector(fileTYPE *file);
unsigned int FileOpen(fileTYPE *file, const char *name);
unsigned int FileSeek(fileTYPE *file, unsigned long offset, unsigned long origin);
unsigned int FileRead(fileTYPE *file, unsigned char *pBuffer);
unsigned int FileWrite(fileTYPE *file, unsigned char *pBuffer);
//unsigned char FileReadEx(fileTYPE *file, unsigned char *pBuffer, unsigned long nSize);
unsigned int FileCreate(unsigned long iDirectory, fileTYPE *file);
unsigned int UpdateEntry(fileTYPE *file);
int ScanDirectory(unsigned long mode, char *extension, unsigned char options);
void ChangeDirectory(DIRENTRY *p);
DIRENTRY *NextDirEntry(int prev); // Must be called in ascending sequence, starting with 0
#ifdef __cplusplus
}
#endif
#endif

146
include/fileio.h Executable file
View File

@@ -0,0 +1,146 @@
/* Hosted File I/O interface definitions, for GDB, the GNU Debugger.
Copyright 2003 Free Software Foundation, Inc.
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., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#ifndef GDB_FILEIO_H_
#define GDB_FILEIO_H_
/* The following flags are defined to be independent of the host
as well as the target side implementation of these constants.
All constants are defined with a leading FILEIO_ in the name
to allow the usage of these constants together with the
corresponding implementation dependent constants in one module. */
/* open(2) flags */
#define FILEIO_O_RDONLY 0x0
#define FILEIO_O_WRONLY 0x1
#define FILEIO_O_RDWR 0x2
#define FILEIO_O_APPEND 0x8
#define FILEIO_O_CREAT 0x200
#define FILEIO_O_TRUNC 0x400
#define FILEIO_O_EXCL 0x800
#define FILEIO_O_SUPPORTED (FILEIO_O_RDONLY | FILEIO_O_WRONLY| \
FILEIO_O_RDWR | FILEIO_O_APPEND| \
FILEIO_O_CREAT | FILEIO_O_TRUNC| \
FILEIO_O_EXCL)
/* mode_t bits */
#define FILEIO_S_IFREG 0100000
#define FILEIO_S_IFDIR 040000
#define FILEIO_S_IFCHR 020000
#define FILEIO_S_IRUSR 0400
#define FILEIO_S_IWUSR 0200
#define FILEIO_S_IXUSR 0100
#define FILEIO_S_IRWXU 0700
#define FILEIO_S_IRGRP 040
#define FILEIO_S_IWGRP 020
#define FILEIO_S_IXGRP 010
#define FILEIO_S_IRWXG 070
#define FILEIO_S_IROTH 04
#define FILEIO_S_IWOTH 02
#define FILEIO_S_IXOTH 01
#define FILEIO_S_IRWXO 07
#define FILEIO_S_SUPPORTED (FILEIO_S_IFREG|FILEIO_S_IFDIR| \
FILEIO_S_IRWXU|FILEIO_S_IRWXG| \
FILEIO_S_IRWXO)
/* lseek(2) flags */
#define FILEIO_SEEK_SET 0
#define FILEIO_SEEK_CUR 1
#define FILEIO_SEEK_END 2
/* errno values */
#define FILEIO_EPERM 1
#define FILEIO_ENOENT 2
#define FILEIO_EINTR 4
#define FILEIO_EIO 5
#define FILEIO_EBADF 9
#define FILEIO_EACCES 13
#define FILEIO_EFAULT 14
#define FILEIO_EBUSY 16
#define FILEIO_EEXIST 17
#define FILEIO_ENODEV 19
#define FILEIO_ENOTDIR 20
#define FILEIO_EISDIR 21
#define FILEIO_EINVAL 22
#define FILEIO_ENFILE 23
#define FILEIO_EMFILE 24
#define FILEIO_EFBIG 27
#define FILEIO_ENOSPC 28
#define FILEIO_ESPIPE 29
#define FILEIO_EROFS 30
#define FILEIO_ENOSYS 88
#define FILEIO_ENAMETOOLONG 91
#define FILEIO_EUNKNOWN 9999
/* limits */
#define FILEIO_INT_MIN -2147483648L
#define FILEIO_INT_MAX 2147483647L
#define FILEIO_UINT_MAX 4294967295UL
#define FILEIO_LONG_MIN -9223372036854775808LL
#define FILEIO_LONG_MAX 9223372036854775807LL
#define FILEIO_ULONG_MAX 18446744073709551615ULL
/* Integral types as used in protocol. */
#if 0
typedef __int32_t fio_int_t;
typedef __uint32_t fio_uint_t, fio_mode_t, fio_time_t;
typedef __int64_t fio_long_t;
typedef __uint64_t fio_ulong_t;
#endif
#define FIO_INT_LEN 4
#define FIO_UINT_LEN 4
#define FIO_MODE_LEN 4
#define FIO_TIME_LEN 4
#define FIO_LONG_LEN 8
#define FIO_ULONG_LEN 8
typedef char fio_int_t[FIO_INT_LEN];
typedef char fio_uint_t[FIO_UINT_LEN];
typedef char fio_mode_t[FIO_MODE_LEN];
typedef char fio_time_t[FIO_TIME_LEN];
typedef char fio_long_t[FIO_LONG_LEN];
typedef char fio_ulong_t[FIO_ULONG_LEN];
/* Struct stat as used in protocol. For complete independence
of host/target systems, it's defined as an array with offsets
to the members. */
struct fio_stat {
fio_uint_t fst_dev;
fio_uint_t fst_ino;
fio_mode_t fst_mode;
fio_uint_t fst_nlink;
fio_uint_t fst_uid;
fio_uint_t fst_gid;
fio_uint_t fst_rdev;
fio_ulong_t fst_size;
fio_ulong_t fst_blksize;
fio_ulong_t fst_blocks;
fio_time_t fst_atime;
fio_time_t fst_mtime;
fio_time_t fst_ctime;
};
struct fio_timeval {
fio_time_t ftv_sec;
fio_long_t ftv_usec;
};
#endif /* GDB_FILEIO_H_ */

20
include/interrupts.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
#ifdef __cplusplus
extern "C" {
#endif
// Prototypes.
void SetIntHandler(void(*handler)());
void EnableInterrupt(uint32_t);
void DisableInterrupt(uint32_t);
extern void DisableInterrupts(void);
extern void EnableInterrupts(void);
#ifdef __cplusplus
}
#endif
#endif

139
include/k64f_soc.h Normal file
View File

@@ -0,0 +1,139 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: k64f_soc.h
// Created: January 2019 - April 2020
// Author(s): Philip Smart
// Description: K64F System On a Chip utilities.
// A set of utilities specific to interaction with the K64F SoC hardware.
//
// Credits:
// Copyright: (c) 2019 Philip Smart <philip.smart@net2net.org>
//
// History: January 2019 - Initial script written.
// April 2020 - Duplicated the zpu_soc for the Freescale K64F used in the Teensy3.5
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __K64FSOC_H__
#define __K64FSOC_H__
#ifdef __cplusplus
extern "C" {
#endif
// Macro to omit code if deemed optional and the compile time flag MINIMUM_FUNCTIONALITY is defined.
#ifdef MINIMUM_FUNCTIONALITY
#define OPTIONAL(a)
#else
#define OPTIONAL(a) a
#endif
// System settings.
#define CLK_FREQ 120000000UL // Default frequency of the Teensy3.5 K64F CPU
// Memory sizes and devices implemented - these can be ignored if the SoC Configuration register is implemented as this provides the exact build configuration.
#define FRAM_IMPL 1
#define FRAMNV_IMPL 1
#define FRAMNVC_IMPL 1
#define RAM_IMPL 1
#define PS2_IMPL 1
#define SPI_IMPL 1
#define SD_IMPL 1
#define SD_DEVICE_CNT 1
#define INTRCTL_IMPL 1
#define INTRCTL_CHANNELS 16
#define TIMER1_IMPL 1
#define TIMER1_TIMERS_CNT 1
#define FRAM_ADDR 0x00000000
#define FRAM_SIZE 0x0007FFFF
#define FRAMNV_ADDR 0x10000000
#define FRAMNV_SIZE 0x0001FFFF
#define FRAMNVC_ADDR 0x14000000
#define FRAMNVC_SIZE 0x00000FFF
#define RAM_ADDR 0x1FFF0000
#define RAM_SIZE 0x0003FFFF
#define STACK_BRAM_ADDR 0x00007800
#define STACK_BRAM_SIZE 0x000007FF
#define CPU_RESET_ADDR 0x00000000
#define CPU_MEM_START 0x00000000
#define BRAM_APP_START_ADDR 0x2000
// Debug only macros which dont generate code when debugging disabled.
#ifdef DEBUG
// Macro to print to the debug channel.
//
#define debugf(a, ...) ({\
xprintf(a, ##__VA_ARGS__);\
})
#define dbg_putchar(a) ({\
xputc(a);\
})
#define dbg_puts(a) ({\
xputs(a);\
})
#define dbg_breadcrumb(x) putc(x);
#else
#define dbg_putchar(a)
#define dbg_puts(a)
#define debugf(a, ...)
#define dbg_breadcrumb(x)
#endif
// Prototypes.
void setupSoCConfig(void);
void showSoCConfig(void);
void printCPU(void);
// Configuration values.
typedef struct
{
uint32_t addrFRAM;
uint32_t sizeFRAM;
uint32_t addrFRAMNV;
uint32_t sizeFRAMNV;
uint32_t addrFRAMNVC;
uint32_t sizeFRAMNVC;
uint32_t addrRAM;
uint32_t sizeRAM;
uint32_t resetVector;
uint32_t cpuMemBaseAddr;
uint32_t stackStartAddr;
uint32_t sysFreq;
uint32_t memFreq;
uint8_t implRAM;
uint8_t implFRAM;
uint8_t implFRAMNV;
uint8_t implFRAMNVC;
uint8_t implPS2;
uint8_t implSPI;
uint8_t implSD;
uint8_t sdCardNo;
uint8_t implIntrCtl;
uint8_t intrChannels;
uint8_t implTimer1;
uint8_t timer1No;
} SOC_CONFIG;
#ifdef __cplusplus
}
#endif
#endif

50
include/keyboard.h Normal file
View File

@@ -0,0 +1,50 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
#define KEY_EXT 0xe0
#define KEY_KEYUP 0xf0
#define KEY_F1 0x5
#define KEY_F2 0x6
#define KEY_F3 0x4
#define KEY_F4 0x0C
#define KEY_F5 0x3
#define KEY_F6 0x0B
#define KEY_F7 0x83
#define KEY_F8 0x0A
#define KEY_F9 0x1
#define KEY_F10 0x9
#define KEY_F11 0x78
#define KEY_F12 0x7
#define KEY_CAPSLOCK 0x58
#define KEY_NUMLOCK 0x77
#define KEY_SCROLLLOCK 0x7e
#define KEY_LEFTARROW 0xeb
#define KEY_RIGHTARROW 0xf4
#define KEY_UPARROW 0xf5
#define KEY_DOWNARROW 0xf2
#define KEY_ENTER 0x5a
#define KEY_PAGEUP 0xfd
#define KEY_PAGEDOWN 0xfa
#define KEY_SPACE 0x29
#define KEY_ESC 0x76
#ifdef __cplusplus
extern "C" {
#endif
int HandlePS2RawCodes();
void ClearKeyboard();
int TestKey(int rawcode);
// Each keytable entry has two bits: bit 0 - currently pressed, bit 1 - pressed since last test
extern unsigned int keytable[16];
#ifdef __cplusplus
}
#endif
#endif

66
include/malloc.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* malloc.h
*
* Internals for the memory allocator
*/
// #include <stdint.h>
#include <stddef.h>
// #include <klibc/sysconfig.h>
#define _KLIBC_MALLOC_CHUNK_SIZE 65536
#ifdef __cplusplus
extern "C" {
#endif
/*
* This structure should be a power of two. This becomes the
* alignment unit.
*/
struct free_arena_header;
struct arena_header {
size_t type;
size_t size;
struct free_arena_header *next, *prev;
};
#ifdef DEBUG_MALLOC
#define ARENA_TYPE_USED 0x64e69c70
#define ARENA_TYPE_FREE 0x012d610a
#define ARENA_TYPE_HEAD 0x971676b5
#define ARENA_TYPE_DEAD 0xeeeeeeee
#else
#define ARENA_TYPE_USED 0
#define ARENA_TYPE_FREE 1
#define ARENA_TYPE_HEAD 2
#endif
#define MALLOC_CHUNK_MASK (_KLIBC_MALLOC_CHUNK_SIZE-1)
#define ARENA_SIZE_MASK (~(sizeof(struct arena_header)-1))
/*
* This structure should be no more than twice the size of the
* previous structure.
*/
struct free_arena_header {
struct arena_header a;
struct free_arena_header *next_free, *prev_free;
};
extern char heap_low, heap_top; // Take the addresses of these.
void malloc_add(void *p,size_t size);
void *malloc(size_t);
void free(void *m);
#ifdef __cplusplus
}
#endif
/*
* Internal variable used by brk/sbrk
*/
// extern char *__current_brk;

102
include/oc_i2c_master.h Normal file
View File

@@ -0,0 +1,102 @@
/*
/////////////////////////////////////////////////////////////////////
//// ////
//// Include file for OpenCores I2C Master core ////
//// ////
//// File : oc_i2c_master.h ////
//// Function: c-include file ////
//// ////
//// Authors: Richard Herveille (richard@asics.ws) ////
//// Filip Miletic ////
//// ////
//// www.opencores.org ////
//// ////
/////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2001 Richard Herveille ////
//// Filip Miletic ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
//// ////
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
//// 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. ////
//// ////
/////////////////////////////////////////////////////////////////////
*/
/*
* Definitions for the Opencores i2c master core
*/
/* --- Definitions for i2c master's registers --- */
/* ----- Read-write access */
#define OC_I2C_PRER_LO 0x00 /* Low byte clock prescaler register */
#define OC_I2C_PRER_HI 0x01 /* High byte clock prescaler register */
#define OC_I2C_CTR 0x02 /* Control register */
/* ----- Write-only registers */
#define OC_I2C_TXR 0x03 /* Transmit byte register */
#define OC_I2C_CR 0x04 /* Command register */
/* ----- Read-only registers */
#define OC_I2C_RXR 0x03 /* Receive byte register */
#define OC_I2C_SR 0x04 /* Status register */
/* ----- Bits definition */
/* ----- Control register */
#define OC_I2C_EN (1<<7) /* Core enable bit: */
/* 1 - core is enabled */
/* 0 - core is disabled */
#define OC_I2C_IEN (1<<6) /* Interrupt enable bit */
/* 1 - Interrupt enabled */
/* 0 - Interrupt disabled */
/* Other bits in CR are reserved */
/* ----- Command register bits */
#define OC_I2C_STA (1<<7) /* Generate (repeated) start condition*/
#define OC_I2C_STO (1<<6) /* Generate stop condition */
#define OC_I2C_RD (1<<5) /* Read from slave */
#define OC_I2C_WR (1<<4) /* Write to slave */
#define OC_I2C_ACK (1<<3) /* Acknowledge from slave */
/* 1 - ACK */
/* 0 - NACK */
#define OC_I2C_IACK (1<<0) /* Interrupt acknowledge */
/* ----- Status register bits */
#define OC_I2C_RXACK (1<<7) /* ACK received from slave */
/* 1 - ACK */
/* 0 - NACK */
#define OC_I2C_BUSY (1<<6) /* Busy bit */
#define OC_I2C_TIP (1<<1) /* Transfer in progress */
#define OC_I2C_IF (1<<0) /* Interrupt flag */
/* bit testing and setting macros */
#define OC_ISSET(reg,bitmask) ((reg)&(bitmask))
#define OC_ISCLEAR(reg,bitmask) (!(OC_ISSET(reg,bitmask)))
#define OC_BITSET(reg,bitmask) ((reg)|(bitmask))
#define OC_BITCLEAR(reg,bitmask) ((reg)|(~(bitmask)))
#define OC_BITTOGGLE(reg,bitmask) ((reg)^(bitmask))
#define OC_REGMOVE(reg,value) ((reg)=(value))

46
include/ps2.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef PS2_H
#define PS2_H
// Private
#define PS2_RINGBUFFER_SIZE 16 // 32 bytes
struct ps2_ringbuffer
{
volatile int in_hw;
volatile int in_cpu;
volatile int out_hw;
volatile int out_cpu;
unsigned int inbuf[PS2_RINGBUFFER_SIZE]; // Int is much easier than char for ZPU to deal with
unsigned int outbuf[PS2_RINGBUFFER_SIZE];
};
#ifdef __cplusplus
extern "C" {
#endif
void ps2_ringbuffer_init(struct ps2_ringbuffer *r);
void ps2_ringbuffer_write(struct ps2_ringbuffer *r,int in);
int ps2_ringbuffer_read(struct ps2_ringbuffer *r);
int ps2_ringbuffer_count(struct ps2_ringbuffer *r);
extern struct ps2_ringbuffer kbbuffer;
extern struct ps2_ringbuffer mousebuffer;
void PS2Handler();
// Public interface
void PS2Init();
#ifdef __cplusplus
}
#endif
#define PS2KeyboardRead(x) ps2_ringbuffer_read(&kbbuffer)
#define PS2KeyboardBytesReady(x) ps2_ringbuffer_count(&kbbuffer)
#define PS2KeyboardWrite(x) ps2_ringbuffer_write(&kbbuffer,x);
#define PS2MouseRead(x) ps2_ringbuffer_read(&mousebuffer)
#define PS2MouseBytesReady(x) ps2_ringbuffer_count(&mousebuffer)
#define PS2MouseWrite(x) ps2_ringbuffer_write(&mousebuffer,x);
#define PS2_INT 4
#endif

51
include/readline.h Normal file
View File

@@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: readline.h
// Created: April 2020
// Author(s): Alfred Klomp (www.alfredklomp.com) - original readline.c
// Philip Smart - Port to K64f/ZPU and additions of history buffer logic.
// Description: A readline module for embedded systems without the overhead of GNU readline or the
// need to use > C99 standard as the ZPU version of GCC doesnt support it!
// The readline modules originally came from Alfred Klomp's Raduino project and whilst
// I was searching for an alternative to GNU after failing to compile it with the ZPU
// version of GCC (as well as the size), I came across RADUINO and this readline
// module was very well written and easily portable to this project.
//
// Credits:
// Copyright: (c) -> 2016 - Alfred Klomp (www.alfredklomp.com)
// (C) 2020 - Philip Smart <philip.smart@net2net.org> porting and history buf.
//
// History: April 2020 - With the advent of the tranZPUter SW, I needed a better command
// line module for entering, recalling and editting commands. This
// module after adding history buffer mechanism is the ideal
// solution.
// features of zOS where applicable.
//
// Notes: See Makefile to enable/disable conditional components
// __SD_CARD__ - Add the SDCard logic.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
uint8_t *readline (uint8_t *, int, const char *);
#ifdef __cplusplus
}
#endif

185
include/register.h Normal file
View File

@@ -0,0 +1,185 @@
#ifndef __ZPUINO_REGISTER_H__
#define __ZPUINO_REGISTER_H__
#if defined( __ZPUINO_DE0NANO__ )
# include "board_de0nano.h"
#else
# error Unknown board.
# endif
#ifndef ASSEMBLY
typedef volatile unsigned int* register_t;
#endif
#define SPIISBLOCKING 1
#define BIT(x) (1<<(x))
#define IO_SLOT(x) (IOBASE + ((x)<<IO_SLOT_OFFSET_BIT))
#define REGISTER(SLOT, y) *(volatile unsigned int*)(SLOT + ((y)<<2))
#define SYSCTLBASE IO_SLOT(0)
#define SPIBASE IO_SLOT(4)
#define UARTBASE IO_SLOT(1)
#define GPIOBASE IO_SLOT(2)
#define TIMERSBASE IO_SLOT(3)
#define SIGMADELTABASE IO_SLOT(5)
#define USERSPIBASE IO_SLOT(6)
#define CRC16BASE IO_SLOT(7)
#define ROFF_UARTDATA 0
#define ROFF_UARTCTL 1
#define ROFF_UARTSTATUS 1
#define UARTDATA REGISTER(UARTBASE,ROFF_UARTDATA)
#define UARTCTL REGISTER(UARTBASE,ROFF_UARTCTL)
#define UARTSTATUS REGISTER(UARTBASE,ROFF_UARTSTATUS)
#define ROFF_SPICTL 0
#define ROFF_SPIDATA 1
#define SPICTL REGISTER(SPIBASE,ROFF_SPICTL)
#define SPIDATA REGISTER(SPIBASE,ROFF_SPIDATA)
#define GPIODATA(x) REGISTER(GPIOBASE,x)
#define GPIOTRIS(x) REGISTER(GPIOBASE,4+x)
#define GPIOPPSMODE(x) REGISTER(GPIOBASE,8+x)
#define GPIOPPSOUT(x) REGISTER(GPIOBASE,128 + x)
#define GPIOPPSIN(x) REGISTER(GPIOBASE,256 + x)
// for direct pin access
#define GPIOSET(x) REGISTER(GPIOBASE,16+x)
#define GPIOCLR(x) REGISTER(GPIOBASE,20+x)
#define GPIOTGL(x) REGISTER(GPIOBASE,24+x)
#define PINSET(x) GPIOSET((x>>5))=(1<<(x&0x1F))
#define PINCLR(x) GPIOCLR((x>>5))=(1<<(x&0x1F))
#define PINTGL(x) GPIOTGL((x>>5))=(1<<(x&0x1F))
#define ROFF_TMR0CTL 0
#define ROFF_TMR0CNT 1
#define ROFF_TMR0CMP 2
#define ROFF_TIMERTSC 3
//#define ROFF_TMR0OCR 3
#define ROFF_TMR1CTL 64
#define ROFF_TMR1CNT 65
#define ROFF_TMR1CMP 66
//#define ROFF_TMR1OCR 67
#define TMR0CTL REGISTER(TIMERSBASE,0)
#define TMR0CNT REGISTER(TIMERSBASE,1)
#define TMR0CMP REGISTER(TIMERSBASE,2)
#define TIMERTSC REGISTER(TIMERSBASE,3)
#define MILLISL REGISTER(TIMERSBASE,4)
#define MILLISH REGISTER(TIMERSBASE,5)
// PWM for timer 0
#define TMR0PWMLOW(x) REGISTER(TIMERSBASE, 32+(4*x))
#define TMR0PWMHIGH(x) REGISTER(TIMERSBASE, 33+(4*x))
#define TMR0PWMCTL(x) REGISTER(TIMERSBASE, 34+(4*x))
#define TMR1CTL REGISTER(TIMERSBASE,64)
#define TMR1CNT REGISTER(TIMERSBASE,65)
#define TMR1CMP REGISTER(TIMERSBASE,66)
// PWM for timer 1
#define TMR1PWMLOW(x) REGISTER(TIMERSBASE, 96+(4*x))
#define TMR1PWMHIGH(x) REGISTER(TIMERSBASE, 97+(4*x))
#define TMR1PWMCTL(x) REGISTER(TIMERSBASE, 98+(4*x))
#define INTRCTL REGISTER(SYSCTLBASE,0)
#define INTRMASK REGISTER(SYSCTLBASE,1)
#define INTRLEVEL REGISTER(SYSCTLBASE,2)
#define SIGMADELTACTL REGISTER(SIGMADELTABASE,0)
#define SIGMADELTADATA REGISTER(SIGMADELTABASE,1)
#define USPICTL REGISTER(USERSPIBASE,0)
#define USPIDATA REGISTER(USERSPIBASE,1)
#define ROFF_CRC16ACC 0
#define ROFF_CRC16POLY 1
#define ROFF_CRC16APP 2
#define ROFF_CRC16AM1 4
#define ROFF_CRC16AM2 5
#define CRC16ACC REGISTER(CRC16BASE,0)
#define CRC16POLY REGISTER(CRC16BASE,1)
#define CRC16APP REGISTER(CRC16BASE,2)
#define CRC16AM1 REGISTER(CRC16BASE,4)
#define CRC16AM2 REGISTER(CRC16BASE,5)
#define UARTEN 16 /* Uart enable */
/* Timer CTL bits */
#define TCTLENA 0 /* Timer Enable */
#define TCTLCCM 1 /* Clear on Compare Match */
#define TCTLDIR 2 /* Direction */
#define TCTLIEN 3 /* Interrupt enable */
#define TCTLCP0 4 /* Clock prescaler bit 0 */
#define TCTLCP1 5 /* Clock prescaler bit 1 */
#define TCTLCP2 6 /* Clock prescaler bit 2 */
#define TCTLIF 7 /* Interrupt flag */
#define TCTUPDP0 9 /* Update policy */
#define TCTUPDP1 10 /* Update policy */
#define TPWMEN 0 /* PWM enabled */
#define TCTL_UPDATE_NOW (0<<TCTUPDP0)
#define TCTL_UPDATE_ZERO_SYNC (1<<TCTUPDP0)
#define TCTL_UPDATE_LATER (2<<TCTUPDP0)
/* SPI bits */
#define SPIREADY 0 /* SPI ready */
#define SPICP0 1 /* Clock prescaler bit 0 */
#define SPICP1 2 /* Clock prescaler bit 1 */
#define SPICP2 3 /* Clock prescaler bit 2 */
#define SPICPOL 4 /* Clock polarity */
#define SPISRE 5 /* Sample on Rising Edge */
#define SPIEN 6 /* SPI Enabled (gpio acquire) */
#define SPIBLOCK 7
#define SPITS0 8
#define SPITS1 9
/* Sigma-Delta bits */
#define SDENA0 0 /* Sigma-delta enable */
#define SDENA1 1
#define SDLE 2 /* Little-endian */
/* Baud rate computation */
#define BAUDRATEGEN(x) (((CLK_FREQ/(x))/16)-1)
#define INPUT 1
#define OUTPUT 0
#define HIGH 1
#define LOW 0
/* PPS configuration - output */
#define IOPIN_SIGMADELTA0 0
#define IOPIN_TIMER0_OC 1
#define IOPIN_TIMER1_OC 2
#define IOPIN_USPI_MOSI 3
#define IOPIN_USPI_SCK 4
#define IOPIN_SIGMADELTA1 5
/* PPS configuration - input */
#define IOPIN_USPI_MISO 0
/* Current interrupts (might not be implemented) */
#define INTRLINE_TIMER0 3
#define INTRLINE_TIMER1 4
#define INTRLINE_EXT1 16
#define INTRLINE_EXT2 17
#endif

76
include/simple_utils.h Normal file
View File

@@ -0,0 +1,76 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: simple_utils.h
// Created: January 2019
// Author(s): Philip Smart
// Description: ZPU boottime simple utilities.
// A set of utilities to be used in the IOCP (or other minimalist application) which
// assume a minimum compile environment (ie. no printf)such that the smallest code
// size is created.
//
// Credits:
// Copyright: (c) 2019 Philip Smart <philip.smart@net2net.org>
//
// History: January 2019 - Initial script written.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef SIMPLE_UTILS_H
#define SIMPLE_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
// Prototypes
void printnibble(uint8_t c);
void printhexbyte(uint8_t c);
void printhex(uint32_t c);
void printdhex(uint32_t c);
int memoryDump(uint32_t, uint32_t);
unsigned int crc32_init(void);
unsigned int crc32_addword(unsigned int, unsigned int);
unsigned int get_dword(void);
// Macro to print out hex data to the debug channel.
//
#define dbg_printnibble(a) ({\
set_serial_output(1);\
printnibble(a);\
set_serial_output(0);\
})
#define dbg_printhexbyte(a) ({\
set_serial_output(1);\
printhexbyte(a);\
set_serial_output(0);\
})
#define dbg_printhex(a) ({\
set_serial_output(1);\
printhex(a);\
set_serial_output(0);\
})
#define dbg_printdhex(a) ({\
set_serial_output(1);\
printdhex(a);\
set_serial_output(0);\
})
#ifdef __cplusplus
}
#endif
#endif

18
include/spi.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef SPI_H
#define SPI_H
//#include "zpu-types.h"
#ifdef __cplusplus
extern "C" {
#endif
int spi_init(uint32_t device);
int sd_read_sector(uint32_t device, unsigned long lba,unsigned char *buf);
int sd_write_sector(uint32_t device, unsigned long lba,unsigned char *buf); // FIXME - stub
#ifdef __cplusplus
}
#endif
#endif

17
include/swap.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef SWAP_H
#define SWAP_H
#ifdef __cplusplus
extern "C" {
#endif
unsigned int SwapBBBB(unsigned int i);
unsigned int SwapBB(unsigned int i);
unsigned int SwapWW(unsigned int i);
#ifdef __cplusplus
}
#endif
#endif

49
include/syscalls.h Executable file
View File

@@ -0,0 +1,49 @@
/* General use syscall.h file.
The more ports that use this file, the simpler sim/common/nltvals.def
remains. */
#ifndef LIBGLOSS_SYSCALL_H
#define LIBGLOSS_SYSCALL_H
/* Note: This file may be included by assembler source. */
/* These should be as small as possible to allow a port to use a trap type
instruction, which the system call # as the trap (the d10v for instance
supports traps 0..31). An alternative would be to define one trap for doing
system calls, and put the system call number in a register that is not used
for the normal calling sequence (so that you don't have to shift down the
arguments to add the system call number). Obviously, if these system call
numbers are ever changed, all of the simulators and potentially user code
will need to be updated. */
/* There is no current need for the following: SYS_execv, SYS_creat, SYS_wait,
etc. etc. Don't add them. */
/* These are required by the ANSI C part of newlib (excluding system() of
course). */
#define SYS_exit 1
#define SYS_open 2
#define SYS_close 3
#define SYS_read 4
#define SYS_write 5
#define SYS_lseek 6
#define SYS_unlink 7
#define SYS_getpid 8
#define SYS_kill 9
#define SYS_fstat 10
/*#define SYS_sbrk 11 - not currently a system call, but reserved. */
/* ARGV support. */
#define SYS_argvlen 12
#define SYS_argv 13
/* These are extras added for one reason or another. */
#define SYS_chdir 14
#define SYS_stat 15
#define SYS_chmod 16
#define SYS_utime 17
#define SYS_time 18
#define SYS_gettimeofday 19
#define SYS_times 20
#define SYS_link 21
#endif

538
include/tools.h Normal file
View File

@@ -0,0 +1,538 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: tools.h
// Created: January 2019
// Author(s): Philip Smart
// Description: zOS application tools.
// A set of tools to be used by the zOS application.
//
// Credits:
// Copyright: (c) 2019 Philip Smart <philip.smart@net2net.org>
//
// History: January 2019 - Initial script written.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef TOOLS_H
#define TOOLS_H
#ifdef __cplusplus
extern "C" {
#endif
// Constants.
#define CMD_DISK_DUMP 1 // Disk Commands Range 01 .. 09
#define CMD_DISK_INIT 2
#define CMD_DISK_STATUS 3
#define CMD_DISK_IOCTL_SYNC 4
#define CMD_BUFFER_DUMP 10 // Buffer Commands Range 10 .. 19
#define CMD_BUFFER_EDIT 11
#define CMD_BUFFER_READ 12
#define CMD_BUFFER_WRITE 13
#define CMD_BUFFER_FILL 14
#define CMD_BUFFER_LEN 15
#define CMD_FS_INIT 20 // FS Commands Range 20 .. 59
#define CMD_FS_STATUS 21
#define CMD_FS_DIRLIST 22
#define CMD_FS_OPEN 23
#define CMD_FS_CLOSE 24
#define CMD_FS_SEEK 25
#define CMD_FS_READ 26
#define CMD_FS_CAT 27
#define CMD_FS_INSPECT 28
#define CMD_FS_WRITE 29
#define CMD_FS_TRUNC 30
#define CMD_FS_RENAME 31
#define CMD_FS_DELETE 32
#define CMD_FS_CREATEDIR 33
#define CMD_FS_ALLOCBLOCK 34
#define CMD_FS_CHANGEATTRIB 35
#define CMD_FS_CHANGETIME 36
#define CMD_FS_COPY 37
#define CMD_FS_CHANGEDIR 38
#define CMD_FS_CHANGEDRIVE 39
#define CMD_FS_SHOWDIR 40
#define CMD_FS_SETLABEL 41
#define CMD_FS_CREATEFS 42
#define CMD_FS_LOAD 43
#define CMD_FS_DUMP 44
#define CMD_FS_CONCAT 45
#define CMD_FS_XTRACT 46
#define CMD_FS_SAVE 47
#define CMD_FS_EXEC 48
#define CMD_MEM_CLEAR 60 // MEM Commands Range 60 .. 79
#define CMD_MEM_COPY 61
#define CMD_MEM_DIFF 63
#define CMD_MEM_DUMP 64
#define CMD_MEM_EDIT_BYTES 65
#define CMD_MEM_EDIT_HWORD 66
#define CMD_MEM_EDIT_WORD 67
#define CMD_MEM_PERF 68
#define CMD_MEM_SRCH 69
#define CMD_MEM_TEST 70
#define CMD_HW_INTR_DISABLE 80 // HW Commands Range 80 .. 99
#define CMD_HW_INTR_ENABLE 81
#define CMD_HW_SHOW_REGISTER 82
#define CMD_HW_TEST_TIMERS 83
#define CMD_HW_FIFO_DISABLE 84
#define CMD_HW_FIFO_ENABLE 85
#define CMD_HW_TCPU 86
#define CMD_TEST_DHRYSTONE 100 // TEST Commands Range 100 .. 119
#define CMD_TEST_COREMARK 101
#define CMD_EXECUTE 120 // EXECUTE Commands Range 120 .. 129
#define CMD_CALL 121
#define CMD_MISC_RESTART_APP 130 // MISC Commands Range 130 ..149
#define CMD_MISC_REBOOT 131
#define CMD_MISC_HELP 132
#define CMD_MISC_INFO 133
#define CMD_MISC_SETTIME 134
#define CMD_MISC_TEST 135
#define CMD_APP_TBASIC 140 // TinyBasic
#define CMD_APP_MBASIC 141 // Mini Basic
#define CMD_APP_KILO 142 // Kilo Editor
#define CMD_APP_ED 143 // Ed Editor
#define CMD_BADKEY -1
#define CMD_NOKEY 0
#define CMD_GROUP_DISK 1
#define CMD_GROUP_BUFFER 2
#define CMD_GROUP_FS 3
#define CMD_GROUP_MEM 4
#define CMD_GROUP_HW 5
#define CMD_GROUP_TEST 6
#define CMD_GROUP_EXEC 7
#define CMD_GROUP_MISC 8
#define CMD_GROUP_APP 9
#define CMD_GROUP_DISK_NAME "DISK IO CONTROLS"
#define CMD_GROUP_BUFFER_NAME "DISK BUFFER CONTROLS"
#define CMD_GROUP_FS_NAME "FILESYSTEM CONTROLS"
#define CMD_GROUP_MEM_NAME "MEMORY"
#define CMD_GROUP_HW_NAME "HARDWARE"
#define CMD_GROUP_TEST_NAME "TESTING"
#define CMD_GROUP_EXEC_NAME "EXECUTION"
#define CMD_GROUP_MISC_NAME "MISC COMMANDS"
#define CMD_GROUP_APP_NAME "APPLICATIONS"
// File Execution modes.
//
#define EXEC_MODE_CALL 0
#define EXEC_MODE_JMP 1
// Size of sector buffer.
//
#define SECTOR_SIZE 512
// Command list.
//
typedef struct {
const char *cmd;
uint8_t builtin;
uint8_t key;
uint8_t group;
const char *params;
const char *description;
} t_cmdstruct;
// Group id to names.
//
typedef struct {
uint8_t key;
const char *name;
} t_groupstruct;
// Help text mapped to associated command.
typedef struct {
uint8_t key;
const char *params;
const char *description;
} t_helpstruct;
#if (defined(BUILTIN_MISC_HELP) && BUILTIN_MISC_HELP == 1)
// Table of groups and associated group id, used to index the cmd table.
static t_groupstruct groupTable[] = {
{ CMD_GROUP_DISK, CMD_GROUP_DISK_NAME },
{ CMD_GROUP_BUFFER, CMD_GROUP_BUFFER_NAME },
{ CMD_GROUP_FS, CMD_GROUP_FS_NAME },
{ CMD_GROUP_MEM, CMD_GROUP_MEM_NAME },
{ CMD_GROUP_HW, CMD_GROUP_HW_NAME },
{ CMD_GROUP_TEST, CMD_GROUP_TEST_NAME },
{ CMD_GROUP_EXEC, CMD_GROUP_EXEC_NAME },
{ CMD_GROUP_MISC, CMD_GROUP_MISC_NAME },
{ CMD_GROUP_APP, CMD_GROUP_APP_NAME },
};
#endif
#if ((defined(__ZOS__) || defined(__ZPUTA__)) && !defined(__APP__)) || (defined(BUILTIN_MISC_HELP) && BUILTIN_MISC_HELP == 1)
// Table of supported commands. The table contains the command, group to which it belongs, parameters needed (for display)
// and help text.
static t_cmdstruct cmdTable[] = {
// Full command names.
#if defined(__SD_CARD__)
// Disk level commands.
#if (defined(BUILTIN_DISK_DUMP) && BUILTIN_DISK_DUMP == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "ddump", BUILTIN_DISK_DUMP, CMD_DISK_DUMP, CMD_GROUP_DISK },
#endif
{ "dinit", BUILTIN_DEFAULT, CMD_DISK_INIT, CMD_GROUP_DISK },
#if (defined(BUILTIN_DISK_STATUS) && BUILTIN_DISK_STATUS == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "dstat", BUILTIN_DISK_STATUS, CMD_DISK_STATUS, CMD_GROUP_DISK },
#endif
{ "dioctl", BUILTIN_DEFAULT, CMD_DISK_IOCTL_SYNC, CMD_GROUP_DISK },
// Disk buffer level commands.
#if (defined(BUILTIN_BUFFER_DUMP) && BUILTIN_BUFFER_DUMP == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "bdump", BUILTIN_BUFFER_DUMP, CMD_BUFFER_DUMP, CMD_GROUP_BUFFER },
#endif
#if (defined(BUILTIN_BUFFER_EDIT) && BUILTIN_BUFFER_EDIT == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "bedit", BUILTIN_BUFFER_EDIT, CMD_BUFFER_EDIT, CMD_GROUP_BUFFER },
#endif
#if (defined(BUILTIN_BUFFER_READ) && BUILTIN_BUFFER_READ == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "bread", BUILTIN_BUFFER_READ, CMD_BUFFER_READ, CMD_GROUP_BUFFER },
#endif
#if (defined(BUILTIN_BUFFER_WRITE) && BUILTIN_BUFFER_WRITE == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "bwrite", BUILTIN_BUFFER_WRITE, CMD_BUFFER_WRITE, CMD_GROUP_BUFFER },
#endif
#if (defined(BUILTIN_BUFFER_FILL) && BUILTIN_BUFFER_FILL == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "bfill", BUILTIN_BUFFER_FILL, CMD_BUFFER_FILL, CMD_GROUP_BUFFER },
#endif
#if (defined(BUILTIN_BUFFER_LEN) && BUILTIN_BUFFER_LEN == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "blen", BUILTIN_BUFFER_LEN, CMD_BUFFER_LEN, CMD_GROUP_BUFFER },
#endif
// Filesystem level commands.
// File contents manipulation commands.
{ "finit", BUILTIN_DEFAULT, CMD_FS_INIT, CMD_GROUP_FS },
#if (defined(BUILTIN_FS_OPEN) && BUILTIN_FS_OPEN == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fopen", BUILTIN_FS_OPEN, CMD_FS_OPEN, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_CLOSE) && BUILTIN_FS_CLOSE == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fclose", BUILTIN_FS_CLOSE, CMD_FS_CLOSE, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_SEEK) && BUILTIN_FS_SEEK == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fseek", BUILTIN_FS_SEEK, CMD_FS_SEEK, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_READ) && BUILTIN_FS_READ == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fread", BUILTIN_FS_READ, CMD_FS_READ, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_INSPECT) && BUILTIN_FS_INSPECT == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "finspect", BUILTIN_FS_INSPECT, CMD_FS_INSPECT, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_WRITE) && BUILTIN_FS_WRITE == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fwrite", BUILTIN_FS_WRITE, CMD_FS_WRITE, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_TRUNC) && BUILTIN_FS_TRUNC == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "ftrunc", BUILTIN_FS_TRUNC, CMD_FS_TRUNC, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_ALLOCBLOCK) && BUILTIN_FS_ALLOCBLOCK == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "falloc", BUILTIN_FS_ALLOCBLOCK, CMD_FS_ALLOCBLOCK, CMD_GROUP_FS },
#endif
// File commands.
#if (defined(BUILTIN_FS_CHANGEATTRIB) && BUILTIN_FS_CHANGEATTRIB == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fattr", BUILTIN_FS_CHANGEATTRIB, CMD_FS_CHANGEATTRIB, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_CHANGETIME) && BUILTIN_FS_CHANGETIME == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "ftime", BUILTIN_FS_CHANGETIME, CMD_FS_CHANGETIME, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_RENAME) && BUILTIN_FS_RENAME == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "frename", BUILTIN_FS_RENAME, CMD_FS_RENAME, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_DELETE) && BUILTIN_FS_DELETE == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fdel", BUILTIN_FS_DELETE, CMD_FS_DELETE, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_CREATEDIR) && BUILTIN_FS_CREATEDIR == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fmkdir", BUILTIN_FS_CREATEDIR, CMD_FS_CREATEDIR, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_STATUS) && BUILTIN_FS_STATUS == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fstat", BUILTIN_FS_STATUS, CMD_FS_STATUS, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_DIRLIST) && BUILTIN_FS_DIRLIST == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fdir", BUILTIN_FS_DIRLIST, CMD_FS_DIRLIST, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_CAT) && BUILTIN_FS_CAT == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fcat", BUILTIN_FS_CAT, CMD_FS_CAT, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_COPY) && BUILTIN_FS_COPY == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fcp", BUILTIN_FS_COPY, CMD_FS_COPY, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_CONCAT) && BUILTIN_FS_CONCAT == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fconcat", BUILTIN_FS_CONCAT, CMD_FS_CONCAT, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_XTRACT) && BUILTIN_FS_XTRACT == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fxtract", BUILTIN_FS_XTRACT, CMD_FS_XTRACT, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_LOAD) && BUILTIN_FS_LOAD == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fload", BUILTIN_FS_LOAD, CMD_FS_LOAD, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_EXEC) && BUILTIN_FS_EXEC == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fexec", BUILTIN_FS_EXEC, CMD_FS_EXEC, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_SAVE) && BUILTIN_FS_SAVE == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fsave", BUILTIN_FS_SAVE, CMD_FS_SAVE, CMD_GROUP_FS },
#endif
#if (defined(BUILTIN_FS_DUMP) && BUILTIN_FS_DUMP == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fdump", BUILTIN_FS_DUMP, CMD_FS_DUMP, CMD_GROUP_FS },
#endif
#if FF_FS_RPATH
#if (defined(BUILTIN_FS_CHANGEDIR) && BUILTIN_FS_CHANGEDIR == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fcd", BUILTIN_FS_CHANGEDIR, CMD_FS_CHANGEDIR, CMD_GROUP_FS },
#endif
#if FF_VOLUMES >= 2
#if (defined(BUILTIN_FS_CHANGEDRIVE) && BUILTIN_FS_CHANGEDRIVE == 1)|| (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fdrive", BUILTIN_FS_CHANGEDRIVE, CMD_FS_CHANGEDRIVE, CMD_GROUP_FS },
#endif
#endif
#if FF_FS_RPATH >= 2
#if (defined(BUILTIN_FS_SHOWDIR) && BUILTIN_FS_SHOWDIR == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fshowdir", BUILTIN_FS_SHOWDIR, CMD_FS_SHOWDIR, CMD_GROUP_FS },
#endif
#endif
#endif
#if FF_USE_LABEL
#if (defined(BUILTIN_FS_SETLABEL) && BUILTIN_FS_SETLABEL == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "flabel", BUILTIN_FS_SETLABEL, CMD_FS_SETLABEL, CMD_GROUP_FS },
#endif
#endif
#if FF_USE_MKFS
#if (defined(BUILTIN_FS_CREATEFS) && BUILTIN_FS_CREATEFS == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "fmkfs", BUILTIN_FS_CREATEFS, CMD_FS_CREATEFS, CMD_GROUP_FS },
#endif
#endif
#endif
// Memory commands.
#if (defined(BUILTIN_MEM_CLEAR) && BUILTIN_MEM_CLEAR == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mclear", BUILTIN_MEM_CLEAR, CMD_MEM_CLEAR, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_COPY) && BUILTIN_MEM_COPY == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mcopy", BUILTIN_MEM_COPY, CMD_MEM_COPY, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_DIFF) && BUILTIN_MEM_DIFF == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mdiff", BUILTIN_MEM_DIFF, CMD_MEM_DIFF, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_DUMP) && BUILTIN_MEM_DUMP == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mdump", BUILTIN_MEM_DUMP, CMD_MEM_DUMP, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_PERF) && BUILTIN_MEM_PERF == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mperf", BUILTIN_MEM_PERF, CMD_MEM_PERF, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_SRCH) && BUILTIN_MEM_SRCH == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "msrch", BUILTIN_MEM_SRCH, CMD_MEM_SRCH, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_TEST) && BUILTIN_MEM_TEST == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mtest", BUILTIN_MEM_TEST, CMD_MEM_TEST, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_EDIT_BYTES) && BUILTIN_MEM_EDIT_BYTES == 1)|| (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "meb", BUILTIN_MEM_EDIT_BYTES, CMD_MEM_EDIT_BYTES, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_EDIT_HWORD) && BUILTIN_MEM_EDIT_HWORD == 1)|| (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "meh", BUILTIN_MEM_EDIT_HWORD, CMD_MEM_EDIT_HWORD, CMD_GROUP_MEM },
#endif
#if (defined(BUILTIN_MEM_EDIT_WORD) && BUILTIN_MEM_EDIT_WORD == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "mew", BUILTIN_MEM_EDIT_WORD, CMD_MEM_EDIT_WORD, CMD_GROUP_MEM },
#endif
// Hardware commands.
{ "hid", BUILTIN_DEFAULT, CMD_HW_INTR_DISABLE, CMD_GROUP_HW },
{ "hie", BUILTIN_DEFAULT, CMD_HW_INTR_ENABLE, CMD_GROUP_HW },
#if (defined(BUILTIN_HW_SHOW_REGISTER) && BUILTIN_HW_SHOW_REGISTER == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "hr", BUILTIN_HW_SHOW_REGISTER, CMD_HW_SHOW_REGISTER, CMD_GROUP_HW },
#endif
#if (defined(BUILTIN_HW_TEST_TIMERS) && BUILTIN_HW_TEST_TIMERS == 1)|| (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "ht", BUILTIN_HW_TEST_TIMERS, CMD_HW_TEST_TIMERS, CMD_GROUP_HW },
#endif
#if (defined(BUILTIN_HW_TCPU) && BUILTIN_HW_TCPU == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "tcpu", BUILTIN_HW_TCPU, CMD_HW_TCPU, CMD_GROUP_HW },
#endif
{ "hfd", BUILTIN_DEFAULT, CMD_HW_FIFO_DISABLE, CMD_GROUP_HW },
{ "hfe", BUILTIN_DEFAULT, CMD_HW_FIFO_ENABLE, CMD_GROUP_HW },
// Test suite commands.
#if (defined(BUILTIN_TST_DHRYSTONE) && BUILTIN_TST_DHRYSTONE == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "dhry", BUILTIN_TST_DHRYSTONE, CMD_TEST_DHRYSTONE, CMD_GROUP_TEST },
#endif
#if (defined(BUILTIN_TST_COREMARK) && BUILTIN_TST_COREMARK == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "coremark", BUILTIN_TST_COREMARK, CMD_TEST_COREMARK, CMD_GROUP_TEST },
#endif
// Execution commands.
{ "call", BUILTIN_DEFAULT, CMD_CALL, CMD_GROUP_EXEC },
{ "jmp", BUILTIN_DEFAULT, CMD_EXECUTE, CMD_GROUP_EXEC },
// Miscellaneous commands.
{ "restart", BUILTIN_DEFAULT, CMD_MISC_RESTART_APP, CMD_GROUP_MISC },
{ "reset", BUILTIN_DEFAULT, CMD_MISC_REBOOT, CMD_GROUP_MISC },
#if defined(BUILTIN_MISC_HELP) && BUILTIN_MISC_HELP == 1
{ "help", BUILTIN_MISC_HELP, CMD_MISC_HELP, CMD_GROUP_MISC },
#endif
{ "info", BUILTIN_DEFAULT, CMD_MISC_INFO, CMD_GROUP_MISC },
#if (defined(BUILTIN_MISC_SETTIME) && BUILTIN_MISC_SETTIME == 1) || (defined(BUILTIN_MISC_HELP) == 1 && BUILTIN_MISC_HELP == 1)
{ "time", BUILTIN_MISC_SETTIME, CMD_MISC_SETTIME, CMD_GROUP_MISC },
#endif
{ "test", BUILTIN_DEFAULT, CMD_MISC_TEST, CMD_GROUP_MISC },
// Applications - most are not built in so dont need to be in this table or just placed here commented out for reference.
{ "tbasic", BUILTIN_DEFAULT, CMD_APP_TBASIC, CMD_GROUP_APP },
{ "mbasic", BUILTIN_DEFAULT, CMD_APP_MBASIC, CMD_GROUP_APP },
{ "kilo", BUILTIN_DEFAULT, CMD_APP_KILO, CMD_GROUP_APP },
{ "ed", BUILTIN_DEFAULT, CMD_APP_ED, CMD_GROUP_APP },
};
#endif
// Table of text to describe a command and its associated parameters. This table maps to the cmdTable with the Command as the key.
//
#if (defined(BUILTIN_MISC_HELP) && BUILTIN_MISC_HELP == 1)
static t_helpstruct helpTable[] = {
#if defined(__SD_CARD__)
// Disk level commands.
{ CMD_DISK_DUMP, "[<pd#> <sect>]", "Dump a sector" },
{ CMD_DISK_INIT, "<pd#> [<card type>]", "Initialize disk" },
{ CMD_DISK_STATUS, "<pd#>", "Show disk status" },
{ CMD_DISK_IOCTL_SYNC, "<pd#>", "ioctl(CTRL_SYNC)" },
// Disk buffer level commands.
{ CMD_BUFFER_DUMP, "<ofs>", "Dump buffer" },
{ CMD_BUFFER_EDIT, "<ofs> [<data>] ...", "Edit buffer" },
{ CMD_BUFFER_READ, "<pd#> <sect> [<num>]", "Read into buffer" },
{ CMD_BUFFER_WRITE, "<pd#> <sect> [<num>]", "Write buffer to disk" },
{ CMD_BUFFER_FILL, "<val>", "Fill buffer" },
{ CMD_BUFFER_LEN, "<len>", "Set read/write length for fr/fw command" },
// Filesystem level commands.
// File contents manipulation commands.
{ CMD_FS_INIT, "<ld#> [<mount>]", "Force init the volume" },
{ CMD_FS_OPEN, "<mode> <file>", "Open a file" },
{ CMD_FS_CLOSE, "", "Close the file" },
{ CMD_FS_SEEK, "<ofs>", "Move fp in normal seek" },
{ CMD_FS_READ, "<len>", "Read part of file into buffer" },
{ CMD_FS_INSPECT, "<len>", "Read part of file and examine" },
{ CMD_FS_WRITE, "<len> <val>", "Write part of buffer into file" },
{ CMD_FS_TRUNC, "", "Truncate the file at current fp" },
{ CMD_FS_ALLOCBLOCK, "<fsz> <opt>", "Allocate ctg blks to file" },
// File commands.
{ CMD_FS_CHANGEATTRIB, "<atrr> <mask> <name>", "Change object attribute" },
{ CMD_FS_CHANGETIME, "<y> <m> <d> <h> <M> <s> <fn>", "Change object timestamp" },
{ CMD_FS_RENAME, "<org name> <new name>", "Rename an object" },
{ CMD_FS_DELETE, "<obj name>", "Delete an object" },
{ CMD_FS_CREATEDIR, "<dir name>", "Create a directory" },
{ CMD_FS_STATUS, "[<path>]", "Show volume status" },
{ CMD_FS_DIRLIST, "[<path>]", "Show a directory" },
{ CMD_FS_CAT, "<name>", "Output file contents" },
{ CMD_FS_COPY, "<src file> <dst file>", "Copy a file" },
{ CMD_FS_CONCAT, "<src fn1> <src fn2> <dst fn>", "Concatenate 2 files" },
{ CMD_FS_XTRACT, "<src> <dst> <start pos> <len>", "Extract a portion of file" },
{ CMD_FS_LOAD, "<name> [<addr>]", "Load a file into memory" },
{ CMD_FS_EXEC, "<name> <ldAddr> <xAddr> <mode>", "Load and execute file" },
{ CMD_FS_SAVE, "<name> <addr> <len>", "Save memory range to a file" },
{ CMD_FS_DUMP, "<name> [<width>]", "Dump a file contents as hex" },
#if FF_FS_RPATH
{ CMD_FS_CHANGEDIR, "<path>", "Change current directory" },
#if FF_VOLUMES >= 2
{ CMD_FS_CHANGEDRIVE, "<path>", "Change current drive" },
#endif
#if FF_FS_RPATH >= 2
{ CMD_FS_SHOWDIR, "", "Show current directory" },
#endif
#endif
#if FF_USE_LABEL
{ CMD_FS_SETLABEL, "<label>", "Set volume label" },
#endif
#if FF_USE_MKFS
{ CMD_FS_CREATEFS, "<ld#> <type> <au>", "Create FAT volume" },
#endif
#endif
// Memory commands.
{ CMD_MEM_CLEAR, "<start> <end> [<word>]", "Clear memory" },
{ CMD_MEM_COPY, "<start> <end> <dst addr>", "Copy memory" },
{ CMD_MEM_DIFF, "<start> <end> <cmp addr>", "Compare memory" },
{ CMD_MEM_DUMP, "[<start> [<end>] [<size>]]", "Dump memory" },
{ CMD_MEM_EDIT_BYTES, "<addr> <byte> [...]", "Edit memory (Bytes)" },
{ CMD_MEM_EDIT_HWORD, "<addr> <h-word> [...]", "Edit memory (H-Word)" },
{ CMD_MEM_EDIT_WORD, "<addr> <word> [...]", "Edit memory (Word)" },
{ CMD_MEM_PERF, "<start> <end> [<width>] [<xfersz>]", "Test performance" },
{ CMD_MEM_SRCH, "<start> <end> <value>", "Search memory for value" },
{ CMD_MEM_TEST, "[<start> [<end>] [iter] [tests]]", "Test memory" },
// Hardware commands.
{ CMD_HW_INTR_DISABLE, "", "Disable Interrupts" },
{ CMD_HW_INTR_ENABLE, "", "Enable Interrupts" },
{ CMD_HW_SHOW_REGISTER, "", "Display Register Information" },
{ CMD_HW_TEST_TIMERS, "", "Test uS Timer" },
{ CMD_HW_FIFO_DISABLE, "", "Disable UART FIFO" },
{ CMD_HW_FIFO_ENABLE, "", "Enable UART FIFO" },
{ CMD_HW_TCPU, "", "TranZPUter test progra" },
// Test suite commands.
{ CMD_TEST_DHRYSTONE, "", "Dhrystone Test v2.1" },
{ CMD_TEST_COREMARK, "", "CoreMark Test v1.0" },
// Execution commands.
{ CMD_CALL, "<addr>", "Call function @ <addr>" },
{ CMD_EXECUTE, "<addr>", "Execute code @ <addr>" },
// Miscellaneous commands.
{ CMD_MISC_RESTART_APP, "", "Restart application" },
{ CMD_MISC_REBOOT, "", "Reset system" },
{ CMD_MISC_HELP, "[<cmd %>|<group %>]", "Show this screen" },
{ CMD_MISC_INFO, "", "Config info" },
{ CMD_MISC_SETTIME, "[<y> <m> <d> <h> <M> <s>]", "Set/Show current time" },
{ CMD_MISC_TEST, "", "Test Screen" },
// Miscellaneous commands.
{ CMD_APP_TBASIC, "", "Tiny Basic" },
{ CMD_APP_MBASIC, "[<file]>", "Mini Basic" },
{ CMD_APP_KILO, "<file>", "VT100 editor" },
{ CMD_APP_ED, "<file>", "Minimal VT100 editor" },
};
#endif
#define NGRPKEYS (sizeof(groupTable)/sizeof(t_groupstruct))
#define NCMDKEYS (sizeof(cmdTable)/sizeof(t_cmdstruct))
#define NHELPKEYS (sizeof(helpTable)/sizeof(t_helpstruct))
#if defined(__K64F__) && defined(__APP__)
uint32_t milliseconds(void)
{
// Reading a volatile variable to another volatile
// seems redundant, but isn't for some cases.
// Eventually this should probably be replaced by a
// proper memory barrier or other technique. Please
// do not remove this "redundant" code without
// carefully verifying the case mentioned here:
//
// https://forum.pjrc.com/threads/17469-millis%28%29-on-teensy-3?p=104924&viewfull=1#post104924
//
volatile uint32_t ret = *G->millis; // single aligned 32 bit is atomic
return ret;
}
#endif
// Prototypes
#if defined(__SD_CARD__)
FRESULT scan_files(char *);
void printFSCode(FRESULT);
void printBytesPerSec(uint32_t, uint32_t, const char *);
FRESULT printDirectoryListing(char *);
FRESULT printFatFSStatus(char *);
FRESULT fileConcatenate(char *, char *, char *);
FRESULT fileCopy(char *, char *);
FRESULT fileXtract(char *, char *, uint32_t, uint32_t);
FRESULT fileCat(char *);
FRESULT fileLoad(char *, uint32_t, uint8_t);
FRESULT fileSave(char *, uint32_t, uint32_t);
FRESULT fileDump(char *, uint32_t);
uint32_t fileExec(char *, uint32_t, uint32_t, uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
FRESULT fileBlockRead(FIL *, uint32_t);
FRESULT fileBlockWrite(FIL *fp, uint32_t len);
FRESULT fileBlockDump(uint32_t, uint32_t);
FRESULT fileSetBlockLen(uint32_t);
#endif
#if defined(BUILTIN_MISC_HELP) && BUILTIN_MISC_HELP == 1
void displayHelp(char *);
#endif
#if defined(__ZOS__) || defined(__ZPUTA__) || (defined(BUILTIN_MISC_HELP) && BUILTIN_MISC_HELP == 1)
void printVersion(uint8_t);
#endif
#if (defined(BUILTIN_FS_DUMP) && BUILTIN_FS_DUMP == 1) || (defined(BUILTIN_FS_INSPECT) && BUILTIN_FS_INSPECT == 1) || (defined(BUILTIN_DISK_DUMP) && BUILTIN_DISK_DUMP == 1) || (defined(BUILTIN_DISK_STATUS) && BUILTIN_DISK_STATUS == 1) || (defined(BUILTIN_BUFFER_DUMP) && BUILTIN_BUFFER_DUMP == 1) || (defined(BUILTIN_MEM_DUMP) && BUILTIN_MEM_DUMP == 1)
int memoryDump(uint32_t, uint32_t, uint32_t, uint32_t, uint8_t);
#endif
#ifdef __cplusplus
}
#endif
#endif

60
include/uart.h Normal file
View File

@@ -0,0 +1,60 @@
#ifndef UART_H
#define UART_H
/* Hardware registers for a supporting UART to the ZPUFlex project. */
#ifdef __cplusplus
extern "C" {
#endif
// Method to direct output to stdout or stddebug.
void set_serial_output(uint8_t);
int putchar(int);
void _putchar(unsigned char);
int dbgputchar(int);
void _dbgputchar(unsigned char);
int puts(const char *);
char getserial();
char getdbgserial();
int8_t getserial_nonblocking();
int8_t getdbgserial_nonblocking();
// Macros to put breadcrumbs out to the screen, for reference and debugging purposes.
#define breadcrumb(x) UART_DATA(UART0)=x;
// Debug only macros which dont generate code when debugging disabled.
#ifdef DEBUG
// Macro to print to the debug channel.
//
#define debugf(a, ...) ({\
set_serial_output(1);\
printf(a, ##__VA_ARGS__);\
set_serial_output(0);\
})
#define dbg_putchar(a) ({\
dbgputchar(a);\
})
#define dbg_puts(a) ({\
set_serial_output(1);\
puts(a);\
set_serial_output(0);\
})
#define dbg_breadcrumb(x) UART_DATA(UART1)=x;
#else
#define dbg_putchar(a)
#define dbg_puts(a)
#define debugf(a, ...)
#define dbg_breadcrumb(x)
#endif
#ifdef __cplusplus
}
#endif
#endif // UART_H

102
include/utils.h Normal file
View File

@@ -0,0 +1,102 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: utils.h
// Created: January 2019
// Author(s): Philip Smart
// Description: ZPU boottime simple utilities.
// A set of utilities to be used in the IOCP (or other minimalist application) which
// assume a minimum compile environment (ie. no printf)such that the smallest code
// size is created.
//
// Credits:
// Copyright: (c) 2019 Philip Smart <philip.smart@net2net.org>
//
// History: January 2019 - Initial script written.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef UTILS_H
#define UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
// Real time clock structure, maps to the underlying hardware.
typedef struct {
uint16_t year; /* 2000..2099 */
uint8_t month; /* 1..12 */
uint8_t day; /* 1.. 31 */
uint8_t hour; /* 0..23 */
uint8_t min; /* 0..59 */
uint8_t sec; /* 0..59 */
uint16_t msec; /* 0..999 */
uint16_t usec; /* 0..999 */
} RTC;
// Prototypes
void printnibble(uint8_t c);
void printhexbyte(uint8_t c);
void printhex(uint32_t c);
void printdhex(uint32_t c);
unsigned int crc32_init(void);
unsigned int crc32_addword(unsigned int, unsigned int);
unsigned int get_dword(void);
char *getStrParam(char **);
uint32_t getUintParam(char **ptr);
uint8_t rtcSet(RTC *);
void rtcGet(RTC *);
// Debug only macros which dont generate code when debugging disabled.
#ifdef DEBUG
// Macro to print out hex data to the debug channel.
//
#define dbg_printnibble(a) ({\
set_serial_output(1);\
printnibble(a);\
set_serial_output(0);\
})
#define dbg_printhexbyte(a) ({\
set_serial_output(1);\
printhexbyte(a);\
set_serial_output(0);\
})
#define dbg_printhex(a) ({\
set_serial_output(1);\
printhex(a);\
set_serial_output(0);\
})
#define dbg_printdhex(a) ({\
set_serial_output(1);\
printdhex(a);\
set_serial_output(0);\
})
#else
#define dbg_printnibble(a)
#define dbg_printhexbyte(a)
#define dbg_printhex(a)
#define dbg_printdhex(a)
#endif
#ifdef __cplusplus
}
#endif
#endif

21
include/vga.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef VGA_H
#define VGA_H
/* Hardware registers for the ZPU MiniSOC VGA demo project.
Based on the similar TG68MiniSOC project, but with
changes to suit the ZPU's archicture */
#define VGABASE 0xFFFFFE00
#define FRAMEBUFFERPTR 0
#define SP0PTR 0x10
#define SP0XPOS 0x14
#define SP0YPOS 0x18
#define HW_VGA(x) *(volatile unsigned long *)(VGABASE+x)
#define VGA_INT_VBLANK 1 /* Not currently implemented */
#endif

50
include/xprintf.h Normal file
View File

@@ -0,0 +1,50 @@
/*------------------------------------------------------------------------*/
/* Universal string handler for user console interface (C)ChaN, 2012 */
/*------------------------------------------------------------------------*/
#ifndef _STRFUNC
#define _STRFUNC
#ifdef __cplusplus
extern "C" {
#endif
#define _USE_XFUNC_OUT 1 /* 1: Use output functions */
#define _CR_CRLF 1 /* 1: Convert \n ==> \r\n in the output char */
#define _USE_LONGLONG 0 /* 1: Enable long long integer in type "ll". */
#define _LONGLONG_t long long /* Platform dependent long long integer type */
#define _USE_XFUNC_IN 1 /* 1: Use input function */
#define _LINE_ECHO 1 /* 1: Echo back input chars in xgets function */
//#if _USE_XFUNC_OUT
#define xdev_out(func) xfunc_out = (void(*)(unsigned char))(func)
extern void (*xfunc_out)(unsigned char);
void xputc (char c);
void xfputc (void (*func)(unsigned char), char c);
void xputs (const char* str);
void xfputs (void (*func)(unsigned char), const char* str);
void xprintf (const char* fmt, ...);
void xsprintf (char* buff, const char* fmt, ...);
void xfprintf (void (*func)(unsigned char), const char* fmt, ...);
void put_dump (const void* buff, unsigned long addr, int len, int width);
#define DW_CHAR sizeof(char)
#define DW_SHORT sizeof(short)
#define DW_LONG sizeof(long)
//#endif
//#if _USE_XFUNC_IN
#define xdev_in(func) xfunc_in = (unsigned char(*)(void))(func)
extern unsigned char (*xfunc_in)(void);
int xgets (char* buff, int len);
int xfgets (unsigned char (*func)(void), char* buff, int len);
int xatoi (char** str, long* res);
int uxatoi(char **, uint32_t *);
//#endif
#ifdef __cplusplus
}
#endif
#endif

23
include/zpu-types.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef __ZPU_TYPES_H__
#define __ZPU_TYPES_H__
#include <sys/types.h>
#define true 1
#define false 0
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned long uintptr_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef signed long intptr_t;
typedef uint8_t byte;
#endif

518
include/zpu_soc.h Normal file
View File

@@ -0,0 +1,518 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: zpu_soc.h
// Created: January 2019
// Author(s): Philip Smart
// Description: ZPU System On a Chip utilities.
// A set of utilities specific to interaction with the ZPU SoC hardware.
//
// Credits:
// Copyright: (c) 2019 Philip Smart <philip.smart@net2net.org>
//
// History: January 2019 - Initial script written.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __ZPUSOC_H__
#define __ZPUSOC_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef ASSEMBLY
typedef volatile unsigned int* register_t;
#endif
// Macro to omit code if deemed optional and the compile time flag MINIMUM_FUNCTIONALITY is defined.
#ifdef MINIMUM_FUNCTIONALITY
#define OPTIONAL(a)
#else
#define OPTIONAL(a) a
#endif
// System settings.
#define CLK_FREQ 100000000UL // Default frequency used to configure SoC if not present.
// Memory sizes and devices implemented - these can be ignored if the SoC Configuration register is implemented as this provides the exact build configuration.
#define ZPU_ID 0x0000
#define WB_IMPL 0
#define WB_SDRAM_IMPL 0
#define WB_I2C_IMPL 0
#define BRAM_IMPL 1
#define RAM_IMPL 1
#define INSN_BRAM_IMPL 1
#define SDRAM_IMPL 1
#define IOCTL_IMPL 1
#define PS2_IMPL 1
#define SPI_IMPL 1
#define SD_IMPL 1
#define SD_DEVICE_CNT 1
#define INTRCTL_IMPL 1
#define INTRCTL_CHANNELS 16
#define TIMER1_IMPL 1
#define TIMER1_TIMERS_CNT 1
#define SDRAM_ADDR 0x00010000
#define SDRAM_SIZE 0x00810000
#define WB_SDRAM_ADDR 0x01000000
#define WB_SDRAM_SIZE 0x017FFFFF
#define BRAM_ADDR 0x00000000
#define BRAM_SIZE 0x00007FFF
#define INSN_BRAM_ADDR 0x00000000
#define INSN_BRAM_SIZE 0x00007FFF
#define RAM_ADDR 0x00010000
#define RAM_SIZE 0x00007FFF
#define STACK_BRAM_ADDR 0x00007800
#define STACK_BRAM_SIZE 0x000007FF
#define CPU_RESET_ADDR 0x00000000
#define CPU_MEM_START 0x00000000
#define BRAM_APP_START_ADDR 0x2000
//
#define SPIISBLOCKING 1
#define BIT(x) (1<<(x))
#define MEMIO32 *(volatile unsigned int *)
// ZPU Id definitions.
//
#define ZPU_ID_SMALL 0x01
#define ZPU_ID_MEDIUM 0x02
#define ZPU_ID_FLEX 0x03
#define ZPU_ID_EVO 0x04
#define ZPU_ID_EVO_MINIMAL 0x05
// IO base address.
//#define IO_ADDR_PERIPHERALS 0xFFFFF000
#define IO_ADDR_PERIPHERALS 0x0F00000
#define IO_ADDR_WB_PERIPHERALS 0x1F00000
// Baud rate computation for UART
#define BAUDRATEGEN(b,x,y) (((UART_SYSCLK(b)/(x))) << 16) | (((UART_SYSCLK(b)/(y))))
// ----------------------------------
// CPU Bus I/O Peripheral definition.
// ----------------------------------
// TCPU Processor Controller.
//
#define TCPU_BASE IO_ADDR_PERIPHERALS + 0x700
#define ADDR_REGISTER 0x00
#define DATA_REGISTER 0x04
#define TCPU_ADDR (MEMIO32 (TCPU_BASE + ADDR_REGISTER))
#define TCPU_DATA (MEMIO32 (TCPU_BASE + DATA_REGISTER))
// IO Processor Controller.
#define IOCTL_BASE IO_ADDR_PERIPHERALS + 0x800
#define CMDADDR_REGISTER 0x00
#define DATA_REGISTER 0x04
#define CHRCOLS_REGISTER 0x08
#define CGADDR_REGISTER 0x0C
#define IOCTL_CMDADDR (MEMIO32 (IOCTL_BASE + CMDADDR_REGISTER))
#define IOCTL_DOUT (MEMIO32 (IOCTL_BASE + DATA_REGISTER))
#define IOCTL_DIN (MEMIO32 (IOCTL_BASE + DATA_REGISTER))
#define IOCTL_CHRCOLS (MEMIO32 (IOCTL_BASE + CHRCOLS_REGISTER))
#define IOCTL_CGADDR (MEMIO32 (IOCTL_BASE + CGADDR_REGISTER))
// SD Card Controller.
#define SD_BASE IO_ADDR_PERIPHERALS + 0x900
#define SD0 0
#define SD1 1
#define SD2 2
#define SD3 3
#define SD_SPACING 0x10
#define SD_ADDR_REGISTER 0x00
#define SD_DATA_REGISTER 0x04
#define SD_STATUS_REGISTER 0x0c
#define SD_CMD_REGISTER 0x0c
#define SD_CMD_RESET 0x00000001
#define SD_CMD_WRITE 0x00000002
#define SD_CMD_READ 0x00000004
#define SD_CMD_CARDTYPE 0x00000008
#define SD_CMD_CARDTYPE_SD 0x00000008
#define SD_CMD_CARDTYPE_SDHC 0x00000088
#define SD_STATUS_CONTINUE 0x00000001
#define SD_STATUS_BUSY 0x00000002
#define SD_STATUS_HNDSHK_OUT 0x00000004
#define SD_STATUS_HNDSHK_IN 0x00000008
#define SD_STATUS_DATA_REQ 0x00000010
#define SD_STATUS_DATA_VALID 0x00000020
#define SD_STATUS_OVERRUN 0x00000040
#define SD_STATUS_IDLESTATE 0x00010000
#define SD_STATUS_ERASERESET 0x00020000
#define SD_STATUS_ILLEGALCMD 0x00040000
#define SD_STATUS_CRCERROR 0x00080000
#define SD_STATUS_ERASESEQ 0x00100000
#define SD_STATUS_ADDRERR 0x00200000
#define SD_STATUS_PARAMERR 0x00400000
#define SD_STATUS_ERROR 0xFFFF0000
#define SD(x, y) (MEMIO32 (SD_BASE+(x*SD_SPACING) + y))
#define SD_ADDR(x) (MEMIO32 (SD_BASE+(x*SD_SPACING) + SD_ADDR_REGISTER))
#define SD_DATA(x) (MEMIO32 (SD_BASE+(x*SD_SPACING) + SD_DATA_REGISTER))
#define SD_CMD(x) (MEMIO32 (SD_BASE+(x*SD_SPACING) + SD_CMD_REGISTER))
#define SD_STATUS(x) (MEMIO32 (SD_BASE+(x*SD_SPACING) + SD_STATUS_REGISTER))
#define IS_SD_BUSY(x) ((MEMIO32 (SD_BASE+(x*SD_SPACING) + SD_STATUS_REGISTER)) & SD_STATUS_BUSY) >> 1
#define IS_SD_ERROR(x) ((MEMIO32 (SD_BASE+(x*SD_SPACING) + SD_STATUS_REGISTER)) & SD_STATUS_ERROR) >> 16
// UART definitions.
#define UART_BASE IO_ADDR_PERIPHERALS + 0xA00
#define UART0 0
#define UART1 1
#define UART_SPACING 0x10 // Address spacing between UART modules.
// UART Registers and macros to read/write them.
#define UART_DATA_REGISTER 0x00
#define UART_CTRL_REGISTER 0x04
#define UART_STATUS_REGISTER 0x04
#define UART_FIFO_REGISTER 0x08
#define UART_BAUDRATE_REGISTER 0x0C
#define UART_SYSCLK_REGISTER 0x0C
#define UART_DATA(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_DATA_REGISTER))
#define UART_STATUS(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_STATUS_REGISTER))
#define UART_FIFO_STATUS(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_FIFO_REGISTER))
#define UART_CTRL(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_CTRL_REGISTER))
#define UART_BRGEN(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_BAUDRATE_REGISTER))
#define UART_SYSCLK(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_SYSCLK_REGISTER))
// UART Status flags.
#define UART_RX_FIFO_EMPTY 0x00000001
#define UART_RX_FIFO_FULL 0x00000002
#define UART_RX_DATA_READY 0x00000004
#define UART_RX_OVERRUN 0x00000008
#define UART_RX_INTERRUPT 0x00000010
#define UART_RX_FIFO_ENABLED 0x00000020
#define UART_RX_ENABLED 0x00000040
#define UART_RX_IN_RESET 0x00000080
#define UART_TX_FIFO_EMPTY 0x00010000
#define UART_TX_FIFO_FULL 0x00020000
#define UART_TX_BUSY 0x00040000
#define UART_TX_DATA_LOADED 0x00080000
#define UART_TX_OVERRUN 0x00100000
#define UART_TX_INTERRUPT 0x00200000
#define UART_TX_FIFO_ENABLED 0x00400000
#define UART_TX_ENABLED 0x00800000
#define UART_TX_IN_RESET 0x01000000
// UART Control flags.
#define UART_RX_ENABLE 0x00000001
#define UART_RX_FIFO_ENABLE 0x00000002
#define UART_RX_RESET 0x00000004
#define UART_TX_ENABLE 0x00010000
#define UART_TX_FIFO_ENABLE 0x00020000
#define UART_TX_RESET 0x00040000
// UART macros to test 32bit status register value.
#define UART_IS_TX_FIFO_ENABLED(x) ((x & UART_TX_FIFO_ENABLED) != 0)
#define UART_IS_TX_FIFO_DISABLED(x) ((x & UART_TX_FIFO_ENABLED) == 0)
#define UART_IS_TX_FIFO_FULL(x) ((x & UART_TX_FIFO_FULL) != 0)
#define UART_IS_TX_BUSY(x) ((x & UART_TX_BUSY) != 0)
#define UART_IS_TX_DATA_LOADED(x) ((x & UART_TX_DATA_LOADED) != 0)
#define UART_IS_RX_FIFO_ENABLED(x) ((x & UART_RX_FIFO_ENABLED) != 0)
#define UART_IS_RX_FIFO_DISABLED(x) ((x & UART_RX_FIFO_ENABLED) == 0)
#define UART_IS_RX_FIFO_EMPTY(x) ((x & UART_RX_FIFO_EMPTY) != 0)
#define UART_IS_RX_DATA_READY(x) ((x & UART_RX_DATA_READY) != 0)
// UART macros to test for a specific flag.
#define UART_STATUS_RX_FIFO_EMPTY(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_FIFO_EMPTY
#define UART_STATUS_RX_FIFO_FULL(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_FIFO_FULL
#define UART_STATUS_RX_DATA_READY(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_DATA_READY
#define UART_STATUS_RX_OVERRUN(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_OVERRUN
#define UART_STATUS_RX_INTR(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_INTERRUPT
#define UART_STATUS_RX_FIFO_ENABLED(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_FIFO_ENABLED
#define UART_STATUS_RX_ENABLED(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_RX_ENABLED
#define UART_STATUS_RX_IN_RESET(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_RX_REGISTER)) & UART_IN_RESET
#define UART_STATUS_TX_FIFO_EMPTY(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_FIFO_EMPTY
#define UART_STATUS_TX_FIFO_FULL(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_FIFO_FULL
#define UART_STATUS_TX_BUSY(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_BUSY
#define UART_STATUS_TX_DATA_LOADED(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_DATA_LOADED
#define UART_STATUS_TX_OVERRUN(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_OVERRUN
#define UART_STATUS_TX_INTR(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_INTERRUPT
#define UART_STATUS_TX_FIFO_ENABLED(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_FIFO_ENABLED
#define UART_STATUS_TX_ENABLED(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_TX_ENABLED
#define UART_STATUS_TX_IN_RESET(x) (MEMIO32 (UART_BASE+(x*UART_SPACING)+UART_TX_REGISTER)) & UART_IN_RESET
// Interrupt Controller.
#define INTERRUPT_BASE IO_ADDR_PERIPHERALS + 0xB00
#define INTR0 0
#define INTERRUPT_SPACING 0x10
#define INTERRUPT_STATUS_REGISTER 0x0
#define INTERRUPT_CTRL_REGISTER 0x4
#define INTERRUPT(x,y) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING)+y))
#define INTERRUPT_STATUS(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING)+INTERRUPT_STATUS_REGISTER))
#define INTERRUPT_CTRL(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING)+INTERRUPT_CTRL_REGISTER))
// Interrupt bit locations.
#define INTR_TIMER 0x00000002
#define INTR_PS2 0x00000004
#define INTR_IOCTL_RD 0x00000008
#define INTR_IOCTL_WR 0x00000010
#define INTR_UART0_RX 0x00000020
#define INTR_UART0_TX 0x00000040
#define INTR_UART1_RX 0x00000080
#define INTR_UART1_TX 0x00000100
// Macros to test a specific interrupt, ignoring others.
#define INTR_TEST_TIMER(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_TIMER
#define INTR_TEST_PS2(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_PS2
#define INTR_TEST_IOCTL_RD(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_IOCTL_RD
#define INTR_TEST_IOCTL_WR(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_IOCTL_WR
#define INTR_TEST_UART0_RX(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_UART0_RX
#define INTR_TEST_UART0_TX(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_UART0_TX
#define INTR_TEST_UART1_RX(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_UART1_RX
#define INTR_TEST_UART1_TX(x) (MEMIO32 (INTERRUPT_BASE+(x*INTERRUPT_SPACING))) & INTR_UART1_TX
// Macros to test a variable for a specific interrupt.
#define INTR_IS_TIMER(x) (x) & INTR_TIMER
#define INTR_IS_PS2(x) (x) & INTR_PS2
#define INTR_IS_IOCTL_RD(x) (x) & INTR_IOCTL_RD
#define INTR_IS_IOCTL_WR(x) (x) & INTR_IOCTL_WR
#define INTR_IS_UART0_RX(x) (x) & INTR_UART0_RX
#define INTR_IS_UART0_TX(x) (x) & INTR_UART0_TX
#define INTR_IS_UART1_RX(x) (x) & INTR_UART1_RX
#define INTR_IS_UART1_TX(x) (x) & INTR_UART1_TX
// Timer.
// TIMER0 -> An RTC down to microsecond resolution and 3 delay counters, 1x uS and 1x mS down counters and 1x mS up counter.
// TIMER1-> are standard timers.
#define TIMER_BASE IO_ADDR_PERIPHERALS + 0xC00
#define TIMER_SPACING 0x40
#define TIMER0 0
#define TIMER1 1
#define TIMER_ENABLE_REG 0x00
#define TIMER_INDEX_REG 0x04
#define TIMER_COUNTER_REG 0x08
#define TIMER_MICROSEC_DOWN_REG 0x00
#define TIMER_MILLISEC_DOWN_REG 0x04
#define TIMER_MILLISEC_UP_REG 0x08
#define TIMER_SECONDS_DOWN_REG 0x0C
#define RTC_CTRL_HALT 0x00000001
#define RTC_CONTROL_REG 0x1C
#define RTC_MICROSECONDS_REG 0x20
#define RTC_MILLISECONDS_REG 0x24
#define RTC_SECOND_REG 0x28
#define RTC_MINUTE_REG 0x2C
#define RTC_HOUR_REG 0x30
#define RTC_DAY_REG 0x34
#define RTC_MONTH_REG 0x38
#define RTC_YEAR_REG 0x3C
#define TIMER(x, y) (MEMIO32 (TIMER_BASE+(x*TIMER_SPACING) + y))
#define TIMER_ENABLE(x) (MEMIO32 (TIMER_BASE+(x*TIMER_SPACING) + TIMER_ENABLE_REG))
#define TIMER_INDEX(x) (MEMIO32 (TIMER_BASE+(x*TIMER_SPACING) + TIMER_INDEX_REG))
#define TIMER_COUNTER(x) (MEMIO32 (TIMER_BASE+(x*TIMER_SPACING) + TIMER_COUNTER_REG))
#define TIMER_MICROSECONDS_DOWN (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + TIMER_MICROSEC_DOWN_REG))
#define TIMER_MILLISECONDS_DOWN (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + TIMER_MILLISEC_DOWN_REG))
#define TIMER_MILLISECONDS_UP (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + TIMER_MILLISEC_UP_REG))
#define TIMER_SECONDS_DOWN (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + TIMER_SECONDS_DOWN_REG))
#define RTC_CONTROL (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_CONTROL_REG))
#define RTC_MICROSECONDS (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_MICROSECONDS_REG))
#define RTC_MILLISECONDS (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_MILLISECONDS_REG))
#define RTC_SECOND (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_SECOND_REG))
#define RTC_MINUTE (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_MINUTE_REG))
#define RTC_HOUR (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_HOUR_REG))
#define RTC_DAY (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_DAY_REG))
#define RTC_MONTH (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_MONTH_REG))
#define RTC_YEAR (MEMIO32 (TIMER_BASE+(TIMER0*TIMER_SPACING) + RTC_YEAR_REG))
// SPI Controller.
#define SPI_BASE IO_ADDR_PERIPHERALS + 0xD00
#define SPI0 0
#define SPI1 1
#define SPI2 2
#define SPI3 3
#define SPI_SPACING 0x10
#define CS_REGISTER 0x00
#define DATA_REGISTER 0x04
#define PUMP_REGISTER 0x08
#define SPI(x, y) (MEMIO32 (SPI_BASE+(x*SPI_SPACING) + y))
#define SPI_CS(x) (MEMIO32 (SPI_BASE+(x*SPI_SPACING) + CS_REGISTER)) /* CS bits are write-only, but bit 15 reads as the SPI busy signal */
#define SPI_DATA(x) (MEMIO32 (SPI_BASE+(x*SPI_SPACING) + DATA_REGISTER)) /* Blocks on both reads and writes, making BUSY signal redundant. */
#define SPI_PUMP(x) (MEMIO32 (SPI_BASE+(x*SPI_SPACING) + PUMP_REGISTER)) /* Push 16-bits through SPI in one instruction */
#define SPI_SET_CS(x,y) {while((SPI_CS(x)&(1<<SPI_BUSY))); SPI_CS(x)=(y);}
#define SPI_CS_SD 0
#define SPI_FAST 8
#define SPI_BUSY 15
// PS2
#define PS2_BASE IO_ADDR_PERIPHERALS + 0xE00
#define PS2_0 0
#define PS2_1 1
#define PS2_SPACING 0x10
#define PS2_KEYBOARD_REGISTER 0
#define PS2_MOUSE_REGISTER 0x4
#define PS2(x, y) (MEMIO32 (PS2_BASE+(x*0x10) + y))
#define PS2_KEYBOARD(x) (MEMIO32 (PS2_BASE+(x*0x10) + PS2_KEYBOARD_REGISTER))
#define PS2_MOUSE(x) (MEMIO32 (PS2_BASE+(x*0x10) + PS2_MOUSE_REGISTER))
#define BIT_PS2_RECV 11
#define BIT_PS2_CTS 10
// SoC Configuration registers.
#define SOCCFG_BASE IO_ADDR_PERIPHERALS + 0xF00
// Registers
#define SOCCFG_ZPU_ID 0x00 // ID of the instantiated ZPU
#define SOCCFG_SYSFREQ 0x04 // System Clock Frequency in MHz x 10 (ie. 100KHź)
#define SOCCFG_MEMFREQ 0x08 // Sysbus SDRAM Clock Frequency in MHz x 10 (ie. 100KHź)
#define SOCCFG_WBMEMFREQ 0x0c // Wishbone SDRAM Clock Frequency in MHz x 10 (ie. 100KHź)
#define SOCCFG_DEVIMPL 0x10 // Bit map of devices implemented in SOC.
#define SOCCFG_BRAMADDR 0x14 // Address of Block RAM.
#define SOCCFG_BRAMSIZE 0x18 // Size of Block RAM.
#define SOCCFG_RAMADDR 0x1c // Address of RAM (additional BRAM, DRAM etc).
#define SOCCFG_RAMSIZE 0x20 // Size of RAM.
#define SOCCFG_BRAMINSNADDR 0x24 // Address of dedicated instruction Block RAM.
#define SOCCFG_BRAMINSNSIZE 0x28 // Size of dedicated instruction Block RAM.
#define SOCCFG_SDRAMADDR 0x2c // Address of SDRAM.
#define SOCCFG_SDRAMSIZE 0x30 // Size of SDRAM.
#define SOCCFG_WBSDRAMADDR 0x34 // Address of Wishbone SDRAM.
#define SOCCFG_WBSDRAMSIZE 0x38 // Size of Wishbone SDRAM.
#define SOCCFG_CPURSTADDR 0x3c // Address CPU executes after a RESET.
#define SOCCFG_CPUMEMSTART 0x40 // Start address of Memory containing BIOS/Microcode for CPU.
#define SOCCFG_STACKSTART 0x44 // Start address of Memory for Stack use.
// Implementation bits.
#define IMPL_WB 0x00400000
#define IMPL_WB_SDRAM 0x00200000
#define IMPL_WB_I2C 0x00100000
#define IMPL_BRAM 0x00080000
#define IMPL_RAM 0x00040000
#define IMPL_INSN_BRAM 0x00020000
#define IMPL_SDRAM 0x00010000
#define IMPL_IOCTL 0x00008000
#define IMPL_PS2 0x00004000
#define IMPL_SPI 0x00002000
#define IMPL_SD 0x00001000
#define IMPL_SD_DEVICE_CNT 0x00000C00
#define IMPL_INTRCTL 0x00000200
#define IMPL_INTRCTL_CNT 0x000001F0
#define IMPL_TIMER1 0x00000008
#define IMPL_TIMER1_TIMER_CNT 0x00000007
#define IMPL_SOCCFG 0x0000000a
// Test macros
#define IS_IMPL_WB ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_WB) >> 22
#define IS_IMPL_WB_SDRAM ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_WB_SDRAM) >> 21
#define IS_IMPL_WB_I2C ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_WB_I2C) >> 20
#define IS_IMPL_BRAM ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_BRAM) >> 19
#define IS_IMPL_RAM ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_RAM) >> 18
#define IS_IMPL_INSN_BRAM ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_INSN_BRAM) >> 17
#define IS_IMPL_SDRAM ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_SDRAM) >> 16
#define IS_IMPL_IOCTL ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_IOCTL) >> 15
#define IS_IMPL_PS2 ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_PS2) >> 14
#define IS_IMPL_SPI ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_SPI) >> 13
#define IS_IMPL_SD ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_SD) >> 12
#define SOCCFG_SD_DEVICES ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_SD_DEVICE_CNT) >> 10
#define IS_IMPL_INTRCTL ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_INTRCTL) >> 9
#define SOCCFG_INTRCTL_CHANNELS ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_INTRCTL_CNT) >> 4
#define IS_IMPL_TIMER1 ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_TIMER1) >> 3
#define SOCCFG_TIMER1_TIMERS ((MEMIO32 (SOCCFG_BASE + SOCCFG_DEVIMPL)) & IMPL_TIMER1_TIMER_CNT)
#define IS_IMPL_SOCCFG (MEMIO32 (SOCCFG_BASE + SOCCFG_ZPU_ID)) >> 28 & IMPL_SOCCFG
#define SOCCFG(x) (MEMIO32 (SOCCFG_BASE + x))
// -------------------------------
// Wishbone Peripheral definition.
// -------------------------------
// I2C Master Controller.
#define I2C_BASE IO_ADDR_WB_PERIPHERALS + 0x000
#define I2C0 0
#define I2C1 1
#define I2C2 2
#define I2C3 3
#define I2C_SPACING 0x10
#define I2C_PRE_LOW_REGISTER 0x00 // Low byte clock prescaler register
#define I2C_PRE_HI_REGISTER 0x01 // High byte clock prescaler register
#define I2C_CTRL_REGISTER 0x02 // Control register
#define I2C_TX_REGISTER 0x03 // Transmit byte register
#define I2C_CMD_REGISTER 0x04 // Command register
#define I2C_RX_REGISTER 0x03 // Receive byte register
#define I2C_STATUS_REGISTER 0x04 // Status register
#define I2C(x, y) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + y))
#define I2C_PRE_LOW(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_PRE_LOW_REGISTER))
#define I2C_PRE_HI(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_PRE_HI_REGISTER))
#define I2C_CTRL(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_CTRL_REGISTER))
#define I2C_TX(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_TX_REGISTER))
#define I2C_CMD(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_CMD_REGISTER))
#define I2C_RX(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_RX_REGISTER))
#define I2C_STATUS(x) (MEMIO32 (I2C_BASE+(x*I2C_SPACING) + I2C_STATUS_REGISTER))
#define I2C_EN (1<<7) // Core enable bit:
// 1 - core is enabled
// 0 - core is disabled
#define OC_I2C_IEN (1<<6) // Interrupt enable bit
// 1 - Interrupt enabled
// 0 - Interrupt disabled
// Other bits in CR are reserved
#define I2C_STA (1<<7) // Generate (repeated) start condition
#define I2C_STO (1<<6) // Generate stop condition
#define I2C_RD (1<<5) // Read from slave
#define I2C_WR (1<<4) // Write to slave
#define I2C_ACK (1<<3) // Acknowledge from slave
// 1 - ACK
// 0 - NACK
#define I2C_IACK (1<<0) // Interrupt acknowledge
#define I2C_RXACK (1<<7) // ACK received from slave
// 1 - ACK
// 0 - NACK
#define I2C_BUSY (1<<6) // Busy bit
#define I2C_TIP (1<<1) // Transfer in progress
#define I2C_IF (1<<0) // Interrupt flag
#define I2C_IS_SET(reg,bitmask) ((reg)&(bitmask))
#define I2C_IS_CLEAR(reg,bitmask) (!(I2C_IS_SET(reg,bitmask)))
#define I2C_BITSET(reg,bitmask) ((reg)|(bitmask))
#define I2C_BITCLEAR(reg,bitmask) ((reg)|(~(bitmask)))
#define I2C_BITTOGGLE(reg,bitmask) ((reg)^(bitmask))
#define I2C_REGMOVE(reg,value) ((reg)=(value))
// State definitions.
#define INPUT 1
#define OUTPUT 0
#define HIGH 1
#define LOW 0
// Prototypes.
void setupSoCConfig(void);
void showSoCConfig(void);
void printZPUId(uint32_t);
// Configuration values.
typedef struct
{
uint32_t addrInsnBRAM;
uint32_t sizeInsnBRAM;
uint32_t addrBRAM;
uint32_t sizeBRAM;
uint32_t addrRAM;
uint32_t sizeRAM;
uint32_t addrSDRAM;
uint32_t sizeSDRAM;
uint32_t addrWBSDRAM;
uint32_t sizeWBSDRAM;
uint32_t resetVector;
uint32_t cpuMemBaseAddr;
uint32_t stackStartAddr;
uint16_t zpuId;
uint32_t sysFreq;
uint32_t memFreq;
uint32_t wbMemFreq;
uint8_t implSoCCFG;
uint8_t implWB;
uint8_t implWBSDRAM;
uint8_t implWBI2C;
uint8_t implInsnBRAM;
uint8_t implBRAM;
uint8_t implRAM;
uint8_t implSDRAM;
uint8_t implIOCTL;
uint8_t implPS2;
uint8_t implSPI;
uint8_t implSD;
uint8_t sdCardNo;
uint8_t implIntrCtl;
uint8_t intrChannels;
uint8_t implTimer1;
uint8_t timer1No;
} SOC_CONFIG;
#ifdef __cplusplus
}
#endif
#endif

54
include/zstdio.h Normal file
View File

@@ -0,0 +1,54 @@
#ifndef __ZSTDIO_H__
#define __ZSTDIO_H__
#ifndef NOPOSIX
#include <sys/types.h>
#include <stdarg.h>
struct __zFILE {
int fd;
};
typedef struct __zFILE FILE;
#ifdef __cplusplus
extern "C" {
#endif
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
FILE *fopen(const char *path, const char *mode);
void fclose(FILE*);
int fflush(FILE*);
int fputc(int c, FILE *stream);
int fputs(const char *s, FILE *stream);
int putc(int c, FILE *stream);
int putchar(int c);
int puts(const char *s);
typedef int fpos_t;
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, fpos_t *pos);
void perror(const char *);
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
#ifdef __cplusplus
}
#endif
#endif
#endif