Author Topic: Task executed only once and then from interrupt  (Read 4025 times)

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Task executed only once and then from interrupt
« on: January 03, 2020, 01:59:27 AM »
Hi I have a task that should be executed once (to set up some pins and variables) and then executed based on an external interrupt. However the task is executed periodically and every time it repeats the set-up. Basically, the if (iState) is entered periodically and the OUTPUT_PIN doesn't stay low but goes high between executions


#include "config.h"

#define OUTPUT_PIN              PORTB_BIT5
#define SETUP_PIN()  _CONFIG_DRIVE_PORT_OUTPUT_VALUE(B, OUTPUT_PIN, OUTPUT_PIN, (PORT_SRE_FAST | PORT_DSE_LOW));
#define SET_PIN_LOW()      _CLEARBITS(B, OUTPUT_PIN)
#define SET_PIN_HIGH()     _SETBITS(B, OUTPUT_PIN)   

static int iState = 0;

static void fn_my_interrupt(void)
{
   fnInterruptMessage(TASK_MY_INTERRUPT, 141);
}



extern void fnTaskMyInterrupt(TTASKTABLE *ptrTaskTable) {

   QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID;
   unsigned char ucInputMessage[MEDIUM_MESSAGE];
   
   if (!iState) {
      SETUP_PIN();
      SET_PIN_LOW();
      
            INTERRUPT_SETUP interrupt_setup;                                     // interrupt configuration parameters
       interrupt_setup.int_type       = PORT_INTERRUPT;                     // identifier to configure port interrupt
       interrupt_setup.int_handler    = fn_my_interrupt;                    // handling function
       interrupt_setup.int_priority   = PRIORITY_PORT_B_INT;                 // interrupt priority level
       interrupt_setup.int_port       = PORTB;                 // the port that the interrupt input is on
       interrupt_setup.int_port_bits  = PORTB_BIT4;                      // the IRQ input connected
       interrupt_setup.int_port_sense = IRQ_FALLING_EDGE ;// | PULLUP_ON);     // interrupt is to be falling edge sensitive
       fnConfigureInterrupt((void *)&interrupt_setup);
       iState = 1;
       //uTaskerStateChange(TASK_MY_INTERRUPT, UTASKER_SUSPENDED);
   }


   while (fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH)) {
      switch (ucInputMessage[MSG_SOURCE_TASK]) {
      case 141 :
         // YOUR CODE HERE //
         SET_PIN_HIGH();
      break;
      }
      break;
      }
}




Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Task executed only once and then from interrupt
« Reply #1 on: January 03, 2020, 02:09:29 AM »
Hi

If iState is set to 0 when the task is entered a second time I expect that there was a reset taking place. Since you are setting it to 1 when the initialisation has been performed it should not otherwise be possible to be reset to 0; this is irrespective of whether the task is scheduled a second time or not.

Check that there is not a periodic watchdog interrupt taking place.

Regards

Mark

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Task executed only once and then from interrupt
« Reply #2 on: January 03, 2020, 05:23:29 AM »
Thank you Mark,
that is the behavior I was expecting in fact. And the watchdog is disabled, but there is something that every second retriggers it
I use the command {"r", fnTaskMyInterrupt, NO_QUE,  (DELAY_LIMIT)(0.5 * SEC), UTASKER_STOP}, in TaskConfig to execute the task the first time. I tried other variations (UTASKER_GO etc) but no much luck
« Last Edit: January 03, 2020, 05:47:02 AM by Raffaele »

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Task executed only once and then from interrupt
« Reply #3 on: January 03, 2020, 05:57:01 PM »
I've been doing few tests, unless there is something wrong in my code, it looks like there is a reset every second. In fact the static or global iState variable switches between 0 and 1 every  (DELAY_LIMIT)(0.5 * SEC)

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Task executed only once and then from interrupt
« Reply #4 on: January 03, 2020, 11:08:31 PM »
Hi

Check the reset cause in the
SIM_SRSID, RCM_SRS0 or MC_SRSH /  MC_SRSL register(s), depending on the processor used.

If you have disabled the watchdog task make sure that you have
#define WATCHDOG_DISABLE() 1

Regards

Mark

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Task executed only once and then from interrupt
« Reply #5 on: January 04, 2020, 04:08:20 AM »
ok I was able to fix the problem. The only thing now is that my handler function doesn't get called. I was expecting that whenever a FALLING_EDGE signal is on PTB4 the function fn_my_interrupt should be called but nothing happens

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Task executed only once and then from interrupt
« Reply #6 on: January 04, 2020, 02:46:29 PM »
Hi

Which processor are you using? Not all support interrupts on every port - if you build and test in the simulator there is generally an exception when configuring for a non-supported interrupt.

Verify also that SUPPORT_PORT_INTERRUPTS is enabled so that the port interrupt driver is present.

Regards

Mark

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Task executed only once and then from interrupt
« Reply #7 on: January 04, 2020, 05:36:39 PM »
The microcontroller is the KL03 so the Cortex M0+

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Task executed only once and then from interrupt
« Reply #8 on: January 04, 2020, 08:54:34 PM »
Verify also that SUPPORT_PORT_INTERRUPTS is enabled so that the port interrupt driver is present.

Great, this was part of the problem.
Also my code works on a KL03 20-pin WLCSP, but didn't fully work on the FRDM-LK03Z.
But essentially this solved my issue.

Thank you again Mark :)