[SOLVED] Call OS_EnterInterrupt() inside IRQHandler throws an error

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Call OS_EnterInterrupt() inside IRQHandler throws an error

    Hello,

    I'm using EmbOS version: 5.06.1 on an IMXRT1062 board with a ARM Cortex M7.
    I'm writing my own driver for CANbus and I have defined some interrupt service routines that executes every time I send/receive a message.

    This is how I initialize the CAN and the IRQHandlers :

    ---------------------------------------------------------------------------------------
    /* Interrupt handlers. */
    extern "C" void CAN1_IRQHandler(void)
    {
    MISRAC_DISABLE
    OS_EnterInterrupt();
    can1.interrupt_handler();
    OS_LeaveInterrupt();
    MISRAC_ENABLE
    }

    extern "C" void CAN2_IRQHandler(void)
    {
    MISRAC_DISABLE
    OS_VFP_Save();
    OS_EnterInterrupt();
    can2.interrupt_handler();
    OS_LeaveInterrupt();
    OS_VFP_Restore();
    MISRAC_ENABLE
    }

    /**
    * Init method for CAN
    */
    void imx1062_can_t::init(uint32_t bitrate)
    {

    OS_IncDI(); /*disable interrupts*/

    /* Init FlexCAN module. */
    FLEXCAN_GetDefaultConfig(&flexcanConfig);
    FLEXCAN_Init(this->can_ptr, &flexcanConfig, 40000000U);


    NVIC_SetPriority(CAN2_IRQn, 5u);
    NVIC_EnableIRQ(CAN2_IRQn);

    /* Setup RX message buffer to receive any ID */
    setupRxMessageBuffer(kFLEXCAN_FrameFormatStandard, kFLEXCAN_FrameTypeData);

    /* Set IMASK such that an interrupt is triggered on message receive in message buffer MESSAGE_OB_RX (community.nxp.com/thread/459431)*/
    this->can_ptr->IMASK1 = 1 << MESSAGE_OBJ_RX;

    OS_DecRI(); /*enable interrupts*/
    }
    ------------------------------------------------------------------------------------------------------------
    Since in the method interrupt_handler() I make some calls to OS functions (like OS_PutMail used for mailboxes) If I'm not mistaken I have to tell the OS that I'm within an interrupt, with the methods OS_EnterInterrupt() and OS_LeaveInterrupt().

    However, when OS_EnterInterrupt() gets executed, it throws a status error. I don't know where it is thrown because I cannot debug inside these methods.

    I saw some other threads in this community about my same problem, I tried to do what they tell to do:
    1) set the priority to a value higher then 127
    2) try to use the 'ARM' version of the methods to enable the interrupt

    //OS_ARM_InstallISRHandler(CAN2_IRQn, (OS_ISR_HANDLER*) CAN2_IRQHandler);
    //OS_ARM_ISRSetPrio(CAN2_IRQn, 130); // Set prio < 128
    //OS_ARM_EnableISR(CAN2_IRQn);

    But it didn't work.

    How can I fix it?

    thank you in advance,
    Giacomo
  • Dear Giacomo,

    j000 wrote:

    Since in the method interrupt_handler() I make some calls to OS functions (like OS_PutMail used for mailboxes) If I'm not mistaken I have to tell the OS that I'm within an interrupt, with the methods OS_EnterInterrupt() and OS_LeaveInterrupt().
    Yes, that's correct.

    Which error code do you get? Most likely you are using an invalid interrupt priority.
    The iMXRT1062 has four interrupt priority bits implemented, thus NVIC_SetPriority() expects values from 0 to 15 and 0 is the highest priority.

    j000 wrote:

    NVIC_SetPriority(CAN2_IRQn, 5u);
    This is an invalid interrupt priority for embOS interrupts. Please try e.g. NVIC_SetPriority(CAN2_IRQn, 10u) instead.

    Please have a look here for more details: wiki.segger.com/Interrupt_prioritization

    Does that solve your issue? If not please let me know.

    Best regards,
    Til
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.