app_datetime.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /**************************************************************
  29. *
  30. * Module Name: RTC module
  31. * File name: app_datetime.h
  32. * Brief description:
  33. * RCT function for nrf52 platform
  34. * Author: Eagle.Lao
  35. * Data: 2017-06-12
  36. * Revision:V0.01
  37. ****************************************************************/
  38. #ifndef APP_DATETIME_H
  39. #define APP_DATETIME_H
  40. #include "types.h"
  41. #define DATETIME_SYNC_INTERVAL 30*1*1000 //interval is 30s
  42. #define DTM2TM(tm, dtm) { (tm)->tm_mon = (dtm)->month-1;\
  43. (tm)->tm_year = (dtm)->year-1900;\
  44. (tm)->tm_mday = (dtm)->day;\
  45. (tm)->tm_hour = (dtm)->hour;\
  46. (tm)->tm_min = (dtm)->minutes;\
  47. (tm)->tm_sec = (dtm)->seconds;}
  48. #define TM2DTM(dtm, tm) { (dtm)->month = (tm)->tm_mon+1;\
  49. (dtm)->year = (tm)->tm_year+1900;\
  50. (dtm)->day = (tm)->tm_mday;\
  51. (dtm)->hour = (tm)->tm_hour;\
  52. (dtm)->minutes = (tm)->tm_min;\
  53. (dtm)->seconds = (tm)->tm_sec;}
  54. #define BCDTM2DTM(dtm, bcdtm) { (dtm)->year = bcdtm[0] + 2000;\
  55. (dtm)->month = bcdtm[1];\
  56. (dtm)->day = bcdtm[2];\
  57. (dtm)->hour = bcdtm[3];\
  58. (dtm)->minutes = bcdtm[4];\
  59. (dtm)->seconds = bcdtm[5];}
  60. #define DTM2BCDTM(bcdtm, dtm) { bcdtm[0] = (dtm)->year - 2000;\
  61. bcdtm[1] = (dtm)->month;\
  62. bcdtm[2] = (dtm)->day;\
  63. bcdtm[3] = (dtm)->hour;\
  64. bcdtm[4] = (dtm)->minutes;\
  65. bcdtm[5] = (dtm)->seconds;}
  66. #define DTM2U32(u32val, dtm) { uint32 tmp = (dtm)->year; u32val = (tmp << 16);\
  67. tmp = (dtm)->month; u32val |= (tmp << 8);\
  68. tmp = (dtm)->day; u32val |= tmp;}
  69. #define U322DTM(dtm,u32val) { (dtm)->year = (uint16)((u32val)>>16);\
  70. (dtm)->month = (uint8)(((u32val) >> 8) & 0xff);\
  71. (dtm)->day = (uint8)((u32val) &0xff);\
  72. (dtm)->hour = 0; (dtm)->minutes =0; (dtm)->seconds = 0;}
  73. typedef struct
  74. {
  75. uint64_t tm_base;
  76. uint32_t snapshot;
  77. uint32_t reserved; //reserved for 4 byte align
  78. } datetime_cfg_t;
  79. typedef struct
  80. {
  81. uint8_t seconds;
  82. uint8_t minutes;
  83. uint8_t hour;
  84. uint8_t day;
  85. uint8_t month;
  86. uint16_t year;
  87. } datetime_t;
  88. typedef enum{
  89. DTM_EV_ALRRM_0 = 1,
  90. DTM_EV_ALRRM_1,
  91. DTM_EV_ALRRM_2,
  92. DTM_EV_ALRRM_3,
  93. DTM_EV_ALRRM_4,
  94. }app_dtm_evt_t;
  95. //typedef void (*app_dtm_hdl_t)(app_dtm_evt_t ev);
  96. void app_datetime_sync_handler(void );
  97. int app_datetime_diff(const datetime_t* pdtm_base, const datetime_t* pdtm_cmp);
  98. int app_datetime_set(datetime_t dtm);
  99. int app_datetime(datetime_t* pdtm);
  100. void app_datetime_init(void);//app_dtm_hdl_t evt_hdl);
  101. #endif