Skip to content

Commit

Permalink
Merge pull request #6399 from OlegHahm/timex_constants
Browse files Browse the repository at this point in the history
timex: unambiguous time conversion macros
  • Loading branch information
OlegHahm committed Jan 19, 2017
2 parents 76f951b + dd58ea3 commit 6936366
Show file tree
Hide file tree
Showing 65 changed files with 137 additions and 164 deletions.
6 changes: 3 additions & 3 deletions cpu/cc2538/periph/i2c.c
Expand Up @@ -30,7 +30,7 @@
#ifdef MODULE_XTIMER
#include "xtimer.h"
#endif
#include "timex.h" /* for SEC_IN_USEC */
#include "timex.h" /* for US_PER_SEC */

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand Down Expand Up @@ -169,7 +169,7 @@ static void callback(void *arg)
static uint_fast8_t i2c_ctrl_blocking(uint_fast8_t flags)
{
#ifdef MODULE_XTIMER
const unsigned int xtimer_timeout = 3 * (DATA_BITS + ACK_BITS) * SEC_IN_USEC / speed_hz;
const unsigned int xtimer_timeout = 3 * (DATA_BITS + ACK_BITS) * US_PER_SEC / speed_hz;
#endif

mutex_trylock(&i2c_wait_mutex);
Expand Down Expand Up @@ -302,7 +302,7 @@ int i2c_init_master(i2c_t dev, i2c_speed_t speed)
cc2538_i2c_init_master(speed_hz);

/* Pre-compute an SCL delay in microseconds */
scl_delay = SEC_IN_USEC;
scl_delay = US_PER_SEC;
scl_delay += speed_hz;
scl_delay /= 2 * speed_hz;

Expand Down
2 changes: 1 addition & 1 deletion cpu/lpc2387/mci/lpc2387-mci.c
Expand Up @@ -475,7 +475,7 @@ static int wait_ready(unsigned short tmr)
{
unsigned long rc;

uint32_t stoppoll = xtimer_now_usec() + tmr * MS_IN_USEC;
uint32_t stoppoll = xtimer_now_usec() + tmr * US_PER_MS;
bool bBreak = false;

while (xtimer_now_usec() < stoppoll/*Timer[0]*/) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/dht/dht.c
Expand Up @@ -91,7 +91,7 @@ int dht_init(dht_t *dev, const dht_params_t *params)
}
gpio_set(dev->pin);

xtimer_usleep(2000 * MS_IN_USEC);
xtimer_usleep(2000 * US_PER_MS);

DEBUG("dht_init: success\n");
return 0;
Expand All @@ -104,7 +104,7 @@ int dht_read(dht_t *dev, int16_t *temp, int16_t *hum)

/* send init signal to device */
gpio_clear(dev->pin);
xtimer_usleep(20 * MS_IN_USEC);
xtimer_usleep(20 * US_PER_MS);
gpio_set(dev->pin);
xtimer_usleep(40);

Expand Down
4 changes: 2 additions & 2 deletions drivers/servo/servo.c
Expand Up @@ -22,7 +22,7 @@

#include "servo.h"
#include "periph/pwm.h"
#include "timex.h" /* for SEC_IN_USEC */
#include "timex.h" /* for US_PER_SEC */

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand All @@ -32,7 +32,7 @@
#endif

#ifndef SERVO_RESOLUTION
#define SERVO_RESOLUTION (SEC_IN_USEC / SERVO_FREQUENCY)
#define SERVO_RESOLUTION (US_PER_SEC / SERVO_FREQUENCY)
#endif

int servo_init(servo_t *dev, pwm_t pwm, int pwm_channel, unsigned int min, unsigned int max)
Expand Down
2 changes: 1 addition & 1 deletion drivers/si70xx/si70xx.c
Expand Up @@ -82,7 +82,7 @@ int si70xx_init(si70xx_t *dev, i2c_t i2c_dev, uint8_t address)
i2c_release(dev->i2c_dev);

/* sensor is ready after at most 25 ms */
xtimer_usleep(25 * MS_IN_USEC);
xtimer_usleep(25 * US_PER_MS);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/xbee/xbee.c
Expand Up @@ -50,7 +50,7 @@
/**
* @brief Timeout for receiving AT command response
*/
#define RESP_TIMEOUT_USEC (SEC_IN_USEC)
#define RESP_TIMEOUT_USEC (US_PER_SEC)

/**
* @brief Start delimiter in API frame mode
Expand Down
2 changes: 1 addition & 1 deletion examples/timer_periodic_wakeup/main.c
Expand Up @@ -23,7 +23,7 @@
#include "timex.h"

/* set interval to 1 second */
#define INTERVAL (1U * SEC_IN_USEC)
#define INTERVAL (1U * US_PER_SEC)

int main(void)
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccn-lite/Makefile
@@ -1,6 +1,6 @@
PKG_NAME=ccn-lite
PKG_URL=https://github.com/cn-uofbasel/ccn-lite/
PKG_VERSION=0b1de2da1ef407ee5793c0e7eda420391ae056dc
PKG_VERSION=10119ca8173457e8a26b28fc9f30fe0d97d17857
PKG_LICENSE=ISC

.PHONY: all
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/emb6/contrib/target.c
Expand Up @@ -201,13 +201,13 @@ clock_time_t hal_getTick(void)

clock_time_t hal_getSec(void)
{
return (clock_time_t)xtimer_now_usec() / SEC_IN_USEC;
return (clock_time_t)xtimer_now_usec() / US_PER_SEC;
}


clock_time_t hal_getTRes(void)
{
return SEC_IN_USEC;
return US_PER_SEC;
}

/** @} */
2 changes: 1 addition & 1 deletion pkg/lwip/contrib/sock/lwip_sock.c
Expand Up @@ -412,7 +412,7 @@ int lwip_sock_recv(struct netconn *conn, uint32_t timeout, struct netbuf **buf)
}
#if LWIP_SO_RCVTIMEO
if ((timeout != 0) && (timeout != SOCK_NO_TIMEOUT)) {
netconn_set_recvtimeout(conn, timeout / MS_IN_USEC);
netconn_set_recvtimeout(conn, timeout / US_PER_MS);
}
else
#endif
Expand Down
8 changes: 4 additions & 4 deletions pkg/lwip/contrib/sys_arch.c
Expand Up @@ -80,12 +80,12 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t count)
if (count != 0) {
uint64_t stop, start;
start = xtimer_now_usec64();
int res = sema_wait_timed((sema_t *)sem, count * MS_IN_USEC);
int res = sema_wait_timed((sema_t *)sem, count * US_PER_MS);
stop = xtimer_now_usec64() - start;
if (res == -ETIMEDOUT) {
return SYS_ARCH_TIMEOUT;
}
return (u32_t)(stop / MS_IN_USEC);
return (u32_t)(stop / US_PER_MS);
}
else {
sema_wait_timed((sema_t *)sem, 0);
Expand Down Expand Up @@ -140,7 +140,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)

