From 5197166f23f97c3c25b35b96bbd290c6fef8a206 Mon Sep 17 00:00:00 2001 From: Christoph Schueler Date: Mon, 20 May 2024 01:59:00 -0400 Subject: [PATCH] Update Arduino driver --- inc/queue.h | 118 ---------- inc/xcp.h | 23 +- src/tl/can/arduino_can.cpp | 112 ++++++--- src/xcp_daq.c | 45 ++-- tools/amalgam8.py | 1 + tools/arduino/hello_xcp/hello_xcp.ino | 34 +-- tools/arduino/hello_xcp/xcp.h | 326 +++++++++++--------------- tools/arduino/hello_xcp/xcp_config.h | 38 +-- tools/build.cmd | 3 +- tools/xcp_config.h | 25 +- 10 files changed, 316 insertions(+), 409 deletions(-) delete mode 100644 inc/queue.h diff --git a/inc/queue.h b/inc/queue.h deleted file mode 100644 index 67ceb3e..0000000 --- a/inc/queue.h +++ /dev/null @@ -1,118 +0,0 @@ - -#ifndef CXCP_QUEUE_HPP -#define CXCP_QUEUE_HPP - -template -class Queue { - public: - - explicit Queue(size_t size) { - arr = new T[size]; - m_capacity = size; - m_front = 0; - m_rear = -1; - m_count = 0; - } - - Queue() = delete; - - ~Queue() { - delete[] arr; - } - - T pop() { - if (isEmpty()) { - exit(EXIT_FAILURE); - } - T x = arr[m_front]; - - m_front = (m_front + 1) % m_capacity; - m_count--; - - return x; - } - - void push(const T &item) { - if (isFull()) { - exit(EXIT_FAILURE); - } - - m_rear = (m_rear + 1) % m_capacity; - arr[m_rear] = item; - m_count++; - } -#if 0 - T peek() { - if (isEmpty()) { - exit(EXIT_FAILURE); - } - return arr[m_front]; - } -#endif - size_t size() { - return m_count; - } - - bool isEmpty() { - return (size() == 0); - } - - bool isFull() { - return (size() == m_capacity); - } - - private: - - T *arr; - size_t m_capacity; - int m_front; - int m_rear; - size_t m_count; -}; - -template -class Observers { - public: - - explicit Observers(size_t size) { - arr = new T[size]; - m_capacity = size; - m_count = 0; - } - - Observers() = delete; - - ~Observers() { - delete[] arr; - } - - void append(const T &item) { - if (isFull()) { - exit(EXIT_FAILURE); - } - arr[m_count++] = item; - } - - bool isFull() { - return (size() == m_capacity); - } - - size_t size() { - return m_count; - } - - template - void notify(const V &value) { - for (size_t i = 0; i < m_capacity; ++i) { - arr[i]->update(value); - } - } - - private: - - T *arr; - size_t m_capacity; - size_t m_count; -}; - -#endif // CXCP_QUEUE_HPP diff --git a/inc/xcp.h b/inc/xcp.h index 7798c75..7820d52 100644 --- a/inc/xcp.h +++ b/inc/xcp.h @@ -106,8 +106,7 @@ extern "C" { #if XCP_TRANSPORT_LAYER == XCP_ON_CAN - #if ((XCP_ENABLE_CAN_GET_SLAVE_ID == XCP_ON) || (XCP_ENABLE_CAN_GET_DAQ_ID == XCP_ON) || \ - (XCP_ENABLE_CAN_SET_DAQ_ID == XCP_ON)) + #if ((XCP_ENABLE_CAN_GET_SLAVE_ID == XCP_ON) || (XCP_ENABLE_CAN_GET_DAQ_ID == XCP_ON) || (XCP_ENABLE_CAN_SET_DAQ_ID == XCP_ON)) #define XCP_ENABLE_TRANSPORT_LAYER_CMD (XCP_ON) #endif @@ -270,7 +269,7 @@ extern "C" { #define XCP_MIN_ST_PGM (0) #endif /* XCP_MIN_ST_PGM */ - #define XCP_DOWNLOAD_PAYLOAD_LENGTH ((XCP_MAX_CTO) - 2) + #define XCP_DOWNLOAD_PAYLOAD_LENGTH ((XCP_MAX_CTO)-2) /* * Packet Identifiers. @@ -497,7 +496,7 @@ extern "C" { /* ** XCPonCAN specific function-like macros. */ - #define XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(i) (((i) & XCP_ON_CAN_EXT_IDENTIFIER) == XCP_ON_CAN_EXT_IDENTIFIER) + #define XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(i) (((i)&XCP_ON_CAN_EXT_IDENTIFIER) == XCP_ON_CAN_EXT_IDENTIFIER) #define XCP_ON_CAN_STRIP_IDENTIFIER(i) ((i) & (~XCP_ON_CAN_EXT_IDENTIFIER)) /* @@ -518,6 +517,22 @@ extern "C" { #define XCP_ETH_HEADER_SIZE (4) + /* + * CAN Interfaces. + */ + #define XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD (0x01) + #define XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD (0x02) + #define XCP_CAN_IF_MKR_ZERO_CAN_SHIELD (0x03) + + // Set defaults for MCP25XX CAN controllers. + #if !defined(XCP_CAN_IF_MCP25XX_PIN_CS) + #define XCP_CAN_IF_MCP25XX_PIN_CS UINT8(9) + #endif + + #if !defined(XCP_CAN_IF_MCP25XX_PIN_INT) + #define XCP_CAN_IF_MCP25XX_PIN_INT UINT8(2) + #endif + /* ** Bounds-checking macros. */ diff --git a/src/tl/can/arduino_can.cpp b/src/tl/can/arduino_can.cpp index e468b6c..8ea28a3 100644 --- a/src/tl/can/arduino_can.cpp +++ b/src/tl/can/arduino_can.cpp @@ -25,15 +25,24 @@ #include "xcp_config.h" -/*!!! START-INCLUDE-SECTION !!!*/ -#include "queue.h" -/*!!! END-INCLUDE-SECTION !!!*/ - #if XCP_TRANSPORT_LAYER == XCP_ON_CAN - #include + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + #include + #include + #include + #include + #include + #include + #include + #else + // XCP_CAN_IF_MKR_ZERO_CAN_SHIELD + #include + #endif + #include +uint32_t filter_mask(uint32_t identifier); extern const uint32_t Xcp_DaqIDs[]; extern const uint16_t Xcp_DaqIDCount; @@ -42,10 +51,24 @@ static const char XCP_MAGIC[] = "XCP"; static bool connected = false; static volatile bool XcpTl_FrameReceived{ false }; -static char XcpTl_Buffer[64]; -static int XcpTl_Dlc = 0; +static unsigned char XcpTl_Buffer[64]; +static unsigned char XcpTl_Dlc = 0; +static int XcpTl_ID = 0; + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) +static void on_receive(); + #else static void on_receive(int packetSize); + #endif + + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + #if XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD +mcp2515_can CAN(XCP_CAN_IF_MCP25XX_PIN_CS); + #elif XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD +mcp2518fd CAN(XCP_CAN_IF_MCP25XX_PIN_CS); + #endif + #else + #endif void XcpTl_Init(void) { Serial.begin(9600); @@ -54,7 +77,30 @@ void XcpTl_Init(void) { Serial.println("Starting Blueparrot XCP..."); - // start the CAN bus at 500 kbps + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + attachInterrupt(digitalPinToInterrupt(XCP_CAN_IF_MCP25XX_PIN_INT), on_receive, FALLING); + + while (CAN_OK != CAN.begin(XCP_ON_CAN_FREQ)) { + Serial.println("CAN init fail, retry..."); + delay(100); + } + + Serial.println("CAN init OK!"); + // #if 0 + CAN.init_Mask(0, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_INBOUND_IDENTIFIER), filter_mask(XCP_ON_CAN_INBOUND_IDENTIFIER)); + CAN.init_Mask( + 1, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_BROADCAST_IDENTIFIER), filter_mask(XCP_ON_CAN_BROADCAST_IDENTIFIER) + ); + // #endif + // CAN.init_Mask(0, 0, 0); + // CAN.init_Mask(1, 0, 0); + + CAN.init_Filt(0, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_INBOUND_IDENTIFIER), XCP_ON_CAN_INBOUND_IDENTIFIER); + CAN.init_Filt(1, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_BROADCAST_IDENTIFIER), XCP_ON_CAN_BROADCAST_IDENTIFIER); + #else + + // XCP_CAN_IF_MKR_ZERO_CAN_SHIELD + if (!CAN.begin(XCP_ON_CAN_FREQ)) { Serial.println("Starting CAN failed!"); while (1) { @@ -62,6 +108,7 @@ void XcpTl_Init(void) { } CAN.setTimeout(1000); CAN.onReceive(on_receive); + #endif } void XcpTl_DeInit(void) { @@ -83,40 +130,36 @@ void XcpTl_MainFunction(void) { // ARDUINO_API_VERSION + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) +static void on_receive() { + #else static void on_receive(int packetSize) { uint_least8_t idx = 0; + XcpTl_Dlc = packetSize; + #endif - XcpTl_Dlc = packetSize; - XcpTl_FrameReceived = true; + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) - // received a packet - // Serial.print("Received "); + if (CAN.checkReceive() == CAN_MSGAVAIL) { + XcpTl_FrameReceived = true; + CAN.readMsgBuf(&XcpTl_Dlc, static_cast(XcpTl_Buffer)); + // XcpTl_ID + // canBusPacket.id = CAN.getCanId(); + } + #else + XcpTl_FrameReceived = true; if (CAN.packetExtended()) { - // Serial.print("extended "); } - if (CAN.packetRtr()) { - // Remote transmission request, packet contains no data - // Serial.print("RTR "); } - - // Serial.print("packet with id 0x"); - // Serial.print(CAN.packetId(), HEX); - if (CAN.packetRtr()) { - // Serial.print(" and requested length "); - // Serial.println(CAN.packetDlc()); } else { - // Serial.print(" and length "); - // Serial.println(packetSize); - - // only print packet data for non-RTR packets while (CAN.available()) { XcpTl_Buffer[idx++] = CAN.read(); } } - // Serial.println(); + #endif } void XcpTl_RxHandler(void) { @@ -141,6 +184,12 @@ void XcpTl_Send(uint8_t const *buf, uint16_t len) { can_id = XCP_ON_CAN_STRIP_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER); + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + + CAN.sendMsgBuf(can_id, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER), len, buf); + + #else + if (XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER)) { CAN.beginExtendedPacket(can_id, len); } else { @@ -149,6 +198,15 @@ void XcpTl_Send(uint8_t const *buf, uint16_t len) { CAN.write(buf, len); CAN.endPacket(); + #endif +} + +uint32_t filter_mask(uint32_t identifier) { + if (XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(identifier)) { + return (2 << (29 - 1)) - 1; + } else { + return (2 << (11 - 1)) - 1; + } } void XcpTl_SaveConnection(void) { diff --git a/src/xcp_daq.c b/src/xcp_daq.c index d16c161..d01f769 100644 --- a/src/xcp_daq.c +++ b/src/xcp_daq.c @@ -109,16 +109,16 @@ bool XcpDaq_QueueEnqueue(uint16_t len, uint8_t const *data); */ #if XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON XCP_STATIC const uint8_t XcpDaq_AllocTransitionTable[5][4] = { - /* FREE_DAQ ALLOC_DAQ ALLOC_ODT ALLOC_ODT_ENTRY */ - /* ALLOC_IDLE*/ { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR) }, - /* AFTER_FREE_DAQ */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR) }, - /* AFTER_ALLOC_DAQ */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR) }, - /* AFTER_ALLOC_ODT */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK) }, - /* AFTER_ALLOC_ODT_ENTRY */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK) }, + /* FREE_DAQ ALLOC_DAQ ALLOC_ODT ALLOC_ODT_ENTRY */ + /* ALLOC_IDLE*/ {UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR)}, + /* AFTER_FREE_DAQ */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR)}, + /* AFTER_ALLOC_DAQ */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR)}, + /* AFTER_ALLOC_ODT */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK) }, + /* AFTER_ALLOC_ODT_ENTRY */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK) }, }; #endif /* XCP_DAQ_ENABLE_DYNAMIC_LISTS */ @@ -390,8 +390,9 @@ void XcpDaq_SetPointer( bool XcpDaq_ValidateConfiguration(void) { #if (XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON) && (XCP_DAQ_ENABLE_PREDEFINED_LISTS == XCP_OFF) /* Dynamic DAQs only */ - return (bool)((XcpDaq_EntityCount > (XCP_DAQ_ENTITY_TYPE)0) && (XcpDaq_ListCount > (XCP_DAQ_ENTITY_TYPE)0) && - (XcpDaq_OdtCount > (XCP_DAQ_ENTITY_TYPE)0)); + return (bool + )((XcpDaq_EntityCount > (XCP_DAQ_ENTITY_TYPE)0) && (XcpDaq_ListCount > (XCP_DAQ_ENTITY_TYPE)0) && + (XcpDaq_OdtCount > (XCP_DAQ_ENTITY_TYPE)0)); #elif (XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_OFF) && (XCP_DAQ_ENABLE_PREDEFINED_LISTS == XCP_ON) /* Predefined DAQs only */ return (bool)XCP_TRUE; @@ -482,16 +483,16 @@ void XcpDaq_AddEventChannel(XcpDaq_ListIntegerType daqListNumber, uint16_t event * @param eventChannelNumber Number of event to trigger. */ void XcpDaq_TriggerEvent(uint8_t eventChannelNumber) { - Xcp_StateType const *state = XCP_NULL; - XcpDaq_ListIntegerType daqListNumber = 0; - XcpDaq_ODTIntegerType odtIdx = 0; - XcpDaq_ODTIntegerType pid = 0; - XcpDaq_ODTEntryIntegerType odtEntryIdx = 0; - XcpDaq_ODTType const *odt = XCP_NULL; - XcpDaq_ODTEntryType *entry = XCP_NULL; - XcpDaq_ListConfigurationType const *listConf = XCP_NULL; - uint16_t offset = UINT16(0); - uint8_t data[XCP_MAX_DTO] = { 0 }; + Xcp_StateType const *state = XCP_NULL; + XcpDaq_ListIntegerType daqListNumber = 0; + XcpDaq_ODTIntegerType odtIdx = 0; + XcpDaq_ODTIntegerType pid = 0; + XcpDaq_ODTEntryIntegerType odtEntryIdx = 0; + XcpDaq_ODTType const *odt = XCP_NULL; + XcpDaq_ODTEntryType *entry = XCP_NULL; + XcpDaq_ListConfigurationType const *listConf = XCP_NULL; + uint16_t offset = UINT16(0); + uint8_t data[k] = { 0 }; #if XCP_DAQ_ENABLE_TIMESTAMPING == XCP_ON XcpDaq_ListStateType *listState = XCP_NULL; uint32_t timestamp = UINT32(0); diff --git a/tools/amalgam8.py b/tools/amalgam8.py index 5b8c7e9..0f1475a 100644 --- a/tools/amalgam8.py +++ b/tools/amalgam8.py @@ -75,6 +75,7 @@ def print_file_name(out_file, item): STOP_LIST = [ # don't include these files. + r"..\inc\queue.h", r'..\src\hw\options.c', r'..\src\hw\terminal.c', r'..\src\hw\threads.c', diff --git a/tools/arduino/hello_xcp/hello_xcp.ino b/tools/arduino/hello_xcp/hello_xcp.ino index dad8da1..7c92a4b 100644 --- a/tools/arduino/hello_xcp/hello_xcp.ino +++ b/tools/arduino/hello_xcp/hello_xcp.ino @@ -29,7 +29,7 @@ XCP_DAQ_DEFINE_EVENT( __attribute__((section(".measurements"))) volatile uint16_t triangle_wave = 0U; __attribute__((section(".measurements"))) volatile uint8_t sq0_wave = 0U; __attribute__((section(".measurements"))) volatile uint8_t sq1_wave = 0U; -__attribute__((section(".measurements"))) volatile float sine_wave = 0U; +__attribute__((section(".measurements"))) volatile float sine_wave = 0U; // Parameters volatile uint16_t triangle_min = 0x00; @@ -60,7 +60,7 @@ class AbstractWave { } void notify_observers() noexcept { - m_observers.notify(m_wave); + m_observers.notify(m_wave); #if 0 for (auto element : m_observers) { element->update(m_wave); @@ -73,10 +73,10 @@ class AbstractWave { protected: - uint16_t m_wave; - uint16_t m_min; - uint16_t m_max; - Observers m_observers; + uint16_t m_wave; + uint16_t m_min; + uint16_t m_max; + Observers m_observers; }; class TriangleWave : public AbstractWave { @@ -117,7 +117,7 @@ class SquareWave : public AbstractWave { } void update(uint16_t value) noexcept override { - if (m_skew > 0) { + if (m_skew > 0) { auto tmp_value = m_queue.pop(); m_queue.push(value); value = tmp_value; @@ -137,9 +137,9 @@ class SquareWave : public AbstractWave { } } - uint16_t m_level; - uint16_t m_skew; - bool m_raising_edge; + uint16_t m_level; + uint16_t m_skew; + bool m_raising_edge; Queue m_queue; }; @@ -163,10 +163,10 @@ class SineWave : public AbstractWave { private: uint16_t m_steps; - float m_amplitude; - bool m_symetrical; - float m_angle; - float m_value; + float m_amplitude; + bool m_symetrical; + float m_angle; + float m_value; }; void setup() { @@ -175,15 +175,17 @@ void setup() { startTime = millis(); } +#if 0 auto triangle = TriangleWave(); auto square0 = SquareWave(&triangle, 64); auto square1 = SquareWave(&triangle, 64, 96, false); auto sin0 = SineWave(&triangle, 0xff, 100.0, true); +#endif void loop() { XcpTl_MainFunction(); Xcp_MainFunction(); - #if 0 +#if 0 if ((millis() - startTime) >= 10) { startTime = millis(); triangle.step(); @@ -193,5 +195,5 @@ void loop() { sine_wave = sin0.get_float_value(); XcpDaq_TriggerEvent(0); } - #endif +#endif } diff --git a/tools/arduino/hello_xcp/xcp.h b/tools/arduino/hello_xcp/xcp.h index 760fef4..4afaa70 100644 --- a/tools/arduino/hello_xcp/xcp.h +++ b/tools/arduino/hello_xcp/xcp.h @@ -1,127 +1,4 @@ -//////////////////////////////////////////////////////////////////////////////// -// queue.h // -//////////////////////////////////////////////////////////////////////////////// - - -#ifndef CXCP_QUEUE_HPP -#define CXCP_QUEUE_HPP - -template -class Queue { - public: - - explicit Queue(size_t size) { - arr = new T[size]; - m_capacity = size; - m_front = 0; - m_rear = -1; - m_count = 0; - } - - Queue() = delete; - - ~Queue() { - delete[] arr; - } - - T pop() { - if (isEmpty()) { - exit(EXIT_FAILURE); - } - T x = arr[m_front]; - - m_front = (m_front + 1) % m_capacity; - m_count--; - - return x; - } - - void push(const T &item) { - if (isFull()) { - exit(EXIT_FAILURE); - } - - m_rear = (m_rear + 1) % m_capacity; - arr[m_rear] = item; - m_count++; - } -#if 0 - T peek() { - if (isEmpty()) { - exit(EXIT_FAILURE); - } - return arr[m_front]; - } -#endif - size_t size() { - return m_count; - } - - bool isEmpty() { - return (size() == 0); - } - - bool isFull() { - return (size() == m_capacity); - } - - private: - - T *arr; - size_t m_capacity; - int m_front; - int m_rear; - size_t m_count; -}; - -template -class Observers { - public: - - explicit Observers(size_t size) { - arr = new T[size]; - m_capacity = size; - m_count = 0; - } - - Observers() = delete; - - ~Observers() { - delete[] arr; - } - - void append(const T &item) { - if (isFull()) { - exit(EXIT_FAILURE); - } - arr[m_count++] = item; - } - - bool isFull() { - return (size() == m_capacity); - } - - size_t size() { - return m_count; - } - - template - void notify(const V &value) { - for (size_t i = 0; i < m_capacity; ++i) { - arr[i]->update(value); - } - } - - private: - - T *arr; - size_t m_capacity; - size_t m_count; -}; - -#endif // CXCP_QUEUE_HPP - //////////////////////////////////////////////////////////////////////////////// // xcp_macros.h // //////////////////////////////////////////////////////////////////////////////// @@ -536,14 +413,13 @@ typedef struct tagXcpTl_ConnectionType { */ #ifndef __XCP_TL_TIMEOUT_H -#define __XCP_TL_TIMEOUT_H + #define __XCP_TL_TIMEOUT_H -#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON - #if defined(__cplusplus) + #if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON + #if defined(__cplusplus) extern "C" { - #endif /* __cplusplus */ -#endif /* XCP_EXTERN_C_GUARDS */ - + #endif /* __cplusplus */ + #endif /* XCP_EXTERN_C_GUARDS */ static void XcpTl_TimeoutInit(uint16_t timeout_value, void (*timeout_function)(void)); @@ -555,11 +431,11 @@ extern "C" { static void XcpTl_TimeoutReset(void); -#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON - #if defined(__cplusplus) + #if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON + #if defined(__cplusplus) } - #endif /* __cplusplus */ -#endif /* XCP_EXTERN_C_GUARDS */ + #endif /* __cplusplus */ + #endif /* XCP_EXTERN_C_GUARDS */ #endif // __XCP_TL_TIMEOUT_H @@ -601,12 +477,11 @@ extern "C" { #endif /* __cplusplus */ #endif /* XCP_EXTERN_C_GUARDS */ - - void XcpUtl_MemCopy(void* dst, void const * src, uint32_t len); - void XcpUtl_MemSet(void* dest, uint8_t fill_char, uint32_t len); - bool XcpUtl_MemCmp(void const * dst, void const * src, uint32_t len); - void XcpUtl_Hexdump(uint8_t const * buf, uint16_t sz); - void XcpUtl_Itoa(uint32_t value, uint8_t base, uint8_t* buf); + void XcpUtl_MemCopy(void *dst, void const *src, uint32_t len); + void XcpUtl_MemSet(void *dest, uint8_t fill_char, uint32_t len); + bool XcpUtl_MemCmp(void const *dst, void const *src, uint32_t len); + void XcpUtl_Hexdump(uint8_t const *buf, uint16_t sz); + void XcpUtl_Itoa(uint32_t value, uint8_t base, uint8_t *buf); #define XcpUtl_ZeroMem(dest, len) XcpUtl_MemSet((dest), '\0', (len)) @@ -652,7 +527,6 @@ extern "C" { #include - #define XCP_PROTOCOL_VERSION_MAJOR (1) #define XCP_PROTOCOL_VERSION_RELEASE (0) @@ -725,8 +599,7 @@ extern "C" { #if XCP_TRANSPORT_LAYER == XCP_ON_CAN - #if ((XCP_ENABLE_CAN_GET_SLAVE_ID == XCP_ON) || (XCP_ENABLE_CAN_GET_DAQ_ID == XCP_ON) || \ - (XCP_ENABLE_CAN_SET_DAQ_ID == XCP_ON)) + #if ((XCP_ENABLE_CAN_GET_SLAVE_ID == XCP_ON) || (XCP_ENABLE_CAN_GET_DAQ_ID == XCP_ON) || (XCP_ENABLE_CAN_SET_DAQ_ID == XCP_ON)) #define XCP_ENABLE_TRANSPORT_LAYER_CMD (XCP_ON) #endif @@ -889,7 +762,7 @@ extern "C" { #define XCP_MIN_ST_PGM (0) #endif /* XCP_MIN_ST_PGM */ - #define XCP_DOWNLOAD_PAYLOAD_LENGTH ((XCP_MAX_CTO) - 2) + #define XCP_DOWNLOAD_PAYLOAD_LENGTH ((XCP_MAX_CTO)-2) /* * Packet Identifiers. @@ -1116,7 +989,7 @@ extern "C" { /* ** XCPonCAN specific function-like macros. */ - #define XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(i) (((i) & XCP_ON_CAN_EXT_IDENTIFIER) == XCP_ON_CAN_EXT_IDENTIFIER) + #define XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(i) (((i)&XCP_ON_CAN_EXT_IDENTIFIER) == XCP_ON_CAN_EXT_IDENTIFIER) #define XCP_ON_CAN_STRIP_IDENTIFIER(i) ((i) & (~XCP_ON_CAN_EXT_IDENTIFIER)) /* @@ -1137,6 +1010,21 @@ extern "C" { #define XCP_ETH_HEADER_SIZE (4) + /* + * CAN Interfaces. + */ + #define XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD (0x01) + #define XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD (0x02) + + // Set defaults for MCP25XX CAN controllers. + #if !defined(XCP_CAN_IF_MCP25XX_PIN_CS) + #define XCP_CAN_IF_MCP25XX_PIN_CS UINT8(9) + #endif + + #if !defined(XCP_CAN_IF_MCP25XX_PIN_INT) + #define XCP_CAN_IF_MCP25XX_PIN_INT UINT8(2) + #endif + /* ** Bounds-checking macros. */ @@ -1901,7 +1789,6 @@ extern "C" { #endif /* __cplusplus */ #endif /* XCP_EXTERN_C_GUARDS */ - /* ** Global Functions. */ @@ -1946,7 +1833,6 @@ extern "C" { * s. FLOSS-EXCEPTION.txt */ - /* ** Private Options. */ @@ -2665,7 +2551,7 @@ void Xcp_SendCto(void) { Xcp_CtoOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE] = XCP_LOBYTE(Xcp_State.counter); Xcp_State.counter++; #elif XCP_TRANSPORT_LAYER_COUNTER_SIZE == 2 - Xcp_CtoOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE] = XCP_LOBYTE(Xcp_State.counter); + Xcp_CtoOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE] = XCP_LOBYTE(Xcp_State.counter); Xcp_CtoOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE + 1] = XCP_HIBYTE(Xcp_State.counter); Xcp_State.counter++; #endif /* XCP_TRANSPORT_LAYER_COUNTER_SIZE */ @@ -2687,8 +2573,8 @@ void Xcp_SendDto(void) { #if XCP_TRANSPORT_LAYER_LENGTH_SIZE == 1 Xcp_DtoOut.data[0] = XCP_LOBYTE(len); #elif XCP_TRANSPORT_LAYER_LENGTH_SIZE == 2 - Xcp_DtoOut.data[0] = XCP_LOBYTE(len); - Xcp_DtoOut.data[1] = XCP_HIBYTE(len); + Xcp_DtoOut.data[0] = XCP_LOBYTE(len); + Xcp_DtoOut.data[1] = XCP_HIBYTE(len); #endif /* XCP_TRANSPORT_LAYER_LENGTH_SIZE */ #if XCP_TRANSPORT_LAYER_COUNTER_SIZE == 1 @@ -4104,7 +3990,7 @@ INLINE void Xcp_SetWord(Xcp_PduType const * const pdu, uint8_t offs, uint16_t va (*(pdu->data + offs)) = value & UINT8(0xff); (*(pdu->data + UINT8(1) + offs)) = (value & UINT16(0xff00)) >> UINT8(8); #elif XCP_BYTE_ORDER == XCP_BYTE_ORDER_MOTOROLA - (*(pdu->data + offs)) = (value & UINT16(0xff00)) >> UINT8(8); + (*(pdu->data + offs)) = (value & UINT16(0xff00)) >> UINT8(8); (*(pdu->data + UINT8(1) + offs)) = value & UINT8(0xff); #endif } @@ -4319,7 +4205,6 @@ XCP_STATIC void Xcp_WriteDaqEntry(uint8_t bitOffset, uint8_t elemSize, uint8_t a * expressed or implied by its publication or distribution. **********************************************************************/ - /* ** Local Types */ @@ -4711,7 +4596,6 @@ void Xcp_ChecksumMainFunction(void) { #include #endif /* _WIN32 */ - /* ** Private Parameters for now. */ @@ -4783,16 +4667,16 @@ bool XcpDaq_QueueEnqueue(uint16_t len, uint8_t const *data); */ #if XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON XCP_STATIC const uint8_t XcpDaq_AllocTransitionTable[5][4] = { - /* FREE_DAQ ALLOC_DAQ ALLOC_ODT ALLOC_ODT_ENTRY */ - /* ALLOC_IDLE*/ { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR) }, - /* AFTER_FREE_DAQ */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR) }, - /* AFTER_ALLOC_DAQ */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR) }, - /* AFTER_ALLOC_ODT */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK) }, - /* AFTER_ALLOC_ODT_ENTRY */ - { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK) }, + /* FREE_DAQ ALLOC_DAQ ALLOC_ODT ALLOC_ODT_ENTRY */ + /* ALLOC_IDLE*/ {UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR)}, + /* AFTER_FREE_DAQ */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR)}, + /* AFTER_ALLOC_DAQ */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR)}, + /* AFTER_ALLOC_ODT */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK) }, + /* AFTER_ALLOC_ODT_ENTRY */ + { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK) }, }; #endif /* XCP_DAQ_ENABLE_DYNAMIC_LISTS */ @@ -5064,8 +4948,9 @@ void XcpDaq_SetPointer( bool XcpDaq_ValidateConfiguration(void) { #if (XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON) && (XCP_DAQ_ENABLE_PREDEFINED_LISTS == XCP_OFF) /* Dynamic DAQs only */ - return (bool)((XcpDaq_EntityCount > (XCP_DAQ_ENTITY_TYPE)0) && (XcpDaq_ListCount > (XCP_DAQ_ENTITY_TYPE)0) && - (XcpDaq_OdtCount > (XCP_DAQ_ENTITY_TYPE)0)); + return (bool + )((XcpDaq_EntityCount > (XCP_DAQ_ENTITY_TYPE)0) && (XcpDaq_ListCount > (XCP_DAQ_ENTITY_TYPE)0) && + (XcpDaq_OdtCount > (XCP_DAQ_ENTITY_TYPE)0)); #elif (XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_OFF) && (XCP_DAQ_ENABLE_PREDEFINED_LISTS == XCP_ON) /* Predefined DAQs only */ return (bool)XCP_TRUE; @@ -5456,7 +5341,6 @@ bool XcpDaq_QueueDequeue(uint16_t *len, uint8_t *data) { * s. FLOSS-EXCEPTION.txt */ - void XcpUtl_MemCopy(/*@out@*/ void *dst, /*@in@*/ void const *src, uint32_t len) { uint8_t *pd = (uint8_t *)dst; uint8_t const *ps = (uint8_t const *)src; @@ -5572,7 +5456,6 @@ void XcpUtl_Itoa(uint32_t value, uint8_t base, uint8_t *buf) { * s. FLOSS-EXCEPTION.txt */ - /* * * Time-out handling functions for Transport-Layer. @@ -5652,7 +5535,6 @@ static void XcpTl_TimeoutReset(void) { #include "Arduino.h" #endif - #define XCP_SXI_MAKEWORD(buf, offs) ((*((buf) + (offs))) | ((*((buf) + (offs) + 1) << 8))) #define TIMEOUT_VALUE (100) @@ -5832,7 +5714,6 @@ void serialEvent() #include #include - typedef struct tagHwStateType { uint32_t StartingTime; } HwStateType; @@ -5916,12 +5797,23 @@ void XcpHw_Sleep(uint64_t usec) { #include "xcp_config.h" - #if XCP_TRANSPORT_LAYER == XCP_ON_CAN - #include + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + #include + #include + #include + #include + #include + #include + #include + #else + #include + #endif + #include +uint32_t filter_mask(uint32_t identifier); extern const uint32_t Xcp_DaqIDs[]; extern const uint16_t Xcp_DaqIDCount; @@ -5930,10 +5822,24 @@ static const char XCP_MAGIC[] = "XCP"; static bool connected = false; static volatile bool XcpTl_FrameReceived{ false }; -static char XcpTl_Buffer[64]; -static int XcpTl_Dlc = 0; +static unsigned char XcpTl_Buffer[64]; +static unsigned char XcpTl_Dlc = 0; +static int XcpTl_ID = 0; + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) +static void on_receive(); + #else static void on_receive(int packetSize); + #endif + + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + #if XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD +mcp2515_can CAN(XCP_CAN_IF_MCP25XX_PIN_CS); + #elif XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD +mcp2518fd CAN(XCP_CAN_IF_MCP25XX_PIN_CS); + #endif + #else + #endif void XcpTl_Init(void) { Serial.begin(9600); @@ -5942,7 +5848,29 @@ void XcpTl_Init(void) { Serial.println("Starting Blueparrot XCP..."); - // start the CAN bus at 500 kbps + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + attachInterrupt(digitalPinToInterrupt(XCP_CAN_IF_MCP25XX_PIN_INT), on_receive, FALLING); + + while (CAN_OK != CAN.begin(XCP_ON_CAN_FREQ)) { + Serial.println("CAN init fail, retry..."); + delay(100); + } + // XCP_ON_CAN_IS_EXTENDED_IDENTIFIER() + + Serial.println("CAN init OK!"); + // #if 0 + CAN.init_Mask(0, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_INBOUND_IDENTIFIER), filter_mask(XCP_ON_CAN_INBOUND_IDENTIFIER)); + CAN.init_Mask( + 1, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_BROADCAST_IDENTIFIER), filter_mask(XCP_ON_CAN_BROADCAST_IDENTIFIER) + ); + // #endif + // CAN.init_Mask(0, 0, 0); + // CAN.init_Mask(1, 0, 0); + + CAN.init_Filt(0, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_INBOUND_IDENTIFIER), XCP_ON_CAN_INBOUND_IDENTIFIER); + CAN.init_Filt(1, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_BROADCAST_IDENTIFIER), XCP_ON_CAN_BROADCAST_IDENTIFIER); + #else + if (!CAN.begin(XCP_ON_CAN_FREQ)) { Serial.println("Starting CAN failed!"); while (1) { @@ -5950,6 +5878,7 @@ void XcpTl_Init(void) { } CAN.setTimeout(1000); CAN.onReceive(on_receive); + #endif } void XcpTl_DeInit(void) { @@ -5971,40 +5900,36 @@ void XcpTl_MainFunction(void) { // ARDUINO_API_VERSION + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) +static void on_receive() { + #else static void on_receive(int packetSize) { - uint_least8_t idx = 0; - + uint_least8_t idx = 0; XcpTl_Dlc = packetSize; - XcpTl_FrameReceived = true; + #endif - // received a packet - // Serial.print("Received "); + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) - if (CAN.packetExtended()) { - // Serial.print("extended "); + if (CAN.checkReceive() == CAN_MSGAVAIL) { + XcpTl_FrameReceived = true; + CAN.readMsgBuf(&XcpTl_Dlc, static_cast(XcpTl_Buffer)); + // XcpTl_ID + // canBusPacket.id = CAN.getCanId(); } + #else + XcpTl_FrameReceived = true; + if (CAN.packetExtended()) { + } if (CAN.packetRtr()) { - // Remote transmission request, packet contains no data - // Serial.print("RTR "); } - - // Serial.print("packet with id 0x"); - // Serial.print(CAN.packetId(), HEX); - if (CAN.packetRtr()) { - // Serial.print(" and requested length "); - // Serial.println(CAN.packetDlc()); } else { - // Serial.print(" and length "); - // Serial.println(packetSize); - - // only print packet data for non-RTR packets while (CAN.available()) { XcpTl_Buffer[idx++] = CAN.read(); } } - // Serial.println(); + #endif } void XcpTl_RxHandler(void) { @@ -6029,6 +5954,12 @@ void XcpTl_Send(uint8_t const *buf, uint16_t len) { can_id = XCP_ON_CAN_STRIP_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER); + #if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD) + + CAN.sendMsgBuf(can_id, XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER), len, buf); + + #else + if (XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER)) { CAN.beginExtendedPacket(can_id, len); } else { @@ -6037,6 +5968,15 @@ void XcpTl_Send(uint8_t const *buf, uint16_t len) { CAN.write(buf, len); CAN.endPacket(); + #endif +} + +uint32_t filter_mask(uint32_t identifier) { + if (XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(identifier)) { + return (2 << (29 - 1)) - 1; + } else { + return (2 << (11 - 1)) - 1; + } } void XcpTl_SaveConnection(void) { diff --git a/tools/arduino/hello_xcp/xcp_config.h b/tools/arduino/hello_xcp/xcp_config.h index 2590798..44ed4a3 100644 --- a/tools/arduino/hello_xcp/xcp_config.h +++ b/tools/arduino/hello_xcp/xcp_config.h @@ -1,7 +1,7 @@ /* * BlueParrot XCP * - * (C) 2007-2021 by Christoph Schueler * * All Rights Reserved @@ -34,10 +34,11 @@ /* ** General Options. */ - -#define TP_CAN + #define TP_CAN // #define TP_SXI + #define XCP_CAN_INTERFACE (XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) + #define XCP_GET_ID_0 "BlueParrot XCP running on Arduino" #define XCP_GET_ID_1 "BlueParrot_XCP_on_Arduino" @@ -79,14 +80,8 @@ /* ** DAQ Settings. */ - #define XCP_DAQ_CONFIG_TYPE XCP_DAQ_CONFIG_TYPE_DYNAMIC - #define XCP_DAQ_DTO_BUFFER_SIZE (24) - #define XCP_DAQ_ENABLE_TIMESTAMPING (XCP_ON) - // #define XCP_DAQ_ENABLE_EVENT_CHANNEL (XCP_ON) - // #define XCP_DAQ_ENABLE_DYNAMIC_LISTS (XCP_ON) - // #define XCP_DAQ_ENABLE_DYNAMIC_LISTS_PER_EVENT (XCP_ON) - // #define XCP_DAQ_ENABLE_DYNAMIC_LISTS_PER_CHANNEL (XCP_ON) - // #define XCP_DAQ_ENABLE_DYNAMIC_LISTS_PER_EVENT_TYPE (XCP_ON) + #define XCP_DAQ_CONFIG_TYPE XCP_DAQ_CONFIG_TYPE_DYNAMIC + #define XCP_DAQ_DTO_BUFFER_SIZE (40) #define XCP_DAQ_ENABLE_PREDEFINED_LISTS (XCP_OFF) #define XCP_DAQ_TIMESTAMP_UNIT (XCP_DAQ_TIMESTAMP_UNIT_1US) #define XCP_DAQ_TIMESTAMP_SIZE (XCP_DAQ_TIMESTAMP_SIZE_4) @@ -97,7 +92,7 @@ #define XCP_DAQ_ENABLE_ALTERNATING (XCP_OFF) #define XCP_DAQ_ENABLE_CLOCK_ACCESS_ALWAYS (XCP_ON) #define XCP_DAQ_ENABLE_WRITE_THROUGH (XCP_OFF) - #define XCP_DAQ_MAX_DYNAMIC_ENTITIES (20) + #define XCP_DAQ_MAX_DYNAMIC_ENTITIES (16) #define XCP_DAQ_MAX_EVENT_CHANNEL (3) #define XCP_DAQ_ENABLE_MULTIPLE_DAQ_LISTS_PER_EVENT (XCP_OFF) @@ -175,14 +170,19 @@ #define XCP_ON_CAN_INBOUND_IDENTIFIER (0x300) #define XCP_ON_CAN_OUTBOUND_IDENTIFIER (0x301) - #define XCP_ON_CAN_MAX_DLC_REQUIRED (XCP_OFF) + #define XCP_ON_CAN_MAX_DLC_REQUIRED (XCP_ON) #define XCP_ON_CAN_BROADCAST_IDENTIFIER (0x222) - #define XCP_ON_CAN_FREQ (500E3) - #define XCP_ON_CAN_BTQ (16) - #define XCP_ON_CAN_TSEG1 (14) - #define XCP_ON_CAN_TSEG2 (2) - #define XCP_ON_CAN_SJW (2) - #define XCP_ON_CAN_NOSAMP (1) + + // Chip-Select- and Interrupt-Pins / SeeedStudio CAN Shield v2. + #define XCP_CAN_IF_MCP25XX_PIN_CS (9) + #define XCP_CAN_IF_MCP25XX_PIN_INT (2) + + #define XCP_ON_CAN_FREQ (CAN_500KBPS) + #define XCP_ON_CAN_BTQ (16) + #define XCP_ON_CAN_TSEG1 (14) + #define XCP_ON_CAN_TSEG2 (2) + #define XCP_ON_CAN_SJW (2) + #define XCP_ON_CAN_NOSAMP (1) /* Transport-Layer Commands. */ #define XCP_ENABLE_CAN_GET_SLAVE_ID (XCP_ON) diff --git a/tools/build.cmd b/tools/build.cmd index 54cb856..8eb1761 100644 --- a/tools/build.cmd +++ b/tools/build.cmd @@ -1,2 +1,3 @@ python amalgam8.py -cp -v xcp.h arduino/hello_xcp \ No newline at end of file +cp -v xcp.h arduino/hello_xcp +cp -v xcp_config.h arduino/hello_xcp diff --git a/tools/xcp_config.h b/tools/xcp_config.h index 7be6d79..03b1de3 100644 --- a/tools/xcp_config.h +++ b/tools/xcp_config.h @@ -1,7 +1,7 @@ /* * BlueParrot XCP * - * (C) 2007-2021 by Christoph Schueler * * All Rights Reserved @@ -37,6 +37,8 @@ #define TP_CAN // #define TP_SXI + #define XCP_CAN_INTERFACE (XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) + #define XCP_GET_ID_0 "BlueParrot XCP running on Arduino" #define XCP_GET_ID_1 "BlueParrot_XCP_on_Arduino" @@ -90,7 +92,7 @@ #define XCP_DAQ_ENABLE_ALTERNATING (XCP_OFF) #define XCP_DAQ_ENABLE_CLOCK_ACCESS_ALWAYS (XCP_ON) #define XCP_DAQ_ENABLE_WRITE_THROUGH (XCP_OFF) - #define XCP_DAQ_MAX_DYNAMIC_ENTITIES (100) + #define XCP_DAQ_MAX_DYNAMIC_ENTITIES (16) #define XCP_DAQ_MAX_EVENT_CHANNEL (3) #define XCP_DAQ_ENABLE_MULTIPLE_DAQ_LISTS_PER_EVENT (XCP_OFF) @@ -168,14 +170,19 @@ #define XCP_ON_CAN_INBOUND_IDENTIFIER (0x300) #define XCP_ON_CAN_OUTBOUND_IDENTIFIER (0x301) - #define XCP_ON_CAN_MAX_DLC_REQUIRED (XCP_ON) + #define XCP_ON_CAN_MAX_DLC_REQUIRED (XCP_OFF) #define XCP_ON_CAN_BROADCAST_IDENTIFIER (0x222) - #define XCP_ON_CAN_FREQ (500E3) - #define XCP_ON_CAN_BTQ (16) - #define XCP_ON_CAN_TSEG1 (14) - #define XCP_ON_CAN_TSEG2 (2) - #define XCP_ON_CAN_SJW (2) - #define XCP_ON_CAN_NOSAMP (1) + + // Chip-Select- and Interrupt-Pins / SeeedStudio CAN Shield v2. + #define XCP_CAN_IF_MCP25XX_PIN_CS (9) + #define XCP_CAN_IF_MCP25XX_PIN_INT (2) + + #define XCP_ON_CAN_FREQ (CAN_500KBPS) + #define XCP_ON_CAN_BTQ (16) + #define XCP_ON_CAN_TSEG1 (14) + #define XCP_ON_CAN_TSEG2 (2) + #define XCP_ON_CAN_SJW (2) + #define XCP_ON_CAN_NOSAMP (1) /* Transport-Layer Commands. */ #define XCP_ENABLE_CAN_GET_SLAVE_ID (XCP_ON)