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.

28335的cputimer1和cputimer0怎么嵌套使用?



cputimer0频率为10Khz,cputimer1频率为1khz,cputimer0中断中的程序执行时间为64us,剩下36us。想设置cputimer0的优先级比cputimer1的优先级高,当cputimer0中的程序执行完后,剩下的36us执行cputimer1中的程序,当100us到达时,cputimer0中断打断cputimer1中断,执行cputimer0中的程序,cputimer0执行完后,cputimer1继续执行,请问改怎么编写程序?

  • 对你的问题解答如下:

    1 TI DSP的中断是不支持中断嵌套的,只能按照中断优先级顺序进行,可以参考PIE相关文档查看CPU是如何通过IE和IF处理中断信号的;

    2 如果你一定要实现这个功能,也是可以的,cputimer0 10KHz的程序在cputimer0中断程序中执行,cputimer1的程序在main while循环中执行,cputimer1中断仅仅提供1khz计时标志位就好了,这样可以实现1khz程序在10khz程序间隙运行的目标;

    reference code:

    interrupt void cputimer0(void)

    {

    10khz task code run;

    }

    interrupt void cputimer1(void)

    {

    1hhz flag = 1;

    }

    void main(void)

    {

    while(1)

    {

        if(1hhz flag ==  1)

        {

            1khz task code run;

        }

    }

    }

  • cputimer0的优先级本身就 是比cputimer1高,不用设置,进入cputimer1中断后先开通全局中断(忘记28335中是否还需要这样操作了,保险起见这样设置),以免cputimer0进入不了中断。需要注意的就是各级中断程序执行的时间与你预想是否一致。