@@ -31,7 +31,9 @@ static void
3131ble_npl_callout_timer_cb (union sigval sv )
3232{
3333 struct ble_npl_callout * c = (struct ble_npl_callout * )sv .sival_ptr ;
34+
3435 assert (c );
36+
3537 c -> c_active = false;
3638 if (c -> c_evq ) {
3739 ble_npl_eventq_put (c -> c_evq , & c -> c_ev );
@@ -40,12 +42,11 @@ ble_npl_callout_timer_cb(union sigval sv)
4042 }
4143}
4244
43- void ble_npl_callout_init (struct ble_npl_callout * c ,
44- struct ble_npl_eventq * evq ,
45- ble_npl_event_fn * ev_cb ,
46- void * ev_arg )
45+ void
46+ ble_npl_callout_init (struct ble_npl_callout * c , struct ble_npl_eventq * evq ,
47+ ble_npl_event_fn * ev_cb , void * ev_arg )
4748{
48- struct sigevent event ;
49+ struct sigevent event ;
4950
5051 /* Initialize the callout. */
5152 memset (c , 0 , sizeof (* c ));
@@ -55,29 +56,32 @@ void ble_npl_callout_init(struct ble_npl_callout *c,
5556 c -> c_active = false;
5657
5758 event .sigev_notify = SIGEV_THREAD ;
58- event .sigev_value .sival_ptr = c ; // put callout obj in signal args
59+ event .sigev_value .sival_ptr = c ; // put callout obj in signal args
5960 event .sigev_notify_function = ble_npl_callout_timer_cb ;
6061 event .sigev_notify_attributes = NULL ;
6162
6263 timer_create (CLOCK_REALTIME , & event , & c -> c_timer );
6364}
6465
65- bool ble_npl_callout_is_active (struct ble_npl_callout * c )
66+ bool
67+ ble_npl_callout_is_active (struct ble_npl_callout * c )
6668{
67- // TODO: seek native posix method to determine whether timer_t is active.
68- // TODO: fix bug where one-shot timer is still active after fired.
69+ /* TODO: seek native posix method to determine whether timer_t is active.
70+ * TODO: fix bug where one-shot timer is still active after fired.
71+ */
6972 return c -> c_active ;
7073}
7174
72- int ble_npl_callout_inited (struct ble_npl_callout * c )
75+ int
76+ ble_npl_callout_inited (struct ble_npl_callout * c )
7377{
7478 return (c -> c_timer != NULL );
7579}
7680
77- ble_npl_error_t ble_npl_callout_reset ( struct ble_npl_callout * c ,
78- ble_npl_time_t ticks )
81+ ble_npl_error_t
82+ ble_npl_callout_reset ( struct ble_npl_callout * c , ble_npl_time_t ticks )
7983{
80- struct itimerspec its ;
84+ struct itimerspec its ;
8185
8286 if (ticks < 0 ) {
8387 return BLE_NPL_EINVAL ;
@@ -90,7 +94,7 @@ ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
9094 c -> c_ticks = ble_npl_time_get () + ticks ;
9195
9296 its .it_interval .tv_sec = 0 ;
93- its .it_interval .tv_nsec = 0 ; // one shot
97+ its .it_interval .tv_nsec = 0 ; // one shot
9498 its .it_value .tv_sec = (ticks / 1000 );
9599 its .it_value .tv_nsec = (ticks % 1000 ) * 1000000 ; // expiration
96100 its .it_value .tv_nsec %= 1000000000 ;
@@ -100,16 +104,17 @@ ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
100104 return BLE_NPL_OK ;
101105}
102106
103- int ble_npl_callout_queued (struct ble_npl_callout * c )
107+ int
108+ ble_npl_callout_queued (struct ble_npl_callout * c )
104109{
105110 struct itimerspec its ;
106111 timer_gettime (c -> c_timer , & its );
107112
108- return ((its .it_value .tv_sec > 0 ) ||
109- (its .it_value .tv_nsec > 0 ));
113+ return ((its .it_value .tv_sec > 0 ) || (its .it_value .tv_nsec > 0 ));
110114}
111115
112- void ble_npl_callout_stop (struct ble_npl_callout * c )
116+ void
117+ ble_npl_callout_stop (struct ble_npl_callout * c )
113118{
114119 if (!ble_npl_callout_inited (c )) {
115120 return ;
@@ -137,13 +142,12 @@ ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
137142}
138143
139144uint32_t
140- ble_npl_callout_remaining_ticks (struct ble_npl_callout * co ,
141- ble_npl_time_t now )
145+ ble_npl_callout_remaining_ticks (struct ble_npl_callout * co , ble_npl_time_t now )
142146{
143147 ble_npl_time_t rt ;
144148 uint32_t exp ;
145-
146149 struct itimerspec its ;
150+
147151 timer_gettime (co -> c_timer , & its );
148152
149153 exp = its .it_value .tv_sec * 1000 ;
0 commit comments