diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..fabcc76 --- /dev/null +++ b/src/config.h @@ -0,0 +1,157 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#include +#include +#include + +#if defined(__TINYC__) +#pragma pack(1) +#endif + +#define DEBUG 1 +#define PROFILE 1 + +#define HAS_TYPES 1 +#define HAS_FLOAT 0 +/* Support for functions and local variables (stack) */ +#define HAS_FUNC 1 +/* Speed-up variable look-up with small hash table */ +#define HASH_VAR 1 + +/* + A stack undeflow can only occur if compiler generates wrong code or VM is faulty. + Or external ccalls are wrong. + Should only be enabled for testing and debugging. +*/ +#define STACKUNDERFLOWCHECK 0 + +/* Default length of strings (heap) */ +#define DEFSTRINGLEN 16 +/* event module: maximal number of events (table) */ +#define MAXEVENTS 16 +/* maximum length of identifiers */ +#define MAXNAMELEN 8 +/* maximum number of context tasks. At least 1, typical 2 (0: main program, foreground, 1:command line, background) */ +#define MAXTASKS 4 +/* Memory alignment of data part of variables (scalars, strings, arrays) */ +#define MEMALIGN 2 +/* Memory alignment of data part of variables (scalars, strings, arrays) */ +/* Total padding is HAS_LOCK + VARPADDING */ +#define VARPADDING 0 +/* Variable/Function locking via lock(x) and unlock(x) */ +#define HAS_LOCK 1 + +/* Default stack size */ +#define DEFSTACKSIZE 100 + +/* Defaukt number type, inherited by stacks, too */ +#define NUMBER_T int16_t + +/* Some functions can be inlined, leave empty if these function candidates should not be converted to inline code */ +#define INLINE + +/* SHM support for debgging and hw-signal simulation? */ +#define SHM 1 + +/* With network module supporting serial communication devices? */ +#define HAS_NET 1 +/* W/o routing a simplified network module is used providing only down- and up-direction message proapagation with 1 link per node */ +#define HAS_NET_ROUTING 0 +/* Maximal number of serial ports (1 if HAS_NET and HAS_NET_ROUTING=0) */ +#define NUMPORTS 1 +/* Port buffer PORTRXBUFFERSIZE:[rx,inp] PORTTXBUFFERSIZE:[tx], one port*/ +#define PORTRXBUFFERSIZE 1024 +/* only needed if HAS_NET_ROUTING==1 */ +#define PORTTXBUFFERSIZE 1024 +/* message log buffer (shared by all ports), number of messages, only for HAS_NET_ROUTING==1 */ +#define MSGLOGSIZE 32 + + +/** MEMORY ***/ +/* Dynamic memory allocation */ +#define MEMALLOC malloc +#define MEMCOPY memcpy +#define MEMSET memset +/* + VM access to communication channels (including stdin,stdout) + Without or with net module (or only mini net w/o routing). + + Entry points are the following operations that must be provided by the host application. +*/ +/* + IO Multiplexer API: These funcions must be provided by host applcation. + fd >= 0: Real file or serial port IO from net module + fd <= 0: Virtual IO by VM, must be handled separately +*/ +extern int availbyte(int fd); +extern char inbyte(int fd); +extern int outbyte(int fd,char x); + +#define AVAILBYTE(fd) availbyte(-(fd+1)) +#define INBYTE(fd) inbyte(-(fd+1)) +#define OUTBYTE(fd,x) outbyte(-(fd+1),x) + +/* + Wake up blocked Loop (if Loop is blocking) + Unix: self sending of signal + Actually not needed. +*/ +extern void interrupt(); +#define INTERRUPT() interrupt() + +/* + Read/write-through versions w/o using the net module, can be used for single node systems +#define AVAILBYTE(fd) 1 +#define INBYTE(fd) getchar() +#define OUTBYTE(fd,x) putchar(x) +*/ + +#ifndef MILLIS +// millis, relative to program start +/* return system clock in milliseconds */ +#include +time_t __millis0; +suseconds_t __micros0; +#define MILLIS() ({ \ + struct timeval t ; \ + gettimeofday ( & t , NULL ) ; \ + unsigned long retval = (int)((t.tv_sec * 1000 + ( t.tv_usec + 500 ) / 1000)-__millis0); \ + retval;\ +}) +#endif + +#ifndef MICROS +#define MICROS() ({ \ + struct timeval t ; \ + gettimeofday ( & t , NULL ) ; \ + unsigned long retval = t.tv_usec - __micros0; \ + retval;\ +}) +#endif + +#ifndef TIMEINIT +// timeinit +#define TIMEINIT() {\ + struct timeval t ; \ + gettimeofday ( & t , NULL ) ; \ + __millis0 = t.tv_sec * 1000 + ( t.tv_usec + 500 ) / 1000 ;\ + __micros0 = t.tv_usec;\ +} +#endif + +extern int iowait(); +#define IOINIT ioinit +#define IOAWAIT iowait + + +// Only for debugging/monitoring (print_format can be redirected to router/serial port) +// always redirected to stdout +#ifdef DEBUG + void vLog(const char* fmtStr, ...); +#else + #define vLog(...) +#endif + + +#endif