mirror of https://github.com/rusefi/openblt.git
Refs #229. Improved the serial communication implementation in MicroBoot and SerialBoot to support FTDI based virtual COM ports.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@204 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
be16df91d0
commit
cbf012dedc
Binary file not shown.
|
@ -86,6 +86,10 @@ begin
|
|||
sciDriver.DataBits := dbEight;
|
||||
sciDriver.StopBits := sbOneStopBit;
|
||||
sciDriver.Parity.Bits := prNone;
|
||||
sciDriver.FlowControl.XonXoffOut := false;
|
||||
sciDriver.FlowControl.XonXoffIn := false;
|
||||
sciDriver.FlowControl.ControlRTS := rtsDisable;
|
||||
sciDriver.FlowControl.ControlDTR := dtrEnable;
|
||||
|
||||
// reset packet length
|
||||
packetLen := 0;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <sb_types.h> /* C types */
|
||||
#include <unistd.h> /* UNIX standard functions */
|
||||
#include <fcntl.h> /* file control definitions */
|
||||
#include <time.h> /* time definitions */
|
||||
#include <sys/time.h> /* time definitions */
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <fcntl.h> /* file control definitions */
|
||||
#include <errno.h> /* error number definitions */
|
||||
#include <termios.h> /* POSIX terminal control */
|
||||
#include <sys/ioctl.h> /* system I/O control */
|
||||
#include "xcpmaster.h" /* XCP master protocol module */
|
||||
#include "timeutil.h" /* time utility module */
|
||||
|
||||
|
@ -79,6 +80,7 @@ static sb_int32 hUart = UART_INVALID_HANDLE;
|
|||
sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
|
||||
{
|
||||
struct termios options;
|
||||
int iFlags;
|
||||
|
||||
/* open the port */
|
||||
hUart = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
|
@ -132,6 +134,9 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
|
|||
XcpTransportClose();
|
||||
return SB_FALSE;
|
||||
}
|
||||
/* turn on DTR */
|
||||
iFlags = TIOCM_DTR;
|
||||
ioctl(hUart, TIOCMBIS, &iFlags);
|
||||
/* success */
|
||||
return SB_TRUE;
|
||||
} /*** end of XcpTransportInit ***/
|
||||
|
@ -183,16 +188,21 @@ sb_uint8 XcpTransportSendPacket(sb_uint8 *data, sb_uint8 len, sb_uint16 timeOutM
|
|||
|
||||
/* read the first byte, which contains the length of the xcp packet that follows */
|
||||
bytesToRead = 1;
|
||||
uartReadDataPtr = &responsePacket.len;
|
||||
responsePacket.len = 0;
|
||||
while(bytesToRead > 0)
|
||||
{
|
||||
result = read(hUart, uartReadDataPtr, bytesToRead);
|
||||
result = read(hUart, &responsePacket.len, bytesToRead);
|
||||
if (result != -1)
|
||||
{
|
||||
bytesRead = result;
|
||||
/* update the bytes that were already read */
|
||||
uartReadDataPtr += bytesRead;
|
||||
bytesToRead -= bytesRead;
|
||||
/* one byte should be read and it should contain the packet length, which cannot be 0 */
|
||||
if ((bytesRead == bytesToRead) && (responsePacket.len > 0))
|
||||
{
|
||||
/* valid packet length received so stop this loop to continue with the reception
|
||||
* remaining packet bytes
|
||||
*/
|
||||
bytesToRead = 0;
|
||||
}
|
||||
}
|
||||
/* check for timeout if not yet done */
|
||||
if ( (bytesToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) )
|
||||
|
|
|
@ -47,9 +47,6 @@
|
|||
#define XCP_MASTER_UART_MAX_DATA ((XCP_MASTER_TX_MAX_DATA>XCP_MASTER_RX_MAX_DATA) ? \
|
||||
(XCP_MASTER_TX_MAX_DATA+1) : (XCP_MASTER_RX_MAX_DATA+1))
|
||||
|
||||
/** \brief The smallest time in millisecond that the UART is configured for. */
|
||||
#define UART_RX_TIMEOUT_MIN_MS (5)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Local data declarations
|
||||
|
@ -97,6 +94,11 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
|
|||
dcbSerialParams.ByteSize = 8;
|
||||
dcbSerialParams.StopBits = ONESTOPBIT;
|
||||
dcbSerialParams.Parity = NOPARITY;
|
||||
dcbSerialParams.fOutX = FALSE;
|
||||
dcbSerialParams.fInX = FALSE;
|
||||
dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE;
|
||||
dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
|
||||
if (!SetCommState(hUart, &dcbSerialParams))
|
||||
{
|
||||
XcpTransportClose();
|
||||
|
@ -104,11 +106,12 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
|
|||
}
|
||||
|
||||
/* set communication timeout parameters */
|
||||
timeouts.ReadIntervalTimeout = UART_RX_TIMEOUT_MIN_MS;
|
||||
timeouts.ReadTotalTimeoutConstant = UART_RX_TIMEOUT_MIN_MS;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 1;
|
||||
timeouts.WriteTotalTimeoutConstant = UART_RX_TIMEOUT_MIN_MS;
|
||||
timeouts.WriteTotalTimeoutMultiplier = 1;
|
||||
timeouts.ReadIntervalTimeout = 0;
|
||||
timeouts.ReadTotalTimeoutConstant = 0;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 100;
|
||||
timeouts.WriteTotalTimeoutConstant = 0;
|
||||
timeouts.WriteTotalTimeoutMultiplier = 100;
|
||||
|
||||
if (!SetCommTimeouts(hUart, &timeouts))
|
||||
{
|
||||
XcpTransportClose();
|
||||
|
@ -177,19 +180,24 @@ sb_uint8 XcpTransportSendPacket(sb_uint8 *data, sb_uint8 len, sb_uint16 timeOutM
|
|||
|
||||
/* ------------------------ XCP packet reception ----------------------------------- */
|
||||
/* determine timeout time */
|
||||
timeoutTime = TimeUtilGetSystemTimeMs() + timeOutMs + UART_RX_TIMEOUT_MIN_MS;
|
||||
timeoutTime = TimeUtilGetSystemTimeMs() + timeOutMs + 100;
|
||||
|
||||
/* read the first byte, which contains the length of the xcp packet that follows */
|
||||
dwToRead = 1;
|
||||
uartReadDataPtr = &responsePacket.len;
|
||||
responsePacket.len = 0;
|
||||
while(dwToRead > 0)
|
||||
{
|
||||
dwRead = 0;
|
||||
if (ReadFile(hUart, uartReadDataPtr, dwToRead, &dwRead, NULL))
|
||||
if (ReadFile(hUart, &responsePacket.len, dwToRead, &dwRead, NULL))
|
||||
{
|
||||
/* update the bytes that were already read */
|
||||
uartReadDataPtr += dwRead;
|
||||
dwToRead -= dwRead;
|
||||
/* one byte should be read and it should contain the packet length, which cannot be 0 */
|
||||
if ((dwRead == dwToRead) && (responsePacket.len > 0))
|
||||
{
|
||||
/* valid packet length received so stop this loop to continue with the reception
|
||||
* remaining packet bytes
|
||||
*/
|
||||
dwToRead = 0;
|
||||
}
|
||||
}
|
||||
/* check for timeout if not yet done */
|
||||
if ( (dwToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) )
|
||||
|
|
Binary file not shown.
|
@ -36,7 +36,7 @@
|
|||
/** \brief Minor version of the bootloader core. */
|
||||
#define BOOT_VERSION_CORE_MINOR (3u)
|
||||
/** \brief Build version of the bootloader core. */
|
||||
#define BOOT_VERSION_CORE_BUILD (0u)
|
||||
#define BOOT_VERSION_CORE_BUILD (1u)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
|
|
Loading…
Reference in New Issue