This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652R7: Disabling and enabling interrupts globally

Part Number: CC2652R7


Hi

I have a critical section (CS) in my code. I need to disable all interrupts before starting the CS and need to enable them back after the CS. In the simplelink SDK, is there any way to disable and enable interrupts globally?

Also, is there any other way to do that?

Thanks

  • Hi Vivek,

    You can refer to HAL_ENTER_CRITICAL_SECTION from hal_mcu or OsalPort_enterCS if your application uses osal_port.

    Regards,
    Ryan

  • We are not using osal_port. Where can I find the hal_mcu file? I did a search in the sdk folder. I could find it only in the ble5stack folder or ti154stack folder. Do I need to include these stacks in the code mandatorily?

    Or, is there any other way to include the file?

  • Are you using a radio stack?  It will be included in these projects by default.  It's ultimately a call to HwiP_disable (HwiP_tirtos) or Hwi_disable (Hwi)

    /* Enter critical section */
    #define HAL_ENTER_CRITICAL_SECTION(x)                   \
      do { x = HwiP_disable(); } while (0)
    
    /* Exit critical section */
    #define HAL_EXIT_CRITICAL_SECTION(x)                    \
      do { HwiP_restore(x); } while (0)

    BLE5-Stack uses an Icall implementation

    /* For now critical sections completely disable hardware interrupts
     * because they are used from ISRs in MAC layer implementation.
     * If MAC layer implementation changes, critical section
     * implementation may change to reduce overall interrupt latency.
     */
    /* Enter critical section implementation. See header file for comment. */
    ICall_CSState ICall_enterCSImpl(void)
    {
      ICall_CSStateUnion cu;
      cu.each.swikey = (uint_least16_t) Swi_disable();
      cu.each.hwikey = (uint_least16_t) Hwi_disable();
      return cu.state;
    }
    
    /* See header file for comment */
    ICall_EnterCS ICall_enterCriticalSection = ICall_enterCSImpl;
    
    /* leave critical section implementation. See header file for comment */
    void ICall_leaveCSImpl(ICall_CSState key)
    {
      ICall_CSStateUnion *cu = (ICall_CSStateUnion *) &key;
      Hwi_restore((UInt) cu->each.hwikey);
      Swi_restore((UInt) cu->each.swikey);
    }

    You can find more information in the TI-RTOS7 Kernel documentation and SimpleLink MCU SDK User's Guide.  I must caution about critical section usage as this could block other application activity from being completed in the time expected.

    Regards,
    Ryan

  • Thank you and I understand the problem associated with it. Can I use semaphores before and after the critical section?

  • Use of semaphores around, but not contained within, critical sections is allowed.  Once again, please refer to the TI-RTOS7 and SYS/BIOS documentation.

    Regards,
    Ryan