Skip to content

Commit

Permalink
CLOCK_MONOTONIC_RAW
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Oct 27, 2024
1 parent 13153e5 commit 956cae3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 51 deletions.
69 changes: 29 additions & 40 deletions xcplib/main_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,37 @@


/*
Build options:
OPTION_ENABLE_DBG_PRINTS // Enable debug prints
OPTION_DEFAULT_DEBUG_LEVEL // Default debug level 1-5
OPTION_MTU // UDP MTU
Clock default is 1ns since 1970 epoch, free running timescale
OPTION_ARB_CLOCK // 1 us free running timescale and arbitrary epoch
OPTION_TAI_CLOCK // 1ns since 1970 clock, TAI syncronized by platform specific real time clock NTP, PTP4L, ...
PLATFORM_ENABLE_GET_LOCAL_ADDR
PLATFORM_ENABLE_KEYBOARD
XCPTL_ENABLE_TCP
XCPTL_ENABLE_UDP
xcptl_cfg.h:
XCPTL_QUEUE_SIZE // Allocate static memory for transmit queue, an entry has XCPTL_MAX_SEGMENT_SIZE bytes
XCPTL_MAX_SEGMENT_SIZE // Set to (OPTION_MTU-20-8) optimzed for the maximum possible UDP payload
xcp_cfg.h:
XCP_DAQ_MEM_SIZE // Amount of memory used for DAQ setup
CLOCK_TICKS_PER_S // Resolution of the DAQ clock
XCP library build options:
// Logging
#define OPTION_ENABLE_DBG_PRINTS Enable debug prints
#define OPTION_DEFAULT_DEBUG_LEVEL Default log level: 1 - Error, 2 - Warn, 3 - Info, 4 - Trace, 5 - Debug
// Clock
// Default is 1ns since 1970 epoch based on real time clock
#define OPTION_ARB_CLOCK 1us free running timescale and arbitrary epoch
#define OPTION_TAI_CLOCK 1ns since 1970 clock, TAI syncronized by platform specific real time clock NTP, PTP4L, ...
// XCP
#define OPTION_ENABLE_TCP
#define OPTION_ENABLE_UDP
#define OPTION_MTU UDP MTU
#define OPTION_QUEUE_SIZE Size of the DAQ queue in XCP DTO/CRM packets (not messages as in V1.x)
#define OPTION_DAQ_MEM_SIZE Size of memory for DAQ setup in bytes
*/

// Application configuration:
// XCP configuration is in xcp_cfg.h (Protocol Layer) and xcptl_cfg.h (Transport Layer)
// More specific XCP configuration is in xcp_cfg.h (Protocol Layer) and xcptl_cfg.h (Transport Layer)

// Debug prints
// Logging
#define OPTION_ENABLE_DBG_PRINTS
#define OPTION_DEFAULT_DBG_LEVEL 4 /* Default log level: 1 - Error, 2 - Warn, 3 - Info, 4 - Trace, 5 - Debug */


// Ethernet Server
// TCP or/and UDP server enabled
#define XCPTL_ENABLE_TCP
#define XCPTL_ENABLE_UDP
//#define XCP_SERVER_FORCEFULL_TERMINATION // Otherwise use gracefull server thread termination in xcplib

// Ethernet Transport Layer
#define OPTION_MTU 8000 // Ethernet MTU

#define OPTION_DEFAULT_DBG_LEVEL 4

// XCP options
#define OPTION_ENABLE_TCP
#define OPTION_ENABLE_UDP
#define OPTION_MTU 1500
#define OPTION_QUEUE_SIZE 200
#define OPTION_DAQ_MEM_SIZE (3000*5)

4 changes: 2 additions & 2 deletions xcplib/src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void mutexDestroy(MUTEX* m) {
// Sockets
/**************************************************************************/

#if defined(XCPTL_ENABLE_UDP) || defined(XCPTL_ENABLE_TCP)
#if defined(OPTION_ENABLE_TCP) || defined(OPTION_ENABLE_TCP)

#ifdef _LINUX

Expand Down Expand Up @@ -757,7 +757,7 @@ BOOL clockInit()
sClock = 0;

clock_getres(CLOCK_TYPE, &gtr);
DBG_PRINTF3("Clock resolution is %lds,%ldns!\n", gtr.tv_sec, gtr.tv_nsec);
DBG_PRINTF3("Clock resolution is %ldns!\n", gtr.tv_nsec);

#ifdef OPTION_ARB_CLOCK
clock_gettime(CLOCK_TYPE, &gts0);
Expand Down
2 changes: 1 addition & 1 deletion xcplib/src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ typedef pthread_t tXcpThread;
//-------------------------------------------------------------------------------
// Platform independant socket functions

#if defined(XCPTL_ENABLE_UDP) || defined(XCPTL_ENABLE_TCP)
#if defined(OPTION_ENABLE_TCP) || defined(OPTION_ENABLE_TCP)

#ifdef _LINUX // Linux sockets

Expand Down
13 changes: 11 additions & 2 deletions xcplib/xcp_cfg.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once
#define __XCP_CFG_H__

#ifndef __MAIN_CFG_H__
#error "Include dependency error! options not set"
#endif

/*----------------------------------------------------------------------------
| File:
| xcp_cfg.h
|
| Description:
| User configuration file for XCP protocol layer parameters
| Parameter configuration for XCP protocol layer parameters
----------------------------------------------------------------------------*/


Expand Down Expand Up @@ -112,7 +116,12 @@
// #define XCP_ENABLE_PACKED_MODE

// Static allocated memory for DAQ tables
#define XCP_DAQ_MEM_SIZE (10000*5) // Amount of memory for DAQ tables, each ODT entry (e.g. measurement variable) needs 5 bytes
// Amount of memory for DAQ tables, each ODT entry (e.g. measurement variable) needs 5 bytes
#ifdef OPTION_DAQ_MEM_SIZE
#define XCP_DAQ_MEM_SIZE OPTION_DAQ_MEM_SIZE
#else
#define XCP_DAQ_MEM_SIZE (1024*4) // Amount of memory for DAQ tables, each ODT entry (e.g. measurement variable or memory block) needs 5 bytes
#endif

// Maximum number of DAQ lists
// Numbers smaller than 256 will switch to 2 byte transport layer header DAQ_HDR_ODT_DAQB
Expand Down
36 changes: 30 additions & 6 deletions xcplib/xcptl_cfg.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once
#define __XCPTL_CFG_H__

#ifndef __MAIN_CFG_H__
#error "Include dependency error! options not set"
#endif

/*----------------------------------------------------------------------------
| File:
| xcptl_cfg.h
|
| Description:
| User configuration file for XCP transport layer parameters
| Parameter configuration for XCP transport layer parameters
|
| Code released into public domain, no attribution required
|
Expand All @@ -15,6 +19,16 @@
// 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)
Expand All @@ -34,18 +48,28 @@
// This is fixed, no other options supported
#define XCPTL_TRANSPORT_LAYER_HEADER_SIZE 4

// TL segment size and DTO size
// Segment size is the maximum data buffer size given to 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
// #define XCPTL_MAX_SEGMENT_SIZE (OPTION_MTU-20-8) // UDP MTU (MTU - IP-header - UDP-header)
#define XCPTL_MAX_SEGMENT_SIZE (7000)
#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 in segments, should at least be able to hold all data produced until the next call to HandleTransmitQueue
#define XCPTL_QUEUE_SIZE (256) // Size of the mpsc queue in XCP DTO/CRM packets (not messages as in V1.x)
// 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
#define XCPTL_QUEUE_SIZE OPTION_QUEUE_SIZE
#else
#define XCPTL_QUEUE_SIZE (256)
#endif

// Maximum queue trigger event rate
#define XCPTL_QUEUE_TRANSMIT_CYCLE_TIME (1*CLOCK_TICKS_PER_MS)
Expand Down

0 comments on commit 956cae3

Please sign in to comment.