Major update. The filtering system was optimised, and new features introduced.
1) The multiple mailbox function pointers now use indices instead of separate lines, cleaner.
Example,
Before:
Code:
_MB_ptr IFCT::_MB0handler = nullptr;
_MB_ptr IFCT::_MB1handler = nullptr;
_MB_ptr IFCT::_MB2handler = nullptr;
_MB_ptr IFCT::_MB3handler = nullptr;
_MB_ptr IFCT::_MB4handler = nullptr;
_MB_ptr IFCT::_MB5handler = nullptr;
_MB_ptr IFCT::_MB6handler = nullptr;
_MB_ptr IFCT::_MB7handler = nullptr;
_MB_ptr IFCT::_MB8handler = nullptr;
_MB_ptr IFCT::_MB9handler = nullptr;
_MB_ptr IFCT::_MB10handler = nullptr;
_MB_ptr IFCT::_MB11handler = nullptr;
_MB_ptr IFCT::_MB12handler = nullptr;
_MB_ptr IFCT::_MB13handler = nullptr;
_MB_ptr IFCT::_MB14handler = nullptr;
_MB_ptr IFCT::_MB15handler = nullptr;
_MB_ptr IFCT::_MBAllhandler = nullptr;
After:
Code:
_MB_ptr IFCT::_MBhandlers[16] = { nullptr };
_MB_ptr IFCT::_MBAllhandler = nullptr;
2) Mailbox setup and filter settings now return bool, 1 == success, 0 == fail
3) I added a new function call, Can0.currentMasks(), which displays on serial monitor the status of your mailbox filters:
Code:
FIFO enabled. Filters 0 to 7 used for FIFO.
Masks:
[ 0 ]: Flexcan Mask: 0x3FFF3FFF ( FIFO Filter )
^-- [Table B]
* Filter was not set
[ 1 ]: Flexcan Mask: 0xFFFFFFFF ( FIFO Filter )
^-- [Table B]
* User Mask 1: (Extended Mask) 0x3FFF
* User Mask 2: (Extended Mask) 0x3FFF
[ 2 ]: Flexcan Mask: 0xFEF7FEFF ( FIFO Filter )
^-- [Table B]
* User Mask 1: (Standard Mask) 0x7DE
* User Mask 2: (Standard Mask) 0x7DF
[ 3 ]: Flexcan Mask: 0x3FFF3FFF ( FIFO Filter )
^-- [Table B]
* Filter was not set
[ 4 ]: Flexcan Mask: 0x3FFF3FFF ( FIFO Filter )
^-- [Table B]
* Filter was not set
[ 5 ]: Flexcan Mask: 0x3FFF3FFF ( FIFO Filter )
^-- [Table B]
* Filter was not set
[ 6 ]: Flexcan Mask: 0x3FFF3FFF ( FIFO Filter )
^-- [Table B]
* Filter was not set
[ 7 ]: Flexcan Mask: 0x3FFF3FFF ( FIFO Filter )
^-- [Table B]
* Filter was not set
[ 8 ]: Flexcan Mask: 0x1F300000 ( Mailbox Filter )
^-- (Standard Mask) * User Mask: 0x7CC
[ 9 ]: Flexcan Mask: 0x00020002 ( Mailbox Filter )
^-- (Extended Mask) * User Mask: 0x20002
[ 10 ]: Flexcan Mask: 0x0003FFE0 ( Mailbox Filter )
^-- (Extended Mask) * User Mask: 0x3FFE0
[ 11 ]: Flexcan Mask: 0xFFFFFFFF ( Mailbox Filter )
^-- * Filter was not set
[ 12 ]: Flexcan Mask: 0xFFFFFFFF ( Mailbox Filter )
^-- * Filter was not set
[ 13 ]: Transmit Mailbox
[ 14 ]: Transmit Mailbox
[ 15 ]: Transmit Mailbox
4) Added mailbox distribution. This is a VERY useful feature when using duplicate or cross-filtering. If 2 callback filters receive same ID, the distribution code will send it to both mailboxes. The process is done by matching an incomming ID against the mailbox/FIFO local mask filtering via code, if the ID & MASK of that MB/FIFO filter match the ID of the received ID, it will be copied there as well. To enable this feature, just call Can0.distribute();.
Example:
You setup 2 filter ranges
Can0.setMBFilterRange(MB9, 0x10, 0x20);
Can0.setMBFilterRange(MB10, 0x18, 0x25);
When your callbacks fire, IDs 0x10-> 0x20 will enter MB9 callback and IDs 0x18->0x25 enter MB10 callback.
Normally, it's first come first serve, and the ID will goto only one mailbox, and you need to handle it as you wish.
If you expect the 2nd mailbox to receive the IDs between 0x18->0x20, may the odds be for ever in your favour
The distribution code will assure that the 2nd callback gets the message as well, as long as the incomming ID matches against the mask list.
Enhancement is supported for distributions as well.
5) Added Table B and C support for enhanced filtering.
Table A allows either standard or extended ids with all bits checked, with IFCT you get 2,3,4 and 5 ID support, as well as ranged based IDs.
TableB uses all bits for masking 11bit IDs, extended ID's are only masked the 14 most significant bits. This table has dual ID support, a bonus of quad ID support via IFCT, and dual range based IDs.
TableC uses only 11 most significant bits of any ID, be it extended or standard. If enhancement is enabled for Table C, only the 4 set IDs per filter will be received, essentially
giving you up to 32 ID receptions using 8 filters if RFFN is 0;
Tony