Skip to content

Add CAN api filter support and LPC11CXX CAN implementation #91

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

Merged
merged 3 commits into from
Oct 25, 2013

Conversation

omdathetkan
Copy link
Contributor

Add CAN->filter function and modify CAN->read definition to allow reading specific messages.
Add bitfields definition to LPC11XX target generated from UM10398
Implemented most of the CAN functionality for LPC11CXX target

Add filter function and modify CAN->read definition to allow reading specific messages.
Most of the functionality works, interrupts might need a little more work.
@matthewelse
Copy link
Contributor

Nice to see that you've got the CAN done Joris :)
On Oct 22, 2013 7:07 PM, "jorisa" [email protected] wrote:

Add CAN->filter function and modify CAN->read definition to allow reading
specific messages.
Add bitfields definition to LPC11XX target generated from UM10398

Implemented most of the CAN functionality for LPC11CXX target

You can merge this Pull Request by running

git pull https://github.com/jorisa/mbed master

Or view, comment on, or merge it at:

#91
Commit Summary

  • Add CAN->filter to API and add placeholders to hal's
  • Add bitfields definition to LPC11XX target
  • Add can_api hal implementation to LPC11CXX target

File Changes

Patch Links:

*
* @returns
* 0 if no message arrived,
* 1 if message arrived
*/
int read(CANMessage &msg);
int read(CANMessage &msg, int handle = 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain a bit the usage of "handle" in this context (both in read and filter functions) ? Do you think that this "handle" mechanism is generic enough to implement CAN message filtering on all platforms with a CAN transceiver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the LPC11CXX the handle is the message object index (1-32). 32 is used for transmitting message and 1 is used by default as the accept-all mailbox, so by overriding it you disable acceptance of any message.
If there are no more mailboxes available the function will return 0.

Now that I think of it it might be better to make 31 the defailt object for accept-all, as messages are accepted and prioritized by the message boxes in order. This way you can make sure you don't loose the message you're interested in while still receiving any other message as well assuming you can read fast enough.

I think it should be relatively easy to implement the same scheme using the Acceptance Filter Mode on the LPC17XX. Everytime you call can->filter you add it to the identifier table, where handle returns the index in that table.

Here's a typical usage scenario:

int h1,h2;
can->reset(); // reset and clear all filters (accept all messages)
h1 = can->filter(0x100, 0x700, CANStandard); // Accept standard messages with id 0x100-0x1FF
h2 = can->filter(0x200, 0x7FF, CANStandard); // Accept standard message 0x200 as well
[...]
h2 = can->filter(0x300, 0x7FF, CANStandard, h2); // Accept standard message 0x300, overwrite 0x200

CANMessage msg = CANMessage();
int r = can.read(msg, h1); // Should only return messages with id 0x100-0x1FF
int r = can.read(msg, h2); // Should only return messages with id 0x300
int r = can.read(msg);     // Returns 0x100-0x1FF if pending, otherwise 0x300, otherwise any message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed comment. I'm not at all that familiar with CAN, so I'd like to think a bit more if this method is really universal enough. The problem is not really in the HAL, but can_api.h (below) also uses an "int handle" and that has to be good enough for all platforms/CAN transceivers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "can_api.h also uses an int handle"?

Here's someone who implemented filtering for the LPC1768:
http://mbed.org/users/ym1784/code/CAN_MONITOR/file/fe1f886dff76/main.cpp

Here cnt1 would be the handle. If I understand the datasheet correctly the can peripheral can also automatically move the received message from the buffer to RAM. Calling can->read can then return the requested message from RAM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that the type of the handle in api/CAN.h (read and filter) is an int and I'm not sure if this is generic enough. Thanks for the link, I'll take a closer look at the LPC1768 implementation.

emilmont added a commit that referenced this pull request Oct 25, 2013
Add CAN api filter support and LPC11CXX CAN implementation
@emilmont emilmont merged commit 317a1f6 into ARMmbed:master Oct 25, 2013
@emilmont
Copy link
Contributor

Yes, we like the API change. It works very well with the common concept of CAN bus "mailboxes".

Having it defaulted to 0 makes it compatible with all the existing code.

Thanks for your contribution.

deepakvenugopal added a commit to deepakvenugopal/mbed-os that referenced this pull request Feb 9, 2018
… from 8689fca..f6281ed

f6281ed CoAP transaction delete improvements (ARMmbed#91)
a4bb497 Add check for interface when receiving CoAP request (ARMmbed#92)
bca55ce Fix invalid memory read error (ARMmbed#90)

git-subtree-dir: features/nanostack/FEATURE_NANOSTACK/coap-service
git-subtree-split: f6281ed
geky pushed a commit to geky/mbed that referenced this pull request Aug 25, 2018
Config option for initialization frequency
yossi2le pushed a commit to yossi2le/mbed-os that referenced this pull request Jan 2, 2019
* Allow releasing for a single target

* Add doc for releasing single target
lrusinowicz pushed a commit to lrusinowicz/mbed-os that referenced this pull request Feb 5, 2019
Updating mbed-os to mbed-os-5.6.3
linlingao added a commit to linlingao/mbed-os that referenced this pull request Jul 12, 2019
Fixed a bug in soft reset where RTC is not enabled after soft reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants