fork download
  1. uint32_t result;
  2.  
  3. cli();
  4. uint16_t my_tcnt = TCNT1;
  5. __sync_synchronize(); // memory barrier
  6. if ((TIFR1 & (1 << TOV1))) {
  7. // Timer overflowed but interrupt hasn't run yet,
  8. // and it won't here because we cli.
  9. // Re-capture TCNT1 to make sure we get a post-overflow sample,
  10. // and use ovfs+1 for the result.
  11. result = (((TimeType)(ovfs + 1) << 16) + TCNT1);
  12. } else {
  13. // Timer hasn't yet overflowed when we captured TCNT,
  14. // and cli makes sure ovfs is consistent with my_tcnt.
  15. result = (((TimeType)ovfs << 16) + my_tcnt);
  16. }
  17. sei();
  18.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty