Skip to content

Commit 082604c

Browse files
committed
Arduino Ethernet driver now working
1 parent 681bf8f commit 082604c

File tree

5 files changed

+82
-77
lines changed

5 files changed

+82
-77
lines changed

inc/xcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ extern "C" {
14321432
*/
14331433
void Serial_Init(void);
14341434
void Serial_DeInit(void);
1435-
bool Serial_Available(void);
1435+
uint32_t Serial_Available(void);
14361436
bool Serial_Read(uint8_t *in_byte);
14371437
void Serial_WriteByte(uint8_t out_byte);
14381438
void Serial_WriteBuffer(uint8_t const *out_bytes, uint32_t size);

src/tl/eth/arduino_networking.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ class EthernetUdpClientWrapper : public ClientWrapper {
181181
uint8_t m_buf[XCP_COMM_BUFLEN];
182182
size_t m_size;
183183
size_t m_offset;
184-
EthernetUdpClientWrapper m_udpClientWrapper;
185184
};
186185

187186
class EthernetAdapter : public ArduinoNetworkIf {
@@ -257,6 +256,7 @@ class EthernetAdapter : public ArduinoNetworkIf {
257256
IPAddress m_ip;
258257
uint16_t m_port;
259258
EthernetUDP m_udp;
259+
EthernetUdpClientWrapper m_udpClientWrapper; // preallocated UDP client wrapper
260260
};
261261
#endif // XCP_ON_ETHERNET_ARDUINO_DRIVER == XCP_ON_ETHERNET_DRIVER_ETHERNET
262262

@@ -493,8 +493,14 @@ extern "C" {
493493
#if XCP_ON_ETHERNET_ARDUINO_DRIVER == XCP_ON_ETHERNET_DRIVER_WIFI
494494
s_net = new WiFiAdapter(XCP_ON_ETHERNET_WIFI_SSID, XCP_ON_ETHERNET_WIFI_PASSWORD, XCP_ON_ETHERNET_PORT);
495495
#else
496-
#if defined(XCP_ON_ETHERNET_IP)
497-
s_net = new EthernetAdapter(IPAddress(XCP_ON_ETHERNET_IP), XCP_ON_ETHERNET_PORT);
496+
#if defined(XCP_ON_ETHERNET_IP_OCTETS)
497+
s_net = new EthernetAdapter(IPAddress(XCP_ON_ETHERNET_IP_OCTETS), XCP_ON_ETHERNET_PORT);
498+
#elif defined(XCP_ON_ETHERNET_IP)
499+
{
500+
IPAddress ip;
501+
ip.fromString(XCP_ON_ETHERNET_IP);
502+
s_net = new EthernetAdapter(ip, XCP_ON_ETHERNET_PORT);
503+
}
498504
#else
499505
s_net = new EthernetAdapter(XCP_ON_ETHERNET_PORT);
500506
#endif

src/xcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ XCP_STATIC void Xcp_SlaveBlockTransferSetActive(bool onOff) {
870870
void Xcp_UploadSingleBlock(void) {
871871
uint8_t *dataOut = XCP_NULL;
872872
uint8_t length = UINT8(0x00);
873-
Xcp_MtaType dst = { 0 };
873+
Xcp_MtaType dst = { 0,0 };
874874

875875
if (!Xcp_SlaveBlockTransferIsActive()) {
876876
return;

tools/arduino/hello_xcp/xcp_config.h

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,75 @@
3535
** General Options.
3636
*/
3737
// #define TP_CAN
38-
// #define TP_ETHER
39-
#define TP_SXI
38+
#define TP_ETHER
39+
//#define TP_SXI
4040

41-
#define XCP_CAN_INTERFACE (XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD)
41+
/*
42+
** Transport-Layer specific Options.
43+
*/
44+
#if defined(TP_CAN)
45+
#define XCP_TRANSPORT_LAYER XCP_ON_CAN
46+
#define XCP_CAN_INTERFACE (XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD)
47+
48+
#define XCP_ON_CAN_INBOUND_IDENTIFIER (0x300)
49+
#define XCP_ON_CAN_OUTBOUND_IDENTIFIER (0x301)
50+
#define XCP_ON_CAN_MAX_DLC_REQUIRED (XCP_OFF)
51+
#define XCP_ON_CAN_BROADCAST_IDENTIFIER (0x222)
52+
53+
// Chip-Select- and Interrupt-Pins / SeeedStudio CAN Shield v2.
54+
#define XCP_CAN_IF_MCP25XX_PIN_CS (9)
55+
#define XCP_CAN_IF_MCP25XX_PIN_INT (2)
56+
57+
#define XCP_ON_CAN_FREQ (CAN_500KBPS)
58+
#define XCP_ON_CAN_BTQ (16)
59+
#define XCP_ON_CAN_TSEG1 (14)
60+
#define XCP_ON_CAN_TSEG2 (2)
61+
#define XCP_ON_CAN_SJW (2)
62+
#define XCP_ON_CAN_NOSAMP (1)
63+
64+
/* Transport-Layer Commands. */
65+
#define XCP_ENABLE_CAN_GET_SLAVE_ID (XCP_ON)
66+
#define XCP_ENABLE_CAN_GET_DAQ_ID (XCP_ON)
67+
#define XCP_ENABLE_CAN_SET_DAQ_ID (XCP_OFF)
68+
69+
#elif defined(TP_BLUETOOTH)
70+
#define XCP_TRANSPORT_LAYER XCP_ON_BTH
71+
72+
#define XCP_MAX_CTO (64) // (16)
73+
#define XCP_MAX_DTO (64)
74+
75+
#elif defined(TP_ETHER)
76+
#define XCP_TRANSPORT_LAYER XCP_ON_ETHERNET
77+
78+
#define XCP_ON_ETHERNET_IP_OCTETS 192, 168, 137, 100
79+
#define XCP_ON_ETHERNET_PORT (5555)
80+
81+
#define XCP_ON_ETHERNET_ARDUINO_DRIVER (XCP_ON_ETHERNET_DRIVER_ETHERNET)
82+
#define XCP_ON_ETHERNET_WIFI_SSID ("")
83+
#define XCP_ON_ETHERNET_WIFI_PASSWORD ("")
84+
#define XCP_ON_ETHERNET_MAC_ADDRESS { 0xBE, 0xEF, 0xCA, 0xAA, 0xFF, 0xFE }
85+
86+
#define XCP_MAX_CTO (32) // (16)
87+
#define XCP_MAX_DTO (32)
88+
89+
#elif defined(TP_SXI) || (XCP_TRANSPORT_LAYER == XCP_ON_SXI)
90+
/* Allow command-line or parent CMake to override these via -D defines */
91+
#define XCP_TRANSPORT_LAYER XCP_ON_SXI
92+
#define XCP_ON_SXI_HEADER_FORMAT (XCP_ON_SXI_HEADER_LEN_CTR_WORD)
93+
#define XCP_ON_SXI_BITRATE (38400)
94+
#define XCP_ON_SXI_CONFIG (SERIAL_8N1)
95+
#define XCP_MAX_CTO (64)
96+
#define XCP_MAX_DTO (64)
97+
#define XCP_ON_SXI_TAIL_CHECKSUM (XCP_ON_SXI_NO_CHECKSUM)
98+
/* Framing and escaping (as used by xcp_tl.c) */
99+
#define XCP_ON_SXI_ENABLE_FRAMING (XCP_OFF)
100+
#define XCP_ON_SXI_SYNC_CHAR (0xAA)
101+
#define XCP_ON_SXI_ESC_CHAR (0xAB)
102+
#define XCP_ON_SXI_ESC_SYNC_CHAR (0x01)
103+
#define XCP_ON_SXI_ESC_ESC_CHAR (0x00)
104+
#else
105+
#error "No transport-layer. please define either TP_ETHER, TP_CAN, or TP_BLUETOOTH."
106+
#endif // KVASER_CAN
42107

43108
#define XCP_GET_ID_0 "BlueParrot XCP running on Arduino"
44109
#define XCP_GET_ID_1 "BlueParrot_XCP_on_Arduino"
@@ -165,72 +230,6 @@
165230
#define XCP_ENABLE_EVENT_PACKET_API (XCP_ON)
166231
#define XCP_ENABLE_SERVICE_REQUEST_API (XCP_OFF)
167232

168-
/*
169-
** Transport-Layer specific Options (may not apply to every Transport).
170-
*/
171-
#if defined(TP_CAN)
172-
#define XCP_TRANSPORT_LAYER XCP_ON_CAN
173-
174-
#define XCP_ON_CAN_INBOUND_IDENTIFIER (0x300)
175-
#define XCP_ON_CAN_OUTBOUND_IDENTIFIER (0x301)
176-
#define XCP_ON_CAN_MAX_DLC_REQUIRED (XCP_OFF)
177-
#define XCP_ON_CAN_BROADCAST_IDENTIFIER (0x222)
178-
179-
// Chip-Select- and Interrupt-Pins / SeeedStudio CAN Shield v2.
180-
#define XCP_CAN_IF_MCP25XX_PIN_CS (9)
181-
#define XCP_CAN_IF_MCP25XX_PIN_INT (2)
182-
183-
#define XCP_ON_CAN_FREQ (CAN_500KBPS)
184-
#define XCP_ON_CAN_BTQ (16)
185-
#define XCP_ON_CAN_TSEG1 (14)
186-
#define XCP_ON_CAN_TSEG2 (2)
187-
#define XCP_ON_CAN_SJW (2)
188-
#define XCP_ON_CAN_NOSAMP (1)
189-
190-
/* Transport-Layer Commands. */
191-
#define XCP_ENABLE_CAN_GET_SLAVE_ID (XCP_ON)
192-
#define XCP_ENABLE_CAN_GET_DAQ_ID (XCP_ON)
193-
#define XCP_ENABLE_CAN_SET_DAQ_ID (XCP_OFF)
194-
195-
#elif defined(TP_BLUETOOTH)
196-
#define XCP_TRANSPORT_LAYER XCP_ON_BTH
197-
198-
#define XCP_MAX_CTO (64) // (16)
199-
#define XCP_MAX_DTO (64)
200-
201-
#elif defined(TP_ETHER)
202-
#define XCP_TRANSPORT_LAYER XCP_ON_ETHERNET
203-
204-
#define XCP_ON_ETHERNET_IP (192, 168, 0, 100)
205-
#define XCP_ON_ETHERNET_PORT (5555)
206-
207-
#define XCP_ON_ETHERNET_ARDUINO_DRIVER (XCP_ON_ETHERNET_DRIVER_ETHERNET)
208-
#define XCP_ON_ETHERNET_WIFI_SSID ("")
209-
#define XCP_ON_ETHERNET_WIFI_PASSWORD ("")
210-
#define XCP_ON_ETHERNET_MAC_ADDRESS { 0xBE, 0xEF, 0xCA, 0xAA, 0xFF, 0xFE }
211-
212-
#define XCP_MAX_CTO (64) // (16)
213-
#define XCP_MAX_DTO (64)
214-
215-
#elif defined(TP_SXI) || (XCP_TRANSPORT_LAYER == XCP_ON_SXI)
216-
/* Allow command-line or parent CMake to override these via -D defines */
217-
#define XCP_TRANSPORT_LAYER XCP_ON_SXI
218-
#define XCP_ON_SXI_HEADER_FORMAT (XCP_ON_SXI_HEADER_LEN_CTR_WORD)
219-
#define XCP_ON_SXI_BITRATE (38400)
220-
#define XCP_ON_SXI_CONFIG (SERIAL_8N1)
221-
#define XCP_MAX_CTO (64)
222-
#define XCP_MAX_DTO (64)
223-
#define XCP_ON_SXI_TAIL_CHECKSUM (XCP_ON_SXI_NO_CHECKSUM)
224-
/* Framing and escaping (as used by xcp_tl.c) */
225-
#define XCP_ON_SXI_ENABLE_FRAMING (XCP_OFF)
226-
#define XCP_ON_SXI_SYNC_CHAR (0xAA)
227-
#define XCP_ON_SXI_ESC_CHAR (0xAB)
228-
#define XCP_ON_SXI_ESC_SYNC_CHAR (0x01)
229-
#define XCP_ON_SXI_ESC_ESC_CHAR (0x00)
230-
#else
231-
#error "No transport-layer. please define either TP_ETHER, TP_CAN, or TP_BLUETOOTH."
232-
#endif // KVASER_CAN
233-
234233
/*
235234
** Customization Options.
236235
*/

tools/xcp_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@
7575
#elif defined(TP_ETHER)
7676
#define XCP_TRANSPORT_LAYER XCP_ON_ETHERNET
7777

78-
#define XCP_ON_ETHERNET_IP (192, 168, 0, 100)
78+
#define XCP_ON_ETHERNET_IP_OCTETS 192, 168, 137, 100
7979
#define XCP_ON_ETHERNET_PORT (5555)
8080

8181
#define XCP_ON_ETHERNET_ARDUINO_DRIVER (XCP_ON_ETHERNET_DRIVER_ETHERNET)
8282
#define XCP_ON_ETHERNET_WIFI_SSID ("")
8383
#define XCP_ON_ETHERNET_WIFI_PASSWORD ("")
8484
#define XCP_ON_ETHERNET_MAC_ADDRESS { 0xBE, 0xEF, 0xCA, 0xAA, 0xFF, 0xFE }
8585

86-
#define XCP_MAX_CTO (64) // (16)
87-
#define XCP_MAX_DTO (64)
86+
#define XCP_MAX_CTO (32) // (16)
87+
#define XCP_MAX_DTO (32)
8888

8989
#elif defined(TP_SXI) || (XCP_TRANSPORT_LAYER == XCP_ON_SXI)
9090
/* Allow command-line or parent CMake to override these via -D defines */

0 commit comments

Comments
 (0)