OSAL_Clock.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. Filename: OSAL_Clock.h
  30. Revised:
  31. Revision:
  32. Description: OSAL Clock definition and manipulation functions.
  33. ******************************************************************************/
  34. #ifndef OSAL_CLOCK_H
  35. #define OSAL_CLOCK_H
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif
  40. /*********************************************************************
  41. * INCLUDES
  42. */
  43. /*********************************************************************
  44. * MACROS
  45. */
  46. #define IsLeapYear(yr) (!((yr) % 400) || (((yr) % 100) && !((yr) % 4)))
  47. /*********************************************************************
  48. * CONSTANTS
  49. */
  50. /*********************************************************************
  51. * TYPEDEFS
  52. */
  53. // number of seconds since 0 hrs, 0 minutes, 0 seconds, on the
  54. // 1st of January 2000 UTC
  55. typedef unsigned int UTCTime; // to confirm , int is 32bits long
  56. // To be used with
  57. typedef struct
  58. {
  59. uint8 seconds; // 0-59
  60. uint8 minutes; // 0-59
  61. uint8 hour; // 0-23
  62. uint8 day; // 0-30
  63. uint8 month; // 0-11
  64. uint16 year; // 2000+
  65. } UTCTimeStruct;
  66. /*********************************************************************
  67. * GLOBAL VARIABLES
  68. */
  69. /*********************************************************************
  70. * FUNCTIONS
  71. */
  72. /*
  73. * Updates the OSAL clock and Timers from the MAC 320us timer tick.
  74. */
  75. extern void osalTimeUpdate( void );
  76. /*
  77. * Set the new time. This will only set the seconds portion
  78. * of time and doesn't change the factional second counter.
  79. * newTime - number of seconds since 0 hrs, 0 minutes,
  80. * 0 seconds, on the 1st of January 2000 UTC
  81. */
  82. extern void osal_setClock( UTCTime newTime );
  83. /*
  84. * Gets the current time. This will only return the seconds
  85. * portion of time and doesn't include the factional second counter.
  86. * returns: number of seconds since 0 hrs, 0 minutes,
  87. * 0 seconds, on the 1st of January 2000 UTC
  88. */
  89. extern UTCTime osal_getClock( void );
  90. /*
  91. * Converts UTCTime to UTCTimeStruct
  92. *
  93. * secTime - number of seconds since 0 hrs, 0 minutes,
  94. * 0 seconds, on the 1st of January 2000 UTC
  95. * tm - pointer to breakdown struct
  96. */
  97. extern void osal_ConvertUTCTime( UTCTimeStruct *tm, UTCTime secTime );
  98. /*
  99. * Converts UTCTimeStruct to UTCTime (seconds since 00:00:00 01/01/2000)
  100. *
  101. * tm - pointer to UTC time struct
  102. */
  103. extern UTCTime osal_ConvertUTCSecs( UTCTimeStruct *tm );
  104. /*
  105. * Update/Adjust the osal clock and timers
  106. * Msec - elapsed time in milli seconds
  107. */
  108. extern void osalAdjustTimer( uint32 Msec );
  109. /*********************************************************************
  110. *********************************************************************/
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif /* OSAL_CLOCK_H */