Initial commit

This commit is contained in:
7u83 2024-05-26 15:35:24 +02:00
parent b59c6e44e3
commit 29b4079482
5 changed files with 244 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "mc8051fun"]
path = mc8051fun
url = https://git.planix.org/7u83/mc8051fun.git

57
Makefile Normal file
View File

@ -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

1
mc8051fun Submodule

@ -0,0 +1 @@
Subproject commit 5c00e1633a9c10cd45a5fa0d0c4dac28ded394c8

166
pinsh.c Normal file
View File

@ -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<<p;
return;
case 1:
P1 |= 1<<p;
return;
case 2:
P2 |= 1<<p;
return;
case 3:
P3 |= 1<<p;
return;
}
}
switch(n){
case 0:
P0 &= (1<<p)^0xff;
return;
case 1:
P1 &= (1<<p)^0xff;
return;
case 2:
P2 &= (1<<p)^0xff;
return;
case 3:
P3 &= (1<<p)^0xff;
return;
}
}
static void assign_port(int n, const char*cmd)
{
for (int i=0; i<8 && cmd[i]!=0; i++)
{
if(cmd[i]!='0' && cmd[i]!='1'){
syntax_error();
return;
}
}
for (int i=0; i<8 && cmd[i]!=0; i++)
{
assign_pin(n,7-i,cmd[i]-0x30);
}
}
static void pinsh_exec_p(const char *cmd)
{
if (!cmd[0]){
show_stat();
return;
}
int n = cmd[0];
if(n<0x30 || n>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);
}

17
pinsh.h Normal file
View File

@ -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