From 83b343d67c0c2bf5e90c4e7b2dbbef567a0b3b34 Mon Sep 17 00:00:00 2001 From: Rainer Zaiser Date: Thu, 12 Sep 2024 21:20:40 +0200 Subject: [PATCH] Sync with xcp-lite --- CPP_Demo/CPP_Demo.a2l | 19 +++--- CPP_Demo/build.sh | 6 ++ CPP_Demo/main.cpp | 2 +- CPP_Demo/main_cfg.h | 27 ++++---- CPP_Demo/main_cfg.h.in | 39 ----------- CPP_Demo/xcpAppl.c | 11 ++-- CPP_Demo/xcp_cfg.h | 12 +++- C_Demo/C_Demo.a2l | 146 +++++++++++++++++++++++++++++++++++++++++ C_Demo/build.sh | 6 ++ C_Demo/ecu.c | 3 +- C_Demo/main.c | 2 +- C_Demo/main_cfg.h | 38 ++++++----- C_Demo/main_cfg.h.in | 44 ------------- C_Demo/xcp_cfg.h | 12 +++- README.md | 17 ++++- XCPlib/main_cfg.h | 26 ++++---- XCPlib/xcpAppl.c | 12 ++-- XCPlib/xcp_cfg.h | 10 ++- XCPlite/XCPlite.a2l | 98 +++++++++++++++++++++++++++ XCPlite/build.sh | 6 ++ XCPlite/main.c | 6 +- XCPlite/main.h | 79 ---------------------- XCPlite/main_cfg.h | 35 ++++++---- XCPlite/xcp_cfg.h | 1 + src/A2L.c | 4 +- src/dbg_print.h | 13 +++- src/main.h | 1 + src/options.c | 8 ++- src/xcp.cpp | 9 ++- src/xcp.hpp | 5 +- src/xcpAppl.c | 24 ++++--- src/xcpCanServer.c | 1 + 32 files changed, 452 insertions(+), 270 deletions(-) create mode 100755 CPP_Demo/build.sh delete mode 100644 CPP_Demo/main_cfg.h.in create mode 100644 C_Demo/C_Demo.a2l create mode 100755 C_Demo/build.sh delete mode 100644 C_Demo/main_cfg.h.in create mode 100644 XCPlite/XCPlite.a2l create mode 100755 XCPlite/build.sh delete mode 100644 XCPlite/main.h diff --git a/CPP_Demo/CPP_Demo.a2l b/CPP_Demo/CPP_Demo.a2l index 134fd37..404bae9 100644 --- a/CPP_Demo/CPP_Demo.a2l +++ b/CPP_Demo/CPP_Demo.a2l @@ -51,14 +51,14 @@ ALIGNMENT_INT64 1 /begin STRUCTURE_COMPONENT offset C_FLOAT64_IEEE 0x8 SYMBOL_TYPE_LINK "offset" /end STRUCTURE_COMPONENT /begin STRUCTURE_COMPONENT phase C_FLOAT64_IEEE 0x10 SYMBOL_TYPE_LINK "phase" /end STRUCTURE_COMPONENT /end TYPEDEF_STRUCTURE -/begin INSTANCE gSignalParameters "This is the global signal parameters structure instance" sSignalParameters 0x400C0 /end INSTANCE -/begin CHARACTERISTIC gPeriod "Period of sinus signal in s" VALUE 0x400D8 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 10 PHYS_UNIT "s" SYMBOL_LINK "gPeriod" 0 /end CHARACTERISTIC -/begin CHARACTERISTIC gCycleTime "Cycle time of demo event loop in us" VALUE 0x400BC R_ULONG 0 NO_COMPU_METHOD 0 1e+06 PHYS_UNIT "us" SYMBOL_LINK "gCycleTime" 0 /end CHARACTERISTIC -/begin CHARACTERISTIC gDebugLevel "Console output verbosity level" VALUE 0x400B8 R_ULONG 0 NO_COMPU_METHOD 0 4294967295 SYMBOL_LINK "gDebugLevel" 0 /end CHARACTERISTIC +/begin INSTANCE gSignalParameters "This is the global signal parameters structure instance" sSignalParameters 0x2F58000 /end INSTANCE +/begin CHARACTERISTIC gPeriod "Period of sinus signal in s" VALUE 0x2F58018 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 10 PHYS_UNIT "s" SYMBOL_LINK "gPeriod" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC gCycleTime "Cycle time of demo event loop in us" VALUE 0x2F58020 R_SLONG 0 NO_COMPU_METHOD 0 1e+06 PHYS_UNIT "us" SYMBOL_LINK "gCycleTime" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC gDebugLevel "Console output verbosity level" VALUE 0x2F58024 R_SBYTE 0 NO_COMPU_METHOD -128 127 SYMBOL_LINK "gDebugLevel" 0 /end CHARACTERISTIC /begin COMPU_METHOD gChannel1.Conversion "" LINEAR "%6.3" "V" COEFFS_LINEAR 1 0 /end COMPU_METHOD -/begin MEASUREMENT gChannel1 "Sinus signal as double with physical conversion rule" FLOAT64_IEEE gChannel1.Conversion 0 0 -1000000000000.0000 1000000000000.00000 ECU_ADDRESS 0x598F0 PHYS_UNIT "V" READ_WRITE SYMBOL_LINK "gChannel1" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin MEASUREMENT gChannel1 "Sinus signal as double with physical conversion rule" FLOAT64_IEEE gChannel1.Conversion 0 0 -1000000000000.0000 1000000000000.00000 ECU_ADDRESS 0x2F58038 PHYS_UNIT "V" READ_WRITE SYMBOL_LINK "gChannel1" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT /begin COMPU_METHOD gCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD -/begin MEASUREMENT gCounter "Event counter as uint32" UWORD gCounter.Conversion 0 0 0.000000 65535.000000 ECU_ADDRESS 0x598F8 READ_WRITE SYMBOL_LINK "gCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin MEASUREMENT gCounter "Event counter as uint32" SWORD gCounter.Conversion 0 0 -32768.000000 32767.000000 ECU_ADDRESS 0x2F58040 READ_WRITE SYMBOL_LINK "gCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT /begin INSTANCE SigGen1 "" SigGen 0x10000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x1 /end DAQ_EVENT /end IF_DATA /end INSTANCE /begin INSTANCE SigGen2 "" SigGen 0x20000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x2 /end DAQ_EVENT /end IF_DATA /end INSTANCE /begin INSTANCE SigGen3 "" SigGen 0x30000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x3 /end DAQ_EVENT /end IF_DATA /end INSTANCE @@ -70,7 +70,7 @@ ALIGNMENT_INT64 1 /begin INSTANCE SigGen9 "" SigGen 0x90000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x9 /end DAQ_EVENT /end IF_DATA /end INSTANCE /begin INSTANCE SigGen10 "" SigGen 0xA0000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0xA /end DAQ_EVENT /end IF_DATA /end INSTANCE /begin TYPEDEF_STRUCTURE SigGen "" 0x48 SYMBOL_TYPE_LINK "SigGen" - /begin STRUCTURE_COMPONENT xcpInstanceId M_UWORD 0x14 SYMBOL_TYPE_LINK "xcpInstanceId" /end STRUCTURE_COMPONENT + /begin STRUCTURE_COMPONENT xcpInstanceId M_SWORD 0x14 SYMBOL_TYPE_LINK "xcpInstanceId" /end STRUCTURE_COMPONENT /begin STRUCTURE_COMPONENT value M_FLOAT64_IEEE 0x38 SYMBOL_TYPE_LINK "value" /end STRUCTURE_COMPONENT /begin STRUCTURE_COMPONENT par_ampl C_FLOAT64_IEEE 0x20 SYMBOL_TYPE_LINK "par_ampl" /end STRUCTURE_COMPONENT /begin STRUCTURE_COMPONENT par_phase C_FLOAT64_IEEE 0x28 SYMBOL_TYPE_LINK "par_phase" /end STRUCTURE_COMPONENT @@ -79,7 +79,7 @@ ALIGNMENT_INT64 1 /begin IF_DATA XCP /begin PROTOCOL_LAYER - 0x0103 1000 2000 0 0 0 0 0 252 1024 BYTE_ORDER_MSB_LAST ADDRESS_GRANULARITY_BYTE + 0x0103 1000 2000 0 0 0 0 0 248 1468 BYTE_ORDER_MSB_LAST ADDRESS_GRANULARITY_BYTE OPTIONAL_CMD GET_COMM_MODE_INFO OPTIONAL_CMD GET_ID OPTIONAL_CMD SET_MTA @@ -87,6 +87,9 @@ OPTIONAL_CMD UPLOAD OPTIONAL_CMD SHORT_UPLOAD OPTIONAL_CMD DOWNLOAD OPTIONAL_CMD SHORT_DOWNLOAD +OPTIONAL_CMD GET_CAL_PAGE +OPTIONAL_CMD SET_CAL_PAGE +OPTIONAL_CMD BUILD_CHECKSUM OPTIONAL_CMD GET_DAQ_RESOLUTION_INFO OPTIONAL_CMD GET_DAQ_PROCESSOR_INFO OPTIONAL_CMD FREE_DAQ diff --git a/CPP_Demo/build.sh b/CPP_Demo/build.sh new file mode 100755 index 0000000..2b02bca --- /dev/null +++ b/CPP_Demo/build.sh @@ -0,0 +1,6 @@ + +cmake -DCMAKE_BUILD_TYPE=Release -S . -B build +cd build +make +cd .. + diff --git a/CPP_Demo/main.cpp b/CPP_Demo/main.cpp index 632880b..5bbedeb 100644 --- a/CPP_Demo/main.cpp +++ b/CPP_Demo/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char* argv[]) { // XCP singleton Xcp* xcp = Xcp::getInstance(); - if (!xcp->init(gOptionBindAddr, gOptionPort, gOptionUseTCP, FALSE, XCPTL_MAX_SEGMENT_SIZE)) return -1; + if (!xcp->init(gOptionBindAddr, gOptionPort, gOptionUseTCP, FALSE)) return -1; // Create a measurement event // Must be defined before A2L generation diff --git a/CPP_Demo/main_cfg.h b/CPP_Demo/main_cfg.h index 1dadbcc..8490ac9 100644 --- a/CPP_Demo/main_cfg.h +++ b/CPP_Demo/main_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __MAIN_CFG_H__ // main_cfg.h // CPP_Demo @@ -9,16 +10,22 @@ // Application configuration: // XCP configuration is in xcp_cfg.h (Protocol Layer) and xcptl_cfg.h (Transport Layer) - #define ON 1 #define OFF 0 +// Set clock resolution (for clock function in platform.c) +#define CLOCK_USE_APP_TIME_US +//#define CLOCK_USE_UTC_TIME_NS -// Debug prints -#define OPTION_ENABLE_DBG_PRINTS ON -#define OPTION_DEBUG_LEVEL 2 -#define OPTION_UDP_DEBUG_LEVEL 0 +// Platform options +#define PLATFORM_ENABLE_GET_LOCAL_ADDR +#define PLATFORM_ENABLE_KEYBOARD +// 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 // Enable C++ class wrapper #define OPTION_ENABLE_XCP_CLASS ON @@ -26,7 +33,6 @@ // Enable demo how to measure dynamic instances #define OPTION_ENABLE_DYNAMIC_DEMO ON - // A2L generation #define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation #if OPTION_ENABLE_A2L_GEN @@ -34,15 +40,12 @@ #define OPTION_A2L_FILE_NAME "CPP_Demo.a2l" // A2L filename #endif - -// Set clock resolution (for clock function in platform.c) -#define CLOCK_USE_APP_TIME_US -//#define CLOCK_USE_UTC_TIME_NS - - // Ethernet Transport Layer #define OPTION_USE_TCP OFF #define OPTION_MTU 1500 // Ethernet MTU #define OPTION_SERVER_PORT 5555 // Default UDP port #define OPTION_SERVER_ADDR {127,0,0,1} // IP addr to bind, 0.0.0.0 = ANY +// Debug prints +#define OPTION_ENABLE_DBG_PRINTS ON +#define OPTION_DEBUG_LEVEL 3 // 1 - Error, 2 - Warn, 3 - Info, 4 - Trace, 5 - Debug diff --git a/CPP_Demo/main_cfg.h.in b/CPP_Demo/main_cfg.h.in deleted file mode 100644 index 4a3f597..0000000 --- a/CPP_Demo/main_cfg.h.in +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -// main_cfg.h -// CPP_Demo - -/* Copyright(c) Vector Informatik GmbH.All rights reserved. - Licensed under the MIT license.See LICENSE file in the project root for details. */ - -#define APP_CPP_Demo - -#define APP_NAME "CPP_Demo" -#define APP_VERSION_MAJOR @CPP_Demo_VERSION_MAJOR@ -#define APP_VERSION_MINOR @CPP_Demo_VERSION_MINOR@ - -//----------------------------------------------------------------------------------------------------- -// Application configuration: -// XCP configuration is in xcp_cfg.h (Protocol Layer) and xcptl_cfg.h (Transport Layer) - -#define ON 1 -#define OFF 0 - -#define OPTION_DEBUG_LEVEL @OPTION_DEBUG_LEVEL@ - -// A2L generation -#define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation -#if OPTION_ENABLE_A2L_GEN -#define OPTION_ENABLE_A2L_SYMBOL_LINKS ON // Enable generation of symbol links (required for CANape integrated linker map update) -#define OPTION_A2L_NAME "CPP_Demo" // A2L name -#define OPTION_A2L_FILE_NAME "CPP_Demo.a2l" // A2L filename -#define OPTION_A2L_PROJECT_NAME "CPP_Demo" // A2L project name -#endif - -// Default communication parameters -#define OPTION_ENABLE_TCP @OPTION_ENABLE_TCP@ // Enable TCP support -#define OPTION_USE_TCP @OPTION_USE_TCP@ // Default -#define OPTION_MTU @OPTION_MTU@ // Ethernet MTU -#define OPTION_SERVER_PORT @OPTION_SERVER_PORT@ // Default UDP port, overwritten by commandline option -port -#define OPTION_SERVER_ADDR @OPTION_SERVER_ADDR@ // Default IP addr to bind, 0.0.0.0 = ANY, overwritten by commandline option -bind x.x.x.x - diff --git a/CPP_Demo/xcpAppl.c b/CPP_Demo/xcpAppl.c index cc89bd7..73db15a 100644 --- a/CPP_Demo/xcpAppl.c +++ b/CPP_Demo/xcpAppl.c @@ -13,9 +13,7 @@ ----------------------------------------------------------------------------*/ #include "main.h" -#include "main_cfg.h" #include "../src/platform.h" -#include "../src/util.h" #include "../src/xcp.h" #include "../src/xcp.hpp" @@ -39,6 +37,11 @@ BOOL ApplXcpConnect() { return Xcp::getInstance()->onConnect(); } +void ApplXcpDisconnect() { + Xcp::getInstance()->onDisconnect(); +} + + BOOL ApplXcpPrepareDaq() { return Xcp::getInstance()->onPrepareDaq(); } @@ -107,7 +110,7 @@ uint8_t* ApplXcpGetBaseAddr() { return baseAddr; } -uint32_t ApplXcpGetAddr(uint8_t* p) { +uint32_t ApplXcpGetAddr(const uint8_t* p) { assert(p >= ApplXcpGetBaseAddr()); #ifdef _WIN64 @@ -130,7 +133,7 @@ uint8_t* ApplXcpGetBaseAddr() return ((uint8_t*)0); } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { assert((uint64_t)p <= 0xFFFFFFFF); return ((uint32_t)p); diff --git a/CPP_Demo/xcp_cfg.h b/CPP_Demo/xcp_cfg.h index 2a88a7e..db1ce4f 100644 --- a/CPP_Demo/xcp_cfg.h +++ b/CPP_Demo/xcp_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __XCP_CFG_H__ /*---------------------------------------------------------------------------- | File: @@ -108,9 +109,16 @@ // Debug // Debug console prints +#if !defined(OPTION_ENABLE_DBG_PRINTS) || !defined(OPTION_DEBUG_LEVEL) + #warning "Please define OPTION_ENABLE_DBG_PRINTS and OPTION_DEBUG_LEVEL in main_cfg.h to ON or OFF" +#else #if OPTION_ENABLE_DBG_PRINTS -#define XCP_ENABLE_DEBUG_PRINTS -#define XCP_DBG_LEVEL XCP_DEBUG_LEVEL + #define XCP_ENABLE_DEBUG_PRINTS + #define XCP_DBG_LEVEL OPTION_DEBUG_LEVEL +#else + #undef XCP_ENABLE_DEBUG_PRINTS + #undef XCP_DBG_LEVEL OPTION_DEBUG_LEVEL +#endif #endif // Enable extended error checks, performance penalty !!! diff --git a/C_Demo/C_Demo.a2l b/C_Demo/C_Demo.a2l new file mode 100644 index 0000000..e8a464c --- /dev/null +++ b/C_Demo/C_Demo.a2l @@ -0,0 +1,146 @@ +ASAP2_VERSION 1 71 +/begin PROJECT C_Demo "" +/begin HEADER "" VERSION "1.0" /end HEADER +/begin MODULE C_Demo "" +/include "XCP_104.aml" + +/begin MOD_COMMON "" +BYTE_ORDER MSB_LAST +ALIGNMENT_BYTE 1 +ALIGNMENT_WORD 1 +ALIGNMENT_LONG 1 +ALIGNMENT_FLOAT16_IEEE 1 +ALIGNMENT_FLOAT32_IEEE 1 +ALIGNMENT_FLOAT64_IEEE 1 +ALIGNMENT_INT64 1 +/end MOD_COMMON + +/begin RECORD_LAYOUT R_FLOAT64_IEEE FNC_VALUES 1 FLOAT64_IEEE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_FLOAT64_IEEE "" FLOAT64_IEEE NO_COMPU_METHOD 0 0 -1E12 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_FLOAT64_IEEE "" VALUE R_FLOAT64_IEEE 0 NO_COMPU_METHOD -1E12 1E12 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_FLOAT32_IEEE FNC_VALUES 1 FLOAT32_IEEE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_FLOAT32_IEEE "" FLOAT32_IEEE NO_COMPU_METHOD 0 0 -1E12 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_FLOAT32_IEEE "" VALUE R_FLOAT32_IEEE 0 NO_COMPU_METHOD -1E12 1E12 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_A_INT64 FNC_VALUES 1 A_INT64 ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_A_INT64 "" A_INT64 NO_COMPU_METHOD 0 0 -1E12 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_A_INT64 "" VALUE R_A_INT64 0 NO_COMPU_METHOD -1E12 1E12 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_SLONG FNC_VALUES 1 SLONG ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_SLONG "" SLONG NO_COMPU_METHOD 0 0 -2147483648 2147483647 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_SLONG "" VALUE R_SLONG 0 NO_COMPU_METHOD -2147483648 2147483647 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_SWORD FNC_VALUES 1 SWORD ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_SWORD "" SWORD NO_COMPU_METHOD 0 0 -32768 32767 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_SWORD "" VALUE R_SWORD 0 NO_COMPU_METHOD -32768 32767 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_SBYTE FNC_VALUES 1 SBYTE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_SBYTE "" SBYTE NO_COMPU_METHOD 0 0 -128 127 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_SBYTE "" VALUE R_SBYTE 0 NO_COMPU_METHOD -128 127 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_UBYTE FNC_VALUES 1 UBYTE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_UBYTE "" UBYTE NO_COMPU_METHOD 0 0 0 255 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_UBYTE "" VALUE R_UBYTE 0 NO_COMPU_METHOD 0 255 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_UWORD FNC_VALUES 1 UWORD ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_UWORD "" UWORD NO_COMPU_METHOD 0 0 0 65535 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_UWORD "" VALUE R_UWORD 0 NO_COMPU_METHOD 0 65535 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_ULONG FNC_VALUES 1 ULONG ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_ULONG "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_ULONG "" VALUE R_ULONG 0 NO_COMPU_METHOD 0 4294967295 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_A_UINT64 FNC_VALUES 1 A_UINT64 ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_A_UINT64 "" A_UINT64 NO_COMPU_METHOD 0 0 0 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_A_UINT64 "" VALUE R_A_UINT64 0 NO_COMPU_METHOD 0 1E12 /end TYPEDEF_CHARACTERISTIC + +/begin MOD_PAR "" +EPK "Sep 12 2024 21:04:13" +ADDR_EPK 0x04ABFBB0 +/begin MEMORY_SEGMENT +CALRAM "" DATA FLASH INTERN 0x04ABFBB0 0x000000A8 -1 -1 -1 -1 -1 +/begin IF_DATA XCP +/begin SEGMENT 0x01 0x02 0x00 0x00 0x00 +/begin CHECKSUM XCP_ADD_44 MAX_BLOCK_SIZE 0xFFFF EXTERNAL_FUNCTION "" /end CHECKSUM +/begin PAGE 0x01 ECU_ACCESS_WITH_XCP_ONLY XCP_READ_ACCESS_WITH_ECU_ONLY XCP_WRITE_ACCESS_NOT_ALLOWED /end PAGE +/begin PAGE 0x00 ECU_ACCESS_WITH_XCP_ONLY XCP_READ_ACCESS_WITH_ECU_ONLY XCP_WRITE_ACCESS_WITH_ECU_ONLY /end PAGE +/end SEGMENT +/end IF_DATA +/end MEMORY_SEGMENT +/end MOD_PAR + +/begin CHARACTERISTIC ecuPar.ampl "Amplitude" VALUE 0x4ABFBF0 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 800 PHYS_UNIT "V" SYMBOL_LINK "ecuPar.ampl" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC ecuPar.offset "RefOffset" VALUE 0x4ABFBE0 R_FLOAT64_IEEE 0 NO_COMPU_METHOD -200 200 PHYS_UNIT "V" SYMBOL_LINK "ecuPar.offset" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC ecuPar.phase "Phase" VALUE 0x4ABFBE8 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 6.28319 SYMBOL_LINK "ecuPar.phase" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC ecuPar.period "Period in s" VALUE 0x4ABFBD8 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 10 PHYS_UNIT "s" SYMBOL_LINK "ecuPar.period" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC ecuPar.cycleTimeUs "ECU task cycle time in us" VALUE 0x4ABFBD0 R_ULONG 0 NO_COMPU_METHOD 50 1e+06 PHYS_UNIT "us" SYMBOL_LINK "ecuPar.cycleTimeUs" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC ecuPar.map1_8_8 "8*8 byte calibration array" MAP 0x4ABFBF8 R_UBYTE 0 NO_COMPU_METHOD 0 255 /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD 8 0 7 FIX_AXIS_PAR_DIST 0 1 8 /end AXIS_DESCR /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD 8 0 7 FIX_AXIS_PAR_DIST 0 1 8 /end AXIS_DESCR SYMBOL_LINK "ecuPar.map1_8_8" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC ecuPar.curve1_32 "32 byte calibration array" CURVE 0x4ABFC38 R_UBYTE 0 NO_COMPU_METHOD 0 255 /begin AXIS_DESCR FIX_AXIS NO_INPUT_QUANTITY NO_COMPU_METHOD 32 0 31 FIX_AXIS_PAR_DIST 0 1 32 /end AXIS_DESCR SYMBOL_LINK "ecuPar.curve1_32" 0 /end CHARACTERISTIC +/begin GROUP Parameters "" /begin REF_CHARACTERISTIC + ecuPar.cycleTimeUs ecuPar.map1_8_8 ecuPar.curve1_32 ecuPar.period ecuPar.ampl ecuPar.phase ecuPar.offset +/end REF_CHARACTERISTIC /end GROUP + +/begin COMPU_METHOD byteCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT byteCounter "" UBYTE byteCounter.Conversion 0 0 0.000000 255.000000 ECU_ADDRESS 0x4AC4038 READ_WRITE SYMBOL_LINK "byteCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD wordCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT wordCounter "" UWORD wordCounter.Conversion 0 0 0.000000 65535.000000 ECU_ADDRESS 0x4AC403A READ_WRITE SYMBOL_LINK "wordCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD dwordCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT dwordCounter "" ULONG dwordCounter.Conversion 0 0 0.000000 4294967295.000000 ECU_ADDRESS 0x4AC403C READ_WRITE SYMBOL_LINK "dwordCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD sbyteCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT sbyteCounter "" SBYTE sbyteCounter.Conversion 0 0 -128.000000 127.000000 ECU_ADDRESS 0x4AC4040 READ_WRITE SYMBOL_LINK "sbyteCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD swordCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT swordCounter "" SWORD swordCounter.Conversion 0 0 -32768.000000 32767.000000 ECU_ADDRESS 0x4AC4042 READ_WRITE SYMBOL_LINK "swordCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD sdwordCounter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT sdwordCounter "" SLONG sdwordCounter.Conversion 0 0 -2147483648.000000 2147483647.000000 ECU_ADDRESS 0x4AC4044 READ_WRITE SYMBOL_LINK "sdwordCounter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD channel1.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT channel1 "Sinus signal 1" FLOAT64_IEEE channel1.Conversion 0 0 -1000000000000.0000 1000000000000.00000 ECU_ADDRESS 0x4AC4020 READ_WRITE SYMBOL_LINK "channel1" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD channel2.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT channel2 "Sinus signal 2" FLOAT64_IEEE channel2.Conversion 0 0 -1000000000000.0000 1000000000000.00000 ECU_ADDRESS 0x4AC4028 READ_WRITE SYMBOL_LINK "channel2" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD channel3.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT channel3 "Sinus signal 3" FLOAT64_IEEE channel3.Conversion 0 0 -1000000000000.0000 1000000000000.00000 ECU_ADDRESS 0x4AC4030 READ_WRITE SYMBOL_LINK "channel3" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin CHARACTERISTIC byteArray1 "" VAL_BLK 0x4AC4048 R_UBYTE 0 NO_COMPU_METHOD 0 255 MATRIX_DIM 1024 SYMBOL_LINK "byteArray1" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end CHARACTERISTIC +/begin CHARACTERISTIC longArray1 "" VAL_BLK 0x4AC44F0 R_ULONG 0 NO_COMPU_METHOD 0 4294967295 MATRIX_DIM 1024 SYMBOL_LINK "longArray1" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end CHARACTERISTIC +/begin GROUP EcuTaskSignals "" /begin REF_MEASUREMENT channel1 channel2 channel3 byteCounter wordCounter dwordCounter sbyteCounter swordCounter sdwordCounter /end REF_MEASUREMENT /end GROUP + +/begin GROUP EcuTaskArrays "" /begin REF_CHARACTERISTIC + byteArray1 longArray1 +/end REF_CHARACTERISTIC /end GROUP + +/begin CHARACTERISTIC gDebugLevel "Console output verbosity" VALUE 0x4AC4008 R_ULONG 0 NO_COMPU_METHOD 0 100 SYMBOL_LINK "gDebugLevel" 0 /end CHARACTERISTIC + +/begin IF_DATA XCP +/begin PROTOCOL_LAYER + 0x0104 1000 2000 0 0 0 0 0 248 1468 BYTE_ORDER_MSB_LAST ADDRESS_GRANULARITY_BYTE +OPTIONAL_CMD GET_COMM_MODE_INFO +OPTIONAL_CMD GET_ID +OPTIONAL_CMD SET_MTA +OPTIONAL_CMD UPLOAD +OPTIONAL_CMD SHORT_UPLOAD +OPTIONAL_CMD DOWNLOAD +OPTIONAL_CMD SHORT_DOWNLOAD +OPTIONAL_CMD GET_CAL_PAGE +OPTIONAL_CMD SET_CAL_PAGE +OPTIONAL_CMD BUILD_CHECKSUM +OPTIONAL_CMD GET_DAQ_RESOLUTION_INFO +OPTIONAL_CMD GET_DAQ_PROCESSOR_INFO +OPTIONAL_CMD FREE_DAQ +OPTIONAL_CMD ALLOC_DAQ +OPTIONAL_CMD ALLOC_ODT +OPTIONAL_CMD ALLOC_ODT_ENTRY +OPTIONAL_CMD SET_DAQ_PTR +OPTIONAL_CMD WRITE_DAQ +OPTIONAL_CMD GET_DAQ_LIST_MODE +OPTIONAL_CMD SET_DAQ_LIST_MODE +OPTIONAL_CMD START_STOP_SYNCH +OPTIONAL_CMD START_STOP_DAQ_LIST +OPTIONAL_CMD GET_DAQ_CLOCK +OPTIONAL_CMD WRITE_DAQ_MULTIPLE +OPTIONAL_CMD TIME_CORRELATION_PROPERTIES +OPTIONAL_LEVEL1_CMD GET_VERSION +/end PROTOCOL_LAYER +/begin DAQ +DYNAMIC 0 1 0 OPTIMISATION_TYPE_DEFAULT ADDRESS_EXTENSION_FREE IDENTIFICATION_FIELD_TYPE_RELATIVE_BYTE GRANULARITY_ODT_ENTRY_SIZE_DAQ_BYTE 0xF8 OVERLOAD_INDICATION_PID +/begin TIMESTAMP_SUPPORTED +0x01 SIZE_DWORD UNIT_1NS TIMESTAMP_FIXED +/end TIMESTAMP_SUPPORTED +/begin EVENT "ecuTask" "ecuTask" 0x0 DAQ 0xFF 200 4 0 CONSISTENCY EVENT /end EVENT +/end DAQ +/begin XCP_ON_UDP_IP + 0x0104 5555 ADDRESS "127.0.0.1" +/end XCP_ON_UDP_IP +/end IF_DATA + +/end MODULE +/end PROJECT diff --git a/C_Demo/build.sh b/C_Demo/build.sh new file mode 100755 index 0000000..2b02bca --- /dev/null +++ b/C_Demo/build.sh @@ -0,0 +1,6 @@ + +cmake -DCMAKE_BUILD_TYPE=Release -S . -B build +cd build +make +cd .. + diff --git a/C_Demo/ecu.c b/C_Demo/ecu.c index 852b789..28fb576 100644 --- a/C_Demo/ecu.c +++ b/C_Demo/ecu.c @@ -12,6 +12,7 @@ #include "main.h" #include "platform.h" +#include "dbg_print.h" #include "xcpLite.h" #if OPTION_ENABLE_A2L_GEN #include "A2L.h" @@ -191,7 +192,7 @@ void ecuCreateA2lDescription() { // Calibration Memory Segment #if OPTION_ENABLE_CAL_SEGMENT - A2lCreate_MOD_PAR(ApplXcpGetAddr((uint8_t*)&ecuPar), sizeof(struct ecuPar), (char*)ecuPar.epk); + A2lCreate_MOD_PAR(ApplXcpGetAddr((const uint8_t*)&ecuPar), sizeof(struct ecuPar), (char*)ecuPar.epk); #endif // Parameters diff --git a/C_Demo/main.c b/C_Demo/main.c index 93686d1..323d333 100644 --- a/C_Demo/main.c +++ b/C_Demo/main.c @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) { // Initialize the XCP Server if (!socketStartup()) return 0; // Initialize sockets - if (!XcpEthServerInit(gOptionBindAddr, gOptionPort, gOptionUseTCP, XCPTL_MAX_SEGMENT_SIZE)) return 0; + if (!XcpEthServerInit(gOptionBindAddr, gOptionPort, gOptionUseTCP)) return 0; // Initialize a demo measurement task thread (in ecu.c) and create an A2L for its measurement and calibration objects ecuInit(); diff --git a/C_Demo/main_cfg.h b/C_Demo/main_cfg.h index 04fe15f..e237350 100644 --- a/C_Demo/main_cfg.h +++ b/C_Demo/main_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __MAIN_CFG_H__ // main_cfg.h // C_Demo @@ -12,17 +13,29 @@ #define ON 1 #define OFF 0 +// Set clock resolution (for clock function in platform.c) +//#define CLOCK_USE_APP_TIME_US +#define CLOCK_USE_UTC_TIME_NS -// Debug prints -#define OPTION_ENABLE_DBG_PRINTS ON -#define OPTION_DEBUG_LEVEL 2 -#define OPTION_UDP_DEBUG_LEVEL 0 +// Platform options +#define PLATFORM_ENABLE_GET_LOCAL_ADDR +#define PLATFORM_ENABLE_KEYBOARD +// 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_USE_TCP OFF +#define OPTION_MTU 1500 // Ethernet MTU +#define OPTION_SERVER_PORT 5555 // Default UDP port +#define OPTION_SERVER_ADDR {127,0,0,1} // IP addr to bind, 0.0.0.0 = ANY // Enable demo how to create a calibration segment with page switching #define OPTION_ENABLE_CAL_SEGMENT ON - // A2L generation #define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation #if OPTION_ENABLE_A2L_GEN @@ -30,15 +43,6 @@ #define OPTION_A2L_FILE_NAME "C_Demo.a2l" // A2L filename #endif - -// Set clock resolution (for clock function in platform.c) -//#define CLOCK_USE_APP_TIME_US -#define CLOCK_USE_UTC_TIME_NS - - -// Ethernet Transport Layer -#define OPTION_USE_TCP OFF -#define OPTION_MTU 1500 // Ethernet MTU -#define OPTION_SERVER_PORT 5555 // Default UDP port -#define OPTION_SERVER_ADDR {127,0,0,1} // IP addr to bind, 0.0.0.0 = ANY - +// Debug prints +#define OPTION_ENABLE_DBG_PRINTS ON +#define OPTION_DEBUG_LEVEL 3 // 1 - Error, 2 - Warn, 3 - Info, 4 - Trace, 5 - Debug diff --git a/C_Demo/main_cfg.h.in b/C_Demo/main_cfg.h.in deleted file mode 100644 index b60ebcf..0000000 --- a/C_Demo/main_cfg.h.in +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -// main_cfg.h -// C_Demo - -/* Copyright(c) Vector Informatik GmbH.All rights reserved. - Licensed under the MIT license.See LICENSE file in the project root for details. */ - - -#define APP_NAME "C_Demo" -#define APP_VERSION_MAJOR @C_Demo_VERSION_MAJOR@ -#define APP_VERSION_MINOR @C_Demo_VERSION_MINOR@ - - -//----------------------------------------------------------------------------------------------------- -// Application configuration: -// XCP configuration is in xcp_cfg.h (Protocol Layer) and xcptl_cfg.h (Transport Layer) - -#define ON 1 -#define OFF 0 - -#define OPTION_DEBUG_LEVEL @OPTION_DEBUG_LEVEL@ - -// A2L generation -#define OPTION_ENABLE_A2L_GEN @OPTION_ENABLE_A2L_GEN@ // Enable A2L generation -#if OPTION_ENABLE_A2L_GEN -#define OPTION_ENABLE_A2L_SYMBOL_LINKS ON // Enable generation of symbol links (required for CANape integrated linker map update) -#define OPTION_A2L_NAME "C_Demo" // A2L name -#define OPTION_A2L_FILE_NAME "C_Demo.a2l" // A2L filename -#define OPTION_A2L_PROJECT_NAME "C_Demo" // A2L project name -#endif - - -// Default communication parameters -#define OPTION_ENABLE_TCP @OPTION_ENABLE_TCP@ // Enable TCP support -#define OPTION_USE_TCP @OPTION_USE_TCP@ // Default -#define OPTION_MTU @OPTION_MTU@ // Ethernet MTU -#define OPTION_SERVER_PORT @OPTION_SERVER_PORT@ // Default UDP port, overwritten by commandline option -port -#define OPTION_SERVER_ADDR @OPTION_SERVER_ADDR@ // Default IP addr, 0.0.0.0 = ANY, 255.255.255.255 = first adapter found, overwritten by commandline option -bind x.x.x.x - -// Calibration segment -#define OPTION_ENABLE_CAL_SEGMENT ON - - diff --git a/C_Demo/xcp_cfg.h b/C_Demo/xcp_cfg.h index a5bb28b..f85a69f 100644 --- a/C_Demo/xcp_cfg.h +++ b/C_Demo/xcp_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __XCP_CFG_H__ /*---------------------------------------------------------------------------- | File: @@ -101,9 +102,16 @@ // Debug // Debug console prints +#if !defined(OPTION_ENABLE_DBG_PRINTS) || !defined(OPTION_DEBUG_LEVEL) + #warning "Please define OPTION_ENABLE_DBG_PRINTS and OPTION_DEBUG_LEVEL in main_cfg.h to ON or OFF" +#else #if OPTION_ENABLE_DBG_PRINTS -#define XCP_ENABLE_DEBUG_PRINTS -#define XCP_DBG_LEVEL XCP_DEBUG_LEVEL + #define XCP_ENABLE_DEBUG_PRINTS + #define XCP_DBG_LEVEL OPTION_DEBUG_LEVEL +#else + #undef XCP_ENABLE_DEBUG_PRINTS + #undef XCP_DBG_LEVEL OPTION_DEBUG_LEVEL +#endif #endif // Enable extended error checks, performance penalty !!! diff --git a/README.md b/README.md index 5c52e02..e036f90 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# XCPlite V6 +# XCPlite V7.x.x Copyright 2024 Vector Informatik GmbH @@ -20,6 +20,7 @@ XCPlite - Compiles as C or C++. - Has no dependencies but includes some boilerplate code to abstract socket communication and clock - Achieves up to 100 MByte/s throughput on a Raspberry Pi 4. +- v7 is used as the XCP on ETH protocol and transport layer implementation for the rust xcp-lite API XCPlite has been testet on CANFD, there is some experimental code included, but there is no example target to showcase this. XCPlite is not recomended for CAN. @@ -118,6 +119,20 @@ Turn Multicast off in device/protocol/event/TIME_CORRELATION_GETDAQCLOCK by chan ## Version History +Version 7.x.x + +- Sync with xcp-lite (rust FFI) version +- Refactoring for xcplib +- Debug level 1-error, 2-warn,3-info,4-debug,5-trace +- New addressing mode with callbacks +- XcpEthServer optional, XcpTlTransmitQueuePeek and XcpTlTransmitQueueNext +- Option for forcefull or gracefull thread termination +- Segment_size parameters removed +- SendCallback removed, additional callback for rust FFI +- Type of BOOL changed to uint8_t to simplify FFI +- XcpReset + + Version 6.x: - Bugfixes, optimizations, refactorings and simplifications - New targets XCPlite and XCPlite as a static library for Linux diff --git a/XCPlib/main_cfg.h b/XCPlib/main_cfg.h index 448e8f2..c2378be 100644 --- a/XCPlib/main_cfg.h +++ b/XCPlib/main_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __MAIN_CFG_H__ // main_cfg.h // XCPlite @@ -38,21 +39,6 @@ #define ON 1 #define OFF 0 - -// Debug prints -#define OPTION_ENABLE_DBG_PRINTS ON -#define OPTION_DEBUG_LEVEL 2 -#define OPTION_UDP_DEBUG_LEVEL 0 - - -// A2L generation -#define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation -#if OPTION_ENABLE_A2L_GEN -#define OPTION_A2L_NAME "XCPlite" // A2L name -#define OPTION_A2L_FILE_NAME "XCPlite.a2l" // A2L filename -#endif - - // Set clock resolution (for clock function in platform.c) #define CLOCK_USE_APP_TIME_US //#define CLOCK_USE_UTC_TIME_NS @@ -64,3 +50,13 @@ #define OPTION_SERVER_PORT 5555 // Default UDP port #define OPTION_SERVER_ADDR {127,0,0,1} // IP addr to bind, 0.0.0.0 = ANY +// A2L generation +#define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation +#if OPTION_ENABLE_A2L_GEN +#define OPTION_A2L_NAME "XCPlite" // A2L name +#define OPTION_A2L_FILE_NAME "XCPlite.a2l" // A2L filename +#endif + +// Debug prints +#define OPTION_ENABLE_DBG_PRINTS ON +#define OPTION_DEBUG_LEVEL 3 // 1 - Error, 2 - Warn, 3 - Info, 4 - Trace, 5 - Debug diff --git a/XCPlib/xcpAppl.c b/XCPlib/xcpAppl.c index 283284a..b88171e 100644 --- a/XCPlib/xcpAppl.c +++ b/XCPlib/xcpAppl.c @@ -26,6 +26,10 @@ BOOL ApplXcpConnect() { return TRUE; } +void ApplXcpDisconnect() { + DBG_PRINT3("XCP disconnect\n"); +} + #if XCP_PROTOCOL_LAYER_VERSION >= 0x0104 BOOL ApplXcpPrepareDaq() { DBG_PRINT1("XCP prepare DAQ\n"); @@ -110,7 +114,7 @@ uint8_t* ApplXcpGetBaseAddr() { return baseAddr; } -uint32_t ApplXcpGetAddr(uint8_t* p) { +uint32_t ApplXcpGetAddr(const uint8_t* p) { assert(p >= ApplXcpGetBaseAddr()); #ifdef _WIN64 @@ -157,7 +161,7 @@ uint8_t* ApplXcpGetBaseAddr() { return baseAddr; } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { ApplXcpGetBaseAddr(); return (uint32_t)(p - baseAddr); @@ -175,7 +179,7 @@ uint8_t* ApplXcpGetBaseAddr() return ((uint8_t*)((uint64_t)(&__base_addr_val)&0xffffffff00000000)); } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { return ((uint32_t)((uint64_t) p)& 0xffffffff); } @@ -191,7 +195,7 @@ uint8_t* ApplXcpGetBaseAddr() return ((uint8_t*)0); } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { return ((uint32_t)(p)); } diff --git a/XCPlib/xcp_cfg.h b/XCPlib/xcp_cfg.h index d908e1b..84354c2 100644 --- a/XCPlib/xcp_cfg.h +++ b/XCPlib/xcp_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __XCP_CFG_H__ /*---------------------------------------------------------------------------- | File: @@ -73,9 +74,16 @@ // Debug // Debug console prints +#if !defined(OPTION_ENABLE_DBG_PRINTS) || !defined(OPTION_DEBUG_LEVEL) + #error "Please define OPTION_ENABLE_DBG_PRINTS and OPTION_DEBUG_LEVEL in main_cfg.h to ON or OFF" +#else #if OPTION_ENABLE_DBG_PRINTS #define XCP_ENABLE_DEBUG_PRINTS - #define XCP_DBG_LEVEL XCP_DEBUG_LEVEL + #define XCP_DBG_LEVEL OPTION_DEBUG_LEVEL +#else + #undef XCP_ENABLE_DEBUG_PRINTS + #undef XCP_DBG_LEVEL OPTION_DEBUG_LEVEL +#endif #endif // Enable extended error checks, performance penalty !!! diff --git a/XCPlite/XCPlite.a2l b/XCPlite/XCPlite.a2l new file mode 100644 index 0000000..6b13d34 --- /dev/null +++ b/XCPlite/XCPlite.a2l @@ -0,0 +1,98 @@ +ASAP2_VERSION 1 71 +/begin PROJECT XCPlite "" +/begin HEADER "" VERSION "1.0" /end HEADER +/begin MODULE XCPlite "" +/include "XCP_104.aml" + +/begin MOD_COMMON "" +BYTE_ORDER MSB_LAST +ALIGNMENT_BYTE 1 +ALIGNMENT_WORD 1 +ALIGNMENT_LONG 1 +ALIGNMENT_FLOAT16_IEEE 1 +ALIGNMENT_FLOAT32_IEEE 1 +ALIGNMENT_FLOAT64_IEEE 1 +ALIGNMENT_INT64 1 +/end MOD_COMMON + +/begin RECORD_LAYOUT R_FLOAT64_IEEE FNC_VALUES 1 FLOAT64_IEEE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_FLOAT64_IEEE "" FLOAT64_IEEE NO_COMPU_METHOD 0 0 -1E12 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_FLOAT64_IEEE "" VALUE R_FLOAT64_IEEE 0 NO_COMPU_METHOD -1E12 1E12 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_FLOAT32_IEEE FNC_VALUES 1 FLOAT32_IEEE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_FLOAT32_IEEE "" FLOAT32_IEEE NO_COMPU_METHOD 0 0 -1E12 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_FLOAT32_IEEE "" VALUE R_FLOAT32_IEEE 0 NO_COMPU_METHOD -1E12 1E12 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_A_INT64 FNC_VALUES 1 A_INT64 ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_A_INT64 "" A_INT64 NO_COMPU_METHOD 0 0 -1E12 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_A_INT64 "" VALUE R_A_INT64 0 NO_COMPU_METHOD -1E12 1E12 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_SLONG FNC_VALUES 1 SLONG ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_SLONG "" SLONG NO_COMPU_METHOD 0 0 -2147483648 2147483647 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_SLONG "" VALUE R_SLONG 0 NO_COMPU_METHOD -2147483648 2147483647 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_SWORD FNC_VALUES 1 SWORD ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_SWORD "" SWORD NO_COMPU_METHOD 0 0 -32768 32767 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_SWORD "" VALUE R_SWORD 0 NO_COMPU_METHOD -32768 32767 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_SBYTE FNC_VALUES 1 SBYTE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_SBYTE "" SBYTE NO_COMPU_METHOD 0 0 -128 127 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_SBYTE "" VALUE R_SBYTE 0 NO_COMPU_METHOD -128 127 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_UBYTE FNC_VALUES 1 UBYTE ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_UBYTE "" UBYTE NO_COMPU_METHOD 0 0 0 255 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_UBYTE "" VALUE R_UBYTE 0 NO_COMPU_METHOD 0 255 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_UWORD FNC_VALUES 1 UWORD ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_UWORD "" UWORD NO_COMPU_METHOD 0 0 0 65535 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_UWORD "" VALUE R_UWORD 0 NO_COMPU_METHOD 0 65535 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_ULONG FNC_VALUES 1 ULONG ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_ULONG "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_ULONG "" VALUE R_ULONG 0 NO_COMPU_METHOD 0 4294967295 /end TYPEDEF_CHARACTERISTIC +/begin RECORD_LAYOUT R_A_UINT64 FNC_VALUES 1 A_UINT64 ROW_DIR DIRECT /end RECORD_LAYOUT +/begin TYPEDEF_MEASUREMENT M_A_UINT64 "" A_UINT64 NO_COMPU_METHOD 0 0 0 1E12 /end TYPEDEF_MEASUREMENT +/begin TYPEDEF_CHARACTERISTIC C_A_UINT64 "" VALUE R_A_UINT64 0 NO_COMPU_METHOD 0 1E12 /end TYPEDEF_CHARACTERISTIC + +/begin CHARACTERISTIC ampl "Amplitude of sinus signal in V" VALUE 0x4E8C000 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 800 PHYS_UNIT "V" SYMBOL_LINK "ampl" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC period "Period of sinus signal in s" VALUE 0x4E8C008 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 10 PHYS_UNIT "s" SYMBOL_LINK "period" 0 /end CHARACTERISTIC +/begin CHARACTERISTIC cycleTime "Cycle time of demo event loop in us" VALUE 0x4E8C010 R_FLOAT64_IEEE 0 NO_COMPU_METHOD 0 1e+06 PHYS_UNIT "us" SYMBOL_LINK "cycleTime" 0 /end CHARACTERISTIC +/begin COMPU_METHOD channel1.Conversion "" LINEAR "%6.3" "V" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT channel1 "Sinus demo signal" FLOAT64_IEEE channel1.Conversion 0 0 -1000000000000.0000 1000000000000.00000 ECU_ADDRESS 0x4E8C028 PHYS_UNIT "V" READ_WRITE SYMBOL_LINK "channel1" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT +/begin COMPU_METHOD counter.Conversion "" LINEAR "%6.3" "" COEFFS_LINEAR 1 0 /end COMPU_METHOD +/begin MEASUREMENT counter "Event counter" ULONG counter.Conversion 0 0 0.000000 4294967295.000000 ECU_ADDRESS 0x4E8C030 READ_WRITE SYMBOL_LINK "counter" 0 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0x0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT + +/begin IF_DATA XCP +/begin PROTOCOL_LAYER + 0x0104 1000 2000 0 0 0 0 0 248 1468 BYTE_ORDER_MSB_LAST ADDRESS_GRANULARITY_BYTE +OPTIONAL_CMD GET_COMM_MODE_INFO +OPTIONAL_CMD GET_ID +OPTIONAL_CMD SET_MTA +OPTIONAL_CMD UPLOAD +OPTIONAL_CMD SHORT_UPLOAD +OPTIONAL_CMD DOWNLOAD +OPTIONAL_CMD SHORT_DOWNLOAD +OPTIONAL_CMD BUILD_CHECKSUM +OPTIONAL_CMD GET_DAQ_RESOLUTION_INFO +OPTIONAL_CMD GET_DAQ_PROCESSOR_INFO +OPTIONAL_CMD FREE_DAQ +OPTIONAL_CMD ALLOC_DAQ +OPTIONAL_CMD ALLOC_ODT +OPTIONAL_CMD ALLOC_ODT_ENTRY +OPTIONAL_CMD SET_DAQ_PTR +OPTIONAL_CMD WRITE_DAQ +OPTIONAL_CMD GET_DAQ_LIST_MODE +OPTIONAL_CMD SET_DAQ_LIST_MODE +OPTIONAL_CMD START_STOP_SYNCH +OPTIONAL_CMD START_STOP_DAQ_LIST +OPTIONAL_CMD GET_DAQ_CLOCK +OPTIONAL_CMD WRITE_DAQ_MULTIPLE +OPTIONAL_CMD TIME_CORRELATION_PROPERTIES +OPTIONAL_LEVEL1_CMD GET_VERSION +/end PROTOCOL_LAYER +/begin DAQ +DYNAMIC 0 1 0 OPTIMISATION_TYPE_DEFAULT ADDRESS_EXTENSION_FREE IDENTIFICATION_FIELD_TYPE_RELATIVE_BYTE GRANULARITY_ODT_ENTRY_SIZE_DAQ_BYTE 0xF8 OVERLOAD_INDICATION_PID +/begin TIMESTAMP_SUPPORTED +0x01 SIZE_DWORD UNIT_1US TIMESTAMP_FIXED +/end TIMESTAMP_SUPPORTED +/begin EVENT "mainLoop" "mainLoop" 0x0 DAQ 0xFF 0 0 0 CONSISTENCY EVENT /end EVENT +/end DAQ +/begin XCP_ON_UDP_IP + 0x0104 5555 ADDRESS "127.0.0.1" +/end XCP_ON_UDP_IP +/end IF_DATA + +/end MODULE +/end PROJECT diff --git a/XCPlite/build.sh b/XCPlite/build.sh new file mode 100755 index 0000000..2b02bca --- /dev/null +++ b/XCPlite/build.sh @@ -0,0 +1,6 @@ + +cmake -DCMAKE_BUILD_TYPE=Release -S . -B build +cd build +make +cd .. + diff --git a/XCPlite/main.c b/XCPlite/main.c index 94d5101..7da9df1 100644 --- a/XCPlite/main.c +++ b/XCPlite/main.c @@ -60,12 +60,12 @@ int main() { // Initialize the XCP Server uint8_t ipAddr[] = OPTION_SERVER_ADDR; - if (!XcpEthServerInit(ipAddr, OPTION_SERVER_PORT, OPTION_USE_TCP, XCPTL_MAX_SEGMENT_SIZE)) return 0; + if (!XcpEthServerInit(ipAddr, OPTION_SERVER_PORT, OPTION_USE_TCP)) return 0; // Test address conversion functions // uint8_t* ApplXcpGetPointer(uint8_t addr_ext, uint32_t addr); - // uint32_t ApplXcpGetAddr(uint8_t * p); - uint32_t a = ApplXcpGetAddr((uint8_t*)&l); + // uint32_t ApplXcpGetAddr(const uint8_t * p); + uint32_t a = ApplXcpGetAddr((const uint8_t*)&l); uint8_t* p = ApplXcpGetPointer(0 /*addr_ext*/, a); double val = *(double*)p; // read assert(ampl == val); diff --git a/XCPlite/main.h b/XCPlite/main.h deleted file mode 100644 index 1332275..0000000 --- a/XCPlite/main.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - - -/* main.h */ -/* -| Code released into public domain, no attribution required -*/ - -// Windows or Linux ? -#if defined(_WIN32) || defined(_WIN64) - #define _WIN - #if defined(_WIN32) && defined(_WIN64) - #undef _WIN32 - #endif - #if defined(_LINUX) || defined(_LINUX64)|| defined(_LINUX32) - #error - #endif -#else - #define _LINUX - #if defined (_ix64_) || defined (__x86_64__) || defined (__aarch64__) - #define _LINUX64 - #else - #define _LINUX32 - #endif - #if defined(_WIN) || defined(_WIN64)|| defined(_WIN32) - #error - #endif -#endif - - -#ifdef _WIN -#define WIN32_LEAN_AND_MEAN -#define _CRT_SECURE_NO_WARNINGS -#else -#define _DEFAULT_SOURCE -#endif - - -#include -#include -#include -#include -#include -#include - -#ifndef _WIN // Linux - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#else // Windows - -#include -#include -#include - -#endif - - -#ifdef __cplusplus -#include -#include -#include -#include -#endif - -#define BOOL int -#define FALSE 0 -#define TRUE 1 - -#include "main_cfg.h" - diff --git a/XCPlite/main_cfg.h b/XCPlite/main_cfg.h index 33dc0d9..a0e92b9 100644 --- a/XCPlite/main_cfg.h +++ b/XCPlite/main_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __MAIN_CFG_H__ // main_cfg.h // XCPlite @@ -38,27 +39,33 @@ #define ON 1 #define OFF 0 - -// Debug prints -#define OPTION_ENABLE_DBG_PRINTS ON -#define OPTION_DEBUG_LEVEL 2 - -// A2L generation -#define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation -#if OPTION_ENABLE_A2L_GEN -#define OPTION_A2L_NAME "XCPlite" // A2L name -#define OPTION_A2L_FILE_NAME "XCPlite.a2l" // A2L filename -#endif - - // Set clock resolution (for clock function in platform.c) #define CLOCK_USE_APP_TIME_US //#define CLOCK_USE_UTC_TIME_NS +// Platform options +#define PLATFORM_ENABLE_GET_LOCAL_ADDR +#define PLATFORM_ENABLE_KEYBOARD + +// 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 +// Ethernet Transport Layer options #define OPTION_USE_TCP OFF #define OPTION_MTU 1500 // Ethernet MTU #define OPTION_SERVER_PORT 5555 // Default UDP port #define OPTION_SERVER_ADDR {127,0,0,1} // IP addr to bind, 0.0.0.0 = ANY +// A2L generation +#define OPTION_ENABLE_A2L_GEN ON // Enable A2L generation +#if OPTION_ENABLE_A2L_GEN +#define OPTION_A2L_NAME "XCPlite" // A2L name +#define OPTION_A2L_FILE_NAME "XCPlite.a2l" // A2L filename +#endif + +// Debug prints +#define OPTION_ENABLE_DBG_PRINTS ON +#define OPTION_DEBUG_LEVEL 3 // 1 - Error, 2 - Warn, 3 - Info, 4 - Trace, 5 - Debug diff --git a/XCPlite/xcp_cfg.h b/XCPlite/xcp_cfg.h index c5b0a18..1fad0d6 100644 --- a/XCPlite/xcp_cfg.h +++ b/XCPlite/xcp_cfg.h @@ -1,4 +1,5 @@ #pragma once +#define __XCP_CFG_H__ /*---------------------------------------------------------------------------- | File: diff --git a/src/A2L.c b/src/A2L.c index 5ac186a..6ac4bbe 100644 --- a/src/A2L.c +++ b/src/A2L.c @@ -341,12 +341,12 @@ void A2lCreate_MOD_PAR(uint32_t startAddr, uint32_t size, char *epk) { assert(gA2lFile != NULL); fprintf(gA2lFile, "/begin MOD_PAR \"\"\n"); fprintf(gA2lFile, "EPK \"%s\"\n", epk); - fprintf(gA2lFile, "ADDR_EPK 0x%08X\n", ApplXcpGetAddr((uint8_t*)epk)); + fprintf(gA2lFile, "ADDR_EPK 0x%08X\n", ApplXcpGetAddr((const uint8_t*)epk)); fprintf(gA2lFile, gA2lMemorySegment, startAddr, size); DBG_PRINTF3(" A2L MOD_PAR MEMORY_SEGMENT 1: 0x%08X %u\n", startAddr, size); fprintf(gA2lFile, "/end MOD_PAR\n\n"); #if OPTION_ENABLE_DBG_PRINTS - if (epk) DBG_PRINTF3(" A2L MOD_PAR EPK \"%s\" 0x%08X\n", epk, ApplXcpGetAddr((uint8_t*)epk)); + if (epk) DBG_PRINTF3(" A2L MOD_PAR EPK \"%s\" 0x%08X\n", epk, ApplXcpGetAddr((const uint8_t*)epk)); #endif } diff --git a/src/dbg_print.h b/src/dbg_print.h index 1f204ba..5b37f30 100644 --- a/src/dbg_print.h +++ b/src/dbg_print.h @@ -1,4 +1,6 @@ #pragma once +#define __DBG_PRINT_H__ + /* dbg_print.h */ /* @@ -9,10 +11,12 @@ //------------------------------------------------------------------------------- // Debug print -#ifdef XCP_ENABLE_DBG_PRINTS +#if !defined(OPTION_ENABLE_DBG_PRINTS) || !defined(OPTION_DEBUG_LEVEL) + #error "Please define OPTION_ENABLE_DBG_PRINTS and OPTION_DEBUG_LEVEL in main_cfg.h to ON or OFF" +#endif -extern uint8_t gDebugLevel; -#define DBG_LEVEL gDebugLevel + +#if OPTION_ENABLE_DBG_PRINTS /* 1 - Error @@ -21,6 +25,9 @@ extern uint8_t gDebugLevel; 4 - Trace 5 - Debug */ +extern uint8_t gDebugLevel; +#define DBG_LEVEL gDebugLevel + #define DBG_PRINTF(level, format, ...) if (DBG_LEVEL>=level) printf(format, __VA_ARGS__) #define DBG_PRINTF_ERROR(format, ...) if (DBG_LEVEL>=1) printf(format, __VA_ARGS__) diff --git a/src/main.h b/src/main.h index dc5068a..16d515f 100644 --- a/src/main.h +++ b/src/main.h @@ -1,4 +1,5 @@ #pragma once +#define __MAIN_CFG_H__ /* main.h */ diff --git a/src/options.c b/src/options.c index 98b006b..78395e1 100644 --- a/src/options.c +++ b/src/options.c @@ -73,9 +73,11 @@ BOOL cmdline_parser(int argc, char* argv[]) { #if OPTION_ENABLE_DBG_PRINTS else if (strcmp(argv[i], "-log") == 0) { if (++i < argc) { - extern unsigned int gDebugLevel; - if (sscanf(argv[i], "%u", &gDebugLevel) == 1) { - printf("Debug output level = %u\n", gDebugLevel); + unsigned int l = 0; + if (sscanf(argv[i], "%u", &l) == 1) { + extern uint8_t gDebugLevel; + gDebugLevel = (uint8_t)l; + printf("Debug output level = %u\n", gDebugLevel); } } } diff --git a/src/xcp.cpp b/src/xcp.cpp index 3cd2034..1271b5b 100644 --- a/src/xcp.cpp +++ b/src/xcp.cpp @@ -52,7 +52,7 @@ Xcp::~Xcp() {} -BOOL Xcp::init(const uint8_t* addr0, uint16_t port0, BOOL useTCP0, BOOL usePTP0, uint16_t segmentSize) { +BOOL Xcp::init(const uint8_t* addr0, uint16_t port0, BOOL useTCP0, BOOL usePTP0) { addr = addr0; port = port0; @@ -69,7 +69,7 @@ BOOL Xcp::init(const uint8_t* addr0, uint16_t port0, BOOL useTCP0, BOOL usePTP0, if (!clockInit()) return FALSE; // Init and start XCP server - if (!XcpEthServerInit(addr, port, useTCP, segmentSize)) return FALSE; + if (!XcpEthServerInit(addr, port, useTCP)) return FALSE; return TRUE; } @@ -99,6 +99,9 @@ BOOL Xcp::onConnect() { return TRUE; } +void Xcp::onDisconnect() { +} + BOOL Xcp::onPrepareDaq() { return TRUE; } @@ -167,7 +170,7 @@ std::vector* Xcp::getEventList() { #if OPTION_ENABLE_A2L_GEN -uint32_t Xcp::getA2lAddr(uint8_t* p) { // Get A2L addr from pointer +uint32_t Xcp::getA2lAddr(const uint8_t* p) { // Get A2L addr from pointer return ApplXcpGetAddr(p); } diff --git a/src/xcp.hpp b/src/xcp.hpp index 77d1272..6ab007e 100644 --- a/src/xcp.hpp +++ b/src/xcp.hpp @@ -73,10 +73,11 @@ class Xcp { static Xcp* getInstance(); - virtual BOOL init(const uint8_t* addr, uint16_t port, BOOL useTCP, BOOL usePTP, uint16_t segmentSize); + virtual BOOL init(const uint8_t* addr, uint16_t port, BOOL useTCP, BOOL usePTP); virtual void shutdown(); virtual BOOL onConnect(); // Callbacks + virtual void onDisconnect(); virtual BOOL onPrepareDaq(); virtual BOOL onStartDaq(); virtual BOOL onStopDaq(); @@ -97,7 +98,7 @@ class Xcp { void eventAt(uint16_t event, uint64_t clock); void eventExtAt(uint16_t event, uint8_t* base, uint64_t clock); - uint32_t getA2lAddr(uint8_t* p); // Get A2L addr from pointer + uint32_t getA2lAddr(const uint8_t* p); // Get A2L addr from pointer // Optional: A2L generation #if OPTION_ENABLE_A2L_GEN diff --git a/src/xcpAppl.c b/src/xcpAppl.c index 4a8504d..7c0f3a7 100644 --- a/src/xcpAppl.c +++ b/src/xcpAppl.c @@ -24,22 +24,24 @@ #endif - - #if OPTION_ENABLE_DBG_PRINTS -unsigned int gDebugLevel = OPTION_DEBUG_LEVEL; +uint8_t gDebugLevel = OPTION_DEBUG_LEVEL; #endif /**************************************************************************/ // General Callbacks from XCPlite.c /**************************************************************************/ -#ifdef OPTION_ENABLE_XCP_CLASS +#if OPTION_ENABLE_XCP_CLASS BOOL ApplXcpConnect() { return Xcp::getInstance()->onConnect(); } +void ApplXcpDisconnect() { + Xcp::getInstance()->onDisconnect(); +} + #if XCP_PROTOCOL_LAYER_VERSION >= 0x0104 BOOL ApplXcpPrepareDaq() { return Xcp::getInstance()->onPrepareDaq(); @@ -61,6 +63,10 @@ BOOL ApplXcpConnect() { return TRUE; } +void ApplXcpDisconnect() { + DBG_PRINT3("XCP disconnect\n"); +} + #if XCP_PROTOCOL_LAYER_VERSION >= 0x0104 BOOL ApplXcpPrepareDaq() { DBG_PRINT3("XCP prepare DAQ\n"); @@ -171,7 +177,7 @@ uint8_t* ApplXcpGetBaseAddr() { return baseAddr; } -uint32_t ApplXcpGetAddr(uint8_t* p) { +uint32_t ApplXcpGetAddr(const uint8_t* p) { assert(p >= ApplXcpGetBaseAddr()); #ifdef _WIN64 @@ -218,7 +224,7 @@ uint8_t* ApplXcpGetBaseAddr() { return baseAddr; } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { ApplXcpGetBaseAddr(); return (uint32_t)(p - baseAddr); @@ -236,7 +242,7 @@ uint8_t* ApplXcpGetBaseAddr() return ((uint8_t*)((uint64_t)(&__base_addr_val)&0xffffffff00000000)); } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { return ((uint32_t)((uint64_t) p)& 0xffffffff); } @@ -252,7 +258,7 @@ uint8_t* ApplXcpGetBaseAddr() return ((uint8_t*)0); } -uint32_t ApplXcpGetAddr(uint8_t* p) +uint32_t ApplXcpGetAddr(const uint8_t* p) { return ((uint32_t)(p)); } @@ -288,7 +294,7 @@ uint8_t ApplXcpGetExt(uint8_t* addr) return 0; } -uint32_t ApplXcpGetAddr(uint8_t* addr) +uint32_t ApplXcpGetAddr(const uint8_t* addr) { uint8_t addr_ext = ApplXcpGetExt(addr); union { diff --git a/src/xcpCanServer.c b/src/xcpCanServer.c index a24c6f9..d0a6da0 100644 --- a/src/xcpCanServer.c +++ b/src/xcpCanServer.c @@ -14,6 +14,7 @@ #include "main.h" #include "platform.h" +#include "dbg_print.h" #include "util.h" #include "xcpLite.h" #include "xcpCanServer.h"