Skip to content

Commit 317a1f6

Browse files
committed
Merge pull request #91 from jorisa/master
Add CAN api filter support and LPC11CXX CAN implementation
2 parents 9d88177 + 739f2a6 commit 317a1f6

File tree

10 files changed

+2236
-21
lines changed

10 files changed

+2236
-21
lines changed

libraries/mbed/api/CAN.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,13 @@ class CAN {
131131
/** Read a CANMessage from the bus.
132132
*
133133
* @param msg A CANMessage to read to.
134+
* @param handle message filter handle (0 for any message)
134135
*
135136
* @returns
136137
* 0 if no message arrived,
137138
* 1 if message arrived
138139
*/
139-
int read(CANMessage &msg);
140+
int read(CANMessage &msg, int handle = 0);
140141

141142
/** Reset CAN interface.
142143
*
@@ -169,6 +170,19 @@ class CAN {
169170
*/
170171
int mode(Mode mode);
171172

173+
/** Filter out incomming messages
174+
*
175+
* @param id the id to filter on
176+
* @param mask the mask applied to the id
177+
* @param format format to filter on (Default CANAny)
178+
* @param handle message filter handle (Optional)
179+
*
180+
* @returns
181+
* 0 if filter change failed or unsupported,
182+
* new filter handle if successful
183+
*/
184+
int filter(unsigned int id, unsigned int mask, CANFormat format = CANAny, int handle = 0);
185+
172186
/** Returns number of read errors to detect read overflow errors.
173187
*/
174188
unsigned char rderror();

libraries/mbed/api/can_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ extern "C" {
2424

2525
enum CANFormat {
2626
CANStandard = 0,
27-
CANExtended = 1
27+
CANExtended = 1,
28+
CANAny = 2
2829
};
2930
typedef enum CANFormat CANFormat;
3031

libraries/mbed/common/CAN.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ int CAN::write(CANMessage msg) {
3939
return can_write(&_can, msg, 0);
4040
}
4141

42-
int CAN::read(CANMessage &msg) {
43-
return can_read(&_can, &msg);
42+
int CAN::read(CANMessage &msg, int handle) {
43+
return can_read(&_can, &msg, handle);
4444
}
4545

4646
void CAN::reset() {
@@ -63,19 +63,23 @@ int CAN::mode(Mode mode) {
6363
return can_mode(&_can, (CanMode)mode);
6464
}
6565

66-
void CAN::attach(void (*fptr)(void), IrqType type) {
67-
if (fptr) {
68-
_irq[(CanIrqType)type].attach(fptr);
69-
can_irq_set(&_can, (CanIrqType)type, 1);
70-
} else {
71-
can_irq_set(&_can, (CanIrqType)type, 0);
72-
}
73-
}
66+
int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle) {
67+
return can_filter(&_can, id, mask, format, handle);
68+
}
7469

75-
void CAN::_irq_handler(uint32_t id, CanIrqType type) {
76-
CAN *handler = (CAN*)id;
77-
handler->_irq[type].call();
70+
void CAN::attach(void (*fptr)(void), IrqType type) {
71+
if (fptr) {
72+
_irq[(CanIrqType)type].attach(fptr);
73+
can_irq_set(&_can, (CanIrqType)type, 1);
74+
} else {
75+
can_irq_set(&_can, (CanIrqType)type, 0);
7876
}
77+
}
78+
79+
void CAN::_irq_handler(uint32_t id, CanIrqType type) {
80+
CAN *handler = (CAN*)id;
81+
handler->_irq[type].call();
82+
}
7983

8084
} // namespace mbed
8185

libraries/mbed/hal/can_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ void can_irq_free (can_t *obj);
6363
void can_irq_set (can_t *obj, CanIrqType irq, uint32_t enable);
6464

6565
int can_write (can_t *obj, CAN_Message, int cc);
66-
int can_read (can_t *obj, CAN_Message *msg);
66+
int can_read (can_t *obj, CAN_Message *msg, int handle);
6767
int can_mode (can_t *obj, CanMode mode);
68+
int can_filter (can_t *obj, unsigned int id, unsigned int mask, CANFormat format, int handle);
6869
void can_reset (can_t *obj);
6970
unsigned char can_rderror (can_t *obj);
7071
unsigned char can_tderror (can_t *obj);

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/bitfields.h

Lines changed: 1768 additions & 0 deletions
Large diffs are not rendered by default.

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99

1010
#include "LPC11xx.h"
1111
#include "cmsis_nvic.h"
12+
#include "bitfields.h"
1213

1314
#endif

0 commit comments

Comments
 (0)