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.

CC2538的sleep timer无法进入中断

Other Parts Discussed in Thread: CC2538

您好, 我最近尝试将6TiSCH协议的代码移植到CC2538平台上,我使用了sleep timer用于设置定时休眠,但是我发现程序一直停在SleepModeTimerCompareSet()函数中的while(!(HWREG(SMWDTHROSC_STLOAD) & SMWDTHROSC_STLOAD_STLOAD));处,为啥一直在等待ST0,ST3准备写入,在执行该函数之前需要提前调用别的函数名,我在该函数的用户指导文件并未看到说明。该如何进行修改,可能是因为优先级不够吗。

  • 若是可以的话,能否给出相关代码?另外您可以参考文档内SleepModeTimerCompareSet的相关说明

    www.ti.com/.../swru325a.pdf

    (在文档内搜索 SleepModeTimerCompareSet)

    如 12.2.2.7 SleepModeTimerCompareSet
  • #define TIMERLOOP_THRESHOLD 0xffffff // 511 seconds @ 32768Hz clock
    #define MINIMUM_COMPAREVALE_ADVANCE 5

    // ========================== variable ========================================

    typedef struct {
    sctimer_cbt sctimer_cb;
    } sctimer_vars_t;

    sctimer_vars_t sctimer_vars;


    // ========================== private =========================================

    void sctimer_isr_internal(void);

    // ========================== protocol =========================================

    /**
    \brief Initialization sctimer.
    */
    void sctimer_init(void){
    memset(&sctimer_vars, 0, sizeof(sctimer_vars_t));
    //register sleep mode timer interrupt with ISR
    IntRegister(INT_SMTIM, &sctimer_isr_internal);
    //Enbale sleep mode interrupt from GPIO pin interrupt
    GPIOIntWakeupEnable(GPIO_IWE_SM_TIMER);
    //Disable sleep mode interrupt
    IntDisable(INT_SMTIM);
    IntPrioritySet(INT_SMTIM,3<<5);
    }

    void sctimer_set_callback(sctimer_cbt cb){
    sctimer_vars.sctimer_cb = cb;
    }

    /**
    \brief set compare interrupt
    */
    void sctimer_setCompare(uint32_t
    ){
    IntEnable(INT_SMTIM);
    if (SleepModeTimerCountGet() - val < TIMERLOOP_THRESHOLD){
    // the timer is already late, schedule the ISR right now manually
    IntPendSet(INT_SMTIM);
    } else {
    if (val-SleepModeTimerCountGet()<MINIMUM_COMPAREVALE_ADVANCE){
    // there is hardware limitation to schedule the timer within TIMERTHRESHOLD ticks
    // schedule ISR right now manually
    IntPendSet(INT_SMTIM);
    } else {
    // schedule the timer at val
    SleepModeTimerCompareSet(val);
    }
    }
    }

    /**
    \brief Return the current value of the timer's counter.

    \returns The current value of the timer's counter.
    */
    uint32_t sctimer_readCounter(void){
    return SleepModeTimerCountGet();
    }

    void sctimer_enable(void){
    IntEnable(INT_SMTIM);
    }

    void sctimer_disable(void){
    IntDisable(INT_SMTIM);
    }

    // ========================== private =========================================

    void sctimer_isr_internal(void){
    debugpins_isr_set();
    if (sctimer_vars.sctimer_cb!=NULL) {
    IntPendClear(INT_SMTIM);
    sctimer_vars.sctimer_cb();
    debugpins_isr_clr();
    }
    debugpins_isr_clr();
    }
  • 根据您的现有程序,暂时没有发现问题。

    请问您在调试时SMWDTHROSC_STLOAD与 SMWDTHROSC_STLOAD_STLOAD的值分别是多少?

    #define SMWDTHROSC_STLOAD_STLOAD \
    0x00000001 // Status signal for when STx
    // registers have been uploaded to
    // 32-kHz counter. 1: Load is
    // complete 0: Load is busy and STx
    // regs are blocked for writing
  • 我看了一下,他显示:Error (col 1): Unknown or ambiguous symbol. SMWDTHROSC_STLOAD_STLOAD,
    SMWDTHROSC_STLOAD_STLOAD:0

    因为是库函数,我决定应该不会出现逻辑问题,但是就一直卡在这个地方,应该是ST0-ST2无法写入

  • 确定问题所在,在调用系统时钟初始化函数:SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);不应设置第一个参数为true,在无外部晶振提供时钟服务的情况下应使用内部晶振。
  • 感谢您的详细反馈!