time.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * time.h
  3. *
  4. * Created on: May 31, 2016
  5. * Author: liuhan
  6. */
  7. #ifndef TIME_H_
  8. #define TIME_H_
  9. #include "osapi.h"
  10. #include "os_type.h"
  11. #include "lwip/sntp.h"
  12. struct timeval {
  13. unsigned long tv_sec; /* seconds */
  14. unsigned long tv_usec; /* and microseconds */
  15. };
  16. /***************************RTC TIME OPTION***************************************/
  17. // daylight settings
  18. // Base calculated with value obtained from NTP server (64 bits)
  19. #define sntp_base (*((uint64_t*)RTC_STORE0))
  20. // Timer value when base was obtained
  21. #define TIM_REF_SET(value) WRITE_PERI_REG(RTC_STORE2, value)
  22. #define TIM_REF_GET() READ_PERI_REG(RTC_STORE2)
  23. // Setters and getters for CAL, TZ and DST.
  24. #define RTC_CAL_SET(val) do {uint32 value = READ_PERI_REG(RTC_STORE3);\
  25. value |= ((val) & 0x0000FFFF);\
  26. WRITE_PERI_REG(RTC_STORE3, value);\
  27. }while(0)
  28. #define RTC_DST_SET(val) do {uint32 value = READ_PERI_REG(RTC_STORE3);\
  29. value |= (((val)<<16) & 0x00010000);\
  30. WRITE_PERI_REG(RTC_STORE3, value);\
  31. }while(0)
  32. #define RTC_TZ_SET(val) do {uint32 value = READ_PERI_REG(RTC_STORE3);\
  33. value |= (((val)<<24) & 0xFF000000);\
  34. WRITE_PERI_REG(RTC_STORE3, value);\
  35. }while(0)
  36. #define RTC_CAL_GET() (READ_PERI_REG(RTC_STORE3) & 0x0000FFFF)
  37. #define RTC_DST_GET() ((READ_PERI_REG(RTC_STORE3) & 0x00010000)>>16)
  38. #define RTC_TZ_GET() ((((int)READ_PERI_REG(RTC_STORE3)) & ((int)0xFF000000))>>24)
  39. void system_update_rtc(time_t t, uint32_t us);
  40. time_t sntp_get_rtc_time(sint32_t *us);
  41. int gettimeofday(struct timeval* t, void* timezone);
  42. void updateTime(uint32 ms);
  43. bool configTime(int timezone, int daylightOffset, char *server1, char *server2, char *server3, bool enable);
  44. time_t time(time_t *t);
  45. unsigned long millis(void);
  46. unsigned long micros(void);
  47. #endif /* TIME_H_ */