start = xtimer_now_usec64();
if (timeout > 0) {
uint64_t u_timeout = (timeout * MS_IN_USEC);
uint64_t u_timeout = (timeout * US_PER_MS);
_xtimer_set64(&timer, (uint32_t)u_timeout, (uint32_t)(u_timeout >> 32));
}
mbox_get(&mbox->mbox, &m);
Expand All @@ -149,7 +149,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
switch (m.type) {
case _MSG_SUCCESS:
*msg = m.content.ptr;
return (u32_t)((stop - start) / MS_IN_USEC);
return (u32_t)((stop - start) / US_PER_MS);
case _MSG_TIMEOUT:
break;
default: /* should not happen */
Expand Down
6 changes: 3 additions & 3 deletions sys/include/net/gnrc/ndp.h
Expand Up @@ -120,13 +120,13 @@ extern "C" {
* @brief Base value in mircoseconds for computing randomised
* reachable time.
*/
#define GNRC_NDP_REACH_TIME (30U * SEC_IN_USEC)
#define GNRC_NDP_REACH_TIME (30U * US_PER_SEC)

/**
* @brief Time in mircoseconds between retransmissions of neighbor
* solicitations to a neighbor.
*/
#define GNRC_NDP_RETRANS_TIMER (1U * SEC_IN_USEC)
#define GNRC_NDP_RETRANS_TIMER (1U * US_PER_SEC)

/**
* @brief Delay in seconds for neighbor cache entry between entering
Expand Down Expand Up @@ -179,7 +179,7 @@ extern "C" {
* solicitation reception and responding router advertisement
* transmission.
*/
#define GNRC_NDP_MAX_RTR_ADV_DELAY (500U * MS_IN_USEC)
#define GNRC_NDP_MAX_RTR_ADV_DELAY (500U * US_PER_MS)
/** @} */

/**
Expand Down
2 changes: 1 addition & 1 deletion sys/include/net/gnrc/sixlowpan/nd.h
Expand Up @@ -113,7 +113,7 @@ extern "C" {
/**
* @brief replacement value (in microseconds) for @ref GNRC_NDP_MAX_RTR_ADV_DELAY
*/
#define GNRC_SIXLOWPAN_ND_MAX_RTR_ADV_DELAY (2U * SEC_IN_USEC)
#define GNRC_SIXLOWPAN_ND_MAX_RTR_ADV_DELAY (2U * US_PER_SEC)
/**
* @brief Lifetime of a tentative address entry in seconds
*/
Expand Down
2 changes: 1 addition & 1 deletion sys/include/net/gnrc/tftp.h
Expand Up @@ -85,7 +85,7 @@ extern "C" {
* @brief The default timeout of a data packet
*/
#ifndef GNRC_TFTP_DEFAULT_TIMEOUT
#define GNRC_TFTP_DEFAULT_TIMEOUT (1 * SEC_IN_USEC)
#define GNRC_TFTP_DEFAULT_TIMEOUT (1 * US_PER_SEC)
#endif

/**
Expand Down
4 changes: 2 additions & 2 deletions sys/include/net/sock/ip.h
Expand Up @@ -170,7 +170,7 @@
* sock_ip_close(&sock);
* return 1;
* }
* if ((res = sock_ip_recv(&sock, buf, sizeof(buf), 1 * SEC_IN_USEC,
* if ((res = sock_ip_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,
* NULL)) < 0) {
* if (res == -ETIMEDOUT) {
* puts("Timed out");
Expand Down Expand Up @@ -232,7 +232,7 @@
* We then wait a second for a reply and print it when it is received.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.c}
* if ((res = sock_ip_recv(&sock, buf, sizeof(buf), 1 * SEC_IN_USEC,
* if ((res = sock_ip_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,
* NULL)) < 0) {
* if (res == -ETIMEDOUT) {
* puts("Timed out");
Expand Down
4 changes: 2 additions & 2 deletions sys/include/net/sock/udp.h
Expand Up @@ -168,7 +168,7 @@
* sock_udp_close(&sock);
* return 1;
* }
* if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * SEC_IN_USEC,
* if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,
* NULL)) < 0) {
* if (res == -ETIMEDOUT) {
* puts("Timed out");
Expand Down Expand Up @@ -232,7 +232,7 @@
* We then wait a second for a reply and print it when it is received.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.c}
* if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * SEC_IN_USEC,
* if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,
* NULL)) < 0) {
* if (res == -ETIMEDOUT) {
* puts("Timed out");
Expand Down
22 changes: 11 additions & 11 deletions sys/include/timex.h
Expand Up @@ -31,32 +31,32 @@ extern "C" {
/**
* @brief The number of microseconds per second
*/
#define SEC_IN_USEC (1000000U)
#define US_PER_SEC (1000000U)

/**
* @brief The number of seconds per minute
*/
#define MIN_IN_SEC (60U)
#define SEC_PER_MIN (60U)

/**
* @brief The number of centiseconds per second
*/
#define SEC_IN_CS (100U)
#define CS_PER_SEC (100U)

/**
* @brief The number of milliseconds per second
*/
#define SEC_IN_MS (1000U)
#define MS_PER_SEC (1000U)

/**
* @brief The number of microseconds per millisecond
*/
#define MS_IN_USEC (1000U)
#define US_PER_MS (1000U)

/**
* @brief The number of nanoseconds per microsecond
*/
#define USEC_IN_NS (1000)
#define NS_PER_US (1000)

/**
* @brief The maximum length of the string representation of a timex timestamp
Expand Down Expand Up @@ -133,8 +133,8 @@ int timex_cmp(const timex_t a, const timex_t b);
*/
static inline void timex_normalize(timex_t *time)
{
time->seconds += (time->microseconds / SEC_IN_USEC);
time->microseconds %= SEC_IN_USEC;
time->seconds += (time->microseconds / US_PER_SEC);
time->microseconds %= US_PER_SEC;
}

/**
Expand All @@ -147,7 +147,7 @@ static inline void timex_normalize(timex_t *time)
*/
static inline int timex_isnormalized(const timex_t *time)
{
return (time->microseconds < SEC_IN_USEC);
return (time->microseconds < US_PER_SEC);
}

/**
Expand All @@ -160,7 +160,7 @@ static inline int timex_isnormalized(const timex_t *time)
/* cppcheck-suppress passedByValue */
static inline uint64_t timex_uint64(const timex_t a)
{
return (uint64_t) a.seconds * SEC_IN_USEC + a.microseconds;
return (uint64_t) a.seconds * US_PER_SEC + a.microseconds;
}

/**
Expand All @@ -172,7 +172,7 @@ static inline uint64_t timex_uint64(const timex_t a)
*/
static inline timex_t timex_from_uint64(const uint64_t timestamp)
{
return timex_set(timestamp / SEC_IN_USEC, timestamp % SEC_IN_USEC);
return timex_set(timestamp / US_PER_SEC, timestamp % US_PER_SEC);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sys/include/xtimer/implementation.h
Expand Up @@ -168,12 +168,12 @@ static inline void xtimer_usleep64(uint64_t microseconds)

static inline void xtimer_sleep(uint32_t seconds)
{
_xtimer_tsleep64(_xtimer_ticks_from_usec64((uint64_t)seconds * SEC_IN_USEC));
_xtimer_tsleep64(_xtimer_ticks_from_usec64((uint64_t)seconds * US_PER_SEC));
}

static inline void xtimer_nanosleep(uint32_t nanoseconds)
{
_xtimer_tsleep32(_xtimer_ticks_from_usec(nanoseconds / USEC_IN_NS));
_xtimer_tsleep32(_xtimer_ticks_from_usec(nanoseconds / NS_PER_US));
}

static inline void xtimer_tsleep32(xtimer_ticks32_t ticks)
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/sntp/sntp.c
Expand Up @@ -71,7 +71,7 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
return result;
}
sock_udp_close(&_sntp_sock);
_sntp_offset = (byteorder_ntohl(_sntp_packet.transmit.seconds) * SEC_IN_USEC) +
_sntp_offset = (byteorder_ntohl(_sntp_packet.transmit.seconds) * US_PER_SEC) +
((byteorder_ntohl(_sntp_packet.transmit.fraction) * 232)
/ 1000000) - xtimer_now64();
mutex_unlock(&_sntp_mutex);
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/uhcp/uhcpc.c
Expand Up @@ -43,7 +43,7 @@ void uhcp_client(uhcp_iface_t iface)
while(1) {
puts("uhcp_client(): sending REQ...");
sock_udp_send(&sock, &req, sizeof(uhcp_req_t), &req_target);
res = sock_udp_recv(&sock, buf, sizeof(buf), 10U*SEC_IN_USEC, &remote);
res = sock_udp_recv(&sock, buf, sizeof(buf), 10U*US_PER_SEC, &remote);
if (res > 0) {
uhcp_handle_udp(buf, res, remote.addr.ipv6, remote.port, iface);
xtimer_sleep(60);
Expand Down

0 comments on commit 6936366

Please sign in to comment.