zmatt

pru ecap timestamp generic.c

Oct 7th, 2020 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. // Initialization from python (using py-uio):
  2. //    pruss.ecap.pwm.initialize( PERIOD )  where PERIOD (in PRU cycles) is max 2**32
  3.  
  4. struct Timestamp {
  5.     uint32_t major;  // number of times the ecap counter has wrapped
  6.     uint32_t minor;  // number of cycles since last time it wrapped
  7. };
  8. // note: total number of cycles (since ecap initialized) is  major * PERIOD + minor
  9.  
  10. // Get timestamp.
  11. // Must be called at least once every PERIOD cycles to ensure correct timekeeping.
  12. struct Timestamp timestamp()
  13. {
  14.     static struct Timestamp now = { 0, 0 };
  15.     uint32_t minor = CT_ECAP.TSCTR;
  16.     if( minor < now.minor )  // ecap counter has wrapped
  17.         ++now.major;
  18.     now.minor = minor;
  19.     return now;
  20. }
Add Comment
Please, Sign In to add comment