zmatt icon

pru ecap timestamp generic.c

zmatt | PRO | 01/09/22 07:03:27 AM UTC (Edited) | 0 ⭐ | 312 👁️ | Never ⏰ | []
C |

680 B

|

None

|

0 👍

/

0 👎

// Initialization from python (using py-uio):
//    pruss.ecap.pwm.initialize( PERIOD )  where PERIOD (in PRU cycles) is max 2**32
 
struct Timestamp {
    uint32_t major;  // number of times the ecap counter has wrapped
    uint32_t minor;  // number of cycles since last time it wrapped
};
// note: total number of cycles (since ecap initialized) is  major * PERIOD + minor
 
// Get timestamp.
// Must be called at least once every PERIOD cycles to ensure correct timekeeping.
struct Timestamp timestamp()
{
    static struct Timestamp now = { 0, 0 };
    uint32_t minor = CT_ECAP.TSCTR;
    if( minor < now.minor )  // ecap counter has wrapped
        ++now.major;
    now.minor = minor;
    return now;
}

Comments