Author Topic: conditionally execute interrupt handler function  (Read 2313 times)

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
conditionally execute interrupt handler function
« on: January 16, 2021, 06:33:25 AM »
Hi,

I'm using the KL03. I have two independent parallel tasks.
One task changes from one state to another periodically. This is the simplified code:

Code: [Select]
case 1:
nState  = 2;
uTaskerMonoTimer('B', (DELAY_LIMIT) (2 * SEC), UTASKER_ACTIVATE);
break;

case 2:
nState = 1;
uTaskerMonoTimer('B', (DELAY_LIMIT) (3 * SEC), UTASKER_ACTIVATE);
break;


The other task configures a port interrupt (on a GPIO pin) and its handling function fn_rx_interrupt_handler is called whenever the interrupt is triggered externally on that pin.

Code: [Select]
static void fn_rx_interrupt_handler(void) {
fn_b();
}

All this works.

Now, I want that fn_b() is executed ONLY if nSTate==1, so I simply do:

Code: [Select]
static void fn_rx_interrupt_handler(void) {
if (nState == 1) {
fn_b();
}
}
But this doesn't work. The task ignores the interrupt. Even if I try to put the control of nState in fn_b, it still doesn't work. It is as if that if statement in the interrupt disables it

Any idea why and what I can do?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: conditionally execute interrupt handler function
« Reply #1 on: January 16, 2021, 03:43:17 PM »
Hi

From the code shown there is no reason visible that explains why it shouldn't work.

1. Ensure that the code is being rebuilt after this change by doing first a clean and then rebuild
2.Ensure that you don't have two local variables nState - one local (static) one in the file which is changing the value and one local (static) in the file that is making the decision [if that were the case it would be valid code but there would be two variables, rather than a single shared one, whereby the one being used for the conditional execution would probably always be 0]

Regards

Mark