Soft reset on DTR change

This commit is contained in:
Todd Fleming 2017-01-16 14:20:52 -05:00
parent e0438230b5
commit 3ebbfa4dd3
4 changed files with 29 additions and 11 deletions

View File

@ -157,7 +157,7 @@ build/%.hex : build/%.elf
.PHONY: flash
flash: build/grbl.hex
fm COM(13, 115200) DEVICE(LPC1769, 0.000000, 0) HARDWARE(BOOTEXEC, 50, 100) ERASEUSED(build\grbl.hex, PROTECTISP) HEXFILE(build\grbl.hex, NOCHECKSUMS, NOFILL, PROTECTISP)
fm COM(15, 115200) DEVICE(LPC1769, 0.000000, 0) HARDWARE(BOOTEXEC, 50, 100) ERASEUSED(build\grbl.hex, PROTECTISP) HEXFILE(build\grbl.hex, NOCHECKSUMS, NOFILL, PROTECTISP)
.PHONY: clean
clean:

View File

@ -86,6 +86,7 @@ static U8 txdata[VCOM_FIFO_SIZE];
static fifo_t txfifo;
//static fifo_t rxfifo;
static UsbSerialLineStateCallback* usbSerialLineStateCallback = nullptr;
static UsbSerialReadCallback* usbSerialReadCallback = nullptr;
// forward declaration of interrupt handler
@ -299,10 +300,13 @@ static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
break;
// set control line state
case SET_CONTROL_LINE_STATE:
// bit0 = DTR, bit = RTS
case SET_CONTROL_LINE_STATE: {
bool dtr = (pSetup->wValue >> 0) & 1;
bool rts = (pSetup->wValue >> 1) & 1;
if (usbSerialLineStateCallback)
usbSerialLineStateCallback(dtr, rts);
break;
}
default:
return FALSE;
@ -376,8 +380,9 @@ void enable_USB_interrupts(void);
main
====
**************************************************************************/
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback)
int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback)
{
::usbSerialLineStateCallback = usbSerialLineStateCallback;
::usbSerialReadCallback = usbSerialReadCallback;
// initialise stack

View File

@ -98,10 +98,13 @@ void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and ec
#include "serial_fifo.h"
// Receives line state. Called by an interrupt.
typedef void UsbSerialLineStateCallback(bool dtr, bool rts);
// Receives serial data. Called by an interrupt.
typedef void UsbSerialReadCallback(const U8* data, unsigned len);
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback); // run once in main b4 main loop starts.
int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback); // run once in main b4 main loop starts.
/*
Writes one character to VCOM port

View File

@ -49,6 +49,8 @@ void serialInterrupt(uint32_t event);
void legacy_ISR(uint8_t data);
uint8_t arm_rx_buf[1];
bool lastDtr = false;
// Returns the number of bytes available in the RX serial buffer.
uint16_t serial_get_rx_buffer_available()
{
@ -80,7 +82,15 @@ uint8_t serial_get_tx_buffer_count()
void serial_init()
{
#ifdef USE_USB
usbSerialInit([](const U8* data, unsigned len) {
usbSerialInit(
[](bool dtr, bool rts) {
if (dtr != lastDtr)
{
lastDtr = dtr;
mc_reset();
}
},
[](const U8* data, unsigned len) {
while (len--)
legacy_ISR(*data++);
});