embkernel
 All Classes Functions Variables Typedefs Groups Pages
LibRtc.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef LIB_RTC_HPP_
7 #define LIB_RTC_HPP_
8 
9 #include <stdint.h>
10 
11 class LibRtc {
12 public:
13 
14  typedef enum {
15  SUNDAY,
16  MONDAY,
17  TUESDAY,
18  WEDNESDAY,
19  THURSDAY,
20  FRIDAY,
21  SATURDAY,
22  } DAY_OF_WEEK;
23 
24  typedef enum {
25  MONTH_INVALID = 0,
26  JANUARY,
27  FEBRUARY,
28  MARCH,
29  APRIL,
30  MAY,
31  JUNE,
32  JULY,
33  AUGUST,
34  SEPTEMBER,
35  OCTOBER,
36  NOVEMBER,
37  DECEMBER
38  } MONTH;
39 
40  typedef struct {
41  uint32_t dayOfMonth :5;
42  DAY_OF_WEEK dayOfWeek :3;
43  uint32_t dayOfYear :9;
44  MONTH month :4;
45  uint32_t year :11;
46  } DATE;
47 
48  typedef struct {
49  uint32_t ms :10;
50  uint32_t sec :6;
51  uint32_t min :6;
52  uint32_t hour :5;
53  uint32_t spare :5;
54  } TIME;
55 
56  typedef struct {
57  DATE date;
58  TIME time;
59  } DATE_AND_TIME;
60 
61  static bool isLeapYear(int year);
62  static void updateDayOfWeek(DATE* date);
63  static void updateDayOfYear(DATE* date);
64  static void getCurrentDateAndTime(DATE_AND_TIME* dateAndTime);
65  static void setCurrentDateAndTime(DATE_AND_TIME* dateAndTime);
66  static uint32_t getGmtUnixTime();
67 
68 private:
69  const static uint8_t DAYS_IN_MONTH[];
70 
71 };
72 
73 #endif /* LIB_RTC_HPP_ */