From bf091223d277e2f338ac640ac9859ef73799aff5 Mon Sep 17 00:00:00 2001 From: zhanglinjing Date: Tue, 2 Jul 2024 19:47:58 +0200 Subject: [PATCH] Add: Filtering API Update: README regarding filtering issue --- libraries/CAN/README_CAN.md | 5 +++-- libraries/CAN/src/CANXMC.cpp | 15 +++++++++++---- .../XMC1400/config/XMC1400_XMC2GO/pins_arduino.h | 2 +- .../config/XMC4200_Platform2GO/pins_arduino.h | 2 +- .../config/XMC4400_Platform2GO/pins_arduino.h | 2 +- .../config/XMC4700_Relax_Kit/pins_arduino.h | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libraries/CAN/README_CAN.md b/libraries/CAN/README_CAN.md index 2a5055c4..c5569ef8 100644 --- a/libraries/CAN/README_CAN.md +++ b/libraries/CAN/README_CAN.md @@ -14,7 +14,7 @@ using namespace ifx; Initialize the library with the specified bit rate. ```arduino -CAN.begin(bitrate, id); +CAN.begin(bitrate); ``` * `bitrate` - bit rate in bits per seconds (bps) (`1000E3`, `500E3`(default), `250E3`, `200E3`, `125E3`, `100E3`, `80E3`, `50E3`, `40E3`, `20E3`, `10E3`, `5E3`) @@ -177,7 +177,7 @@ Returns the next byte in the packet or `-1` if no bytes are available. **Note:** Other Arduino [`Stream` API's](https://www.arduino.cc/en/Reference/Stream) can also be used to read data from the packet - + ### Filtering Filter packets that meet the desired criteria. @@ -205,6 +205,7 @@ if ((packetId & mask) == id) { Returns `1` on success, `0` on failure. + ## Other modes ### Loopback mode diff --git a/libraries/CAN/src/CANXMC.cpp b/libraries/CAN/src/CANXMC.cpp index d3e048e5..1d49d0b9 100644 --- a/libraries/CAN/src/CANXMC.cpp +++ b/libraries/CAN/src/CANXMC.cpp @@ -32,7 +32,7 @@ CANXMC::CANXMC(XMC_ARD_CAN_t *conf) { _XMC_CAN_config = conf; } CANXMC::~CANXMC() {} int CANXMC::setIdentifier(long id) { // TODO: delete in the future! - // figure out filtering problem + // figure out filtering problem for xmc4700 XMC_CAN_MO_SetIdentifier(&CAN_msg_rx, id); return 0; }; @@ -183,13 +183,20 @@ CANXMC::~CANXMC() {} int CANXMC::filter(int id, int mask) { - XMC_CAN_NODE_SetInitBit(_XMC_CAN_config->can_node); - return 0; + XMC_CAN_MO_SetStandardID(&CAN_msg_rx); + XMC_CAN_MO_SetIdentifier(&CAN_msg_rx, id); + XMC_CAN_MO_AcceptOnlyMatchingIDE(&CAN_msg_rx); + XMC_CAN_MO_SetAcceptanceMask(&CAN_msg_rx, mask); + + return 1; }; int CANXMC::filterExtended(long id, long mask) { - XMC_CAN_NODE_SetInitBit(_XMC_CAN_config->can_node); + XMC_CAN_MO_SetExtendedID(&CAN_msg_rx); + XMC_CAN_MO_SetIdentifier(&CAN_msg_rx, id); + XMC_CAN_MO_AcceptOnlyMatchingIDE(&CAN_msg_rx); + XMC_CAN_MO_SetAcceptanceMask(&CAN_msg_rx, mask); return 0; }; diff --git a/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h b/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h index 99b6c3e9..0923e2a7 100644 --- a/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h +++ b/variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h @@ -377,7 +377,7 @@ XMC_I2S_t i2s_config = #ifdef CAN_xmc XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE0, - .can_node_num = 0, + .can_node_num = XMC_NODE_NUM_0, .can_clock = XMC_CAN_CANCLKSRC_MCLK, .can_frequency = (uint32_t)48000000, .rx = {.port = (XMC_GPIO_PORT_t *)PORT1_BASE, .pin = (uint8_t)1}, diff --git a/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h b/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h index f9b7ef8a..768a276f 100644 --- a/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h +++ b/variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h @@ -380,7 +380,7 @@ XMC_I2C_t XMC_I2C_0 = XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE0, - .can_node_num = 0, + .can_node_num = XMC_NODE_NUM_0, .can_clock = XMC_CAN_CANCLKSRC_FPERI, .can_frequency = (uint32_t)144000000, .rx = { .port = (XMC_GPIO_PORT_t*)PORT14_BASE, diff --git a/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h b/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h index 51a3c045..734ca39c 100644 --- a/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h +++ b/variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h @@ -432,7 +432,7 @@ XMC_I2C_t XMC_I2C_0 = XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE1, - .can_node_num = 1, + .can_node_num = XMC_NODE_NUM_1, .can_clock = XMC_CAN_CANCLKSRC_FPERI, .can_frequency = (uint32_t)144000000, .rx = { .port = (XMC_GPIO_PORT_t*)PORT1_BASE, diff --git a/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h b/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h index 3a7fab2e..9105d732 100644 --- a/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h +++ b/variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h @@ -713,7 +713,7 @@ XMC_I2S_t i2s_config = XMC_ARD_CAN_t XMC_CAN_0 = { .can_node = CAN_NODE1, - .can_node_num = 1, + .can_node_num = XMC_NODE_NUM_1, .can_clock = XMC_CAN_CANCLKSRC_FPERI, .can_frequency = (uint32_t)144000000, .rx = { .port = (XMC_GPIO_PORT_t*)PORT1_BASE,