chiark / gitweb /
support PICs change of X from PING to PONG; also leave various useless stuff out...
authorian <ian>
Sat, 17 May 2008 14:50:01 +0000 (14:50 +0000)
committerian <ian>
Sat, 17 May 2008 14:50:01 +0000 (14:50 +0000)
hostside/eventhelp.c
hostside/realtime.c
hostside/realtime.h
hostside/simulate.c
hostside/startup.c

index 0232a69ee16175482144106e29277440bbb6a211..0e907baf85698dc03af2cb2ef00d5b0cb20c3813 100644 (file)
@@ -8,16 +8,24 @@
 
 #include "realtime.h"
 
+const char toev_fast_pclass[]= "fast";
+
 void real_mgettimeofday(struct timeval *tv) {
   int r;
   r= gettimeofday(tv,0);
   if (r) diee("gettimeofday failed");
 }
 
+static int toev_sim_show(TimeoutEvent *toev) {
+  return simlog_full || toev->pclass!=toev_fast_pclass;
+}
+
 void *toev_callback(oop_source *source, struct timeval tv, void *t_v) {
   TimeoutEvent *toev= t_v;
-  simlog("timer-event %s.%s\n",toev->pclass,toev->pinst);
-  simlog_flush();
+  if (toev_sim_show(toev)) {
+    simlog("timer-event %s.%s\n",toev->pclass,toev->pinst);
+    simlog_flush();
+  }
   toev->running= 0;
   toev->callback(toev);
   return OOP_CONTINUE;
@@ -29,7 +37,8 @@ void toev_start(TimeoutEvent *toev) {
   toev_stop(toev);
   if (toev->duration==-1) return;
   toev->running= 1;
-  mgettimeofday(&toev->abs);
+  if (toev_sim_show(toev)) mgettimeofday(&toev->abs);
+  else real_mgettimeofday(&toev->abs);
   assert(toev->duration < INT_MAX/1000);
   toev->abs.tv_usec += toev->duration * 1000;
   toev->abs.tv_sec += toev->abs.tv_usec / 1000000;
index fcd02aec13ba1ac759519f3f3e710917b58f094a..f76e922dd24b1c41af2d4164b7a5379400aecc99 100644 (file)
@@ -339,6 +339,7 @@ int main(int argc, const char **argv) {
       case 'p': persist_fn= arg;                  arg=0; break;
       case 'v': picio_send_noise= atoi(arg);      arg=0; break;
       case 'm': sta_state= Sta_Manual;                   break;
+      case 'V': simlog_full=1;                           break;
       case 'L': logcopy_fn= arg;                  arg=0; break;
       case 'S': simulate= arg;                    arg=0; break;
       default: badusage("unknown option");
index fafa15d96827414f51b31b02bef9e32a85349c61..fb98a7237dc340454af4f4eab4cfe136f5e0251c 100644 (file)
@@ -158,7 +158,6 @@ void serial_transmit(const PicInsn *pi);
 
 /*---------- for/from simulate.c ----------*/
 
-const char *simulate;
 void serial_indata_process(int buf_used);
 
 void sim_initialise(const char *logduplicate);
@@ -177,6 +176,9 @@ void sim_toev_start(TimeoutEvent *toev);
 void sim_toev_stop(TimeoutEvent *toev);
 void sim_mgettimeofday(struct timeval *tv);
 
+extern int simlog_full;
+extern const char *simulate;
+
 extern PicInsn serial_buf;
 
 /*---------- from actual.c ----------*/
@@ -192,6 +194,8 @@ void motions_all_abandon(void);
 
 /*---------- from eventhelp.c ----------*/
 
+extern const char toev_fast_pclass[];
+
 typedef void TimeoutEventFn(TimeoutEvent*);
 struct TimeoutEvent {         /* Undefined   Idle      Running     set by   */
   int running;                /*  any         0         1           toev_   */
index f0b8f7e4e4f57bbaa507ca1b94d8e2d274e4b7c3..2f42e32db9d315c9243df11d8b6a210ddb82437d 100644 (file)
@@ -12,6 +12,9 @@ typedef struct SimTimeout {
 
 typedef void SimEventFn(void);
 
+int simlog_full;
+const char *simulate;
+
 static SimEventFn se_timestamp, se_timerevent;
 static SimEventFn se_serial, se_command, se_eof;
 
index fb7c137400781112c7aa47ba24ab4d15ba02d671..275941c623b52e26190ed648ad1aa60b2100c98b 100644 (file)
@@ -15,8 +15,8 @@ static void sta_goto(StartupState new_state);
 
 /*---------- ping ----------*/
 
-static int ping_seq;
-static TimeoutEvent ping_toev= { .pclass="startup", .pinst="ping" };
+static int pong_seq;
+static TimeoutEvent ping_toev= { .pclass=toev_fast_pclass, .pinst="ping" };
 
 static void timedout_ping(TimeoutEvent *toev) {
   assert(sta_state >= Sta_Ping);
@@ -24,7 +24,7 @@ static void timedout_ping(TimeoutEvent *toev) {
 }
 
 static void timefor_ping(TimeoutEvent *toev) {
-  enco_pic_ping(&piob, ping_seq);
+  enco_pic_ping(&piob, pong_seq ^ PING_PONG_PATTERN);
   serial_transmit(&piob);
   ping_toev.callback= timedout_ping;
   toev_start(&ping_toev);
@@ -34,15 +34,19 @@ static void initial_ping(void) {
   struct timeval now;
   
   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 */
+  pong_seq= (now.tv_sec & 0x1fU) << 5; /* bottom 5bi of secs: period 32s */
+  pong_seq |= (now.tv_usec >> 15);      /* top 5bi of 20bi us: res.~2^15us */
   ping_toev.duration=  300;
   timefor_ping(0);
 }
 
 /*---------- watchdog ----------*/
 
-static TimeoutEvent watchdog_toev= { .pclass="startup", .pinst="watchdog" };
+static TimeoutEvent watchdog_toev= {
+  .pclass=toev_fast_pclass,
+  .pinst="watchdog",
+  .duration= UNMARGIN_WATCHDOG - MARGIN_WATCHDOG,
+};
 static PicInsn watchdog_piob;
 
 static void watchdog_transmit(TimeoutEvent *toev) {
@@ -51,7 +55,6 @@ static void watchdog_transmit(TimeoutEvent *toev) {
 }
 
 static void watchdog_start(void) {
-  watchdog_toev.duration= UNMARGIN_WATCHDOG - MARGIN_WATCHDOG;
   watchdog_toev.callback= watchdog_transmit;
   enco_pic_watchdog(&watchdog_piob, UNMARGIN_WATCHDOG_16);
   watchdog_transmit(0);
@@ -219,7 +222,10 @@ void serial_moredata(PicInsn *buf) {
   if (!suppress && picio_send_noise >= 2)
     ouhexi("picioh in msg", buf->d, buf->l);
   else
-    simlog_serial(buf->d, buf->l);
+    if (simlog_full || sta_state < Sta_Settling ||
+       !((pii->opcode==PICMSG_NMRADONE && obj==1) ||
+         (pii->opcode==PICMSG_PONG && obj==pong_seq)))
+      simlog_serial(buf->d, buf->l);
   
   if (!pii) { oprintf(UPO, "picio in unknown\n"); return; }
   if (!suppress)
@@ -240,8 +246,8 @@ void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   if (sta_state == Sta_Manual)
     return;
 
-  if (objnum != ping_seq)
-    die("PIC sent wrong ping response (0x%x, wanted 0x%x)", objnum, ping_seq);
+  if (objnum != pong_seq)
+    die("PIC sent wrong ping response (0x%x, wanted 0x%x)", objnum, pong_seq);
 
   ping_toev.duration= 1000;
   ping_toev.callback= timefor_ping;