srv_power_manager.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 2020 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _SRV_POWER_MANAGE_H_
  13. #define _SRV_POWER_MANAGE_H_
  14. #include "osi_compiler.h"
  15. OSI_EXTERN_C_BEGIN
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. /**
  19. * \brief function type for power on sequence
  20. */
  21. typedef void (*srvPmPonFunc_t)(void *arg);
  22. /**
  23. * \brief function type for event `SRVPM_EV_CHR_HOTPLUG`
  24. *
  25. * \param on charger plugin(true) or plugout(false)
  26. * \param ctx caller context
  27. */
  28. typedef void (*srvPmChargerNotfiy_t)(bool on, void *ctx);
  29. /**
  30. * \brief EVENTs defination
  31. */
  32. typedef enum
  33. {
  34. // use callback `srvPmChargerNotfiy_t`
  35. SRVPM_EV_CHR_HOTPLUG = 0,
  36. SRVPM_EV_COUNT,
  37. } srvPmEv_t;
  38. /**
  39. * \brief EVENTs notify token, create by `srvPmAddEvNotify` as an identifier
  40. */
  41. typedef struct srv_pm_ev_token srvPmEvToken_t;
  42. /**
  43. * \brief function type for event notify
  44. */
  45. typedef void (*srvPmEventNotify_t)(srvPmEv_t event, uint32_t name, void *ctx);
  46. /**
  47. * \brief initial power manager
  48. *
  49. * \param poweron_func poweron function, will be called when pm allow poweron
  50. * \param arg poweron function argument
  51. * \return
  52. * - true on success else false
  53. */
  54. bool srvPmInit(srvPmPonFunc_t poweron_func, void *arg);
  55. /**
  56. * \brief run power manager
  57. */
  58. void srvPmRun();
  59. /**
  60. * \brief add event notify function to monitor the `ev` trigger
  61. *
  62. * \param ev the event id
  63. * \param func the callback function, caller should set proper function type according
  64. * to `ev`. srvpm will do type conversion before calling the `func`
  65. * \param ctx caller context
  66. * \return
  67. * - NULL for fail
  68. * - the identifier for this notifier
  69. */
  70. srvPmEvToken_t *srvPmAddEvNotify(srvPmEv_t ev, void *func, void *ctx);
  71. /**
  72. * \brief remove a ev notifier
  73. *
  74. * \param token the identifier of the registered notifier
  75. */
  76. void srvPmRemoveEvNotify(srvPmEvToken_t *token);
  77. OSI_EXTERN_C_END
  78. #endif