pmSleep.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef __FPM_SLEEP_H__
  2. #define __FPM_SLEEP_H__
  3. #include "user_interface.h"
  4. #include "c_types.h"
  5. #include "lauxlib.h"
  6. #include "gpio.h"
  7. #include "platform.h"
  8. #include "task/task.h"
  9. #include <string.h>
  10. #if defined(DEVELOP_VERSION)
  11. #define PMSLEEP_DEBUG
  12. #endif
  13. #if defined(PMSLEEP_DEBUG)
  14. #define PMSLEEP_DBG(fmt, ...) dbg_printf("\tPMSLEEP(%s):"fmt"\n", __FUNCTION__, ##__VA_ARGS__)
  15. #else
  16. #define PMSLEEP_DBG(...) //c_printf(__VA_ARGS__)
  17. #endif
  18. #if defined(NODE_ERROR)
  19. #define PMSLEEP_ERR(fmt, ...) NODE_ERR("%s"fmt"\n", "PMSLEEP:", ##__VA_ARGS__)
  20. #else
  21. #define PMSLEEP_ERR(...)
  22. #endif
  23. #define PMSLEEP_SLEEP_MIN_TIME 50000
  24. #define PMSLEEP_SLEEP_MAX_TIME 268435454 //FPM_MAX_SLEEP_TIME-1
  25. #define pmSleep_INIT_CFG(X) pmSleep_param_t X = {.sleep_duration=0, .wake_pin=255, \
  26. .preserve_opmode=TRUE, .suspend_cb_ptr=NULL, .resume_cb_ptr=NULL}
  27. #define PMSLEEP_INT_MAP \
  28. LROT_NUMENTRY( INT_BOTH, GPIO_PIN_INTR_ANYEDGE ) \
  29. LROT_NUMENTRY( INT_UP, GPIO_PIN_INTR_POSEDGE ) \
  30. LROT_NUMENTRY( INT_DOWN, GPIO_PIN_INTR_NEGEDGE ) \
  31. LROT_NUMENTRY( INT_HIGH, GPIO_PIN_INTR_HILEVEL ) \
  32. LROT_NUMENTRY( INT_LOW, GPIO_PIN_INTR_LOLEVEL )
  33. typedef struct pmSleep_param{
  34. uint32 sleep_duration;
  35. uint8 sleep_mode;
  36. uint8 wake_pin;
  37. uint8 int_type;
  38. bool preserve_opmode;
  39. void (*suspend_cb_ptr)(void);
  40. void (*resume_cb_ptr)(void);
  41. }pmSleep_param_t; //structure to hold pmSleep configuration
  42. enum PMSLEEP_STATE{
  43. PMSLEEP_AWAKE = 0,
  44. PMSLEEP_SUSPENSION_PENDING = 1,
  45. PMSLEEP_SUSPENDED = 2
  46. };
  47. uint8 pmSleep_get_state(void);
  48. void pmSleep_resume(void (*resume_cb_ptr)(void));
  49. void pmSleep_suspend(pmSleep_param_t *param);
  50. void pmSleep_execute_lua_cb(int* cb_ref);
  51. int pmSleep_parse_table_lua( lua_State* L, int table_idx, pmSleep_param_t *cfg, int *suspend_lua_cb_ref, int *resume_lua_cb_ref);
  52. #endif // __FPM_SLEEP_H__