diff --git a/afterburner.ino b/afterburner.ino index c19a23c..a219de0 100644 --- a/afterburner.ino +++ b/afterburner.ino @@ -253,12 +253,13 @@ void printHelp(char full) { // setup the Arduino board void setup() { // initialize serial: - Serial.begin(38400); + Serial.begin(57600); isUploading = 0; endOfLine = 0; echoEnabled = 0; mapUploaded = 0; typeCheck = 1; //do type check + lineIndex = 0; // Serial output from the GAL chip, input for Arduino pinMode(PIN_SDOUT, INPUT); diff --git a/src_pc/afterburner.c b/src_pc/afterburner.c index d2df72f..84e74b5 100644 --- a/src_pc/afterburner.c +++ b/src_pc/afterburner.c @@ -51,7 +51,7 @@ To compile: gcc -g3 -O0 afterburner afterburner.c #include "serial_port.h" -#define VERSION "v.0.3.1" +#define VERSION "v.0.4" #define MAX_LINE 200 @@ -466,7 +466,7 @@ static char readJedec(void) { } static int openSerial(void) { - char buf[512]; + char buf[512] = {0}; char devName[256] = {0}; int total; int labelPos; @@ -596,8 +596,13 @@ static int waitForSerialPrompt(char* buf, int bufSize, int maxDelay) { } } if (maxDelay > 0) { + /* WIN_API handles timeout itself */ +#ifndef _USE_WIN_API_ usleep(3 * 1000); maxDelay -= 3; +#else + maxDelay -= 30; +#endif } } return bufPos; diff --git a/src_pc/serial_port.h b/src_pc/serial_port.h index 4ee8358..b819dbf 100644 --- a/src_pc/serial_port.h +++ b/src_pc/serial_port.h @@ -37,18 +37,26 @@ static inline SerialDeviceHandle serialDeviceOpen(char* deviceName) { return INVALID_HANDLE; } - dcbSerialParams.BaudRate = CBR_38400; // Setting BaudRate = 38400 + dcbSerialParams.BaudRate = CBR_57600; // Setting BaudRate dcbSerialParams.ByteSize = 8; // Setting ByteSize = 8 dcbSerialParams.StopBits = ONESTOPBIT;// Setting StopBits = 1 dcbSerialParams.Parity = NOPARITY; // Setting Parity = None + dcbSerialParams.fOutxCtsFlow = FALSE; + dcbSerialParams.fOutxDsrFlow = FALSE; + dcbSerialParams.fDtrControl = DTR_CONTROL_DISABLE; + dcbSerialParams.fOutX = FALSE; + dcbSerialParams.fInX = FALSE; + dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE; + dcbSerialParams.fBinary = TRUE; + result = SetCommState(h, &dcbSerialParams); if (!result) { return INVALID_HANDLE; } - timeouts.ReadIntervalTimeout = 50; // in milliseconds - timeouts.ReadTotalTimeoutConstant = 50; // in milliseconds + timeouts.ReadIntervalTimeout = 30; // in milliseconds + timeouts.ReadTotalTimeoutConstant = 30; // in milliseconds timeouts.ReadTotalTimeoutMultiplier = 10; // in milliseconds timeouts.WriteTotalTimeoutConstant = 50; // in milliseconds timeouts.WriteTotalTimeoutMultiplier = 10; // in milliseconds @@ -57,6 +65,8 @@ static inline SerialDeviceHandle serialDeviceOpen(char* deviceName) { if (!result) { return INVALID_HANDLE; } + //ensure no leftover bytes exist on the serial line + result = PurgeComm(h, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT); return h; } else { @@ -128,8 +138,8 @@ static inline SerialDeviceHandle serialDeviceOpen(char* deviceName) { struct termios serial; memset(&serial, 0, sizeof(struct termios)); - cfsetispeed(&serial, B38400); - cfsetospeed(&serial, B38400); + cfsetispeed(&serial, B57600); + cfsetospeed(&serial, B57600); serial.c_cflag |= CS8; // no parity, 1 stop bit serial.c_cflag |= CREAD | CLOCAL;