Suggestion for Interrupt (Audiolib) / NVIC_SET_PENDING

Frank B

Senior Member
Code:
//Suggestion:
#define NVIC_STIR		(*(volatile uint32_t *)0xE000EF00) //Software Trigger Interrupt Register
//#define TRIGGER_INTERRUPT(x)    NVIC_SET_PENDING(x);
#define TRIGGER_INTERRUPT(x)    NVIC_STIR=(x);

Hi Paul, two little suggetions:
a) during the search of a good "free" software interrupt for the mp3/aac audioobject, i noticed, that there unused ("reserved") interruptnumbers.
You are using IRQ_SOFTWARE, and it is not free anymore for the user. You could use (for example) #55 instead, then IRQ_SOFTWARE stays available for the user.
b) there is a register called "NVIC_STIR", Software Trigger Interrupt Register, which basically does the same as the Pending-Register - but you don't need the shifts. This needs less instructions.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s01s01.html

Regards, Frank
 
Last edited:
you could also do something like this:

Code:
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  NVIC_ENABLE_IRQ(IRQ_SOFTWARE);
  attachInterruptVector( IRQ_SOFTWARE, softISR );
  
}


void loop() {
  NVIC_SET_PENDING(IRQ_SOFTWARE);
  delay(1000);
}


void softISR() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  Serial.println("ISR");
}
 
you could also do something like this:

Code:
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  NVIC_ENABLE_IRQ(IRQ_SOFTWARE);
  attachInterruptVector( IRQ_SOFTWARE, softISR );
  
}


void loop() {
  NVIC_SET_PENDING(IRQ_SOFTWARE);
  delay(1000);
}


void softISR() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  Serial.println("ISR");
}

yes thatss the reason for my suggestion not to use IRQ_SOFTWARE. for audiolib.
 
ah i see, you want to use it with audio library but couldn't you just use #55 instead also, but i agree that it would be an advatage to have that one open.
 
no,i could use #55, or any other. (i'm going to use #56)

working example:
Code:
//a)
#define RESERVED_INT  55 //or any other (reserved)
//b) optional
#define NVIC_STIR		(*(volatile uint32_t *)0xE000EF00)
#define TRIGGER_INTERRUPT(x)    NVIC_STIR=(x);


void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  NVIC_ENABLE_IRQ(RESERVED_INT);
   _VectorsRam[RESERVED_INT  + 16] = softISR;
  
}


void loop() {
  //Trigger int this way 
  // NVIC_SET_PENDING(RESERVED_INT);

  //Or this way:
  TRIGGER_INTERRUPT(RESERVED_INT)

  delay(1000);
}


void softISR() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
 
Back
Top