From 438b2276d6fb6127528e40137337b2cb8e95600e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 30 Dec 2010 13:15:28 +0000 Subject: [PATCH] movpos: wip multiple movfeatkinds: tidying up, before add lots of DPRINTFs --- hostside/movpos.c | 103 ++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/hostside/movpos.c b/hostside/movpos.c index fc09eb3..7cfa07e 100644 --- a/hostside/movpos.c +++ b/hostside/movpos.c @@ -20,7 +20,7 @@ typedef struct Method Method; */ /* * The following states exist for each Method - * I Initialising corresponds to global states other than Sta_Run + * S Starting corresponds to global states other than Sta_Run * T Tentative changes have been made but may yet be undone * Y Yes proposed changes have been checked and are OK * E Executing the method is executing @@ -70,7 +70,7 @@ struct Method { ErrorCode (*check)(Method *m); /* TYE->Y; err: TYE->TYE */ void (*execute)(Method *m); /* EY->E */ - void (*all_abandon)(Method *m); /* I */ + void (*all_abandon)(Method *m); /* TYE->S */ }; /*========== general utility functions ==========*/ @@ -122,41 +122,15 @@ static void ignore_all_abandon(Method *m) { } typedef unsigned FsqSlot; typedef int FsqSlotSigned; -/* We think there are three states: Allocated, Reserved and Confirmed. - * (plus of course Unallocated where we don't have a request at all). - * These correspond to the indep code as follows: - * - * indep state pt state queues checked and plan viable - * Unallocated n/a yes - * Allocated Allocated yes - * Reserved Reserved yes - * Confirmed Confirmed yes - * Erroneous A/R/C no - * - * Erroneous exists only after a failed reserve() or confirm() so it's - * not that confusing to have this slightly malleable terminology. - */ - #define FSQDN (~(FsqSlot)0) -typedef struct { /* PR QR PC QC */ - /* in queue? absent reserved absent confirmed */ - Change h; - FsqSlot deadline; /* relative relative absolute absolute */ - int n_motions; /* 1 1 alloc'd num undone */ - Motion motions[]; - /* [0].i: 0 0 non-0 non-0 */ - /* .posn: undef undef defined defined */ +typedef struct { /* state Prep Resv Inst Resv Prep Conf Inst Conf */ + Change h; /* in queue? absent reserved absent confirmed */ + FsqSlot deadline; /* relative relative absolute absolute */ + int n_motions; /* 1 1 num undone num undone */ + Motion motions[]; /* [0].i: 0 0 non-0 non-0 */ + /* .posn: undef undef defined defined */ } FsqReq; - /* We can determine the the state by looking at the two - * `statedet' fields, marked <- above. - * There are also intermediate states where the req's - * statedet fields do not agree with the queue it's on. - * We write these as, for example, - * AR to mean statedet says Allocated, but queued on fsq_reserved - * A? to mean statedet says Allocated, but may be queued - * etc. They are only allowed while we are in a fsq_... method function. - */ #define FSQ_MAX_QUEUE 15 @@ -303,13 +277,13 @@ static void fsq_item_debug(FsqMethod *m, FsqReq *r, } } -static ErrorCode fsq_enqueue(FsqMethod *m, FsqReq *r) { /* P->Q; err: P->P */ +static ErrorCode fsq_enqueue(FsqMethod *m, FsqReq *r) { /* P->I; err: P->P */ if (!r) return 0; fsq_item_debug(m,r,"enqueue:",r->h.indep.move); return fsq_queue_insert_item(fsq_item_queue(m,r), r); } -static void fsq_dequeue(FsqMethod *m, FsqReq *r) { /* Q->P */ +static void fsq_dequeue(FsqMethod *m, FsqReq *r) { /* I->P */ if (!r) return 0; fsq_item_debug(m,r,"dequeue:",r->h.indep.move); fsq_remove_item(fsq_item_queue(m,r), r); @@ -409,7 +383,7 @@ static void fsq_check_action(FsqMethod *m) { if (!r->n_motions) { fsq_queue_remove_index(&m->f.confirmed, 0); - indep_change_done(&m->m, &r->h); + method_change_done(&m->m, &r->h); m->h.dispose(&m->m, &r->h); ec= fsq_check_plan(m); assert(!ec); @@ -489,7 +463,8 @@ void on_pic_charged(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { static FsqMethod points_method= { { "point", mfk_point, - point_prepare, fsq_consider, fsq_dispose, + point_prepare, fsq_dispose, + fsq_install, fsq_remove, fsq_check, fsq_execute, points_all_abandon }, { .lag_ms= POINT_MOVEMENT, .slot_ms= CDU_RECHARGE, .move= point_move } }; @@ -567,7 +542,7 @@ 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) { waggle.f.ready= 1; @@ -581,7 +556,8 @@ void on_pic_waggled(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { static FsqMethod waggle= { { "relay", mfk_relay, - fsq_prepare, fsq_consider, fsq_dispose, + fsq_prepare, fsq_dispose, + fsq_install, fsq_remove, fsq_check, fsq_execute, ignore_all_abandon }, { .lag_ms= 5, .slot_ms= 50, .move= waggle_do } }; @@ -995,11 +971,11 @@ ErrorCode movpos_change(Segment *move, MovPosComb target, } DPRINTF(movpos,change, "%s/%s maxdelay=%dms actual=%s\n", - move->i->pname, movpos_pname(move,target), + move->i->pname, movpos_pname(move, target), maxdelay_ms, movpos_pname(move, actual)); - if (resv) DPRINTF(movpos,change, " chg=%s:%s/%s\n", - chg->meth->pname, chg->move->i->pname, - movpos_pname(chg->move, chg->intent)); + if (resv) DPRINTF(movpos,change, " resv=%s:%s/%s\n", + resv->meth->pname, resv->move->i->pname, + movpos_pname(resv->move, resv->target)); MovPosChange *inst= 0; @@ -1020,6 +996,10 @@ ErrorCode movpos_change(Segment *move, MovPosComb target, move->motion= inst; indep_check_execute(); + + DPRINTF(movpos,change, "%s/%s maxdelay=%dms ok\n", + move->i->pname, movpos_pname(move, target), + maxdelay_ms); return 0; x: @@ -1028,6 +1008,10 @@ ErrorCode movpos_change(Segment *move, MovPosComb target, ec= indep_install(move->motion, 0); assert(!ec); ec= indep_install(resv, 0); assert(!ec); indep_check_execute(); + + DPRINTF(movpos,change, "%s/%s maxdelay=%dms err=%s\n", + move->i->pname, movpos_pname(move, target), + maxdelay_ms, ec2str(ec)); return ec; } @@ -1047,6 +1031,16 @@ MovPosComb movpos_change_intent(MovPosChange *indep) { void motions_all_abandon(void) { Method **meth; + SEG_IV + FOR_SEG { + if (!seg->moving) continue; + + MovPosChange *abandon= seg->motion; + indep_remove(abandon); + indep_dispose(abandon); + seg->movposcomb= abandon->actual; + seg->moving= 0; + } for (meth=methods; *meth; meth++) (*meth)->all_abandon(*meth); } @@ -1057,8 +1051,7 @@ void motions_all_abandon(void) { - STUFF BEYOND HERE IS FUNCTIONALITY WHICH NEEDS MOVING TO INDEP - AND/OR CHECKING THAT WE STILL HAVE IT + STUFF BEYOND HERE IS JUST KEPT FOR GETTING DPRINTFS OUT OF static ErrorCode fsq_confirm(Method *mm, Change *chg, Segment *move, @@ -1161,24 +1154,6 @@ static ErrorCode fsq_confirm(Method *mm, Change *chg, Segment *move, - r->actual= movposcomb_update_feature(r->actual,mo->i,mo->posn); - if (r->h.actual >= 0 || !r->n_motions) - r->h.actual= r->actual; - ouposn_moving(&r->h); - - - - - /* look for something to report - * we can get things here other than from the above - * eg if we are asked to move the - */ - Segment *move= r->h.move; - assert(move->moving && move->motion == (Change*)r); - fsq_mark_as_allocated(r); /* now state A aka Done */ - motion_done(move,r->h.actual); - free(r); - /*---------- entrypoints from rest of program ----------*/ static void fsq_all_abandon(Method *mm) { -- 2.30.2