Skip to content

Commit 5c48ce8

Browse files
committed
Support custom SxI interface on Arduino
1 parent 89dce95 commit 5c48ce8

File tree

10 files changed

+170
-160
lines changed

10 files changed

+170
-160
lines changed

docs/tutorial.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ Prerequisites
3333
^^^^^^^^^^^^^^^^^^^^^
3434
Open the sketch folder (e.g., ``tools/arduino/hello_xcp``) and edit its ``xcp_config.h``,
3535
un-comment the transport you want to use:
36+
3637
- `#define TP_SXI` for Serial SXI.
38+
3739
- `#define TP_CAN` for CAN bus.
40+
3841
- `#define TP_ETHER` for Ethernet.
3942

4043
Now fill the minimal settings:

inc/xcp.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ extern "C" {
267267
#else
268268
#error "Unknown XCP_ON_SXI_TAIL_CHECKSUM value."
269269
#endif
270+
271+
#if !defined(XCP_ON_SXI_CUSTOM_INTERFACE)
272+
#define XCP_ON_SXI_CUSTOM_INTERFACE (XCP_OFF)
273+
#endif
274+
275+
#if !defined(XCP_ON_SXI_PORT_NAME)
276+
#define XCP_ON_SXI_PORT_NAME Serial
277+
#endif
270278
#elif (XCP_TRANSPORT_LAYER == XCP_ON_ETHERNET) || (XCP_TRANSPORT_LAYER == XCP_ON_BTH)
271279
#define XCP_TRANSPORT_LAYER_CHECKSUM_SIZE (0)
272280
#else
@@ -1430,13 +1438,13 @@ extern "C" {
14301438
/*
14311439
** Serial Port Function Prototypes.
14321440
*/
1433-
void Serial_Init(void);
1434-
void Serial_DeInit(void);
1441+
void Serial_Init(void);
1442+
void Serial_DeInit(void);
14351443
uint32_t Serial_Available(void);
1436-
bool Serial_Read(uint8_t *in_byte);
1437-
void Serial_WriteByte(uint8_t out_byte);
1438-
void Serial_WriteBuffer(uint8_t const *out_bytes, uint32_t size);
1439-
void Serial_MainFunction(void);
1444+
bool Serial_Read(uint8_t *in_byte);
1445+
void Serial_WriteByte(uint8_t out_byte);
1446+
void Serial_WriteBuffer(uint8_t const *out_bytes, uint32_t size);
1447+
void Serial_MainFunction(void);
14401448

14411449
#endif
14421450

inc/xcp_types.h

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,90 +24,90 @@
2424
*/
2525

2626
#if !defined(__XCP_TYPES_H)
27-
#define __XCP_TYPES_H
27+
#define __XCP_TYPES_H
2828

29-
#include <limits.h>
29+
#include <limits.h>
3030

31-
#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON
32-
#if defined(__cplusplus)
31+
#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON
32+
#if defined(__cplusplus)
3333
extern "C" {
34-
#endif /* __cplusplus */
35-
#endif /* XCP_EXTERN_C_GUARDS */
36-
37-
/* check for C99-Compiler */
38-
#if defined(__STDC_VERSION__)
39-
#if __STDC_VERSION__ >= 199901L
40-
#define C99_COMPILER
41-
#endif
42-
#endif
43-
44-
/* check for C1x-Compiler */
45-
#if defined(__STDC_VERSION__)
46-
#if __STDC_VERSION__ >= 201112L
47-
#define C11_COMPILER
48-
#endif
49-
#endif
50-
51-
#if (defined(__CSMC__) || (!defined(C99_COMPILER) && !defined(C11_COMPILER))) && !defined(__cplusplus)
52-
53-
#if defined(_MSC_VER)
54-
55-
#include <stdbool.h>
56-
#include <stdint.h>
57-
#else
34+
#endif /* __cplusplus */
35+
#endif /* XCP_EXTERN_C_GUARDS */
36+
37+
/* check for C99-Compiler */
38+
#if defined(__STDC_VERSION__)
39+
#if __STDC_VERSION__ >= 199901L
40+
#define C99_COMPILER
41+
#endif
42+
#endif
43+
44+
/* check for C1x-Compiler */
45+
#if defined(__STDC_VERSION__)
46+
#if __STDC_VERSION__ >= 201112L
47+
#define C11_COMPILER
48+
#endif
49+
#endif
50+
51+
#if (defined(__CSMC__) || (!defined(C99_COMPILER) && !defined(C11_COMPILER))) && !defined(__cplusplus)
52+
53+
#if defined(_MSC_VER)
54+
55+
#include <stdbool.h>
56+
#include <stdint.h>
57+
#else
5858
typedef unsigned char bool;
59-
#if !defined(__int8_t_defined)
60-
typedef signed char int8_t;
59+
#if !defined(__int8_t_defined)
60+
typedef signed char int8_t;
6161
typedef unsigned char uint8_t;
62-
#endif
63-
#if !defined(__int16_t_defined)
64-
typedef signed short int16_t;
62+
#endif
63+
#if !defined(__int16_t_defined)
64+
typedef signed short int16_t;
6565
typedef unsigned short uint16_t;
66-
#endif
67-
#if !defined(__int32_t_defined)
68-
typedef signed long int32_t;
66+
#endif
67+
#if !defined(__int32_t_defined)
68+
typedef signed long int32_t;
6969
typedef unsigned long uint32_t;
70-
#endif
71-
#if !defined(__int64_t_defined)
72-
typedef signed long long int64_t;
70+
#endif
71+
#if !defined(__int64_t_defined)
72+
typedef signed long long int64_t;
7373
typedef unsigned long long uint64_t;
74-
#endif
75-
#endif
74+
#endif
75+
#endif
7676

77-
#else
77+
#else
7878

79-
#include <stdbool.h>
80-
#include <stdint.h>
81-
#endif
79+
#include <stdbool.h>
80+
#include <stdint.h>
81+
#endif
8282

83-
/* 64-bit */
84-
#if UINTPTR_MAX == 0xffffffffffffffff
85-
#define ENV64BIT
86-
typedef uint64_t Xcp_PointerSizeType;
87-
#elif UINTPTR_MAX == 0xffffffff
83+
/* 64-bit */
84+
#if UINTPTR_MAX == 0xffffffffffffffff
85+
#define ENV64BIT
86+
typedef uint64_t Xcp_PointerSizeType;
87+
#elif UINTPTR_MAX == 0xffffffff
8888
typedef uint32_t Xcp_PointerSizeType;
89-
#define ENV32BIT
90-
#else
91-
#define ENV16BIT
89+
#define ENV32BIT
90+
#else
91+
#define ENV16BIT
9292
typedef uint32_t Xcp_PointerSizeType;
93-
#endif
93+
#endif
9494

95-
#define UINT8(x) ((uint8_t)(x))
96-
#define INT8(x) ((int8_t)(x))
95+
#define UINT8(x) ((uint8_t)(x))
96+
#define INT8(x) ((int8_t)(x))
9797

98-
#define UINT16(x) ((uint16_t)(x))
99-
#define INT16(x) ((int16_t)(x))
98+
#define UINT16(x) ((uint16_t)(x))
99+
#define INT16(x) ((int16_t)(x))
100100

101-
#define UINT32(x) ((uint32_t)(x))
102-
#define INT32(x) ((int32_t)(x))
101+
#define UINT32(x) ((uint32_t)(x))
102+
#define INT32(x) ((int32_t)(x))
103103

104-
#define UINT64(x) ((uint64_t)(x))
105-
#define INT64(x) ((int64_t)(x))
104+
#define UINT64(x) ((uint64_t)(x))
105+
#define INT64(x) ((int64_t)(x))
106106

107-
#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON
108-
#if defined(__cplusplus)
107+
#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON
108+
#if defined(__cplusplus)
109109
}
110-
#endif /* __cplusplus */
111-
#endif /* XCP_EXTERN_C_GUARDS */
110+
#endif /* __cplusplus */
111+
#endif /* XCP_EXTERN_C_GUARDS */
112112

113113
#endif /* __XCP_TYPES_H */

src/hw/arduino/.idea/arduino.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tl/sxi/arduino_serial.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
* s. FLOSS-EXCEPTION.txt
2424
*/
2525

26+
/*!!! START-INCLUDE-SECTION !!!*/
27+
#include "xcp.h"
28+
#include "xcp_tl_timeout.h"
29+
#include "xcp_util.h"
30+
/*!!! END-INCLUDE-SECTION !!!*/
31+
2632
#if (XCP_TRANSPORT_LAYER == XCP_ON_SXI) && (defined(ARDUINO))
2733

2834
#include "Arduino.h"
29-
#include "xcp_config.h"
30-
31-
/*!!! START-INCLUDE-SECTION !!!*/
32-
#include "xcp.h"
33-
#include "xcp_tl_timeout.h"
34-
#include "xcp_util.h"
35-
/*!!! END-INCLUDE-SECTION !!!*/
3635

3736
extern "C" {
3837

38+
#if XCP_ON_SXI_CUSTOM_INTERFACE == XCP_OFF
39+
3940
void Serial_Init(void) {
4041
Serial.begin(XCP_ON_SXI_BITRATE, XCP_ON_SXI_CONFIG);
4142
}
@@ -66,6 +67,8 @@ extern "C" {
6667
Serial.write(out_bytes, size);
6768
}
6869

70+
#endif /* XCP_ON_SXI_CUSTOM_INTERFACE == XCP_OFF */
71+
6972
void Serial_MainFunction(void) {
7073
}
7174
}

0 commit comments

Comments
 (0)