Skip to content

Commit 23ca74b

Browse files
JordanYateshenrikbrixandersen
authored andcommitted
convert: use k_uptime_seconds
Replace usage of `k_uptime_get() / MSEC_PER_SEC` and `k_uptime_get() / 1000` with dedicated function. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 98deebd commit 23ca74b

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

samples/basic/hash_map/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(void)
4747

4848
LOG_DBG("Inserted %zu", i);
4949

50-
if (k_uptime_get() / MSEC_PER_SEC > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
50+
if (k_uptime_seconds() > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
5151
goto out;
5252
}
5353
}
@@ -60,7 +60,7 @@ int main(void)
6060

6161
LOG_DBG("Replaced %zu", i);
6262

63-
if (k_uptime_get() / MSEC_PER_SEC > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
63+
if (k_uptime_seconds() > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
6464
goto out;
6565
}
6666
}
@@ -72,7 +72,7 @@ int main(void)
7272

7373
LOG_DBG("Removed %zu", i - 1);
7474

75-
if (k_uptime_get() / MSEC_PER_SEC > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
75+
if (k_uptime_seconds() > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
7676
goto out;
7777
}
7878
}

subsys/lorawan/services/clock_sync.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static struct clock_sync_context ctx;
7171
*/
7272
static int clock_sync_serialize_device_time(uint8_t *buf, size_t size)
7373
{
74-
uint32_t device_time = k_uptime_get() / MSEC_PER_SEC + ctx.time_offset;
74+
uint32_t device_time = k_uptime_seconds() + ctx.time_offset;
7575

7676
if (size < sizeof(uint32_t)) {
7777
return -ENOSPC;
@@ -221,7 +221,7 @@ int lorawan_clock_sync_get(uint32_t *gps_time)
221221
__ASSERT(gps_time != NULL, "gps_time parameter is required");
222222

223223
if (ctx.synchronized) {
224-
*gps_time = (uint32_t)(k_uptime_get() / MSEC_PER_SEC + ctx.time_offset);
224+
*gps_time = k_uptime_seconds() + ctx.time_offset;
225225
return 0;
226226
} else {
227227
return -EAGAIN;

subsys/net/ip/ipv6_pe.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ static bool ipv6_pe_prefix_update_lifetimes(struct net_if_ipv6 *ipv6,
193193
continue;
194194
}
195195

196-
addr_age = (uint32_t)(k_uptime_get() / 1000UL) -
197-
ipv6->unicast[i].addr_create_time;
196+
addr_age = k_uptime_seconds() - ipv6->unicast[i].addr_create_time;
198197
new_age = abs(addr_age) + vlifetime;
199198

200199
if ((new_age >= TEMP_VALID_LIFETIME) ||
@@ -382,7 +381,7 @@ void net_ipv6_pe_start(struct net_if *iface, const struct in6_addr *prefix,
382381
ifaddr->is_temporary = true;
383382
ifaddr->addr_preferred_lifetime = preferred_lifetime;
384383
ifaddr->addr_timeout = ifaddr->addr_preferred_lifetime - DESYNC_FACTOR(ipv6);
385-
ifaddr->addr_create_time = (uint32_t)(k_uptime_get() / 1000UL);
384+
ifaddr->addr_create_time = k_uptime_seconds();
386385

387386
NET_DBG("Lifetime %d desync %d timeout %d preferred %d valid %d",
388387
lifetime, DESYNC_FACTOR(ipv6), ifaddr->addr_timeout,
@@ -674,8 +673,7 @@ static void renewal_cb(struct net_if *iface, void *user_data)
674673
/* If the address is too old, then generate a new one
675674
* and remove the old address.
676675
*/
677-
diff = (int32_t)(ipv6->unicast[i].addr_create_time -
678-
((uint32_t)(k_uptime_get() / 1000UL)));
676+
diff = (int32_t)(ipv6->unicast[i].addr_create_time - k_uptime_seconds());
679677
diff = abs(diff);
680678

681679
if (diff < (ipv6->unicast[i].addr_preferred_lifetime -

subsys/net/lib/lwm2m/ipso_light_control.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ static void *on_time_read_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res
7878
}
7979

8080
if (on_off_value[i]) {
81-
on_time_value[i] = (k_uptime_get() / MSEC_PER_SEC) -
82-
on_time_offset[i];
81+
on_time_value[i] = k_uptime_seconds() - on_time_offset[i];
8382
}
8483

8584
*data_len = sizeof(on_time_value[i]);
@@ -109,8 +108,7 @@ static int on_time_post_write_cb(uint16_t obj_inst_id,
109108
}
110109

111110
if (counter == 0) {
112-
on_time_offset[i] =
113-
(int32_t)(k_uptime_get() / MSEC_PER_SEC);
111+
on_time_offset[i] = k_uptime_seconds();
114112
}
115113

116114
return 0;

subsys/net/lib/lwm2m/lwm2m_obj_device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static int reset_error_list_cb(uint16_t obj_inst_id,
176176
static void *current_time_read_cb(uint16_t obj_inst_id, uint16_t res_id,
177177
uint16_t res_inst_id, size_t *data_len)
178178
{
179-
time_temp = time_offset + (k_uptime_get() / 1000);
179+
time_temp = time_offset + k_uptime_seconds();
180180
*data_len = sizeof(time_temp);
181181

182182
return &time_temp;
@@ -195,10 +195,10 @@ static int current_time_post_write_cb(uint16_t obj_inst_id, uint16_t res_id,
195195
bool last_block, size_t total_size)
196196
{
197197
if (data_len == 4U) {
198-
time_offset = *(uint32_t *)data - (uint32_t)(k_uptime_get() / 1000);
198+
time_offset = *(uint32_t *)data - k_uptime_seconds();
199199
return 0;
200200
} else if (data_len == 8U) {
201-
time_offset = *(time_t *)data - (time_t)(k_uptime_get() / 1000);
201+
time_offset = *(time_t *)data - (time_t)k_uptime_seconds();
202202
return 0;
203203
}
204204

tests/subsys/lorawan/clock_sync/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ZTEST(clock_sync, test_app_time)
8181

8282
device_time = sys_get_le32(req.data + 1);
8383
token_req = req.data[5] & 0xF;
84-
zassert_within((int)device_time, (int)(k_uptime_get() / 1000), 1);
84+
zassert_within((int)device_time, k_uptime_seconds(), 1);
8585

8686
/* apply a time correction of 1000 seconds */
8787
sys_put_le32(1000, ans_data + 1);
@@ -90,7 +90,7 @@ ZTEST(clock_sync, test_app_time)
9090
lorawan_emul_send_downlink(CLOCK_SYNC_PORT, false, 0, 0, sizeof(ans_data), ans_data);
9191

9292
lorawan_clock_sync_get(&gps_time);
93-
zassert_within(gps_time, (k_uptime_get() / 1000) + 1000, 1);
93+
zassert_within(gps_time, k_uptime_seconds() + 1000, 1);
9494
}
9595

9696
ZTEST(clock_sync, test_device_app_time_periodicity)

0 commit comments

Comments
 (0)