Other Parts Discussed in Thread: CC2640R2F
SysTick can be used to achieve time tracking with 20.833 ns accuracy (i.e. same accuracy as the System Clock).
More details, such as API description can be found here.
The code below can be used to replace the content of empty.c in the empty example.
This code does the following:
- triggers an interrupt (to toggle the red LED of the launchpad) every 1 second
- collect the systick value at pseudo random interval
/* 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; } }; }
Note: The code provided here is applicable to pretty much all the CC26xx and CC13xx devices (including CC2640R2F, CC2651, CC2652R7, CC1311, etc.)