CyLib.h defines the following:
void CySysTickSetReload(uint32 value);
cySysTickCallback CySysTickSetCallback(uint32 number, cySysTickCallback function);
cySysTickCallback CySysTickGetCallback(uint32 number);
You can look at the implementation in CyLib.c
I believe this infrastructure starts a 1ms tick and allows on to register one's own call-backs to be called every ms. There is a note that some components may rely on this functionality so disrupting it will affect their operation. You can also access the SysTick API directly through through the ARM CMSIS API. See, for example core_cm0.h on the PSoC4 and the ARM reference manual for the CortexM0.
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
// SysTick Timer counts down on each tick of 24MHz CPU clock
SysTick->LOAD = 0x00ffffff;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
I have not enabled interrupts, I was just using this for timing
uint32_t startTick = SysTick->VAL;
uint32_t stopTick1 = SysTick->VAL;
uint32_t timeDiff = (startTick - stopTick1) & 0xffffffu; // counter is 24-bit; correct for counter wrap-around.
You can also use a TCPWM module to generate periodic interrupts.
1 of 1 people found this helpful
When needing microseconds resolution I would suggest to set up a timer fed with 1MHz and a divisor of 1000. At interrupt increase a volatile uint64 countervalue. So at any time you can get a tick value with µs accuracy. Use CyEnterCriticalSection() when retrieving timer and counter parts.
Roger, thank you. That is what I was looking for, and is plenty lapse time measurement in code segments.
Bob, I think for a timing application you are right. I should have explained I need it just for development environment. I find having to add/remove a component is a hassle. I can hide debug code with comments or even defines if I wanted to enable/disable easily.
Thank you both.