Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Filtering API #285

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libraries/CAN/README_CAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down Expand Up @@ -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

<strike>

### Filtering

Filter packets that meet the desired criteria.
Expand Down Expand Up @@ -205,6 +205,7 @@ if ((packetId & mask) == id) {

Returns `1` on success, `0` on failure.

<strike>
## Other modes

### Loopback mode
Expand Down
15 changes: 11 additions & 4 deletions libraries/CAN/src/CANXMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion variants/XMC1400/config/XMC1400_XMC2GO/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion variants/XMC4200/config/XMC4200_Platform2GO/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion variants/XMC4400/config/XMC4400_Platform2GO/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading