Skip to content

Commit

Permalink
Merge pull request #285 from LinjingZhang/master
Browse files Browse the repository at this point in the history
Add: Filtering API
  • Loading branch information
LinjingZhang committed Jul 4, 2024
2 parents 36f8fa5 + bf09122 commit 644093d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
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

0 comments on commit 644093d

Please sign in to comment.