Merge pull request #226 from synthetos/dev-225-flush-and-clear

Work on issue #225 - queue flush and clear handling
This commit is contained in:
Rob Giseburt
2017-01-24 10:08:26 -06:00
committed by GitHub
8 changed files with 427 additions and 199 deletions
+1 -1
Submodule Motate updated: cae12cb4ba...b68d34bf0f
+1
View File
@@ -823,6 +823,7 @@ void cm_clear()
{
if (cm.machine_state == MACHINE_ALARM) {
cm.machine_state = MACHINE_PROGRAM_STOP;
xio_flush_to_command();
} else if (cm.machine_state == MACHINE_SHUTDOWN) {
cm.machine_state = MACHINE_READY;
}
+1 -1
View File
@@ -236,7 +236,7 @@ static void _dispatch_kernel(const devflags_t flags)
// trap single character commands
if (*cs.bufp == '!') { cm_request_feedhold(); }
else if (*cs.bufp == '%') { cm_request_queue_flush(); }
else if (*cs.bufp == '%') { cm_request_queue_flush(); xio_flush_to_command(); }
else if (*cs.bufp == '~') { cm_request_end_hold(); }
else if (*cs.bufp == EOT) { cm_alarm(STAT_KILL_JOB, "EOT Received"); }
else if (*cs.bufp == ENQ) { controller_request_enquiry(); }
+14 -14
View File
@@ -34,21 +34,21 @@
//+++++ DIAGNOSTICS
#if IN_DEBUGGER < 1
//#if IN_DEBUGGER < 1
#define LOG_RETURN(msg) // LOG_RETURN with no action (production)
#else
#include "xio.h"
static char logbuf[128];
static void _logger(const char *msg, const mpBuf_t *bf) // LOG_RETURN with full state dump
{
sprintf(logbuf, "[%2d] %s (%d) mt:%5.2f, L:%1.3f [%1.3f, %1.3f, %1.3f] V:[%1.2f, %1.2f, %1.2f]\n",
bf->buffer_number, msg, bf->hint, (bf->block_time * 60000),
bf->length, bf->head_length, bf->body_length, bf->tail_length,
bf->pv->exit_velocity, bf->cruise_velocity, bf->exit_velocity);
xio_writeline(logbuf);
}
#define LOG_RETURN(msg) { _logger(msg, bf); }
#endif
//#else
//#include "xio.h"
//static char logbuf[128];
//static void _logger(const char *msg, const mpBuf_t *bf) // LOG_RETURN with full state dump
//{
// sprintf(logbuf, "[%2d] %s (%d) mt:%5.2f, L:%1.3f [%1.3f, %1.3f, %1.3f] V:[%1.2f, %1.2f, %1.2f]\n",
// bf->buffer_number, msg, bf->hint, (bf->block_time * 60000),
// bf->length, bf->head_length, bf->body_length, bf->tail_length,
// bf->pv->exit_velocity, bf->cruise_velocity, bf->exit_velocity);
// xio_writeline(logbuf);
//}
//#define LOG_RETURN(msg) { _logger(msg, bf); }
//#endif
#if IN_DEBUGGER < 1
#define TRAP_ZERO(t,m)
+1 -1
View File
@@ -56,7 +56,7 @@
// Communications and reporting settings
#define USB_SERIAL_PORTS_EXPOSED 2 // Valid options are 1 or 2, only!
#define USB_SERIAL_PORTS_EXPOSED 1 // Valid options are 1 or 2, only!
#define COMM_MODE JSON_MODE // one of: TEXT_MODE, JSON_MODE
#define XIO_ENABLE_FLOW_CONTROL FLOW_CONTROL_RTS // FLOW_CONTROL_OFF, FLOW_CONTROL_RTS
+14 -13
View File
@@ -76,7 +76,7 @@ extern OutputPin<kDebug3_PinNumber> debug_pin3;
//extern OutputPin<kDebug4_PinNumber> debug_pin4;
dda_timer_type dda_timer {kTimerUpToMatch, FREQUENCY_DDA}; // stepper pulse generation
load_timer_type load_timer; // triggers load of next stepper segment
//load_timer_type load_timer; // triggers load of next stepper segment
exec_timer_type exec_timer; // triggers calculation of next+1 stepper segment
fwd_plan_timer_type fwd_plan_timer; // triggers planning of next block
@@ -126,7 +126,7 @@ void stepper_init()
dda_timer.setInterrupts(kInterruptOnOverflow | kInterruptPriorityHighest);
// setup software interrupt load timer
load_timer.setInterrupts(kInterruptOnSoftwareTrigger | kInterruptPriorityHigh);
// load_timer.setInterrupts(kInterruptOnSoftwareTrigger | kInterruptPriorityHigh);
// setup software interrupt exec timer & initial condition
exec_timer.setInterrupts(kInterruptOnSoftwareTrigger | kInterruptPriorityMedium);
@@ -417,20 +417,21 @@ void st_request_load_move()
stepper_debug("l");
if (st_pre.buffer_state == PREP_BUFFER_OWNED_BY_LOADER) { // bother interrupting
stepper_debug("_");
load_timer.setInterruptPending();
// load_timer.setInterruptPending();
_load_move();
}
}
namespace Motate { // Define timer inside Motate namespace
template<>
void load_timer_type::interrupt()
{
load_timer.getInterruptCause(); // read SR to clear interrupt condition
stepper_debug("L>");
_load_move();
stepper_debug("L+\n");
}
} // namespace Motate
//namespace Motate { // Define timer inside Motate namespace
// template<>
// void load_timer_type::interrupt()
// {
// load_timer.getInterruptCause(); // read SR to clear interrupt condition
// stepper_debug("L>");
// _load_move();
// stepper_debug("L+\n");
// }
//} // namespace Motate
/****************************************************************************************
* _load_move() - Dequeue move and load into stepper runtime structure
+325 -167
View File
File diff suppressed because it is too large Load Diff
+70 -2
View File
@@ -49,7 +49,8 @@
#define XIO_H_ONCE
//#include "g2core.h" // not required if used in g2core project
#include "config.h" // required for nvObj typedef
#include "config.h" // required for nvObj typedef
#include "canonical_machine.h" // needed for cm_has_hold()
/**** Defines, Macros, and Assorted Parameters ****/
@@ -97,6 +98,7 @@ enum xioDeviceEnum { // reconfigure this enum as you add
DEV_USB1, // must be 1
DEV_UART1, // must be 2
// DEV_SPI0, // We can't have it here until we actually define it
DEV_FLASH_FILE, // must be 0
DEV_MAX
};
@@ -106,7 +108,7 @@ enum xioSPIMode {
};
/**** readline stuff -- TODO *****/
/**** readline stuff *****/
#define RX_BUFFER_MIN_SIZE 256 // minimum requested buffer size (they are usually larger)
@@ -119,6 +121,7 @@ size_t xio_write(const char *buffer, size_t size, bool only_to_muted = false);
char *xio_readline(devflags_t &flags, uint16_t &size);
int16_t xio_writeline(const char *buffer, bool only_to_muted = false);
bool xio_connected();
void xio_flush_to_command();
stat_t xio_set_spi(nvObj_t *nv);
@@ -160,6 +163,71 @@ extern "C" {
#define CHAR_QUEUE_FLUSH (char)'%'
//#define CHAR_BOOTLOADER ESC
/**** xio_flash_file - object to hold in-flash (compiled-in) "files" to run ****/
struct xio_flash_file {
const char * const _data;
const int32_t _length;
int32_t _read_offset = 0;
xio_flash_file(const char * const data, int32_t length) : _data{data}, _length{length} {};
void reset() {
_read_offset = 0;
};
const char *readline(bool control_only, uint16_t &line_size) {
line_size = 0;
if (_read_offset == _length) { return nullptr; }
if (control_only) {
char c = _data[_read_offset];
if (!
((c == '!') ||
(c == '~') ||
(c == ENQ) || // request ENQ/ack
(c == CHAR_RESET) || // ^X - reset (aka cancel, terminate)
(c == CHAR_ALARM) || // ^D - request job kill (end of transmission)
(c == '%' && cm_has_hold()) // flush (only in feedhold or part of control header)
))
{
return nullptr;
}
}
const char *line_start = _data + _read_offset;
while (_read_offset < _length) {
char c = _data[_read_offset++];
if (c == '\n') {
break;
}
line_size++;
}
return line_start;
};
bool isDone() {
return _read_offset == _length;
}
};
/**** convenience function to construct a xio_flash_file ****/
template <int32_t length>
constexpr xio_flash_file make_xio_flash_file(const char (&data)[length]) {
return {data, length};
}
/**** function prototype for file-sending ****/
bool xio_send_file(xio_flash_file &file);
#ifdef __TEXT_MODE
void xio_print_spi(nvObj_t *nv);