Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

timer.c 770B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Time-Keeping helper
  3. */
  4. #include <avr/io.h>
  5. #include <avr/interrupt.h>
  6. #include "timer.h"
  7. volatile time_t systemTime = 0;
  8. void timerInit(void) {
  9. #ifdef DEBUG
  10. TCCR2A |= (1 << WGM21); // CTC Mode
  11. TCCR2B |= (1 << CS22); // Prescaler: 64
  12. OCR2A = 250; // Count to 250
  13. TIMSK2 |= (1 << OCIE2A); // Enable compare match interrupt
  14. #else
  15. // Using 8bit Timer1
  16. TCCR1 |= (1 << CTC1); // CTC Mode
  17. TCCR1 |= (1 << CS12) | (1 << CS11) | (1 << CS10); // Prescaler: 64
  18. OCR1A = 250; // Count to 250
  19. TIMSK |= (1 << OCIE1A); // Enable compare match interrupt
  20. #endif
  21. }
  22. #ifdef DEBUG
  23. ISR(TIMER2_COMPA_vect) {
  24. #else
  25. ISR(TIMER1_COMPA_vect) {
  26. #endif
  27. systemTime++; // one millisecond has passed
  28. }
  29. time_t timerGet(void) {
  30. return systemTime;
  31. }