system_timer.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //! @file
  2. #ifndef FIRMWARE_SYSTEM_TIMER_H_
  3. #define FIRMWARE_SYSTEM_TIMER_H_
  4. #include "Arduino.h"
  5. #include "macros.h"
  6. #define SYSTEM_TIMER_2
  7. #ifdef SYSTEM_TIMER_2
  8. #include "timer02.h"
  9. #include "tone04.h"
  10. #define _millis millis2
  11. #define _micros micros2
  12. #define _delay delay2
  13. #define _tone tone4
  14. #define _noTone noTone4
  15. #define timer02_set_pwm0(pwm0)
  16. #else //SYSTEM_TIMER_2
  17. #define _millis millis
  18. #define _micros micros
  19. #define _delay delay
  20. #define _tone tone
  21. #define _noTone noTone
  22. #define timer02_set_pwm0(pwm0)
  23. #endif //SYSTEM_TIMER_2
  24. // Timer counter, incremented by the 1ms Arduino timer.
  25. // The standard Arduino timer() function returns this value atomically
  26. // by disabling / enabling interrupts. This is costly, if the interrupts are known
  27. // to be disabled.
  28. #ifdef SYSTEM_TIMER_2
  29. extern volatile unsigned long timer2_millis;
  30. #else //SYSTEM_TIMER_2
  31. extern volatile unsigned long timer0_millis;
  32. #endif //SYSTEM_TIMER_2
  33. // An unsynchronized equivalent to a standard Arduino _millis() function.
  34. // To be used inside an interrupt routine.
  35. FORCE_INLINE unsigned long millis_nc() {
  36. #ifdef SYSTEM_TIMER_2
  37. return timer2_millis;
  38. #else //SYSTEM_TIMER_2
  39. return timer0_millis;
  40. #endif //SYSTEM_TIMER_2
  41. }
  42. #endif /* FIRMWARE_SYSTEM_TIMER_H_ */