#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;
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;
/*---------- for/from simulate.c ----------*/
-const char *simulate;
void serial_indata_process(int buf_used);
void sim_initialise(const char *logduplicate);
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 ----------*/
/*---------- 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_ */
/*---------- 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);
}
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);
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) {
}
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);
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)
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;