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:
Frank Voorburg 2017-01-20 11:45:38 +00:00
parent be16df91d0
commit cbf012dedc
7 changed files with 43 additions and 21 deletions

Binary file not shown.

View File

@ -86,6 +86,10 @@ begin
sciDriver.DataBits := dbEight; sciDriver.DataBits := dbEight;
sciDriver.StopBits := sbOneStopBit; sciDriver.StopBits := sbOneStopBit;
sciDriver.Parity.Bits := prNone; sciDriver.Parity.Bits := prNone;
sciDriver.FlowControl.XonXoffOut := false;
sciDriver.FlowControl.XonXoffIn := false;
sciDriver.FlowControl.ControlRTS := rtsDisable;
sciDriver.FlowControl.ControlDTR := dtrEnable;
// reset packet length // reset packet length
packetLen := 0; packetLen := 0;

View File

@ -33,7 +33,7 @@
#include <sb_types.h> /* C types */ #include <sb_types.h> /* C types */
#include <unistd.h> /* UNIX standard functions */ #include <unistd.h> /* UNIX standard functions */
#include <fcntl.h> /* file control definitions */ #include <fcntl.h> /* file control definitions */
#include <time.h> /* time definitions */ #include <sys/time.h> /* time definitions */
/************************************************************************************//** /************************************************************************************//**

View File

@ -37,6 +37,7 @@
#include <fcntl.h> /* file control definitions */ #include <fcntl.h> /* file control definitions */
#include <errno.h> /* error number definitions */ #include <errno.h> /* error number definitions */
#include <termios.h> /* POSIX terminal control */ #include <termios.h> /* POSIX terminal control */
#include <sys/ioctl.h> /* system I/O control */
#include "xcpmaster.h" /* XCP master protocol module */ #include "xcpmaster.h" /* XCP master protocol module */
#include "timeutil.h" /* time utility 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) sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
{ {
struct termios options; struct termios options;
int iFlags;
/* open the port */ /* open the port */
hUart = open(device, O_RDWR | O_NOCTTY | O_NDELAY); hUart = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
@ -132,6 +134,9 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
XcpTransportClose(); XcpTransportClose();
return SB_FALSE; return SB_FALSE;
} }
/* turn on DTR */
iFlags = TIOCM_DTR;
ioctl(hUart, TIOCMBIS, &iFlags);
/* success */ /* success */
return SB_TRUE; return SB_TRUE;
} /*** end of XcpTransportInit ***/ } /*** 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 */ /* read the first byte, which contains the length of the xcp packet that follows */
bytesToRead = 1; bytesToRead = 1;
uartReadDataPtr = &responsePacket.len; responsePacket.len = 0;
while(bytesToRead > 0) while(bytesToRead > 0)
{ {
result = read(hUart, uartReadDataPtr, bytesToRead); result = read(hUart, &responsePacket.len, bytesToRead);
if (result != -1) if (result != -1)
{ {
bytesRead = result; bytesRead = result;
/* update the bytes that were already read */ /* one byte should be read and it should contain the packet length, which cannot be 0 */
uartReadDataPtr += bytesRead; if ((bytesRead == bytesToRead) && (responsePacket.len > 0))
bytesToRead -= bytesRead; {
/* 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 */ /* check for timeout if not yet done */
if ( (bytesToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) ) if ( (bytesToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) )

View File

@ -47,9 +47,6 @@
#define XCP_MASTER_UART_MAX_DATA ((XCP_MASTER_TX_MAX_DATA>XCP_MASTER_RX_MAX_DATA) ? \ #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)) (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 * Local data declarations
@ -97,6 +94,11 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
dcbSerialParams.ByteSize = 8; dcbSerialParams.ByteSize = 8;
dcbSerialParams.StopBits = ONESTOPBIT; dcbSerialParams.StopBits = ONESTOPBIT;
dcbSerialParams.Parity = NOPARITY; dcbSerialParams.Parity = NOPARITY;
dcbSerialParams.fOutX = FALSE;
dcbSerialParams.fInX = FALSE;
dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE;
dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE;
if (!SetCommState(hUart, &dcbSerialParams)) if (!SetCommState(hUart, &dcbSerialParams))
{ {
XcpTransportClose(); XcpTransportClose();
@ -104,11 +106,12 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate)
} }
/* set communication timeout parameters */ /* set communication timeout parameters */
timeouts.ReadIntervalTimeout = UART_RX_TIMEOUT_MIN_MS; timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutConstant = UART_RX_TIMEOUT_MIN_MS; timeouts.ReadTotalTimeoutConstant = 0;
timeouts.ReadTotalTimeoutMultiplier = 1; timeouts.ReadTotalTimeoutMultiplier = 100;
timeouts.WriteTotalTimeoutConstant = UART_RX_TIMEOUT_MIN_MS; timeouts.WriteTotalTimeoutConstant = 0;
timeouts.WriteTotalTimeoutMultiplier = 1; timeouts.WriteTotalTimeoutMultiplier = 100;
if (!SetCommTimeouts(hUart, &timeouts)) if (!SetCommTimeouts(hUart, &timeouts))
{ {
XcpTransportClose(); XcpTransportClose();
@ -177,19 +180,24 @@ sb_uint8 XcpTransportSendPacket(sb_uint8 *data, sb_uint8 len, sb_uint16 timeOutM
/* ------------------------ XCP packet reception ----------------------------------- */ /* ------------------------ XCP packet reception ----------------------------------- */
/* determine timeout time */ /* 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 */ /* read the first byte, which contains the length of the xcp packet that follows */
dwToRead = 1; dwToRead = 1;
uartReadDataPtr = &responsePacket.len; responsePacket.len = 0;
while(dwToRead > 0) while(dwToRead > 0)
{ {
dwRead = 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 */ /* one byte should be read and it should contain the packet length, which cannot be 0 */
uartReadDataPtr += dwRead; if ((dwRead == dwToRead) && (responsePacket.len > 0))
dwToRead -= dwRead; {
/* 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 */ /* check for timeout if not yet done */
if ( (dwToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) ) if ( (dwToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) )

Binary file not shown.

View File

@ -36,7 +36,7 @@
/** \brief Minor version of the bootloader core. */ /** \brief Minor version of the bootloader core. */
#define BOOT_VERSION_CORE_MINOR (3u) #define BOOT_VERSION_CORE_MINOR (3u)
/** \brief Build version of the bootloader core. */ /** \brief Build version of the bootloader core. */
#define BOOT_VERSION_CORE_BUILD (0u) #define BOOT_VERSION_CORE_BUILD (1u)
/**************************************************************************************** /****************************************************************************************