Skip to content

Commit

Permalink
Sync with rust xcp-lite
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Aug 30, 2024
1 parent a6dbc77 commit 155ad41
Show file tree
Hide file tree
Showing 27 changed files with 1,364 additions and 1,036 deletions.
26 changes: 20 additions & 6 deletions CPP_Demo/xcp_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,32 @@
// #define XCP_PROTOCOL_LAYER_VERSION 0x0104 // PACKED_MODE, CC_START_STOP_SYNCH prepare





/*----------------------------------------------------------------------------*/
/* Driver features */
/* Adress, address extension coding */

#define XCP_TRANSPORT_LAYER_TYPE XCP_TRANSPORT_LAYER_ETH // Enable ethernet specific commands
// Use addr_ext XCP_ADDR_EXT_ABS to indicate absulute addr format (ApplXcpGetBaseAddr()+(uint32_t)addr)
#define XCP_ENABLE_ABS_ADDRESSING
#define XCP_ADDR_EXT_ABS 0x01 // Absolute address format

// Use addr_ext XCP_ADDR_EXT_DYN to indicate relative addr format (event<<16)|offset
#if OPTION_ENABLE_XCP_CLASS
#define XCP_ENABLE_DYN_ADDRESSING // Enable addr_ext=1 indicating relative addr format (event<<16)|offset
#define XCP_ENABLE_DYN_ADDRESSING
#define XCP_ADDR_EXT_DYN 0x02 // Relative address format
#endif

// Use addr_ext XCP_ADDR_EXT_APP to indicate application specific addr format and use ApplXcpReadMemory and ApplXcpWriteMemory
// #define XCP_ENABLE_APP_ADDRESSING
// #define XCP_ADDR_EXT_APP 0x00 // Address format handled by application

// Internally used address extensions
// Use addr_ext XCP_ADDR_EXT_A2L to indicate A2L upload memory space
#define XCP_ADDR_EXT_A2L 0xFD
// Use addr_ext XCP_ADDR_EXT_PTR to indicate gXcp.MtaPtr is valid
#define XCP_ADDR_EXT_PTR 0xFE

// Undefined address extension
#define XCP_ADDR_EXT_UNDEFINED 0xFF // Undefined address extension

/*----------------------------------------------------------------------------*/
/* Protocol features */

Expand Down
4 changes: 3 additions & 1 deletion CPP_Demo/xcptl_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

// CTO size
// Maximum size of a XCP command
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4
#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

// DAQ transmit queue
// Transmit queue size in segments, should at least be able to hold all data produced until the next call to HandleTransmitQueue
Expand Down
5 changes: 2 additions & 3 deletions C_Demo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static BOOL createA2L() {
static BOOL checkKeyboard() {
if (_kbhit()) {
switch (_getch()) {
case 27: XcpSendEvent(EVC_SESSION_TERMINATED, NULL, 0); return FALSE; // Stop on ESC
case 27: XcpSendEvent(PID_EV,EVC_SESSION_TERMINATED, NULL, 0); return FALSE; // Stop on ESC
#if OPTION_ENABLE_DBG_PRINTS
case '+': if (gDebugLevel < 5) gDebugLevel++; printf("\nDebuglevel = %u\n", gDebugLevel); break;
case '-': if (gDebugLevel > 0) gDebugLevel--; printf("\nDebuglevel = %u\n", gDebugLevel); break;
Expand Down Expand Up @@ -91,8 +91,7 @@ int main(int argc, char* argv[]) {
}

// Terminate task
sleepMs(1000);
cancel_thread(t2);
// @@@@

// Stop the XCP server
XcpEthServerShutdown();
Expand Down
38 changes: 21 additions & 17 deletions C_Demo/main.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once


/* main.h */
/*
| Code released into public domain, no attribution required
Expand Down Expand Up @@ -40,12 +41,6 @@
#include <stdint.h>
#include <inttypes.h>
#include <math.h>

#ifdef _WIN
#define M_PI 3.14159265358979323846
#endif
#define M_2PI (M_PI*2)

#include <assert.h>

#ifndef _WIN // Linux
Expand All @@ -54,35 +49,44 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>

#include <sys/time.h>
#include <time.h>
//#include <time.h>

#include <sys/stat.h>
#include <pthread.h>

#include <ifaddrs.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
//#include <ifaddrs.h>
//#include <fcntl.h>
//#include <netinet/in.h>
//#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define MAX_PATH 256
#define BOOL int
#define FALSE 0
#define TRUE 1
//#define MAX_PATH 256

#else // Windows

#include <windows.h>
#include <time.h>
#include <conio.h>

#endif


#ifdef __cplusplus
#include <typeinfo>
#include <thread>
#include <string>
#include <vector>
#endif

#define BOOL int
#define FALSE 0
#define TRUE 1

#ifdef _WIN
#define M_PI 3.14159265358979323846
#endif
#define M_2PI (M_PI*2)

#include "main_cfg.h"

23 changes: 21 additions & 2 deletions C_Demo/xcp_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,28 @@
#define XCP_PROTOCOL_LAYER_VERSION 0x0104 // PACKED_MODE, CC_START_STOP_SYNCH prepare

/*----------------------------------------------------------------------------*/
/* Driver features */
/* Adress, address extension coding */

// #define XCP_ENABLE_DYN_ADDRESSING // Enable addr_ext=1 indicating relative addr format (event<<16)|offset
// Use addr_ext XCP_ADDR_EXT_ABS to indicate absulute addr format (ApplXcpGetBaseAddr()+(uint32_t)addr)
#define XCP_ENABLE_ABS_ADDRESSING
#define XCP_ADDR_EXT_ABS 0x01 // Absolute address format

// Use addr_ext XCP_ADDR_EXT_DYN to indicate relative addr format (event<<16)|offset
// #define XCP_ENABLE_DYN_ADDRESSING
// #define XCP_ADDR_EXT_DYN 0x02 // Relative address format

// Use addr_ext XCP_ADDR_EXT_APP to indicate application specific addr format and use ApplXcpReadMemory and ApplXcpWriteMemory
// #define XCP_ENABLE_APP_ADDRESSING
// #define XCP_ADDR_EXT_APP 0x00 // Address format handled by application

// Internally used address extensions
// Use addr_ext XCP_ADDR_EXT_A2L to indicate A2L upload memory space
#define XCP_ADDR_EXT_A2L 0xFD
// Use addr_ext XCP_ADDR_EXT_PTR to indicate gXcp.MtaPtr is valid
#define XCP_ADDR_EXT_PTR 0xFE

// Undefined address extension
#define XCP_ADDR_EXT_UNDEFINED 0xFF // Undefined address extension


/*----------------------------------------------------------------------------*/
Expand Down
4 changes: 3 additions & 1 deletion C_Demo/xcptl_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

// CTO size
// Maximum size of a XCP command
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4
#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

// DAQ transmit queue
// Transmit queue size in segments, should at least be able to hold all data produced until the next call to HandleTransmitQueue
Expand Down
6 changes: 3 additions & 3 deletions XCPlib/xcpAppl.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ uint8_t baseAddrValid = 0;

static int dump_phdr(struct dl_phdr_info* pinfo, size_t size, void* data)
{
// DBG_PRINTF1("name=%s (%d segments)\n", pinfo->dlpi_name, pinfo->dlpi_phnum);
// DBG_PRINTF3("name=%s (%d segments)\n", pinfo->dlpi_name, pinfo->dlpi_phnum);

// Application modules has no name
if (0 == strlen(pinfo->dlpi_name)) {
Expand All @@ -151,7 +151,7 @@ uint8_t* ApplXcpGetBaseAddr() {
dl_iterate_phdr(dump_phdr, NULL);
assert(baseAddr != NULL);
baseAddrValid = 1;
DBG_PRINTF1("BaseAddr = %lX\n", (uint64_t)baseAddr);
DBG_PRINTF3("BaseAddr = %lX\n", (uint64_t)baseAddr);
}

return baseAddr;
Expand Down Expand Up @@ -251,7 +251,7 @@ uint8_t* loadFile(const char* filename, uint32_t* length) {
uint8_t* fileBuf = NULL; // file content
uint32_t fileLen = 0; // file length

DBG_PRINTF1("Load %s\n", filename);
DBG_PRINTF3("Load %s\n", filename);

#if defined(_LINUX) // Linux

Expand Down
5 changes: 3 additions & 2 deletions XCPlib/xcptl_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@

// CTO size
// Maximum size of a XCP command
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4

#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



Expand Down
2 changes: 1 addition & 1 deletion XCPlite/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int main() {
if (!XcpEthServerStatus()) { printf("\nXCP Server failed\n"); break; } // Check if the XCP server is running

if (!checkKeyboard()) {
XcpSendEvent(EVC_SESSION_TERMINATED, NULL, 0);
XcpSendEvent(PID_EV,EVC_SESSION_TERMINATED, NULL, 0);
break;
}
}
Expand Down
38 changes: 21 additions & 17 deletions XCPlite/main.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once


/* main.h */
/*
| Code released into public domain, no attribution required
Expand Down Expand Up @@ -40,12 +41,6 @@
#include <stdint.h>
#include <inttypes.h>
#include <math.h>

#ifdef _WIN
#define M_PI 3.14159265358979323846
#endif
#define M_2PI (M_PI*2)

#include <assert.h>

#ifndef _WIN // Linux
Expand All @@ -54,35 +49,44 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>

#include <sys/time.h>
#include <time.h>
//#include <time.h>

#include <sys/stat.h>
#include <pthread.h>

#include <ifaddrs.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
//#include <ifaddrs.h>
//#include <fcntl.h>
//#include <netinet/in.h>
//#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define MAX_PATH 256
#define BOOL int
#define FALSE 0
#define TRUE 1
//#define MAX_PATH 256

#else // Windows

#include <windows.h>
#include <time.h>
#include <conio.h>

#endif


#ifdef __cplusplus
#include <typeinfo>
#include <thread>
#include <string>
#include <vector>
#endif

#define BOOL int
#define FALSE 0
#define TRUE 1

#ifdef _WIN
#define M_PI 3.14159265358979323846
#endif
#define M_2PI (M_PI*2)

#include "main_cfg.h"

23 changes: 21 additions & 2 deletions XCPlite/xcp_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@
//#define XCP_PROTOCOL_LAYER_VERSION 0x0103 // GET_DAQ_CLOCK_MULTICAST, GET_TIME_CORRELATION_PROPERTIES
#define XCP_PROTOCOL_LAYER_VERSION 0x0104 // PACKED_MODE, CC_START_STOP_SYNCH prepare


/*----------------------------------------------------------------------------*/
/* Driver features */
/* Adress, address extension coding */

// Use addr_ext XCP_ADDR_EXT_ABS to indicate absulute addr format (ApplXcpGetBaseAddr()+(uint32_t)addr)
#define XCP_ENABLE_ABS_ADDRESSING
#define XCP_ADDR_EXT_ABS 0x01 // Absolute address format

// Use addr_ext XCP_ADDR_EXT_DYN to indicate relative addr format (event<<16)|offset
// #define XCP_ENABLE_DYN_ADDRESSING
// #define XCP_ADDR_EXT_DYN 0x02 // Relative address format

// Use addr_ext XCP_ADDR_EXT_APP to indicate application specific addr format and use ApplXcpReadMemory and ApplXcpWriteMemory
// #define XCP_ENABLE_APP_ADDRESSING
// #define XCP_ADDR_EXT_APP 0x00 // Address format handled by application

// #define XCP_ENABLE_DYN_ADDRESSING // Enable addr_ext=1 indicating relative addr format (event<<16)|offset
// Internally used address extensions
// Use addr_ext XCP_ADDR_EXT_A2L to indicate A2L upload memory space
#define XCP_ADDR_EXT_A2L 0xFD
// Use addr_ext XCP_ADDR_EXT_PTR to indicate gXcp.MtaPtr is valid
#define XCP_ADDR_EXT_PTR 0xFE

// Undefined address extension
#define XCP_ADDR_EXT_UNDEFINED 0xFF // Undefined address extension

/*----------------------------------------------------------------------------*/
/* Protocol features */
Expand Down
6 changes: 3 additions & 3 deletions XCPlite/xcptl_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@

// CTO size
// Maximum size of a XCP command
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4

#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



Loading

0 comments on commit 155ad41

Please sign in to comment.