From 54530f8b4157839359273958a6ad36bb48257456 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 4 May 2006 00:18:01 +0000 Subject: [PATCH] working on making initial startup version of realtime compile --- cebpic/README.protocol | 2 +- hostside/Makefile | 27 +++++++++---------- hostside/client.c | 2 +- hostside/commands.c | 2 +- hostside/common.h | 57 ++++++++++++++++++++++++++++++++++++++++ hostside/daemons.h | 44 +++---------------------------- hostside/gui-plan.c | 3 ++- hostside/hostside.h | 22 +++------------- hostside/main.c | 1 + hostside/multiplex.h | 2 -- hostside/obc.c | 8 +++++- hostside/parseutils.c | 13 ++++----- hostside/realtime.c | 10 ++++--- hostside/realtime.h | 25 +++++++++++++++++- hostside/skelproto-pic.c | 2 +- hostside/startup.c | 48 +++++++++++++++++++-------------- hostside/utils.c | 1 + 17 files changed, 155 insertions(+), 114 deletions(-) diff --git a/cebpic/README.protocol b/cebpic/README.protocol index 3ceace6..7e0861a 100644 --- a/cebpic/README.protocol +++ b/cebpic/README.protocol @@ -58,7 +58,7 @@ From PIC to host: < 1 0001 XXX 0 XXXXXXX (88+) PONG Pong `X' (reply to Ping `X') < 0 000 1001 (HT) HELLO I am booted < 0 000 1011 (VT) AAARGH Followed by debug chars (only) - < 0 000 1101 (CR) WATCHDOG Timeout happened + < 0 000 1101 (CR) WTIMEOUT Watchdog timeout happened < 0 000 0111 (BEL) FAULT Fault exists < 0 000 0110 (ACK) FIXED Fault now fixed < 0 0100 PPP (20+) POINTED Point change done using capacitor P diff --git a/hostside/Makefile b/hostside/Makefile index 9e31d70..add2355 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -1,12 +1,11 @@ # -AUTOINCS= selectors.h +AUTOINCS= auproto-pic.h layoutinfo.h selectors.h +TARGETS= hostside-old gui-plan-bot realtime include ../common.make include ../cprogs.make -TARGETS= hostside hostside-old gui-plan-bot realtime - default: all recurse: all for-pic: @@ -15,10 +14,9 @@ all: $(TARGETS) hostside-old: serialio.o nmra.o main.o encode.o utils.o $(LINK) -hostside: hostside.o serialio.o client.o obc.o commands.o utils.o \ - nmra.o encode.o retransmit.o output.o auproto-pic.o \ - parseutils.o \ - -loop +realtime: realtime.o startup.o cdumgr.o \ + cmdinput.o \ + utils.o serialio.o auproto-pic.o $(LINK) proto-expanded: ../cebpic/README.protocol @@ -29,7 +27,8 @@ gui-plan-bot: gui-plan-%: gui-plan.o utils.o parseutils.o \ __oop-read-copy.o -loop $(LINK) -L/usr/X11R6/lib -lXpm -lX11 -auproto-%: parse-proto-spec proto-expanded skelproto-% +auproto-pic.c auproto-pic.h: auproto-%: \ + parse-proto-spec proto-expanded skelproto-% ./$+ $o layoutinfo.h: ../layout/ours.layout-data.c Makefile @@ -38,15 +37,13 @@ layoutinfo.h: ../layout/ours.layout-data.c Makefile selectors.h: selectors.h.gen ./$< $o -%.o: auproto-pic.h -safety.o trackloc.o: layoutinfo.h - -realtime: realtime.o startup.o cdumgr.o - cmdinput.o - utils.o serialio.o auproto-pic.o +safety: safety.o utils.o trackloc.o ../layout/ours.layout-data.o $(LINK) -safety: safety.o utils.o trackloc.o ../layout/ours.layout-data.o +hostside: hostside.o serialio.o client.o obc.o commands.o utils.o \ + nmra.o encode.o retransmit.o output.o auproto-pic.o \ + parseutils.o \ + -loop $(LINK) clean: diff --git a/hostside/client.c b/hostside/client.c index 0519795..8b3a24a 100644 --- a/hostside/client.c +++ b/hostside/client.c @@ -5,7 +5,7 @@ #include #include -#include "hostside.h" +#include "multiplex.h" #include "../layout/dlist.h" struct ClientList clients; diff --git a/hostside/commands.c b/hostside/commands.c index 4683877..26ee20d 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -6,7 +6,7 @@ #include #include -#include "hostside.h" +#include "realtime.h" #include "auproto-pic.h" #define NMRA_MAX_NARGS 10 diff --git a/hostside/common.h b/hostside/common.h index 1d11bb5..7354b09 100644 --- a/hostside/common.h +++ b/hostside/common.h @@ -12,6 +12,12 @@ #include #include +typedef struct ParseState ParseState; +typedef struct CmdInfo CmdInfo; +typedef struct Client Client; + +extern const char *progname; + /*---------- types ----------*/ typedef unsigned char Byte; @@ -29,6 +35,55 @@ typedef struct PicInsn { int l; } PicInsn; +/*---------- from parseutils.c ----------*/ + +struct ParseState { + Client *cl; /* used only by multiplexer */ + const char *remain; + const char *thisword; + int lthisword; +}; + +void vbadcmd(ParseState *ps, const char *fmt, va_list al) + __attribute__((format(printf,2,0))); +void badcmd(ParseState *ps, const char *fmt, ...) + __attribute__((format(printf,2,3))); + +int lstrstrcmp(const char *a, int la, const char *b); +int thiswordstrcmp(ParseState *ps, const char *b); + +int ps_word(ParseState *ps); +int ps_needword(ParseState *ps); +int ps_needhextoend(ParseState *ps, Byte *dbuf, int *len_io); +int ps_neednumber(ParseState *ps, long *r, long min, long max, const char *wh); +int ps_neednoargs(ParseState *ps); + +/*---------- macro for table lookups, with help from parseutils.c ----------*/ + +#define some_lookup(ps, infos) \ + ((const typeof(infos[0])*) \ + any_lookup((ps),(infos),sizeof((infos)[0]))) + +#define some_needword_lookup(ps, infos, what) \ + ((const typeof(infos[0])*) \ + any_needword_lookup((ps),(infos),sizeof((infos)[0]),(what))) + +const void *any_lookup(ParseState *ps, const void *infos, size_t infosz); +const void *any_needword_lookup(ParseState *ps, const void *infos, + size_t sz, const char *what); + +/*---------- from client.c ----------*/ + +struct CmdInfo { + const char *name; + void (*fn)(ParseState *ps, const CmdInfo *ci); + int xarg; +}; + +void stdin_client(void); + +extern const CmdInfo toplevel_cmds[]; /* defined in commands.c*/ + /*---------- from utils.c ----------*/ void vdie(const char *fmt, int ev, va_list al) @@ -42,6 +97,8 @@ char *mstrdupl(const char *s, int l); char *mstrdup(const char *s); void mgettimeofday(struct timeval *tv); +#define massert(x) ((x) ? (void)0 : diem()) + /*---------- from serialio.c ----------*/ void serial_open(const char *device); diff --git a/hostside/daemons.h b/hostside/daemons.h index 836680e..205b66a 100644 --- a/hostside/daemons.h +++ b/hostside/daemons.h @@ -10,15 +10,16 @@ #include #include -#include -#include +#include "common.h" + +typedef struct CommandInput CommandInput; /*---------- from obc.c ----------*/ typedef struct OutBuffer OutBuffer; typedef struct OutBufferChain OutBufferChain; typedef void OutBufferError(OutBufferChain*, const char *e1, const char *e2 - /* both e1 and e2 always non-0. say `$e1: $e2'); + /* both e1 and e2 always non-0. say `$e1: $e2' */); struct OutBufferChain { /* set by user: */ @@ -48,13 +49,6 @@ struct CommandInput { oop_read *rd; }; -struct ParseState { - Client *cl; /* used only by multiplexer */ - const char *remain; - const char *thisword; - int lthisword; -}; - void cmdin_new(CommandInput *cmdi, int readfd); /* fill in cmdi->out's `set by user' fields before calling cmdin_new, * as cmdin_new will call obc_init and will use cmdi->out->fd. */ @@ -82,34 +76,4 @@ void toev_start(TimeoutEvent*); /* IR -> R; reads duration */ /* if duration is -1 then is same as toev_stop */ void toev_stop(TimeoutEvent*); /* IR -> I */ -/*---------- from parseutils.c ----------*/ - -void vbadcmd(ParseState *ps, const char *fmt, va_list al) - __attribute__((format(printf,2,0))); -void badcmd(ParseState *ps, const char *fmt, ...) - __attribute__((format(printf,2,3))); - -int lstrstrcmp(const char *a, int la, const char *b); -int thiswordstrcmp(ParseState *ps, const char *b); - -int ps_word(ParseState *ps); -int ps_needword(ParseState *ps); -int ps_needhextoend(ParseState *ps, Byte *dbuf, int *len_io); -int ps_neednumber(ParseState *ps, long *r, long min, long max, const char *wh); -int ps_neednoargs(ParseState *ps); - -/*---------- macro for table lookups, with help from parseutils.c ----------*/ - -#define some_lookup(ps, infos) \ - ((const typeof(infos[0])*) \ - any_lookup((ps),(infos),sizeof((infos)[0]))) - -#define some_needword_lookup(ps, infos, what) \ - ((const typeof(infos[0])*) \ - any_needword_lookup((ps),(infos),sizeof((infos)[0]),(what))) - -const void *any_lookup(ParseState *ps, const void *infos, size_t infosz); -const void *any_needword_lookup(ParseState *ps, const void *infos, - size_t sz, const char *what); - #endif /*DAEMONS_H*/ diff --git a/hostside/gui-plan.c b/hostside/gui-plan.c index 73bdbee..1eb7196 100644 --- a/hostside/gui-plan.c +++ b/hostside/gui-plan.c @@ -15,7 +15,7 @@ #include #include -#include "hostside.h" +#include "common.h" #include "../layout/plan-data-format.h" #include @@ -44,6 +44,7 @@ struct SegmovfeatState { }; oop_source *events; +const char *progname= "gui-plan"; static SegmovfeatState **state, *states_head; static Display *d; diff --git a/hostside/hostside.h b/hostside/hostside.h index 8d1ed6d..b6fbdc6 100644 --- a/hostside/hostside.h +++ b/hostside/hostside.h @@ -1,4 +1,5 @@ /* + * OBSOLETE FILE * declarations for hostside controller daemon */ @@ -7,9 +8,6 @@ #include "common.h" -typedef struct ParseState ParseState; -typedef struct CmdInfo CmdInfo; - /*---------- from protocol.c ----------*/ typedef struct OrdinaryPicMessage OrdinaryPicMessage; @@ -19,22 +17,6 @@ struct OrdinaryPicMessage { int operand_bits; /* 0: no operand. >=7, insn is a 2-byte message */ }; -/*---------- from hostside.c ----------*/ - -extern oop_source *events; - -/*---------- from client.c ----------*/ - -struct CmdInfo { - const char *name; - void (*fn)(ParseState *ps, const CmdInfo *ci); - int xarg; -}; - -void stdin_client(void); - -extern const CmdInfo toplevel_cmds[]; /* defined in commands.c*/ - /*---------- from retransmit.c ----------*/ struct RetransmitNode { @@ -45,3 +27,5 @@ struct RetransmitNode { void retransmit_queue(RetransmitNode *rn); void retransmit_cancel(RetransmitNode *rn); + +#endif diff --git a/hostside/main.c b/hostside/main.c index 7f2cc6d..378c173 100644 --- a/hostside/main.c +++ b/hostside/main.c @@ -19,6 +19,7 @@ #include "common.h" +const char *progname= "hostside-old"; static FILE *dump_stream= 0; static int repeat_delay= -1, iterations= -1; diff --git a/hostside/multiplex.h b/hostside/multiplex.h index 81d3b13..0c66f2c 100644 --- a/hostside/multiplex.h +++ b/hostside/multiplex.h @@ -8,8 +8,6 @@ #include "daemons.h" -typedef struct Client Client; - /*---------- from output.c ----------*/ typedef unsigned long Selector; diff --git a/hostside/obc.c b/hostside/obc.c index ef294fc..63547a0 100644 --- a/hostside/obc.c +++ b/hostside/obc.c @@ -6,7 +6,7 @@ #include #include -#include "hostside.h" +#include "daemons.h" #include "../layout/dlist.h" struct OutBuffer { @@ -15,6 +15,12 @@ struct OutBuffer { int l; }; +void vbadcmd(ParseState *ps, const char *fmt, va_list al) { + oprintf(&ps->ci->out,"error "); + ovprintf(&ps->ci->out,fmt,al); + owrite(&ps->ci->out,"\n",1); +} + static void *writeable(oop_source *evts, int fd, oop_event evt, void *ch_v) { OutBufferChain *ch= ch_v; diff --git a/hostside/parseutils.c b/hostside/parseutils.c index 89ab4ba..7cb962a 100644 --- a/hostside/parseutils.c +++ b/hostside/parseutils.c @@ -1,17 +1,14 @@ -/**/ +/* + * common + * utilities for helping parsing + */ #include #include #include #include -#include "hostside.h" - -void vbadcmd(ParseState *ps, const char *fmt, va_list al) { - oprintf(&ps->ci->out,"error "); - ovprintf(&ps->ci->out,fmt,al); - owrite(&ps->ci->out,"\n",1); -} +#include "common.h" void badcmd(ParseState *ps, const char *fmt, ...) { va_list al; diff --git a/hostside/realtime.c b/hostside/realtime.c index 59285eb..7d2b7cd 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -4,6 +4,8 @@ #include "realtime.h" +const char *progname= "realtime"; + /*---------- global variables ----------*/ CommandInput cmdi; @@ -19,11 +21,11 @@ static void comms_error(const char *ch, const char *e1, static void *read_exception(oop_source *evts, int fd, oop_event evt, void *cl_v) { - OutBufferChain *ch; + const char *ch; char bufc; int r; - ch= (fd==up_ochain.fd ? up_ochain.desc : + ch= (fd==UPO->fd ? UPO->desc : fd==serial_fd ? "serial port" : 0); @@ -31,6 +33,8 @@ static void *read_exception(oop_source *evts, int fd, if (r==-1) comms_error(ch, "read error", strerror(errno)); else if (r==0) comms_error(ch, "reports exception, reads EOF", 0); else comms_error(ch, "reports exception, but readable", 0); + + return OOP_CONTINUE; } /*---------- command channel handling (oop_read, obc) ----------*/ @@ -67,7 +71,6 @@ static PicInsn serial_buf; static void *serial_readable(oop_source *evts, int fd, oop_event evt, void *u0) { - const Byte *ep; int r, buf_used; r= read(serial_fd, &serial_buf.d, sizeof(serial_buf.d) - serial_buf.l); @@ -139,6 +142,7 @@ int main(int argc, const char **argv) { events->on_fd(events, serial_fd, OOP_READ, serial_readable, 0); events->on_fd(events, serial_fd, OOP_EXCEPTION, read_exception, 0); + sta_startup(); oop_sys_run(sys_events); abort(); } diff --git a/hostside/realtime.h b/hostside/realtime.h index b98c547..473f415 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -5,6 +5,18 @@ #ifndef REALTIME_H #define REALTIME_H +#include "daemons.h" +#include "auproto-pic.h" + +#include +#include +#include +#include +#include + +#include +#include + typedef struct RetransmitNode RetransmitNode; extern CommandInput cmdi; @@ -19,6 +31,17 @@ typedef enum { /* sta_toev ping_toev */ Sta_Run /* I ? R set */ } StartupState; -#define UPO (&(cmdi->out)); +#define UPO (&(cmdi.out)) + +void oupicio(const char *dirn, const PicInsnInfo *pii, int objnum); +void ouhex(const char *word, const Byte *command, int length); + +void serial_moredata(PicInsn *buf); +void serial_transmit(const PicInsn *pi); + +void sta_startup(void); +extern StartupState sta_state; + +void abandon_run(void); #endif /*REALTIME_H*/ diff --git a/hostside/skelproto-pic.c b/hostside/skelproto-pic.c index d4403e4..ec565e2 100644 --- a/hostside/skelproto-pic.c +++ b/hostside/skelproto-pic.c @@ -7,7 +7,7 @@ * and related functions */ -#include "hostside.h" +#include "common.h" #include "auproto-pic.h" extern void enco_pic_anyinsn(PicInsn *out, const PicInsnInfo *pii, diff --git a/hostside/startup.c b/hostside/startup.c index a72a0b0..f9fd986 100644 --- a/hostside/startup.c +++ b/hostside/startup.c @@ -5,11 +5,13 @@ #include "realtime.h" -static StartupState sta_state; +StartupState sta_state; + static TimeoutEvent sta_toev; +static TimeoutEvent ping_toev; static int ping_seq; -static PicInsn *piob; +static PicInsn piob; static void sta_goto(StartupState new_state); static void timedout_onward(TimeoutEvent *toev) { @@ -23,31 +25,28 @@ static void timedout_ping(TimeoutEvent *toev) { } static void timefor_ping(TimeoutEvent *toev) { - serial_transit(&ping_pi); + enco_pic_ping(&piob, ping_seq); + serial_transmit(&piob); + ping_toev.callback= timedout_ping; toev_start(&ping_toev); } static void initial_ping(void) { struct timeval now; - ping_toev.callback= timedout_ping; - ping_toev.duration= 300; mgettimeofday(&now); ping_seq= (now.tv_sec & 0x1fU) << 5; /* bottom 5bi of secs: period 32s */ ping_seq |= (now.tv_usec >> 15); /* top 5bi of 20bi us: res.~2^15us */ - enco_pic_ping(&piob, ping_seq); - serial_transmit(&piob); + ping_toev.duration= 300; timefor_ping(0); } +void sta_startup(void) { sta_goto(Sta_Flush); } + static void sta_goto(StartupState new_state) { toev_stop(&sta_toev); sta_toev.callback= timedout_onward; - sta_toev.callback= -1; - - toev_stop(&ping_toev); - ping_toev.callback= timedout_ping; - ping_toev.duration= -1; + sta_toev.duration= -1; if (new_state < Sta_Ping) { toev_stop(&ping_toev); @@ -81,13 +80,16 @@ static void sta_goto(StartupState new_state) { toev_start(&sta_toev); sta_state= new_state; - notify_startup(new_state); + + /* notify various people: */ + oprintf(UPO, "stastate %d\n", sta_state); + /* ... add others here. */ } void serial_moredata(PicInsn *buf) { const PicInsnInfo *pii; int objnum; - char *&ep + Byte *ep; /* Called when more data is received from PICs. * On entry, buf->l is amount of data available. @@ -132,16 +134,17 @@ void serial_moredata(PicInsn *buf) { ouhex("picioh in toolong", buf->d, buf->l); die("PIC sent packet too long"); } - return 0; + buf->l= 0; /* message not yet finished, so consume nothing */ + return; found_end: /* Aha! */ buf->l= ep - buf->d; ouhex("picioh in msg", buf->d, buf->l); - picinsn_decode(&buf, pic_reply_infos, &pii, &objnum); + picinsn_decode(buf, pic_reply_infos, &pii, &objnum); if (!pii) { oprintf(UPO, "picio in unknown\n"); return; } oupicio("in",pii,objnum); - pii->input_fn(pii,pi,objnum); + pii->input_fn(pii,buf,objnum); } void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { @@ -151,7 +154,8 @@ void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { if (sta_state == Sta_Ping) { sta_goto(Sta_Settling); } else { - ping_toev.callback= timedfor_ping; + ping_toev.duration= 1000; + ping_toev.callback= timefor_ping; toev_start(&ping_toev); } } @@ -167,9 +171,9 @@ void on_pic_fault(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { sta_goto(Sta_Fault); } -void on_pic_watchdog(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { +void on_pic_wtimeout(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { if (sta_state <= Sta_Settling) return; - if (sta_state == Sta_Resolving) die("PIC sent WATCHDOG in Resolving"); + if (sta_state == Sta_Resolving) die("PIC sent WTIMEOUT in Resolving"); oprintf(UPO, "warning watchdog \"PIC watchdog timer triggered\"\n"); } @@ -187,3 +191,7 @@ void on_pic_detect0(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { void on_pic_detect1(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { /* fixme do something here */ } + +void abandon_run(void) { + /* fixme do something here */ +} diff --git a/hostside/utils.c b/hostside/utils.c index db23184..3a1cb42 100644 --- a/hostside/utils.c +++ b/hostside/utils.c @@ -45,6 +45,7 @@ char *mstrdupl(const char *s, int l) { char *mstrdup(const char *s) { return mstrdupl(s,strlen(s)); } void mgettimeofday(struct timeval *tv) { + int r; r= gettimeofday(tv,0); if (r) diee("gettimeofday failed"); } -- 2.30.2