Further updates, added libraries to make the build independent of toolchain libraries
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -44,6 +44,7 @@ build/output_files/
|
||||
build/simulation/
|
||||
apps/*/build/
|
||||
apps/*/*_obj/
|
||||
libraries/build/
|
||||
zputa/build/
|
||||
zOS/build/
|
||||
iocp/iocp_obj/
|
||||
@@ -56,3 +57,6 @@ iocp/test
|
||||
startup/*0x*.ld
|
||||
apps/*/*.zpu
|
||||
apps/*/*.k64
|
||||
common/old2
|
||||
include.bak
|
||||
libraries/umlibc/misc2
|
||||
|
||||
@@ -89,6 +89,8 @@ DHRY_DIR = $(CURDIR)/../../common/Dhrystone
|
||||
COREMARK_DIR = $(CURDIR)/../../common/CoreMark
|
||||
UMM_DIR = $(CURDIR)/../../common/umm
|
||||
INCLUDE_DIR = $(CURDIR)/../../include
|
||||
LIB_DIR = $(CURDIR)/../../libraries/lib
|
||||
LIB_INCLUDE_DIR= $(CURDIR)/../../libraries/include
|
||||
APP_INCLUDE_DIR= $(CURDIR)/../include
|
||||
|
||||
# Working directory to build object files.
|
||||
@@ -109,7 +111,7 @@ endif
|
||||
|
||||
# Common modules needed for this app.
|
||||
#COMMON_SRC = $(COMMON_DIR)/syscalls.c $(COMMON_DIR)/malloc.c $(COMMON_DIR)/tools.c #$(COMMON_DIR)/utils.c
|
||||
COMMON_SRC = $(COMMON_DIR)/syscalls.c # $(COMMON_DIR)/malloc.c
|
||||
COMMON_SRC = #$(CURDIR)/../common/sysutils.c #$(COMMON_DIR)/syscalls.c # $(COMMON_DIR)/malloc.c
|
||||
|
||||
MAIN_PRJ_APP = $(APP_NAME)
|
||||
MAIN_SRC = $(APP_NAME).c
|
||||
@@ -136,7 +138,7 @@ ZPUOPTS = -mloadsp \
|
||||
-mcompare \
|
||||
-mpoppcrel \
|
||||
-mmemreg
|
||||
ifeq ($(CPU), $(filter $(CPU),SMALL MEDIUM FLEX))
|
||||
ifeq ($(CPU), $(filter $(CPU),SMALL MEDIUM FLEX EVOMIN))
|
||||
ZPUOPTS += -mno-mult \
|
||||
-mno-div \
|
||||
-mno-mod \
|
||||
@@ -150,7 +152,8 @@ ifeq ($(CPU), $(filter $(CPU),EVO))
|
||||
endif
|
||||
|
||||
#CFLAGS += -I. -I$(INCLUDE_DIR) -I$(COMMON_DIR)/. -c -Os $(ZPUOPTS) -DPRINTF_HEX_ONLY -DDISABLE_PRINTF # -DDISABLE_UART_TX -DDISABLE_UART_RX
|
||||
CFLAGS += -I. -I$(COMMON_DIR) -I$(FATFS_DIR) -I$(OSDIR) -I$(INCLUDE_DIR) -I$(APP_INCLUDE_DIR) -I${UMM_DIR} -c -O3 -ffunction-sections -fdata-sections $(ZPUOPTS)
|
||||
CFLAGS += -I. -I$(COMMON_DIR) -I$(FATFS_DIR) -I$(OSDIR) -I$(INCLUDE_DIR) -I$(APP_INCLUDE_DIR) -I${UMM_DIR} -I$(LIB_INCLUDE_DIR)
|
||||
CFLAGS += -c -Os -ffunction-sections -fdata-sections $(ZPUOPTS)
|
||||
CFLAGS += -D__ZPU__ -D__APP__ -DOS_BASEADDR=$(OS_BASEADDR) -DOS_APPADDR=$(OS_APPADDR)
|
||||
ifeq (-nostdlib,$(findstring -nostdlib,$(LDFLAGS)))
|
||||
CFLAGS += -DUMM_BEST_FIT -DUMM_INFO -DUMM_DBG_LOG_LEVEL=0
|
||||
@@ -192,7 +195,7 @@ OFLAGS += -DUSELOADB
|
||||
# Enable SD Card functionality
|
||||
OFLAGS += -D__SD_CARD__
|
||||
FLAGS_STR = -DFLAGS_STR="$(CFLAGS)"
|
||||
LFLAGS = -nostartfiles -Wl,--gc-sections -Wl,--relax -Os -Wl,--defsym=OS_BASEADDR=$(OS_BASEADDR) -Wl,--defsym=OS_APPADDR=$(OS_APPADDR)
|
||||
LDFLAGS += -nostartfiles -Wl,--gc-sections -Wl,--relax -Os -Wl,--defsym=OS_BASEADDR=$(OS_BASEADDR) -Wl,--defsym=OS_APPADDR=$(OS_APPADDR) -L$(LIB_DIR)
|
||||
#
|
||||
# Assembler flags.
|
||||
ifeq ($(OS_BASEADDR),0x000000)
|
||||
@@ -280,7 +283,7 @@ $(MAIN_PRJ_APP).elf: $(OBJS)
|
||||
-e "s/APP_STACK_SIZE/$(STACKSIZE)/g" \
|
||||
-e "s/APP_STACK_STARTADDR/$(STACKADDR)/g" \
|
||||
-e "s/APP_STACK_ENDADDR/$(STACKENDADDR)/g" > $(LINKMAPAPP)
|
||||
$(LD) $(LFLAGS) -T $(LINKMAPAPP) -o $@ $(OBJS) $(LIBS)
|
||||
$(LD) $(LDFLAGS) -T $(LINKMAPAPP) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -40,15 +40,13 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
extern unsigned long _stext;
|
||||
extern unsigned long _etext;
|
||||
extern unsigned long _sdata;
|
||||
@@ -61,6 +59,18 @@ extern unsigned long _estack;
|
||||
#define STACK_MARGIN 8192
|
||||
#endif
|
||||
|
||||
#if defined(__ZPU__)
|
||||
void outbyte(char c)
|
||||
{
|
||||
(void)xputc(c);
|
||||
}
|
||||
|
||||
char inbyte(void)
|
||||
{
|
||||
return getserial();
|
||||
}
|
||||
#endif
|
||||
|
||||
int strlen(const char* s) {
|
||||
int i;
|
||||
for (i = 0; s[i]; i++) {
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -41,16 +41,27 @@ APP_COMMON_DIR = $(CURDIR)/../common
|
||||
BASEDIR = ../../..
|
||||
|
||||
# Override values given by parent make for this application as its memory usage differs from the standard app.
|
||||
override HEAPADDR = 0x1FFF5000
|
||||
override HEAPSIZE = 0x00033000
|
||||
override STACKADDR = 0x20028000
|
||||
override STACKSIZE = 0x00000000
|
||||
ifeq ($(__K64F__),1)
|
||||
override HEAPADDR = 0x1FFF5000
|
||||
override HEAPSIZE = 0x00033000
|
||||
override STACKADDR = 0x20028000
|
||||
override STACKSIZE = 0x00000000
|
||||
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = $(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
LIBS =
|
||||
else
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = #$(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
LIBS = -lumansi-zpu -limath-zpu
|
||||
endif
|
||||
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = $(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
|
||||
# Filter out the standard HEAP address and size, replacing with the ones required for this application.
|
||||
# Useful for sub-makes
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ctypelocal.h>
|
||||
#include <stdarg.h>
|
||||
#include <usb_serial.h>
|
||||
#include "k64f_soc.h"
|
||||
@@ -62,13 +61,14 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
#endif
|
||||
//#include <ctypelocal.h>
|
||||
#include <ctype.h>
|
||||
#include "interrupts.h"
|
||||
#include "ff.h" /* Declarations of FatFs API */
|
||||
#include "diskio.h"
|
||||
|
||||
@@ -49,10 +49,8 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
#endif
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -41,16 +41,26 @@ APP_COMMON_DIR = $(CURDIR)/../common
|
||||
BASEDIR = ../../..
|
||||
|
||||
# Override values given by parent make for this application as its memory usage differs from the standard app.
|
||||
override HEAPADDR = 0x1FFF5000
|
||||
override HEAPSIZE = 0x00033000
|
||||
override STACKADDR = 0x20028000
|
||||
override STACKSIZE = 0x00000000
|
||||
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = $(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
ifeq ($(__K64F__),1)
|
||||
override HEAPADDR = 0x1FFF5000
|
||||
override HEAPSIZE = 0x00033000
|
||||
override STACKADDR = 0x20028000
|
||||
override STACKSIZE = 0x00000000
|
||||
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = $(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
LIBS =
|
||||
else
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = #$(APP_COMMON_DIR)/sysutils.c $(APP_COMMON_DIR)/ctypelocal.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
LIBS = -lumansi-zpu -limath-zpu
|
||||
endif
|
||||
|
||||
# Filter out the standard HEAP address and size, replacing with the ones required for this application.
|
||||
# Useful for sub-makes
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ctypelocal.h>
|
||||
#include <stdarg.h>
|
||||
#include "k64f_soc.h"
|
||||
#define uint32_t __uint32_t
|
||||
@@ -59,13 +58,14 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
#endif
|
||||
//#include <ctypelocal.h>
|
||||
#include <ctype.h>
|
||||
#include "interrupts.h"
|
||||
#include "ff.h" /* Declarations of FatFs API */
|
||||
#include "diskio.h"
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
##
|
||||
## Notes: Optional component enables:
|
||||
## USELOADB - The Byte write command is implemented in hw#sw so use it.
|
||||
## USE_BOOT_ROM - The target is ROM so dont use initialised data.
|
||||
## MINIMUM_FUNTIONALITY - Minimise functionality to limit code size.
|
||||
## USE_BOOT_ROM - The target is ROM so dont use initialised data. ## MINIMUM_FUNTIONALITY - Minimise functionality to limit code size.
|
||||
##
|
||||
#########################################################################################################
|
||||
## This source file is free software: you can redistribute it and/or modify
|
||||
@@ -43,15 +42,17 @@ COMMON_DIR = $(CURDIR)../../common
|
||||
BASEDIR = ../../..
|
||||
|
||||
# Override values given by parent make for this application as its memory usage differs from the standard app.
|
||||
ifeq ($(__K64F__),1)
|
||||
override HEAPADDR = 0x2000C000
|
||||
override HEAPSIZE = 0x0001BC00
|
||||
override STACKADDR = 0x20027C00
|
||||
override STACKSIZE = 0x00000400
|
||||
endif
|
||||
|
||||
# Modules making up Mbasic.
|
||||
APP_C_SRC = basic.c ed.c $(APP_COMMON_DIR)/sbrk.c $(APP_COMMON_DIR)/sysutils.c $(COMMON_DIR)/readline.c
|
||||
UMM_C_SRC = fail
|
||||
CFLAGS =
|
||||
UMM_C_SRC =
|
||||
CFLAGS = -Os
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS =
|
||||
|
||||
@@ -64,7 +65,7 @@ NEWMAKEFLAGS = $(FILTER2) HEAPADDR=$(HEADADDR) HEAPSIZE=$(HEAPSIZE)
|
||||
ifeq ($(__K64F__),1)
|
||||
include $(APP_DIR)/Makefile.k64f
|
||||
else
|
||||
# Currently mbasic doesnt build on the ZPU due to missing maths libraries. Once I can source them it should build.
|
||||
# Mbasic needs 128K on the ZPU for some reason, 50% more than the Cortex-M4, so for small ZPU installations, we have to disable it!
|
||||
#include $(APP_DIR)/Makefile.zpu
|
||||
clean:
|
||||
|
||||
|
||||
@@ -31,6 +31,20 @@
|
||||
#include <zpu-types.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define assert(a)
|
||||
#define acos acosf
|
||||
#define floor floorf
|
||||
#define sin sinf
|
||||
#define cos cosf
|
||||
#define tan tanf
|
||||
#define log logf
|
||||
#define pow powf
|
||||
#define sqrt sqrtf
|
||||
#define asin asinf
|
||||
#define atan atanf
|
||||
#define fmod fmodf
|
||||
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
#endif
|
||||
@@ -2420,6 +2434,10 @@ char *stringliteral(void)
|
||||
*/
|
||||
int integer(double x)
|
||||
{
|
||||
#if defined(__ZPU__)
|
||||
#define INT_MIN -2147483648L
|
||||
#define INT_MAX 2147483647L
|
||||
#endif
|
||||
if( x < INT_MIN || x > INT_MAX )
|
||||
seterror( ERR_BADVALUE );
|
||||
if( x != floor(x) )
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
@@ -120,6 +119,13 @@ static t_basic_cmdstruct basicCmdTable[] = {
|
||||
// Define the number of commands in the array.
|
||||
#define NBASICCMDKEYS (sizeof(basicCmdTable)/sizeof(t_basic_cmdstruct))
|
||||
|
||||
// Global scope variables within the ZPUTA memory space.
|
||||
GLOBALS *G;
|
||||
SOC_CONFIG *cfgSoC;
|
||||
|
||||
// Global scope variables in the app memory space.
|
||||
volatile UINT Timer; /* Performance timer (100Hz increment) */
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
// Print out the commands which are recognised by the interactive command processor.
|
||||
|
||||
@@ -427,13 +427,6 @@ char *mystrconcat(const char *, const char *);
|
||||
double factorial(double);
|
||||
uint32_t app(uint32_t, uint32_t);
|
||||
|
||||
// Global scope variables within the ZPUTA memory space.
|
||||
GLOBALS *G;
|
||||
SOC_CONFIG *cfgSoC;
|
||||
|
||||
// Global scope variables in the app memory space.
|
||||
volatile UINT Timer; /* Performance timer (100Hz increment) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -50,8 +50,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -41,16 +41,31 @@ APP_COMMON_DIR = $(CURDIR)/../common
|
||||
BASEDIR = ../../..
|
||||
|
||||
# Override values given by parent make for this application as its memory usage differs from the standard app.
|
||||
override HEAPADDR = 0x1FFF5000
|
||||
override HEAPSIZE = 0x00033000
|
||||
override STACKADDR = 0x20028000
|
||||
override STACKSIZE = 0x00000000
|
||||
ifeq ($(__K64F__),1)
|
||||
override HEAPADDR = 0x1FFF5000
|
||||
override HEAPSIZE = 0x00033000
|
||||
override STACKADDR = 0x20028000
|
||||
override STACKSIZE = 0x00000000
|
||||
|
||||
# Modules making up Kilo.
|
||||
APP_C_SRC = basic_main.c basic_editor.c basic_exectoks.c basic_expr.c basic_tokens.c basic_utils.c $(APP_COMMON_DIR)/sysutils.c
|
||||
CFLAGS =
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
# Modules making up BASIC.
|
||||
APP_C_SRC = basic_main.c basic_editor.c basic_exectoks.c basic_expr.c basic_tokens.c basic_utils.c $(APP_COMMON_DIR)/sysutils.c
|
||||
CFLAGS = -Wno-write-strings -Wno-char-subscripts
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
LIBS =
|
||||
else
|
||||
override HEAPADDR = 0x0000E200
|
||||
override HEAPSIZE = 0x00000D00
|
||||
override STACKADDR = 0x0000F000
|
||||
override STACKSIZE = 0x00000000
|
||||
|
||||
# Modules making up BASIC.
|
||||
APP_C_SRC = basic_main.c basic_editor.c basic_exectoks.c basic_expr.c basic_tokens.c basic_utils.c #$(APP_COMMON_DIR)/sysutils.c
|
||||
CFLAGS = -Wno-write-strings -Wno-char-subscripts
|
||||
CPPFLAGS = -D__HEAPADDR__=$(HEAPADDR) -D__HEAPSIZE__=$(HEAPSIZE)
|
||||
LDFLAGS = -nostdlib
|
||||
LIBS = -lumansi-zpu -limath-zpu
|
||||
endif
|
||||
|
||||
# Filter out the standard HEAP address and size, replacing with the ones required for this application.
|
||||
# Useful for sub-makes
|
||||
@@ -58,10 +73,6 @@ FILTER1 = $(filter-out $(filter HEAPADDR=%,$(MAKEFLAGS)), $(MAKEFLAGS))
|
||||
FILTER2 = $(filter-out $(filter HEAPSIZE=%,$(FILTER1)), $(FILTER1))
|
||||
NEWMAKEFLAGS = $(FILTER2) HEAPADDR=$(HEADADDR) HEAPSIZE=$(HEAPSIZE)
|
||||
|
||||
# Modules making up BASIC.
|
||||
CFLAGS =
|
||||
CPPFLAGS =
|
||||
|
||||
ifeq ($(__K64F__),1)
|
||||
include $(APP_DIR)/Makefile.k64f
|
||||
else
|
||||
|
||||
@@ -277,6 +277,7 @@ void calcArray(char letter) {
|
||||
|
||||
numeric calcExpression(void) {
|
||||
while (1) {
|
||||
|
||||
switch (curTok->type) {
|
||||
case TT_NONE:
|
||||
case TT_SEPARATOR:
|
||||
@@ -590,4 +591,3 @@ void executeParsedRun(void) {
|
||||
progLine = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ void printToken(token* t) {
|
||||
outputChar('E');
|
||||
break;
|
||||
}
|
||||
outputChar('\n');
|
||||
}
|
||||
|
||||
void printTokens(token* t) {
|
||||
|
||||
@@ -89,7 +89,7 @@ void setTokenError(char* pos, char code) {
|
||||
}
|
||||
|
||||
token* nextToken(token* t) {
|
||||
return (token*)(void*)((char*)(void*)t + tokenSize(t));
|
||||
return (token*)(void*) ((char*)(void*)t + tokenSize(t));
|
||||
}
|
||||
|
||||
void skipTokenInInput(char offset) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
g++ -Wall -Wno-write-strings -Wno-char-subscripts -o tinybas.out main_nix.c ../core/*.c
|
||||
g++ -Wall -Wno-write-strings -Wno-char-subscripts -o tinybas.out main_nix.c *.c
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
@@ -161,13 +160,13 @@ numeric sysMillis(numeric div)
|
||||
numeric milliSec;
|
||||
|
||||
#if defined __ZPU__
|
||||
milliSec = (numeric)RTC_MILLISECONDS;
|
||||
milliSec = (numeric)TIMER_MILLISECONDS_UP;
|
||||
#elif defined __K64F__
|
||||
milliSec = (numeric)*G->millis;
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
#endif
|
||||
return milliSec;
|
||||
return milliSec/div;
|
||||
}
|
||||
|
||||
char translateInput(short c)
|
||||
@@ -333,6 +332,11 @@ uint32_t app(uint32_t param1, uint32_t param2)
|
||||
// Initialisation.
|
||||
//
|
||||
//char *ptr = (char *)param1;
|
||||
//
|
||||
// Initialise the ZPU timer.
|
||||
#if defined __ZPU__
|
||||
TIMER_MILLISECONDS_UP = 0;
|
||||
#endif
|
||||
|
||||
init(VARS_SPACE_SIZE, 80, sizeof(dataSpace) - VARS_SPACE_SIZE);
|
||||
while(doExit == 0)
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
@@ -96,31 +95,61 @@ uint32_t app(uint32_t param1, uint32_t param2)
|
||||
//uint32_t *pWordArray = malloc(2048);
|
||||
//uint16_t *pHwordArray = malloc(2048);
|
||||
//uint8_t *pByteArray = malloc(2048);
|
||||
static uint32_t wordArray[2048];
|
||||
static uint16_t hwordArray[2048];
|
||||
static uint8_t byteArray[2048];
|
||||
static uint idx;
|
||||
static uint32_t wordArray[1024];
|
||||
static uint16_t hwordArray[1024];
|
||||
static uint8_t byteArray[1024];
|
||||
static uint16_t idx;
|
||||
static uint32_t sum;
|
||||
long int i, j, k, m;
|
||||
int32_t idx1;
|
||||
uint32_t idx2;
|
||||
|
||||
xputs("This is a test.\n");
|
||||
xputs("Print another line.\n");
|
||||
xprintf("This is another test.\n");
|
||||
xputs("All done\n");
|
||||
|
||||
// Test the maths division.
|
||||
for (i = -10000; i < 10000; i += 8)
|
||||
{
|
||||
for (j = -10000; j < 10000; j += 11)
|
||||
{
|
||||
k = i / j;
|
||||
m = __divsi3 (i, j);
|
||||
if (k != m)
|
||||
xprintf ("fail %d %d %d %d\n", i, j, k, m);
|
||||
}
|
||||
}
|
||||
|
||||
// Test the mod, div and mul.
|
||||
for(idx1=-500; idx1 < 500; idx1++)
|
||||
{
|
||||
xprintf("Result(%d)=%d %d,%u,%u:Mul=%d\n", idx1, (idx1/10), (idx1 % 10),((uint32_t)idx1/10), ((uint32_t)idx1 % 10), idx1 * 10);
|
||||
xprintf("%d, %d\n", __divsi3(idx1,10), __udivsi3(idx1,10));
|
||||
xprintf("%u, %u\n", __divsi3(idx1,10), __udivsi3(idx1,10));
|
||||
}
|
||||
for(idx2=0; idx2 < 500; idx2++)
|
||||
{
|
||||
xprintf("Result(%d)=%d %d, Mul:%d\n", idx2, (int32_t)(idx2/10), (int32_t)(idx2 % 10), idx2 * 10);
|
||||
xprintf(" (%d)=%d %d\n", idx2, (uint32_t)(idx2/10), (uint32_t)(idx2 % 10));
|
||||
xprintf("%d, %d\n", __divsi3(idx2,10), __udivsi3(idx2,10));
|
||||
xprintf("%u, %u\n", __divsi3(idx2,10), __udivsi3(idx2,10));
|
||||
}
|
||||
|
||||
// These are just memory tests, the main test is in premain where a closer knit write operation of BSS fails, thus trying to debug.
|
||||
for(idx=0, sum=0; idx < 2048; idx++)
|
||||
{
|
||||
sum += wordArray[idx];
|
||||
sum += wordArray[idx];
|
||||
}
|
||||
|
||||
for(idx=0, sum=0; idx < 2048; idx++)
|
||||
{
|
||||
sum += hwordArray[idx];
|
||||
sum += hwordArray[idx];
|
||||
}
|
||||
|
||||
for(idx=0, sum=0; idx < 2048; idx++)
|
||||
{
|
||||
sum += byteArray[idx];
|
||||
sum += byteArray[idx];
|
||||
}
|
||||
|
||||
return(0);
|
||||
|
||||
@@ -49,8 +49,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
25
build.sh
25
build.sh
@@ -9,7 +9,7 @@
|
||||
# DESCRIPTION
|
||||
#
|
||||
# OPTIONS
|
||||
# -C <CPU> = Small, Medium, Flex, Evo, K64F - defaults to Evo.
|
||||
# -C <CPU> = Small, Medium, Flex, Evo, EvoMin, K64F - defaults to Evo.
|
||||
# -I <iocp ver> = 0 - Full, 1 - Medium, 2 - Minimum, 3 - Tiny (bootstrap only)
|
||||
# -O <os> = zputa, zos
|
||||
# -o <os ver> = 0 - Standalone, 1 - As app with IOCP Bootloader,
|
||||
@@ -44,6 +44,7 @@
|
||||
# CPU's, ie. small where the emulated mul and div arent working as they should.
|
||||
# v1.2 : Added more zOS logic and the K64F processor target for the tranZPUter board.
|
||||
# v1.21 : Additional changes to manage heap.
|
||||
# v1.22 : Added code to build the libraries.
|
||||
#========================================================================================================
|
||||
# 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
|
||||
@@ -240,7 +241,7 @@ IOCP_VERSION=3;
|
||||
BRAM_SIZE=0x10000;
|
||||
getHex 0x01000 OS_BASEADDR;
|
||||
getHex 0x0C000 APP_BASEADDR;
|
||||
APP_LEN=0x00000;
|
||||
APP_LEN=0x02000;
|
||||
APP_BOOTLEN=0x20; # Fixed size as this is the jump table to make calls within ZPUTA.
|
||||
APP_HEAP_SIZE=0x1000;
|
||||
APP_STACK_SIZE=0x400;
|
||||
@@ -287,7 +288,7 @@ OSNAME=`echo ${OS} | tr 'A-Z' 'a-z'`
|
||||
|
||||
# -C <CPU> = Small, Medium, Flex, Evo, K64F - defaults to Evo.
|
||||
# Check the CPU is correctly defined.
|
||||
if [ "${CPU}" != "SMALL" -a "${CPU}" != "MEDIUM" -a "${CPU}" != "FLEX" -a "${CPU}" != "EVO" -a "${CPU}" != "K64F" ]; then
|
||||
if [ "${CPU}" != "SMALL" -a "${CPU}" != "MEDIUM" -a "${CPU}" != "FLEX" -a "${CPU}" != "EVO" -a "${CPU}" != "EVOMIN" -a "${CPU}" != "K64F" ]; then
|
||||
FatalUsage "Given <cpu> is not valid, must be one of 'Small', 'Medium', 'Flex', 'Evo', 'K64F'"
|
||||
fi
|
||||
if [ ${CPU} = "K64F" ]; then
|
||||
@@ -328,6 +329,13 @@ fi
|
||||
# no reason though why this cant be a fixed address determined by the developer in any memory location.
|
||||
subHex ${BRAM_SIZE} 8 STACK_STARTADDR
|
||||
|
||||
# Build the libraries for this platform.
|
||||
cd ${BUILDPATH}/libraries
|
||||
make ${CPUTYPE}=1 all
|
||||
if [ $? != 0 ]; then
|
||||
Fatal "Aborting, failed to build the libraries for the ${CPUTYPE} processor."
|
||||
fi
|
||||
|
||||
# Setup the bootloader if the OS is not standalone.
|
||||
#
|
||||
#if [ "${OSVER}" -ne 0 ]; then
|
||||
@@ -460,6 +468,7 @@ if [ "${CPUTYPE}" = "__ZPU__" ]; then
|
||||
# Stack start address for the APP. Normally this isnt used as the stack from zOS/ZPUTA is maintained, but available incase of
|
||||
# need for a local stack.
|
||||
addHex ${APP_STARTADDR} ${APP_LEN} APP_ENDADDR
|
||||
#subHex ${APP_ENDADDR} ${OS_STACK_SIZE} APP_ENDADDR
|
||||
subHex ${APP_ENDADDR} 8 APP_STACK_ENDADDR
|
||||
subHex ${APP_STACK_ENDADDR} ${APP_STACK_SIZE} APP_STACK_STARTADDR
|
||||
|
||||
@@ -530,6 +539,7 @@ if [ "${OS}" = "ZPUTA" ]; then
|
||||
-e "s/OS_RAM_LEN/${OS_RAM_LEN}/g" \
|
||||
-e "s/HEAP_SIZE/${OS_HEAP_SIZE}/g" \
|
||||
-e "s/HEAP_STARTADDR/${OS_HEAP_STARTADDR}/g" \
|
||||
-e "s/HEAP_ENDADDR/${OS_HEAP_ENDADDR}/g" \
|
||||
-e "s/STACK_SIZE/${OS_STACK_SIZE}/g" \
|
||||
-e "s/STACK_STARTADDR/${OS_STACK_STARTADDR}/g" \
|
||||
-e "s/STACK_ENDADDR/${OS_STACK_ENDADDR}/g" \
|
||||
@@ -570,6 +580,7 @@ elif [ "${OS}" = "ZOS" ]; then
|
||||
-e "s/OS_RAM_LEN/${OS_RAM_LEN}/g" \
|
||||
-e "s/HEAP_SIZE/${OS_HEAP_SIZE}/g" \
|
||||
-e "s/HEAP_STARTADDR/${OS_HEAP_STARTADDR}/g" \
|
||||
-e "s/HEAP_ENDADDR/${OS_HEAP_ENDADDR}/g" \
|
||||
-e "s/STACK_SIZE/${OS_STACK_SIZE}/g" \
|
||||
-e "s/STACK_STARTADDR/${OS_STACK_STARTADDR}/g" \
|
||||
-e "s/STACK_ENDADDR/${OS_STACK_ENDADDR}/g" \
|
||||
@@ -581,11 +592,11 @@ elif [ "${OS}" = "ZOS" ]; then
|
||||
Fatal "Aborting, failed to clean zOS build environment!"
|
||||
fi
|
||||
if [ "${CPUTYPE}" = "__ZPU__" ]; then
|
||||
Log "make ${OSBUILDSTR} ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU}"
|
||||
make ${OSBUILDSTR} ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU}
|
||||
Log "make ${OSBUILDSTR} ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU} HEAPADDR=${OS_HEAP_STARTADDR} HEAPSIZE=${OS_HEAP_SIZE} STACKADDR=${OS_STACK_STARTADDR} STACKENDADDR=${OS_STACK_ENDADDR} STACKSIZE=${OS_STACK_SIZE}"
|
||||
make ${OSBUILDSTR} ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU} HEAPADDR=${OS_HEAP_STARTADDR} HEAPSIZE=${OS_HEAP_SIZE} STACKADDR=${OS_STACK_STARTADDR} STACKENDADDR=${OS_STACK_ENDADDR} STACKSIZE=${OS_STACK_SIZE}
|
||||
else
|
||||
Log "make ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU}"
|
||||
make ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU}
|
||||
Log "make ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU} HEAPADDR=${OS_HEAP_STARTADDR} HEAPSIZE=${OS_HEAP_SIZE} STACKADDR=${OS_STACK_STARTADDR} STACKENDADDR=${OS_STACK_ENDADDR} STACKSIZE=${OS_STACK_SIZE}"
|
||||
make ${CPUTYPE}=1 ${OSTYPE}=1 OS_BASEADDR=${OS_BOOTADDR} OS_APPADDR=${APP_BASEADDR} CPU=${CPU} HEAPADDR=${OS_HEAP_STARTADDR} HEAPSIZE=${OS_HEAP_SIZE} STACKADDR=${OS_STACK_STARTADDR} STACKENDADDR=${OS_STACK_ENDADDR} STACKSIZE=${OS_STACK_SIZE}
|
||||
fi
|
||||
if [ $? != 0 ]; then
|
||||
Fatal "Aborting, failed to build zOS!"
|
||||
|
||||
@@ -359,7 +359,9 @@
|
||||
|
||||
#ifdef TIMES
|
||||
#include <sys/types.h>
|
||||
#if defined __K64F__
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
/* for "times" */
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,14 +29,14 @@
|
||||
#include "k64f_soc.h"
|
||||
extern uint32_t milliseconds(void);
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#endif
|
||||
|
||||
#include "dhry.h"
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "xprintf.h"
|
||||
#include "dhry.h"
|
||||
|
||||
/* Global Variables: */
|
||||
|
||||
@@ -341,9 +341,9 @@ int main_dhry ()
|
||||
Vax_Mips = (Number_Of_Runs*569) / User_Time;
|
||||
#endif
|
||||
xprintf ("Microseconds for one run through Dhrystone: ");
|
||||
xprintf ("%d \r\n", (int)Microseconds);
|
||||
xprintf ("%d \r\n", (int32_t)Microseconds);
|
||||
xprintf ("Dhrystones per Second: ");
|
||||
xprintf ("%d \r\n", (int)Dhrystones_Per_Second);
|
||||
xprintf ("%d \r\n", (int32_t)Dhrystones_Per_Second);
|
||||
xprintf ("VAX MIPS rating * 1000 = %d \r\n",(int)Vax_Mips);
|
||||
xprintf ("\r\n");
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#if defined __K64F__
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <WProgram.h>
|
||||
#define uint32_t __uint32_t
|
||||
#define uint16_t __uint16_t
|
||||
#define uint8_t __uint8_t
|
||||
@@ -27,11 +28,11 @@
|
||||
#define int8_t __int8_t
|
||||
#include "k64f_soc.h"
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#endif
|
||||
#include "dhry.h"
|
||||
#include <string.h>
|
||||
#include "dhry.h"
|
||||
|
||||
#ifndef REG
|
||||
#define REG
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define int8_t __int8_t
|
||||
#include "k64f_soc.h"
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define int8_t __int8_t
|
||||
#include "k64f_soc.h"
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include "zpu_soc.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#include "xprintf.h"
|
||||
|
||||
#if defined __SD_CARD__
|
||||
#include <ff.h>
|
||||
#endif
|
||||
@@ -521,7 +521,7 @@ uint8_t *readline (uint8_t *line, int lineSize, const char *histFile)
|
||||
char buf[120];
|
||||
FRESULT fr;
|
||||
int bytes;
|
||||
|
||||
|
||||
// If we havent opened the history file and read the contents AND file based history hasnt been disabled, open the history file and read
|
||||
// the contents.
|
||||
if(histFp == NULL && histDisabled == 0 && histFile != NULL)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdlib.h>
|
||||
#include "zpu_soc.h"
|
||||
#endif
|
||||
#include "xprintf.h"
|
||||
|
||||
@@ -31,6 +31,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined __ZPU__
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "uart.h"
|
||||
#include "zpu_soc.h"
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include "zpu_soc.h"
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int tolower(int c) {
|
||||
return isupper(c) ? c - 'A' + 'a' : c ;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright (c) 2007-2008 Ralph Hempel
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -1,32 +0,0 @@
|
||||
// These are the variables and includes needed by the NXT
|
||||
|
||||
#include "stdconst.h"
|
||||
|
||||
#include "checksums.h"
|
||||
|
||||
|
||||
ULONG sum_bytes( const unsigned char *buffer, int size)
|
||||
{
|
||||
ULONG sum = 0;
|
||||
|
||||
while( size-- )
|
||||
sum += (UBYTE)(buffer[size]);
|
||||
|
||||
return( sum );
|
||||
}
|
||||
|
||||
|
||||
UWORD crc_xmodem(const unsigned char *buffer, int size)
|
||||
{
|
||||
UWORD crc = 0;
|
||||
|
||||
while(size--) {
|
||||
crc = (crc>>8) | (crc<<8);
|
||||
crc ^= *buffer++;
|
||||
crc ^= (crc&0xFF) >> 4;
|
||||
crc ^= (crc ) << 12;
|
||||
crc ^= (crc&0xff) << 5;
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
#ifndef __CHECKSUMS_H__
|
||||
#define __CHECKSUMS_H__
|
||||
|
||||
#include "stdconst.h"
|
||||
|
||||
extern UWORD crc_xmodem(const unsigned char *buffer, int size);
|
||||
extern ULONG sum_bytes( const unsigned char *buffer, int size);
|
||||
|
||||
#endif
|
||||
@@ -1,88 +0,0 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// dbglog.h - A set of macros that cleans up code that needs to produce debug
|
||||
// or log information.
|
||||
//
|
||||
// See copyright notice in LICENSE.TXT
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// There are macros to handle the following decreasing levels of detail:
|
||||
//
|
||||
// 6 = TRACE
|
||||
// 5 = DEBUG
|
||||
// 4 = CRITICAL
|
||||
// 3 = ERROR
|
||||
// 2 = WARNING
|
||||
// 1 = INFO
|
||||
// 0 = FORCE - The printf is always compiled in and is called only when
|
||||
// the first parameter to the macro is non-0
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// The following #define should be set up before this file is included so
|
||||
// that we can be sure that the correct macros are defined.
|
||||
//
|
||||
// #define DBG_LOG_LEVEL x
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef DBG_LOG_LEVEL
|
||||
# error "DBG_LOG_LEVEL is not defined!"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// FIXME: Currently the macros are defined at compile time, which means that
|
||||
// the debug level is fixed. It will be possible in later versions to
|
||||
// set up run time control of debug info at the expense of speed and
|
||||
// code size
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#undef DBG_LOG_TRACE
|
||||
#undef DBG_LOG_DEBUG
|
||||
#undef DBG_LOG_CRITICAL
|
||||
#undef DBG_LOG_ERROR
|
||||
#undef DBG_LOG_WARNING
|
||||
#undef DBG_LOG_INFO
|
||||
#undef DBG_LOG_FORCE
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if DBG_LOG_LEVEL >= 6
|
||||
# define DBG_LOG_TRACE( format, ... ) printf( format, ## __VA_ARGS__ )
|
||||
#else
|
||||
# define DBG_LOG_TRACE( format, ... )
|
||||
#endif
|
||||
|
||||
#if DBG_LOG_LEVEL >= 5
|
||||
# define DBG_LOG_DEBUG( format, ... ) printf( format, ## __VA_ARGS__ )
|
||||
#else
|
||||
# define DBG_LOG_DEBUG( format, ... )
|
||||
#endif
|
||||
|
||||
#if DBG_LOG_LEVEL >= 4
|
||||
# define DBG_LOG_CRITICAL( format, ... ) printf( format, ## __VA_ARGS__ )
|
||||
#else
|
||||
# define DBG_LOG_CRITICAL( format, ... )
|
||||
#endif
|
||||
|
||||
#if DBG_LOG_LEVEL >= 3
|
||||
# define DBG_LOG_ERROR( format, ... ) printf( format, ## __VA_ARGS__ )
|
||||
#else
|
||||
# define DBG_LOG_ERROR( format, ... )
|
||||
#endif
|
||||
|
||||
#if DBG_LOG_LEVEL >= 2
|
||||
# define DBG_LOG_WARNING( format, ... ) printf( format, ## __VA_ARGS__ )
|
||||
#else
|
||||
# define DBG_LOG_WARNING( format, ... )
|
||||
#endif
|
||||
|
||||
#if DBG_LOG_LEVEL >= 1
|
||||
# define DBG_LOG_INFO( format, ... ) printf( format, ## __VA_ARGS__ )
|
||||
#else
|
||||
# define DBG_LOG_INFO( format, ... )
|
||||
#endif
|
||||
|
||||
#define DBG_LOG_FORCE( force, format, ... ) {if(force) {printf( format, ## __VA_ARGS__ );}}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef __TYPE_H__
|
||||
#define __TYPE_H__
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#endif
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned long DWORD;
|
||||
typedef unsigned int BOOL;
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef signed char s8;
|
||||
typedef unsigned short u16;
|
||||
typedef signed short s16;
|
||||
typedef unsigned long u32;
|
||||
typedef signed long s32;
|
||||
typedef unsigned long long u64;
|
||||
typedef signed long long s64;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,47 +0,0 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// umm_malloc.h - a memory allocator for embedded systems (microcontrollers)
|
||||
//
|
||||
// See copyright notice in LICENSE.TXT
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef UMM_MALLOC_H
|
||||
#define UMM_MALLOC_H
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// A couple of macros to make packing structures less compiler dependent
|
||||
|
||||
#define UMM_H_ATTPACKPRE
|
||||
#define UMM_H_ATTPACKSUF __attribute__((__packed__))
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// A couple of macros to make it easier to protect the memory allocator
|
||||
// in a multitasking system. You should set these macros up to use whatever
|
||||
// your system uses for this purpose. You can disable interrupts entirely, or
|
||||
// just disable task switching - it's up to you
|
||||
//
|
||||
// NOTE WELL that these macros MUST be allowed to nest, because umm_free() is
|
||||
// called from within umm_malloc()
|
||||
|
||||
#define UMM_CRITICAL_ENTRY()
|
||||
#define UMM_CRITICAL_EXIT()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef struct UMM_HEAP_INFO_t {
|
||||
unsigned short int totalEntries;
|
||||
unsigned short int usedEntries;
|
||||
unsigned short int freeEntries;
|
||||
|
||||
unsigned short int totalBlocks;
|
||||
unsigned short int usedBlocks;
|
||||
unsigned short int freeBlocks;
|
||||
}
|
||||
UMM_HEAP_INFO;
|
||||
|
||||
extern UMM_HEAP_INFO heapInfo;
|
||||
|
||||
void *umm_info( void *ptr, int force );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif // UMM_MALLOC_H
|
||||
@@ -1,13 +0,0 @@
|
||||
// General purpose function/macros
|
||||
|
||||
#ifndef __UTILS_H__
|
||||
#define __UTILS_H__
|
||||
|
||||
#define ABSDIFF( x, y ) ( ( x ) >= ( y ) ? ( x ) - ( y ) : ( y ) - ( x ) )
|
||||
#define UMIN( x, y ) ( ( x ) <= ( y ) ? ( x ) : ( y ) )
|
||||
#define UMAX( x, y ) ( ( x ) >= ( y ) ? ( x ) : ( y ) )
|
||||
#define UABS( x ) ( ( x ) >= 0 ? ( x ) : -( x ) )
|
||||
|
||||
#define STD_CTRLZ_CODE 26
|
||||
|
||||
#endif
|
||||
@@ -1,422 +0,0 @@
|
||||
/*! \file xmodem.c \brief XModem Transmit/Receive Implementation with CRC and 1K support. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'xmodem.c'
|
||||
// Title : XModem Transmit/Receive Implementation with CRC and 1K support
|
||||
// Author : Pascal Stang - Copyright (C) 2006
|
||||
// Created : 4/22/2006
|
||||
// Revised : 7/22/2006
|
||||
// Version : 0.1
|
||||
// Target MCU : AVR processors
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
// Modified by BogdanM for the eLua project
|
||||
// Modified by rhempel for the pbLua project
|
||||
//*****************************************************************************
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "stdconst.h"
|
||||
|
||||
#include "xmodem.h"
|
||||
#include "checksums.h"
|
||||
|
||||
#include "console.h"
|
||||
#include "SysISRHandler.h"
|
||||
|
||||
static int xmodem_out( unsigned char c )
|
||||
{
|
||||
return( nxt_putc( c ) );
|
||||
}
|
||||
|
||||
static int xmodem_in( void )
|
||||
{
|
||||
return( nxt_getc( 0 ) );
|
||||
}
|
||||
|
||||
static int xmodem_crc_check( const unsigned char *buffer, int size )
|
||||
{
|
||||
// check checksum against packet
|
||||
if(crc_xmodem( buffer, size) == ((buffer[size]<<8)+buffer[size+1]))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static xmodem_state *pXMstate;
|
||||
|
||||
static int xmodem_init( UBYTE state )
|
||||
{
|
||||
pXMstate = malloc( sizeof( xmodem_state ) );
|
||||
|
||||
// If we still don't have a state structure allocated, there's an
|
||||
// error...
|
||||
|
||||
if( NULL == pXMstate ) {
|
||||
return( XMODEM_ERROR_NOMEMORY );
|
||||
}
|
||||
|
||||
// Now we can set up the receive state for the first time..
|
||||
|
||||
pXMstate->ready = XMODEM_READY_IDLE;
|
||||
pXMstate->flush = 0;
|
||||
|
||||
pXMstate->seqNum = 1; // Sequence number starts at 1
|
||||
pXMstate->response = 'C'; // Solicit a connection with CRC
|
||||
|
||||
pXMstate->retries = XMODEM_RETRIES;
|
||||
pXMstate->expiry = ISRTicks + XMODEM_TIMEOUT;
|
||||
pXMstate->pktBytes = 0;
|
||||
pXMstate->state = state;
|
||||
|
||||
return( XMODEM_ERROR_NONE );
|
||||
}
|
||||
|
||||
static int xmodem_done( void )
|
||||
{
|
||||
free( pXMstate );
|
||||
pXMstate = NULL;
|
||||
}
|
||||
|
||||
static UBYTE xmodem_updateretry( UBYTE newState )
|
||||
{
|
||||
pXMstate->state = newState;
|
||||
|
||||
if( pXMstate->retries ) {
|
||||
pXMstate->retries--;
|
||||
|
||||
if( (0 == pXMstate->retries) && (pXMstate->state != XMODEM_SEND_ACK) ) {
|
||||
pXMstate->state = XMODEM_ABORT;
|
||||
pXMstate->retries = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int xmodem_processinput( void )
|
||||
{
|
||||
if( NULL == pXMstate ) {
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
pXMstate->process = 0;
|
||||
|
||||
if( EOF != (pXMstate->input = xmodem_in()) ) {
|
||||
// We have a character, process it if we're not flushing the input stream
|
||||
|
||||
if( !pXMstate->flush ) {
|
||||
pXMstate->expiry = ISRTicks + XMODEM_TIMEINC;
|
||||
pXMstate->process = 1;
|
||||
}
|
||||
} else {
|
||||
// We have no character, check to see if we've timed out
|
||||
|
||||
if( pXMstate->expiry <= ISRTicks ) {
|
||||
// We have timed out, so update the next timeout, unconditionally clear
|
||||
// the flush state, set the timeout state, and update the retry counter
|
||||
|
||||
pXMstate->expiry += XMODEM_TIMEINC;
|
||||
pXMstate->flush = 0;
|
||||
|
||||
pXMstate->process = 1;
|
||||
|
||||
xmodem_updateretry( pXMstate->state );
|
||||
}
|
||||
}
|
||||
|
||||
return( pXMstate->process || (pXMstate->state & XMODEM_FORCE) );
|
||||
}
|
||||
|
||||
int xmodem_recv( const char **string )
|
||||
{
|
||||
if( NULL == pXMstate ) {
|
||||
xmodem_init( XMODEM_RECV_QUERY );
|
||||
}
|
||||
|
||||
if( NULL == string ) {
|
||||
xmodem_out( CAN );
|
||||
xmodem_out( CAN );
|
||||
xmodem_done();
|
||||
}
|
||||
|
||||
while( xmodem_processinput() ) {
|
||||
|
||||
// Check for input and process only if we have a character or a timeout...
|
||||
|
||||
switch( pXMstate->state ) {
|
||||
|
||||
case XMODEM_RECV_QUERY: xmodem_out( pXMstate->response );
|
||||
pXMstate->state = XMODEM_RECV_REPLY;
|
||||
break;
|
||||
|
||||
case XMODEM_RECV_REPLY: switch( pXMstate->input ) {
|
||||
|
||||
case EOF: pXMstate->state = XMODEM_RECV_QUERY;
|
||||
break;
|
||||
|
||||
case SOH: pXMstate->buffer[0] = SOH;
|
||||
pXMstate->pktBytes = 1;
|
||||
pXMstate->state = XMODEM_RECV_PART;
|
||||
break;
|
||||
|
||||
case EOT: pXMstate->flush = 1;
|
||||
pXMstate->response = ACK;
|
||||
pXMstate->state = XMODEM_RECV_DONE;
|
||||
break;
|
||||
|
||||
case CAN: pXMstate->state = XMODEM_RECV_CANCEL;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case XMODEM_RECV_PART: switch( pXMstate->input ) {
|
||||
|
||||
case EOF: pXMstate->response = NAK;
|
||||
pXMstate->state = XMODEM_RECV_QUERY;
|
||||
break;
|
||||
|
||||
default: // We've got a character - add it to the packet received
|
||||
// so far...
|
||||
|
||||
do {
|
||||
pXMstate->buffer[pXMstate->pktBytes++] = (unsigned char)(pXMstate->input);
|
||||
|
||||
if( (XMODEM_PKTSIZE+XMODEM_CRCFLAG+4) == pXMstate->pktBytes ) {
|
||||
pXMstate->state = XMODEM_RECV_PACKET;
|
||||
} else {
|
||||
pXMstate->input = xmodem_in();
|
||||
}
|
||||
} while( (EOF != pXMstate->input) && (XMODEM_RECV_PACKET != pXMstate->state ) );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case XMODEM_RECV_PACKET: // We've got a full packet, so do a consistency check on the sequence number
|
||||
// and the CRC
|
||||
|
||||
if( (pXMstate->buffer[1] == (unsigned char)(~pXMstate->buffer[2]) ) &&
|
||||
xmodem_crc_check( &pXMstate->buffer[3], XMODEM_PKTSIZE ) ) {
|
||||
|
||||
if( pXMstate->buffer[1] == pXMstate->seqNum ) {
|
||||
// Is this the packet we are waiting for?
|
||||
|
||||
pXMstate->seqNum++;
|
||||
pXMstate->ready = XMODEM_READY_NEWRX;
|
||||
pXMstate->retries = XMODEM_RETRIES;
|
||||
pXMstate->response = ACK;
|
||||
pXMstate->state = XMODEM_RECV_QUERY;
|
||||
|
||||
*string = &pXMstate->buffer[3];
|
||||
|
||||
} else if( pXMstate->buffer[1] == (unsigned char)(pXMstate->seqNum - 1) ) {
|
||||
// Retry of previous packet, acknowledge and move on...
|
||||
|
||||
pXMstate->response = ACK;
|
||||
pXMstate->state = XMODEM_RECV_QUERY;
|
||||
|
||||
} else {
|
||||
// We're totally out of sync - abort!
|
||||
|
||||
pXMstate->state = XMODEM_ABORT;
|
||||
}
|
||||
} else {
|
||||
// Packet was corrupt - NAK it, flush the input stream for one timeout
|
||||
// period and try again
|
||||
|
||||
pXMstate->response = NAK;
|
||||
pXMstate->flush = 1;
|
||||
|
||||
xmodem_updateretry( XMODEM_RECV_QUERY );
|
||||
}
|
||||
break;
|
||||
|
||||
case XMODEM_RECV_CANCEL: switch( pXMstate->input ) {
|
||||
|
||||
case EOF: // No character recieved, ignore for now
|
||||
break;
|
||||
|
||||
case CAN: // This is two CAN bytes in a row - ACK it, flush the input
|
||||
// stream
|
||||
|
||||
pXMstate->flush = 1;
|
||||
pXMstate->response = ACK;
|
||||
pXMstate->state = XMODEM_RECV_DONE;
|
||||
break;
|
||||
|
||||
default: // Some other character was received, reset the machine
|
||||
|
||||
pXMstate->flush = 1;
|
||||
pXMstate->response = NAK;
|
||||
pXMstate->state = XMODEM_RECV_QUERY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case XMODEM_ABORT: pXMstate->flush = 1;
|
||||
xmodem_out( CAN );
|
||||
xmodem_out( CAN );
|
||||
pXMstate->response = CAN;
|
||||
pXMstate->state = XMODEM_RECV_DONE;
|
||||
break;
|
||||
|
||||
case XMODEM_RECV_DONE: xmodem_out( pXMstate->response );
|
||||
xmodem_done();
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
}
|
||||
return( (NULL == pXMstate) ? XMODEM_READY_DONE : pXMstate->ready );
|
||||
}
|
||||
|
||||
int xmodem_send( const char *string, size_t len )
|
||||
{
|
||||
// First, check if we're sending for the first time, and set up
|
||||
// accordingly...
|
||||
|
||||
if( NULL == pXMstate ) {
|
||||
xmodem_init( XMODEM_SEND_QUERY );
|
||||
}
|
||||
|
||||
if( xmodem_processinput() ) {
|
||||
|
||||
switch( pXMstate->state ) {
|
||||
|
||||
case XMODEM_SEND_QUERY: switch( pXMstate->input ) {
|
||||
|
||||
case 'C': pXMstate->state = XMODEM_SEND_PACKET;
|
||||
pXMstate->ready = XMODEM_READY_NEWTX;
|
||||
break;
|
||||
|
||||
case CAN: pXMstate->state = XMODEM_SEND_CANCEL;
|
||||
break;
|
||||
|
||||
default: // Should we flush if we get a garbage character here?
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case XMODEM_SEND_PACKET: if( pXMstate->ready == XMODEM_READY_TX) {
|
||||
// Ready to send or retry a packet
|
||||
|
||||
UWORD crc = 0;
|
||||
|
||||
xmodem_out( SOH );
|
||||
xmodem_out( pXMstate->seqNum );
|
||||
xmodem_out( ~pXMstate->seqNum );
|
||||
|
||||
for( pXMstate->pktBytes = 3; pXMstate->pktBytes < XMODEM_PKTSIZE+3; pXMstate->pktBytes++ ) {
|
||||
xmodem_out( pXMstate->buffer[pXMstate->pktBytes] );
|
||||
}
|
||||
|
||||
crc = crc_xmodem(&(pXMstate->buffer[3]),XMODEM_PKTSIZE);
|
||||
|
||||
xmodem_out( (crc>>8) & 0xFF );
|
||||
xmodem_out( (crc ) & 0xFF );
|
||||
|
||||
pXMstate->state = XMODEM_SEND_WAIT;
|
||||
|
||||
} else if( (XMODEM_READY_NEWTX == pXMstate->ready) && string ) {
|
||||
// New packet is ready to be copied into the local buffer
|
||||
|
||||
memset( pXMstate->buffer, 0, sizeof( pXMstate->buffer ) );
|
||||
|
||||
len = (len > XMODEM_PKTSIZE) ? XMODEM_PKTSIZE : len;
|
||||
|
||||
for( pXMstate->pktBytes = 3; pXMstate->pktBytes < len+3; pXMstate->pktBytes++ ) {
|
||||
pXMstate->buffer[pXMstate->pktBytes] = *string++;
|
||||
}
|
||||
|
||||
pXMstate->ready = XMODEM_READY_TX;
|
||||
|
||||
} else {
|
||||
// No more data from application
|
||||
|
||||
pXMstate->state = XMODEM_SEND_CLOSE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case XMODEM_SEND_WAIT: switch( pXMstate->input ) {
|
||||
|
||||
case ACK: pXMstate->seqNum++;
|
||||
pXMstate->retries = XMODEM_RETRIES;
|
||||
pXMstate->state = XMODEM_SEND_PACKET;
|
||||
pXMstate->ready = XMODEM_READY_NEWTX;
|
||||
break;
|
||||
|
||||
case NAK: xmodem_updateretry( XMODEM_SEND_PACKET );
|
||||
break;
|
||||
|
||||
case CAN: pXMstate->state = XMODEM_SEND_CANCEL;
|
||||
break;
|
||||
|
||||
default: // Should we flush if we get a garbage character here?
|
||||
xmodem_updateretry( XMODEM_SEND_PACKET );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case XMODEM_SEND_CANCEL: switch( pXMstate->input ) {
|
||||
|
||||
case EOF: // No character recieved, ignore for now
|
||||
break;
|
||||
|
||||
case CAN: // This is two CAN bytes in a row - cancel by receiver
|
||||
xmodem_out( ACK );
|
||||
xmodem_done ();
|
||||
break;
|
||||
|
||||
default: // Should we flush if we get a garbage character here?
|
||||
// Some other character was received, look for correct response
|
||||
pXMstate->state = XMODEM_SEND_WAIT;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case XMODEM_ABORT: pXMstate->response = CAN;
|
||||
|
||||
xmodem_out( pXMstate->response );
|
||||
xmodem_out( pXMstate->response );
|
||||
|
||||
pXMstate->state = XMODEM_SEND_ACK;
|
||||
break;
|
||||
|
||||
case XMODEM_SEND_CLOSE: pXMstate->response = EOT;
|
||||
|
||||
xmodem_out( pXMstate->response );
|
||||
|
||||
pXMstate->state = XMODEM_SEND_ACK;
|
||||
break;
|
||||
|
||||
case XMODEM_SEND_ACK: switch( pXMstate->input ) {
|
||||
|
||||
case ACK: xmodem_done();
|
||||
break;
|
||||
|
||||
default: xmodem_out( pXMstate->response );
|
||||
xmodem_out( pXMstate->response );
|
||||
|
||||
if( 0 == pXMstate->retries ) {
|
||||
xmodem_done();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return( (NULL == pXMstate) ? XMODEM_READY_DONE : pXMstate->ready );
|
||||
}
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
#include "stdconst.h"
|
||||
|
||||
// XMODEM constants
|
||||
|
||||
#define XMODEM_RETRIES (8)
|
||||
#define XMODEM_TIMEOUT (8000)
|
||||
#define XMODEM_TIMEINC (2000)
|
||||
#define XMODEM_PKTSIZE (128)
|
||||
#define XMODEM_CRCFLAG (1)
|
||||
|
||||
typedef struct xmodem_state_t {
|
||||
UBYTE state;
|
||||
UBYTE ready;
|
||||
|
||||
UBYTE response;
|
||||
int input;
|
||||
|
||||
UBYTE flush;
|
||||
UBYTE process;
|
||||
UBYTE done;
|
||||
|
||||
UBYTE retries;
|
||||
ULONG expiry;
|
||||
|
||||
UBYTE seqNum;
|
||||
UBYTE pktBytes;
|
||||
UBYTE buffer[XMODEM_PKTSIZE+6];
|
||||
} xmodem_state;
|
||||
|
||||
extern int xmodem_recv( const char ** );
|
||||
extern int xmodem_send( const char *, size_t );
|
||||
|
||||
// xmodem control characters
|
||||
#define SOH (0x01)
|
||||
#define STX (0x02)
|
||||
#define EOT (0x04)
|
||||
#define ACK (0x06)
|
||||
#define NAK (0x15)
|
||||
#define CAN (0x18)
|
||||
#define CTRLZ (0x1A)
|
||||
|
||||
#define XMODEM_READY_DONE (0)
|
||||
#define XMODEM_READY_IDLE (1)
|
||||
#define XMODEM_READY_NEWRX (2)
|
||||
#define XMODEM_READY_NEWTX (3)
|
||||
#define XMODEM_READY_TX (4)
|
||||
|
||||
// error return codes
|
||||
|
||||
#define XMODEM_ERROR_NONE ( 0)
|
||||
#define XMODEM_ERROR_REMOTECANCEL (-1)
|
||||
#define XMODEM_ERROR_EXCEEDEDRETRY (-2)
|
||||
#define XMODEM_ERROR_OUTOFSYNC (-3)
|
||||
#define XMODEM_ERROR_NOMEMORY (-4)
|
||||
#define XMODEM_ERROR_ALREADYTX (-5)
|
||||
#define XMODEM_ERROR_ALREADYRX (-6)
|
||||
|
||||
// state masks
|
||||
|
||||
#define XMODEM_STATE_MASK (0x0F)
|
||||
#define XMODEM_DIR (0x10)
|
||||
#define XMODEM_FORCE (0x20)
|
||||
|
||||
#define XMODEM_IDLE (0x00)
|
||||
|
||||
#define XMODEM_ABORT (XMODEM_FORCE | 0x0F)
|
||||
|
||||
// receive states
|
||||
|
||||
#define XMODEM_RECV_QUERY (XMODEM_FORCE | 0x01)
|
||||
#define XMODEM_RECV_REPLY ( 0x02)
|
||||
#define XMODEM_RECV_PART ( 0x03)
|
||||
#define XMODEM_RECV_PACKET (XMODEM_FORCE | 0x04)
|
||||
#define XMODEM_RECV_CANCEL ( 0x05)
|
||||
#define XMODEM_RECV_DONE (XMODEM_FORCE | 0x07)
|
||||
|
||||
// send states
|
||||
|
||||
#define XMODEM_SEND_QUERY ( 0x11)
|
||||
#define XMODEM_SEND_PACKET (XMODEM_FORCE | 0x12)
|
||||
#define XMODEM_SEND_WAIT ( 0x13)
|
||||
#define XMODEM_SEND_CANCEL ( 0x14)
|
||||
#define XMODEM_SEND_CLOSE (XMODEM_FORCE | 0x15)
|
||||
#define XMODEM_SEND_ACK ( 0x16)
|
||||
|
||||
// #define XMODEM_ERROR_REMOTECANCEL (-1)
|
||||
// #define XMODEM_ERROR_OUTOFSYNC (-2)
|
||||
// #define XMODEM_ERROR_RETRYEXCEED (-3)
|
||||
// #define XMODEM_ERROR_OUTOFMEM (-4)
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
|
||||
@@ -50,8 +50,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#elif defined(__ZPU__)
|
||||
#include <zstdio.h>
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error "Target CPU not defined, use __ZPU__ or __K64F__"
|
||||
@@ -641,6 +640,7 @@ void *umm_realloc( void *ptr, size_t size ) {
|
||||
if (blockSize >= blocks) {
|
||||
DBGLOG_DEBUG( "realloc the same or smaller size block - %x, do nothing\n", blocks );
|
||||
/* This space intentionally left blank */
|
||||
DBGLOG_DEBUG("Returning 1 alloc address:%08lx#n", ptr);
|
||||
|
||||
// Case 2 - block + next block fits EXACTLY
|
||||
} else if ((blockSize + nextBlockSize) == blocks) {
|
||||
@@ -688,6 +688,7 @@ void *umm_realloc( void *ptr, size_t size ) {
|
||||
blockSize = blocks;
|
||||
}
|
||||
|
||||
DBGLOG_DEBUG("Returning 2 alloc address:%08lx#n", ptr);
|
||||
/* Now all we need to do is figure out if the block fit exactly or if we
|
||||
* need to split and free ...
|
||||
*/
|
||||
@@ -698,9 +699,11 @@ void *umm_realloc( void *ptr, size_t size ) {
|
||||
umm_free_core( (void *)&UMM_DATA(c+blocks) );
|
||||
}
|
||||
|
||||
DBGLOG_DEBUG("Returning 3 alloc address:%08lx#n", ptr);
|
||||
/* Release the critical section... */
|
||||
UMM_CRITICAL_EXIT();
|
||||
|
||||
DBGLOG_DEBUG("Returning 4 alloc address:%08lx#n", ptr);
|
||||
return( ptr );
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "uart.h"
|
||||
#include "zpu_soc.h"
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#define int16_t __int16_t
|
||||
#define int8_t __int8_t
|
||||
#else
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#include "xprintf.h"
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <zpu-types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "uart.h"
|
||||
#include "zpu_soc.h"
|
||||
#include "xprintf.h"
|
||||
|
||||
@@ -66,6 +66,7 @@ RTL_DIR = $(BASEDIR)/rtl
|
||||
COMMON_DIR = $(SWDIR)/common
|
||||
PFS_DIR = $(SWDIR)/common/PetitFS
|
||||
INCLUDE_DIR = $(SWDIR)/include
|
||||
LIB_INCLUDE_DIR = $(SWDIR)/libraries/include
|
||||
|
||||
# Linker mapping file spec file.
|
||||
LINKMAP = $(STARTUP_DIR)/iocp_bram_${IOCP_BASEADDR}.ld
|
||||
@@ -123,8 +124,8 @@ ZPUOPTS += -mmult \
|
||||
endif
|
||||
|
||||
|
||||
#CFLAGS = -I. -I$(COMMON_DIR) -I$(PFS_DIR) -I$(INCLUDE_DIR) -c -Os $(ZPUOPTS) -DZPU -DIOCP -DPFS -DIOCP_BASEADDR=$(IOCP_BASEADDR) -DIOCP_APPADDR=$(IOCP_APPADDR) -DFUNCTIONALITY=$(FUNCTIONALITY)
|
||||
CFLAGS = -I. -I$(COMMON_DIR) -I$(PFS_DIR) -I$(INCLUDE_DIR)
|
||||
#CFLAGS = -I. -I$(COMMON_DIR) -I$(PFS_DIR) -I$(INCLUDE_DIR) -i$(LIB_INCLUDE_DIR) -c -Os $(ZPUOPTS) -DZPU -DIOCP -DPFS -DIOCP_BASEADDR=$(IOCP_BASEADDR) -DIOCP_APPADDR=$(IOCP_APPADDR) -DFUNCTIONALITY=$(FUNCTIONALITY)
|
||||
CFLAGS = -I. -I$(COMMON_DIR) -I$(PFS_DIR) -I$(INCLUDE_DIR) -I$(LIB_INCLUDE_DIR)
|
||||
CFLAGS += -c -Os -ffunction-sections -fdata-sections $(ZPUOPTS)
|
||||
CFLAGS += -D__ZPU__ -D__IOCP__ -DIOCP -DPFS -DIOCP_BASEADDR=$(IOCP_BASEADDR) -DIOCP_APPADDR=$(IOCP_APPADDR) -DFUNCTIONALITY=$(FUNCTIONALITY)
|
||||
#
|
||||
|
||||
265
libraries/Makefile
Executable file
265
libraries/Makefile
Executable file
@@ -0,0 +1,265 @@
|
||||
#########################################################################################################
|
||||
##
|
||||
## Name: Makefile
|
||||
## Created: April 2020
|
||||
## Author(s): Philip Smart
|
||||
## Description: uM Library
|
||||
## This makefile builds the uM Library for the various CPUs in the zOS/ZPUTA scope.
|
||||
##
|
||||
## Credits: (C) Original authors in component files, please see component files for (C) notices.
|
||||
## Copyright: (c) 2020 Philip Smart <philip.smart@net2net.org>, Make system and changes.
|
||||
##
|
||||
## History: April 2020 - Initial Makefile created.
|
||||
##
|
||||
## Notes: Optional component enables:
|
||||
##
|
||||
#########################################################################################################
|
||||
## 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/>.
|
||||
#########################################################################################################
|
||||
ifeq ($(__ZPU__),)
|
||||
BASEDIR = $(CURDIR)/..
|
||||
TOOLSPATH = $(BASEDIR)/tools
|
||||
COMPILERPATH = $(TOOLSPATH)/arm/bin
|
||||
BASE = $(abspath $(COMPILERPATH))/arm-none-eabi
|
||||
else
|
||||
BASEDIR = $(CURDIR)/..
|
||||
TOOLSPATH = /opt/zpu
|
||||
COMPILERPATH = $(TOOLSPATH)/bin
|
||||
BASE = zpu-elf
|
||||
endif
|
||||
CC = $(BASE)-gcc
|
||||
CXX = $(BASE)-g++
|
||||
LD = $(BASE)-gcc
|
||||
AS = $(BASE)-as
|
||||
AR = $(BASE)-ar
|
||||
CP = $(BASE)-objcopy
|
||||
DUMP = $(BASE)-objdump
|
||||
OBJCOPY = $(BASE)-objcopy
|
||||
SIZE = $(BASE)-size
|
||||
RANLIB = $(BASE)-ranlib
|
||||
|
||||
# Version etc.
|
||||
TITLE = "uM Library"
|
||||
COPYRIGHT = "This make system and enhancements (C) P.D. Smart 2020, Version 1.0\n"
|
||||
COPYRIGHT += "Component files, (C) Various authors, please see component files."
|
||||
|
||||
# Working directory to build object files.
|
||||
BUILD_DIR = $(abspath $(CURDIR)/build)
|
||||
|
||||
# Library component directories.
|
||||
COMMON_DIR = $(CURDIR)/../common
|
||||
INCLUDE_DIR = $(CURDIR)/../include
|
||||
UMLIBC_DIR = $(CURDIR)/umlibc
|
||||
IMATH_DIR = $(CURDIR)/imath
|
||||
LIB_DIR = $(CURDIR)//lib
|
||||
LIB_INCLUDE_DIR = $(CURDIR)/include
|
||||
|
||||
# ANSI library.
|
||||
UMLIBC_ANSI_C_SRC = $(wildcard $(UMLIBC_DIR)/ansi/*.c)
|
||||
UMLIBC_ANSI_CPP_SRC = $(wildcard $(UMLIBC_DIR)/ansi/*.cpp)
|
||||
UMLIBC_ANSI_SRC = $(UMLIBC_ANSI_C_SRC:.c=.o) $(UMLIBC_ANSI_CPP_SRC:.cpp=.o)
|
||||
UMLIBC_ANSI_OBJS = $(foreach src,$(UMLIBC_ANSI_SRC), $(BUILD_DIR)/$(src))
|
||||
|
||||
# MATH library.
|
||||
UMLIBC_MATH_C_SRC = $(wildcard $(UMLIBC_DIR)/math/*.c)
|
||||
UMLIBC_MATH_CPP_SRC = $(wildcard $(UMLIBC_DIR)/math/*.cpp)
|
||||
UMLIBC_MATH_SRC = $(UMLIBC_MATH_C_SRC:.c=.o) $(UMLIBC_MATH_CPP_SRC:.cpp=.o)
|
||||
UMLIBC_MATH_OBJS = $(foreach src,$(UMLIBC_MATH_SRC), $(BUILD_DIR)/$(src))
|
||||
|
||||
# MATHF library.
|
||||
UMLIBC_MATHF_C_SRC = $(wildcard $(UMLIBC_DIR)/mathf/*.c)
|
||||
UMLIBC_MATHF_CPP_SRC = $(wildcard $(UMLIBC_DIR)/mathf/*.cpp)
|
||||
UMLIBC_MATHF_SRC = $(UMLIBC_MATHF_C_SRC:.c=.o) $(UMLIBC_MATHF_CPP_SRC:.cpp=.o)
|
||||
UMLIBC_MATHF_OBJS = $(foreach src,$(UMLIBC_MATHF_SRC), $(BUILD_DIR)/$(src))
|
||||
|
||||
# MISC library.
|
||||
UMLIBC_MISC_C_SRC = $(wildcard $(UMLIBC_DIR)/misc/*.c)
|
||||
UMLIBC_MISC_CPP_SRC = $(wildcard $(UMLIBC_DIR)/misc/*.cpp)
|
||||
UMLIBC_MISC_SRC = $(UMLIBC_MISC_C_SRC:.c=.o) $(UMLIBC_MISC_CPP_SRC:.cpp=.o)
|
||||
UMLIBC_MISC_OBJS = $(foreach src,$(UMLIBC_MISC_SRC), $(BUILD_DIR)/$(src))
|
||||
|
||||
# STDIO library.
|
||||
UMLIBC_STDIO_C_SRC = $(wildcard $(UMLIBC_DIR)/stdio/*.c)
|
||||
UMLIBC_STDIO_CPP_SRC = $(wildcard $(UMLIBC_DIR)/stdio/*.cpp)
|
||||
UMLIBC_STDIO_SRC = $(UMLIBC_STDIO_C_SRC:.c=.o) $(UMLIBC_STDIO_CPP_SRC:.cpp=.o)
|
||||
UMLIBC_STDIO_OBJS = $(foreach src,$(UMLIBC_STDIO_SRC), $(BUILD_DIR)/$(src))
|
||||
|
||||
# Integer mathmatics for CRT0 and startup code library.
|
||||
IMATH_C_SRC = $(wildcard $(IMATH_DIR)/*.c)
|
||||
IMATH_CPP_SRC = $(wildcard $(IMATH_DIR)/*.cpp)
|
||||
IMATH_SRC = $(IMATH_C_SRC:.c=.o) $(IMATH_CPP_SRC:.cpp=.o)
|
||||
IMATH_OBJS = $(foreach src,$(IMATH_SRC), $(BUILD_DIR)/$(src))
|
||||
|
||||
# Build time flags dependent on CPU target.
|
||||
CFLAGS = -I. -I$(UMLIBC_DIR)/include -I$(COMMON_DIR) -I$(INCLUDE_DIR) -I$(TEENSY35_DIR)
|
||||
ifeq ($(__ZPU__),)
|
||||
CFLAGS += -D__K64F__
|
||||
else
|
||||
CFLAGS += -D__ZPU__
|
||||
endif
|
||||
|
||||
# Linker flags.
|
||||
LDFLAGS = -static
|
||||
|
||||
# Library name is suffixed by CPU.
|
||||
#
|
||||
ifeq ($(__ZPU__),)
|
||||
LIBTRG = -k64f
|
||||
else
|
||||
LIBTRG = -zpu
|
||||
endif
|
||||
|
||||
|
||||
# Suffixes where interested in for this project.
|
||||
#
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .o .c .h
|
||||
|
||||
# All, ie: all libraries to be built after a clean (necessary due to multi cpu platforms).
|
||||
#
|
||||
all: Begin \
|
||||
DoClean \
|
||||
libumansi \
|
||||
libummath \
|
||||
libummathf \
|
||||
libumstdio \
|
||||
libummisc \
|
||||
libimath \
|
||||
DoInstall \
|
||||
End
|
||||
|
||||
# Targets for individual build or Any specific handling for library.
|
||||
libumansi: libumansi.a
|
||||
|
||||
libummath: libummath.a
|
||||
|
||||
libummathf: libummathf.a
|
||||
|
||||
libumstdio: libumstdio.a
|
||||
|
||||
libummisc: #libummisc.a
|
||||
|
||||
libimath: libimath2.a
|
||||
|
||||
|
||||
# How to clean up the directory... make it look pretty!
|
||||
#
|
||||
clean: Begin \
|
||||
DoClean \
|
||||
End
|
||||
|
||||
# How to perform an installation of the resultant software.
|
||||
#
|
||||
install: Begin \
|
||||
DoInstall \
|
||||
End
|
||||
#
|
||||
# Pre-make start sequence.
|
||||
#
|
||||
Begin:
|
||||
@echo $(TITLE)
|
||||
@echo $(COPYRIGHT)
|
||||
@echo
|
||||
@echo "Operation commencing @ `date`"
|
||||
@echo
|
||||
|
||||
#
|
||||
# Post-make completion sequence.
|
||||
#
|
||||
End:
|
||||
@echo
|
||||
@echo "Completed @ `date`"
|
||||
|
||||
# Perform all cleanup operations to ensure future builds occur with
|
||||
# completeness.
|
||||
#
|
||||
DoClean:
|
||||
rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/*.bak $(BUILD_DIR)/*$(LIBTRG).a $(BUILD_DIR)/*.BAK $(BUILD_DIR)/*.sav $(BUILD_DIR)/core
|
||||
rm -fr $(BUILD_DIR)/srv
|
||||
|
||||
# Perform installation of software as per spec.
|
||||
#
|
||||
DoInstall:
|
||||
mkdir -p $(LIB_DIR)
|
||||
mv $(CURDIR)/*.a $(LIB_DIR)/
|
||||
mkdir -p $(LIB_INCLUDE_DIR)
|
||||
cp -r $(UMLIBC_DIR)/include/* $(LIB_INCLUDE_DIR)/
|
||||
|
||||
# Build the UniX Library.
|
||||
#
|
||||
libumansi.a: $(UMLIBC_ANSI_OBJS)
|
||||
$(AR) rcsv $@ $+
|
||||
mv $(@F) `basename $(@F) .a`$(LIBTRG).a
|
||||
|
||||
libummath.a: $(UMLIBC_MATH_OBJS)
|
||||
$(AR) rcsv $@ $+
|
||||
mv $(@F) `basename $(@F) .a`$(LIBTRG).a
|
||||
|
||||
libummathf.a: $(UMLIBC_MATHF_OBJS)
|
||||
$(AR) rcsv $@ $+
|
||||
mv $(@F) `basename $(@F) .a`$(LIBTRG).a
|
||||
|
||||
libumstdio.a: $(UMLIBC_STDIO_OBJS)
|
||||
$(AR) rcsv $@ $+
|
||||
mv $(@F) `basename $(@F) .a`$(LIBTRG).a
|
||||
|
||||
libummisc.a: $(UMLIBC_MISC_OBJS)
|
||||
$(AR) rcsv $@ $+
|
||||
mv $(@F) `basename $(@F) .a`$(LIBTRG).a
|
||||
|
||||
libimath2.a: $(IMATH_OBJS)
|
||||
$(AR) rcsv $@ $+
|
||||
mv $(@F) `basename $(@F) .a`$(LIBTRG).a
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CXX) $(CFLAGS) $(CXXFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/src/%.o: %.cpp Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CXX) $(CFLAGS) $(CXXFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/%.o: $(COMMON_DIR)/%.c Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/%.o: $(DHRY_DIR)/%.c Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/%.o: $(FATFS_DIR)/%.c Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/%.o: $(PFS_DIR)/%.c Makefile
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(AS) $(ASFLAGS) -o $@ $<
|
||||
|
||||
$(BUILD_DIR)/%.o: $(STARTUP_DIR)/%.s
|
||||
@mkdir -p "$(dir $@)"
|
||||
$(AS) $(ASFLAGS) -o $@ $<
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
# compiler generated dependency info
|
||||
-include $(OBJS:.o=.d)
|
||||
22
libraries/imath/divsi3.c
Normal file
22
libraries/imath/divsi3.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdint.h>
|
||||
//#include "int_lib.h"
|
||||
// Returns: a / b
|
||||
#define CHAR_BIT 8
|
||||
int32_t __divsi3(int32_t a, int32_t b) {
|
||||
const int bits_in_word_m1 = (int)(sizeof(int32_t) * CHAR_BIT) - 1;
|
||||
int32_t s_a = a >> bits_in_word_m1; // s_a = a < 0 ? -1 : 0
|
||||
int32_t s_b = b >> bits_in_word_m1; // s_b = b < 0 ? -1 : 0
|
||||
|
||||
//xprintf("divsi3(1):a=%d, b=%d, s_a=%d, s_b=%s\n", a, b, s_a, s_b);
|
||||
a = (a ^ s_a) - s_a; // negate if s_a == -1
|
||||
b = (b ^ s_b) - s_b; // negate if s_b == -1
|
||||
s_a ^= s_b; // sign of quotient
|
||||
//xprintf("divsi3(2):a=%d, b=%d, s_a=%d, s_b=%s\n", a, b, s_a, s_b);
|
||||
|
||||
// On CPUs without unsigned hardware division support,
|
||||
// this calls __udivsi3 (notice the cast to su_int).
|
||||
// On CPUs with unsigned hardware division support,
|
||||
// this uses the unsigned division instruction.
|
||||
//
|
||||
return ((uint32_t)a / (uint32_t)b ^ s_a) - s_a; // negate if s_a == -1
|
||||
}
|
||||
6
libraries/imath/modsi3.c
Normal file
6
libraries/imath/modsi3.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <stdint.h>
|
||||
//#include "int_lib.h"
|
||||
// Returns: a % b
|
||||
int32_t __modsi3(int32_t a, int32_t b) {
|
||||
return a - __divsi3(a, b) * b;
|
||||
}
|
||||
98
libraries/imath/udivsi3.c
Normal file
98
libraries/imath/udivsi3.c
Normal file
@@ -0,0 +1,98 @@
|
||||
//#include "int_lib.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : __builtin_clz(a))
|
||||
#define CHAR_BIT 8
|
||||
|
||||
// Adapted from Figure 3-40 of The PowerPC Compiler Writer's Guide
|
||||
static __inline uint32_t __udivXi3(uint32_t n, uint32_t d) {
|
||||
const unsigned N = sizeof(uint32_t) * CHAR_BIT;
|
||||
// d == 0 cases are unspecified.
|
||||
unsigned sr = (d ? clz(d) : N) - (n ? clz(n) : N);
|
||||
// 0 <= sr <= N - 1 or sr is very large.
|
||||
if (sr > N - 1) // n < d
|
||||
return 0;
|
||||
if (sr == N - 1) // d == 1
|
||||
return n;
|
||||
++sr;
|
||||
// 1 <= sr <= N - 1. Shifts do not trigger UB.
|
||||
uint32_t r = n >> sr;
|
||||
n <<= N - sr;
|
||||
uint32_t carry = 0;
|
||||
for (; sr > 0; --sr) {
|
||||
r = (r << 1) | (n >> (N - 1));
|
||||
n = (n << 1) | carry;
|
||||
// Branch-less version of:
|
||||
// carry = 0;
|
||||
// if (r >= d) r -= d, carry = 1;
|
||||
const int32_t s = (int32_t)(d - r - 1) >> (N - 1);
|
||||
carry = s & 1;
|
||||
r -= d & s;
|
||||
}
|
||||
n = (n << 1) | carry;
|
||||
return n;
|
||||
}
|
||||
// Mostly identical to __udivXi3 but the return values are different.
|
||||
static __inline uint32_t __umodXi3(uint32_t n, uint32_t d) {
|
||||
const unsigned N = sizeof(uint32_t) * CHAR_BIT;
|
||||
// d == 0 cases are unspecified.
|
||||
unsigned sr = (d ? clz(d) : N) - (n ? clz(n) : N);
|
||||
// 0 <= sr <= N - 1 or sr is very large.
|
||||
if (sr > N - 1) // n < d
|
||||
return n;
|
||||
if (sr == N - 1) // d == 1
|
||||
return 0;
|
||||
++sr;
|
||||
// 1 <= sr <= N - 1. Shifts do not trigger UB.
|
||||
uint32_t r = n >> sr;
|
||||
n <<= N - sr;
|
||||
uint32_t carry = 0;
|
||||
for (; sr > 0; --sr) {
|
||||
r = (r << 1) | (n >> (N - 1));
|
||||
n = (n << 1) | carry;
|
||||
// Branch-less version of:
|
||||
// carry = 0;
|
||||
// if (r >= d) r -= d, carry = 1;
|
||||
const int32_t s = (int32_t)(d - r - 1) >> (N - 1);
|
||||
carry = s & 1;
|
||||
r -= d & s;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
// Returns: a / b
|
||||
uint32_t __udivsi3(uint32_t a, uint32_t b) {
|
||||
//xprintf("udivsi3(1):a=%d, b=%d, udixX=%d\n", a, b,__udivXi3(a, b) );
|
||||
return __udivXi3(a, b);
|
||||
}
|
||||
|
||||
|
||||
int32_t __clzsi2(int32_t a) {
|
||||
uint32_t x = (uint32_t)a;
|
||||
int32_t t = ((x & 0xFFFF0000) == 0) << 4; // if (x is small) t = 16 else 0
|
||||
x >>= 16 - t; // x = [0 - 0xFFFF]
|
||||
uint32_t r = t; // r = [0, 16]
|
||||
// return r + clz(x)
|
||||
t = ((x & 0xFF00) == 0) << 3;
|
||||
x >>= 8 - t; // x = [0 - 0xFF]
|
||||
r += t; // r = [0, 8, 16, 24]
|
||||
// return r + clz(x)
|
||||
t = ((x & 0xF0) == 0) << 2;
|
||||
x >>= 4 - t; // x = [0 - 0xF]
|
||||
r += t; // r = [0, 4, 8, 12, 16, 20, 24, 28]
|
||||
// return r + clz(x)
|
||||
t = ((x & 0xC) == 0) << 1;
|
||||
x >>= 2 - t; // x = [0 - 3]
|
||||
r += t; // r = [0 - 30] and is even
|
||||
// return r + clz(x)
|
||||
// switch (x)
|
||||
// {
|
||||
// case 0:
|
||||
// return r + 2;
|
||||
// case 1:
|
||||
// return r + 1;
|
||||
// case 2:
|
||||
// case 3:
|
||||
// return r;
|
||||
// }
|
||||
return r + ((2 - x) & -((x & 2) == 0));
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user