Skip to content

Commit 0da81a8

Browse files
KKopyscinskiandrzej-kaczmarek
authored andcommitted
ll: Use macros to compare cputime
Time was compared with explicit logic operators and result was casted to int32_t each time. Now CPUTIME_* macros are used.
1 parent 58fa831 commit 0da81a8

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

nimble/controller/src/ble_ll_conn.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ ble_ll_conn_is_lru(struct ble_ll_conn_sm *s1, struct ble_ll_conn_sm *s2)
492492
int rc;
493493

494494
/* Set time that we last serviced the schedule */
495-
if ((int32_t)(s1->last_scheduled - s2->last_scheduled) < 0) {
495+
if (CPUTIME_LT(s1->last_scheduled, s2->last_scheduled)) {
496496
rc = 1;
497497
} else {
498498
rc = 0;
@@ -1157,10 +1157,10 @@ ble_ll_conn_tx_pdu(struct ble_ll_conn_sm *connsm)
11571157
}
11581158

11591159
ticks = os_cputime_usecs_to_ticks(ticks);
1160-
if ((int32_t)((os_cputime_get32() + ticks) - next_event_time) < 0) {
1160+
if (CPUTIME_LT(os_cputime_get32() + ticks, next_event_time)) {
11611161
md = 1;
11621162
}
1163-
}
1163+
}
11641164

11651165
/* If we send an empty PDU we need to initialize the header */
11661166
conn_tx_pdu:

nimble/controller/src/ble_ll_scan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ ble_ll_scan_refresh_nrpa(struct ble_ll_scan_sm *scansm)
305305
ble_npl_time_t now;
306306

