ll_sleep.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifndef LL_SLEEP__H_
  29. #define LL_SLEEP__H_
  30. #include "OSAL_PwrMgr.h"
  31. #include "ll_def.h"
  32. #include "timer.h"
  33. #include "ll_common.h"
  34. /*******************************************************************************
  35. * MACROS
  36. */
  37. // convert 625us units to 32kHz units without round: the ratio of 32 kHz ticks
  38. // to 625 usec ticks is 32768/1600 = 20.48 or 512/25
  39. #define LL_SLEEP_625US_TO_32KHZ( us ) ((((uint32) (us)) * 512) / 25)
  40. // convert 31.25ns units to 32kHz units without round: the ratio of 31.25ns usec
  41. // ticks to 32 kHz ticks is 32M/32768 = 976.5625 or 15625/16, but using 976 is
  42. // close enough given the accuracy
  43. #define LL_SLEEP_31_25NS_TO_32KHZ( ns ) (((uint32) (ns)) / 976)
  44. // 32KHz timer:
  45. // crystal: 32768Hz
  46. // RC : 32768Hz Should be same as Xtal
  47. // timer1 - 4 : 4MHz
  48. #define TIMER_TO_32K_CRYSTAL 122 // 122.0703
  49. #define TIMER_TO_32K_RC 122 // 125
  50. #define STD_RC32_8_CYCLE_16MHZ_CYCLE 3906 // standard 16Mhz cycles for 8 RC32KHz tick
  51. #define STD_CRY32_8_CYCLE_16MHZ_CYCLE 3906 // standard 16Mhz cycles for 8 crystal 32KHz tick
  52. #define ERR_THD_RC32_CYCLE 200 // error threshold for N+x rcosc tracking cycle
  53. #define CRY32_8_CYCLE_16MHZ_CYCLE_MAX (3906 + 196) // tracking value range std +/- 5%
  54. #define CRY32_8_CYCLE_16MHZ_CYCLE_MIN (3906 - 196)
  55. #define SLEEP_MAGIC 0x032141B6
  56. /*******************************************************************************
  57. * TYPEDEFS
  58. */
  59. typedef enum
  60. {
  61. MCU_SLEEP_MODE,
  62. SYSTEM_SLEEP_MODE,
  63. SYSTEM_OFF_MODE
  64. } Sleep_Mode;
  65. /*******************************************************************************
  66. * Functions
  67. */
  68. // is sleep allow
  69. uint8 isSleepAllow(void);
  70. void enableSleep(void);
  71. void disableSleep(void);
  72. void setSleepMode(Sleep_Mode mode);
  73. Sleep_Mode getSleepMode(void);
  74. void enterSleepProcess(uint32 time);
  75. void wakeupProcess(void);
  76. void set_sleep_flag(int flag);
  77. unsigned int get_sleep_flag(void);
  78. void config_RTC(uint32 time);
  79. void enter_sleep_off_mode(Sleep_Mode mode);
  80. #endif // LL_SLEEP__H_