From 9359128df1646588ea0a0e6c89ed95e4474f382c Mon Sep 17 00:00:00 2001 From: Rainer Zaiser Date: Tue, 29 Oct 2024 07:55:34 +0100 Subject: [PATCH] Bugfix --- xcplib/src/xcpLite.c | 5 ++-- xcplib/xcptl_cfg.h | 63 +++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/xcplib/src/xcpLite.c b/xcplib/src/xcpLite.c index 977c0a9..4332de3 100644 --- a/xcplib/src/xcpLite.c +++ b/xcplib/src/xcpLite.c @@ -192,11 +192,10 @@ typedef struct { /****************************************************************************/ -/* XCP Packet */ +/* XCP Packet */ /****************************************************************************/ typedef union { - /* There might be a loss of up to 3 bytes. */ uint8_t b[((XCPTL_MAX_CTO_SIZE + 3) & 0xFFC)]; uint16_t w[((XCPTL_MAX_CTO_SIZE + 3) & 0xFFC) / 2]; uint32_t dw[((XCPTL_MAX_CTO_SIZE + 3) & 0xFFC) / 4]; @@ -1102,7 +1101,7 @@ static uint8_t XcpAsyncCommand( BOOL async, const uint32_t* cmdBuf, uint8_t cmdL uint8_t err = 0; if (!isStarted()) return CRC_GENERIC; - if (CRO_LEN > sizeof(tXcpCto)) return CRC_CMD_SYNTAX; + if (CRO_LEN > XCPTL_MAX_CTO_SIZE) return CRC_CMD_SYNTAX; // Prepare the default response CRM_CMD = PID_RES; /* Response, no error */ diff --git a/xcplib/xcptl_cfg.h b/xcplib/xcptl_cfg.h index 09a8e4a..817fbbf 100644 --- a/xcplib/xcptl_cfg.h +++ b/xcplib/xcptl_cfg.h @@ -10,45 +10,32 @@ | xcptl_cfg.h | | Description: -| Parameter configuration for XCP transport layer parameters +| Parameter configuration for XCP transport layer | | Code released into public domain, no attribution required -| ----------------------------------------------------------------------------*/ -// Transport layer -#define XCP_TRANSPORT_LAYER_VERSION 0x0104 - - #if defined(OPTION_ENABLE_UDP) #define XCPTL_ENABLE_UDP #endif - #if defined(OPTION_ENABLE_TCP) #define XCPTL_ENABLE_TCP #endif -#if defined(XCPTL_ENABLE_UDP) || defined(XCPTL_ENABLE_TCP) -// Multicast (GET_DAQ_CLOCK_MULTICAST) -// Use multicast time synchronisation to improve synchronisation of multiple XCP slaves -// This option is available since XCP V1.3, but it needs to create an additional thread and socket for multicast reception -// It has no benefit with PTP time synchronized slave and is just unnesserary effort -// Older CANapes expect this option is on by default -> turn it off in device/protocol/event/TIME_CORRELATION_GETDAQCLOCK by changing from "multicast" to "extended response" -//#define XCPTL_ENABLE_MULTICAST -#ifdef XCPTL_ENABLE_MULTICAST - //#define XCLTL_RESTRICT_MULTICAST - #define XCPTL_MULTICAST_PORT 5557 -#endif +// Transport layer version +#define XCP_TRANSPORT_LAYER_VERSION 0x0104 -#endif +// CTO size +// Maximum size of a XCP command packet (CRO,CRM) +#define XCPTL_MAX_CTO_SIZE (248) // Prefer %8=0 over the maximum value of 255 for better allignment and granularities -// Transport layer header size -// This is fixed, no other options supported -#define XCPTL_TRANSPORT_LAYER_HEADER_SIZE 4 +// DTO size +// Maximum size of a XCP data packet (DAQ,STIM) +#define XCPTL_MAX_DTO_SIZE (XCPTL_MAX_SEGMENT_SIZE-8) // Segment size - XCP transport layer header size, size must be mod 8 -// Segment size is the maximum data buffer size given to send/sendTo, for UDP it is the UDP MTU +// Segment size is the maximum data buffer size given to sockets send/sendTo, for UDP it is the UDP MTU // Jumbo frames are supported, but it might be more efficient to use a smaller segment sizes #ifdef OPTION_MTU #define XCPTL_MAX_SEGMENT_SIZE (OPTION_MTU-20-8) // UDP MTU (MTU - IP-header - UDP-header) @@ -56,13 +43,9 @@ #define XCPTL_MAX_SEGMENT_SIZE (1500-20-8) #endif -// Maximum DTO size -#define XCPTL_MAX_DTO_SIZE (XCPTL_MAX_SEGMENT_SIZE-8) // Segment size - XCP transport layer header size, size must be mod 8 - // Alignment for packet concatenation #define XCPTL_PACKET_ALIGNMENT 4 // Packet alignment for multiple XCP transport layer packets in a XCP transport layer message -// DAQ transmit queue // Transmit queue size, should at least be able to hold all data produced until the next call to HandleTransmitQueue // Size is in XCP DTO/CRM packets (not messages as in V1.x) #ifdef OPTION_QUEUE_SIZE @@ -71,16 +54,30 @@ #define XCPTL_QUEUE_SIZE (256) #endif -// Maximum queue trigger event rate + + +// Maximum queue (producer->consumer) event rate (Windows only, Linux uses polling on the consumer side) #define XCPTL_QUEUE_TRANSMIT_CYCLE_TIME (1*CLOCK_TICKS_PER_MS) // Flush cycle #define XCPTL_QUEUE_FLUSH_CYCLE_MS 100 // Send a DTO packet at least every x ms, XCPTL_TIMEOUT_INFINITE to turn off -// CTO size -// Maximum size of a XCP command -#define XCPTL_MAX_CTO_SIZE (248) -// CRO_SHORT_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-8 should be %8==0 -// CRO_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-2 +// Transport layer message header size +// This is fixed, no other options supported +#define XCPTL_TRANSPORT_LAYER_HEADER_SIZE 4 + +// Multicast (GET_DAQ_CLOCK_MULTICAST) +// Use multicast time synchronisation to improve synchronisation of multiple XCP slaves +// This option is available since XCP V1.3, but using it, needs to create an additional thread and socket for multicast reception +// There is no benefit if PTP time synchronized is used or if there is only one XCP device +// Older CANape versions expect this option is on by default -> turn it off in device/protocol/event/TIME_CORRELATION_GETDAQCLOCK by changing from "multicast" to "extended response" +//#define XCPTL_ENABLE_MULTICAST +#if defined(XCPTL_ENABLE_UDP) || defined(XCPTL_ENABLE_TCP) +#ifdef XCPTL_ENABLE_MULTICAST + //#define XCLTL_RESTRICT_MULTICAST + #define XCPTL_MULTICAST_PORT 5557 +#endif +#endif +