Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Change radio ISR at runtime


#1

Hi,

I want to know how to define my own ISR and set it dynamically at run time. First, here’s some background info.

I have an application where I want to use both the radioCom and radioQueue libraries. They’re not being used simultaneously, exactly. But rather, the application can switch between two modes based on user input, and each mode uses one of the two radio libraries.

At first, I couldn’t get my application to compile because of multiple definitions of radioMacEventHandler. So I made copies of radioCom, radioLink, and radioMac and called them radioCom2, radioLink2, and radioMac2. And then I renamed radioMacEventHandler in these copied libs to radioMacEventHandler2.

Now the application won’t compile because of multiple definitions of the RF ISR. My thought is to give the RF ISR inside of radioMac2 a different name and then change the RF ISR at runtime.

As I understand it, there are 2 things I need to do:

  1. Define my own ISR with a different name, but with the function definition copied from the current RF ISR
    e.g. void my_isr(void) { ... copy from RF ISR ...}
    But I’m pretty sure SDCC adds instructions to the beginning and end of an ISR to save registers and return with a RETI instead of RET. Do I just need to add __interrupt() to the function signature to make it safe to call from an interrupt?

  2. What do I put at the RF interrupt vector address, and how do I do it, so that my_isr gets called? From the data sheet, the relevant vector address is 0x83.

Please give me your thoughts on 1 and 2 above. Or if you think there’s a better way to accomplish my general goal of compiling radioQueue and radioCom on one app, I’d like to hear that too.

Thanks


#2

On question #2, I’m actually not sure if it’s possible to change the contents of the RF interrupt vector. Is that location in flash or RAM?


#3

Hello.

If you want to define your own radio ISR, you should do it the same way that the radio_mac library does it, using the ISR macro provided by the Wixel SDK.

The ISR vector table is stored in flash so it is not practical to modify it at runtime. I suggest that you define a variable that says what ISR behavior you want, and then check it at runtime inside your ISR. For example:


#define RF_MODE_A 0
#define RF_MODE_B 1

volatile BIT rfMode = RF_MODE_A;

ISR(RF, 0)
{
  if (rfMode == RF_MODE_A)
  {
    // ...
  }
  else
  {
    // ...
  }
}

–David


#4

Got it, thanks David.