I am working in a direction to use SysTick timer in order to record a time period in between two events and save it in a variable. SysTick Timer has not any dedicated API to get time period from it. Can anybody please guide me to resolve this?
The answer is "CySysTickGetValue()". Have a look into "System Reference Guide", Boot Component 5.20. There are all the APIs for the SysTick timer.
This is example of using SysTick timer on PSoC4 and 5 to measure number of CPU cycles. Limit is 2^24 CPU ticks (about 0.7sec @24MHz CPU speed), as SysTick counter on Cortex M0 and M3 can not go beyond SYSTICK_MAXVAL:
#define SYSTICK_MAXVAL 0x00FFFFFF //max allowed SysTick counter value for 24bit
uint32 SysCntVal; // The value of SysTick counter you are trying to retrieve
SysTick_Config(SYSTICK_MAXVAL); //reset counter set to max value, 1-time, will not reload
//do some operations here..
SysCntVal = SYSTICK_MAXVAL - (SysTick->VAL); //get elapsed ticks (min offset 3 ticks)
sprintf(strMsg, "%d\r\n", SysCntVal); //report result
Note that SysTick counter will not reload this way (it will quietly expires). It is possible to roll over 2^24 cpunts by enabling SysTick interrupt and resetting the timer, but doing this accumulates errors