├── tiny9 ├── 8051 │ └── include │ │ └── u.h ├── include │ ├── utf.h │ ├── umacro.h │ ├── libc.h │ └── bio.h ├── libc │ ├── debug.c │ ├── time.c │ ├── zoneinfo.h │ ├── printhex.c │ ├── strecpy.c │ ├── tm2sec.c │ ├── errstr.c │ └── ctime.c ├── libtask │ ├── primes │ ├── tcpproxy │ ├── testdelay │ ├── _build │ │ └── libtask.a │ ├── testdelay1.c │ ├── taskimplunix.h │ ├── makesun │ ├── rendez.c │ ├── testdelay.c │ ├── arm-ucontext.h │ ├── power-ucontext.h │ ├── primes.c │ ├── Makefile.sun │ ├── httpload.c │ ├── tcpproxy.c │ ├── Makefile │ ├── COPYRIGHT │ ├── qlock.c │ ├── mips-ucontext.h │ └── context.c ├── root.mk ├── libfmt │ ├── panic.c │ ├── fmthex.c │ ├── fmtlock.c │ ├── fmtstr.c │ ├── print.c │ ├── smprint.c │ ├── fprint.c │ ├── seprint.c │ ├── snprint.c │ ├── fmtfix.c │ ├── vfprint.c │ ├── fmtfdflush.c │ ├── fmtprint.c │ ├── fmtrune.c │ ├── vseprint.c │ ├── vsnprint.c │ ├── fmtnull.c │ ├── fmtfd.c │ ├── fmtvprint.c │ ├── sprint.c │ ├── dorfmt.c │ ├── vsmprint.c │ ├── pow10.c │ ├── fmtlocale.c │ ├── nan64.c │ ├── charstod.c │ ├── test.c │ └── fmtdef.h ├── README ├── build.mk ├── libutf │ ├── Makefile │ ├── utfdef.h │ ├── utflen.c │ ├── runetype.c │ ├── utfecpy.c │ ├── utfnlen.c │ ├── utfutf.c │ ├── utfrune.c │ └── utfrrune.c ├── unix │ └── include │ │ └── u.h ├── libbio │ ├── bfildes.c │ ├── bputc.c │ ├── bbuffered.c │ ├── bputrune.c │ ├── boffset.c │ ├── brdstr.c │ ├── bflush.c │ ├── bgetd.c │ ├── bwrite.c │ ├── bgetrune.c │ ├── bread.c │ ├── bprint.c │ ├── bgetc.c │ ├── bseek.c │ └── brdline.c └── tiny9.mk ├── .gitignore ├── cc11xx ├── cobs.h ├── erf │ ├── uboard.h │ └── board.c ├── Readme ├── cc1111 │ ├── uboard.h │ ├── board.c │ ├── hal.h │ └── hal.c ├── cc1110dk │ ├── uboard.h │ └── board.c ├── callping.c ├── u.c ├── noprint.c ├── guide ├── callwakeup.c ├── cobs.c ├── callrx.c ├── calltx.c ├── call.c ├── Notes ├── calltxrx.c ├── registers.py ├── pkt.c ├── timer.c ├── impl.h ├── uartsrv.c ├── Makefile ├── spisrv.c ├── usbsrv.c └── print.c ├── TODO ├── libpump ├── task.c ├── Makefile ├── pumpimpl.h ├── testpump.c ├── pumpchk.c └── pump.c ├── root.mk ├── include ├── table.h ├── pump.h ├── intel_hex.h ├── rcall.h └── pcall.h ├── Makefile ├── libradio ├── Makefile ├── rcall.c ├── fmt.c ├── rpigpio.c ├── testradio.c └── conv.c ├── cmd ├── Makefile ├── radio.c ├── impl.h ├── arg.h ├── u.c └── tty.c ├── pingrf.mk ├── LICENSE ├── lib └── intel_hex.c └── unix └── lib └── table.c /tiny9/include/utf.h: -------------------------------------------------------------------------------- 1 | #include "../libutf/utf.h" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */_build/ 2 | cc11xx/pkg 3 | cmd/pingrf 4 | -------------------------------------------------------------------------------- /tiny9/libc/debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int debug = 0; 5 | -------------------------------------------------------------------------------- /tiny9/libtask/primes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariusae/pingrf/HEAD/tiny9/libtask/primes -------------------------------------------------------------------------------- /tiny9/libtask/tcpproxy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariusae/pingrf/HEAD/tiny9/libtask/tcpproxy -------------------------------------------------------------------------------- /tiny9/libtask/testdelay: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariusae/pingrf/HEAD/tiny9/libtask/testdelay -------------------------------------------------------------------------------- /cc11xx/cobs.h: -------------------------------------------------------------------------------- 1 | 2 | uint8 stuff(uint8 *p, uint8 n); 3 | void unstuff(uint8 h, uint8 *p, uint8 n); 4 | -------------------------------------------------------------------------------- /tiny9/libtask/_build/libtask.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariusae/pingrf/HEAD/tiny9/libtask/_build/libtask.a -------------------------------------------------------------------------------- /cc11xx/erf/uboard.h: -------------------------------------------------------------------------------- 1 | #define GREEN P1_7 2 | #define RED P1_7 3 | 4 | #define LEDBITS (BIT(7)) 5 | 6 | #define MHZ 24 7 | -------------------------------------------------------------------------------- /cc11xx/Readme: -------------------------------------------------------------------------------- 1 | 2 | To-do 3 | 4 | * Use a watchdog to detect stuck firmware 5 | * UART flow control 6 | * LEDs for rx/tx 7 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | 3 | Responses that still need work: 4 | 5 | - Status response while pump is rewinding or otherwise 6 | suspended. 7 | -------------------------------------------------------------------------------- /cc11xx/cc1111/uboard.h: -------------------------------------------------------------------------------- 1 | #define GREEN P1_1 2 | #define RED P1_1 3 | 4 | #define LEDBITS (BIT(1)) 5 | 6 | #define MHZ 24 7 | -------------------------------------------------------------------------------- /tiny9/libtask/testdelay1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | taskmain(int argc, char *argv[]) 5 | { 6 | taskdelay(1000); 7 | } 8 | -------------------------------------------------------------------------------- /libpump/task.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | taskdelay(uint ms) 6 | { 7 | return usleep(1000*ms); 8 | } 9 | -------------------------------------------------------------------------------- /cc11xx/cc1110dk/uboard.h: -------------------------------------------------------------------------------- 1 | #define GREEN P1_0 2 | #define RED P1_1 3 | 4 | #define LEDBITS (BIT(0) | BIT(1)) 5 | 6 | #define MHZ 26 7 | -------------------------------------------------------------------------------- /tiny9/libc/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern long time(long*); 5 | 6 | long 7 | now() 8 | { 9 | return time(0); 10 | } 11 | -------------------------------------------------------------------------------- /root.mk: -------------------------------------------------------------------------------- 1 | ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) 2 | 3 | include $(ROOT)/tiny9/build.mk 4 | include $(ROOT)/tiny9/tiny9.mk 5 | include $(ROOT)/pingrf.mk 6 | -------------------------------------------------------------------------------- /include/table.h: -------------------------------------------------------------------------------- 1 | typedef struct Table Table; 2 | 3 | Table* tableopen(char *, uint, uint); 4 | int tablewrite(Table*, void*, void*); 5 | void* tablelookup(Table*, void*); 6 | -------------------------------------------------------------------------------- /tiny9/root.mk: -------------------------------------------------------------------------------- 1 | ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) 2 | 3 | include $(ROOT)/tiny9/build.mk 4 | include $(ROOT)/tiny9/tiny9.mk 5 | include $(ROOT)/pingrf.mk 6 | -------------------------------------------------------------------------------- /cc11xx/callping.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | void 4 | callping(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag) 5 | { 6 | USED(waitflag); 7 | USED(clearflag); 8 | 9 | c->type = Rping; 10 | *state = Reply; 11 | } 12 | -------------------------------------------------------------------------------- /cc11xx/u.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | void putchar(char c); 4 | 5 | void 6 | abort() 7 | { 8 | flag |= Fpanic; 9 | 10 | for(;;){ 11 | RED=1; 12 | GREEN=0; 13 | sleep(1000); 14 | RED=0; 15 | sleep(1000); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C libradio 3 | $(MAKE) -C libpump 4 | $(MAKE) -C cmd 5 | $(MAKE) -C cc11xx 6 | 7 | clean: 8 | $(MAKE) -C libradio clean 9 | $(MAKE) -C libpump clean 10 | $(MAKE) -C cmd clean 11 | $(MAKE) -C cc11xx clean 12 | -------------------------------------------------------------------------------- /cc11xx/noprint.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | void abort(); 4 | 5 | void 6 | printinit() 7 | { 8 | } 9 | 10 | void 11 | putchar(char c) 12 | { 13 | USED(c); 14 | } 15 | 16 | void 17 | panic(char *fmt, ...) 18 | { 19 | USED(fmt); 20 | abort(); 21 | } 22 | -------------------------------------------------------------------------------- /tiny9/libfmt/panic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fmtdef.h" 4 | 5 | void 6 | panic(char *fmt, ...) 7 | { 8 | va_list arg; 9 | 10 | va_start(arg, fmt); 11 | vfprint(2, fmt, arg); 12 | va_end(arg); 13 | fprint(2, "\n"); 14 | abort(); 15 | } -------------------------------------------------------------------------------- /tiny9/libtask/taskimplunix.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | //#if USE_UCONTEXT 7 | //#include 8 | //#endif 9 | #include 10 | 11 | #define TASKUNIX 1 12 | -------------------------------------------------------------------------------- /cc11xx/cc1111/board.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | boardprintinit() 5 | { 6 | /* USART1 Alt. 1 */ 7 | PERCFG = (PERCFG & ~PERCFG_U1CFG) | PERCFG_U0CFG; 8 | P0SEL |= BIT(4) | BIT(5); 9 | 10 | /* Baudrate = 57.6 (U1BAUD.BAUD_M = 131, U1GCR.BAUD_E = 8) */ 11 | U1BAUD = 59; 12 | U1GCR = (U1GCR & ~U1GCR_BAUD_E) | 11; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /cc11xx/erf/board.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | boardprintinit() 5 | { 6 | /* USART1 Alt. 2 */ 7 | PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U1CFG; 8 | P1SEL |= BIT(4) | BIT(5) | BIT(6) | BIT(7); 9 | 10 | /* Baudrate = 57.6 kbps (U1BAUD.BAUD_M = 34, U1GCR.BAUD_E = 11) */ 11 | U1BAUD = 34; 12 | U1GCR = (U1GCR & ~U1GCR_BAUD_E) | 11; 13 | } 14 | -------------------------------------------------------------------------------- /cc11xx/cc1110dk/board.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | boardprintinit() 5 | { 6 | /* USART1 Alt. 2 */ 7 | PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U1CFG; 8 | P1SEL |= BIT(4) | BIT(5) | BIT(6) | BIT(7); 9 | 10 | /* Baudrate = 57.6 kbps (U1BAUD.BAUD_M = 34, U1GCR.BAUD_E = 11) */ 11 | U1BAUD = 34; 12 | U1GCR = (U1GCR & ~U1GCR_BAUD_E) | 11; 13 | } 14 | -------------------------------------------------------------------------------- /cc11xx/guide: -------------------------------------------------------------------------------- 1 | acmemake DEBUG=1 clean 2 | acmemake DEBUG=1 clean flimpl.h 3 | acmemake DEBUG=1 flimpl.h 4 | 5 | acmemake DEBUG=1 clean all 6 | acmemake DEBUG=1 7 | 8 | acmemake DEBUG=1 UART=1 flimpl.h 9 | 10 | acmemake UART=1 flimpl.h 11 | 12 | cc-tool --reset 13 | 14 | acmemake clean flimpl.h 15 | 16 | win termcat /dev/tty.usbserial 17 | 18 | 19 | /dev/tty.usbserial4 20 | -------------------------------------------------------------------------------- /libradio/Makefile: -------------------------------------------------------------------------------- 1 | all: test 2 | test: testradio 3 | 4 | S=../ 5 | include $(S)/tiny9/build.mk 6 | include $(S)/tiny9/tiny9.mk 7 | include $(S)/pingrf.mk 8 | 9 | OBJECTS+=\ 10 | $(TINY9OBJECTS)\ 11 | $(LIBRADIOOBJECTS) 12 | 13 | $(O)/testradio: $(O)/testradio.o $(OFILES) $(HFILES) 14 | $(CC) -o $(O)/testradio $^ 15 | 16 | testradio: $(O)/testradio 17 | $(O)/testradio 18 | -------------------------------------------------------------------------------- /cmd/Makefile: -------------------------------------------------------------------------------- 1 | all: pingrf 2 | HASLIBTASK := 1 3 | 4 | include ../root.mk 5 | 6 | 7 | OBJECTS+=\ 8 | $(TINY9OBJECTS)\ 9 | $(LIBPUMPOBJECTS)\ 10 | $(LIBRADIOOBJECTS)\ 11 | $(PINGRFOBJECTS)\ 12 | $(LIBTASKOBJECTS)\ 13 | $(RADIODRIVEROBJECTS) 14 | 15 | OBJECTS+=\ 16 | u.o 17 | 18 | CLEANFILES+=pingrf 19 | 20 | pingrf: $(O)/pingrf.o $(OFILES) $(HFILES) 21 | $(CC) -o pingrf $^ 22 | -------------------------------------------------------------------------------- /libpump/Makefile: -------------------------------------------------------------------------------- 1 | all: test 2 | test: testpump 3 | 4 | S=../ 5 | include $(S)/tiny9/build.mk 6 | include $(S)/tiny9/tiny9.mk 7 | include $(S)/pingrf.mk 8 | 9 | OBJECTS+=\ 10 | $(TINY9OBJECTS)\ 11 | $(PINGRFOBJECTS)\ 12 | $(LIBPUMPOBJECTS)\ 13 | $(LIBRADIOOBJECTS) 14 | 15 | 16 | $(O)/testpump: $(O)/testpump.o $(OFILES) $(HFILES) 17 | $(CC) -o $(O)/testpump $^ 18 | 19 | testpump: $(O)/testpump 20 | $(O)/testpump 21 | -------------------------------------------------------------------------------- /tiny9/libtask/makesun: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case "x$CC" in 4 | x|xcc) 5 | CC=cc 6 | CFLAGS="-mt -g -O -c -xCC -D__sun__ -I." 7 | ;; 8 | xgcc) 9 | CC=gcc 10 | CFLAGS="-Wall -c -I." 11 | ;; 12 | *) 13 | echo 'unknown $CC' 14 | exit 1 15 | esac 16 | 17 | u=`uname` 18 | v=`uname -r` 19 | s=`echo $u$v | tr '. ' '__'` 20 | CFLAGS="$CFLAGS -D__${s}__" 21 | 22 | make "CC=$CC" "CFLAGS=$CFLAGS" "ASM=" "TCPLIBS=-lsocket -lnsl" 23 | -------------------------------------------------------------------------------- /cc11xx/callwakeup.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | enum 4 | { 5 | Txing = Nstate 6 | }; 7 | 8 | uint8 9 | callwakeup(Rcall *c, uint8 *state) 10 | { 11 | switch(*state){ 12 | case Idle: 13 | rfwakeup(c->nwakeup); 14 | *state = Txing; 15 | return Frftx; 16 | 17 | case Txing: 18 | c->type = Rwakeup; 19 | *state = Reply; 20 | return 0; 21 | 22 | default: 23 | panic("Unknown state %d", *state); 24 | return 0; 25 | } 26 | } -------------------------------------------------------------------------------- /cmd/radio.c: -------------------------------------------------------------------------------- 1 | 2 | struct 3 | { 4 | int (*call)(void*, Rcall*); 5 | void* (*open)(char*); 6 | } Radio; 7 | 8 | /* 9 | make it all thread oriented 10 | 11 | desc = tty->open("..."); 12 | 13 | for(;;){ 14 | rcall = ... 15 | send(rcall) 16 | } 17 | 18 | 19 | so a radio drive is a way of getting a channel, basically. 20 | Channel* open(...); 21 | 22 | maybe a reset channel, too? 23 | 24 | 25 | 26 | rcall(..): 27 | send(....); 28 | recv(...); 29 | */ 30 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmthex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fmtdef.h" 4 | 5 | static char digits[] = "0123456789abcdef"; 6 | 7 | int 8 | hexstrfmt(Fmt *f) 9 | { 10 | uint8 *buf; 11 | int n, i; 12 | 13 | buf = va_arg(f->args, uint8*); 14 | n = va_arg(f->args, uint); 15 | 16 | for(i=0; i 2 | #include 3 | #include 4 | #include 5 | #include "pcall.h" 6 | #include "pump.h" 7 | 8 | uint32 crc32(void*, uint); 9 | int pumpchk(void *v, uint n, uint32 *chkp); 10 | int pumpchkhd(void *v); 11 | int pumpchkpayload(void *v); 12 | 13 | extern uint8 challengetab[256]; 14 | 15 | int _pcall(Pcall *tx, Pcall *rx); 16 | int _presume(); 17 | int _padjourn(); 18 | int _preset(); 19 | int _pcallsimple(int type); 20 | 21 | /* libtask */ 22 | int taskdelay(uint); 23 | -------------------------------------------------------------------------------- /tiny9/README: -------------------------------------------------------------------------------- 1 | Tiny9 is a set of base libraries used for writing C programs that 2 | may be run in on an embedded system (e.g., on an ARM M0 Cortex) as 3 | well as on Unix systems. 4 | 5 | Most of the code is from Plan 9, Inferno, Plan9port, and Russ Cox's 6 | libtask. 7 | 8 | Among the changes made are: 9 | 10 | Libtask 11 | - Ported libtask to the ARM M0 Cortex 12 | - Added Unix domain socket support 13 | 14 | Plan 9 libc 15 | - Ported the Plan 9 time library to be free of Unix dependencies; 16 | timezone information is hardcoded. 17 | -------------------------------------------------------------------------------- /tiny9/build.mk: -------------------------------------------------------------------------------- 1 | TARG ?= unix 2 | 3 | #HEADERS += $(ROOT)/lib/$(TARG)/u.h 4 | 5 | OFILES = $(addprefix $(O)/, $(OBJECTS)) 6 | HFILES = $(HEADERS) 7 | 8 | ifdef DEBUG 9 | CFLAGS += -DDEBUG -g 10 | endif 11 | 12 | O = _build 13 | 14 | $(OFILES): $(HFILES) 15 | 16 | $(O)/%.o : %.c 17 | @mkdir -p $(dir $@) 18 | @echo "cc -o$@ $<" 19 | @$(CC) -c $(CFLAGS) -o$@ $< 20 | 21 | $(O)/%.o : %.S 22 | @mkdir -p $(dir $@) 23 | @echo "cc -o$@ $<" 24 | @$(CC) -c $(CFLAGS) -o$@ $< 25 | 26 | config: 27 | @echo $(O) 28 | @echo $(OFILES) 29 | @echo $(HFILES) 30 | 31 | clean: 32 | /bin/rm -rf $(O) $(CLEANFILES) 33 | -------------------------------------------------------------------------------- /pingrf.mk: -------------------------------------------------------------------------------- 1 | PINGRF := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) 2 | 3 | vpath %.c $(PINGRF) 4 | vpath %.h $(PINGRF) 5 | 6 | PINGRFOBJECTS=\ 7 | $(TARG)/lib/table.o 8 | 9 | LIBPUMPOBJECTS=\ 10 | libpump/conv.o\ 11 | libpump/crc32.o\ 12 | libpump/pcall.o\ 13 | libpump/pump.o\ 14 | libpump/pumpchk.o 15 | 16 | ifndef HASLIBTASK 17 | LIBPUMPOBJECTS+=\ 18 | libpump/task.o 19 | endif 20 | 21 | LIBRADIOOBJECTS=\ 22 | libradio/conv.o\ 23 | libradio/fmt.o 24 | 25 | RADIODRIVEROBJECTS=\ 26 | lib/intel_hex.o\ 27 | libradio/driver.o\ 28 | libradio/rpigpio.o 29 | 30 | CFLAGS+=\ 31 | -I$(PINGRF)/include 32 | -------------------------------------------------------------------------------- /cc11xx/cobs.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* TODO: this needs to be robust to malformed messages. */ 4 | 5 | uint8 6 | stuff(uint8 *p, uint8 n) 7 | { 8 | uint8 header = n+1, *cp = nil; 9 | uint8 *bp = p, *ep = bp + n; 10 | 11 | for(; p 2 | #include 3 | #include "rcall.h" 4 | 5 | int 6 | rcall(Rcall *tx, Rcall *rx) 7 | { 8 | static uint8 buf[RCALLMAX]; 9 | 10 | if(tx->type == Treset){ 11 | rx->type = Rreset; 12 | return radioreset(); 13 | } 14 | 15 | if(convR2M(tx, buf, sizeof buf) == 0){ 16 | werrstr("invalid tx message"); 17 | return -1; 18 | } 19 | 20 | if(radiorpc(buf) < 0) 21 | return -1; 22 | 23 | if(convM2R(buf, buf[0], rx) == 0){ 24 | werrstr("invalid rx message"); 25 | return -1; 26 | } 27 | 28 | if(rx->type != tx->type+1 && rx->type != Rerr){ 29 | werrstr("bad rx Rcall"); 30 | return -1; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /tiny9/libc/zoneinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is distributred under the Lucent Public License, Version 1.02. 4 | See ../../LUCENT 5 | 6 | Copyright © 2000-2009 Lucent Technologies. All Rights Reserved. 7 | Portions Copyright © 2001-2008 Russ Cox 8 | Portions Copyright © 2008-2009 Google Inc. 9 | */ 10 | 11 | #define zonetinfo _p9zonetinfo 12 | #define zonedump _p9zonedump 13 | #define zonelookuptinfo _p9zonelookuptinfo 14 | 15 | typedef long tlong; 16 | 17 | typedef 18 | struct Tinfo 19 | { 20 | long t; 21 | int tzoff; 22 | int dlflag; 23 | char *zone; 24 | } Tinfo; 25 | 26 | extern int zonelookuptinfo(Tinfo*, tlong); 27 | extern int zonetinfo(Tinfo*, int); 28 | extern void zonedump(int fd); 29 | 30 | -------------------------------------------------------------------------------- /tiny9/libc/printhex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int 5 | _isprint(char c) 6 | { 7 | return c >= ' ' && c <= '~'; 8 | } 9 | 10 | void 11 | printhex(uint8 *buf, uint n) 12 | { 13 | int i, j; 14 | 15 | for(i=0; i < n/16; i++){ 16 | for(j=0; j < 16; j+=2) 17 | print("%02x %02x ", buf[16*i+j], buf[16*i+j+1]); 18 | for(j=0; j < 16; j++) 19 | print("%c", _isprint(buf[16*i+j]) ? buf[16*i+j] : '.'); 20 | print("\n"); 21 | } 22 | 23 | for(j=i*16; j 0) 28 | print(" "); 29 | print(" "); 30 | 31 | for(j=i*16; jwaiting, taskrunning); 10 | if(r->l) 11 | qunlock(r->l); 12 | taskstate("sleep"); 13 | taskswitch(); 14 | if(r->l) 15 | qlock(r->l); 16 | } 17 | 18 | static int 19 | _taskwakeup(Rendez *r, int all) 20 | { 21 | int i; 22 | Task *t; 23 | 24 | for(i=0;; i++){ 25 | if(i==1 && !all) 26 | break; 27 | if((t = r->waiting.head) == nil) 28 | break; 29 | deltask(&r->waiting, t); 30 | taskready(t); 31 | } 32 | return i; 33 | } 34 | 35 | int 36 | taskwakeup(Rendez *r) 37 | { 38 | return _taskwakeup(r, 0); 39 | } 40 | 41 | int 42 | taskwakeupall(Rendez *r) 43 | { 44 | return _taskwakeup(r, 1); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /tiny9/libtask/testdelay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | enum { STACK = 32768 }; 9 | 10 | Channel *c; 11 | 12 | void 13 | delaytask(void *v) 14 | { 15 | taskdelay((int)v); 16 | printf("awake after %d ms\n", (int)v); 17 | chansendul(c, 0); 18 | } 19 | 20 | void 21 | taskmain(int argc, char **argv) 22 | { 23 | int i, n; 24 | 25 | c = chancreate(sizeof(unsigned long), 0); 26 | 27 | n = 0; 28 | for(i=1; itimeoutms > 0){ 20 | alarm(c->timeoutms); 21 | *waitflag |= Falarm; 22 | } 23 | 24 | break; 25 | 26 | case Waiting: 27 | if(*waitflag&Falarm){ 28 | rfidle(); 29 | c->type = Rerr; 30 | c->err = Etimeout; 31 | }else{ 32 | memcpy(&c->pkt, rfrxbuf, sizeof c->pkt); 33 | c->type = Rrx; 34 | } 35 | alarm(0); 36 | *state = Reply; 37 | *waitflag = 0; 38 | break; 39 | 40 | default: 41 | panic("Unknown state %d", *state); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /include/pump.h: -------------------------------------------------------------------------------- 1 | 2 | typedef struct 3 | { 4 | uint month; 5 | uint day; 6 | uint hour; 7 | uint minute; 8 | uint year; 9 | 10 | uint basal; 11 | 12 | uint insulinleft; 13 | int temp; 14 | uint temptime; 15 | uint temptotal; 16 | 17 | uint iob; 18 | uint lastbolus; 19 | 20 | /* Temporary. */ 21 | uint comboactive; 22 | uint comboyear; 23 | uint combomonth; 24 | uint comboday; 25 | 26 | uint combostarthour; 27 | uint combostartminute; 28 | uint comboendhour; 29 | uint comboendminute; 30 | uint combodelivered; 31 | uint combototal; 32 | 33 | uint dailybasal; 34 | uint dailybolus; 35 | 36 | uint haswarning; 37 | } Pstat; 38 | 39 | 40 | int pstat(Pstat*); 41 | int pbolus(uint insulin, uint minutes); 42 | int pcancel(); 43 | int pclearwarning(); 44 | int pping(); 45 | -------------------------------------------------------------------------------- /tiny9/libtask/arm-ucontext.h: -------------------------------------------------------------------------------- 1 | typedef struct sigaltstack { 2 | void *ss_sp; 3 | int ss_flags; 4 | size_t ss_size; 5 | } stack_t; 6 | 7 | #define NGREG 15 8 | 9 | typedef int greg_t; 10 | typedef greg_t gregset_t[NGREG]; 11 | 12 | typedef struct { 13 | /* 14 | unsigned regmask; 15 | unsigned status; 16 | */ 17 | gregset_t gregs; 18 | greg_t pc; 19 | /* 20 | fpregset_t fpregs; 21 | unsigned fp_owned; 22 | unsigned fpc_csr; 23 | unsigned fpc_eir; 24 | unsigned used_math; 25 | unsigned dsp; 26 | greg_t mdhi; 27 | greg_t mdlo; 28 | unsigned long hi1; 29 | unsigned long lo1; 30 | unsigned long hi2; 31 | unsigned long lo2; 32 | unsigned long hi3; 33 | unsigned long lo3; 34 | */ 35 | } mcontext_t; 36 | 37 | 38 | typedef struct ucontext { 39 | mcontext_t uc_mcontext; 40 | stack_t uc_stack; 41 | } ucontext_t; 42 | 43 | -------------------------------------------------------------------------------- /cmd/impl.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include "arg.h" 18 | 19 | /* The tty file descriptor. */ 20 | int tty; 21 | 22 | void* emalloc(uint n); 23 | char* estrdup(char *s); 24 | int readn(int fd, void *buf, uint n); 25 | int unhexlify(char *h, void* buf, uint *n); 26 | void printhex(uint8 *buf, uint n); 27 | 28 | int rpigpioinit(); 29 | int rpigpioradioreset(); 30 | 31 | int ttysetblocking(int, int); 32 | int ttysetattr(int, int, int); 33 | 34 | int hexreadn(int, void*, uint); 35 | ssize_t hexwrite(int, const void*, size_t); -------------------------------------------------------------------------------- /cc11xx/calltx.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | enum 4 | { 5 | Txing = Nstate, 6 | Preambling 7 | }; 8 | 9 | void 10 | calltx(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag) 11 | { 12 | USED(clearflag); 13 | 14 | switch(*state){ 15 | case Idle: 16 | memcpy(rftxbuf, c->pkt, sizeof rftxbuf); 17 | if(c->preamblems > 0){ 18 | alarm(c->preamblems); 19 | rftxpreamble(); 20 | *state = Preambling; 21 | *waitflag = Falarm; 22 | }else{ 23 | rftx(0); 24 | *state = Txing; 25 | *waitflag = Frftx; 26 | } 27 | 28 | break; 29 | 30 | case Preambling: 31 | rftx(Txcontinue); 32 | *state = Txing; 33 | *waitflag = Frftx; 34 | break; 35 | 36 | case Txing: 37 | c->type = Rtx; 38 | *state = Reply; 39 | *waitflag = 0; 40 | break; 41 | 42 | default: 43 | panic("Unknown state %d", *state); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tiny9/8051/include/u.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | typedef unsigned short ushort; 6 | typedef unsigned char uchar; 7 | typedef unsigned long ulong; 8 | typedef unsigned int uint; 9 | typedef signed char schar; 10 | 11 | /* Technically unavailable. We fudge it. */ 12 | /*typedef long long vlong; 13 | typedef unsigned long long uvlong;*/ 14 | typedef long vlong; 15 | typedef unsigned long uvlong; 16 | 17 | typedef unsigned long uintptr; 18 | typedef unsigned long usize; 19 | 20 | typedef unsigned char uint8; 21 | typedef char int8; 22 | typedef unsigned int uint16; 23 | typedef int int16; 24 | typedef unsigned long uint32; 25 | typedef long int32; 26 | 27 | #define PACKEDSTRUCT 28 | #define REENTRANT __reentrant 29 | #define XDATA __xdata 30 | 31 | #define USED(x) if(x){}else{} 32 | 33 | #define nil ((void*)0) 34 | -------------------------------------------------------------------------------- /cc11xx/call.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | void callrx(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag); 4 | void calltx(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag); 5 | void calltxrx(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag); 6 | void callwakeup(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag); 7 | void callping(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag); 8 | 9 | void 10 | call(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag) 11 | { 12 | switch(c->type){ 13 | default: 14 | c->type = Rerr; 15 | c->err = Ebadcall; 16 | *state = Reply; 17 | return; 18 | 19 | case Trx: callrx(c, state, waitflag, clearflag); break; 20 | case Ttx: calltx(c, state, waitflag, clearflag); break; 21 | case Ttxrx: calltxrx(c, state, waitflag, clearflag); break; 22 | case Tping: callping(c, state, waitflag, clearflag); break; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cc11xx/Notes: -------------------------------------------------------------------------------- 1 | 2 | - After a timeout, the radio is left in RX mode 3 | 4 | 5 | Note that if an STX strobe is issued but no data is written to the 6 | RFD register after the following assertion of the RFTXRXIF flag, 7 | the radio will start sending preamble without entering TX_UNDERFLOW 8 | state. 9 | 10 | 11 | 12 | PKTCTRL1 = 0xC0 13 | PKTCTRL0 = 0x02 14 | ADDR = 0x0 15 | CHANNR = 0x00 16 | FSCTRL1 = 0x06 17 | FSCTRL0 = 0x00 18 | FREQ2 = 0x00 19 | FREQ1 = 0x00 20 | FREQ0 = 0x00 21 | MDMCFG4 = 0xC9 22 | MDMCFG3 = 0x83 23 | MDMCFG2 = 0x01 24 | MDMCFG1 = 0x23 25 | MDMCFG0 = 0x80 26 | DEVIATN = 0x32 27 | MCSM2 = 0x0F 28 | MCSM1 = 0x0f 29 | MCSM0 = 0x38 30 | FOCCFG = 0x16 31 | BSCFG = 0x6C 32 | AGCCTRL2 = 0x43 33 | AGCCTRL1 = 0x40 34 | AGCCTRL0 = 0x91 35 | WOREVT1 = 0x00 36 | WOREVT0 = 0x00 37 | WORCTRL = 0x79 38 | FREND1 = 0x56 39 | FREND0 = 0x10 40 | FSCAL3 = 0xE9 41 | FSCAL2 = 0x2A 42 | FSCAL1 = 0x00 43 | FSCAL0 = 0x1F 44 | -------------------------------------------------------------------------------- /tiny9/libutf/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2010 The Go Authors. All rights reserved. 2 | # Use of this source code is governed by a BSD-style 3 | # license that can be found in the LICENSE file. 4 | 5 | # The library is built by the Makefile in the parent directory. 6 | # This Makefile only builds mkrunetype. 7 | # GOROOT, GOOS, and GOARCH must be set explicitly. 8 | 9 | TARG=mkrunetype 10 | 11 | UnicodeData-%.txt: 12 | curl http://www.unicode.org/Public/$*/ucd/UnicodeData.txt >_$@ 13 | mv _$@ $@ 14 | 15 | mkrunetype: mkrunetype.c 16 | cc -I../../../include -o mkrunetype -L$(GOROOT)/pkg/obj/$(GOOS)_$(GOARCH)/ mkrunetype.c -l9 17 | 18 | runetypebody-%.c: mkrunetype UnicodeData-%.txt 19 | mkrunetype -p UnicodeData-$*.txt >_$@ 20 | mv _$@ $@ 21 | 22 | CLEANFILES+=UnicodeData.txt 23 | 24 | UNICODE_VERSION=6.0.0 25 | 26 | test: mkrunetype UnicodeData-$(UNICODE_VERSION).txt 27 | mkrunetype -c UnicodeData-$(UNICODE_VERSION).txt 28 | 29 | clean: 30 | rm -f UnicodeData.txt mkrunetype -------------------------------------------------------------------------------- /cc11xx/cc1111/hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CC Bootloader - Hardware Abstraction Layer 3 | * 4 | * Fergus Noble (c) 2011 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 18 | */ 19 | 20 | #ifndef _HAL_H_ 21 | #define _HAL_H_ 22 | 23 | void setup_led(); 24 | void led_on(); 25 | void led_off(); 26 | 27 | void usb_up(); 28 | void usb_down(); 29 | 30 | #endif // _HAL_H_ 31 | -------------------------------------------------------------------------------- /libradio/fmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "rcall.h" 4 | 5 | #ifdef CC1110 6 | static const char* const __code strmsgtype[] = { 7 | #else 8 | static char* strmsgtype[] = { 9 | #endif 10 | "Nop", "Trx", "Rrx", "Ttx", "Rtx", "Ttxrx", "Rtxrx", "Tping", "Rping" 11 | }; 12 | 13 | int 14 | rcallfmt(Fmt *f) 15 | { 16 | Rcall *c = va_arg(f->args, Rcall*); 17 | 18 | if(c->type == Treset) 19 | fmtprint(f, "Treset "); 20 | else if(c->type == Rreset) 21 | fmtprint(f, "Rreset "); 22 | else if(c->type >= Rerr){ 23 | fmtprint(f, "Rerr "); 24 | switch(c->err){ 25 | case Emissing: fmtprint(f, "missing"); break; 26 | case Ebadcall: fmtprint(f, "bad call"); break; 27 | case Etimeout: fmtprint(f, "timeout"); break; 28 | } 29 | } 30 | else if(c->type < nelem(strmsgtype)) 31 | fmtprint(f, "%s", strmsgtype[c->type]); 32 | else 33 | fmtprint(f, "Unknown<%d>", c->type); 34 | 35 | if(c->type == Trx || c->type == Ttxrx) 36 | fmtprint(f, " timeout %dms", c->timeoutms); 37 | if(c->type == Ttx || c->type == Ttxrx) 38 | fmtprint(f, " preamble %dms", c->preamblems); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | void 24 | __fmtlock(void) 25 | { 26 | } 27 | 28 | void 29 | __fmtunlock(void) 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /tiny9/libtask/power-ucontext.h: -------------------------------------------------------------------------------- 1 | #define setcontext(u) _setmcontext(&(u)->mc) 2 | #define getcontext(u) _getmcontext(&(u)->mc) 3 | typedef struct mcontext mcontext_t; 4 | typedef struct ucontext ucontext_t; 5 | struct mcontext 6 | { 7 | ulong pc; /* lr */ 8 | ulong cr; /* mfcr */ 9 | ulong ctr; /* mfcr */ 10 | ulong xer; /* mfcr */ 11 | ulong sp; /* callee saved: r1 */ 12 | ulong toc; /* callee saved: r2 */ 13 | ulong r3; /* first arg to function, return register: r3 */ 14 | ulong gpr[19]; /* callee saved: r13-r31 */ 15 | /* 16 | // XXX: currently do not save vector registers or floating-point state 17 | // ulong pad; 18 | // uvlong fpr[18]; / * callee saved: f14-f31 * / 19 | // ulong vr[4*12]; / * callee saved: v20-v31, 256-bits each * / 20 | */ 21 | }; 22 | 23 | struct ucontext 24 | { 25 | struct { 26 | void *ss_sp; 27 | uint ss_size; 28 | } uc_stack; 29 | sigset_t uc_sigmask; 30 | mcontext_t mc; 31 | }; 32 | 33 | void makecontext(ucontext_t*, void(*)(void), int, ...); 34 | int swapcontext(ucontext_t*, const ucontext_t*); 35 | int _getmcontext(mcontext_t*); 36 | void _setmcontext(const mcontext_t*); 37 | 38 | -------------------------------------------------------------------------------- /tiny9/libtask/primes.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2005 Russ Cox, MIT; see COPYRIGHT */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int quiet; 9 | int goal; 10 | int buffer; 11 | 12 | void 13 | primetask(void *arg) 14 | { 15 | Channel *c, *nc; 16 | int p, i; 17 | c = arg; 18 | 19 | p = chanrecvul(c); 20 | if(p > goal) 21 | taskexitall(0); 22 | if(!quiet) 23 | printf("%d\n", p); 24 | nc = chancreate(sizeof(unsigned long), buffer); 25 | taskcreate(primetask, nc, 32768); 26 | for(;;){ 27 | i = chanrecvul(c); 28 | if(i%p) 29 | chansendul(nc, i); 30 | } 31 | } 32 | 33 | void 34 | taskmain(int argc, char **argv) 35 | { 36 | int i; 37 | Channel *c; 38 | 39 | if(argc>1) 40 | goal = atoi(argv[1]); 41 | else 42 | goal = 100; 43 | printf("goal=%d\n", goal); 44 | 45 | c = chancreate(sizeof(unsigned long), buffer); 46 | taskcreate(primetask, c, 32768); 47 | for(i=2;; i++) 48 | chansendul(c, i); 49 | } 50 | 51 | void* 52 | emalloc(unsigned long n) 53 | { 54 | return calloc(n ,1); 55 | } 56 | 57 | long 58 | lrand(void) 59 | { 60 | return rand(); 61 | } 62 | -------------------------------------------------------------------------------- /cc11xx/calltxrx.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | enum 4 | { 5 | Txrxing = Nstate, 6 | Preambling 7 | }; 8 | 9 | void 10 | calltxrx(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag) 11 | { 12 | switch(*state){ 13 | case Idle: 14 | memcpy(rftxbuf, c->pkt, sizeof rftxbuf); 15 | 16 | if(c->preamblems > 0){ 17 | alarm(c->preamblems); 18 | rftxpreamble(); 19 | *state = Preambling; 20 | *waitflag = Falarm; 21 | }else{ 22 | rftx(Txrx); 23 | goto txrxing; 24 | } 25 | 26 | break; 27 | 28 | case Preambling: 29 | rftx(Txrx|Txcontinue); 30 | 31 | txrxing: 32 | *state = Txrxing; 33 | *waitflag = Frfrx; 34 | *clearflag = Frftx; 35 | if(c->timeoutms > 0){ 36 | alarm(c->timeoutms); 37 | *waitflag |= Falarm; 38 | } 39 | break; 40 | 41 | case Txrxing: 42 | rfidle(); 43 | if(*waitflag&Falarm){ 44 | c->type = Rerr; 45 | c->err = Etimeout; 46 | }else{ 47 | c->type = Rtxrx; 48 | memcpy(&c->pkt, rfrxbuf, sizeof c->pkt); 49 | } 50 | alarm(0); 51 | *state = Reply; 52 | *waitflag = 0; 53 | break; 54 | 55 | default: 56 | panic("Unknown state %d", *state); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tiny9/libtask/Makefile.sun: -------------------------------------------------------------------------------- 1 | LIB=libtask.a 2 | 3 | OFILES=\ 4 | channel.o\ 5 | context.o\ 6 | fd.o\ 7 | net.o\ 8 | print.o\ 9 | qlock.o\ 10 | rendez.o\ 11 | task.o\ 12 | 13 | all: $(LIB) primes tcpproxy testdelay 14 | 15 | $(OFILES): taskimpl.h task.h 386-ucontext.h power-ucontext.h 16 | 17 | AS=as 18 | CC=cc 19 | CFLAGS=-c -I. -g 20 | 21 | %.o: %.S 22 | $(AS) $*.S 23 | 24 | %.o: %.c 25 | $(CC) $(CFLAGS) $*.c 26 | 27 | $(LIB): $(OFILES) 28 | ar rvc $(LIB) $(OFILES) 29 | 30 | primes: primes.o $(LIB) 31 | $(CC) -o primes primes.o $(LIB) 32 | 33 | tcpproxy: tcpproxy.o $(LIB) 34 | $(CC) -o tcpproxy tcpproxy.o $(LIB) 35 | 36 | httpload: httpload.o $(LIB) 37 | $(CC) -o httpload httpload.o $(LIB) 38 | 39 | stdlogger: stdlogger.o $(LIB) 40 | $(CC) -o stdlogger stdlogger.o $(LIB) 41 | 42 | testdelay: testdelay.o $(LIB) 43 | $(CC) -o testdelay testdelay.o $(LIB) 44 | 45 | clock: clock.o $(LIB) 46 | $(CC) -o clock clock.o $(LIB) 47 | 48 | clean: 49 | rm *.o tcpproxy primes $(LIB) 50 | 51 | tgz: 52 | tar czvf libtask.tgz COPYRIGHT README *.[chS] Makefile 53 | 54 | install: $(LIB) 55 | cp $(LIB) /usr/local/lib 56 | cp task.h /usr/local/include 57 | 58 | -------------------------------------------------------------------------------- /include/intel_hex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CC Bootloader - Intel HEX file format functions 3 | * 4 | * Fergus Noble (c) 2011 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 18 | */ 19 | 20 | #ifndef _INTEL_HEX_H_ 21 | #define _INTEL_HEX_H_ 22 | 23 | #define HEX_INVALID 0xFF 24 | 25 | uint8_t hex4(char c); 26 | uint8_t hex8(char s[]); 27 | uint16_t hex16(char s[]); 28 | char to_hex4_ascii(uint8_t x); 29 | void to_hex8_ascii(char buff[], uint8_t x); 30 | void to_hex16_ascii(char buff[], uint16_t x); 31 | 32 | #endif // _INTEL_HEX_H_ 33 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | char* 24 | fmtstrflush(Fmt *f) 25 | { 26 | if(f->start == nil) 27 | return nil; 28 | *(char*)f->to = '\0'; 29 | f->to = f->start; 30 | return (char*)f->start; 31 | } 32 | -------------------------------------------------------------------------------- /tiny9/libfmt/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | print(char *fmt, ...) 25 | { 26 | int n; 27 | va_list args; 28 | 29 | va_start(args, fmt); 30 | n = vfprint(1, fmt, args); 31 | va_end(args); 32 | return n; 33 | } 34 | -------------------------------------------------------------------------------- /tiny9/libfmt/smprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | char* 24 | smprint(char *fmt, ...) 25 | { 26 | va_list args; 27 | char *p; 28 | 29 | va_start(args, fmt); 30 | p = vsmprint(fmt, args); 31 | va_end(args); 32 | return p; 33 | } 34 | -------------------------------------------------------------------------------- /cc11xx/registers.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import sys 4 | from rflib import * 5 | 6 | registers = [ 7 | "SYNC1", 8 | "SYNC0", 9 | "PKTLEN", 10 | "PKTCTRL1", 11 | "PKTCTRL0", 12 | "ADDR", 13 | "CHANNR", 14 | "FSCTRL1", 15 | "FSCTRL0", 16 | "FREQ2", 17 | "FREQ1", 18 | "FREQ0", 19 | "MDMCFG4", 20 | "MDMCFG3", 21 | "MDMCFG2", 22 | "MDMCFG1", 23 | "MDMCFG0", 24 | "DEVIATN", 25 | "MCSM2", 26 | "MCSM1", 27 | "MCSM0", 28 | "FOCCFG", 29 | "BSCFG", 30 | "FREND1", 31 | "FREND0", 32 | "FSCAL3", 33 | "FSCAL2", 34 | "FSCAL1", 35 | "FSCAL0", 36 | "TEST1", 37 | "TEST0", 38 | "PA_TABLE0", 39 | "PA_TABLE1" 40 | ] 41 | 42 | def p(d): 43 | d.setFreq(913979004, mhz=26) 44 | d.setMdmModulation(MOD_2FSK) 45 | d.setMdmSyncWord(0xd391) 46 | d.setMdmDeviatn(24414, mhz=26) 47 | d.setMdmDRate(19191.7, mhz=26) 48 | d.makePktFLEN(78) 49 | 50 | 51 | # d.setEnablePktAppendStatus(True) 52 | 53 | def main(args): 54 | d = RfCat() 55 | p(d) 56 | 57 | d.getRadioConfig() 58 | c = d.radiocfg 59 | 60 | for r in registers: 61 | print("%s = 0x%02x;" % (r, getattr(c, r.lower()))) 62 | 63 | if __name__ == '__main__': 64 | main(sys.argv) 65 | -------------------------------------------------------------------------------- /tiny9/libfmt/fprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | fprint(int fd, char *fmt, ...) 25 | { 26 | int n; 27 | va_list args; 28 | 29 | va_start(args, fmt); 30 | n = vfprint(fd, fmt, args); 31 | va_end(args); 32 | return n; 33 | } 34 | -------------------------------------------------------------------------------- /tiny9/libtask/httpload.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | enum 9 | { 10 | STACK = 32768 11 | }; 12 | 13 | char *server; 14 | char *url; 15 | 16 | void fetchtask(void*); 17 | 18 | void 19 | taskmain(int argc, char **argv) 20 | { 21 | int i, n; 22 | 23 | if(argc != 4){ 24 | fprintf(stderr, "usage: httpload n server url\n"); 25 | taskexitall(1); 26 | } 27 | n = atoi(argv[1]); 28 | server = argv[2]; 29 | url = argv[3]; 30 | 31 | for(i=0; i 1) 34 | ; 35 | sleep(1); 36 | } 37 | } 38 | 39 | void 40 | fetchtask(void *v) 41 | { 42 | int fd, n; 43 | char buf[512]; 44 | 45 | fprintf(stderr, "starting...\n"); 46 | for(;;){ 47 | if((fd = netdial(TCP, server, 80)) < 0){ 48 | fprintf(stderr, "dial %s: %s (%s)\n", server, strerror(errno), taskgetstate()); 49 | continue; 50 | } 51 | snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", url, server); 52 | fdwrite(fd, buf, strlen(buf)); 53 | while((n = fdread(fd, buf, sizeof buf)) > 0) 54 | ; 55 | close(fd); 56 | write(1, ".", 1); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tiny9/libutf/utfdef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 1998-2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | 15 | #define uchar _utfuchar 16 | #define ushort _utfushort 17 | #define uint _utfuint 18 | #define ulong _utfulong 19 | #define vlong _utfvlong 20 | #define uvlong _utfuvlong 21 | 22 | typedef unsigned char uchar; 23 | typedef unsigned short ushort; 24 | typedef unsigned int uint; 25 | typedef unsigned long ulong; 26 | 27 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) 28 | #define nil ((void*)0) 29 | -------------------------------------------------------------------------------- /tiny9/libutf/utflen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "utf.h" 17 | #include "utfdef.h" 18 | 19 | int 20 | utflen(const char *s) 21 | { 22 | int c; 23 | long n; 24 | Rune rune; 25 | 26 | n = 0; 27 | for(;;) { 28 | c = *(uchar*)s; 29 | if(c < Runeself) { 30 | if(c == 0) 31 | return n; 32 | s++; 33 | } else 34 | s += chartorune(&rune, s); 35 | n++; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /tiny9/libutf/runetype.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "utf.h" 15 | #include "utfdef.h" 16 | 17 | static 18 | Rune* 19 | rbsearch(Rune c, Rune *t, int n, int ne) 20 | { 21 | Rune *p; 22 | int m; 23 | 24 | while(n > 1) { 25 | m = n >> 1; 26 | p = t + m*ne; 27 | if(c >= p[0]) { 28 | t = p; 29 | n = n-m; 30 | } else 31 | n = m; 32 | } 33 | if(n && c >= t[0]) 34 | return t; 35 | return 0; 36 | } 37 | 38 | #include "runetypebody-6.0.0.h" 39 | -------------------------------------------------------------------------------- /tiny9/libfmt/seprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | char* 24 | seprint(char *buf, char *e, char *fmt, ...) 25 | { 26 | char *p; 27 | va_list args; 28 | 29 | va_start(args, fmt); 30 | p = vseprint(buf, e, fmt, args); 31 | va_end(args); 32 | return p; 33 | } 34 | -------------------------------------------------------------------------------- /tiny9/libfmt/snprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | snprint(char *buf, int len, char *fmt, ...) 25 | { 26 | int n; 27 | va_list args; 28 | 29 | va_start(args, fmt); 30 | n = vsnprint(buf, len, fmt, args); 31 | va_end(args); 32 | return n; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /tiny9/libutf/utfecpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "utf.h" 17 | #include "utfdef.h" 18 | 19 | char* 20 | utfecpy(char *to, char *e, const char *from) 21 | { 22 | char *end; 23 | 24 | if(to >= e) 25 | return to; 26 | end = memccpy(to, from, '\0', e - to); 27 | if(end == nil){ 28 | end = e-1; 29 | while(end>to && (*--end&0xC0)==0x80) 30 | ; 31 | *end = '\0'; 32 | }else{ 33 | end--; 34 | } 35 | return end; 36 | } 37 | -------------------------------------------------------------------------------- /cc11xx/pkt.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | #include "pkt.h" 3 | 4 | enum 5 | { 6 | Sinit = 255 7 | }; 8 | 9 | void 10 | pktinit(Pkt *p) 11 | { 12 | p->rxstate = p -> txstate = Sinit; 13 | } 14 | 15 | int 16 | pktin(Pkt *p, uint8 b) 17 | { 18 | if (p->rxstate == Sinit){ 19 | p->type = b; 20 | p->rxstate = 0; 21 | return p->type == Pcancel ? 0 : 1; 22 | }else{ 23 | p->data[p->rxstate++] = b; 24 | return p->rxstate == Npkt ? 0 : 1; 25 | } 26 | } 27 | 28 | int 29 | pktout(Pkt *p, uint8 *b) 30 | { 31 | if(p->txstate == Sinit){ 32 | *b = p->type; 33 | p->txstate = 0; 34 | return p->type == Pcancel ? 0 : 1; 35 | }else{ 36 | *b = p->data[p->txstate++]; 37 | return p->txstate == Npkt ? 0 : 1; 38 | } 39 | } 40 | 41 | void 42 | pktprint(Pkt *p) 43 | { 44 | char *type; 45 | uint8 i; 46 | 47 | switch(p->type){ 48 | case Pcancel: type = "cancel"; break; 49 | case Prx: type = "rx"; break; 50 | case Ptx: type = "tx"; break; 51 | } 52 | 53 | dprint("Pkt %s\n", type); 54 | 55 | if(p->type != Prx && p->type != Ptx) 56 | return; 57 | 58 | // Exactly 13 rows 59 | for(i=0; idata[i], p->data[i+1], p->data[i+2], 62 | p->data[i+3], p->data[i+4], p->data[i+5]); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /cc11xx/cc1111/hal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CC Bootloader - Hardware Abstraction Layer 3 | * 4 | * Fergus Noble (c) 2011 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 18 | */ 19 | 20 | #include "cc1111.h" 21 | 22 | void setup_led() { 23 | // Setup LED and turn it off 24 | P1DIR |= 2; 25 | P1_1 = 0; 26 | } 27 | 28 | void led_on() { 29 | P1_1 = 1; 30 | } 31 | 32 | void led_off() { 33 | P1_1 = 0; 34 | } 35 | 36 | void usb_up() { 37 | // Bring up the USB link 38 | P1DIR |= 1; 39 | P1_0 = 1; 40 | } 41 | 42 | void usb_down() { 43 | // Bring down the USB link 44 | P1_0 = 0; 45 | P1DIR &= ~1; 46 | } 47 | -------------------------------------------------------------------------------- /tiny9/unix/include/u.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #define USED(x) if(x){}else{} 17 | 18 | #if __GNUC__ >= 3 19 | # undef USED 20 | # define USED(x) ((void)(x)) 21 | #endif 22 | 23 | typedef unsigned short ushort; 24 | typedef unsigned char uchar; 25 | typedef unsigned long ulong; 26 | typedef unsigned int uint; 27 | typedef signed char schar; 28 | typedef long long vlong; 29 | typedef unsigned long long uvlong; 30 | typedef unsigned long uintptr; 31 | typedef unsigned long usize; 32 | 33 | typedef int8_t int8; 34 | typedef uint8_t uint8; 35 | typedef int16_t int16; 36 | typedef uint16_t uint16; 37 | typedef unsigned int uint24; 38 | typedef uint32_t uint32; 39 | typedef uint64_t uint64; 40 | typedef unsigned int uint; 41 | typedef int32_t int32; 42 | typedef int64_t int64; 43 | 44 | #define PACKEDSTRUCT __attribute__((packed)) 45 | #define REENTRANT 46 | #define XDATA 47 | 48 | #define nil ((void*)0) 49 | 50 | #ifndef O_DIRECT 51 | #define O_DIRECT 0 52 | #endif 53 | -------------------------------------------------------------------------------- /tiny9/libutf/utfnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "utf.h" 17 | #include "utfdef.h" 18 | 19 | int 20 | utfnlen(const char *s, long m) 21 | { 22 | int c; 23 | long n; 24 | Rune rune; 25 | const char *es; 26 | 27 | es = s + m; 28 | for(n = 0; s < es; n++) { 29 | c = *(uchar*)s; 30 | if(c < Runeself){ 31 | if(c == '\0') 32 | break; 33 | s++; 34 | continue; 35 | } 36 | if(!fullrune(s, es-s)) 37 | break; 38 | s += chartorune(&rune, s); 39 | } 40 | return n; 41 | } 42 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtfix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fmtdef.h" 4 | 5 | int 6 | fixstrfmt(Fmt *f) 7 | { 8 | ulong u; 9 | int isv, i; 10 | uvlong div; 11 | char fmt[24]; 12 | 13 | if(!(f->flags & FmtPrec)) 14 | return fmtprint(f, ""); 15 | if(f->flags & FmtVLong) 16 | return fmtprint(f, ""); 17 | 18 | if(f->flags & FmtLong){ 19 | if(f->flags & FmtUnsigned) 20 | u = va_arg(f->args, ulong); 21 | else 22 | u = va_arg(f->args, long); 23 | }else if(f->flags & FmtByte){ 24 | if(f->flags & FmtUnsigned) 25 | u = (uchar)va_arg(f->args, int); 26 | else 27 | u = (char)va_arg(f->args, int); 28 | }else if(f->flags & FmtShort){ 29 | if(f->flags & FmtUnsigned) 30 | u = (ushort)va_arg(f->args, int); 31 | else 32 | u = (short)va_arg(f->args, int); 33 | }else{ 34 | if(f->flags & FmtUnsigned) 35 | u = va_arg(f->args, uint); 36 | else 37 | u = va_arg(f->args, int); 38 | } 39 | 40 | div = 1; 41 | for(i=0; iprec; i++) 42 | div *= 10; 43 | 44 | if(!(f->flags & FmtUnsigned) && (vlong)u < 0){ 45 | u = -u; 46 | fmtprint(f, "-"); 47 | } 48 | 49 | seprint(fmt, fmt+sizeof fmt, "%%llud.%%.%dllud", f->prec); 50 | return fmtprint(f, fmt, u/div, u%div); 51 | } 52 | 53 | void 54 | fixfmtinstall() 55 | { 56 | fmtinstall('F', fixstrfmt); 57 | } 58 | -------------------------------------------------------------------------------- /tiny9/libfmt/vfprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | vfprint(int fd, char *fmt, va_list args) 25 | { 26 | Fmt f; 27 | char buf[256]; 28 | int n; 29 | 30 | fmtfdinit(&f, fd, buf, sizeof(buf)); 31 | VA_COPY(f.args,args); 32 | n = dofmt(&f, fmt); 33 | VA_END(f.args); 34 | if(n > 0 && __fmtFdFlush(&f) == 0) 35 | return -1; 36 | return n; 37 | } 38 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtfdflush.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * generic routine for flushing a formatting buffer 25 | * to a file descriptor 26 | */ 27 | int 28 | __fmtFdFlush(Fmt *f) 29 | { 30 | int n; 31 | 32 | n = (char*)f->to - (char*)f->start; 33 | if(n && write((uintptr)f->farg, f->start, n) != n) 34 | return 0; 35 | f->to = f->start; 36 | return 1; 37 | } 38 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * Format a string into the output buffer. 25 | * Designed for formats which themselves call fmt. 26 | * Flags, precision and width are preserved. 27 | */ 28 | int 29 | fmtprint(Fmt *f, char *fmt, ...) 30 | { 31 | int n; 32 | va_list va; 33 | 34 | va_start(va, fmt); 35 | n = fmtvprint(f, fmt, va); 36 | va_end(va); 37 | return n; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | fmtrune(Fmt *f, int r) 25 | { 26 | Rune *rt; 27 | char *t; 28 | int n; 29 | 30 | if(f->runes){ 31 | rt = (Rune*)f->to; 32 | FMTRCHAR(f, rt, f->stop, r); 33 | f->to = rt; 34 | n = 1; 35 | }else{ 36 | t = (char*)f->to; 37 | FMTRUNE(f, t, f->stop, r); 38 | n = t - (char*)f->to; 39 | f->to = t; 40 | } 41 | f->nfmt += n; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /tiny9/libutf/utfutf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "utf.h" 17 | #include "utfdef.h" 18 | 19 | 20 | /* 21 | * Return pointer to first occurrence of s2 in s1, 22 | * 0 if none 23 | */ 24 | const 25 | char* 26 | utfutf(const char *s1, const char *s2) 27 | { 28 | const char *p; 29 | long f, n1, n2; 30 | Rune r; 31 | 32 | n1 = chartorune(&r, s2); 33 | f = r; 34 | if(f <= Runesync) /* represents self */ 35 | return strstr(s1, s2); 36 | 37 | n2 = strlen(s2); 38 | for(p=s1; (p=utfrune(p, f)) != 0; p+=n1) 39 | if(strncmp(p, s2, n2) == 0) 40 | return p; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /cc11xx/timer.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | #define TICKSPERSECOND ((MHZ*1e6)/128/2) 4 | 5 | static uint32 ticks; 6 | 7 | void 8 | timerinit() 9 | { 10 | // I can't seem to reduce the tickspeed beyond using the /128 11 | // prescaler. The datasheet is hilarious ambiguous: 12 | // "Timer tick speed setting. The value of TICKSPD cannot 13 | // be higher than CLKSPD." 14 | // 15 | // Somehow, there is a factor of two in there, that I don't quite know 16 | // where comes from. 17 | CLKCON = (CLKCON & ~CLKCON_TICKSPD) | TICKSPD_DIV_1; 18 | T1CTL = 0; 19 | } 20 | 21 | void 22 | alarm(uint16 ms) 23 | { 24 | T1CTL = 0; 25 | T1IE = 0; 26 | flag &= ~Falarm; 27 | 28 | if(ms == 0){ 29 | ticks = 0; 30 | return; 31 | } 32 | 33 | T1CTL = 0; 34 | T1CNTL = 0; 35 | 36 | ticks = ((uint32)ms*TICKSPERSECOND)/1000; 37 | 38 | if(ticks>>16){ 39 | T1CC0H = 0xff; 40 | T1CC0L = 0xff; 41 | }else{ 42 | T1CC0H = ticks >> 8; 43 | T1CC0L = ticks & 0xff; 44 | } 45 | 46 | T1CCTL0 = 0x44; 47 | 48 | T1IE = 1; 49 | 50 | T1CTL = T1CTL_DIV_128 | T1CTL_MODE_MODULO; 51 | } 52 | 53 | void 54 | t1intr(void) __interrupt T1_VECTOR 55 | { 56 | if(!(ticks>>16)){ 57 | flag |= Falarm; 58 | ticks = 0; 59 | T1IE = 0; 60 | T1CTL = (T1CTL&~T1CTL_MODE) | T1CTL_MODE_SUSPEND; 61 | }else{ 62 | ticks -= 0xffff; 63 | 64 | if(!(ticks>>16)){ 65 | T1CC0H = ticks >> 8; 66 | T1CC0H = ticks & 0xff; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /include/rcall.h: -------------------------------------------------------------------------------- 1 | 2 | enum 3 | { 4 | Nop = 0, 5 | 6 | Trx, // [1]size [1]Trx [2]timeout 7 | Rrx, // [1]size [1]Rrx [Npkt]pkt 8 | 9 | Ttx, // [1]size [1]Ttx [2]preamblems [Npkt]pkt 10 | Rtx, // [1]size [1]Rtx 11 | 12 | Ttxrx, // [1]size [1]Ttxrx [2]timeout [2]preamblems [Npkt]pkt 13 | Rtxrx, // [1]size [1]Rtxrx [Npkt]pkt 14 | 15 | Tping, // [1]size [1]Tping 16 | Rping, // [1]size [1]Rping 17 | 18 | Tmax, 19 | 20 | Rerr = 128, // [1]size [1]Rerr [1]err 21 | 22 | Treset = 0xff-1, // A special Rcall to reset the radio 23 | Rreset, 24 | }; 25 | 26 | enum 27 | { 28 | Npkt = 78 29 | }; 30 | 31 | enum 32 | { 33 | Ffilterbyte3 = 1<<0 34 | }; 35 | 36 | enum 37 | { 38 | Emissing = 1, 39 | Ebadcall =2, 40 | Etimeout 41 | }; 42 | 43 | #define RCALLMAX (1/*size*/ + 1/*type*/ + 2/*preamblems*/ + 2/*timeout*/ + 1/*flags*/ + 1/*filterbyte3*/+ Npkt) 44 | 45 | typedef struct 46 | { 47 | uint8 type; 48 | uint8 flag; 49 | 50 | uint8 err; 51 | uint16 timeoutms; 52 | uint16 preamblems; 53 | 54 | uint8 filterbyte3; 55 | 56 | uint8 pkt[Npkt]; 57 | } Rcall; 58 | 59 | uint convM2R(uint8 *p, uint8 n, Rcall *r); 60 | uint convR2M(Rcall *r, uint8 *ap, uint8 n); 61 | 62 | #ifdef TINY9 63 | int rcallfmt(Fmt*); 64 | #endif 65 | 66 | /* These must be provided by an underlying implementation. */ 67 | int rcall(Rcall*, Rcall*); 68 | int radioreset(); 69 | 70 | /* Provided by the radio driver. */ 71 | int radioinit(char*); -------------------------------------------------------------------------------- /tiny9/libutf/utfrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "utf.h" 17 | #include "utfdef.h" 18 | 19 | /* const - removed for go code */ 20 | char* 21 | utfrune(const char *s, Rune c) 22 | { 23 | long c1; 24 | Rune r; 25 | int n; 26 | 27 | if(c < Runesync) /* not part of utf sequence */ 28 | return strchr(s, c); 29 | 30 | for(;;) { 31 | c1 = *(uchar*)s; 32 | if(c1 < Runeself) { /* one byte rune */ 33 | if(c1 == 0) 34 | return 0; 35 | if(c1 == c) 36 | return (char*)s; 37 | s++; 38 | continue; 39 | } 40 | n = chartorune(&r, s); 41 | if(r == c) 42 | return (char*)s; 43 | s += n; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /tiny9/libfmt/vseprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | char* 24 | vseprint(char *buf, char *e, char *fmt, va_list args) 25 | { 26 | Fmt f; 27 | 28 | if(e <= buf) 29 | return nil; 30 | f.runes = 0; 31 | f.start = buf; 32 | f.to = buf; 33 | f.stop = e - 1; 34 | f.flush = 0; 35 | f.farg = nil; 36 | f.nfmt = 0; 37 | VA_COPY(f.args,args); 38 | fmtlocaleinit(&f, nil, nil, nil); 39 | dofmt(&f, fmt); 40 | VA_END(f.args); 41 | *(char*)f.to = '\0'; 42 | return (char*)f.to; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tiny9/libfmt/vsnprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | vsnprint(char *buf, int len, char *fmt, va_list args) 25 | { 26 | Fmt f; 27 | 28 | if(len <= 0) 29 | return -1; 30 | f.runes = 0; 31 | f.start = buf; 32 | f.to = buf; 33 | f.stop = buf + len - 1; 34 | f.flush = 0; 35 | f.farg = nil; 36 | f.nfmt = 0; 37 | VA_COPY(f.args,args); 38 | fmtlocaleinit(&f, nil, nil, nil); 39 | dofmt(&f, fmt); 40 | VA_END(f.args); 41 | *(char*)f.to = '\0'; 42 | return (char*)f.to - buf; 43 | } 44 | -------------------------------------------------------------------------------- /tiny9/libutf/utfrrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "utf.h" 17 | #include "utfdef.h" 18 | 19 | /* const - removed for go code */ 20 | char* 21 | utfrrune(const char *s, Rune c) 22 | { 23 | long c1; 24 | Rune r; 25 | const char *s1; 26 | 27 | if(c < Runesync) /* not part of utf sequence */ 28 | return strrchr(s, c); 29 | 30 | s1 = 0; 31 | for(;;) { 32 | c1 = *(uchar*)s; 33 | if(c1 < Runeself) { /* one byte rune */ 34 | if(c1 == 0) 35 | return (char*)s1; 36 | if(c1 == c) 37 | s1 = s; 38 | s++; 39 | continue; 40 | } 41 | c1 = chartorune(&r, s); 42 | if(r == c) 43 | s1 = s; 44 | s += c1; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /libpump/testpump.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | int 10 | main(int argc, char **argv) 11 | { 12 | fmtinstall('C', Pcallfmt); 13 | 14 | uint8 pkt[] = { 15 | 0x50, 0x00, 0x07, 0x18, 0xde, 0xad, 0xbe, 0xef, 0x01, 0x03, 0x03, 0x00, 16 | 0xb8, 0x1f, 0x0c, 0x38, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x1f, 0x00, 17 | 0x00, 0x01, 0xb0, 0xff, 0x00, 0x30, 0x04, 0x00, 0x2f, 0xfd, 0x9c, 0x9f, 18 | 0x19, 0xc5, 0x50, 0x6f, 0xa7, 0x00, 0x00, 0x00, 0x08, 0x34, 0x22, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 22 | }; 23 | 24 | Pcall c; 25 | 26 | assert(convP2C(pkt, &c) == 0); 27 | assert(c.type == Rstatus); 28 | 29 | assert(c.status.month == 12); 30 | assert(c.status.day == 31); 31 | assert(c.status.hour == 12); 32 | assert(c.status.minute == 56); 33 | 34 | assert(c.status.basal == 250); 35 | assert(c.status.insulin == 31); 36 | assert(c.status.temp == -80); 37 | assert(c.status.temptime = 192); 38 | assert(c.status.temptotal == 240); 39 | 40 | dprint("%C\n", &c); 41 | 42 | print("ok\n"); 43 | exit(0); 44 | } 45 | 46 | int 47 | rcall(Rcall *tx, Rcall *rx) 48 | { 49 | werrstr("not implemented"); 50 | return -1; 51 | } 52 | 53 | int 54 | radioreset() 55 | { 56 | werrstr("not implemneted"); 57 | return -1; 58 | } 59 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtnull.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * Absorb output without using resources. 25 | */ 26 | static Rune nullbuf[32]; 27 | 28 | static int 29 | __fmtnullflush(Fmt *f) 30 | { 31 | f->to = nullbuf; 32 | f->nfmt = 0; 33 | return 0; 34 | } 35 | 36 | int 37 | fmtnullinit(Fmt *f) 38 | { 39 | memset(f, 0, sizeof *f); 40 | f->runes = 1; 41 | f->start = nullbuf; 42 | f->to = nullbuf; 43 | f->stop = nullbuf+nelem(nullbuf); 44 | f->flush = __fmtnullflush; 45 | fmtlocaleinit(f, nil, nil, nil); 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /tiny9/libbio/bfildes.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bfildes.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | int 31 | Bfildes(Biobuf *bp) 32 | { 33 | 34 | return bp->fid; 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Marius Eriksen. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Marius Eriksen nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /libpump/pumpchk.c: -------------------------------------------------------------------------------- 1 | #include "pumpimpl.h" 2 | 3 | static Table *chktab; 4 | 5 | static int openchktab(); 6 | 7 | int 8 | pumpchk(void *v, uint n, uint32 *chkp) 9 | { 10 | uint32 crc; 11 | uint8 *chk; 12 | uint8 crcbuf[4]; 13 | 14 | if(chktab == nil && openchktab() < 0) 15 | return -1; 16 | 17 | dprint("pumpchk\n"); 18 | dprinthex(v, n); 19 | 20 | crc = crc32(v, n); 21 | dprint("pumpchk crc32: %ux\n", crc); 22 | U32PUT(crcbuf, crc); 23 | 24 | chk = tablelookup(chktab, crcbuf); 25 | if(chk != nil){ 26 | *chkp = U32GET(chk); 27 | dprint("pumpchk chkhd: %ux\n", *chkp); 28 | return 0; 29 | }else{ 30 | werrstr("checksum missing for payload %H", v, n); 31 | return -1; 32 | } 33 | } 34 | 35 | int 36 | pumpchkhd(void *v) 37 | { 38 | uint8 *p = v; 39 | uint32 chk; 40 | 41 | if(pumpchk(p, 4, &chk) < 0) 42 | return -1; 43 | 44 | U32PUTLE(p+4, chk); 45 | return 0; 46 | } 47 | 48 | int 49 | pumpchkpayload(void *v) 50 | { 51 | uint8 *p = v; 52 | uint32 crc = crc32(p+8, 28); 53 | U32PUT(p+36, crc); 54 | return 0; 55 | } 56 | 57 | int 58 | pumpaddchk(void *v, uint n, uint32 chk) 59 | { 60 | uint32 crc; 61 | uint8 crcbuf[4], chkbuf[4]; 62 | 63 | if(chktab == nil && openchktab() < 0) 64 | return -1; 65 | 66 | crc = crc32(v, n); 67 | U32PUT(crcbuf, crc); 68 | U32PUT(chkbuf, chk); 69 | 70 | if(tablewrite(chktab, crcbuf, chkbuf) <0) 71 | return -1; 72 | 73 | return 0; 74 | } 75 | 76 | static int 77 | openchktab() 78 | { 79 | if(chktab != nil) 80 | return 0; 81 | chktab = tableopen("chktab", 4, 4); 82 | if(chktab == nil) 83 | return -1; 84 | 85 | return 0; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /tiny9/include/umacro.h: -------------------------------------------------------------------------------- 1 | #ifndef nelem 2 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) 3 | #endif 4 | #ifndef offsetof 5 | #define offsetof(s, m) (ulong)(&(((s*)0)->m)) 6 | #endif 7 | 8 | #define nrow2 nelem 9 | #define ncol2(x) nelem(x[0]) 10 | #define elemsz2(x) sizeof(x[0][0]) 11 | 12 | /* From $PLAN9/src/cmd/fossil/pack.c */ 13 | #define U8GET(p) ((p)[0]) 14 | #define U16GET(p) (((p)[0]<<8)|(p)[1]) 15 | #define U24GET(p) (((p)[0]<<16)|((p)[1]<<8)|(p)[2]) 16 | #define U32GET(p) (((p)[0]<<24)|((p)[1]<<16)|((p)[2]<<8)|(p)[3]) 17 | #define U48GET(p) (((uvlong)U16GET(p)<<32)|(uvlong)U32GET((p)+2)) 18 | #define U64GET(p) (((uvlong)U32GET(p)<<32)|(uvlong)U32GET((p)+4)) 19 | 20 | #define U8PUT(p,v) (p)[0]=(v) 21 | #define U16PUT(p,v) (p)[0]=(v)>>8;(p)[1]=(v) 22 | #define U24PUT(p,v) (p)[0]=((v)>>16)&0xFF;(p)[1]=((v)>>8)&0xFF;(p)[2]=(v)&0xFF 23 | #define U32PUT(p,v) (p)[0]=((v)>>24)&0xFF;(p)[1]=((v)>>16)&0xFF;(p)[2]=((v)>>8)&0xFF;(p)[3]=(v)&0xFF 24 | #define U48PUT(p,v,t32) t32=(v)>>32;U16PUT(p,t32);t32=(v);U32PUT((p)+2,t32) 25 | #define U64PUT(p,v,t32) t32=(v)>>32;U32PUT(p,t32);t32=(v);U32PUT((p)+4,t32) 26 | 27 | #define U8GETLE(p) ((p)[0]) 28 | #define U16GETLE(p) (((p)[1]<<8)|(p)[0]) 29 | #define U24GETLE(p) (((p)[2]<<16)|((p)[1]<<8)|(p)[0]) 30 | #define U32GETLE(p) (((p)[3]<<24)|((p)[2]<<16)|((p)[1]<<8)|(p)[0]) 31 | 32 | #define U8PUTLE(p,v) (p)[0]=(v) 33 | #define U16PUTLE(p,v) (p)[1]=(v)>>8;(p)[0]=(v) 34 | #define U24PUTLE(p,v) (p)[2]=((v)>>16)&0xFF;(p)[1]=((v)>>8)&0xFF;(p)[0]=(v)&0xFF 35 | #define U32PUTLE(p,v) (p)[3]=((v)>>24)&0xFF;(p)[2]=((v)>>16)&0xFF;(p)[1]=((v)>>8)&0xFF;(p)[0]=(v)&0xFF 36 | 37 | #define BIT(x) (1<<(x)) 38 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtfd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * public routine for final flush of a formatting buffer 25 | * to a file descriptor; returns total char count. 26 | */ 27 | int 28 | fmtfdflush(Fmt *f) 29 | { 30 | if(__fmtFdFlush(f) <= 0) 31 | return -1; 32 | return f->nfmt; 33 | } 34 | 35 | /* 36 | * initialize an output buffer for buffered printing 37 | */ 38 | int 39 | fmtfdinit(Fmt *f, int fd, char *buf, int size) 40 | { 41 | f->runes = 0; 42 | f->start = buf; 43 | f->to = buf; 44 | f->stop = buf + size; 45 | f->flush = __fmtFdFlush; 46 | f->farg = (void*)(uintptr_t)fd; 47 | f->flags = 0; 48 | f->nfmt = 0; 49 | fmtlocaleinit(f, nil, nil, nil); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtvprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | 24 | /* 25 | * Format a string into the output buffer. 26 | * Designed for formats which themselves call fmt. 27 | * Flags, precision and width are preserved. 28 | */ 29 | int 30 | fmtvprint(Fmt *f, char *fmt, va_list args) 31 | { 32 | va_list va; 33 | int n, w, p; 34 | unsigned long fl; 35 | 36 | w = f->width; 37 | p = f->prec; 38 | fl = f->flags; 39 | VA_COPY(va, f->args); 40 | VA_END(f->args); 41 | VA_COPY(f->args, args); 42 | n = dofmt(f, fmt); 43 | VA_END(f->args); 44 | VA_COPY(f->args, va); 45 | VA_END(va); 46 | f->width = w; 47 | f->prec = p; 48 | f->flags = fl; 49 | if(n >= 0) 50 | return 0; 51 | return n; 52 | } 53 | -------------------------------------------------------------------------------- /tiny9/libfmt/sprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | sprint(char *buf, char *fmt, ...) 25 | { 26 | int n; 27 | uint len; 28 | va_list args; 29 | 30 | len = 1<<30; /* big number, but sprint is deprecated anyway */ 31 | /* 32 | * on PowerPC, the stack is near the top of memory, so 33 | * we must be sure not to overflow a 32-bit pointer. 34 | * 35 | * careful! gcc-4.2 assumes buf+len < buf can never be true and 36 | * optimizes the test away. casting to uintptr works around this bug. 37 | */ 38 | if((uintptr)buf+len < (uintptr)buf) 39 | len = -(uintptr)buf-1; 40 | 41 | va_start(args, fmt); 42 | n = vsnprint(buf, len, fmt, args); 43 | va_end(args); 44 | return n; 45 | } 46 | -------------------------------------------------------------------------------- /cmd/arg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argument parser from Plan 9, lifted from u9fs. 3 | */ 4 | /* 5 | The authors of this software are Bob Flandrena, Ken Thompson, 6 | Rob Pike, and Russ Cox. 7 | 8 | Copyright (c) 1992-2002 by Lucent Technologies. 9 | 10 | Permission to use, copy, modify, and distribute this software for any 11 | purpose without fee is hereby granted, provided that this entire notice 12 | is included in all copies of any software which is or includes a copy 13 | or modification of this software and in all copies of the supporting 14 | documentation for such software. 15 | 16 | THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 17 | WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 18 | REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 19 | OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 20 | */ 21 | extern char *argv0; 22 | #define ARGBEGIN if(argv0==0) argv0=*argv; for(argv++,argc--;\ 23 | argv[0] && argv[0][0]=='-' && argv[0][1];\ 24 | argc--, argv++) {\ 25 | char *_args, *_argt;\ 26 | char _argc;\ 27 | _args = &argv[0][1];\ 28 | if(_args[0]=='-' && _args[1]==0){\ 29 | argc--; argv++; break;\ 30 | }\ 31 | _argc = 0;\ 32 | while(*_args)\ 33 | switch(*_args++) 34 | #define ARGEND SET(_argt);USED(_argt);USED(_argc);USED(_args);}USED(argv);USED(argc); 35 | #define ARGF() (_argt=_args, _args="",\ 36 | (*_argt? _argt: argv[1]? (argc--, *++argv): 0)) 37 | #define EARGF(x) (_argt=_args, _args="",\ 38 | (*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0))) 39 | 40 | #define ARGC() _argc 41 | 42 | #define USED(x) ((void)(x)) 43 | #define SET(x) ((x)=0) 44 | -------------------------------------------------------------------------------- /tiny9/libc/strecpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | Inferno lib9/strecpy.c 3 | http://code.google.com/p/inferno-os/source/browse/lib9/strecpy.c 4 | 5 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 6 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | char* 31 | strecpy(char *to, char *e, char *from) 32 | { 33 | if(to >= e) 34 | return to; 35 | to = memccpy(to, from, '\0', e - to); 36 | if(to == nil){ 37 | to = e - 1; 38 | *to = '\0'; 39 | }else{ 40 | to--; 41 | } 42 | return to; 43 | } 44 | -------------------------------------------------------------------------------- /tiny9/libbio/bputc.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bputc.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | int 31 | Bputc(Biobuf *bp, int c) 32 | { 33 | int i; 34 | 35 | for(;;) { 36 | i = bp->ocount; 37 | if(i) { 38 | bp->ebuf[i++] = c; 39 | bp->ocount = i; 40 | return 0; 41 | } 42 | if(Bflush(bp) == Beof) 43 | break; 44 | } 45 | return Beof; 46 | } 47 | -------------------------------------------------------------------------------- /libradio/rpigpio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* See: http://elinux.org/RPi_GPIO_Code_Samples */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | enum 12 | { 13 | Bcm2708 = 0x20000000, 14 | Gpio = Bcm2708+0x200000, 15 | 16 | Block = 4*1024, 17 | Page = 4*1024, 18 | 19 | Resetpin = 18, 20 | }; 21 | 22 | #define GPIOINPUT(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) 23 | #define GPIOOUTPUT(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) 24 | #define GPIOSETALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3)) 25 | 26 | #define GPIOSET *(gpio+7) // sets bits which are 1 ignores bits which are 0 27 | #define GPIOCLR *(gpio+10) // clears bits which are 1 ignores bits which are 0 28 | 29 | #define GETGPIO(g) (*(gpio+13)&(1< 27 | #include 28 | #include 29 | 30 | int 31 | Bbuffered(Biobuf *bp) 32 | { 33 | switch(bp->state) { 34 | case Bracteof: 35 | case Bractive: 36 | return -bp->icount; 37 | 38 | case Bwactive: 39 | return bp->bsize + bp->ocount; 40 | 41 | case Binactive: 42 | return 0; 43 | } 44 | fprint(2, "Bbuffered: unknown state %d\n", bp->state); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /tiny9/libbio/bputrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bputrune.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | int 32 | Bputrune(Biobuf *bp, long c) 33 | { 34 | Rune rune; 35 | char str[UTFmax]; 36 | int n; 37 | 38 | rune = c; 39 | if(rune < Runeself) { 40 | Bputc(bp, rune); 41 | return 1; 42 | } 43 | n = runetochar(str, &rune); 44 | if(n == 0) 45 | return Bbad; 46 | if(Bwrite(bp, str, n) != n) 47 | return Beof; 48 | return n; 49 | } 50 | -------------------------------------------------------------------------------- /cc11xx/impl.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ioCCxx10_bitdef.h" 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #define zero(x) memset((x), 0, sizeof(*(x))) 14 | #define await(x) while(!(x)) 15 | 16 | enum 17 | { 18 | Frxcall = 1<<0, 19 | Ftxcall = 1<<1, 20 | 21 | /* Furx = 1<<0, 22 | Futx = 1<<1, 23 | */ 24 | 25 | Frfrx = 1<<2, 26 | Frftx = 1<<3, 27 | Frfovf = 1<<4, 28 | Falarm = 1<<5, 29 | Fpanic = 1<<6 30 | }; 31 | 32 | 33 | extern volatile uint8 flag; 34 | 35 | void sleep(int ms); 36 | 37 | void printinit(); 38 | 39 | #ifdef DEBUG 40 | #undef dprint 41 | #define dprint(...) printf_small(__VA_ARGS__) 42 | #else 43 | #define dprint(...) 44 | #endif 45 | 46 | enum 47 | { 48 | Txcontinue = 1<<0, 49 | Txrx = 1<<1, 50 | }; 51 | 52 | void rfinit(); 53 | void rfidle(); 54 | void rfrx(); 55 | void rftx(uint8 flags); 56 | void rftxpreamble(); 57 | void rfwakeup(uint16 n); 58 | extern volatile __xdata uint8 rfrxbuf[Npkt]; 59 | extern volatile __xdata uint8 rftxbuf[Npkt]; 60 | 61 | void timerinit(); 62 | void alarm(uint16 ms); 63 | 64 | void spiinit(); 65 | void spitx(uint8 c); 66 | 67 | void srvinit(); 68 | void srvrx(); 69 | void srvtx(); 70 | void srvrxlower(); 71 | void srvrxpeek(); 72 | 73 | #define SPIMAX (RCALLMAX+2) 74 | 75 | extern volatile __xdata uint8 rxcall[SPIMAX]; 76 | extern volatile __xdata uint8 txcall[SPIMAX]; 77 | 78 | enum 79 | { 80 | Idle = 0, 81 | Reply, 82 | Replying, 83 | Nstate 84 | }; 85 | 86 | void call(Rcall *c, uint8 *state, uint8 *waitflag, uint8 *clearflag); 87 | 88 | void printflag(uint8 flag); 89 | char* strmarcstate(uint8 state); 90 | 91 | void panic(char*, ...); 92 | 93 | 94 | /* 95 | Board implementations. 96 | */ 97 | 98 | void boardprintinit(); 99 | -------------------------------------------------------------------------------- /tiny9/libbio/boffset.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/boffset.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | vlong 31 | Boffset(Biobuf *bp) 32 | { 33 | vlong n; 34 | 35 | switch(bp->state) { 36 | default: 37 | fprint(2, "Boffset: unknown state %d\n", bp->state); 38 | n = Beof; 39 | break; 40 | 41 | case Bracteof: 42 | case Bractive: 43 | n = bp->offset + bp->icount; 44 | break; 45 | 46 | case Bwactive: 47 | n = bp->offset + (bp->bsize + bp->ocount); 48 | break; 49 | } 50 | return n; 51 | } 52 | -------------------------------------------------------------------------------- /libradio/testradio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | static uint8 testpkt[] = { 8 | 0x00, 0x00, 0x00, 0x04, 0xfa, 0x31, 0x8d, 0x82, 0x49, 0x01, 0x2d, 0x14, 9 | 0x50, 0x8b, 0xdb, 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 10 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 11 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 13 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 15 | }; 16 | 17 | 18 | void convR2M2R(Rcall *r, uint8 size); 19 | 20 | int 21 | main(int argc, char **argv) 22 | { 23 | Rcall r; 24 | 25 | r.type = Trx; 26 | convR2M2R(&r, 1+1+1+1+2); 27 | assert(r.type == Trx); 28 | 29 | r.type = Ttx; 30 | r.preamblems = 10; 31 | memcpy(r.pkt, testpkt, sizeof testpkt); 32 | convR2M2R(&r, 1+1+1+2+Npkt); 33 | assert(r.type == Ttx); 34 | assert(r.preamblems == 10); 35 | assert(memcmp(r.pkt, testpkt, sizeof testpkt) == 0); 36 | 37 | r.type = Rrx; 38 | memcpy(r.pkt, testpkt, sizeof testpkt); 39 | convR2M2R(&r, 1+1+1+Npkt); 40 | assert(r.type == Rrx); 41 | assert(memcmp(r.pkt, testpkt, sizeof testpkt) == 0); 42 | 43 | r.type = Rerr; 44 | r.err = 123; 45 | convR2M2R(&r, 1+1+1+1); 46 | assert(r.type == Rerr); 47 | assert(r.err == 123); 48 | 49 | print("ok\n"); 50 | exit(0); 51 | } 52 | 53 | void 54 | convR2M2R(Rcall *r, uint8 size) 55 | { 56 | uint8 buf[RCALLMAX]; 57 | 58 | assert(convR2M(r, buf, sizeof buf) == size); 59 | assert(convM2R(buf, sizeof buf, r) == size); 60 | } 61 | 62 | int 63 | rcall(Rcall *tx, Rcall *rx) 64 | { 65 | werrstr("not implemented"); 66 | return -1; 67 | } 68 | 69 | int 70 | radioreset() 71 | { 72 | werrstr("not implemented"); 73 | return -1; 74 | } 75 | -------------------------------------------------------------------------------- /tiny9/libbio/brdstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright © 2009 The Go Authors. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | char* 28 | Brdstr(Biobuf *bp, int delim, int nulldelim) 29 | { 30 | char *p, *q, *nq; 31 | int n, linelen; 32 | 33 | q = nil; 34 | n = 0; 35 | for(;;) { 36 | p = Brdline(bp, delim); 37 | linelen = Blinelen(bp); 38 | if(n == 0 && linelen == 0) 39 | return nil; 40 | nq = realloc(q, n+linelen+1); 41 | if(nq == nil) { 42 | free(q); 43 | return nil; 44 | } 45 | q = nq; 46 | if(p != nil) { 47 | memmove(q+n, p, linelen); 48 | n += linelen; 49 | if(nulldelim) 50 | q[n-1] = '\0'; 51 | break; 52 | } 53 | if(linelen == 0) 54 | break; 55 | Bread(bp, q+n, linelen); 56 | n += linelen; 57 | } 58 | q[n] = '\0'; 59 | return q; 60 | } 61 | -------------------------------------------------------------------------------- /tiny9/libtask/tcpproxy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | enum 10 | { 11 | STACK = 32768 12 | }; 13 | 14 | char *server; 15 | int port; 16 | void proxytask(void*); 17 | void rwtask(void*); 18 | 19 | int* 20 | mkfd2(int fd1, int fd2) 21 | { 22 | int *a; 23 | 24 | a = malloc(2*sizeof a[0]); 25 | if(a == 0){ 26 | fprintf(stderr, "out of memory\n"); 27 | abort(); 28 | } 29 | a[0] = fd1; 30 | a[1] = fd2; 31 | return a; 32 | } 33 | 34 | void 35 | taskmain(int argc, char **argv) 36 | { 37 | int cfd, fd; 38 | int rport; 39 | char remote[16]; 40 | 41 | if(argc != 4){ 42 | fprintf(stderr, "usage: tcpproxy localport server remoteport\n"); 43 | taskexitall(1); 44 | } 45 | server = argv[2]; 46 | port = atoi(argv[3]); 47 | 48 | if((fd = netannounce(TCP, 0, atoi(argv[1]))) < 0){ 49 | fprintf(stderr, "cannot announce on tcp port %d: %s\n", atoi(argv[1]), strerror(errno)); 50 | taskexitall(1); 51 | } 52 | fdnoblock(fd); 53 | while((cfd = netaccept(fd, remote, &rport)) >= 0){ 54 | fprintf(stderr, "connection from %s:%d\n", remote, rport); 55 | taskcreate(proxytask, (void*)cfd, STACK); 56 | } 57 | } 58 | 59 | void 60 | proxytask(void *v) 61 | { 62 | int fd, remotefd; 63 | 64 | fd = (int)v; 65 | if((remotefd = netdial(TCP, server, port)) < 0){ 66 | close(fd); 67 | return; 68 | } 69 | 70 | fprintf(stderr, "connected to %s:%d\n", server, port); 71 | 72 | taskcreate(rwtask, mkfd2(fd, remotefd), STACK); 73 | taskcreate(rwtask, mkfd2(remotefd, fd), STACK); 74 | } 75 | 76 | void 77 | rwtask(void *v) 78 | { 79 | int *a, rfd, wfd, n; 80 | char buf[2048]; 81 | 82 | a = v; 83 | rfd = a[0]; 84 | wfd = a[1]; 85 | free(a); 86 | 87 | while((n = fdread(rfd, buf, sizeof buf)) > 0) 88 | fdwrite(wfd, buf, n); 89 | shutdown(wfd, SHUT_WR); 90 | close(rfd); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /cmd/u.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | #include 3 | #include 4 | #include 5 | 6 | void* 7 | emalloc(uint n) 8 | { 9 | void *p; 10 | 11 | if((p = calloc(n, 1)) == nil) 12 | abort(); 13 | 14 | return p; 15 | } 16 | 17 | char* 18 | estrdup(char *s) 19 | { 20 | void *d; 21 | 22 | if((d = strdup(s)) == nil) 23 | abort(); 24 | 25 | return d; 26 | } 27 | 28 | ssize_t 29 | hexwrite(int fd, const void *p, size_t n) 30 | { 31 | char hex[RCALLMAX*2]; 32 | int i, nw; 33 | char *cp = (char*)p; 34 | 35 | for(i=0; i0){ 70 | if((m = read(fd, buf, n)) < 0) 71 | return m; 72 | else if(m == 0) 73 | return q-n; 74 | n -= m; 75 | buf += m; 76 | } 77 | 78 | return q; 79 | } 80 | 81 | 82 | static char digits[] = "0123456789abcdef"; 83 | 84 | int 85 | unhexlify(char *h, void* buf, uint *n) 86 | { 87 | uint8 *p = buf; 88 | char *c; 89 | 90 | if(*n < strlen(h)/2) 91 | return -1; 92 | 93 | if(strlen(h)%2 != 0) 94 | return -1; 95 | 96 | while(*h){ 97 | c = strchr(digits, tolower(*h++)); 98 | if(c == nil) 99 | return -1; 100 | *p = (c-digits) << 4; 101 | 102 | c = strchr(digits, tolower(*h++)); 103 | if(c == nil) 104 | return -1; 105 | 106 | *p |= c-digits; 107 | p++; 108 | } 109 | 110 | *n = p-(uint8*)buf; 111 | 112 | return 0; 113 | } 114 | -------------------------------------------------------------------------------- /tiny9/libbio/bflush.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bflush.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | int 32 | Bflush(Biobuf *bp) 33 | { 34 | int n, c; 35 | 36 | switch(bp->state) { 37 | case Bwactive: 38 | n = bp->bsize+bp->ocount; 39 | if(n == 0) 40 | return 0; 41 | c = write(bp->fid, bp->bbuf, n); 42 | if(n == c) { 43 | bp->offset += n; 44 | bp->ocount = -bp->bsize; 45 | return 0; 46 | } 47 | bp->state = Binactive; 48 | bp->ocount = 0; 49 | break; 50 | 51 | case Bracteof: 52 | bp->state = Bractive; 53 | 54 | case Bractive: 55 | bp->icount = 0; 56 | bp->gbuf = bp->ebuf; 57 | return 0; 58 | } 59 | return Beof; 60 | } 61 | -------------------------------------------------------------------------------- /tiny9/libbio/bgetd.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bgetd.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | double fmtcharstod(int(*f)(void*), void *vp); 31 | double __fmtpow10(int n); 32 | 33 | struct bgetd 34 | { 35 | Biobuf* b; 36 | int eof; 37 | }; 38 | 39 | static int 40 | Bgetdf(void *vp) 41 | { 42 | int c; 43 | struct bgetd *bg = vp; 44 | 45 | c = Bgetc(bg->b); 46 | if(c == Beof) 47 | bg->eof = 1; 48 | return c; 49 | } 50 | 51 | int 52 | Bgetd(Biobuf *bp, double *dp) 53 | { 54 | double d; 55 | struct bgetd b; 56 | 57 | b.b = bp; 58 | b.eof = 0; 59 | d = fmtcharstod(Bgetdf, &b); 60 | if(b.eof) 61 | return -1; 62 | Bungetc(bp); 63 | *dp = d; 64 | return 1; 65 | } 66 | -------------------------------------------------------------------------------- /cmd/tty.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This file is mostly derived from the code at 4 | http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c 5 | */ 6 | 7 | #include "impl.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int 14 | ttysetattr(int fd, int speed, int parity) 15 | { 16 | struct termios tty; 17 | 18 | memset(&tty, 0, sizeof tty); 19 | 20 | if(tcgetattr (fd, &tty) != 0){ 21 | werrstr("tcgetattr: %r"); 22 | return -1; 23 | } 24 | 25 | cfsetospeed(&tty, speed); 26 | cfsetispeed(&tty, speed); 27 | 28 | tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8 | speed; /* 8-bit chars */ 29 | /* disable IGNBRK for mismatched speed tests; 30 | otherwise receive break as \000 chars */ 31 | tty.c_iflag &= ~IGNBRK; /*disable break processing */ 32 | tty.c_lflag = 0; /* no signaling chars, no echo, no canonical processing */ 33 | tty.c_oflag = 0; /* no remapping, no delays */ 34 | tty.c_cc[VMIN] = 0; /* read doesn't block */ 35 | tty.c_cc[VTIME] = 5; /* 0.5 seconds read timeout */ 36 | 37 | tty.c_iflag &= ~(IXON | IXOFF | IXANY); /* shut off xon/xoff ctrl */ 38 | 39 | tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls, enable reading */ 40 | tty.c_cflag &= ~(PARENB | PARODD); /* shut off parity */ 41 | tty.c_cflag |= parity; 42 | tty.c_cflag &= ~CSTOPB; 43 | tty.c_cflag &= ~CRTSCTS; 44 | 45 | if(tcsetattr(fd, TCSANOW, &tty) != 0){ 46 | werrstr("tcsetattr: %r"); 47 | return -1; 48 | } 49 | 50 | return 0; 51 | } 52 | 53 | int 54 | ttysetblocking(int fd, int block) 55 | { 56 | struct termios tty; 57 | memset(&tty, 0, sizeof tty); 58 | 59 | if(tcgetattr(fd, &tty) != 0){ 60 | werrstr("tcgetattr: %r"); 61 | return -1; 62 | } 63 | 64 | tty.c_cc[VMIN] = block ? 1 : 0; 65 | tty.c_cc[VTIME] = 5; /* 0.5 seconds read timeout */ 66 | 67 | if (tcsetattr(fd, TCSANOW, &tty) != 0){ 68 | werrstr("tcsetattr: %r"); 69 | return -1; 70 | } 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /tiny9/libfmt/dorfmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* format the output into f->to and return the number of characters fmted */ 24 | 25 | /* BUG: THIS FILE IS NOT UPDATED TO THE NEW SPEC */ 26 | int 27 | dorfmt(Fmt *f, const Rune *fmt) 28 | { 29 | Rune *rt, *rs; 30 | int r; 31 | char *t, *s; 32 | int nfmt; 33 | 34 | nfmt = f->nfmt; 35 | for(;;){ 36 | if(f->runes){ 37 | rt = (Rune*)f->to; 38 | rs = (Rune*)f->stop; 39 | while((r = *fmt++) && r != '%'){ 40 | FMTRCHAR(f, rt, rs, r); 41 | } 42 | f->nfmt += rt - (Rune *)f->to; 43 | f->to = rt; 44 | if(!r) 45 | return f->nfmt - nfmt; 46 | f->stop = rs; 47 | }else{ 48 | t = (char*)f->to; 49 | s = (char*)f->stop; 50 | while((r = *fmt++) && r != '%'){ 51 | FMTRUNE(f, t, f->stop, r); 52 | } 53 | f->nfmt += t - (char *)f->to; 54 | f->to = t; 55 | if(!r) 56 | return f->nfmt - nfmt; 57 | f->stop = s; 58 | } 59 | 60 | fmt = (Rune*)__fmtdispatch(f, (Rune*)fmt, 1); 61 | if(fmt == nil) 62 | return -1; 63 | } 64 | return 0; /* not reached */ 65 | } 66 | -------------------------------------------------------------------------------- /tiny9/libtask/Makefile: -------------------------------------------------------------------------------- 1 | TCPLIBS= 2 | OUT=_build 3 | OUT6M=_build6m 4 | 5 | LIB=libtask.a 6 | 7 | ASM=asm.o 8 | PORTOBJECTS=\ 9 | $(ASM)\ 10 | channel.o\ 11 | context.o\ 12 | print.o\ 13 | qlock.o\ 14 | rendez.o\ 15 | task.o 16 | 17 | OBJECTS=\ 18 | $(PORTOBJECTS)\ 19 | fd.o\ 20 | net.o 21 | 22 | OFILES=$(addprefix $(OUT)/, $(OBJECTS)) 23 | OFILES6M=$(addprefix $(OUT6M)/, $(PORTOBJECTS)) 24 | 25 | all: $(OUT)/$(LIB) primes tcpproxy testdelay 26 | 27 | CC=gcc 28 | AR=ar 29 | CFLAGS=-Wall -c -I. -ggdb 30 | AS=$(CC) -c 31 | 32 | CC6M=arm-none-eabi-gcc 33 | AS6M=$(CC6M) -c 34 | AR6M=arm-none-eabi-ar 35 | CFLAGS6M=-Wall -c -I. \ 36 | -mcpu=cortex-m0 -mthumb -mabi=aapcs \ 37 | -mfloat-abi=soft -ffunction-sections -fdata-sections \ 38 | -fno-strict-aliasing -fno-builtin --short-enums 39 | ifdef DEBUG 40 | CFLAGS6M+=-ggdb 41 | endif 42 | 43 | $(OFILES): taskimpl.h task.h 386-ucontext.h power-ucontext.h arm-ucontext.h 44 | 45 | $(OUT): 46 | mkdir -p $(OUT) 47 | 48 | $(OUT6M): 49 | mkdir -p $(OUT6M) 50 | 51 | $(OUT)/%.o: $(OUT) %.s 52 | $(AS) $*.s -o$@ 53 | 54 | $(OUT)/%.o: $(OUT) %.c 55 | $(CC) $(CFLAGS) $*.c -o$@ 56 | 57 | $(OUT)/$(LIB): $(OUT) $(OFILES) 58 | ar rvc $@ $(OFILES) 59 | 60 | $(OUT6M)/%.o: $(OUT6M) %.s 61 | $(AS6M) -x assembler-with-cpp $*.s -o$@ 62 | 63 | $(OUT6M)/%.o: $(OUT6M) %.c 64 | $(CC6M) $(CFLAGS6M) $*.c -o$@ 65 | 66 | $(OUT6M)/$(LIB): $(OUT6M) $(OFILES6M) 67 | ar rvc $@ $(OFILES6M) 68 | 69 | primes: primes.o $(OUT)/$(LIB) 70 | $(CC) -o primes primes.o $(OUT)/$(LIB) 71 | 72 | tcpproxy: tcpproxy.o $(OUT)/$(LIB) 73 | $(CC) -o tcpproxy tcpproxy.o $(OUT)/$(LIB) $(TCPLIBS) 74 | 75 | httpload: httpload.o $(OUT)/$(LIB) 76 | $(CC) -o httpload httpload.o $(OUT)/$(LIB) 77 | 78 | testdelay: testdelay.o $(OUT)/$(LIB) 79 | $(CC) -o testdelay testdelay.o $(OUT)/$(LIB) 80 | 81 | testdelay1: testdelay1.o $(LIB) 82 | $(CC) -o testdelay1 testdelay1.o $(OUT)/$(LIB) 83 | 84 | clean: 85 | rm -rf *.o primes tcpproxy testdelay testdelay1 httpload $(OUT) $(OUT6M) 86 | 87 | install: $(LIB) 88 | cp $(OUT)/$(LIB) /usr/local/lib 89 | cp task.h /usr/local/include 90 | 91 | -------------------------------------------------------------------------------- /tiny9/libbio/bwrite.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bwrite.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | long 31 | Bwrite(Biobuf *bp, void *ap, long count) 32 | { 33 | long c; 34 | unsigned char *p; 35 | int i, n, oc; 36 | 37 | p = ap; 38 | c = count; 39 | oc = bp->ocount; 40 | 41 | while(c > 0) { 42 | n = -oc; 43 | if(n > c) 44 | n = c; 45 | if(n == 0) { 46 | if(bp->state != Bwactive) 47 | return Beof; 48 | i = write(bp->fid, bp->bbuf, bp->bsize); 49 | if(i != bp->bsize) { 50 | bp->state = Binactive; 51 | return Beof; 52 | } 53 | bp->offset += i; 54 | oc = -bp->bsize; 55 | continue; 56 | } 57 | memmove(bp->ebuf+oc, p, n); 58 | oc += n; 59 | c -= n; 60 | p += n; 61 | } 62 | bp->ocount = oc; 63 | return count-c; 64 | } 65 | -------------------------------------------------------------------------------- /cc11xx/uartsrv.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | /* 4 | UART for comms using USART0 5 | 6 | Pins: 7 | RX P0.2 8 | TX P0.3 9 | CT P0.4 10 | RT P0.5 11 | 12 | */ 13 | 14 | enum 15 | { 16 | Uidle, 17 | Uready, 18 | Urxing 19 | }; 20 | 21 | static volatile __xdata uint8 nrx, ntx; 22 | static volatile uint8 rxstate; 23 | 24 | void 25 | srvinit() 26 | { 27 | U1CSR = U1CSR_MODE; 28 | 29 | PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U1CFG; 30 | P1SEL |= BIT(4) | BIT(5) | BIT(6) | BIT(7); 31 | 32 | #if MHZ == 26 33 | U1BAUD = 131; 34 | U1GCR = (U1GCR&~U1GCR_BAUD_E) | 9; 35 | #elif MHZ == 24 36 | U1BAUD = 163; 37 | U1GCR = (U1GCR&~U1GCR_BAUD_E) | 9; 38 | #endif 39 | 40 | U1UCR |= U1UCR_FLUSH; 41 | 42 | URX1IF = 0; 43 | U1CSR &= ~U1CSR_RX_BYTE; 44 | U1CSR |= U1CSR_RE; 45 | URX1IE = 1; 46 | } 47 | 48 | void 49 | srvrx() 50 | { 51 | flag &= ~Frxcall; 52 | rxstate = Uready; 53 | nrx = 0; 54 | 55 | // URX0IF = 0; 56 | // U0CSR &= ~U0CSR_RX_BYTE; 57 | // U0CSR |= U0CSR_RE; 58 | } 59 | 60 | void 61 | srvrxlower() 62 | {/*no-op*/} 63 | 64 | void 65 | srvrxpeek() 66 | {/*no-op*/} 67 | 68 | void 69 | urx1intr(void) __interrupt URX1_VECTOR 70 | { 71 | static uint8 byte; 72 | 73 | URX1IF = 0; 74 | byte = U1DBUF; 75 | 76 | if((rxstate == Uidle || rxstate == Uready) && byte == 0xff){ 77 | RED=1; 78 | EA = 0; 79 | WDCTL = BIT(3) | BIT(0); 80 | for(;;) sleep(1000); 81 | } 82 | 83 | if(rxstate == Uidle) 84 | return; /* TODO: panic? */ 85 | 86 | if(rxstate == Uready){ 87 | nrx = 0; 88 | rxstate = Urxing; 89 | } 90 | 91 | rxcall[nrx++] = U1DBUF; 92 | 93 | if(nrx == rxcall[0]){ 94 | rxstate = Uidle; 95 | flag |= Frxcall; 96 | } 97 | } 98 | 99 | void 100 | srvtx() 101 | { 102 | // TODO: check that we never perform overlapping xfers 103 | flag &= ~Ftxcall; 104 | 105 | ntx = 1; 106 | U1DBUF = txcall[0]; 107 | IEN2 |= IEN2_UTX1IE; 108 | } 109 | 110 | void 111 | utx1intr(void) __interrupt UTX1_VECTOR 112 | { 113 | UTX1IF = 0; 114 | 115 | U1DBUF = txcall[ntx++]; 116 | if(ntx == txcall[0]){ 117 | IEN2 &= ~IEN2_UTX1IE; 118 | flag |= Ftxcall; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /tiny9/libtask/COPYRIGHT: -------------------------------------------------------------------------------- 1 | 2 | This software was developed as part of a project at MIT. 3 | 4 | Copyright (c) 2005-2007 Russ Cox, 5 | Massachusetts Institute of Technology 6 | Copyright (c) 2015-2016 Marius Eriksen 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | "Software"), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | === 28 | 29 | Contains parts of an earlier library that has: 30 | 31 | /* 32 | * The authors of this software are Rob Pike, Sape Mullender, and Russ Cox 33 | * Copyright (c) 2003 by Lucent Technologies. 34 | * Permission to use, copy, modify, and distribute this software for any 35 | * purpose without fee is hereby granted, provided that this entire notice 36 | * is included in all copies of any software which is or includes a copy 37 | * or modification of this software and in all copies of the supporting 38 | * documentation for such software. 39 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 40 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 41 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 42 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 43 | */ 44 | 45 | -------------------------------------------------------------------------------- /lib/intel_hex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CC Bootloader - Intel HEX file format functions 3 | * 4 | * Fergus Noble (c) 2011 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 18 | */ 19 | 20 | #include "stdint.h" 21 | #include "intel_hex.h" 22 | 23 | uint8_t hex4(char c) { 24 | // Converts a character representation of a hexadecimal nibble 25 | // into a uint8. If the nibble is invalid it will return 255. 26 | if (c >= '0' && c <= '9') 27 | return (uint8_t)(c - '0'); 28 | else if (c >= 'A' && c <= 'F') 29 | return 10 + (uint8_t)(c - 'A'); 30 | else if (c >= 'a' && c <= 'f') 31 | return 10 + (uint8_t)(c - 'a'); 32 | else 33 | return HEX_INVALID; 34 | } 35 | 36 | uint8_t hex8(char s[]) { 37 | // Converts a string representation of a hexadecimal byte into a uint8. 38 | // TODO: handle the case of hex4 failing. 39 | return hex4(s[1]) + 16*hex4(s[0]); 40 | } 41 | 42 | uint16_t hex16(char s[]) { 43 | // Converts a string representation of a 16-bit hexadecimal word into a uint16. 44 | // TODO: handle the case of hex8 failing. 45 | return hex8(&s[2]) + 256*(uint16_t)hex8(&s[0]); 46 | } 47 | 48 | char to_hex4_ascii(uint8_t x) { 49 | if (x <= 0x9) 50 | return '0' + x; 51 | if (x <= 0xF) 52 | return 'A' + (x - 0xA); 53 | return '!'; 54 | } 55 | 56 | void to_hex8_ascii(char buff[], uint8_t x) { 57 | buff[1] = to_hex4_ascii(x & 0xF); 58 | buff[0] = to_hex4_ascii((x>>4) & 0xF); 59 | } 60 | 61 | void to_hex16_ascii(char buff[], uint16_t x) { 62 | to_hex8_ascii(&buff[2], x & 0xFF); 63 | to_hex8_ascii(&buff[0], (x>>8) & 0xFF); 64 | } 65 | -------------------------------------------------------------------------------- /tiny9/libbio/bgetrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bgetrune.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | long 32 | Bgetrune(Biobuf *bp) 33 | { 34 | int c, i; 35 | Rune rune; 36 | char str[UTFmax]; 37 | 38 | c = Bgetc(bp); 39 | if(c < Runeself) { /* one char */ 40 | bp->runesize = 1; 41 | return c; 42 | } 43 | str[0] = c; 44 | 45 | for(i=1;;) { 46 | c = Bgetc(bp); 47 | if(c < 0) 48 | return c; 49 | str[i++] = c; 50 | 51 | if(fullrune(str, i)) { 52 | bp->runesize = chartorune(&rune, str); 53 | while(i > bp->runesize) { 54 | Bungetc(bp); 55 | i--; 56 | } 57 | return rune; 58 | } 59 | } 60 | } 61 | 62 | int 63 | Bungetrune(Biobuf *bp) 64 | { 65 | 66 | if(bp->state == Bracteof) 67 | bp->state = Bractive; 68 | if(bp->state != Bractive) 69 | return Beof; 70 | bp->icount -= bp->runesize; 71 | bp->runesize = 0; 72 | return 1; 73 | } 74 | -------------------------------------------------------------------------------- /tiny9/libbio/bread.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bread.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | long 31 | Bread(Biobuf *bp, void *ap, long count) 32 | { 33 | long c; 34 | unsigned char *p; 35 | int i, n, ic; 36 | 37 | p = ap; 38 | c = count; 39 | ic = bp->icount; 40 | 41 | while(c > 0) { 42 | n = -ic; 43 | if(n > c) 44 | n = c; 45 | if(n == 0) { 46 | if(bp->state != Bractive) 47 | break; 48 | i = read(bp->fid, bp->bbuf, bp->bsize); 49 | if(i <= 0) { 50 | bp->state = Bracteof; 51 | if(i < 0) 52 | bp->state = Binactive; 53 | break; 54 | } 55 | bp->gbuf = bp->bbuf; 56 | bp->offset += i; 57 | if(i < bp->bsize) { 58 | memmove(bp->ebuf-i, bp->bbuf, i); 59 | bp->gbuf = bp->ebuf-i; 60 | } 61 | ic = -i; 62 | continue; 63 | } 64 | memmove(p, bp->ebuf+ic, n); 65 | c -= n; 66 | ic += n; 67 | p += n; 68 | } 69 | bp->icount = ic; 70 | return count-c; 71 | } 72 | -------------------------------------------------------------------------------- /tiny9/libfmt/vsmprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | static int 24 | fmtStrFlush(Fmt *f) 25 | { 26 | char *s; 27 | int n; 28 | 29 | if(f->start == nil) 30 | return 0; 31 | n = (uintptr)f->farg; 32 | n *= 2; 33 | s = (char*)f->start; 34 | f->start = realloc(s, n); 35 | if(f->start == nil){ 36 | f->farg = nil; 37 | f->to = nil; 38 | f->stop = nil; 39 | free(s); 40 | return 0; 41 | } 42 | f->farg = (void*)(uintptr)n; 43 | f->to = (char*)f->start + ((char*)f->to - s); 44 | f->stop = (char*)f->start + n - 1; 45 | return 1; 46 | } 47 | 48 | int 49 | fmtstrinit(Fmt *f) 50 | { 51 | int n; 52 | 53 | memset(f, 0, sizeof *f); 54 | f->runes = 0; 55 | n = 32; 56 | f->start = malloc(n); 57 | if(f->start == nil) 58 | return -1; 59 | f->to = f->start; 60 | f->stop = (char*)f->start + n - 1; 61 | f->flush = fmtStrFlush; 62 | f->farg = (void*)(uintptr)n; 63 | f->nfmt = 0; 64 | fmtlocaleinit(f, nil, nil, nil); 65 | return 0; 66 | } 67 | 68 | /* 69 | * print into an allocated string buffer 70 | */ 71 | char* 72 | vsmprint(char *fmt, va_list args) 73 | { 74 | Fmt f; 75 | int n; 76 | 77 | if(fmtstrinit(&f) < 0) 78 | return nil; 79 | VA_COPY(f.args,args); 80 | n = dofmt(&f, fmt); 81 | VA_END(f.args); 82 | if(n < 0){ 83 | free(f.start); 84 | return nil; 85 | } 86 | return fmtstrflush(&f); 87 | } 88 | -------------------------------------------------------------------------------- /tiny9/libfmt/pow10.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * this table might overflow 127-bit exponent representations. 25 | * in that case, truncate it after 1.0e38. 26 | * it is important to get all one can from this 27 | * routine since it is used in atof to scale numbers. 28 | * the presumption is that C converts fp numbers better 29 | * than multipication of lower powers of 10. 30 | */ 31 | 32 | static 33 | double tab[] = 34 | { 35 | 1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8, 1.0e9, 36 | 1.0e10,1.0e11,1.0e12,1.0e13,1.0e14,1.0e15,1.0e16,1.0e17,1.0e18,1.0e19, 37 | 1.0e20,1.0e21,1.0e22,1.0e23,1.0e24,1.0e25,1.0e26,1.0e27,1.0e28,1.0e29, 38 | 1.0e30,1.0e31,1.0e32,1.0e33,1.0e34,1.0e35,1.0e36,1.0e37,1.0e38,1.0e39, 39 | 1.0e40,1.0e41,1.0e42,1.0e43,1.0e44,1.0e45,1.0e46,1.0e47,1.0e48,1.0e49, 40 | 1.0e50,1.0e51,1.0e52,1.0e53,1.0e54,1.0e55,1.0e56,1.0e57,1.0e58,1.0e59, 41 | 1.0e60,1.0e61,1.0e62,1.0e63,1.0e64,1.0e65,1.0e66,1.0e67,1.0e68,1.0e69, 42 | }; 43 | 44 | double 45 | __fmtpow10(int n) 46 | { 47 | int m; 48 | 49 | if(n < 0) { 50 | n = -n; 51 | if(n < (int)(sizeof(tab)/sizeof(tab[0]))) 52 | return 1/tab[n]; 53 | m = n/2; 54 | return __fmtpow10(-m) * __fmtpow10(m-n); 55 | } 56 | if(n < (int)(sizeof(tab)/sizeof(tab[0]))) 57 | return tab[n]; 58 | m = n/2; 59 | return __fmtpow10(m) * __fmtpow10(n-m); 60 | } 61 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtlocale.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * Fill in the internationalization stuff in the State structure. 25 | * For nil arguments, provide the sensible defaults: 26 | * decimal is a period 27 | * thousands separator is a comma 28 | * thousands are marked every three digits 29 | */ 30 | void 31 | fmtlocaleinit(Fmt *f, char *decimal, char *thousands, char *grouping) 32 | { 33 | if(decimal == nil || decimal[0] == '\0') 34 | decimal = "."; 35 | if(thousands == nil) 36 | thousands = ","; 37 | if(grouping == nil) 38 | grouping = "\3"; 39 | f->decimal = decimal; 40 | f->thousands = thousands; 41 | f->grouping = grouping; 42 | } 43 | 44 | /* 45 | * We are about to emit a digit in e.g. %'d. If that digit would 46 | * overflow a thousands (e.g.) grouping, tell the caller to emit 47 | * the thousands separator. Always advance the digit counter 48 | * and pointer into the grouping descriptor. 49 | */ 50 | int 51 | __needsep(int *ndig, char **grouping) 52 | { 53 | int group; 54 | 55 | (*ndig)++; 56 | group = *(unsigned char*)*grouping; 57 | /* CHAR_MAX means no further grouping. \0 means we got the empty string */ 58 | if(group == 0xFF || group == 0x7f || group == 0x00) 59 | return 0; 60 | if(*ndig > group){ 61 | /* if we're at end of string, continue with this grouping; else advance */ 62 | if((*grouping)[1] != '\0') 63 | (*grouping)++; 64 | *ndig = 1; 65 | return 1; 66 | } 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /tiny9/libfmt/nan64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | /* 20 | * 64-bit IEEE not-a-number routines. 21 | * This is big/little-endian portable assuming that 22 | * the 64-bit doubles and 64-bit integers have the 23 | * same byte ordering. 24 | */ 25 | 26 | #include 27 | #include 28 | #include "fmtdef.h" 29 | 30 | static uvlong uvnan = ((uvlong)0x7FF00000<<32)|0x00000001; 31 | static uvlong uvinf = ((uvlong)0x7FF00000<<32)|0x00000000; 32 | static uvlong uvneginf = ((uvlong)0xFFF00000<<32)|0x00000000; 33 | 34 | /* gcc sees through the obvious casts. */ 35 | static uvlong 36 | d2u(double d) 37 | { 38 | union { 39 | uvlong v; 40 | double d; 41 | } u; 42 | assert(sizeof(u.d) == sizeof(u.v)); 43 | u.d = d; 44 | return u.v; 45 | } 46 | 47 | static double 48 | u2d(uvlong v) 49 | { 50 | union { 51 | uvlong v; 52 | double d; 53 | } u; 54 | assert(sizeof(u.d) == sizeof(u.v)); 55 | u.v = v; 56 | return u.d; 57 | } 58 | 59 | double 60 | __NaN(void) 61 | { 62 | return u2d(uvnan); 63 | } 64 | 65 | int 66 | __isNaN(double d) 67 | { 68 | uvlong x; 69 | 70 | x = d2u(d); 71 | /* IEEE 754: exponent bits 0x7FF and non-zero mantissa */ 72 | return (x&uvinf) == uvinf && (x&~uvneginf) != 0; 73 | } 74 | 75 | double 76 | __Inf(int sign) 77 | { 78 | return u2d(sign < 0 ? uvneginf : uvinf); 79 | } 80 | 81 | int 82 | __isInf(double d, int sign) 83 | { 84 | uvlong x; 85 | 86 | x = d2u(d); 87 | if(sign == 0) 88 | return x==uvinf || x==uvneginf; 89 | else if(sign > 0) 90 | return x==uvinf; 91 | else 92 | return x==uvneginf; 93 | } 94 | -------------------------------------------------------------------------------- /tiny9/libbio/bprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bprint.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | Revisions Copyright © 2010 Google Inc. All rights reserved. 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | int 32 | Bprint(Biobuf *bp, char *fmt, ...) 33 | { 34 | int n; 35 | va_list arg; 36 | 37 | va_start(arg, fmt); 38 | n = Bvprint(bp, fmt, arg); 39 | va_end(arg); 40 | return n; 41 | } 42 | 43 | static int 44 | bflush(Fmt *f) 45 | { 46 | Biobuf *bp; 47 | 48 | if(f->stop == nil) 49 | return 0; 50 | 51 | bp = f->farg; 52 | bp->ocount = (char*)f->to - (char*)f->stop; 53 | if(Bflush(bp) < 0) { 54 | f->stop = nil; 55 | f->to = nil; 56 | return 0; 57 | } 58 | f->to = (char*)f->stop + bp->ocount; 59 | 60 | return 1; 61 | } 62 | 63 | int 64 | Bvprint(Biobuf *bp, char *fmt, va_list arg) 65 | { 66 | int n; 67 | Fmt f; 68 | 69 | memset(&f, 0, sizeof f); 70 | fmtlocaleinit(&f, nil, nil, nil); 71 | f.stop = bp->ebuf; 72 | f.to = (char*)f.stop + bp->ocount; 73 | f.flush = bflush; 74 | f.farg = bp; 75 | 76 | n = fmtvprint(&f, fmt, arg); 77 | 78 | if(f.stop != nil) 79 | bp->ocount = (char*)f.to - (char*)f.stop; 80 | 81 | return n; 82 | } 83 | -------------------------------------------------------------------------------- /tiny9/libfmt/charstod.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | /* 24 | * Reads a floating-point number by interpreting successive characters 25 | * returned by (*f)(vp). The last call it makes to f terminates the 26 | * scan, so is not a character in the number. It may therefore be 27 | * necessary to back up the input stream up one byte after calling charstod. 28 | */ 29 | 30 | double 31 | fmtcharstod(int(*f)(void*), void *vp) 32 | { 33 | double num, dem; 34 | int neg, eneg, dig, exp, c; 35 | 36 | num = 0; 37 | neg = 0; 38 | dig = 0; 39 | exp = 0; 40 | eneg = 0; 41 | 42 | c = (*f)(vp); 43 | while(c == ' ' || c == '\t') 44 | c = (*f)(vp); 45 | if(c == '-' || c == '+'){ 46 | if(c == '-') 47 | neg = 1; 48 | c = (*f)(vp); 49 | } 50 | while(c >= '0' && c <= '9'){ 51 | num = num*10 + c-'0'; 52 | c = (*f)(vp); 53 | } 54 | if(c == '.') 55 | c = (*f)(vp); 56 | while(c >= '0' && c <= '9'){ 57 | num = num*10 + c-'0'; 58 | dig++; 59 | c = (*f)(vp); 60 | } 61 | if(c == 'e' || c == 'E'){ 62 | c = (*f)(vp); 63 | if(c == '-' || c == '+'){ 64 | if(c == '-'){ 65 | dig = -dig; 66 | eneg = 1; 67 | } 68 | c = (*f)(vp); 69 | } 70 | while(c >= '0' && c <= '9'){ 71 | exp = exp*10 + c-'0'; 72 | c = (*f)(vp); 73 | } 74 | } 75 | exp -= dig; 76 | if(exp < 0){ 77 | exp = -exp; 78 | eneg = !eneg; 79 | } 80 | dem = __fmtpow10(exp); 81 | if(eneg) 82 | num /= dem; 83 | else 84 | num *= dem; 85 | if(neg) 86 | return -num; 87 | return num; 88 | } 89 | -------------------------------------------------------------------------------- /unix/lib/table.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | enum 12 | { 13 | MAXTAB = 1<<19 14 | }; 15 | 16 | struct Table 17 | { 18 | int fd; 19 | uint8 *bp; 20 | uint8 *ep; 21 | uint keysize; 22 | uint valuesize; 23 | uint entrysize; 24 | }; 25 | 26 | Table* 27 | tableopen(char *name, uint keysize, uint valuesize) 28 | { 29 | Table *tab; 30 | char *dir = getenv("TAP"); 31 | char path[256]; 32 | int n; 33 | 34 | if(dir == nil){ 35 | werrstr("$TAP not defined"); 36 | return nil; 37 | } 38 | 39 | tab = malloc(sizeof *tab); 40 | if(tab == nil) 41 | return nil; 42 | 43 | snprint(path, sizeof path, "%s/%s", dir, name); 44 | 45 | tab->fd = open(path, O_CREAT|O_RDWR, 0600); 46 | if(tab->fd < 0){ 47 | werrstr("open(%s): %r", path); 48 | free(tab); 49 | return nil; 50 | } 51 | 52 | tab->keysize = keysize; 53 | tab->valuesize = valuesize; 54 | tab->entrysize = keysize+valuesize; 55 | 56 | tab->bp = mmap(0, MAXTAB, PROT_READ|PROT_WRITE, MAP_SHARED, tab->fd, 0); 57 | if(tab->bp == MAP_FAILED){ 58 | werrstr("mmap: %r"); 59 | close(tab->fd); 60 | free(tab); 61 | return nil; 62 | } 63 | 64 | if((n=lseek(tab->fd, 0, SEEK_END)) < 0){ 65 | werrstr("lseek: %r"); 66 | close(tab->fd); 67 | free(tab); 68 | return nil; 69 | } 70 | 71 | tab->ep = tab->bp + n; 72 | 73 | return tab; 74 | } 75 | 76 | int 77 | tablewrite(Table *tab, void *k, void *v) 78 | { 79 | uint n; 80 | uint8 *vv; 81 | 82 | if((vv=tablelookup(tab, k)) != nil){ 83 | memcpy(vv, v, tab->valuesize); 84 | return 0; 85 | } 86 | 87 | n = tab->ep-tab->bp+tab->entrysize; 88 | /* TODO: look up first */ 89 | 90 | if(n > MAXTAB){ 91 | werrstr("Table exceeds maximum size"); 92 | return -1; 93 | } 94 | 95 | ftruncate(tab->fd, n); 96 | 97 | memcpy(tab->ep, k, tab->keysize); 98 | tab->ep += tab->keysize; 99 | memcpy(tab->ep, v, tab->valuesize); 100 | tab->ep += tab->valuesize; 101 | 102 | /* Break out into separate call? */ 103 | msync(tab->bp, n, MS_SYNC); 104 | 105 | return 0; 106 | } 107 | 108 | void* 109 | tablelookup(Table *tab, void *k) 110 | { 111 | uint8 *p; 112 | 113 | for(p=tab->bp; p < tab->ep; p += tab->entrysize) 114 | if(memcmp(p, k, tab->keysize) == 0) 115 | return p+tab->keysize; 116 | 117 | return nil; 118 | } 119 | -------------------------------------------------------------------------------- /tiny9/tiny9.mk: -------------------------------------------------------------------------------- 1 | TINY9 := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) 2 | 3 | vpath %.c $(TINY9) 4 | vpath %.S $(TINY9) 5 | vpath %.h $(TINY9) 6 | 7 | LIBTASKOBJECTS =\ 8 | libtask/asm.o\ 9 | libtask/channel.o\ 10 | libtask/context.o\ 11 | libtask/qlock.o\ 12 | libtask/print.o\ 13 | libtask/rendez.o\ 14 | libtask/task.o\ 15 | libtask/fd.o\ 16 | libtask/net.o 17 | 18 | LIBTASKOFILES = $(addprefix $(O)/, $(LIBTASKOBJECTS)) 19 | 20 | LIBCOBJECTS =\ 21 | libc/ctime.o\ 22 | libc/time.o\ 23 | libc/tm2sec.o\ 24 | libc/zoneinfo.o\ 25 | libc/errstr.o\ 26 | libc/strecpy.o\ 27 | libc/printhex.o\ 28 | libc/debug.o 29 | 30 | LIBCOFILES = $(addprefix $(O)/, $(LIBCOBJECTS)) 31 | 32 | LIBBIOOBJECTS =\ 33 | libbio/bbuffered.o\ 34 | libbio/bfildes.o\ 35 | libbio/bflush.o\ 36 | libbio/bgetc.o\ 37 | libbio/bgetd.o\ 38 | libbio/bgetrune.o\ 39 | libbio/binit.o\ 40 | libbio/boffset.o\ 41 | libbio/bputc.o\ 42 | libbio/bprint.o\ 43 | libbio/brdline.o\ 44 | libbio/brdstr.o\ 45 | libbio/bread.o\ 46 | libbio/bseek.o\ 47 | libbio/bwrite.o 48 | 49 | LIBBIOOFILES = $(addprefix $(O)/, $(LIBBIOOBJECTS)) 50 | 51 | LIBUTFOBJECTS =\ 52 | libutf/rune.o\ 53 | libutf/runetype.o\ 54 | libutf/utfecpy.o\ 55 | libutf/utflen.o\ 56 | libutf/utfnlen.o\ 57 | libutf/utfrrune.o\ 58 | libutf/utfrune.o\ 59 | libutf/utfutf.o 60 | 61 | LIBUTFOFILES = $(addprefix $(O)/, $(LIBUTFOBJECTS)) 62 | 63 | LIBFMTOBJECTS =\ 64 | libfmt/charstod.o\ 65 | libfmt/dofmt.o\ 66 | libfmt/dorfmt.o\ 67 | libfmt/fltfmt.o\ 68 | libfmt/fmt.o\ 69 | libfmt/fmtfd.o\ 70 | libfmt/fmtfdflush.o\ 71 | libfmt/fmtfix.o\ 72 | libfmt/fmthex.o\ 73 | libfmt/fmtlocale.o\ 74 | libfmt/fmtlock.o\ 75 | libfmt/fmtnull.o\ 76 | libfmt/fmtprint.o\ 77 | libfmt/fmtquote.o\ 78 | libfmt/fmtrune.o\ 79 | libfmt/fmtstr.o\ 80 | libfmt/fmtvprint.o\ 81 | libfmt/fprint.o\ 82 | libfmt/nan64.o\ 83 | libfmt/panic.o\ 84 | libfmt/pow10.o\ 85 | libfmt/print.o\ 86 | libfmt/seprint.o\ 87 | libfmt/smprint.o\ 88 | libfmt/snprint.o\ 89 | libfmt/sprint.o\ 90 | libfmt/strtod.o\ 91 | libfmt/vfprint.o\ 92 | libfmt/vseprint.o\ 93 | libfmt/vsmprint.o\ 94 | libfmt/vsnprint.o 95 | 96 | LIBFMTOFILES = $(addprefix $(O)/, $(LIBFMTOBJECTS)) 97 | 98 | TINY9OBJECTS=\ 99 | $(LIBCOBJECTS)\ 100 | $(LIBUTFOBJECTS)\ 101 | $(LIBFMTOBJECTS) 102 | 103 | TINY9OFILES = $(addprefix $(O)/, $(TINY9OBJECTS)) 104 | 105 | CFLAGS+=\ 106 | -I$(TINY9)/include\ 107 | -I$(TINY9)/$(TARG)/include 108 | -------------------------------------------------------------------------------- /tiny9/libbio/bgetc.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bgetc.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | int 31 | Bgetc(Biobuf *bp) 32 | { 33 | int i; 34 | 35 | loop: 36 | i = bp->icount; 37 | if(i != 0) { 38 | bp->icount = i+1; 39 | return bp->ebuf[i]; 40 | } 41 | if(bp->state != Bractive) { 42 | if(bp->state == Bracteof) 43 | bp->state = Bractive; 44 | return Beof; 45 | } 46 | /* 47 | * get next buffer, try to keep Bungetsize 48 | * characters pre-catenated from the previous 49 | * buffer to allow that many ungets. 50 | */ 51 | memmove(bp->bbuf-Bungetsize, bp->ebuf-Bungetsize, Bungetsize); 52 | i = read(bp->fid, bp->bbuf, bp->bsize); 53 | bp->gbuf = bp->bbuf; 54 | if(i <= 0) { 55 | bp->state = Bracteof; 56 | if(i < 0) 57 | bp->state = Binactive; 58 | return Beof; 59 | } 60 | if(i < bp->bsize) { 61 | memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, i+Bungetsize); 62 | bp->gbuf = bp->ebuf-i; 63 | } 64 | bp->icount = -i; 65 | bp->offset += i; 66 | goto loop; 67 | } 68 | 69 | int 70 | Bungetc(Biobuf *bp) 71 | { 72 | 73 | if(bp->state == Bracteof) 74 | bp->state = Bractive; 75 | if(bp->state != Bractive) 76 | return Beof; 77 | bp->icount--; 78 | return 1; 79 | } 80 | -------------------------------------------------------------------------------- /libradio/conv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "rcall.h" 4 | 5 | uint 6 | convM2R(uint8 *p, uint8 n, Rcall *r) 7 | { 8 | uint8 size; 9 | 10 | if(n == 0) return 0; 11 | size = U8GET(p); 12 | p += 1; 13 | 14 | if(n < size) 15 | return 0; 16 | 17 | r->type = U8GET(p); 18 | p+= 1; 19 | r->flag = U8GET(p); 20 | p += 1; 21 | 22 | switch(r->type){ 23 | default: return 0; 24 | 25 | case Tping: 26 | case Rping: 27 | case Rtx: 28 | break; 29 | 30 | case Trx: 31 | r->timeoutms = U16GET(p); 32 | p += 2; 33 | r->filterbyte3 = U8GET(p); 34 | p += 1; 35 | break; 36 | 37 | case Ttxrx: 38 | r->timeoutms = U16GET(p); 39 | p += 2; 40 | r->filterbyte3 = U8GET(p); 41 | p += 1; 42 | 43 | case Ttx: 44 | r->preamblems = U16GET(p); 45 | p += 2; 46 | case Rrx: 47 | case Rtxrx: 48 | memcpy(r->pkt, p, sizeof r->pkt); 49 | p += sizeof r->pkt; 50 | break; 51 | 52 | case Rerr: 53 | r->err = U8GET(p); 54 | p += 1; 55 | } 56 | 57 | return size; 58 | } 59 | 60 | uint 61 | convR2M(Rcall *r, uint8 *ap, uint8 n) 62 | { 63 | uint8 *p = ap; 64 | uint8 size; 65 | 66 | size = 3; // size, type, flag 67 | switch(r->type){ 68 | default: return 0; 69 | 70 | 71 | case Rtx: 72 | case Tping: 73 | case Rping: 74 | break; 75 | 76 | case Trx: 77 | size += 2; // timeout 78 | size += 1; // filterbyte3 79 | break; 80 | 81 | case Ttxrx: 82 | size += 2; // timeout 83 | size += 1; // filterbyte3 84 | case Ttx: 85 | size += 2; // preamble 86 | case Rrx: 87 | case Rtxrx: 88 | size += Npkt; 89 | break; 90 | 91 | case Rerr: 92 | size += 1; 93 | break; 94 | } 95 | 96 | if(n < size) 97 | return 0; 98 | 99 | U8PUT(p, size); 100 | p += 1; 101 | U8PUT(p, r->type); 102 | p += 1; 103 | U8PUT(p, r->flag); 104 | p += 1; 105 | 106 | switch(r->type){ 107 | default: 108 | return 0; 109 | 110 | case Rtx: 111 | case Tping: 112 | case Rping: 113 | break; 114 | 115 | case Trx: 116 | U16PUT(p, r->timeoutms); 117 | p += 2; 118 | U8PUT(p, r->filterbyte3); 119 | p += 1; 120 | break; 121 | 122 | case Ttxrx: 123 | U16PUT(p, r->timeoutms); 124 | p += 2; 125 | U8PUT(p, r->filterbyte3); 126 | p += 1; 127 | case Ttx: 128 | U16PUT(p, r->preamblems); 129 | p += 2; 130 | 131 | case Rrx: 132 | case Rtxrx: 133 | memcpy(p, r->pkt, sizeof r->pkt); 134 | p += sizeof r->pkt; 135 | break; 136 | 137 | case Rerr: 138 | U8PUT(p, r->err); 139 | p += 1; 140 | break; 141 | } 142 | 143 | if(size != p-ap) 144 | return 0; 145 | 146 | return size; 147 | } 148 | -------------------------------------------------------------------------------- /tiny9/libtask/qlock.c: -------------------------------------------------------------------------------- 1 | #include "taskimpl.h" 2 | 3 | /* 4 | * locking 5 | */ 6 | static int 7 | _qlock(QLock *l, int block) 8 | { 9 | if(l->owner == nil){ 10 | l->owner = taskrunning; 11 | return 1; 12 | } 13 | if(!block) 14 | return 0; 15 | addtask(&l->waiting, taskrunning); 16 | taskstate("qlock"); 17 | taskswitch(); 18 | if(l->owner != taskrunning){ 19 | fprint(2, "qlock: owner=%p self=%p oops\n", l->owner, taskrunning); 20 | abort(); 21 | } 22 | return 1; 23 | } 24 | 25 | void 26 | qlock(QLock *l) 27 | { 28 | _qlock(l, 1); 29 | } 30 | 31 | int 32 | canqlock(QLock *l) 33 | { 34 | return _qlock(l, 0); 35 | } 36 | 37 | void 38 | qunlock(QLock *l) 39 | { 40 | Task *ready; 41 | 42 | if(l->owner == 0){ 43 | fprint(2, "qunlock: owner=0\n"); 44 | abort(); 45 | } 46 | if((l->owner = ready = l->waiting.head) != nil){ 47 | deltask(&l->waiting, ready); 48 | taskready(ready); 49 | } 50 | } 51 | 52 | static int 53 | _rlock(RWLock *l, int block) 54 | { 55 | if(l->writer == nil && l->wwaiting.head == nil){ 56 | l->readers++; 57 | return 1; 58 | } 59 | if(!block) 60 | return 0; 61 | addtask(&l->rwaiting, taskrunning); 62 | taskstate("rlock"); 63 | taskswitch(); 64 | return 1; 65 | } 66 | 67 | void 68 | rlock(RWLock *l) 69 | { 70 | _rlock(l, 1); 71 | } 72 | 73 | int 74 | canrlock(RWLock *l) 75 | { 76 | return _rlock(l, 0); 77 | } 78 | 79 | static int 80 | _wlock(RWLock *l, int block) 81 | { 82 | if(l->writer == nil && l->readers == 0){ 83 | l->writer = taskrunning; 84 | return 1; 85 | } 86 | if(!block) 87 | return 0; 88 | addtask(&l->wwaiting, taskrunning); 89 | taskstate("wlock"); 90 | taskswitch(); 91 | return 1; 92 | } 93 | 94 | void 95 | wlock(RWLock *l) 96 | { 97 | _wlock(l, 1); 98 | } 99 | 100 | int 101 | canwlock(RWLock *l) 102 | { 103 | return _wlock(l, 0); 104 | } 105 | 106 | void 107 | runlock(RWLock *l) 108 | { 109 | Task *t; 110 | 111 | if(--l->readers == 0 && (t = l->wwaiting.head) != nil){ 112 | deltask(&l->wwaiting, t); 113 | l->writer = t; 114 | taskready(t); 115 | } 116 | } 117 | 118 | void 119 | wunlock(RWLock *l) 120 | { 121 | Task *t; 122 | 123 | if(l->writer == nil){ 124 | fprint(2, "wunlock: not locked\n"); 125 | abort(); 126 | } 127 | l->writer = nil; 128 | if(l->readers != 0){ 129 | fprint(2, "wunlock: readers\n"); 130 | abort(); 131 | } 132 | while((t = l->rwaiting.head) != nil){ 133 | deltask(&l->rwaiting, t); 134 | l->readers++; 135 | taskready(t); 136 | } 137 | if(l->readers == 0 && (t = l->wwaiting.head) != nil){ 138 | deltask(&l->wwaiting, t); 139 | l->writer = t; 140 | taskready(t); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /tiny9/libbio/bseek.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/bseek.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | vlong 31 | Bseek(Biobuf *bp, vlong offset, int base) 32 | { 33 | vlong n, d; 34 | int bufsz; 35 | 36 | #ifndef _WIN32 37 | if(sizeof(offset) != sizeof(off_t)) { 38 | fprint(2, "Bseek: libbio compiled with %d-byte offset\n", sizeof(off_t)); 39 | abort(); 40 | } 41 | #endif 42 | 43 | switch(bp->state) { 44 | default: 45 | fprint(2, "Bseek: unknown state %d\n", bp->state); 46 | return Beof; 47 | 48 | case Bracteof: 49 | bp->state = Bractive; 50 | bp->icount = 0; 51 | bp->gbuf = bp->ebuf; 52 | 53 | case Bractive: 54 | n = offset; 55 | if(base == 1) { 56 | n += Boffset(bp); 57 | base = 0; 58 | } 59 | 60 | /* 61 | * try to seek within buffer 62 | */ 63 | if(base == 0) { 64 | d = n - Boffset(bp); 65 | bufsz = bp->ebuf - bp->gbuf; 66 | if(-bufsz <= d && d <= bufsz){ 67 | bp->icount += d; 68 | if(d >= 0) { 69 | if(bp->icount <= 0) 70 | return n; 71 | } else { 72 | if(bp->ebuf - bp->gbuf >= -bp->icount) 73 | return n; 74 | } 75 | } 76 | } 77 | 78 | /* 79 | * reset the buffer 80 | */ 81 | n = lseek(bp->fid, n, base); 82 | bp->icount = 0; 83 | bp->gbuf = bp->ebuf; 84 | break; 85 | 86 | case Bwactive: 87 | Bflush(bp); 88 | n = lseek(bp->fid, offset, base); 89 | break; 90 | } 91 | bp->offset = n; 92 | return n; 93 | } 94 | -------------------------------------------------------------------------------- /tiny9/include/libc.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* This turns on plan9-like print behavior. */ 6 | #define PLAN9PORT 1 7 | #define TINY9 1 8 | 9 | #define ERRMAX 128 /* max length of error string */ 10 | 11 | void werrstr(char*, ...); 12 | int errstr(char*, uint); 13 | void rerrstr(char*, uint); 14 | void panic(char *fmt, ...); 15 | 16 | void printhex(uint8*, uint); 17 | 18 | 19 | extern int debug; 20 | #define dprint(...) if(debug)fprint(2, __VA_ARGS__) 21 | #define dprinthex(p, n) if(debug)printhex(p, n) 22 | 23 | typedef 24 | struct Tm 25 | { 26 | int sec; 27 | int min; 28 | int hour; 29 | int mday; 30 | int mon; 31 | int year; 32 | int wday; 33 | int yday; 34 | char zone[4]; 35 | int tzoff; 36 | } Tm; 37 | 38 | #define gmtime p9gmtime 39 | #define localtime p9localtime 40 | #define asctime p9asctime 41 | #define ctime p9ctime 42 | #define cputime p9cputime 43 | #define times p9times 44 | #define tm2sec p9tm2sec 45 | #define nsec p9nsec 46 | 47 | long now(); 48 | 49 | Tm* p9gmtime(long); 50 | Tm* p9localtime(long); 51 | char* p9asctime(Tm*); 52 | char* p9ctime(long); 53 | long p9tm2sec(Tm*); 54 | 55 | char* strecpy(char *dst, char *edst, char *src); 56 | 57 | #define OREAD 0 /* open for read */ 58 | #define OWRITE 1 /* write */ 59 | #define ORDWR 2 /* read and write */ 60 | #define OEXEC 3 /* execute, == read but check execute permission */ 61 | #define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ 62 | #define ORCLOSE 64 /* or'ed in, remove on close */ 63 | #define ODIRECT 128 /* or'ed in, direct access */ 64 | #define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */ 65 | #define OAPPEND 0x4000 /* or'ed in, append only */ 66 | 67 | #define DMDIR 0x80000000 /* mode bit for directories */ 68 | #define DMAPPEND 0x40000000 /* mode bit for append only files */ 69 | #define DMEXCL 0x20000000 /* mode bit for exclusive use files */ 70 | #define DMMOUNT 0x10000000 /* mode bit for mounted channel */ 71 | #define DMAUTH 0x08000000 /* mode bit for authentication file */ 72 | #define DMTMP 0x04000000 /* mode bit for non-backed-up file */ 73 | #define DMSYMLINK 0x02000000 /* mode bit for symbolic link (Unix, 9P2000.u) */ 74 | #define DMDEVICE 0x00800000 /* mode bit for device file (Unix, 9P2000.u) */ 75 | #define DMNAMEDPIPE 0x00200000 /* mode bit for named pipe (Unix, 9P2000.u) */ 76 | #define DMSOCKET 0x00100000 /* mode bit for socket (Unix, 9P2000.u) */ 77 | #define DMSETUID 0x00080000 /* mode bit for setuid (Unix, 9P2000.u) */ 78 | #define DMSETGID 0x00040000 /* mode bit for setgid (Unix, 9P2000.u) */ 79 | 80 | #define DMREAD 0x4 /* mode bit for read permission */ 81 | #define DMWRITE 0x2 /* mode bit for write permission */ 82 | #define DMEXEC 0x1 /* mode bit for execute permission */ 83 | -------------------------------------------------------------------------------- /tiny9/libc/tm2sec.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is distributred under the Lucent Public License, Version 1.02. 4 | See ../../LUCENT 5 | 6 | Copyright © 2000-2009 Lucent Technologies. All Rights Reserved. 7 | Portions Copyright © 2001-2008 Russ Cox 8 | Portions Copyright © 2008-2009 Google Inc. 9 | */ 10 | #include 11 | #include 12 | 13 | #include "zoneinfo.h" 14 | 15 | #define SEC2MIN 60L 16 | #define SEC2HOUR (60L*SEC2MIN) 17 | #define SEC2DAY (24L*SEC2HOUR) 18 | 19 | /* 20 | * days per month plus days/year 21 | */ 22 | static int dmsize[] = 23 | { 24 | 365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 25 | }; 26 | static int ldmsize[] = 27 | { 28 | 366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 29 | }; 30 | 31 | /* 32 | * return the days/month for the given year 33 | */ 34 | static int * 35 | yrsize(int y) 36 | { 37 | if((y%4) == 0 && ((y%100) != 0 || (y%400) == 0)) 38 | return ldmsize; 39 | else 40 | return dmsize; 41 | } 42 | 43 | /* 44 | * compute seconds since Jan 1 1970 GMT 45 | * and convert to our timezone. 46 | */ 47 | long 48 | tm2sec(Tm *tm) 49 | { 50 | Tinfo ti0, ti1, *ti; 51 | long secs; 52 | int i, yday, year, *d2m; 53 | 54 | secs = 0; 55 | 56 | /* 57 | * seconds per year 58 | */ 59 | year = tm->year + 1900; 60 | for(i = 1970; i < year; i++){ 61 | d2m = yrsize(i); 62 | secs += d2m[0] * SEC2DAY; 63 | } 64 | 65 | /* 66 | * if mday is set, use mon and mday to compute yday 67 | */ 68 | if(tm->mday){ 69 | yday = 0; 70 | d2m = yrsize(year); 71 | for(i=0; imon; i++) 72 | yday += d2m[i+1]; 73 | yday += tm->mday-1; 74 | }else{ 75 | yday = tm->yday; 76 | } 77 | secs += yday * SEC2DAY; 78 | 79 | /* 80 | * hours, minutes, seconds 81 | */ 82 | secs += tm->hour * SEC2HOUR; 83 | secs += tm->min * SEC2MIN; 84 | secs += tm->sec; 85 | 86 | /* 87 | * Assume the local time zone if zone is not GMT 88 | */ 89 | if(strcmp(tm->zone, "GMT") != 0) { 90 | i = zonelookuptinfo(&ti0, secs); 91 | ti = &ti0; 92 | if (i != -1) 93 | if (ti->tzoff!=0) { 94 | /* 95 | * to what local time period `secs' belongs? 96 | */ 97 | if (ti->tzoff>0) { 98 | /* 99 | * east of GMT; check previous local time transition 100 | */ 101 | if (ti->t+ti->tzoff > secs) 102 | if (zonetinfo(&ti1, i-1)!=-1) 103 | ti = &ti1; 104 | } else 105 | /* 106 | * west of GMT; check next local time transition 107 | */ 108 | if (zonetinfo(&ti1, i+1)) 109 | if (ti1.t+ti->tzoff < secs) 110 | ti = &ti1; 111 | // fprint(2, "tt: %ld+%d %ld\n", (long)ti->t, ti->tzoff, (long)secs); 112 | secs -= ti->tzoff; 113 | } 114 | } 115 | 116 | if(secs < 0) 117 | secs = 0; 118 | return secs; 119 | } 120 | -------------------------------------------------------------------------------- /tiny9/libfmt/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson, 3 | * with contributions from Mike Burrows and Sean Dorward. 4 | * 5 | * Copyright (c) 2002-2006 by Lucent Technologies. 6 | * Portions Copyright (c) 2004 Google Inc. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose without fee is hereby granted, provided that this entire notice 10 | * is included in all copies of any software which is or includes a copy 11 | * or modification of this software and in all copies of the supporting 12 | * documentation for such software. 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "fmtdef.h" 22 | 23 | int 24 | main(int argc, char *argv[]) 25 | { 26 | quotefmtinstall(); 27 | print("hello world\n"); 28 | print("x: %x\n", 0x87654321); 29 | print("u: %u\n", 0x87654321); 30 | print("d: %d\n", 0x87654321); 31 | print("s: %s\n", "hi there"); 32 | print("q: %q\n", "hi i'm here"); 33 | print("c: %c\n", '!'); 34 | print("g: %g %g %g\n", 3.14159, 3.14159e10, 3.14159e-10); 35 | print("e: %e %e %e\n", 3.14159, 3.14159e10, 3.14159e-10); 36 | print("f: %f %f %f\n", 3.14159, 3.14159e10, 3.14159e-10); 37 | print("smiley: %C\n", (Rune)0x263a); 38 | print("%g %.18g\n", 2e25, 2e25); 39 | print("%2.18g\n", 1.0); 40 | print("%2.18f\n", 1.0); 41 | print("%f\n", 3.1415927/4); 42 | print("%d\n", 23); 43 | print("%i\n", 23); 44 | print("%0.10d\n", 12345); 45 | 46 | /* test %4$d formats */ 47 | print("%3$d %4$06d %2$d %1$d\n", 444, 333, 111, 222); 48 | print("%3$d %4$06d %2$d %1$d\n", 444, 333, 111, 222); 49 | print("%3$d %4$*5$06d %2$d %1$d\n", 444, 333, 111, 222, 20); 50 | print("%3$hd %4$*5$06d %2$d %1$d\n", 444, 333, (short)111, 222, 20); 51 | print("%3$lld %4$*5$06d %2$d %1$d\n", 444, 333, 111LL, 222, 20); 52 | 53 | /* test %'d formats */ 54 | print("%'d %'d %'d\n", 1, 2222, 33333333); 55 | print("%'019d\n", 0); 56 | print("%08d %08d %08d\n", 1, 2222, 33333333); 57 | print("%'08d %'08d %'08d\n", 1, 2222, 33333333); 58 | print("%'x %'X %'b\n", 0x11111111, 0xabcd1234, 12345); 59 | print("%'lld %'lld %'lld\n", 1LL, 222222222LL, 3333333333333LL); 60 | print("%019lld %019lld %019lld\n", 1LL, 222222222LL, 3333333333333LL); 61 | print("%'019lld %'019lld %'019lld\n", 1LL, 222222222LL, 3333333333333LL); 62 | print("%'020lld %'020lld %'020lld\n", 1LL, 222222222LL, 3333333333333LL); 63 | print("%'llx %'llX %'llb\n", 0x111111111111LL, 0xabcd12345678LL, 112342345LL); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /tiny9/libc/errstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Plan 9 from User Space src/lib9/errstr.c 3 | http://code.swtch.com/plan9port/src/tip/src/lib9/errstr.c 4 | 5 | Copyright 2001-2007 Russ Cox. All Rights Reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | /* 27 | * We assume there's only one error buffer for the whole system. 28 | * If you use ffork, you need to provide a _syserrstr. Since most 29 | * people will use libthread (which provides a _syserrstr), this is 30 | * okay. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | enum 38 | { 39 | EPLAN9 = 0x19283745 40 | }; 41 | 42 | char *(*_syserrstr)(void); 43 | static char xsyserr[ERRMAX]; 44 | static char* 45 | getsyserr(void) 46 | { 47 | char *s; 48 | 49 | s = nil; 50 | if(_syserrstr) 51 | s = (*_syserrstr)(); 52 | if(s == nil) 53 | s = xsyserr; 54 | return s; 55 | } 56 | 57 | int 58 | errstr(char *err, uint n) 59 | { 60 | char tmp[ERRMAX]; 61 | char *syserr; 62 | 63 | strecpy(tmp, tmp+ERRMAX, err); 64 | rerrstr(err, n); 65 | syserr = getsyserr(); 66 | strecpy(syserr, syserr+ERRMAX, tmp); 67 | errno = EPLAN9; 68 | return 0; 69 | } 70 | 71 | void 72 | rerrstr(char *err, uint n) 73 | { 74 | char *syserr; 75 | 76 | syserr = getsyserr(); 77 | if(errno == EINTR) 78 | strcpy(syserr, "interrupted"); 79 | else if(errno != EPLAN9) 80 | strcpy(syserr, strerror(errno)); 81 | strecpy(err, err+n, syserr); 82 | } 83 | 84 | /* replaces __errfmt in libfmt */ 85 | 86 | int 87 | __errfmt(Fmt *f) 88 | { 89 | if(errno == EPLAN9) 90 | return fmtstrcpy(f, getsyserr()); 91 | return fmtstrcpy(f, strerror(errno)); 92 | } 93 | 94 | void 95 | werrstr(char *fmt, ...) 96 | { 97 | va_list arg; 98 | char buf[ERRMAX]; 99 | 100 | va_start(arg, fmt); 101 | vseprint(buf, buf+ERRMAX, fmt, arg); 102 | va_end(arg); 103 | errstr(buf, ERRMAX); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /cc11xx/Makefile: -------------------------------------------------------------------------------- 1 | ROOT := ../ 2 | 3 | OBJ = pkg 4 | 5 | CODE_LOC := 6 | CC = sdcc 7 | CFLAGS = --std-c99 --stack-auto 8 | LDFLAGS_FLASH = --xram-loc 0xf000 9 | 10 | CFLAGS += -I$(ROOT)/tiny9/8051/include 11 | CFLAGS += -I$(ROOT)/tiny9/include 12 | CFLAGS += -I../lib 13 | CFLAGS += -I../include 14 | CFLAGS += -I. 15 | 16 | SRC=\ 17 | main.c\ 18 | rf.c\ 19 | timer.c\ 20 | call.c\ 21 | callrx.c\ 22 | calltx.c\ 23 | calltxrx.c\ 24 | callping.c\ 25 | cobs.c\ 26 | u.c\ 27 | libradio/conv.c 28 | 29 | REL=$(SRC:.c=.rel) 30 | 31 | vpath %.c . 32 | vpath %.c .. 33 | 34 | all: $(OBJ)/cc1110dk.hex\ 35 | $(OBJ)/cc1111.hex\ 36 | $(OBJ)/cc1111+ccloader.hex\ 37 | $(OBJ)/erf.hex 38 | 39 | # These are currently broken: 40 | # $(OBJ)/cc1110dk+debug.hex\ 41 | # $(OBJ)/cc1111+debug.hex\ 42 | 43 | $(OBJ): 44 | mkdir -p $@ 45 | 46 | cc1110dkrel =\ 47 | $(REL)\ 48 | uartsrv.rel\ 49 | cc1110dk/board.rel 50 | 51 | $(OBJ)/cc1110dk/%.rel : %.c 52 | @mkdir -p $(@D) 53 | $(CC) -c $(CFLAGS) -DCC1110 -Icc1110dk -o$@ $< 54 | 55 | $(OBJ)/cc1110dk.hex: $(addprefix $(OBJ)/cc1110dk/,$(cc1110dkrel) noprint.rel) 56 | $(CC) $(LDFLAGS_FLASH) --code-loc 0x0000 $(CFLAGS) -o $@ $^ 57 | 58 | $(OBJ)/cc1110dk+debug/%.rel : %.c 59 | @mkdir -p $(@D) 60 | $(CC) -c $(CFLAGS) -DCC1110 -DDEBUG -Icc1110dk -o$@ $< 61 | 62 | $(OBJ)/cc1110dk+debug.hex: $(addprefix $(OBJ)/cc1110dk+debug/,$(cc1110dkrel) print.rel) 63 | $(CC) $(LDFLAGS_FLASH) --code-loc 0x0000 $(CFLAGS) -o $@ $^ 64 | 65 | cc1111rel =\ 66 | $(REL)\ 67 | usbsrv.rel\ 68 | cc1111/board.rel\ 69 | cc1111/usb.rel\ 70 | cc1111/hal.rel\ 71 | cc1111/usb_descriptors.rel\ 72 | lib/intel_hex.rel 73 | 74 | $(OBJ)/cc1111/%.rel : %.c 75 | mkdir -p $(@D) 76 | $(CC) -c $(CFLAGS) -DCC1111 -Icc1111 -o$@ $< 77 | 78 | $(OBJ)/cc1111.hex: $(addprefix $(OBJ)/cc1111/,$(cc1111rel) noprint.rel) 79 | $(CC) $(LDFLAGS_FLASH) --code-loc 0x0000 $(CFLAGS) -o $@ $^ 80 | 81 | $(OBJ)/cc1111+debug/%.rel : %.c 82 | mkdir -p $(@D) 83 | $(CC) -c $(CFLAGS) -DDEBUG -DCC1111 -Icc1111 -o$@ $< 84 | 85 | $(OBJ)/cc1111+debug.hex: $(addprefix $(OBJ)/cc1111+debug/,$(cc1111rel) print.rel) 86 | $(CC) $(LDFLAGS_FLASH) --code-loc 0x0000 $(CFLAGS) -o $@ $^ 87 | 88 | $(OBJ)/cc1111+debug+ccloader.hex: $(addprefix $(OBJ)/cc1111+debug/,$(cc1111rel) print.rel) 89 | $(CC) $(LDFLAGS_FLASH) --code-loc 0x1400 $(CFLAGS) -o $@ $^ 90 | 91 | $(OBJ)/cc1111+ccloader.hex: $(addprefix $(OBJ)/cc1111/,$(cc1111rel) noprint.rel) 92 | $(CC) $(LDFLAGS_FLASH) --code-loc 0x1400 $(CFLAGS) -o $@ $^ 93 | 94 | erfrel =\ 95 | $(REL)\ 96 | uartsrv.rel 97 | 98 | $(OBJ)/erf/%.rel : %.c 99 | @mkdir -p $(@D) 100 | $(CC) -c $(CFLAGS) -DERF -Ierf -o$@ $< 101 | 102 | $(OBJ)/erf.hex: $(addprefix $(OBJ)/erf/,$(erfrel) noprint.rel) 103 | $(CC) $(LDFLAGS_FLASH) $(CFLAGS) -o $@ $^ 104 | 105 | %.ihx: %.hex 106 | packihx $< > $@ 107 | 108 | %.flash: $(OBJ)/%.hex 109 | cc-tool -v -e -w $< 110 | 111 | %.ys1load: $(OBJ)/%.ihx 112 | ./rfcat_bootloader /dev/RFCAT_BL_YS1 download $< 113 | ./rfcat_bootloader /dev/RFCAT_BL_YS1 verify $< 114 | ./rfcat_bootloader /dev/RFCAT_BL_YS1 run 115 | 116 | clean: 117 | rm -rf $(OBJ) 118 | 119 | 120 | .PHONY: all $(OBJ) 121 | -------------------------------------------------------------------------------- /cc11xx/spisrv.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | #include "cobs.h" 3 | 4 | /* 5 | 6 | Configures SPI with: 7 | * ~1.002930 Mbps for 26 MHz clock (doesn't matter, since we're always a slave) 8 | * clock phase to be centered on first edge of SCK period 9 | * negative clock polarity (SCK low when idle) 10 | * bit order for transfers to MSB first 11 | 12 | Pins: 13 | MISO P0.2 14 | MOSI P0.3 15 | SSN P0.4 16 | SCK P0.5 17 | 18 | This works with the default BusPirate settings. 19 | 20 | We use COBS to ensure proper framing and synchronization of messages. 21 | https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing 22 | 23 | */ 24 | 25 | enum 26 | { 27 | Sidle = 0, 28 | Sheader, 29 | Sbuffer 30 | }; 31 | 32 | static volatile uint8 rxstate, txstate; 33 | static volatile uint8 ntx, nrx; 34 | static volatile uint8 rxh, txh; 35 | static volatile uint8 txsz; 36 | 37 | void 38 | srvinit() 39 | { 40 | uint8 pins = BIT(2) | BIT(3) | BIT(4) | BIT(5); 41 | 42 | // USART0, Alt. 1 43 | PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U1CFG; 44 | 45 | // Give priority to USART0 over USART 1 for port 0 pins 46 | P2DIR = (P2DIR & ~P2DIR_PRIP0) | P2DIR_PRIP0_0; 47 | 48 | // SPI slave 49 | U0CSR = (U0CSR & ~U0CSR_MODE) | U0CSR_SLAVE; 50 | 51 | // Select peripheral. 52 | P0SEL |= pins; 53 | 54 | // ~1.002930 Mbps for 26 MHz clock. 55 | // (Doesn't matter since we're the SPI slave.) 56 | U0BAUD = 60; 57 | U0GCR &= ~(U0GCR_BAUD_E | U0GCR_CPOL | U0GCR_CPHA | U0GCR_ORDER); 58 | U0GCR |= 15; 59 | // U0GCR |= U0GCR_ORDER; // MSB first 60 | 61 | URX0IF = 0; 62 | URX0IE = 1; 63 | 64 | UTX0IF = 0; 65 | IEN2 |= IEN2_UTX0IE; 66 | } 67 | 68 | void 69 | srvrx() 70 | { 71 | flag &= ~Frxcall; 72 | rxstate = Sheader; 73 | nrx = 0; 74 | } 75 | 76 | void 77 | srvtx() 78 | { 79 | flag &= ~Ftxcall; 80 | if(txstate != Idle) 81 | panic("spisrv: bad txstate"); 82 | txsz = txcall[0]; 83 | txh = stuff(txcall, txsz); 84 | txstate = Sheader; 85 | } 86 | 87 | void 88 | srvrxlower() 89 | { 90 | unstuff(rxh, rxcall, nrx); 91 | } 92 | 93 | void 94 | srvprintstate() 95 | { 96 | dprint("rxstate=%d txstate=%d ntx=%d nrx=%d\n", rxstate, txstate, ntx, nrx); 97 | } 98 | 99 | void 100 | urx0intr(void) __interrupt URX0_VECTOR 101 | { 102 | uint8 d = U0DBUF; 103 | 104 | switch(rxstate){ 105 | case Sidle: break; 106 | 107 | case Sheader: 108 | if(d != 0){ 109 | rxh = d; 110 | rxstate = Sbuffer; 111 | } 112 | break; 113 | 114 | case Sbuffer: 115 | if(d == 0){ 116 | flag |= Frxcall; 117 | rxstate = Sidle; 118 | }else{ 119 | rxcall[nrx++] = d; 120 | if(nrx == sizeof rxcall) 121 | panic("spi: rxcall overrun"); 122 | } 123 | break; 124 | } 125 | } 126 | 127 | void 128 | utx0intr(void) __interrupt UTX0_VECTOR 129 | { 130 | UTX0IF = 0; 131 | 132 | switch(txstate){ 133 | case Sidle: 134 | U0DBUF = 0; 135 | break; 136 | 137 | case Sheader: 138 | U0DBUF = txh; 139 | txstate = Sbuffer; 140 | break; 141 | 142 | case Sbuffer: 143 | if(txcall[ntx] == 0) 144 | panic("attempting to transmit unstuffed data\n"); 145 | U0DBUF = txcall[ntx++]; 146 | if(ntx == txsz){ 147 | flag |= Ftxcall; 148 | ntx = 0; 149 | txstate = Sidle; 150 | } 151 | break; 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /cc11xx/usbsrv.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | */ 8 | 9 | enum 10 | { 11 | Uidle, 12 | Uready, 13 | Urxing 14 | }; 15 | 16 | static volatile uint8 nrx, ntx; 17 | static volatile uint8 rxstate; 18 | 19 | void 20 | dprintsrvstate() 21 | { 22 | dprint("nrx=%d ntx=%d rxstate=%d\n", nrx, ntx, rxstate); 23 | } 24 | 25 | void 26 | srvinit() 27 | { 28 | usb_init(); 29 | usb_enable(); 30 | usb_up(); 31 | usb_flush(); 32 | 33 | rxstate = Uidle; 34 | } 35 | 36 | void 37 | srvrx() 38 | { 39 | flag &= ~Frxcall; 40 | nrx = 0; 41 | rxstate = Uready; 42 | } 43 | 44 | void 45 | srvrxpeek() 46 | { 47 | uint8_t length; 48 | uint8_t in_byte; 49 | char nibbles[2]; 50 | int bytes_to_read; 51 | 52 | if (rxstate != Urxing){ 53 | return; 54 | } 55 | GREEN=1; 56 | 57 | dprint("start of reading ---- "); 58 | 59 | nibbles[0] = usb_getchar(); 60 | 61 | if(nibbles[0] == 1){ 62 | dprint("info request\n"); 63 | usb_putchar(1); 64 | dprint("flush\n"); 65 | usb_flush(); 66 | rxstate = Uready; 67 | GREEN = 0; 68 | return; 69 | } 70 | 71 | dprint("%c ", nibbles[0]); 72 | nibbles[1] = usb_getchar(); 73 | dprint("%c ", nibbles[1]); 74 | in_byte = hex8(&nibbles[0]); 75 | dprint("(%x) ", in_byte); 76 | 77 | if (nrx == 0) { 78 | if (in_byte == 0) { 79 | dprint("getting 0 size. error\n"); 80 | while (1) {;} 81 | rxstate = Uready; 82 | flag &= ~Frxcall; 83 | GREEN=0; 84 | return; 85 | } 86 | 87 | if (in_byte == 0xff) { 88 | dprint("radio reset\n"); 89 | rxstate = Uready; 90 | flag &= ~Frxcall; 91 | WDCTL = BIT(3) | BIT(0); 92 | for(;;) sleep(1); 93 | } 94 | 95 | // if the index is still at 0, here is the length 96 | rxcall[nrx++] = in_byte; 97 | } 98 | 99 | length = rxcall[0]; 100 | while (nrx < length) { 101 | nibbles[0] = usb_getchar(); 102 | dprint("%c ", nibbles[0]); 103 | nibbles[1] = usb_getchar(); 104 | dprint("%c ", nibbles[1]); 105 | in_byte = hex8(&nibbles[0]); 106 | dprint("(%x) ", in_byte); 107 | 108 | rxcall[nrx++] = in_byte; 109 | if(nrx == sizeof rxcall) 110 | panic("usb: rxcall overrun"); 111 | } 112 | 113 | if (nrx == length) { 114 | rxstate = Uidle; 115 | flag |= Frxcall; 116 | dprint(" ---- read %d\n", length); 117 | } else { 118 | RED=1; 119 | // if we didn't read everything, let's let 120 | // WD take over here 121 | dprint(" ---- only read %d out of %d\n", nrx, length); 122 | while (1) {;} 123 | } 124 | 125 | GREEN=0; 126 | } 127 | 128 | void 129 | srvpending() 130 | { 131 | dprint("srvpending\n"); 132 | 133 | if(rxstate == Uidle) 134 | return; /* TODO: panic? */ 135 | 136 | if(rxstate == Uready){ 137 | rxstate = Urxing; 138 | } 139 | } 140 | 141 | void 142 | srvrxlower() 143 | { 144 | } 145 | 146 | void 147 | srvtx() 148 | { 149 | int i; 150 | uint8 length; 151 | char txcall_in_ascii[SPIMAX * 2]; 152 | int ascii_idx; 153 | 154 | flag &= ~Ftxcall; 155 | length = txcall[0]; 156 | 157 | for (ntx = 0; ntx < length; ntx++) { 158 | to_hex8_ascii(&txcall_in_ascii[ntx * 2], txcall[ntx]); 159 | } 160 | 161 | for (ascii_idx = 0; ascii_idx < length * 2; ascii_idx++) { 162 | usb_putchar(txcall_in_ascii[ascii_idx]); 163 | } 164 | usb_flush( ); 165 | flag |= Ftxcall; 166 | } 167 | -------------------------------------------------------------------------------- /tiny9/libbio/brdline.c: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/libbio/brdline.c 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | void* 31 | Brdline(Biobuf *bp, int delim) 32 | { 33 | char *ip, *ep; 34 | int i, j; 35 | 36 | i = -bp->icount; 37 | if(i == 0) { 38 | /* 39 | * eof or other error 40 | */ 41 | if(bp->state != Bractive) { 42 | if(bp->state == Bracteof) 43 | bp->state = Bractive; 44 | bp->rdline = 0; 45 | bp->gbuf = bp->ebuf; 46 | return 0; 47 | } 48 | } 49 | 50 | /* 51 | * first try in remainder of buffer (gbuf doesn't change) 52 | */ 53 | ip = (char*)bp->ebuf - i; 54 | ep = memchr(ip, delim, i); 55 | if(ep) { 56 | j = (ep - ip) + 1; 57 | bp->rdline = j; 58 | bp->icount += j; 59 | return ip; 60 | } 61 | 62 | /* 63 | * copy data to beginning of buffer 64 | */ 65 | if(i < bp->bsize) 66 | memmove(bp->bbuf, ip, i); 67 | bp->gbuf = bp->bbuf; 68 | 69 | /* 70 | * append to buffer looking for the delim 71 | */ 72 | ip = (char*)bp->bbuf + i; 73 | while(i < bp->bsize) { 74 | j = read(bp->fid, ip, bp->bsize-i); 75 | if(j <= 0) { 76 | /* 77 | * end of file with no delim 78 | */ 79 | memmove(bp->ebuf-i, bp->bbuf, i); 80 | bp->rdline = i; 81 | bp->icount = -i; 82 | bp->gbuf = bp->ebuf-i; 83 | return 0; 84 | } 85 | bp->offset += j; 86 | i += j; 87 | ep = memchr(ip, delim, j); 88 | if(ep) { 89 | /* 90 | * found in new piece 91 | * copy back up and reset everything 92 | */ 93 | ip = (char*)bp->ebuf - i; 94 | if(i < bp->bsize){ 95 | memmove(ip, bp->bbuf, i); 96 | bp->gbuf = (unsigned char*)ip; 97 | } 98 | j = (ep - (char*)bp->bbuf) + 1; 99 | bp->rdline = j; 100 | bp->icount = j - i; 101 | return ip; 102 | } 103 | ip += j; 104 | } 105 | 106 | /* 107 | * full buffer without finding 108 | */ 109 | bp->rdline = bp->bsize; 110 | bp->icount = -bp->bsize; 111 | bp->gbuf = bp->bbuf; 112 | return 0; 113 | } 114 | 115 | int 116 | Blinelen(Biobuf *bp) 117 | { 118 | 119 | return bp->rdline; 120 | } 121 | -------------------------------------------------------------------------------- /tiny9/libtask/mips-ucontext.h: -------------------------------------------------------------------------------- 1 | typedef struct mcontext mcontext_t; 2 | typedef struct ucontext ucontext_t; 3 | 4 | extern int swapcontext(ucontext_t*, const ucontext_t*); 5 | extern void makecontext(ucontext_t*, void(*)(), int, ...); 6 | 7 | /* 8 | * Copyright (c) 1992, 1993 9 | * The Regents of the University of California. All rights reserved. 10 | * 11 | * This code is derived from software contributed to Berkeley by 12 | * Ralph Campbell. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 4. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#)ucontext.h 8.1 (Berkeley) 6/10/93 39 | * JNPR: ucontext.h,v 1.2 2007/08/09 11:23:32 katta 40 | * $FreeBSD: src/sys/mips/include/ucontext.h,v 1.2 2010/01/10 19:50:24 imp Exp $ 41 | */ 42 | 43 | struct mcontext { 44 | /* 45 | * These fields must match the corresponding fields in struct 46 | * sigcontext which follow 'sc_mask'. That way we can support 47 | * struct sigcontext and ucontext_t at the same time. 48 | */ 49 | int mc_onstack; /* sigstack state to restore */ 50 | int mc_pc; /* pc at time of signal */ 51 | int mc_regs[32]; /* processor regs 0 to 31 */ 52 | int sr; /* status register */ 53 | int mullo, mulhi; /* mullo and mulhi registers... */ 54 | int mc_fpused; /* fp has been used */ 55 | int mc_fpregs[33]; /* fp regs 0 to 31 and csr */ 56 | int mc_fpc_eir; /* fp exception instruction reg */ 57 | void *mc_tls; /* pointer to TLS area */ 58 | int __spare__[8]; /* XXX reserved */ 59 | }; 60 | 61 | struct ucontext { 62 | /* 63 | * Keep the order of the first two fields. Also, 64 | * keep them the first two fields in the structure. 65 | * This way we can have a union with struct 66 | * sigcontext and ucontext_t. This allows us to 67 | * support them both at the same time. 68 | * note: the union is not defined, though. 69 | */ 70 | sigset_t uc_sigmask; 71 | mcontext_t uc_mcontext; 72 | 73 | struct __ucontext *uc_link; 74 | stack_t uc_stack; 75 | int uc_flags; 76 | int __spare__[4]; 77 | }; 78 | -------------------------------------------------------------------------------- /libpump/pump.c: -------------------------------------------------------------------------------- 1 | #include "pumpimpl.h" 2 | 3 | int 4 | pstat(Pstat *ps) 5 | { 6 | static Pcall tx, rx; 7 | 8 | memset(ps, 0, sizeof *ps); 9 | 10 | if(_presume() < 0) 11 | return -1; 12 | 13 | tx.type = Tstatus; 14 | if(_pcall(&tx, &rx) != 1) 15 | return -1; 16 | 17 | ps->month = rx.status.month; 18 | ps->day = rx.status.day; 19 | ps->hour = rx.status.hour; 20 | ps->minute = rx.status.minute; 21 | ps->year = rx.status.year; 22 | ps->basal = rx.status.basal; 23 | ps->insulinleft = rx.status.insulin; 24 | ps->temp = rx.status.temp; 25 | ps->temptime = rx.status.temptime; 26 | ps->temptotal = rx.status.temptotal; 27 | 28 | if(rx.flag&Fwarn) 29 | ps->haswarning = 1; 30 | 31 | tx.type = Tstatus4; 32 | if(_pcall(&tx, &rx) != 1) 33 | return -1; 34 | 35 | ps->comboactive = rx.status4.active; 36 | ps->comboyear = rx.status4.year; 37 | ps->combomonth = rx.status4.month; 38 | ps->comboday = rx.status4.day; 39 | ps->combostarthour = rx.status4.starthour; 40 | ps->combostartminute = rx.status4.startminute; 41 | ps->comboendhour = rx.status4.endhour; 42 | ps->comboendminute = rx.status4.endminute; 43 | ps->combodelivered = rx.status4.delivered; 44 | ps->combototal = rx.status4.total; 45 | 46 | if(_preset() < 0) 47 | return -1; 48 | 49 | tx.type = Tstatus2; 50 | if(_pcall(&tx, &rx) != 1) 51 | return -1; 52 | 53 | /* XXX last bolus time */ 54 | 55 | ps->lastbolus = rx.status2.bolus; 56 | ps->iob = rx.status2.iob; 57 | 58 | if(_preset() < 0) 59 | return -1; 60 | 61 | tx.type = Tstatus; 62 | if(_pcall(&tx, &rx) != 1) 63 | return -1; 64 | 65 | tx.type = Tstatus3; 66 | if(_pcall(&tx, &rx) != 1) 67 | return -1; 68 | 69 | ps->dailybolus = rx.status3.bolus; 70 | ps->dailybasal = rx.status3.basal; 71 | 72 | _padjourn(); 73 | 74 | return 0; 75 | } 76 | 77 | int 78 | pbolus(uint insulin, uint minutes) 79 | { 80 | static Pcall tx, rx; 81 | 82 | if(minutes%6 != 0){ 83 | werrstr("combo duration must be in increments of 6 minutes!"); 84 | return -1; 85 | } 86 | 87 | if(_presume() < 0) 88 | return -1; 89 | 90 | tx.type = Tbolus; 91 | tx.bolus.insulin = insulin; 92 | tx.bolus.minutes = minutes; 93 | if(_pcall(&tx, &rx) != 1) 94 | return -1; 95 | 96 | if(rx.bolus.insulin != insulin || rx.bolus.minutes != minutes){ 97 | werrstr("pump returned mismatch bolus parameters (i=%d, m=%d) vs expected (i=%d, m=%d)", 98 | rx.bolus.insulin, rx.bolus.minutes, insulin, minutes); 99 | return -1; 100 | } 101 | 102 | tx.type = minutes > 0 ? Tcomboack : Tbolusack; 103 | if(_pcall(&tx, &rx) != 1) 104 | return -1; 105 | 106 | for(;;){ 107 | tx.type = Tdeliverystatus; 108 | if(_pcall(&tx, &rx) != 1) 109 | return -1; 110 | 111 | switch(rx.deliverystatus){ 112 | case DeliveryBusy: 113 | case DeliveryUnknown: 114 | 115 | tx.type = Tdeliverycontinue; 116 | if(_pcall(&tx, &rx) != 1) 117 | return -1; 118 | continue; 119 | 120 | case DeliveryDone: 121 | break; 122 | } 123 | break; 124 | } 125 | 126 | _padjourn(); 127 | 128 | return 0; 129 | } 130 | 131 | int 132 | pcancel() 133 | { 134 | static Pcall tx, rx; 135 | 136 | if(_presume() < 0) 137 | return -1; 138 | 139 | tx.type = Tcancelcombo; 140 | if(_pcall(&tx, &rx) != 1) 141 | return -1; 142 | 143 | _padjourn(); 144 | return 0; 145 | } 146 | 147 | int 148 | pclearwarning() 149 | { 150 | if(_presume() < 0) 151 | return -1; 152 | 153 | if(_pcallsimple(Tclearwarn) < 0) 154 | return -1; 155 | 156 | _padjourn(); 157 | 158 | return 0; 159 | } 160 | -------------------------------------------------------------------------------- /tiny9/libtask/context.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */ 2 | 3 | #include "taskimpl.h" 4 | 5 | #if defined(__APPLE__) 6 | #if defined(__i386__) 7 | #define NEEDX86MAKECONTEXT 8 | #define NEEDSWAPCONTEXT 9 | #elif defined(__x86_64__) 10 | #define NEEDAMD64MAKECONTEXT 11 | #define NEEDSWAPCONTEXT 12 | #else 13 | #define NEEDPOWERMAKECONTEXT 14 | #define NEEDSWAPCONTEXT 15 | #endif 16 | #endif 17 | 18 | #if defined(__FreeBSD__) && defined(__i386__) && __FreeBSD__ < 5 19 | #define NEEDX86MAKECONTEXT 20 | #define NEEDSWAPCONTEXT 21 | #endif 22 | 23 | #if defined(__OpenBSD__) && defined(__i386__) 24 | #define NEEDX86MAKECONTEXT 25 | #define NEEDSWAPCONTEXT 26 | #endif 27 | 28 | #if defined(__arm__) && !defined(__linux__) 29 | #define NEEDSWAPCONTEXT 30 | #define NEEDARMMAKECONTEXT 31 | #endif 32 | 33 | #if defined(__linux__) && defined(__mips__) 34 | #define NEEDSWAPCONTEXT 35 | #define NEEDMIPSMAKECONTEXT 36 | #endif 37 | 38 | #ifdef NEEDPOWERMAKECONTEXT 39 | void 40 | makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) 41 | { 42 | ulong *sp, *tos; 43 | va_list arg; 44 | 45 | tos = (ulong*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(ulong); 46 | sp = tos - 16; 47 | ucp->mc.pc = (long)func; 48 | ucp->mc.sp = (long)sp; 49 | va_start(arg, argc); 50 | ucp->mc.r3 = va_arg(arg, long); 51 | va_end(arg); 52 | } 53 | #endif 54 | 55 | #ifdef NEEDX86MAKECONTEXT 56 | void 57 | makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) 58 | { 59 | int *sp; 60 | 61 | sp = (int*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/4; 62 | sp -= argc; 63 | sp = (void*)((uintptr_t)sp - (uintptr_t)sp%16); /* 16-align for OS X */ 64 | memmove(sp, &argc+1, argc*sizeof(int)); 65 | 66 | *--sp = 0; /* return address */ 67 | ucp->uc_mcontext.mc_eip = (long)func; 68 | ucp->uc_mcontext.mc_esp = (int)sp; 69 | } 70 | #endif 71 | 72 | #ifdef NEEDAMD64MAKECONTEXT 73 | void 74 | makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) 75 | { 76 | long *sp; 77 | va_list va; 78 | 79 | memset(&ucp->uc_mcontext, 0, sizeof ucp->uc_mcontext); 80 | if(argc != 2) 81 | *(int*)0 = 0; 82 | va_start(va, argc); 83 | ucp->uc_mcontext.mc_rdi = va_arg(va, int); 84 | ucp->uc_mcontext.mc_rsi = va_arg(va, int); 85 | va_end(va); 86 | sp = (long*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(long); 87 | sp -= argc; 88 | sp = (void*)((uintptr_t)sp - (uintptr_t)sp%16); /* 16-align for OS X */ 89 | *--sp = 0; /* return address */ 90 | ucp->uc_mcontext.mc_rip = (long)func; 91 | ucp->uc_mcontext.mc_rsp = (long)sp; 92 | } 93 | #endif 94 | 95 | #ifdef NEEDARMMAKECONTEXT 96 | void 97 | makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...) 98 | { 99 | int i, *sp; 100 | va_list arg; 101 | 102 | sp = (int*)uc->uc_stack.ss_sp+uc->uc_stack.ss_size/4; 103 | va_start(arg, argc); 104 | for(i=0; i<4 && iuc_mcontext.gregs[i] = va_arg(arg, uint); 106 | va_end(arg); 107 | uc->uc_mcontext.gregs[13] = (uint)sp; 108 | uc->uc_mcontext.gregs[14] = (uint)fn; 109 | } 110 | #endif 111 | 112 | #ifdef NEEDMIPSMAKECONTEXT 113 | void 114 | makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...) 115 | { 116 | int i, *sp; 117 | va_list arg; 118 | 119 | va_start(arg, argc); 120 | sp = (int*)uc->uc_stack.ss_sp+uc->uc_stack.ss_size/4; 121 | for(i=0; i<4 && iuc_mcontext.mc_regs[i+4] = va_arg(arg, int); 123 | va_end(arg); 124 | uc->uc_mcontext.mc_regs[29] = (int)sp; 125 | uc->uc_mcontext.mc_regs[31] = (int)fn; 126 | } 127 | #endif 128 | 129 | #ifdef NEEDSWAPCONTEXT 130 | 131 | int 132 | swapcontext(ucontext_t *oucp, const ucontext_t *ucp) 133 | { 134 | if(getcontext(oucp) == 0) 135 | setcontext(ucp); 136 | 137 | return 0; 138 | } 139 | #endif 140 | 141 | -------------------------------------------------------------------------------- /include/pcall.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 2c - may be some sort of configuration */ 4 | 5 | 6 | typedef struct 7 | { 8 | uint8 month; 9 | uint8 day; 10 | uint8 hour; // 24h 11 | uint8 minute; 12 | uint16 year; 13 | 14 | uint16 basal; // milliunits/hr 15 | 16 | uint8 insulin; 17 | 18 | int8 temp; // temp basal 19 | uint16 temptime; // temp time remaining (m) 20 | uint16 temptotal; // temp time total (m) 21 | 22 | // Internal 23 | int type; 24 | } Mstatus; 25 | 26 | typedef struct 27 | { 28 | uint8 prognum; 29 | char progname[11]; 30 | 31 | uint8 insulin; 32 | 33 | uint16 daily; // milliunits/day 34 | uint16 hourly; // milliunits/hr 35 | } Mstatus1; 36 | 37 | typedef struct 38 | { 39 | /* XXX these are last bolus time... */ 40 | uint8 hour; 41 | uint8 minute; 42 | uint8 month; 43 | uint8 day; 44 | uint16 year; 45 | uint16 bolus; // milliunits 46 | uint16 iob; // milliunits 47 | 48 | } Mstatus2; 49 | 50 | typedef struct 51 | { 52 | /* "Delivery today" */ 53 | uint bolus; 54 | uint basal; 55 | 56 | /* Turn these into flags? */ 57 | uint temp; 58 | uint suspend; 59 | } Mstatus3; 60 | 61 | typedef struct 62 | { 63 | uint active; 64 | 65 | uint year; 66 | uint month; 67 | uint day; 68 | 69 | uint starthour; 70 | uint startminute; 71 | uint endhour; 72 | uint endminute; 73 | 74 | uint delivered; 75 | uint total; 76 | 77 | } Mstatus4; 78 | 79 | 80 | /* This only permits 0:100 combos for now; 81 | * time must be in increments of 5 minutes. */ 82 | typedef struct 83 | { 84 | uint insulin; 85 | uint minutes; 86 | } Mbolus; 87 | 88 | enum 89 | { 90 | Eok = 0, 91 | Einternal, 92 | Ebadreq, 93 | 94 | Enocombo, /* Not really an error as such.. */ 95 | Eunknown 96 | }; 97 | 98 | enum 99 | { 100 | Twakeup = 0x00, 101 | Rwakeup = Twakeup+0xff, 102 | 103 | Tkeepalive = 0x03, 104 | Rkeepalive = Tkeepalive+0xff, 105 | 106 | Tadjourn = 0x05, 107 | Radjourn = Tadjourn+0xff, 108 | 109 | T2c = 0x2c, 110 | R2c = T2c+0xff, 111 | 112 | Tstatus = 0x50, 113 | Rstatus = Tstatus+0xff, 114 | 115 | Tstatus1 = 0x20, 116 | Rstatus1 = Tstatus1+0xff, 117 | 118 | Tstatus2 = 0x25, 119 | Rstatus2 = Tstatus2+0xff, 120 | 121 | Tstatus3 = 0x27, 122 | Rstatus3 = Tstatus3+0xff, 123 | 124 | Tstatus4 = 0x26, 125 | Rstatus4 = Tstatus4+0xff, 126 | 127 | Tcancelcombo = 0x35, 128 | Rcancelcombo = Tcancelcombo+0xff, 129 | 130 | /* These are .. not acks exactly. More like "user still present" */ 131 | 132 | Tbolusack = 0x30, 133 | Rbolusack = Tbolusack+0xff, 134 | 135 | Tcomboack = 0x31, 136 | Rcomboack = Tcomboack+0xff, 137 | 138 | Tdeliverycontinue = 0x32, 139 | Rdeliverycontinue = Tdeliverycontinue+0xff, 140 | 141 | Tdeliverystatus = 0x33, 142 | Rdeliverystatus = Tdeliverystatus+0xff, 143 | 144 | 145 | /* This is some sort of delivery summary 146 | Tack3 = 0x36, 147 | Rack3 = Tack3+0xff, 148 | */ 149 | 150 | Tbolus = 0x37, 151 | Rbolus = Tbolus+0xff, 152 | 153 | Tclearwarn = 0x45, 154 | Rclearwarn = 0x45+0xff, 155 | 156 | Rerror = -1 157 | }; 158 | 159 | enum 160 | { 161 | DeliveryBusy, 162 | DeliveryDone, 163 | DeliveryUnknown, 164 | }; 165 | 166 | enum 167 | { 168 | Fwarn = 1 169 | }; 170 | 171 | typedef struct 172 | { 173 | int type; 174 | uint8 tag; 175 | uint8 size; 176 | 177 | uint8 flag; 178 | 179 | union 180 | { 181 | int err; 182 | Mstatus status; 183 | Mstatus1 status1; 184 | Mstatus2 status2; 185 | Mstatus3 status3; 186 | Mstatus4 status4; 187 | Mbolus bolus; 188 | uint16 backoffms; /* Rkeepalive */ 189 | uint deliverystatus; /* Rdeliverystatus */ 190 | }; 191 | } Pcall; 192 | 193 | int pcall(Pcall*, Pcall*); 194 | 195 | int convP2C(uint8 *p, Pcall *c); 196 | int convC2P(Pcall *c, uint8 *p); 197 | int Pcallfmt(Fmt *f); 198 | 199 | 200 | int pumpaddchk(void *v, uint n, uint32 chk); 201 | -------------------------------------------------------------------------------- /tiny9/include/bio.h: -------------------------------------------------------------------------------- 1 | /* 2 | http://code.google.com/p/inferno-os/source/browse/include/bio.h 3 | 4 | Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 | Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _BIO_H_ 27 | #define _BIO_H_ 1 28 | #if defined(__cplusplus) 29 | extern "C" { 30 | #endif 31 | 32 | #ifdef AUTOLIB 33 | AUTOLIB(bio) 34 | #endif 35 | 36 | #include /* for O_RDONLY, O_WRONLY */ 37 | 38 | typedef struct Biobuf Biobuf; 39 | 40 | enum 41 | { 42 | Bsize = 8*1024, 43 | Bungetsize = 4, /* space for ungetc */ 44 | Bmagic = 0x314159, 45 | Beof = -1, 46 | Bbad = -2, 47 | 48 | Binactive = 0, /* states */ 49 | Bractive, 50 | Bwactive, 51 | Bracteof, 52 | 53 | Bend 54 | }; 55 | 56 | struct Biobuf 57 | { 58 | int icount; /* neg num of bytes at eob */ 59 | int ocount; /* num of bytes at bob */ 60 | int rdline; /* num of bytes after rdline */ 61 | int runesize; /* num of bytes of last getrune */ 62 | int state; /* r/w/inactive */ 63 | int fid; /* open file */ 64 | int flag; /* magic if malloc'ed */ 65 | vlong offset; /* offset of buffer in file */ 66 | int bsize; /* size of buffer */ 67 | unsigned char* bbuf; /* pointer to beginning of buffer */ 68 | unsigned char* ebuf; /* pointer to end of buffer */ 69 | unsigned char* gbuf; /* pointer to good data in buf */ 70 | unsigned char b[Bungetsize+Bsize]; 71 | }; 72 | 73 | #define BGETC(bp)\ 74 | ((bp)->icount?(bp)->bbuf[(bp)->bsize+(bp)->icount++]:Bgetc((bp))) 75 | #define BPUTC(bp,c)\ 76 | ((bp)->ocount?(bp)->bbuf[(bp)->bsize+(bp)->ocount++]=(c),0:Bputc((bp),(c))) 77 | #define BOFFSET(bp)\ 78 | (((bp)->state==Bractive)?\ 79 | (bp)->offset + (bp)->icount:\ 80 | (((bp)->state==Bwactive)?\ 81 | (bp)->offset + ((bp)->bsize + (bp)->ocount):\ 82 | -1)) 83 | #define BLINELEN(bp)\ 84 | (bp)->rdline 85 | #define BFILDES(bp)\ 86 | (bp)->fid 87 | 88 | int Bbuffered(Biobuf*); 89 | Biobuf* Bfdopen(int, int); 90 | int Bfildes(Biobuf*); 91 | int Bflush(Biobuf*); 92 | int Bgetc(Biobuf*); 93 | int Bgetd(Biobuf*, double*); 94 | long Bgetrune(Biobuf*); 95 | int Binit(Biobuf*, int, int); 96 | int Binits(Biobuf*, int, int, unsigned char*, int); 97 | int Blinelen(Biobuf*); 98 | vlong Boffset(Biobuf*); 99 | Biobuf* Bopen(char*, int); 100 | int Bprint(Biobuf*, char*, ...); 101 | int Bputc(Biobuf*, int); 102 | int Bputrune(Biobuf*, long); 103 | void* Brdline(Biobuf*, int); 104 | char* Brdstr(Biobuf*, int, int); 105 | long Bread(Biobuf*, void*, long); 106 | vlong Bseek(Biobuf*, vlong, int); 107 | int Bterm(Biobuf*); 108 | int Bungetc(Biobuf*); 109 | int Bungetrune(Biobuf*); 110 | long Bwrite(Biobuf*, void*, long); 111 | int Bvprint(Biobuf*, char*, va_list); 112 | 113 | #if defined(__cplusplus) 114 | } 115 | #endif 116 | #endif 117 | -------------------------------------------------------------------------------- /cc11xx/print.c: -------------------------------------------------------------------------------- 1 | #include "impl.h" 2 | 3 | /* 4 | UART for debug output using USART1. 5 | 6 | Pins: 7 | RX P1.7 8 | TX P1.6 9 | RT P1.5 10 | CT P1.4 11 | 12 | 57.6kbps, 8-bit no parity, 1 stop bit, receive polarity 1, open drain output. 13 | */ 14 | 15 | enum 16 | { 17 | N = 512 18 | }; 19 | 20 | static volatile __xdata uint8 buf[N]; 21 | static volatile __xdata int16 readpos = 0; 22 | static volatile __xdata int16 writepos = 0; 23 | static volatile __xdata int16 n = -1; 24 | 25 | /*static void marcstatefmt(Fmt*); 26 | static void flagfmt(Fmt*);*/ 27 | int _putchar(char c); 28 | void abort(); 29 | 30 | void 31 | printinit() 32 | { 33 | // UART, defaults. 34 | U1CSR = U1CSR_MODE; 35 | 36 | boardprintinit(); 37 | 38 | U1UCR |= U1UCR_FLUSH; 39 | // U1UCR |= U1UCR_FLOW; 40 | } 41 | 42 | int 43 | write(int fd, void *p, int np) 44 | { 45 | int i; 46 | uint8 *bp = p; 47 | USED(fd); 48 | 49 | IEN2 &= ~IEN2_UTX1IE; 50 | 51 | for(i=0; i 0){ 117 | U1DBUF = buf[readpos++]; 118 | if(readpos == N) 119 | readpos = 0; 120 | } 121 | 122 | if(n-- < 0) 123 | IEN2 &= ~IEN2_UTX1IE; 124 | } 125 | 126 | char* 127 | strmarcstate(uint8 state) 128 | { 129 | switch(state){ 130 | case MARC_STATE_SLEEP: return "MARC_STATE_SLEEP"; 131 | case MARC_STATE_IDLE: return "MARC_STATE_IDLE"; 132 | case MARC_STATE_VCOON_MC: return "MARC_STATE_VCOON_MC"; 133 | case MARC_STATE_REGON_MC: return "MARC_STATE_REGON_MC"; 134 | case MARC_STATE_MANCAL: return "MARC_STATE_MANCAL"; 135 | case MARC_STATE_VCOON: return "MARC_STATE_VCOON"; 136 | case MARC_STATE_REGON: return "MARC_STATE_REGON"; 137 | case MARC_STATE_STARTCAL: return "MARC_STATE_STARTCAL"; 138 | case MARC_STATE_BWBOOST: return "MARC_STATE_BWBOOST"; 139 | case MARC_STATE_FS_LOCK: return "MARC_STATE_FS_LOCK"; 140 | case MARC_STATE_IFADCON: return "MARC_STATE_IFADCON"; 141 | case MARC_STATE_ENDCAL: return "MARC_STATE_ENDCAL"; 142 | case MARC_STATE_RX: return "MARC_STATE_RX"; 143 | case MARC_STATE_RX_END: return "MARC_STATE_RX_END"; 144 | case MARC_STATE_RX_RST: return "MARC_STATE_RX_RST"; 145 | case MARC_STATE_TXRX_SWITCH: return "MARC_STATE_TXRX_SWITCH"; 146 | case MARC_STATE_RX_OVERFLOW: return "MARC_STATE_RX_OVERFLOW"; 147 | case MARC_STATE_FSTXON: return "MARC_STATE_FSTXON"; 148 | case MARC_STATE_TX: return "MARC_STATE_TX"; 149 | case MARC_STATE_TX_END: return "MARC_STATE_TX_END"; 150 | case MARC_STATE_RXTX_SWITCH: return "MARC_STATE_RXTX_SWITCH"; 151 | case MARC_STATE_TX_UNDERFLOW: return "MARC_STATE_TX_UNDERFLOW"; 152 | default: return "MARC_STATE_UNKNOWN"; 153 | } 154 | } 155 | 156 | /* 157 | static void 158 | marcstatefmt(Fmt *fmt) 159 | { 160 | fmt->dst = printstr(fmt->dst, fmt->edst, strmarcstate(va_arg(fmt->arg, int)), fmt->size); 161 | } 162 | */ 163 | 164 | static const char* const __code _strflag[] = { 165 | "Rxcall", "Txcall", "Rfrx", "Rftx", "Rfovf", "Alarm", "Panic" 166 | }; 167 | 168 | void 169 | printflag(uint8 flag) 170 | { 171 | int i; 172 | 173 | for(i=0; i < nelem(_strflag); i++){ 174 | if(flag&BIT(i)) 175 | printf("%s", _strflag[i]); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /tiny9/libfmt/fmtdef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * 4 | * Copyright (c) 2002-2006 by Lucent Technologies. 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose without fee is hereby granted, provided that this entire notice 8 | * is included in all copies of any software which is or includes a copy 9 | * or modification of this software and in all copies of the supporting 10 | * documentation for such software. 11 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 12 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 13 | * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 14 | * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 15 | */ 16 | 17 | /* 18 | * dofmt -- format to a buffer 19 | * the number of characters formatted is returned, 20 | * or -1 if there was an error. 21 | * if the buffer is ever filled, flush is called. 22 | * it should reset the buffer and return whether formatting should continue. 23 | */ 24 | 25 | typedef int (*Fmts)(Fmt*); 26 | 27 | typedef struct Quoteinfo Quoteinfo; 28 | struct Quoteinfo 29 | { 30 | int quoted; /* if set, string must be quoted */ 31 | int nrunesin; /* number of input runes that can be accepted */ 32 | int nbytesin; /* number of input bytes that can be accepted */ 33 | int nrunesout; /* number of runes that will be generated */ 34 | int nbytesout; /* number of bytes that will be generated */ 35 | }; 36 | 37 | /* Edit .+1,/^$/ |cfn |grep -v static | grep __ */ 38 | double __Inf(int sign); 39 | double __NaN(void); 40 | int __badfmt(Fmt *f); 41 | int __charfmt(Fmt *f); 42 | int __countfmt(Fmt *f); 43 | int __efgfmt(Fmt *fmt); 44 | int __errfmt(Fmt *f); 45 | int __flagfmt(Fmt *f); 46 | int __fmtFdFlush(Fmt *f); 47 | int __fmtcpy(Fmt *f, const void *vm, int n, int sz); 48 | void* __fmtdispatch(Fmt *f, void *fmt, int isrunes); 49 | void * __fmtflush(Fmt *f, void *t, int len); 50 | void __fmtlock(void); 51 | int __fmtpad(Fmt *f, int n); 52 | double __fmtpow10(int n); 53 | int __fmtrcpy(Fmt *f, const void *vm, int n); 54 | void __fmtunlock(void); 55 | int __ifmt(Fmt *f); 56 | int __isInf(double d, int sign); 57 | int __isNaN(double d); 58 | int __needsep(int*, char**); 59 | int __needsquotes(char *s, int *quotelenp); 60 | int __percentfmt(Fmt *f); 61 | void __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout); 62 | int __quotestrfmt(int runesin, Fmt *f); 63 | int __rfmtpad(Fmt *f, int n); 64 | int __runefmt(Fmt *f); 65 | int __runeneedsquotes(Rune *r, int *quotelenp); 66 | int __runesfmt(Fmt *f); 67 | int __strfmt(Fmt *f); 68 | 69 | #define FMTCHAR(f, t, s, c)\ 70 | do{\ 71 | if(t + 1 > (char*)s){\ 72 | t = (char*)__fmtflush(f, t, 1);\ 73 | if(t != nil)\ 74 | s = (char*)f->stop;\ 75 | else\ 76 | return -1;\ 77 | }\ 78 | *t++ = c;\ 79 | }while(0) 80 | 81 | #define FMTRCHAR(f, t, s, c)\ 82 | do{\ 83 | if(t + 1 > (Rune*)s){\ 84 | t = (Rune*)__fmtflush(f, t, sizeof(Rune));\ 85 | if(t != nil)\ 86 | s = (Rune*)f->stop;\ 87 | else\ 88 | return -1;\ 89 | }\ 90 | *t++ = c;\ 91 | }while(0) 92 | 93 | #define FMTRUNE(f, t, s, r)\ 94 | do{\ 95 | Rune _rune;\ 96 | int _runelen;\ 97 | if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){\ 98 | t = (char*)__fmtflush(f, t, _runelen);\ 99 | if(t != nil)\ 100 | s = (char*)f->stop;\ 101 | else\ 102 | return -1;\ 103 | }\ 104 | if(r < Runeself)\ 105 | *t++ = r;\ 106 | else{\ 107 | _rune = r;\ 108 | t += runetochar(t, &_rune);\ 109 | }\ 110 | }while(0) 111 | 112 | #ifdef va_copy 113 | # define VA_COPY(a,b) va_copy(a,b) 114 | # define VA_END(a) va_end(a) 115 | #else 116 | # define VA_COPY(a,b) (a) = (b) 117 | # define VA_END(a) 118 | #endif 119 | 120 | -------------------------------------------------------------------------------- /tiny9/libc/ctime.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is distributred under the Lucent Public License, Version 1.02. 4 | See ../../LUCENT 5 | 6 | Copyright © 2000-2009 Lucent Technologies. All Rights Reserved. 7 | Portions Copyright © 2001-2008 Russ Cox 8 | Portions Copyright © 2008-2009 Google Inc. 9 | */ 10 | 11 | /* 12 | * This routine converts time as follows. 13 | * The epoch is 0000 Jan 1 1970 GMT. 14 | * The argument time is in seconds since then. 15 | * The localtime(t) entry returns a pointer to an array 16 | * containing 17 | * 18 | * seconds (0-59) 19 | * minutes (0-59) 20 | * hours (0-23) 21 | * day of month (1-31) 22 | * month (0-11) 23 | * year-1970 24 | * weekday (0-6, Sun is 0) 25 | * day of the year 26 | * daylight savings flag 27 | * 28 | * The routine gets the daylight savings time from the environment. 29 | * 30 | * asctime(tvec)) 31 | * where tvec is produced by localtime 32 | * returns a ptr to a character string 33 | * that has the ascii time in the form 34 | * 35 | * \\ 36 | * Thu Jan 01 00:00:00 GMT 1970n0 37 | * 012345678901234567890123456789 38 | * 0 1 2 39 | * 40 | * ctime(t) just calls localtime, then asctime. 41 | */ 42 | 43 | #include 44 | #include 45 | 46 | #include "zoneinfo.h" 47 | 48 | static char dmsize[12] = 49 | { 50 | 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 51 | }; 52 | 53 | #define dysize ctimedysize 54 | static int dysize(int); 55 | static void ct_numb(char*, int); 56 | 57 | char* 58 | p9ctime(long t) 59 | { 60 | return asctime(localtime(t)); 61 | } 62 | 63 | Tm* 64 | p9localtime(long tim) 65 | { 66 | Tinfo ti; 67 | Tm *ct; 68 | 69 | if (zonelookuptinfo(&ti, tim)!=-1) { 70 | ct = gmtime(tim+ti.tzoff); 71 | strncpy(ct->zone, ti.zone, sizeof ct->zone); 72 | ct->zone[sizeof ct->zone-1] = 0; 73 | ct->tzoff = ti.tzoff; 74 | return ct; 75 | } 76 | return gmtime(tim); 77 | } 78 | 79 | Tm* 80 | p9gmtime(long tim) 81 | { 82 | int d0, d1; 83 | long hms, day; 84 | static Tm xtime; 85 | 86 | /* 87 | * break initial number into days 88 | */ 89 | hms = tim % 86400L; 90 | day = tim / 86400L; 91 | if(hms < 0) { 92 | hms += 86400L; 93 | day -= 1; 94 | } 95 | 96 | /* 97 | * generate hours:minutes:seconds 98 | */ 99 | xtime.sec = hms % 60; 100 | d1 = hms / 60; 101 | xtime.min = d1 % 60; 102 | d1 /= 60; 103 | xtime.hour = d1; 104 | 105 | /* 106 | * day is the day number. 107 | * generate day of the week. 108 | * The addend is 4 mod 7 (1/1/1970 was Thursday) 109 | */ 110 | 111 | xtime.wday = (day + 7340036L) % 7; 112 | 113 | /* 114 | * year number 115 | */ 116 | if(day >= 0) 117 | for(d1 = 1970; day >= dysize(d1); d1++) 118 | day -= dysize(d1); 119 | else 120 | for (d1 = 1970; day < 0; d1--) 121 | day += dysize(d1-1); 122 | xtime.year = d1-1900; 123 | xtime.yday = d0 = day; 124 | 125 | /* 126 | * generate month 127 | */ 128 | 129 | if(dysize(d1) == 366) 130 | dmsize[1] = 29; 131 | for(d1 = 0; d0 >= dmsize[d1]; d1++) 132 | d0 -= dmsize[d1]; 133 | dmsize[1] = 28; 134 | xtime.mday = d0 + 1; 135 | xtime.mon = d1; 136 | strcpy(xtime.zone, "GMT"); 137 | return &xtime; 138 | } 139 | 140 | char* 141 | p9asctime(Tm *t) 142 | { 143 | const char *ncp; 144 | static char cbuf[30]; 145 | 146 | strcpy(cbuf, "Thu Jan 01 00:00:00 GMT 1970\n"); 147 | ncp = &"SunMonTueWedThuFriSat"[t->wday*3]; 148 | cbuf[0] = *ncp++; 149 | cbuf[1] = *ncp++; 150 | cbuf[2] = *ncp; 151 | ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[t->mon*3]; 152 | cbuf[4] = *ncp++; 153 | cbuf[5] = *ncp++; 154 | cbuf[6] = *ncp; 155 | ct_numb(cbuf+8, t->mday); 156 | ct_numb(cbuf+11, t->hour+100); 157 | ct_numb(cbuf+14, t->min+100); 158 | ct_numb(cbuf+17, t->sec+100); 159 | ncp = t->zone; 160 | cbuf[20] = *ncp++; 161 | cbuf[21] = *ncp++; 162 | cbuf[22] = *ncp; 163 | if(t->year >= 100) { 164 | cbuf[24] = '2'; 165 | cbuf[25] = '0'; 166 | } 167 | ct_numb(cbuf+26, t->year+100); 168 | return cbuf; 169 | } 170 | 171 | static 172 | int 173 | dysize(int y) 174 | { 175 | 176 | if(y%4 == 0 && (y%100 != 0 || y%400 == 0)) 177 | return 366; 178 | return 365; 179 | } 180 | 181 | static 182 | void 183 | ct_numb(char *cp, int n) 184 | { 185 | 186 | cp[0] = ' '; 187 | if(n >= 10) 188 | cp[0] = (n/10)%10 + '0'; 189 | cp[1] = n%10 + '0'; 190 | } 191 | 192 | --------------------------------------------------------------------------------