Updated for shared stream buffer for tool change protocol.

This commit is contained in:
Terje 2021-03-14 21:57:09 +01:00
parent 78d43844a9
commit 89efaf1be1
4 changed files with 18 additions and 66 deletions

View File

@ -392,12 +392,8 @@ static void enetStreamWriteS (const char *data)
.get_rx_buffer_available = TCPStreamRxFree,
.reset_read_buffer = TCPStreamRxFlush,
.cancel_read_buffer = TCPStreamRxCancel,
.enqueue_realtime_command = protocol_enqueue_realtime_command,
#if M6_ENABLE
.suspend_read = NULL // for now...
#else
.suspend_read = NULL
#endif
.suspend_read = TCPStreamSuspendInput,
.enqueue_realtime_command = protocol_enqueue_realtime_command
};
#endif
@ -410,12 +406,8 @@ static void enetStreamWriteS (const char *data)
.get_rx_buffer_available = WsStreamRxFree,
.reset_read_buffer = WsStreamRxFlush,
.cancel_read_buffer = WsStreamRxCancel,
.enqueue_realtime_command = protocol_enqueue_realtime_command,
#if M6_ENABLE
.suspend_read = NULL // for now...
#else
.suspend_read = NULL
#endif
.suspend_read = WsStreamSuspendInput,
.enqueue_realtime_command = protocol_enqueue_realtime_command
};
#endif
@ -472,7 +464,7 @@ static void (*systick_isr_org)(void) = NULL;
// Millisecond resolution delay function
// Will return immediately if a callback function is provided
static void driver_delay_ms (uint32_t ms, void (*callback)(void))
static void driver_delay_ms (uint32_t ms, delay_callback_ptr callback)
{
if(ms) {
grbl_delay.ms = ms;
@ -2086,7 +2078,7 @@ bool driver_init (void)
options[strlen(options) - 1] = '\0';
hal.info = "iMXRT1062";
hal.driver_version = "210221";
hal.driver_version = "210313";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
#endif

View File

@ -3,7 +3,7 @@
Part of grblHAL
Some parts of this code is Copyright (c) 2020 Terje Io
Some parts of this code is Copyright (c) 2020-2021 Terje Io
Some parts are derived from HardwareSerial.cpp in the Teensyduino Core Library
@ -141,7 +141,7 @@ void transmitterEnable(uint8_t pin)
static uint16_t tx_fifo_size;
static stream_tx_buffer_t txbuffer = {0};
static stream_rx_buffer_t rxbuffer = {0}, rxbackup;
static stream_rx_buffer_t rxbuffer = {0};
void serialInit (uint32_t baud_rate)
{
@ -339,20 +339,9 @@ void serialWrite(const char *s, uint16_t length)
serialPutC(*ptr++);
}
// "dummy" version of serialGetC
static int16_t serialGetNull (void)
{
return -1;
}
bool serialSuspendInput (bool suspend)
{
if(suspend)
hal.stream.read = serialGetNull;
else if(rxbuffer.backup)
memcpy(&rxbuffer, &rxbackup, sizeof(stream_rx_buffer_t));
return rxbuffer.tail != rxbuffer.head;
return stream_rx_suspend(&rxbuffer, suspend);
}
uint16_t serialTxCount(void) {
@ -413,9 +402,7 @@ static void uart_interrupt_handler (void)
rxbuffer.head = bptr; // and update pointer
#else
if(data == CMD_TOOL_ACK && !rxbuffer.backup) {
memcpy(&rxbackup, &rxbuffer, sizeof(stream_rx_buffer_t));
rxbuffer.backup = true;
rxbuffer.tail = rxbuffer.head;
stream_rx_backup(&rxbuffer);
hal.stream.read = serialGetC; // restore normal input
} else if(!hal.stream.enqueue_realtime_command((char)data)) {
rxbuffer.data[rxbuffer.head] = (char)data; // Add data to buffer

View File

@ -4,7 +4,7 @@
Part of grblHAL
Copyright (c) 2018-2020 Terje Io
Copyright (c) 2018-2021 Terje Io
Grbl is free software: you can redistribute it and/or modify
@ -38,7 +38,7 @@ extern "C" {
static stream_block_tx_buffer_t txbuf = {0};
static char rxbuf[BLOCK_RX_BUFFER_SIZE];
static stream_rx_buffer_t usb_rxbuffer, usb_rxbackup;
static stream_rx_buffer_t usb_rxbuffer;
void usb_serialInit(void)
{
@ -183,20 +183,9 @@ int16_t usb_serialGetC (void)
return (int16_t)data;
}
// "dummy" version of serialGetC
static int16_t serialGetNull (void)
{
return -1;
}
bool usb_serialSuspendInput (bool suspend)
{
if(suspend)
hal.stream.read = serialGetNull;
else if(usb_rxbuffer.backup)
memcpy(&usb_rxbuffer, &usb_rxbackup, sizeof(stream_rx_buffer_t));
return usb_rxbuffer.tail != usb_rxbuffer.head;
return stream_rx_suspend(&usb_rxbuffer, suspend);
}
//
@ -221,9 +210,7 @@ void usb_execute_realtime (uint_fast16_t state)
while(avail--) {
c = *dp++;
if(c == CMD_TOOL_ACK && !usb_rxbuffer.backup) {
memcpy(&usb_rxbackup, &usb_rxbuffer, sizeof(stream_rx_buffer_t));
usb_rxbuffer.backup = true;
usb_rxbuffer.tail = usb_rxbuffer.head;
stream_rx_backup(&usb_rxbuffer);
hal.stream.read = usb_serialGetC; // restore normal input
} else if(!hal.stream.enqueue_realtime_command(c)) {
uint32_t bptr = (usb_rxbuffer.head + 1) & (RX_BUFFER_SIZE - 1); // Get next head pointer

View File

@ -4,7 +4,7 @@
Part of grblHAL
Copyright (c) 2018-2020 Terje Io
Copyright (c) 2018-2021 Terje Io
Grbl is free software: you can redistribute it and/or modify
@ -34,7 +34,7 @@
static stream_block_tx_buffer_t txbuf = {0};
static char rxbuf[BLOCK_RX_BUFFER_SIZE];
static stream_rx_buffer_t usb_rxbuffer, usb_rxbackup;
static stream_rx_buffer_t usb_rxbuffer;
void usb_serialInit(void)
{
@ -42,7 +42,6 @@ void usb_serialInit(void)
txbuf.s = txbuf.data;
txbuf.max_length = usb_serial_write_buffer_free(); // 6144
txbuf.max_length = (txbuf.max_length > BLOCK_TX_BUFFER_SIZE ? BLOCK_TX_BUFFER_SIZE : txbuf.max_length) - 20;
}
//
@ -172,20 +171,9 @@ int16_t usb_serialGetC (void)
return (int16_t)data;
}
// "dummy" version of serialGetC
static int16_t serialGetNull (void)
{
return -1;
}
bool usb_serialSuspendInput (bool suspend)
{
if(suspend)
hal.stream.read = serialGetNull;
else if(usb_rxbuffer.backup)
memcpy(&usb_rxbuffer, &usb_rxbackup, sizeof(stream_rx_buffer_t));
return usb_rxbuffer.tail != usb_rxbuffer.head;
return stream_rx_suspend(&usb_rxbuffer, suspend);
}
//
@ -210,9 +198,7 @@ void usb_execute_realtime (uint_fast16_t state)
while(avail--) {
c = *dp++;
if(c == CMD_TOOL_ACK && !usb_rxbuffer.backup) {
memcpy(&usb_rxbackup, &usb_rxbuffer, sizeof(stream_rx_buffer_t));
usb_rxbuffer.backup = true;
usb_rxbuffer.tail = usb_rxbuffer.head;
stream_rx_backup(&usb_rxbuffer);
hal.stream.read = usb_serialGetC; // restore normal input
} else if(!hal.stream.enqueue_realtime_command(c)) {
uint32_t bptr = (usb_rxbuffer.head + 1) & (RX_BUFFER_SIZE - 1); // Get next head pointer