From e934cfda8e112d9e741c4a57b1f1ad29bbf5b180 Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Thu, 8 Dec 2016 14:28:52 -0500 Subject: [PATCH] added switch and return functions --- g2core/config_app.cpp | 36 +++++++++++++++++++----------------- g2core/planner.cpp | 30 +++++++++++++++++++++++++----- g2core/planner.h | 4 ++++ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/g2core/config_app.cpp b/g2core/config_app.cpp index 9ddff796..ed913244 100644 --- a/g2core/config_app.cpp +++ b/g2core/config_app.cpp @@ -655,23 +655,25 @@ const cfgItem_t cfgArray[] = { { "", "gc", _f0, 0, tx_print_nul, gc_get_gc,gc_run_gc,(float *)&cs.null, 0 }, // gcode block - must be last in this group // Actions and Reports - { "", "sr", _f0, 0, sr_print_sr, sr_get, sr_set, (float *)&cs.null, 0 }, // request and set status reports - { "", "qr", _f0, 0, qr_print_qr, qr_get, set_nul, (float *)&cs.null, 0 }, // get queue value - planner buffers available - { "", "qi", _f0, 0, qr_print_qi, qi_get, set_nul, (float *)&cs.null, 0 }, // get queue value - buffers added to queue - { "", "qo", _f0, 0, qr_print_qo, qo_get, set_nul, (float *)&cs.null, 0 }, // get queue value - buffers removed from queue - { "", "er", _f0, 0, tx_print_nul, rpt_er, set_nul, (float *)&cs.null, 0 }, // get bogus exception report for testing - { "", "qf", _f0, 0, tx_print_nul, get_nul, cm_run_qf, (float *)&cs.null, 0 }, // SET to invoke queue flush - { "", "rx", _f0, 0, tx_print_int, get_rx, set_nul, (float *)&cs.null, 0 }, // get RX buffer bytes or packets - { "", "msg", _f0, 0, tx_print_str, get_nul, set_nul, (float *)&cs.null, 0 }, // string for generic messages - { "", "alarm",_f0,0, tx_print_nul, cm_alrm, cm_alrm, (float *)&cs.null, 0 }, // trigger alarm - { "", "panic",_f0,0, tx_print_nul, cm_pnic, cm_pnic, (float *)&cs.null, 0 }, // trigger panic - { "", "shutd",_f0,0, tx_print_nul, cm_shutd, cm_shutd, (float *)&cs.null, 0 }, // trigger shutdown - { "", "clear",_f0,0, tx_print_nul, cm_clr, cm_clr, (float *)&cs.null, 0 }, // GET "clear" to clear alarm state - { "", "clr", _f0,0, tx_print_nul, cm_clr, cm_clr, (float *)&cs.null, 0 }, // synonym for "clear" - { "", "tick", _f0,0, tx_print_int, get_tick, set_nul, (float *)&cs.null, 0 }, // get system time tic - { "", "tram", _f0,0, cm_print_tram, cm_get_tram, cm_set_tram, (float *)&cs.null, 0 },// SET to attempt setting rotation matrix from probes - { "", "defa",_f0, 0, tx_print_nul, help_defa, set_defaults,(float *)&cs.null,0 }, // set/print defaults / help screen - { "", "flash",_f0,0, tx_print_nul, help_flash,hw_flash, (float *)&cs.null,0 }, + { "", "sr", _f0, 0, sr_print_sr, sr_get, sr_set, (float *)&cs.null, 0 }, // request and set status reports + { "", "qr", _f0, 0, qr_print_qr, qr_get, set_nul, (float *)&cs.null, 0 }, // get queue value - planner buffers available + { "", "qi", _f0, 0, qr_print_qi, qi_get, set_nul, (float *)&cs.null, 0 }, // get queue value - buffers added to queue + { "", "qo", _f0, 0, qr_print_qo, qo_get, set_nul, (float *)&cs.null, 0 }, // get queue value - buffers removed from queue + { "", "er", _f0, 0, tx_print_nul, rpt_er, set_nul, (float *)&cs.null, 0 }, // get bogus exception report for testing + { "", "qf", _f0, 0, tx_print_nul, get_nul, cm_run_qf, (float *)&cs.null, 0 }, // SET to invoke queue flush + { "", "rx", _f0, 0, tx_print_int, get_rx, set_nul, (float *)&cs.null, 0 }, // get RX buffer bytes or packets + { "", "msg", _f0, 0, tx_print_str, get_nul, set_nul, (float *)&cs.null, 0 }, // string for generic messages + { "", "alarm",_f0,0, tx_print_nul, cm_alrm, cm_alrm, (float *)&cs.null, 0 }, // trigger alarm + { "", "panic",_f0,0, tx_print_nul, cm_pnic, cm_pnic, (float *)&cs.null, 0 }, // trigger panic + { "", "shutd",_f0,0, tx_print_nul, cm_shutd, cm_shutd, (float *)&cs.null, 0 }, // trigger shutdown + { "", "clear",_f0,0, tx_print_nul, cm_clr, cm_clr, (float *)&cs.null, 0 }, // GET "clear" to clear alarm state + { "", "clr", _f0,0, tx_print_nul, cm_clr, cm_clr, (float *)&cs.null, 0 }, // synonym for "clear" + { "", "tick", _f0,0, tx_print_int, get_tick, set_nul, (float *)&cs.null, 0 }, // get system time tic + { "", "tram", _f0,0, cm_print_tram, cm_get_tram,cm_set_tram, (float *)&cs.null, 0 },// SET to attempt setting rotation matrix from probes + { "", "defa",_f0, 0, tx_print_nul, help_defa, set_defaults,(float *)&cs.null,0 }, // set/print defaults / help screen + { "", "flash",_f0,0, tx_print_nul, help_flash,hw_flash, (float *)&cs.null,0 }, + { "", "switch",_f0,0, tx_print_nul, get_nul, mp_switch_q, (float *)&cs.null,0 }, + { "", "return",_f0,0, tx_print_nul, get_nul, mp_return_q, (float *)&cs.null,0 }, #ifdef __HELP_SCREENS { "", "help",_f0, 0, tx_print_nul, help_config, set_nul, (float *)&cs.null,0 }, // prints config help screen diff --git a/g2core/planner.cpp b/g2core/planner.cpp index 942c7ec3..eef111ac 100644 --- a/g2core/planner.cpp +++ b/g2core/planner.cpp @@ -627,6 +627,26 @@ void mp_planner_time_accounting() UPDATE_MP_DIAGNOSTICS //+++++ } +/* + * mp_switch_q() - switch planner to different quue + * mp_return_q() - return from a planner queue switch + */ +stat_t mp_switch_q(nvObj_t *nv) +{ + if ((nv->value < PRIMARY_Q) || (nv->value < SECONDARY_Q)) { + return (STAT_INPUT_VALUE_RANGE_ERROR); + } + mb.return_q = mb.active_q; + mb.active_q = (uint8_t)nv->value; + return (STAT_OK); +} + +stat_t mp_return_q(nvObj_t *nv) // if value == true return with offset corrections +{ + mb.active_q = mb.return_q; + return (STAT_OK); +} + /**** PLANNER BUFFER PRIMITIVES ************************************************************ * * Planner buffers are used to queue and operate on Gcode blocks. Each buffer contains @@ -830,16 +850,16 @@ mpBuf_t * mp_get_run_buffer() } // Note: mp_free_run_buffer() is only called from mp_exec_XXX, which are within an interrupt +// Clearing and advancing must be done atomically as other interrupts may be using the run buffer bool mp_free_run_buffer() // EMPTY current run buffer & advance to the next { mpQueue_t *q = &mb.q[mb.active_q]; - mpBuf_t *r_now = q->r; // this is to avoid a race condition when clearing the buffer - + mpBuf_t *r_now = q->r; // save this pointer is to avoid a race condition when clearing the buffer + _audit_buffers(); // ++++diagnostic audit for buffer chain integrity (only runs in DEBUG mode) - q->r = q->r->nx; // advance to next run buffer - _clear_buffer(r_now); // clear out the old buffer (& reset unlocked and set MP_BUFFER_EMPTY) - + q->r = q->r->nx; // advance to next run buffer first, + _clear_buffer(r_now); // ... then clear out the old buffer (& set MP_BUFFER_EMPTY) q->buffers_available++; qr_request_queue_report(-1); // request a QR and add to the "removed buffers" count return (q->w == q->r); // return true if the queue emptied diff --git a/g2core/planner.h b/g2core/planner.h index 42e5a274..2192bbe5 100644 --- a/g2core/planner.h +++ b/g2core/planner.h @@ -423,6 +423,7 @@ typedef struct mpQueue { // a planner buffer queue typedef struct mpBufferQueue { // one or more planner buffer queues uint8_t active_q; // index of currently active queue + uint8_t return_q; // index of queue to return to mpQueue_t q[2]; // number of queues } mpBufferQueue_t; @@ -565,6 +566,9 @@ void mp_start_feed_override(const float ramp_time, const float override); void mp_end_feed_override(const float ramp_time); void mp_planner_time_accounting(void); +stat_t mp_switch_q(nvObj_t *nv); +stat_t mp_return_q(nvObj_t *nv); + // planner buffer primitives void mp_init_buffers(void); mpBuf_t * mp_get_w(int8_t q);