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.

[FAQ] [参考译文] [常见问题解答] CC2652R:如何使用 SysTick?

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

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1164777/faq-cc2652r-how-to-use-systick

器件型号:CC2652R
主题中讨论的其他器件: CC2640R2F

SysTick 可用于实现20.833ns 精度(即与系统时钟相同的精度)的时间跟踪。  

如需了解更多详细信息、如 API 说明 、请点击此处。

以下代码可用于替换空示例中 empty.c 的内容。

此代码执行以下操作:

  • 每隔1秒触发一次中断(以切换 Launchpad 的红色 LED)
  • 以伪随机间隔收集 SysTick 值

/* Driver Header files */
#include <ti/drivers/GPIO.h>

/* RTOS header files */
#include <ti/sysbios/BIOS.h>

/* Driver configuration */
#include "ti_drivers_config.h"

/* For Systick */
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/systick.h)
#include DeviceFamily_constructPath(driverlib/interrupt.h)

/*
 *  ======== mainThread ========
 */
/* Systick callback executed every time the timer is wrapped */
void TickTimerISR(void){
    GPIO_toggle(CONFIG_GPIO_LED_0);
}

const int NUM_TS_SAMPLES = 100;
uint32_t tickstamps[NUM_TS_SAMPLES] = {0};

void *mainThread(void *arg0)
{
     int i;

     /* GPIO initialization and configuration */
     GPIO_init();
     GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

     /* Systick  configuration */
     SysTickDisable();
     SysTickPeriodSet(48000000); // 1s interrupt timing ==> TickTimerISR() is executed every 1 second
     SysTickIntRegister(TickTimerISR);
     SysTickIntEnable();
     SysTickEnable();
     IntMasterEnable();


     while(1) {

         /* Random delay */
         volatile int delay = (123456 + 7890123*tickstamps[i]) % 1234567;

         /* Systick collection */
         tickstamps[i++] = SysTickValueGet();

         if(i == NUM_TS_SAMPLES)
         {
             i = 0;
         }
     };
}

注意:此处提供的代码几乎适用于所有 CC26xx 和 CC13xx 器件(包括 CC2640R2F、CC2651、CC2652R7、CC1311等)

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

    感谢 Cl é ment 提供的信息!