1 /* 2 * Description: declaration for lowpower APIs 3 */ 4 #ifndef LWIP_HDR_LOWPOWER_H 5 #define LWIP_HDR_LOWPOWER_H 6 7 #include "lwip/opt.h" 8 #include "lwip/err.h" 9 #if !NO_SYS 10 #include "lwip/sys.h" 11 #endif 12 13 #if LWIP_LOWPOWER 14 15 #define LOWPOWER_TIMER_DEBUG 0 16 #define TIMEOUT_TICK 100 /* 100ms */ 17 #define TIMEOUT_CHECK 30 18 19 #if LOWPOWER_TIMER_DEBUG 20 #define TCP_FASTTMR_NAME ,"tcp_fasttmr" 21 #define TCP_SLOWTMR_NAME ,"tcp_slowtmr" 22 #define IP_REASSTRM_NAME ,"ip_reass_tmr" 23 #define ETHARPTMR_NAME ,"etharp_tmr" 24 #define DHCP_COARSETMR_NAME ,"dhcp_coarse_tmr" 25 #define DHCP_FINETMR_NAME ,"dhcp_fine_tmr" 26 #define AUTOIPTMR_NAME ,"autoip_tmr" 27 #define IGMPTMR_NAME ,"igmp_tmr" 28 #define DNSTMR_NAME ,"dns_tmr" 29 #define NAT64TMR_NAME ,"nat64_tmr" 30 #define ND6TMR_NAME ,"nd6_tmr" 31 #define IP6_TREASSTMR_NAME ,"ip6_reass_tmr" 32 #define MLD6TMR_NAME ,"mld6_tmr" 33 #define DHCP6TMR_NAME ,"dhcp6_tmr" 34 #define LOWPAN6TMR_NAME ,"lowpan6_tmr" 35 #else 36 #define TCP_FASTTMR_NAME 37 #define TCP_SLOWTMR_NAME 38 #define IP_REASSTRM_NAME 39 #define ETHARPTMR_NAME 40 #define DHCP_COARSETMR_NAME 41 #define DHCP_FINETMR_NAME 42 #define AUTOIPTMR_NAME 43 #define IGMPTMR_NAME 44 #define DNSTMR_NAME 45 #define NAT64TMR_NAME 46 #define ND6TMR_NAME 47 #define IP6_TREASSTMR_NAME 48 #define MLD6TMR_NAME 49 #define DHCP6TMR_NAME 50 #define LOWPAN6TMR_NAME 51 #endif 52 53 #define SET_TMR_TICK(tick, val) do { \ 54 if ((val) > 0) { \ 55 if ((tick) == 0) { \ 56 (tick) = (val); \ 57 } else { \ 58 (tick) = (tick) > (val) ? (val) : (tick); \ 59 } \ 60 } \ 61 } while (0) 62 63 typedef void (*lwip_timer_handler)(void); 64 typedef void (*sys_timeout_handler)(void *args); 65 66 /* get time count to trigger */ 67 typedef u32_t (*get_next_timeout)(void); 68 69 struct timer_handler { 70 u32_t interval; 71 lwip_timer_handler handler; 72 get_next_timeout next_tick; 73 #if LOWPOWER_TIMER_DEBUG 74 char *name; 75 #endif 76 }; 77 78 struct timer_entry { 79 u32_t clock_max; /* tmr interval */ 80 u32_t timeout; 81 sys_timeout_handler handler; 82 void *args; 83 get_next_timeout next_tick; 84 struct timer_entry *next; 85 #if LOWPOWER_TIMER_DEBUG 86 char *name; 87 #endif 88 u8_t enable; 89 }; 90 91 enum timer_state { 92 LOW_TMR_GETING_TICKS = 0, 93 LOW_TMR_TIMER_WAITING, 94 LOW_TMR_TIMER_HANDLING, 95 }; 96 97 struct timer_mng { 98 enum timer_state state; 99 u32_t waiting_time; 100 }; 101 102 enum lowpower_msg_type { 103 LOW_NON_BLOCK = 0, 104 LOW_BLOCK = 1, 105 LOW_FORCE_NON_BLOCK = 2, 106 }; 107 108 enum lowpower_mod { 109 LOW_TMR_LOWPOWER_MOD = 0, 110 LOW_TMR_NORMAL_MOD = 1, 111 }; 112 113 #define lowpower_sem_t sys_sem_t 114 #define LOWPOWER_SEM_WAIT(lock) sys_sem_wait(&(lock)) 115 #define LOWPOWER_SIGNAL(lock) sys_sem_signal(&(lock)) 116 #define LOWPOWER_SEM_NEW(lock, val) \ 117 do { \ 118 (val) = sys_sem_new(&(lock), 0); \ 119 } while (0) 120 #define LOWPOWER_SEM_FREE(lock) sys_sem_free(&(lock)) 121 122 /* all timer use the same timeout step */ 123 #define STEP_TIMEOUT_TO_TICK(step, type) (((step) * lwip_cyclic_timers[(type)].interval_ms) / TIMEOUT_TICK) 124 #define STEP_TICK_TO_TIMEOUT(tick, type) (((tick) * TIMEOUT_TICK) / lwip_cyclic_timers[(type)].interval_ms) 125 #define sys_timeout(msecs, handler, arg) (void)sys_timeout_ext(msecs, handler, arg) 126 127 #define LOW_TMR_DELAY 20 128 void sys_timeout_set_wake_time(u32_t val); 129 u32_t sys_timeout_get_wake_time(void); 130 131 void sys_untimeout(sys_timeout_handler handler, void *arg); 132 void sys_restart_timeouts(void); 133 void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg); 134 void sys_timeouts_init(void); 135 err_t sys_timeout_ext(u32_t msecs, sys_timeout_handler handler, void *arg); 136 u8_t sys_timeout_waiting_long(void); 137 138 void set_lowpower_mod(enum lowpower_mod sw); 139 enum lowpower_mod get_lowpowper_mod(void); 140 141 #endif /* LOWEPOWER */ 142 143 #endif /* LWIP_HDR_LOWPOWER_H */