pierremolinaro / acan2515

MCP2515 CAN Controller Driver for Arduino
MIT License
76 stars 30 forks source link

Feature request: Interruptable ISR #28

Open wangnick opened 3 years ago

wangnick commented 3 years ago

Hi Pierre,

I found that I can allow the ISR to be interruptable, thereby lowering the latency of other interrupts significantly, as follows:

static void can_isr () { // We don't want to block interrupts whilst performing low-level CAN processing ...
  detachInterrupt(digitalPinToInterrupt(CAN_INT)) ;
  interrupts();
  can.isr();
  noInterrupts();
  attachInterrupt(digitalPinToInterrupt(CAN_INT),can_isr,LOW);
}

However, that's a bit of a hassle, including the attachInterrupt after ACAN2515::begin and the detachInterrupt prior to ACAN2515::end.

Can you add ISR interuptability as an option?

Kind regards, Sebastian

pierremolinaro commented 3 years ago

Hi Sebastian,

On which platform did you run this code? I'm not sure if it runs on all. I propose to add your code in the documentation, indicating the precautions of use.

Kind Regards,

Pierre

Le 31 mai 2021 à 15:07, wangnick @.***> a écrit :

Hi Pierre,

I found that I can allow the ISR to be interruptable, thereby lowering the latency of other interrupts significantly, as follows:

static void can_isr () { // We don't want to block interrupts whilst performing low-level CAN processing ... detachInterrupt(digitalPinToInterrupt(CAN_INT)) ; interrupts(); can.isr(); noInterrupts(); attachInterrupt(digitalPinToInterrupt(CAN_INT),can_isr,LOW); } However, that's a bit of a hassle, including the attachInterrupt after ACAN2515::begin and the detachInterrupt prior to ACAN2515::end.

Can you add ISR interuptability as an option?

Kind regards, Sebastian

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/28, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVCCIS6JAGOS4PDJK3DTQOC2DANCNFSM4523RVDQ.

wangnick commented 3 years ago

Hi Pierre, this is on an Atmega328PB, but I guess it should work on all AVR 8-bit platforms. I guess you are concerned about the ESP32?

Kind regards, Sebastian

pierremolinaro commented 3 years ago

Hi Sebastian,

Ok, it is a 8-bit microcontroller.

Yes about ESP32, and also for all Cortex-M based microcontrollers. A Cortex-M implements a Nested Vectored Interrupt Controller that allows interrupts to be nested, but we have to set interrupt priorities carefully.

I need somme times to make some experimentations with a Teensy 3.5, a bord with a Cortex-M4 microcontroller.

Kind Regards,

Pierre

Le 4 juin 2021 à 16:17, wangnick @.***> a écrit :

Hi Pierre, this is on an Atmega328PB, but I guess it should work on all AVR 8-bit platforms. I guess you are concerned about the ESP32?

Kind regards, Sebastian

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/28#issuecomment-854761702, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVDEJPOFQTROCFJJ2YLTRDN6HANCNFSM4523RVDQ.