chiark / gitweb /
wagglers as a movfeatkind
authorian <ian>
Sun, 11 May 2008 11:15:35 +0000 (11:15 +0000)
committerian <ian>
Sun, 11 May 2008 11:15:35 +0000 (11:15 +0000)
hostside/movpos.c
hostside/realtime.h
hostside/startup.c

index efac841f5ab6b1443dc13955f07f49bbb056cfa6..4b77d7c64f5b0c6fc3f2d809e8780e12eb51fee9 100644 (file)
@@ -85,6 +85,8 @@ static void motion_done(Segment *move, MovPosComb actual) {
          move->i->pname, posnpname(move, move->movposcomb));
 }
 
+static void ignore_all_abandon(Method *m) { }
+
 /*========== points and other fixed timeslot movfeats ==========*/
 
 /*
@@ -565,6 +567,91 @@ static FsqMethod points_method= {
   { .lag_ms= POINT_MOVEMENT, .slot_ms= CDU_RECHARGE, .move= point_move }
 };
 
+/*========== relays ==========*/
+
+/*
+ * Waggler states:
+ *
+ *    ____________                             conf'd
+ *   /  wagglers_ \                ready         .n
+ *   |   all_      |
+ *   |   abandon   |
+ *   |             V
+ *   |from       UNKNOWN               -1      0
+ *   |any       <=Sta_Settling
+ *  ^^^^^^^^     (start)
+ *                 |
+ *     ___________ |turning
+ *    /           \| _on
+ *   |             V
+ *   |           CHARGING              0       any
+ *   |          >=Sta_Resolving
+ *   |             |
+ *   |             |on_pic
+ *   |             |_charged
+ *   |             V
+ *   ^           READY                 1       any
+ *   |             |
+ *   |             |fsq_check_action
+ *   |             | calls point_move which fires a point
+ *    \___________/
+ *
+ */
+
+static FsqMethod waggle;
+
+static Change *waggle_allocate(Method *mm, int alloc_motions) {
+  FsqMethod *m= (void*)mm;
+  assert(m->f.ready>=0);
+  return fsq_allocate(mm, alloc_motions);
+}
+
+static void waggle_do(FsqMethod *m, const MovFeatInfo *mfi, int posn) {
+  /* actually firing points, yay! */
+  PicInsn piob;
+  enco_pic_waggle(&piob, mfi->boob[0], posn);
+  serial_transmit(&piob);
+}
+
+static void waggle_settle_check(void) {
+  SEG_IV;
+  int feat;
+  
+  FOR_SEG {
+    if (seg->movposcomb<0) continue;
+    for (feat=0; feat < seg->i->n_movfeats; feat++) {
+      const MovFeatInfo *feati= &seg->i->movfeats[feat];
+      if (feati->kind != mfk_relay) continue;
+      assert(feati->posns==2);
+      waggle.f.ready= 0;
+      waggle_do(&waggle, feati, (seg->movposcomb / feati->weight) & 1);
+      return;
+    }
+  }
+}
+
+void waggle_settle(void) {
+  waggle.f.ready= 1;
+  waggle_settle_check();
+}
+  
+void on_pic_waggled(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
+  if (sta_state < Sta_Settling) return;
+
+  waggle.f.ready= 1;
+  if (sta_state >= Sta_Resolving) { fsq_check_action(&waggle); return; }
+
+  assert(sta_state == Sta_Settling);
+  waggle_settle_check();
+}
+
+static FsqMethod relays_method= {
+  { "relay", mfk_relay,
+    waggle_allocate, fsq_reserve, fsq_confirm,
+    fsq_destroy, fsq_all_abandon },
+  { .lag_ms= 5, .slot_ms= 50, .move= waggle_do }
+};
+
 /*========== dummy `nomove' kind ==========*/
 
 static Change *nomove_allocate(Method *m, int alloc_motions) {
@@ -582,11 +669,10 @@ static ErrorCode nomove_confirm(Method *m, Change *c, Segment *move, int n,
   nomove_destroy(m,c);
   return 0;
 }
-static void nomove_all_abandon(Method *m) { }
 
 static Method nomove_method= {
   "nomove", mfk_none, nomove_allocate, nomove_reserve, nomove_confirm,
-  nomove_destroy, nomove_all_abandon
+  nomove_destroy, ignore_all_abandon
 };
 
 /*========== method-independent machinery ==========*/
@@ -594,7 +680,7 @@ static Method nomove_method= {
 static Method *methods[]= {
   &nomove_method,
   (Method*)&points_method,
-  0, /* relay */
+  (Method*)&relays_method,
   0
 };
 
index 3a573d23589d1d76471b9c6f54f19e7b7c1f3219..065f1c0da794bfdb0876388c10be6fd4b72a5864 100644 (file)
@@ -133,6 +133,8 @@ void resolve_begin(void); /* from resolve.c */
 int resolve_complete(void);
 void resolve_motioncheck(void);
 
+void waggle_settle(void); /* from movpos.c */
+
 /*---------- from/for record.c and persist.c ----------*/
 
 void records_parse(const char **argv);
index 0fdcfcb5850470686db223ddec290029d6ada5c2..de23ac0c21d5bb3a49e0e83e24d186330d244c10 100644 (file)
@@ -85,7 +85,7 @@ static void sta_goto(StartupState new_state) {
   case Sta_Off:   if (sta_state > Sta_Ping) enco_pic_off(&piob);   break;
   case Sta_Ping:                                                   break;
   case Sta_Fault:                                                  break;
-  case Sta_Settling:                        enco_pic_off(&piob);   break;
+  case Sta_Settling:   waggle_settle();     enco_pic_off(&piob);   break;
   case Sta_Resolving:
     resolve_begin();
     points_turning_on();
@@ -213,8 +213,6 @@ void on_pic_wtimeout(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
 
 void on_pic_hello(const PicInsnInfo *pii, const PicInsn *pi, int objnum)
   { abort(); }
-void on_pic_waggled(const PicInsnInfo *pii, const PicInsn *pi, int objnum)
-  { abort(); }
 void on_pic_aaargh(const PicInsnInfo *pii, const PicInsn *pi, int objnum)
   { abort(); }
 void on_pic_spurious(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {