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>
This commit is contained in:
parent
98deebd29b
commit
23ca74b756
6 changed files with 15 additions and 19 deletions
|
@ -47,7 +47,7 @@ int main(void)
|
|||
|
||||
LOG_DBG("Inserted %zu", i);
|
||||
|
||||
if (k_uptime_get() / MSEC_PER_SEC > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
|
||||
if (k_uptime_seconds() > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ int main(void)
|
|||
|
||||
LOG_DBG("Replaced %zu", i);
|
||||
|
||||
if (k_uptime_get() / MSEC_PER_SEC > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
|
||||
if (k_uptime_seconds() > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ int main(void)
|
|||
|
||||
LOG_DBG("Removed %zu", i - 1);
|
||||
|
||||
if (k_uptime_get() / MSEC_PER_SEC > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
|
||||
if (k_uptime_seconds() > CONFIG_TEST_LIB_HASH_MAP_DURATION_S) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ static struct clock_sync_context ctx;
|
|||
*/
|
||||
static int clock_sync_serialize_device_time(uint8_t *buf, size_t size)
|
||||
{
|
||||
uint32_t device_time = k_uptime_get() / MSEC_PER_SEC + ctx.time_offset;
|
||||
uint32_t device_time = k_uptime_seconds() + ctx.time_offset;
|
||||
|
||||
if (size < sizeof(uint32_t)) {
|
||||
return -ENOSPC;
|
||||
|
@ -221,7 +221,7 @@ int lorawan_clock_sync_get(uint32_t *gps_time)
|
|||
__ASSERT(gps_time != NULL, "gps_time parameter is required");
|
||||
|
||||
if (ctx.synchronized) {
|
||||
*gps_time = (uint32_t)(k_uptime_get() / MSEC_PER_SEC + ctx.time_offset);
|
||||
*gps_time = k_uptime_seconds() + ctx.time_offset;
|
||||
return 0;
|
||||
} else {
|
||||
return -EAGAIN;
|
||||
|
|
|
@ -193,8 +193,7 @@ static bool ipv6_pe_prefix_update_lifetimes(struct net_if_ipv6 *ipv6,
|
|||
continue;
|
||||
}
|
||||
|
||||
addr_age = (uint32_t)(k_uptime_get() / 1000UL) -
|
||||
ipv6->unicast[i].addr_create_time;
|
||||
addr_age = k_uptime_seconds() - ipv6->unicast[i].addr_create_time;
|
||||
new_age = abs(addr_age) + vlifetime;
|
||||
|
||||
if ((new_age >= TEMP_VALID_LIFETIME) ||
|
||||
|
@ -382,7 +381,7 @@ void net_ipv6_pe_start(struct net_if *iface, const struct in6_addr *prefix,
|
|||
ifaddr->is_temporary = true;
|
||||
ifaddr->addr_preferred_lifetime = preferred_lifetime;
|
||||
ifaddr->addr_timeout = ifaddr->addr_preferred_lifetime - DESYNC_FACTOR(ipv6);
|
||||
ifaddr->addr_create_time = (uint32_t)(k_uptime_get() / 1000UL);
|
||||
ifaddr->addr_create_time = k_uptime_seconds();
|
||||
|
||||
NET_DBG("Lifetime %d desync %d timeout %d preferred %d valid %d",
|
||||
lifetime, DESYNC_FACTOR(ipv6), ifaddr->addr_timeout,
|
||||
|
@ -674,8 +673,7 @@ static void renewal_cb(struct net_if *iface, void *user_data)
|
|||
/* If the address is too old, then generate a new one
|
||||
* and remove the old address.
|
||||
*/
|
||||
diff = (int32_t)(ipv6->unicast[i].addr_create_time -
|
||||
((uint32_t)(k_uptime_get() / 1000UL)));
|
||||
diff = (int32_t)(ipv6->unicast[i].addr_create_time - k_uptime_seconds());
|
||||
diff = abs(diff);
|
||||
|
||||
if (diff < (ipv6->unicast[i].addr_preferred_lifetime -
|
||||
|
|
|
@ -78,8 +78,7 @@ static void *on_time_read_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res
|
|||
}
|
||||
|
||||
if (on_off_value[i]) {
|
||||
on_time_value[i] = (k_uptime_get() / MSEC_PER_SEC) -
|
||||
on_time_offset[i];
|
||||
on_time_value[i] = k_uptime_seconds() - on_time_offset[i];
|
||||
}
|
||||
|
||||
*data_len = sizeof(on_time_value[i]);
|
||||
|
@ -109,8 +108,7 @@ static int on_time_post_write_cb(uint16_t obj_inst_id,
|
|||
}
|
||||
|
||||
if (counter == 0) {
|
||||
on_time_offset[i] =
|
||||
(int32_t)(k_uptime_get() / MSEC_PER_SEC);
|
||||
on_time_offset[i] = k_uptime_seconds();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -176,7 +176,7 @@ static int reset_error_list_cb(uint16_t obj_inst_id,
|
|||
static void *current_time_read_cb(uint16_t obj_inst_id, uint16_t res_id,
|
||||
uint16_t res_inst_id, size_t *data_len)
|
||||
{
|
||||
time_temp = time_offset + (k_uptime_get() / 1000);
|
||||
time_temp = time_offset + k_uptime_seconds();
|
||||
*data_len = sizeof(time_temp);
|
||||
|
||||
return &time_temp;
|
||||
|
@ -195,10 +195,10 @@ static int current_time_post_write_cb(uint16_t obj_inst_id, uint16_t res_id,
|
|||
bool last_block, size_t total_size)
|
||||
{
|
||||
if (data_len == 4U) {
|
||||
time_offset = *(uint32_t *)data - (uint32_t)(k_uptime_get() / 1000);
|
||||
time_offset = *(uint32_t *)data - k_uptime_seconds();
|
||||
return 0;
|
||||
} else if (data_len == 8U) {
|
||||
time_offset = *(time_t *)data - (time_t)(k_uptime_get() / 1000);
|
||||
time_offset = *(time_t *)data - (time_t)k_uptime_seconds();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ ZTEST(clock_sync, test_app_time)
|
|||
|
||||
device_time = sys_get_le32(req.data + 1);
|
||||
token_req = req.data[5] & 0xF;
|
||||
zassert_within((int)device_time, (int)(k_uptime_get() / 1000), 1);
|
||||
zassert_within((int)device_time, k_uptime_seconds(), 1);
|
||||
|
||||
/* apply a time correction of 1000 seconds */
|
||||
sys_put_le32(1000, ans_data + 1);
|
||||
|
@ -90,7 +90,7 @@ ZTEST(clock_sync, test_app_time)
|
|||
lorawan_emul_send_downlink(CLOCK_SYNC_PORT, false, 0, 0, sizeof(ans_data), ans_data);
|
||||
|
||||
lorawan_clock_sync_get(&gps_time);
|
||||
zassert_within(gps_time, (k_uptime_get() / 1000) + 1000, 1);
|
||||
zassert_within(gps_time, k_uptime_seconds() + 1000, 1);
|
||||
}
|
||||
|
||||
ZTEST(clock_sync, test_device_app_time_periodicity)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue