Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clock.c 576B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <LUFA/Common/Common.h>
  5. #include "clock.h"
  6. //Counted time
  7. volatile clock_time_t clock_datetime = 0;
  8. //Overflow interrupt
  9. ISR(TIMER1_COMPA_vect, ISR_BLOCK)
  10. {
  11. clock_datetime += 1;
  12. }
  13. //Initialise the clock
  14. void clock_init()
  15. {
  16. OCR1A = (((F_CPU / 1024) / 100) - 1);
  17. TCCR1B = ((1 << WGM12) | (1 << CS12) | (1 << CS10));
  18. TIMSK1 = (1 << OCIE1A);
  19. }
  20. //Return time
  21. clock_time_t clock_time()
  22. {
  23. clock_time_t time;
  24. GlobalInterruptDisable();
  25. time = clock_datetime;
  26. GlobalInterruptEnable();
  27. return time;
  28. }