Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Oct 29, 2024
1 parent d5b969e commit 9359128
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
5 changes: 2 additions & 3 deletions xcplib/src/xcpLite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 */
Expand Down
63 changes: 30 additions & 33 deletions xcplib/xcptl_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,42 @@
| 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)
#else
#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
Expand All @@ -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

0 comments on commit 9359128

Please sign in to comment.