diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..09af0a0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "mc8051fun"] + path = mc8051fun + url = https://git.planix.org/7u83/mc8051fun.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..00d9fa5 --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +SDCC ?= sdcc +SDAR ?= sdar +STCCODESIZE ?= 8192 +SDCCOPTS ?= +SDCCREV ?= -Dstc15f204ea +STCGAL ?= stcgal +#/stcgal.py +STCGALOPTS ?= +STCGALPORT ?= /dev/ttyUSB0 +STCGALPROT ?= auto +FLASHFILE ?= main.ihx + + +SYSCLK ?= 11059 +FOSC ?=11059200L +CFLAGS ?= + +LIBSRC = + +LIBNAME = mc8051fun/mc8051fun.lib + +PRGSRC = term.c pinsh.c + +PRGOBJ =$(patsubst %.c,%.rel, $(PRGSRC)) + + +$(FLASHFILE): $(LIBNAME) $(PRGOBJ) + $(SDCC) -o $(FLASHFILE) $(SDCCOPTS) $(SDCCREV) $(CFLAGS) $(PRGOBJ) $(LIBNAME) + + +$(LIBNAME): $(LIBOBJ) + $(SDAR) -rc $(LIBNAME) $(LIBOBJ) +#all: +# make uart2.ihx + +%.rel: %.c + $(SDCC) $(SDCCOPTS) $(SDCCREV) -DFOSC=$(FOSC) -o $@ -c $< + +eeprom: + sed -ne '/:..1/ { s/1/0/2; p }' main.hex > eeprom.hex + +flash: $(FLASHFILE) + $(STCGAL) -p $(STCGALPORT) -P $(STCGALPROT) -t $(SYSCLK) $(STCGALOPTS) $(FLASHFILE) + +clean: + rm -f *.ihx *.hex *.bin *.rst + rm -f *.map + rm -f *.rel + rm -f *.lst + rm -f *.sym + rm -f *.asm + rm -f *.lk + rm -f *.mem + rm -f *.lib + +cpp: SDCCOPTS+=-E +cpp: main diff --git a/mc8051fun b/mc8051fun new file mode 160000 index 0000000..5c00e16 --- /dev/null +++ b/mc8051fun @@ -0,0 +1 @@ +Subproject commit 5c00e1633a9c10cd45a5fa0d0c4dac28ded394c8 diff --git a/pinsh.c b/pinsh.c new file mode 100644 index 0000000..220936a --- /dev/null +++ b/pinsh.c @@ -0,0 +1,166 @@ +#include "mc8051fun/mc8051fun.h" +#include "pinsh.h" + +void (*pinsh_output_chr)(char); +uint8_t pinsh_buf[PINSH_BUF_SIZE]; +volatile int pinsh_buf_pos=0; + + +void pinsh_irq_handler() +{ + if (RI) { + unsigned char b = SBUF; + if (b=='\r'){ + //pinsh_go=1; + pinsh_exec(pinsh_buf); + } else { + SBUF=b; + if (pinsh_buf_pos < PINSH_BUF_SIZE-1){ + pinsh_buf[pinsh_buf_pos++]=b; + pinsh_buf[pinsh_buf_pos]=0; + } + + } + RI=0; + + } + +} + +static void pinsh_output(const char *str) +{ + while(*str) + pinsh_output_chr(*str++); +} + +void pinsh_welcome_msg() +{ + pinsh_output("Pinsh 8051, V1.0\r\n"); +} + +static void show_port(int n) +{ + pinsh_output("P"); + uint8_t b = getport(n); + pinsh_output_chr(n+0x30); + pinsh_output("="); + for (int i=0; i<8; i++) { + if (b&(1<<(7-i))) + pinsh_output("1"); + else + pinsh_output("0"); + } + pinsh_output("\r\n"); +} + + + + +static void show_stat() +{ + for (int i=0; i<4; i++) + show_port(i); + +/* uint8_t b = P0; + show_port("P0",b); + b = P1; + show_port("P1",b); + b = P2; + show_port("P2",b); + b = P3; + show_port("P3",b); + */ +} + +static void syntax_error() +{ + pinsh_output("Syntax error\r\n"); + +} + + +static void assign_pin(int n, int p, char val) +{ + if (val){ + switch(n){ + case 0: + P0 |= 1<
0x33){ + syntax_error(); + return; + } + + if(cmd[1]==0){ + show_port(n-0x30); + return; + } + + if(cmd[1]=='='){ + assign_port(n-0x30,cmd+2); + return; + } + + + +} + +void pinsh_exec(const char *cmd) +{ + if(cmd[0]=='p') + pinsh_exec_p(cmd+1); +} diff --git a/pinsh.h b/pinsh.h new file mode 100644 index 0000000..abad3d7 --- /dev/null +++ b/pinsh.h @@ -0,0 +1,17 @@ +#ifndef PINSH_H_ +#define PINSH_H_ + +#define PINSH_BUF_SIZE 32 + +extern void (*pinsh_output_chr)(char); + +void pinsh_welcome_msg(); +void pinsh_exec(const char *cmd); + + +extern uint8_t pinsh_buf[PINSH_BUF_SIZE]; +extern volatile int pinsh_buf_pos; +void pinsh_uart_irq_handler(); + + +#endif