307307
now = ble_npl_time_get();
308-
if ((ble_npl_stime_t)(now - scansm->scan_nrpa_timer) >= 0) {
308+
if (CPUTIME_GEQ(now, scansm->scan_nrpa_timer)) {
309309
/* Generate new NRPA */
310310
ble_ll_rand_data_get(scansm->scan_nrpa, BLE_DEV_ADDR_LEN);
311311
scansm->scan_nrpa[5] &= ~0xc0;

nimble/controller/src/ble_ll_sched.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ ble_ll_sched_is_overlap(struct ble_ll_sched_item *s1,
8383
int rc;
8484

8585
rc = 1;
86-
if ((int32_t)(s1->start_time - s2->start_time) < 0) {
86+
if (CPUTIME_LT(s1->start_time, s2->start_time)) {
8787
/* Make sure this event does not overlap current event */
88-
if ((int32_t)(s1->end_time - s2->start_time) <= 0) {
88+
if (CPUTIME_LEQ(s1->end_time, s2->start_time)) {
8989
rc = 0;
9090
}
9191
} else {
9292
/* Check for overlap */
93-
if ((int32_t)(s1->start_time - s2->end_time) >= 0) {
93+
if (CPUTIME_GEQ(s1->start_time, s2->end_time)) {
9494
rc = 0;
9595
}
9696
}
@@ -111,7 +111,7 @@ ble_ll_sched_overlaps_current(struct ble_ll_sched_item *sch)
111111
rc = 0;
112112
if (ble_ll_state_get() == BLE_LL_STATE_CONNECTION) {
113113
ce_end_time = ble_ll_conn_get_ce_end_time();
114-
if ((int32_t)(ce_end_time - sch->start_time) > 0) {
114+
if (CPUTIME_GT(ce_end_time, sch->start_time)) {
115115
rc = 1;
116116
}
117117
}
@@ -178,7 +178,7 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
178178
sch->end_time = connsm->ce_end_time;
179179

180180
/* Better be past current time or we just leave */
181-
if ((int32_t)(sch->start_time - os_cputime_get32()) < 0) {
181+
if (CPUTIME_LT(sch->start_time, os_cputime_get32())) {
182182
return -1;
183183
}
184184

@@ -216,7 +216,7 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
216216
end_overlap = entry;
217217
}
218218
} else {
219-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
219+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
220220
rc = 0;
221221
TAILQ_INSERT_BEFORE(entry, sch, link);
222222
break;
@@ -468,7 +468,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
468468
sch->end_time = earliest_end;
469469

470470
/* We can insert if before entry in list */
471-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
471+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
472472
if ((earliest_start - initial_start) <= itvl_t) {
473473
rc = 0;
474474
TAILQ_INSERT_BEFORE(entry, sch, link);
@@ -655,7 +655,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
655655
sch->end_time = earliest_end;
656656

657657
/* We can insert if before entry in list */
658-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
658+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
659659
if ((earliest_start - initial_start) <= itvl_t) {
660660
rc = 0;
661661
TAILQ_INSERT_BEFORE(entry, sch, link);
@@ -770,7 +770,7 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
770770
while (1) {
771771
next_sch = entry->link.tqe_next;
772772
/* Insert if event ends before next starts */
773-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
773+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
774774
rc = 0;
775775
TAILQ_INSERT_BEFORE(entry, sch, link);
776776
break;
@@ -1047,7 +1047,7 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch, ble_ll_sched_adv_new_cb cb,
10471047
os_cputime_timer_stop(&g_ble_ll_sched_timer);
10481048
TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) {
10491049
/* We can insert if before entry in list */
1050-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
1050+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
10511051
TAILQ_INSERT_BEFORE(entry, sch, link);
10521052
break;
10531053
}
@@ -1111,7 +1111,7 @@ ble_ll_sched_periodic_adv(struct ble_ll_sched_item *sch, uint32_t *start,
11111111
os_cputime_timer_stop(&g_ble_ll_sched_timer);
11121112
TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) {
11131113
/* We can insert if before entry in list */
1114-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
1114+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
11151115
TAILQ_INSERT_BEFORE(entry, sch, link);
11161116
break;
11171117
}
@@ -1200,7 +1200,7 @@ ble_ll_sched_adv_reschedule(struct ble_ll_sched_item *sch, uint32_t *start,
12001200
end_overlap = entry;
12011201
}
12021202
} else {
1203-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
1203+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
12041204
before = entry;
12051205
break;
12061206
}
@@ -1233,7 +1233,7 @@ ble_ll_sched_adv_reschedule(struct ble_ll_sched_item *sch, uint32_t *start,
12331233
sch->end_time = sch->start_time + duration;
12341234
while (1) {
12351235
next_sch = entry->link.tqe_next;
1236-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
1236+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
12371237
rand_ticks = entry->start_time - sch->end_time;
12381238
before = entry;
12391239
TAILQ_INSERT_BEFORE(before, sch, link);
@@ -1580,7 +1580,7 @@ ble_ll_sched_scan_req_over_aux_ptr(uint32_t chan, uint8_t phy_mode)
15801580
while (sch) {
15811581
/* Let's check if there is no scheduled item which want to start within
15821582
* given usecs.*/
1583-
if ((int32_t)(sch->start_time - now + os_cputime_usecs_to_ticks(usec_dur)) > 0) {
1583+
if (CPUTIME_GT(sch->start_time, now + os_cputime_usecs_to_ticks(usec_dur))) {
15841584
/* We are fine. Have time for scan req */
15851585
return 0;
15861586
}
@@ -1670,7 +1670,7 @@ ble_ll_sched_aux_scan(struct ble_mbuf_hdr *ble_hdr,
16701670
os_cputime_timer_stop(&g_ble_ll_sched_timer);
16711671
TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) {
16721672
/* We can insert if before entry in list */
1673-
if ((int32_t)(sch->end_time - entry->start_time) <= 0) {
1673+
if (CPUTIME_LEQ(sch->end_time, entry->start_time)) {
16741674
rc = 0;
16751675
TAILQ_INSERT_BEFORE(entry, sch, link);
16761676
sch->enqueued = 1;

0 commit comments

Comments
 (0)