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.

[参考译文] CC2340R5:使用 RTC 作为内部中断从待机模式唤醒

Guru**** 2337880 points
Other Parts Discussed in Thread: CC2340R5
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/other-wireless-group/other-wireless/f/other-wireless-technologies-forum/1513115/cc2340r5-wake-up-from-standby-mode-using-the-rtc-as-an-internal-interrupt

器件型号:CC2340R5

工具/软件:

您好、

我正在使用 CC2340R5并成功实现了rfPacketTx示例代码、到目前为止、一切都正常运行。

我为内部中断编写了 RTC 中断设置和 ISR、但不起作用。 下面是我的代码供您参考—请检查并告诉我问题可能是什么。

#define RTC_CTL_EN       (1 << 0) // Enable bit
volatile bool rtcWakeFlag = false;

void RTC_IRQHandler(void)
{
    // Check if Compare Channel 1 (EV1) interrupt is pending
    if (HWREG(RTC_BASE + RTC_O_MIS) & RTC_MIS_EV1)
    {
        // Clear the EV1 interrupt flag
        HWREG(RTC_BASE + RTC_O_ICLR) = RTC_ICLR_EV1_CLR;

        // Set your application flag
        rtcWakeFlag = true;
    }
}

void setupRTCWakeup(uint32_t seconds)
{
    // Reset the RTC counter (if required)
    HWREG(RTC_BASE + RTC_O_CTL) = RTC_CTL_RST_CLR;

    // Enable RTC counter
    HWREG(RTC_BASE + RTC_O_CTL) |= RTC_CTL_EN;

    // Get current RTC time
    uint32_t now = HWREG(RTC_BASE + RTC_O_TIME8U); // bits [34:3] of counter
    uint32_t future = now + (seconds << 13); // RTC tick = 1/8192 s → seconds * 8192 ticks

    // Set Compare Channel 1 (CH1) to trigger at `future` time
    HWREG(RTC_BASE + RTC_O_CH1CC8U) = future;

    // Clear previous interrupt flag for EV1 (CH1)
    HWREG(RTC_BASE + RTC_O_ICLR) = RTC_ICLR_EV1_CLR;

    // Enable interrupt for EV1
    HWREG(RTC_BASE + RTC_O_IMSET) = RTC_IMSET_EV1;  // << Corrected

    // Register and enable RTC interrupt in NVIC
    IntRegister(INT_CPUIRQ0, RTC_IRQHandler);

    IntEnable(INT_CPUIRQ0);
    // Enable global interrupts
    IntEnableMaster();

}

提前感谢!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Kumar、

    我希望您做得好。 虽然我们应该能够按照您上述说明设置 RTC、但为了实现相同的用途、通常使用我们的计时器功能/驱动器会更容易一些。 此处是否有具体原因想要以这种方式而不是 ClockP/TIMER 来使用 RTC?  

    谢谢、
    Alex F

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Alex、

    感谢您的快速答复。 我已经使用 ClockP 实现了相同的功能。 然而、在开始编码之前、我设计了代码架构、旨在使用 RTC 从待机模式唤醒。

    如果我可以使用 RTC 实现我的原始架构目标、那就非常理想了、因为它与我的设计计划一致、并且无需进一步说明。

    如果使用 RTC 实现此目的有任何已知问题或限制、请告知我。 这样、我就可以在我的设计说明中清楚地记录下来(例如、"由于 TI 芯片的限制而未实现目标")为什么无法实施原始计划。


  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Kumar、

    在这种情况下、我将进一步了解 RTC 中断/回调。 我认为、使 RTC 在这里工作不应该有问题、但开始/设置可能会有点困难。 我可能需要联系其他内部成员、看看我们是否有任何其他相关文档或示例。

    谢谢、
    Alex F

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Kumar、

    以下主题可能对我们此处的案例很有用: https://e2e.ti.com/f/1/t/1234806/

    谢谢、
    Alex F

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Alex、

    感谢您的快速答复以及您为帮助解决此问题所做的努力。 我已经看到过这个主题、但我无法直接将其与我的特定问题联系起来。 如果您了解需要完成的操作、能否对我的代码进行必要的更改以使其正常工作?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Kumar、

    我之前编写了一些代码(*也来自以下 E2E、 https://e2e.ti.com/f/1/t/1500766/)、这使我们能够设置/使用 RTC 唤醒并每隔1秒切换一次 LED;您应该能够获取代码并将其应用到您的用例中:

    typedef struct rtc_struct_t
    {
        uint32_t                    delay_ticks;
        uint32_t                    rtc_timeout_ticks;
        HwiP_Struct                 hw_interrupt;
    } rtc_struct_t;
    rtc_struct_t rtc_struct;
    
    void rtc_isr_callback(uintptr_t arg)
    {
            rtc_struct.rtc_timeout_ticks += rtc_struct.delay_ticks;
            HWREG(RTC_BASE + RTC_O_CH0CC8U) = rtc_struct.rtc_timeout_ticks;
            GPIO_toggle((uint8_t)CONFIG_GPIO_GLED);
    }
    
    /*
     *  ======== mainThread ========
     */
    int mainThread(void)
    {
        uint32_t delay_usec;
        Board_init();
        GPIO_init();
        GPIO_setConfig(CONFIG_GPIO_GLED, GPIO_CFG_OUTPUT);
        GPIO_write(CONFIG_GPIO_GLED, 0);
    
        // Install the interrupt handler for the RTC.
        HwiP_Params rtc_params;
        HwiP_Params_init(&rtc_params);
        //rtc_params.arg = 0;
        //rtc_params.priority = INT_PRI_LEVEL2;
        HwiP_construct(&rtc_struct.hw_interrupt, INT_CPUIRQ0, rtc_isr_callback, &rtc_params);
        HWREG(EVTSVT_BASE + EVTSVT_O_CPUIRQ0SEL) = EVTSVT_CPUIRQ0SEL_PUBID_AON_RTC_COMB;
        delay_usec = 1E6;
        // Update the run-time status for this timer
        rtc_struct.delay_ticks = delay_usec/8UL;
    
        // Adjust timeout value to be relative to the current time.
        rtc_struct.rtc_timeout_ticks = HWREG(RTC_BASE + RTC_O_TIME8U) + rtc_struct.delay_ticks;
        HWREG(RTC_BASE + RTC_O_CH0CC8U) = rtc_struct.rtc_timeout_ticks;
        HwiP_enableInterrupt(INT_CPUIRQ0);
    
        while (1)
        {
            sleep(10);
        }
        return 0;
    }
    

    谢谢、
    Alex F