Skip to content

Commit 01d79b6

Browse files
authored
Bugfixes (#25)
* Build breaks on Raspberry Pi fixed * Bugfix type detection, tA2lTypeId uin8_t, Warnings fixed * Problem fixed, when atomic_uint_fast32_t is larger than 4 byte * XCP_104.aml missing * xcplite.c pow and math.h removed * Math library missing for xcplib multi_thread_demo * Examples use the simplified macros for DAQ
1 parent 07092e7 commit 01d79b6

File tree

15 files changed

+1557
-202
lines changed

15 files changed

+1557
-202
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"stdatomic.h": "c"
4+
}
5+
}

XCP_104.aml

Lines changed: 1329 additions & 0 deletions
Large diffs are not rendered by default.

src/xcp/xcplib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ unsafe extern "C" {
99
unsafe extern "C" {
1010
pub fn XcpDisconnect();
1111
}
12+
pub type tXcpEventId = u16;
1213
unsafe extern "C" {
13-
pub fn XcpEventExt(event: u16, base: *const u8) -> u8;
14+
pub fn XcpEventExt(event: tXcpEventId, base: *const u8) -> u8;
1415
}
1516
unsafe extern "C" {
16-
pub fn XcpEvent(event: u16);
17+
pub fn XcpEvent(event: tXcpEventId);
1718
}
1819
unsafe extern "C" {
1920
pub fn XcpSendTerminateSessionEvent();

xcplib/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
/C_Demo.a2l
44
/hello_xcp.a2l
5+
/struct_demo.a2l
6+
/multi_thread_demo.a2l

xcplib/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ target_compile_options(xcplib
5353
-Wall
5454
-Wextra
5555
-Wconversion
56-
-Werror
56+
# -Werror
5757
-pedantic
5858
# -Wshadow
5959
)
@@ -86,6 +86,8 @@ if (WINDOWS)
8686

8787
else ()
8888

89+
target_link_libraries(multi_thread_demo PRIVATE m)
90+
8991
set_target_properties(c_demo PROPERTIES SUFFIX ".out")
9092
set_target_properties(hello_xcp PROPERTIES SUFFIX ".out")
9193
set_target_properties(struct_demo PROPERTIES SUFFIX ".out")

xcplib/examples/c_demo/src/main.c

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
#define OPTION_USE_TCP false // TCP or UDP
2020
#define OPTION_SERVER_PORT 5555 // Port
2121
// #define OPTION_SERVER_ADDR {0, 0, 0, 0} // Bind addr, 0.0.0.0 = ANY
22-
// #define OPTION_SERVER_ADDR {127, 0, 0, 1} // Bind addr, 0.0.0.0 = ANY
23-
#define OPTION_SERVER_ADDR {172, 19, 13, 239} // Bind addr, 0.0.0.0 = ANY
24-
#define OPTION_QUEUE_SIZE 1024 * 32 // Size of the measurement queue in bytes, must be a multiple of 8
22+
#define OPTION_SERVER_ADDR {127, 0, 0, 1} // Bind addr, 0.0.0.0 = ANY
23+
#define OPTION_QUEUE_SIZE 1024 * 32 // Size of the measurement queue in bytes, must be a multiple of 8
2524
#define OPTION_LOG_LEVEL 3
2625

2726
//-----------------------------------------------------------------------------------------------------
@@ -40,11 +39,6 @@ const params_t params = {.counter_max = 100, .delay_us = 1000, .test_byte1 = -1,
4039

4140
//-----------------------------------------------------------------------------------------------------
4241

43-
// Global demo measurement variable
44-
static uint16_t counter_global = 0;
45-
46-
//-----------------------------------------------------------------------------------------------------
47-
4842
// Demo main
4943
int main(void) {
5044

@@ -83,13 +77,6 @@ int main(void) {
8377
A2lCreateCurve(params.curve, 8, "", "");
8478
A2lCreateMap(params.map, 8, 8, "", "");
8579

86-
// Create a measurement event for global variables
87-
uint16_t event_global = XcpCreateEvent("mainloop_global", 0, 0);
88-
89-
// Register global measurement variables
90-
A2lSetAbsAddrMode(); // Set absolute addressing
91-
A2lCreatePhysMeasurement(counter_global, "Measurement variable", 1.0, 0.0, "counts");
92-
9380
// Variables on stack
9481
uint8_t counter8 = 0;
9582
uint16_t counter16 = 0;
@@ -101,18 +88,18 @@ int main(void) {
10188
int64_t counter64s = 0;
10289

10390
// Create a measurement event for local variables
104-
uint16_t event = XcpCreateEvent("mainloop_local", 0, 0);
91+
DaqCreateEvent(mainloop);
10592

10693
// Register measurement variables located on stack
107-
A2lSetDynAddrMode(&event); // Set event relative addressing with write access
108-
A2lCreatePhysMeasurement(counter8, "Measurement variable", 1.0, 0.0, "counts");
109-
A2lCreatePhysMeasurement(counter16, "Measurement variable", 1.0, 0.0, "counts");
110-
A2lCreatePhysMeasurement(counter32, "Measurement variable", 1.0, 0.0, "counts");
111-
A2lCreatePhysMeasurement(counter64, "Measurement variable", 1.0, 0.0, "counts");
112-
A2lCreatePhysMeasurement(counter8s, "Measurement variable", 1.0, 0.0, "counts");
113-
A2lCreatePhysMeasurement(counter16s, "Measurement variable", 1.0, 0.0, "counts");
114-
A2lCreatePhysMeasurement(counter32s, "Measurement variable", 1.0, 0.0, "counts");
115-
A2lCreatePhysMeasurement(counter64s, "Measurement variable", 1.0, 0.0, "counts");
94+
A2lSetStackAddrMode(mainloop);
95+
A2lCreatePhysMeasurement(counter8, "Measurement variable", 1.0, 0.0, "");
96+
A2lCreatePhysMeasurement(counter16, "Measurement variable", 1.0, 0.0, "");
97+
A2lCreatePhysMeasurement(counter32, "Measurement variable", 1.0, 0.0, "");
98+
A2lCreatePhysMeasurement(counter64, "Measurement variable", 1.0, 0.0, "");
99+
A2lCreatePhysMeasurement(counter8s, "Measurement variable", 1.0, 0.0, "");
100+
A2lCreatePhysMeasurement(counter16s, "Measurement variable", 1.0, 0.0, "");
101+
A2lCreatePhysMeasurement(counter32s, "Measurement variable", 1.0, 0.0, "");
102+
A2lCreatePhysMeasurement(counter64s, "Measurement variable", 1.0, 0.0, "");
116103

117104
// Multidimensional measurements on stack
118105
float curve_f32[8] = {000, 100, 200, 300, 400, 500, 600, 700};
@@ -124,9 +111,8 @@ int main(void) {
124111

125112
};
126113

127-
A2lSetDynAddrMode(&event); // Set event relative addressing with write access
128114
A2lCreateMeasurementArray(curve_f32, "array float[8]");
129-
A2lCreateMeasurementMatrix(map_f32, "matrix float[8][8]");
115+
A2lCreateMeasurementMatrix(map_f32, "matrix float[4][8]");
130116

131117
// Create a measurement typedef for the calibration parameter struct
132118
A2lTypedefBegin(params_t, "The calibration parameter struct as measurement typedef");
@@ -155,10 +141,10 @@ int main(void) {
155141
if (curve_f32[i] > 2000) {
156142
curve_f32[i] = 0;
157143
}
158-
for (int j = 0; j < 8; j++) {
159-
map_f32[i][j] += i + j;
160-
if (map_f32[i][j] > 2000) {
161-
map_f32[i][j] = 0;
144+
for (int j = 0; j < 4; j++) {
145+
map_f32[j][i] += i + j;
146+
if (map_f32[j][i] > 2000) {
147+
map_f32[j][i] = 0;
162148
}
163149
}
164150
}
@@ -187,12 +173,8 @@ int main(void) {
187173
// Unlock the calibration segment
188174
XcpUnlockCalSeg(calseg);
189175

190-
// Global variable
191-
counter_global = counter16;
192-
193-
// Trigger measurement events
194-
XcpEventDyn(&event); // For local variables
195-
XcpEvent(event_global); // For global variables
176+
// Trigger the measurement event
177+
DaqEvent(mainloop);
196178

197179
// Check server status
198180
if (!XcpEthServerStatus()) {
@@ -202,7 +184,7 @@ int main(void) {
202184

203185
A2lFinalize(); // Optional: Finalize the A2L file generation early, to write the A2L now, not when the client connects
204186

205-
} // for(;;)
187+
} // for (;;)
206188

207189
// Force disconnect the XCP client
208190
XcpDisconnect();

xcplib/examples/hello_xcp/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ int main(void) {
7878
A2lCreateParameterWithLimits(params.delay_us, "mainloop delay time in us", "us", 0, 1000000);
7979

8080
// Create a measurement event
81-
uint16_t event = XcpCreateEvent("mainloop", 0, 0);
81+
DaqCreateEvent(mainloop);
8282

8383
// Register a global measurement variable
84-
A2lSetAbsAddrMode(); // Set absolute addressing
84+
A2lSetAbsoluteAddrMode(mainloop); // Set absolute addressing
8585
A2lCreatePhysMeasurement(counter, "Measurement variable", 1.0, 0.0, "counts");
8686

8787
A2lFinalize(); // Optional: Finalize the A2L file generation early, to write the A2L now, not when the client connects
@@ -105,7 +105,7 @@ int main(void) {
105105
XcpUnlockCalSeg(calseg);
106106

107107
// Trigger measurement events
108-
XcpEvent(event);
108+
DaqEvent(mainloop);
109109

110110
} // for(;;)
111111

xcplib/examples/multi_thread_demo/src/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
#define OPTION_USE_TCP false // TCP or UDP
2626
#define OPTION_SERVER_PORT 5555 // Port
2727
// #define OPTION_SERVER_ADDR {0, 0, 0, 0} // Bind addr, 0.0.0.0 = ANY
28-
// #define OPTION_SERVER_ADDR {127, 0, 0, 1} // Bind addr, 0.0.0.0 = ANY
29-
// #define OPTION_SERVER_ADDR {172, 19, 13, 239} // Bind addr, 0.0.0.0 = ANY
30-
#define OPTION_SERVER_ADDR {192, 168, 0, 128} // Bind addr, 0.0.0.0 = ANY
31-
#define OPTION_QUEUE_SIZE 1024 * 32 // Size of the measurement queue in bytes, must be a multiple of 8
28+
#define OPTION_SERVER_ADDR {127, 0, 0, 1} // Bind addr, 0.0.0.0 = ANY
29+
#define OPTION_QUEUE_SIZE 1024 * 32 // Size of the measurement queue in bytes, must be a multiple of 8
3230
#define OPTION_LOG_LEVEL 3
3331

3432
//-----------------------------------------------------------------------------------------------------

xcplib/examples/struct_demo/src/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#define OPTION_USE_TCP false // TCP or UDP
2121
#define OPTION_SERVER_PORT 5555 // Port
2222
// #define OPTION_SERVER_ADDR {0, 0, 0, 0} // Bind addr, 0.0.0.0 = ANY
23-
// #define OPTION_SERVER_ADDR {127, 0, 0, 1} // Bind addr, 0.0.0.0 = ANY
24-
// #define OPTION_SERVER_ADDR {172, 19, 13, 239} // Bind addr, 0.0.0.0 = ANY
25-
#define OPTION_SERVER_ADDR {192, 168, 0, 128} // Bind addr, 0.0.0.0 = ANY
26-
#define OPTION_QUEUE_SIZE 1024 * 32 // Size of the measurement queue in bytes, must be a multiple of 8
23+
#define OPTION_SERVER_ADDR {127, 0, 0, 1} // Bind addr, 0.0.0.0 = ANY
24+
#define OPTION_QUEUE_SIZE 1024 * 32 // Size of the measurement queue in bytes, must be a multiple of 8
2725
#define OPTION_LOG_LEVEL 4
2826

2927
//-----------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)