ql_power.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /*================================================================
  2. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  3. Quectel Wireless Solutions Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. =================================================================*/
  12. #ifndef QL_POWER_H
  13. #define QL_POWER_H
  14. #include "ql_api_common.h"
  15. #include "ql_usb.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /*===========================================================================
  20. * Macro Definition
  21. ===========================================================================*/
  22. #define QL_POWER_ERRCODE_BASE (QL_COMPONENT_PM<<16)
  23. #define QL_QSCLKEX_NO_DATA_MIN 1 //unit: second
  24. #define QL_QSCLKEX_NO_DATA_DEFAULT 3
  25. #define QL_QSCLKEX_NO_DATA_MAX 50
  26. #define QL_QSCLKEX_PUNISH_TIME_MIN 1 //unit: minute
  27. #define QL_QSCLKEX_PUNISH_TIME_DEFAULT 30
  28. #define QL_QSCLKEX_PUNISH_TIME_MAX 600
  29. #define QL_PSM_ENTER_LIMIT_TIME_MINS 5 //mins
  30. #ifdef CONFIG_QUEC_PROJECT_FEATURE_PWK
  31. #define QL_PWRKEY_SHUTDOWN_TIME 2500 //unit: ms, default 2500ms
  32. #define QL_PWRKEY_LONGPRESS_TIME 5000 //unit: ms, default 5000ms
  33. /*===========================================================================
  34. * Typedef
  35. ===========================================================================*/
  36. typedef void (*ql_pwrkey_callback)(void);
  37. #ifdef CONFIG_QUEC_PROJECT_FEATURE_PSM
  38. typedef void (*ql_psm_enter_callback)(void *ctx);
  39. #endif
  40. /*===========================================================================
  41. * Extern
  42. ===========================================================================*/
  43. extern ql_pwrkey_callback ql_pwrkey_shutdown_cb;
  44. extern ql_pwrkey_callback ql_pwrkey_longpress_cb;
  45. extern ql_pwrkey_callback ql_pwrkey_press_cb;
  46. extern ql_pwrkey_callback ql_pwrkey_release_cb;
  47. extern uint8_t ql_pwrkey_status;
  48. extern uint32_t ql_shutdown_time;
  49. extern uint32_t ql_longpress_time;
  50. #endif
  51. /*===========================================================================
  52. * Enum
  53. ===========================================================================*/
  54. /**
  55. * POWER errcode
  56. */
  57. typedef enum
  58. {
  59. QL_POWER_POWD_SUCCESS = QL_SUCCESS,
  60. QL_POWER_RESET_SUCCESS = QL_POWER_POWD_SUCCESS,
  61. QL_POWER_CFW_CTRL_ERR = 1|QL_POWER_ERRCODE_BASE,
  62. QL_POWER_CFW_CTRL_RSP_ERR,
  63. QL_POWER_CFW_RESET_BUSY,
  64. QL_POWER_SEMAPHORE_CREATE_ERR = 5|QL_POWER_ERRCODE_BASE,
  65. QL_POWER_SEMAPHORE_TIMEOUT_ERR,
  66. QL_POWER_POWD_EXECUTE_ERR = 11|QL_POWER_ERRCODE_BASE,
  67. QL_POWER_POWD_INVALID_PARAM_ERR,
  68. QL_POWER_RESET_EXECUTE_ERR = 21|QL_POWER_ERRCODE_BASE,
  69. QL_POWER_RESET_INVALID_PARAM_ERR,
  70. QL_POWER_UP_REASON_GET_ERR = 31|QL_POWER_ERRCODE_BASE,
  71. QL_POWER_UP_REASON_MEM_NULL_ERR,
  72. QL_POWER_KEY_CB_NULL_ERR = 41|QL_POWER_ERRCODE_BASE,
  73. QL_POWER_KEY_STATUS_GET_ERR,
  74. QL_POWER_KEY_MEM_NULL_ERR,
  75. QL_POWER_KEY_SHUTDOWN_TIME_SET_ERR,
  76. QL_POWER_KEY_LONGPRESS_TIME_SET_ERR,
  77. QL_POWER_USB_DETECT_INVALID_PARAM = 51|QL_POWER_ERRCODE_BASE,
  78. QL_POWER_USB_DETECT_SAVE_NV_ERR,
  79. }ql_errcode_power;
  80. typedef enum
  81. {
  82. QL_SLEEP_SUCCESS = QL_SUCCESS,
  83. QL_SLEEP_INVALID_PARAM = (QL_COMPONENT_PM_SLEEP << 16) | 1000, /* invalid input param */
  84. QL_SLEEP_LOCK_CREATE_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1001, /* failed to create wake lock */
  85. QL_SLEEP_LOCK_DELETE_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1002, /* failed to delete wake lock */
  86. QL_SLEEP_LOCK_LOCK_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1003, /* failed to lock the wake lock */
  87. QL_SLEEP_LOCK_UNLOCK_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1004, /* failed to unlock the wake lock */
  88. QL_SLEEP_LOCK_AUTOSLEEP_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1005, /* failed to enter auto sleep */
  89. QL_SLEEP_PARAM_SAVE_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1006, /* failed to save sleep param */
  90. QL_SLEEP_EXECUTE_FAIL = (QL_COMPONENT_PM_SLEEP << 16) | 1007, /* failed to execute */
  91. }ql_errcode_sleep;
  92. #define QL_CHARGE_ERRCODE_BASE (QL_COMPONENT_BSP_CHARGE<<16)
  93. /**
  94. * usb charge errcode
  95. */
  96. typedef enum
  97. {
  98. QL_CHARGE_SUCCESS = QL_SUCCESS,
  99. QL_CHARGE_INVALID_PARAM_ERR = 1|QL_CHARGE_ERRCODE_BASE,
  100. QL_CHARGE_CHARGE_STATUS_ERROR,
  101. QL_CHARGE_BATTERY_DETECT_ERROR,
  102. QL_CHARGE_SAVE_NV_ERROR,
  103. QL_CHARGE_MEM_NULL_ERROR,
  104. }ql_errcode_charge;
  105. #ifdef CONFIG_QUEC_PROJECT_FEATURE_USB_CHARGE
  106. /**
  107. * usb charge status
  108. */
  109. typedef enum
  110. {
  111. //charge idle
  112. QL_CHG_IDLE = 0,
  113. //charging
  114. QL_CHG_CHARGING
  115. } ql_charge_status_e;
  116. typedef enum
  117. {
  118. QL_CHARGER_CURRENT_300MA = 300,
  119. QL_CHARGER_CURRENT_350MA = 350,
  120. QL_CHARGER_CURRENT_400MA = 400,
  121. QL_CHARGER_CURRENT_450MA = 450,
  122. QL_CHARGER_CURRENT_500MA = 500,
  123. QL_CHARGER_CURRENT_550MA = 550,
  124. QL_CHARGER_CURRENT_600MA = 600,
  125. QL_CHARGER_CURRENT_650MA = 650,
  126. QL_CHARGER_CURRENT_700MA = 700,
  127. QL_CHARGER_CURRENT_750MA = 750,
  128. QL_CHARGER_CURRENT_800MA = 800,
  129. QL_CHARGER_CURRENT_850MA = 850,
  130. QL_CHARGER_CURRENT_900MA = 900,
  131. QL_CHARGER_CURRENT_950MA = 950,
  132. QL_CHARGER_CURRENT_1000MA = 1000,
  133. QL_CHARGER_CURRENT_1050MA = 1050,
  134. QL_CHARGER_CURRENT_1100MA = 1100,
  135. QL_CHARGER_CURRENT_1200MA = 1200,
  136. QL_CHARGER_CURRENT_MAX = 1300,
  137. }ql_charge_current_e;
  138. typedef struct
  139. {
  140. uint16_t rechg_vol; //recharge vol,default:4150mV
  141. uint16_t chg_end_vol; //charge end vol,default:4210mV
  142. uint16_t standard_chg_current; //charging current,default:700mA
  143. uint16_t chg_timeout; //total charging time,default:18000s
  144. uint32_t chg_ontime_ms; //battery charging on time,unit: ms, range<1000,100000>,default:9000ms
  145. uint32_t chg_offtime_ms; //battery charging off time,unit: ms, range<1000,100000>,default:1000ms
  146. }ql_charge_config_t;
  147. #endif
  148. /**
  149. * Power down mode select
  150. */
  151. typedef enum
  152. {
  153. POWD_IMMDLY,
  154. POWD_NORMAL, //actually psm shutdown
  155. POWD_ORDINARY, //ordinary shutdown.Ps: when pwk pin pull down, mode will restart after shutdown
  156. }ql_PowdMode;
  157. /**
  158. * Reset mode select
  159. */
  160. typedef enum
  161. {
  162. RESET_QUICK,
  163. RESET_NORMAL
  164. }ql_ResetMode;
  165. /**
  166. * Enable auto sleep
  167. */
  168. typedef enum
  169. {
  170. QL_NOT_ALLOW_SLEEP = 0,
  171. QL_ALLOW_SLEEP,
  172. }QL_SLEEP_FLAG_E;
  173. /**
  174. * Power up reason
  175. */
  176. typedef enum
  177. {
  178. QL_PWRUP_UNKNOWN, // unknown reason
  179. QL_PWRUP_PWRKEY, // power up by power key
  180. QL_PWRUP_PIN_RESET, // power up by pin reset
  181. QL_PWRUP_ALARM, // power up by alarm
  182. QL_PWRUP_CHARGE, // power up by charge in
  183. QL_PWRUP_WDG, // power up by watchdog
  184. QL_PWRUP_PSM_WAKEUP, // power up from PSM wakeup
  185. QL_PWRUP_PANIC // power up by panic reset
  186. }ql_pwrup_reason;
  187. /**
  188. * Boot cause
  189. */
  190. typedef enum
  191. {
  192. QL_BOOTCAUSE_UNKNOWN = 0, // placeholder for unknown reason
  193. QL_BOOTCAUSE_PWRKEY = (1 << 0), // boot by power key
  194. QL_BOOTCAUSE_PIN_RESET = (1 << 1), // boot by pin reset
  195. QL_BOOTCAUSE_ALARM = (1 << 2), // boot by alarm
  196. QL_BOOTCAUSE_CHARGE = (1 << 3), // boot by charge in
  197. QL_BOOTCAUSE_WDG = (1 << 4), // boot by watchdog
  198. QL_BOOTCAUSE_PIN_WAKEUP = (1 << 5), // boot by gpio wakeup
  199. QL_BOOTCAUSE_SMPL_WAKEUP = (1 << 6), // boot from SMPL
  200. QL_BOOTCAUSE_GPT_WAKEUP = (1 << 7), // boot from GPT
  201. QL_BOOTCAUSE_WDG_IN_PSM = (1 << 8), // boot by watchdog rst
  202. QL_BOOTCAUSE_PANIC = (1 << 9), // boot by panic reset
  203. QL_BOOTCAUSE_PM2BOOT = (1 << 10), // boot from PM2 cold boot
  204. QL_BOOTCAUSE_SW_RST = (1 << 15), // boot by sw reset
  205. }ql_boot_cause;
  206. #ifdef CONFIG_QUEC_PROJECT_FEATURE_PWK
  207. /**
  208. * Pwrkey status
  209. */
  210. typedef enum
  211. {
  212. PWRKEY_RELEASE = 0,
  213. PWRKEY_PRESSED
  214. }QL_PWRKEY_STATUS_E;
  215. #endif
  216. /*===========================================================================
  217. * Struct
  218. ===========================================================================*/
  219. typedef struct
  220. {
  221. uint8_t enable;
  222. uint8_t no_data_time;
  223. uint16_t punish_time;
  224. uint16_t punish_remain_time;
  225. }qsclkex_cfg_s;
  226. /*===========================================================================
  227. * Functions declaration
  228. ===========================================================================*/
  229. /*****************************************************************
  230. * Function: ql_power_down
  231. *
  232. * Description: power off for shutdown
  233. *
  234. * Parameters:
  235. * powd_mode [in] IMMDLY/NORMAL/ORDINARY power off
  236. *
  237. * Return:
  238. * 0 success
  239. * other failed
  240. *
  241. *****************************************************************/
  242. ql_errcode_power ql_power_down(ql_PowdMode powd_mode);
  243. /*****************************************************************
  244. * Function: ql_power_reset
  245. *
  246. * Description: reset for shutdown
  247. *
  248. * Parameters:
  249. * powd_mode [in] QUICK/NORMAL reset
  250. *
  251. * Return:
  252. * 0 success
  253. * other failed
  254. *
  255. *****************************************************************/
  256. ql_errcode_power ql_power_reset(ql_ResetMode reset_mode);
  257. /*****************************************************************
  258. * Function: ql_get_powerup_reason
  259. *
  260. * Description: get power on reason
  261. *
  262. * Parameters:
  263. * pwrup_reason [out] getted power on reason
  264. *
  265. * Return:
  266. * 0 success
  267. * other failed
  268. *
  269. *****************************************************************/
  270. ql_errcode_power ql_get_powerup_reason(uint8_t *pwrup_reason);
  271. /*****************************************************************
  272. * Function: ql_get_boot_cause
  273. *
  274. * Description: get boot cause
  275. *
  276. * Parameters:
  277. * pwrup_reason [out] getted boot cause
  278. *
  279. * Return:
  280. * 0 success
  281. * other failed
  282. *
  283. *****************************************************************/
  284. ql_errcode_power ql_get_boot_cause(uint32_t *boot_cause);
  285. #ifdef CONFIG_QUEC_PROJECT_FEATURE_PWK
  286. /*****************************************************************
  287. * Function: ql_get_pwrkey_status
  288. *
  289. * Description: get powerkey's status
  290. *
  291. * Parameters:
  292. * pwrkey_status [out] getted powerkey's status
  293. *
  294. * Return:
  295. * 0 success
  296. * other failed
  297. *
  298. *****************************************************************/
  299. ql_errcode_power ql_get_pwrkey_status(uint8_t *pwrkey_status);
  300. /*****************************************************************
  301. * Function: ql_pwrkey_callback_register
  302. *
  303. * Description: register powerkey's shutdown callback(trigger after pwrkey released)
  304. *
  305. * Parameters:
  306. * pwrkey_cb [in] be registered callback
  307. *
  308. * Return:
  309. * 0 success
  310. * other failed
  311. *
  312. *****************************************************************/
  313. ql_errcode_power ql_pwrkey_callback_register(ql_pwrkey_callback pwrkey_cb);
  314. /*****************************************************************
  315. * Function: ql_pwrkey_longpress_cb_register
  316. *
  317. * Description: register powerkey's callback when long press(but not release trigger)
  318. *
  319. * Parameters:
  320. * pwrkey_cb [in] be registered callback
  321. * longpress_time [in] needed powerkey pressed time
  322. *
  323. * Return:
  324. * 0 success
  325. * other failed
  326. *
  327. *****************************************************************/
  328. ql_errcode_power ql_pwrkey_longpress_cb_register(ql_pwrkey_callback pwrkey_cb, uint32_t longpress_time);
  329. /*****************************************************************
  330. * Function: ql_pwrkey_press_cb_register
  331. *
  332. * Description: register powerkey's callback when press
  333. *
  334. * Parameters:
  335. * pwrkey_cb [in] be registered callback
  336. *
  337. * Return:
  338. * 0 success
  339. * other failed
  340. *
  341. *****************************************************************/
  342. ql_errcode_power ql_pwrkey_press_cb_register(ql_pwrkey_callback pwrkey_cb);
  343. /*****************************************************************
  344. * Function: ql_pwrkey_release_cb_register
  345. *
  346. * Description: register powerkey's callback when release from short press
  347. *
  348. * Parameters:
  349. * pwrkey_cb [in] be registered callback
  350. *
  351. * Return:
  352. * 0 success
  353. * other failed
  354. *
  355. *****************************************************************/
  356. ql_errcode_power ql_pwrkey_release_cb_register(ql_pwrkey_callback pwrkey_cb);
  357. /*****************************************************************
  358. * Function: ql_pwrkey_shutdown_time_set
  359. *
  360. * Description: set the time of shutdown by powerkey
  361. *
  362. * Parameters:
  363. * shutdown_time [in] needed powerkey pressed time
  364. *
  365. * Return:
  366. * 0 success
  367. * other failed
  368. *
  369. *****************************************************************/
  370. ql_errcode_power ql_pwrkey_shutdown_time_set(uint32_t shutdown_time);
  371. #endif
  372. /*****************************************************************
  373. * Function: ql_lpm_wakelock_create
  374. *
  375. * Description: 用于创建休眠锁
  376. *
  377. * Parameters:
  378. * lock_name [in] 休眠锁名字
  379. name_size [in] 休眠锁名字长度
  380. *
  381. * Return:
  382. * >0 休眠锁id
  383. * other 错误码。
  384. *
  385. *****************************************************************/
  386. int ql_lpm_wakelock_create(char *lock_name, int name_size);
  387. /*****************************************************************
  388. * Function: ql_autosleep_enable
  389. *
  390. * Description: 用于使能普通休眠
  391. *
  392. * Parameters:
  393. * sleep_flag [in] 休眠选择
  394. *
  395. * Return:
  396. * 0 成功
  397. * other 错误码。
  398. *
  399. *****************************************************************/
  400. ql_errcode_sleep ql_autosleep_enable(QL_SLEEP_FLAG_E sleep_flag);
  401. /*****************************************************************
  402. * Function: ql_autosleepex_enable
  403. *
  404. * Description: 用于使能增强型休眠
  405. *
  406. * Parameters:
  407. * sleep_flag [in] 休眠选择
  408. * no_data_time [in] 无数据交互后释放RRC时间
  409. * punish_time [in] 异常注网后不可使用增强休眠时间
  410. *
  411. * Return:
  412. * 0 成功
  413. * other 错误码。
  414. *
  415. *****************************************************************/
  416. ql_errcode_sleep ql_autosleepex_enable(QL_SLEEP_FLAG_E sleep_flag, uint8_t no_data_time, uint16_t punish_time);
  417. #ifdef CONFIG_QUEC_PROJECT_FEATURE_PSM
  418. /*****************************************************************
  419. * Function: ql_psm_sleep_enable
  420. *
  421. * Description: This api controls the setting of the UE's power saving mode (PSM) parameters.
  422. *
  423. * Parameters:
  424. * nSim [in] sim index,range: 0-1
  425. * psm_enable [in] Indication to disable or enable the use of PSM in the UE
  426. * periodic_TAU_time [in] string type; one byte in an 8 bit format. Requested extended periodic TAU value (T3412) to be allocated to the UE in E-UTRAN.
  427. * The requested extended periodic TAU value is coded as one byte (octet 3) of the GPRS Timer 3 information element coded as bit
  428. * format (e.g. "01000111" equals 70 hours). For the coding and the value range, see the GPRS Timer 3 IE in 3GPP TS 24.008 [8]
  429. * Table 10.5.163a/3GPP TS 24.008. See also 3GPP TS 23.682 [149] and 3GPP TS 23.401 [82]. The default value, if available, is manufacturer specific
  430. *
  431. * GPRS Timer 3 value
  432. * Bits 5 to 1 represent the binary coded timer value
  433. * Bits 6 to 8 defines the timer value uint for the GPRS timer as follows
  434. * Bits
  435. * 8 7 6
  436. * -----------------------------------------------------------
  437. * 0 0 0 value is incremented in multiples of 10 minutes
  438. * 0 0 1 value is incremented in multiples of 1 hour
  439. * 0 1 0 value is incremented in multiples of 10 hours
  440. * 0 1 1 value is incremented in multiples of 2 seconds
  441. * 1 0 0 value is incremented in multiples of 30 seconds
  442. * 1 0 1 value is incremented in multiples of 1 minute
  443. * 1 1 0 value is incremented in multiples of 320 hours
  444. * 1 1 1 value indicates that the timer is deactivated
  445. *
  446. *
  447. * active_time [in] string type; one byte in an 8 bit format. Requested Active Time value (T3324) to be allocated to the UE. The requested Active Time
  448. * value is coded as one byte (octet 3) of the GPRS Timer 2 information element coded as bit format (e.g. "00100100" equals 4 minutes).
  449. * For the coding and the value range, see the GPRS Timer 2 IE in 3GPP TS 24.008 [8] Table 10.5.163/3GPP TS 24.008. See also 3GPP TS 23.682 [149],
  450. * 3GPP TS 23.060 [47] and 3GPP TS 23.401 [82]. The default value, if available, is manufacturer specific.
  451. *
  452. * GPRS Timer 2 value
  453. * Bits 5 to 1 represent the binary coded timer value
  454. * Bits 6 to 8 defines the timer value uint for the GPRS timer as follows
  455. * Bits
  456. * 8 7 6
  457. * -----------------------------------------------------------
  458. * 0 0 0 value is incremented in multiples of 2 seconds
  459. * 0 0 1 value is incremented in multiples of 1 minute
  460. * 0 1 0 value is incremented in multiples of decihours
  461. * 1 1 1 value indicates that the timer is deactivated
  462. *
  463. * Return:
  464. * 0 success
  465. * other error code
  466. *
  467. *****************************************************************/
  468. ql_errcode_sleep ql_psm_sleep_enable(uint8_t nSim, bool psm_enable, const char *periodic_TAU_time, const char *active_time);
  469. /*****************************************************************
  470. * Function: ql_psm_register_enter_cb
  471. *
  472. * Description: Used to register the callback function before entering the PSM.
  473. * 用于注册进入PSM模式前的回调函数。
  474. *
  475. * Parameters:
  476. * ql_psm_enter_callback [in] callback function
  477. * 回调函数
  478. *
  479. * ctx [in] parameter of the callback function
  480. * 回调函数的传入参数
  481. * Return:
  482. * 0 success
  483. * 注册状态成功。
  484. * other error code
  485. * 错误码。
  486. *
  487. *****************************************************************/
  488. ql_errcode_sleep ql_psm_register_enter_cb(ql_psm_enter_callback cb, void *ctx);
  489. #endif
  490. /*****************************************************************
  491. * Function: ql_lpm_wakelock_delete
  492. *
  493. * Description: 用于删除休眠锁
  494. *
  495. * Parameters:
  496. * wakelock_fd [in] 休眠锁id
  497. *
  498. * Return:
  499. * 0 成功
  500. * other 错误码。
  501. *
  502. *****************************************************************/
  503. ql_errcode_sleep ql_lpm_wakelock_delete(int wakelock_fd);
  504. /*****************************************************************
  505. * Function: ql_lpm_wakelock_lock
  506. *
  507. * Description: 锁定休眠锁,不允许系统进入休眠
  508. *
  509. * Parameters:
  510. * wakelock_fd [in] 休眠锁id
  511. *
  512. * Return:
  513. * 0 成功
  514. * other 错误码。
  515. *
  516. *****************************************************************/
  517. ql_errcode_sleep ql_lpm_wakelock_lock(int wakelock_fd);
  518. /*****************************************************************
  519. * Function: ql_lpm_wakelock_unlock
  520. *
  521. * Description: 释放休眠锁,所有休眠锁均释放后,系统可进入休眠
  522. *
  523. * Parameters:
  524. * wakelock_fd [in] 休眠锁id
  525. *
  526. * Return:
  527. * 0 成功
  528. * other 错误码。
  529. *
  530. *****************************************************************/
  531. ql_errcode_sleep ql_lpm_wakelock_unlock(int wakelock_fd);
  532. #ifdef CONFIG_QL_OPEN_EXPORT_PKG
  533. /*****************************************************************
  534. * Function: ql_enter_sleep_callback
  535. *
  536. * Description: callback function before enter sleep
  537. *
  538. * Parameters:
  539. * ctx [out] reserved parameters
  540. *
  541. * Return:
  542. * 0 success。
  543. * other error code。
  544. *
  545. *****************************************************************/
  546. typedef void (*ql_enter_sleep_callback)(void *ctx);
  547. /*****************************************************************
  548. * Function: ql_exit_sleep_callback
  549. *
  550. * Description: callback function after exit sleep
  551. *
  552. * Parameters:
  553. * ctx [out] reserved parameters
  554. *
  555. * Return:
  556. * 0 success。
  557. * other error code。
  558. *
  559. *****************************************************************/
  560. typedef void (*ql_exit_sleep_callback)(void *ctx);
  561. /*****************************************************************
  562. * Function: ql_sleep_register_cb
  563. *
  564. * Description: registering sleep callback function
  565. *
  566. * Parameters:
  567. * cb [in] sleep callback function
  568. *
  569. * Return:
  570. * 0 success。
  571. * other error code。
  572. *
  573. *****************************************************************/
  574. ql_errcode_sleep ql_sleep_register_cb(ql_enter_sleep_callback cb);
  575. /*****************************************************************
  576. * Function: ql_wakeup_register_cb
  577. *
  578. * Description: registering wakeup callback function
  579. *
  580. * Parameters:
  581. * cb [in] wakeup callback function
  582. *
  583. * Return:
  584. * 0 success。
  585. * other error code。
  586. *
  587. *****************************************************************/
  588. ql_errcode_sleep ql_wakeup_register_cb(ql_exit_sleep_callback cb);
  589. /*****************************************************************
  590. * Function: ql_get_wakeup_source
  591. *
  592. * Description: get the wakeup source function
  593. *
  594. * Return:
  595. * 0 do not enter sleep
  596. * other
  597. * Wakeup source corresponding to each bit
  598. * QUEC_RESUME_SRC_PMIC (1 << 0)
  599. * QUEC_RESUME_SRC_VAD (1 << 1)
  600. * QUEC_RESUME_SRC_KEY (1 << 2)
  601. * QUEC_RESUME_SRC_GPIO1 (1 << 3)
  602. * QUEC_RESUME_SRC_UART1 (1 << 4 | 1<<5) //UART1 and UART1_RXD
  603. * QUEC_RESUME_SRC_WCN2SYS (1 << 6)
  604. * QUEC_RESUME_SRC_WCN_OSC (1 << 7)
  605. * QUEC_RESUME_SRC_IDLE_TIMER1 (1 << 8)
  606. * QUEC_RESUME_SRC_IDLE_TIMER2 (1 << 9)
  607. * QUEC_RESUME_SRC_SELF (1 << 10)
  608. * QUEC_RESUME_SRC_USB_MON (1 << 11)
  609. *
  610. *****************************************************************/
  611. uint ql_get_wakeup_source();
  612. #endif
  613. #ifdef CONFIG_QUEC_PROJECT_FEATURE_USB_CHARGE
  614. /*****************************************************************
  615. * Function: ql_get_vchg_vol
  616. *
  617. * Description: 用于获取USB端电压
  618. *
  619. * Parameters:
  620. * vol [out] USB端电压
  621. *
  622. * Return:
  623. * 0 获取电压成功。
  624. * other 错误码。
  625. *
  626. *****************************************************************/
  627. ql_errcode_charge ql_get_vchg_vol(uint32_t* vol);
  628. /*****************************************************************
  629. * Function: ql_get_vbus_state
  630. *
  631. * Description: 用于获取USB在位状态
  632. *
  633. * Parameters:
  634. * state [out] USB在位状态,0表示未连接USB,1表示已连接USB
  635. *
  636. * Return:
  637. * 0 获取状态成功。
  638. * other 错误码。
  639. *
  640. *****************************************************************/
  641. ql_errcode_charge ql_get_vbus_state(uint32_t* state);
  642. /*****************************************************************
  643. * Function: ql_get_battery_vol
  644. *
  645. * Description: 用于获取电池端电压
  646. *
  647. * Parameters:
  648. * vol [out] 电池端电压
  649. *
  650. * Return:
  651. * 0 获取电压成功。
  652. * other 错误码。
  653. *
  654. *****************************************************************/
  655. ql_errcode_charge ql_get_battery_vol(uint32_t* vol);
  656. /*****************************************************************
  657. * Function: ql_get_battery_level
  658. *
  659. * Description: 用于获取电池电量百分比
  660. *
  661. * Parameters:
  662. * level [out] 电池电量百分比
  663. *
  664. * Return:
  665. * 0 获取电量成功。
  666. * other 错误码。
  667. *
  668. *****************************************************************/
  669. ql_errcode_charge ql_get_battery_level(uint32_t* level);
  670. /*****************************************************************
  671. * Function: ql_get_charge_cur
  672. *
  673. * Description: 用于获取充电电流
  674. *
  675. * Parameters:
  676. * cur [out] 充电电流
  677. *
  678. * Return:
  679. * 0 获取电流成功。
  680. * other 错误码。
  681. *
  682. *****************************************************************/
  683. ql_errcode_charge ql_get_charge_cur(uint32_t* cur);
  684. /*****************************************************************
  685. * Function: ql_get_charge_status
  686. *
  687. * Description: 用于获取当前充电状态
  688. *
  689. * Parameters:
  690. * status [out] 充电状态,参考ql_charge_status_e枚举
  691. *
  692. * Return:
  693. * 0 获取状态成功。
  694. * other 错误码。
  695. *
  696. *****************************************************************/
  697. ql_errcode_charge ql_get_charge_status(ql_charge_status_e* status);
  698. /*****************************************************************
  699. * Function: ql_charge_set_config
  700. *
  701. * Description: 用于设置充电参数
  702. *
  703. * Parameters:
  704. * charge_config [in] 充电参数,参考ql_charge_config_t结构体
  705. *
  706. * Return:
  707. * 0 设置成功。
  708. * other 错误码。
  709. *
  710. *****************************************************************/
  711. ql_errcode_charge ql_charge_set_config(ql_charge_config_t *charge_config);
  712. /*****************************************************************
  713. * Function: ql_charge_get_config
  714. *
  715. * Description: 用于获取充电参数
  716. *
  717. * Parameters:
  718. * charge_config [out] 充电参数,参考ql_charge_config_t结构体
  719. *
  720. * Return:
  721. * 0 设置成功。
  722. * other 错误码。
  723. *
  724. *****************************************************************/
  725. ql_errcode_charge ql_charge_get_config(ql_charge_config_t *charge_config);
  726. /*****************************************************************
  727. * Function: ql_charge_set_over_temp
  728. *
  729. * Description: 用于温度过高/低时设置保护
  730. *
  731. * Parameters:
  732. * over_temp [in] true-温度过高,停止充电, false-温度正常,恢复充电
  733. *
  734. * Return:
  735. * 0 设置成功。
  736. * other 错误码。
  737. *
  738. *****************************************************************/
  739. ql_errcode_charge ql_charge_set_over_temp(bool over_temp);
  740. #endif
  741. #ifdef __cplusplus
  742. } /*"C" */
  743. #endif
  744. #endif /* QL_POWER_H */