-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
Add filter function and modify CAN->read definition to allow reading specific messages.
Generated from UM10398
Most of the functionality works, interrupts might need a little more work.
Nice to see that you've got the CAN done Joris :)
|
* | ||
* @returns | ||
* 0 if no message arrived, | ||
* 1 if message arrived | ||
*/ | ||
int read(CANMessage &msg); | ||
int read(CANMessage &msg, int handle = 0); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Add CAN api filter support and LPC11CXX CAN implementation
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. |
… 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
Config option for initialization frequency
* Allow releasing for a single target * Add doc for releasing single target
Updating mbed-os to mbed-os-5.6.3
Fixed a bug in soft reset where RTC is not enabled after soft reset
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