Skip to content

Commit 155ad41

Browse files
committed
Sync with rust xcp-lite
1 parent a6dbc77 commit 155ad41

27 files changed

+1364
-1036
lines changed

CPP_Demo/xcp_cfg.h

+20-6
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,32 @@
2525
// #define XCP_PROTOCOL_LAYER_VERSION 0x0104 // PACKED_MODE, CC_START_STOP_SYNCH prepare
2626

2727

28-
29-
30-
3128
/*----------------------------------------------------------------------------*/
32-
/* Driver features */
29+
/* Adress, address extension coding */
3330

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

35+
// Use addr_ext XCP_ADDR_EXT_DYN to indicate relative addr format (event<<16)|offset
3636
#if OPTION_ENABLE_XCP_CLASS
37-
#define XCP_ENABLE_DYN_ADDRESSING // Enable addr_ext=1 indicating relative addr format (event<<16)|offset
37+
#define XCP_ENABLE_DYN_ADDRESSING
38+
#define XCP_ADDR_EXT_DYN 0x02 // Relative address format
3839
#endif
3940

41+
// Use addr_ext XCP_ADDR_EXT_APP to indicate application specific addr format and use ApplXcpReadMemory and ApplXcpWriteMemory
42+
// #define XCP_ENABLE_APP_ADDRESSING
43+
// #define XCP_ADDR_EXT_APP 0x00 // Address format handled by application
44+
45+
// Internally used address extensions
46+
// Use addr_ext XCP_ADDR_EXT_A2L to indicate A2L upload memory space
47+
#define XCP_ADDR_EXT_A2L 0xFD
48+
// Use addr_ext XCP_ADDR_EXT_PTR to indicate gXcp.MtaPtr is valid
49+
#define XCP_ADDR_EXT_PTR 0xFE
50+
51+
// Undefined address extension
52+
#define XCP_ADDR_EXT_UNDEFINED 0xFF // Undefined address extension
53+
4054
/*----------------------------------------------------------------------------*/
4155
/* Protocol features */
4256

CPP_Demo/xcptl_cfg.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444

4545
// CTO size
4646
// Maximum size of a XCP command
47-
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4
47+
#define XCPTL_MAX_CTO_SIZE (248)
48+
// CRO_SHORT_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-8 should be %8==0
49+
// CRO_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-2
4850

4951
// DAQ transmit queue
5052
// Transmit queue size in segments, should at least be able to hold all data produced until the next call to HandleTransmitQueue

C_Demo/main.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static BOOL createA2L() {
5252
static BOOL checkKeyboard() {
5353
if (_kbhit()) {
5454
switch (_getch()) {
55-
case 27: XcpSendEvent(EVC_SESSION_TERMINATED, NULL, 0); return FALSE; // Stop on ESC
55+
case 27: XcpSendEvent(PID_EV,EVC_SESSION_TERMINATED, NULL, 0); return FALSE; // Stop on ESC
5656
#if OPTION_ENABLE_DBG_PRINTS
5757
case '+': if (gDebugLevel < 5) gDebugLevel++; printf("\nDebuglevel = %u\n", gDebugLevel); break;
5858
case '-': if (gDebugLevel > 0) gDebugLevel--; printf("\nDebuglevel = %u\n", gDebugLevel); break;
@@ -91,8 +91,7 @@ int main(int argc, char* argv[]) {
9191
}
9292

9393
// Terminate task
94-
sleepMs(1000);
95-
cancel_thread(t2);
94+
// @@@@
9695

9796
// Stop the XCP server
9897
XcpEthServerShutdown();

C_Demo/main.h

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
34
/* main.h */
45
/*
56
| Code released into public domain, no attribution required
@@ -40,12 +41,6 @@
4041
#include <stdint.h>
4142
#include <inttypes.h>
4243
#include <math.h>
43-
44-
#ifdef _WIN
45-
#define M_PI 3.14159265358979323846
46-
#endif
47-
#define M_2PI (M_PI*2)
48-
4944
#include <assert.h>
5045

5146
#ifndef _WIN // Linux
@@ -54,35 +49,44 @@
5449
#include <string.h>
5550
#include <errno.h>
5651
#include <unistd.h>
57-
5852
#include <sys/time.h>
59-
#include <time.h>
53+
//#include <time.h>
54+
6055
#include <sys/stat.h>
6156
#include <pthread.h>
62-
63-
#include <ifaddrs.h>
64-
#include <fcntl.h>
65-
#include <netinet/in.h>
66-
#include <netinet/tcp.h>
57+
//#include <ifaddrs.h>
58+
//#include <fcntl.h>
59+
//#include <netinet/in.h>
60+
//#include <netinet/tcp.h>
6761
#include <arpa/inet.h>
6862
#include <sys/socket.h>
6963

70-
#define MAX_PATH 256
71-
#define BOOL int
72-
#define FALSE 0
73-
#define TRUE 1
64+
//#define MAX_PATH 256
7465

7566
#else // Windows
7667

7768
#include <windows.h>
7869
#include <time.h>
7970
#include <conio.h>
8071

72+
#endif
73+
74+
75+
#ifdef __cplusplus
76+
#include <typeinfo>
77+
#include <thread>
78+
#include <string>
79+
#include <vector>
80+
#endif
81+
8182
#define BOOL int
8283
#define FALSE 0
8384
#define TRUE 1
8485

86+
#ifdef _WIN
87+
#define M_PI 3.14159265358979323846
8588
#endif
89+
#define M_2PI (M_PI*2)
8690

8791
#include "main_cfg.h"
8892

C_Demo/xcp_cfg.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@
2121
#define XCP_PROTOCOL_LAYER_VERSION 0x0104 // PACKED_MODE, CC_START_STOP_SYNCH prepare
2222

2323
/*----------------------------------------------------------------------------*/
24-
/* Driver features */
24+
/* Adress, address extension coding */
2525

26-
// #define XCP_ENABLE_DYN_ADDRESSING // Enable addr_ext=1 indicating relative addr format (event<<16)|offset
26+
// Use addr_ext XCP_ADDR_EXT_ABS to indicate absulute addr format (ApplXcpGetBaseAddr()+(uint32_t)addr)
27+
#define XCP_ENABLE_ABS_ADDRESSING
28+
#define XCP_ADDR_EXT_ABS 0x01 // Absolute address format
29+
30+
// Use addr_ext XCP_ADDR_EXT_DYN to indicate relative addr format (event<<16)|offset
31+
// #define XCP_ENABLE_DYN_ADDRESSING
32+
// #define XCP_ADDR_EXT_DYN 0x02 // Relative address format
33+
34+
// Use addr_ext XCP_ADDR_EXT_APP to indicate application specific addr format and use ApplXcpReadMemory and ApplXcpWriteMemory
35+
// #define XCP_ENABLE_APP_ADDRESSING
36+
// #define XCP_ADDR_EXT_APP 0x00 // Address format handled by application
37+
38+
// Internally used address extensions
39+
// Use addr_ext XCP_ADDR_EXT_A2L to indicate A2L upload memory space
40+
#define XCP_ADDR_EXT_A2L 0xFD
41+
// Use addr_ext XCP_ADDR_EXT_PTR to indicate gXcp.MtaPtr is valid
42+
#define XCP_ADDR_EXT_PTR 0xFE
43+
44+
// Undefined address extension
45+
#define XCP_ADDR_EXT_UNDEFINED 0xFF // Undefined address extension
2746

2847

2948
/*----------------------------------------------------------------------------*/

C_Demo/xcptl_cfg.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444

4545
// CTO size
4646
// Maximum size of a XCP command
47-
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4
47+
#define XCPTL_MAX_CTO_SIZE (248)
48+
// CRO_SHORT_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-8 should be %8==0
49+
// CRO_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-2
4850

4951
// DAQ transmit queue
5052
// Transmit queue size in segments, should at least be able to hold all data produced until the next call to HandleTransmitQueue

XCPlib/xcpAppl.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ uint8_t baseAddrValid = 0;
133133

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

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

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

254-
DBG_PRINTF1("Load %s\n", filename);
254+
DBG_PRINTF3("Load %s\n", filename);
255255

256256
#if defined(_LINUX) // Linux
257257

XCPlib/xcptl_cfg.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252

5353
// CTO size
5454
// Maximum size of a XCP command
55-
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4
56-
55+
#define XCPTL_MAX_CTO_SIZE (248)
56+
// CRO_SHORT_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-8 should be %8==0
57+
// CRO_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-2
5758

5859

5960

XCPlite/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main() {
104104
if (!XcpEthServerStatus()) { printf("\nXCP Server failed\n"); break; } // Check if the XCP server is running
105105

106106
if (!checkKeyboard()) {
107-
XcpSendEvent(EVC_SESSION_TERMINATED, NULL, 0);
107+
XcpSendEvent(PID_EV,EVC_SESSION_TERMINATED, NULL, 0);
108108
break;
109109
}
110110
}

XCPlite/main.h

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
34
/* main.h */
45
/*
56
| Code released into public domain, no attribution required
@@ -40,12 +41,6 @@
4041
#include <stdint.h>
4142
#include <inttypes.h>
4243
#include <math.h>
43-
44-
#ifdef _WIN
45-
#define M_PI 3.14159265358979323846
46-
#endif
47-
#define M_2PI (M_PI*2)
48-
4944
#include <assert.h>
5045

5146
#ifndef _WIN // Linux
@@ -54,35 +49,44 @@
5449
#include <string.h>
5550
#include <errno.h>
5651
#include <unistd.h>
57-
5852
#include <sys/time.h>
59-
#include <time.h>
53+
//#include <time.h>
54+
6055
#include <sys/stat.h>
6156
#include <pthread.h>
62-
63-
#include <ifaddrs.h>
64-
#include <fcntl.h>
65-
#include <netinet/in.h>
66-
#include <netinet/tcp.h>
57+
//#include <ifaddrs.h>
58+
//#include <fcntl.h>
59+
//#include <netinet/in.h>
60+
//#include <netinet/tcp.h>
6761
#include <arpa/inet.h>
6862
#include <sys/socket.h>
6963

70-
#define MAX_PATH 256
71-
#define BOOL int
72-
#define FALSE 0
73-
#define TRUE 1
64+
//#define MAX_PATH 256
7465

7566
#else // Windows
7667

7768
#include <windows.h>
7869
#include <time.h>
7970
#include <conio.h>
8071

72+
#endif
73+
74+
75+
#ifdef __cplusplus
76+
#include <typeinfo>
77+
#include <thread>
78+
#include <string>
79+
#include <vector>
80+
#endif
81+
8182
#define BOOL int
8283
#define FALSE 0
8384
#define TRUE 1
8485

86+
#ifdef _WIN
87+
#define M_PI 3.14159265358979323846
8588
#endif
89+
#define M_2PI (M_PI*2)
8690

8791
#include "main_cfg.h"
8892

XCPlite/xcp_cfg.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,30 @@
2020
//#define XCP_PROTOCOL_LAYER_VERSION 0x0103 // GET_DAQ_CLOCK_MULTICAST, GET_TIME_CORRELATION_PROPERTIES
2121
#define XCP_PROTOCOL_LAYER_VERSION 0x0104 // PACKED_MODE, CC_START_STOP_SYNCH prepare
2222

23+
2324
/*----------------------------------------------------------------------------*/
24-
/* Driver features */
25+
/* Adress, address extension coding */
26+
27+
// Use addr_ext XCP_ADDR_EXT_ABS to indicate absulute addr format (ApplXcpGetBaseAddr()+(uint32_t)addr)
28+
#define XCP_ENABLE_ABS_ADDRESSING
29+
#define XCP_ADDR_EXT_ABS 0x01 // Absolute address format
30+
31+
// Use addr_ext XCP_ADDR_EXT_DYN to indicate relative addr format (event<<16)|offset
32+
// #define XCP_ENABLE_DYN_ADDRESSING
33+
// #define XCP_ADDR_EXT_DYN 0x02 // Relative address format
34+
35+
// Use addr_ext XCP_ADDR_EXT_APP to indicate application specific addr format and use ApplXcpReadMemory and ApplXcpWriteMemory
36+
// #define XCP_ENABLE_APP_ADDRESSING
37+
// #define XCP_ADDR_EXT_APP 0x00 // Address format handled by application
2538

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

45+
// Undefined address extension
46+
#define XCP_ADDR_EXT_UNDEFINED 0xFF // Undefined address extension
2847

2948
/*----------------------------------------------------------------------------*/
3049
/* Protocol features */

XCPlite/xcptl_cfg.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252

5353
// CTO size
5454
// Maximum size of a XCP command
55-
#define XCPTL_MAX_CTO_SIZE 252 // must be mod 4
56-
57-
55+
#define XCPTL_MAX_CTO_SIZE (248)
56+
// CRO_SHORT_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-8 should be %8==0
57+
// CRO_DOWNLOAD_MAX_SIZE = XCPTL_MAX_CTO_SIZE-2
5858

5959

6060

0 commit comments

Comments
 (0)