Skip to content

Commit a16dc72

Browse files
committed
Add @param documentation for new event parameter
Add clear irq to attach() template function Call irq_handler for every interrupt set
1 parent 63b2b27 commit a16dc72

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

libraries/mbed/api/CAN.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class CAN {
162162
* generated.
163163
*
164164
* @param fptr A pointer to a void function, or 0 to set as none
165+
* @param event Which can interrupt to attach the member function to (CAN::IRQ_RX, CAN::IRQ_TX, CAN::IRQ_ERROR, CAN::IRQ_OVERRUN, CAN::IRQ_WAKEUP, CAN::IRQ_PASSIVE, CAN::IRQ_ARB, CAN::IRQ_BUS, CAN::IRQ_READY) - Note that not every event is supported by all hardware
165166
*/
166167
void attach(void (*fptr)(void), can_irq_event event=IRQ_RX);
167168

@@ -170,13 +171,17 @@ class CAN {
170171
*
171172
* @param tptr pointer to the object to call the member function on
172173
* @param mptr pointer to the member function to be called
174+
* @param event Which can interrupt to attach the member function to (CAN::IRQ_RX, CAN::IRQ_TX, CAN::IRQ_ERROR, CAN::IRQ_OVERRUN, CAN::IRQ_WAKEUP, CAN::IRQ_PASSIVE, CAN::IRQ_ARB, CAN::IRQ_BUS, CAN::IRQ_READY) - Note that not every event is supported by all hardware
173175
*/
174176
template<typename T>
175177
void attach(T* tptr, void (T::*mptr)(void), can_irq_event event=IRQ_RX) {
176178
if((mptr != NULL) && (tptr != NULL)) {
177-
_irq[type].attach(tptr, mptr);
179+
_irq[event].attach(tptr, mptr);
178180
can_irq_set(&_can, event, 1);
179181
}
182+
else {
183+
can_irq_set(&_can, event, 0);
184+
}
180185
}
181186

182187
static void _irq_handler(uint32_t id, can_irq_event event);

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,25 @@ static inline void can_enable(can_t *obj) {
7979
}
8080

8181
static inline void can_irq(uint32_t icr, uint32_t index) {
82-
#warning TODO(@jorisa) Check that events not happen at same time
83-
can_irq_event event;
84-
switch (icr) {
85-
case (1 << 0): event = IRQ_RX; break;
86-
case (1 << 1): event = IRQ_TX; break;
87-
case (1 << 2): event = IRQ_ERROR; break;
88-
case (1 << 3): event = IRQ_OVERRUN; break;
89-
case (1 << 4): event = IRQ_WAKEUP; break;
90-
case (1 << 5): event = IRQ_PASSIVE; break;
91-
case (1 << 6): event = IRQ_ARB; break;
92-
case (1 << 7): event = IRQ_BUS; break;
93-
case (1 << 8): event = IRQ_READY; break;
94-
default: return;
82+
uint32_t i;
83+
84+
for(i = 0; i < 8; i++)
85+
{
86+
if((can_irq_ids[index] != 0) && (icr & (1 << i)))
87+
{
88+
switch (i) {
89+
case 0: irq_handler(can_irq_ids[index], IRQ_RX); break;
90+
case 1: irq_handler(can_irq_ids[index], IRQ_TX); break;
91+
case 2: irq_handler(can_irq_ids[index], IRQ_ERROR); break;
92+
case 3: irq_handler(can_irq_ids[index], IRQ_OVERRUN); break;
93+
case 4: irq_handler(can_irq_ids[index], IRQ_WAKEUP); break;
94+
case 5: irq_handler(can_irq_ids[index], IRQ_PASSIVE); break;
95+
case 6: irq_handler(can_irq_ids[index], IRQ_ARB); break;
96+
case 7: irq_handler(can_irq_ids[index], IRQ_BUS); break;
97+
case 8: irq_handler(can_irq_ids[index], IRQ_READY); break;
98+
}
99+
}
95100
}
96-
97-
if (can_irq_ids[index] != 0)
98-
irq_handler(can_irq_ids[index], event);
99101
}
100102

101103
// Have to check that the CAN block is active before reading the Interrupt

0 commit comments

Comments
 (0)