systime.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Get time according to system (RTC or whatever we have...)
  3. * This is similar to localtime() in the standard C library, except
  4. * only the current time is supported and some of the derived fields
  5. * are not produced.
  6. */
  7. #ifndef SYSTIME_H
  8. #define SYSTIME_H
  9. #include <stdint.h>
  10. struct tms_tick_reg {
  11. union {
  12. uint16_t ticks;
  13. struct {
  14. unsigned int tm_1sec : 1;
  15. unsigned int tm_tick : 15;
  16. };
  17. };
  18. } __attribute__((aligned(2)));
  19. struct tms {
  20. union {
  21. uint32_t words[2];
  22. struct {
  23. unsigned int tm_2sec : 5;
  24. unsigned int tm_min : 6;
  25. unsigned int tm_hour : 5;
  26. unsigned int tm_mday : 5;
  27. unsigned int tm_mon : 4;
  28. unsigned int tm_year : 7;
  29. struct tms_tick_reg hold;
  30. struct tms_tick_reg now;
  31. };
  32. };
  33. } __attribute__((aligned(4)));
  34. static inline struct tms get_systime(void)
  35. {
  36. struct tms tms;
  37. tms.words[0] = SYSCLOCK_DATETIME;
  38. tms.words[1] = SYSCLOCK_TICK;
  39. return tms;
  40. }
  41. static inline void set_systime(struct tms tms)
  42. {
  43. SYSCLOCK_TICK_HOLD = tms.hold.ticks;
  44. SYSCLOCK_DATETIME = tms.words[0];
  45. }
  46. #endif /* SYSTIME_H */