Skip to content

Commit

Permalink
Sync with xcp-lite
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Sep 12, 2024
1 parent d1adee9 commit 83b343d
Show file tree
Hide file tree
Showing 32 changed files with 452 additions and 270 deletions.
19 changes: 11 additions & 8 deletions CPP_Demo/CPP_Demo.a2l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -79,14 +79,17 @@ 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
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
Expand Down
6 changes: 6 additions & 0 deletions CPP_Demo/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
cd build
make
cd ..

2 changes: 1 addition & 1 deletion CPP_Demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions CPP_Demo/main_cfg.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#define __MAIN_CFG_H__

// main_cfg.h
// CPP_Demo
Expand All @@ -9,40 +10,42 @@
// 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

// 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
#define OPTION_A2L_NAME "CPP_Demo" // A2L name
#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
39 changes: 0 additions & 39 deletions CPP_Demo/main_cfg.h.in

This file was deleted.

11 changes: 7 additions & 4 deletions CPP_Demo/xcpAppl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -39,6 +37,11 @@ BOOL ApplXcpConnect() {
return Xcp::getInstance()->onConnect();
}

void ApplXcpDisconnect() {
Xcp::getInstance()->onDisconnect();
}


BOOL ApplXcpPrepareDaq() {
return Xcp::getInstance()->onPrepareDaq();
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions CPP_Demo/xcp_cfg.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#define __XCP_CFG_H__

/*----------------------------------------------------------------------------
| File:
Expand Down Expand Up @@ -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 !!!
Expand Down
Loading

0 comments on commit 83b343d

Please sign in to comment.