请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC2652R 主题中讨论的其他器件: CC2640R2F
SysTick 可用于实现20.833ns 精度(即与系统时钟相同的精度)的时间跟踪。
以下代码可用于替换空示例中 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等)