// This assumes PRUSS is clocked at 200 MHz, which is its typical clock frequency.
//
// A more generic version of this code for any frequency and period: https://pastebin.com/rBR4v35a
// Initialization from python (using py-uio):
// pruss.ecap.pwm.initialize( 200000000 ) # 1 second period
struct Timestamp {
uint32_t s;
uint32_t ns;
};
// Returns timestamp in seconds and nanoseconds (with 5ns precision).
// Must be called at least once every second to ensure correct timekeeping.
struct Timestamp timestamp()
{
static struct Timestamp now = { 0, 0 };
uint32_t ns = CT_ECAP.TSCTR * 5;
if( ns < now.ns ) // ecap counter has wrapped
++now.s;
now.ns = ns;
return now;
}
Comments