Skip to content

Commit

Permalink
xtimer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Oct 8, 2017
1 parent cde263e commit 8030ca7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 108 deletions.
2 changes: 2 additions & 0 deletions burba/boards/cc3200-launchxl/dist/gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#*****************************************************************************
target remote | openocd -c "gdb_port pipe; log_output openocd.log" -f cc3200.cfg

set auto-load safe-path /

#*****************************************************************************
# Load the binary
#*****************************************************************************
Expand Down
114 changes: 6 additions & 108 deletions burba/sys/include/xtimer/tick_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
*
* @{
* @file
* @brief xtimer tick <-> seconds conversions for different values of XTIMER_HZ
* @brief xtimer tick <-> seconds conversions for different values of
* XTIMER_HZ
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/

Expand All @@ -28,126 +29,23 @@
extern "C" {
#endif

/* Some optimizations for common timer frequencies */
#if (XTIMER_SHIFT != 0)
#if (XTIMER_HZ % 15625 != 0)
#error XTIMER_HZ must be a multiple of 15625 (5^6) when using XTIMER_SHIFT
#endif
#if (XTIMER_HZ > 1000000ul)
#if (XTIMER_HZ != (1000000ul << XTIMER_SHIFT))
#error XTIMER_HZ != (1000000ul << XTIMER_SHIFT)
#endif
/* XTIMER_HZ is a power-of-two multiple of 1 MHz */
/* e.g. cc2538 uses a 16 MHz timer */
inline static uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
return (usec << XTIMER_SHIFT); /* multiply by power of two */
}

inline static uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
return (usec << XTIMER_SHIFT); /* multiply by power of two */
}

inline static uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
return (ticks >> XTIMER_SHIFT); /* divide by power of two */
}

inline static uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
return (ticks >> XTIMER_SHIFT); /* divide by power of two */
}

#else /* !(XTIMER_HZ > 1000000ul) */
#if ((XTIMER_HZ << XTIMER_SHIFT) != 1000000ul)
#error (XTIMER_HZ << XTIMER_SHIFT) != 1000000ul
#endif
/* 1 MHz is a power-of-two multiple of XTIMER_HZ */
/* e.g. ATmega2560 uses a 250 kHz timer */
inline static uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
return (usec >> XTIMER_SHIFT); /* divide by power of two */
}

inline static uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
return (usec >> XTIMER_SHIFT); /* divide by power of two */
}

inline static uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
return (ticks << XTIMER_SHIFT); /* multiply by power of two */
}

inline static uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
return (ticks << XTIMER_SHIFT); /* multiply by power of two */
}
#endif /* defined(XTIMER_SHIFT) && (XTIMER_SHIFT != 0) */
#elif XTIMER_HZ == (1000000ul)
/* This is the most straightforward as the xtimer API is based around
* microseconds for representing time values. */
inline static uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
return ticks; /* no-op */
return ticks / XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

inline static uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
return ticks; /* no-op */
return ticks / XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

inline static uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
return usec; /* no-op */
return usec * XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

inline static uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
return usec; /* no-op */
}

#elif XTIMER_HZ == (32768ul)
/* This is a common frequency for RTC crystals. We use the fact that the
* greatest common divisor between 32768 and 1000000 is 64, so instead of
* multiplying by the fraction (32768 / 1000000), we will instead use
* (512 / 15625), which reduces the truncation caused by the integer widths */
inline static uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
return div_u32_by_15625div512(usec);
}

inline static uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
return div_u64_by_15625div512(usec);
}

inline static uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
/* return (usec * 15625) / 512; */
/* Using 64 bit multiplication to avoid truncating the top 9 bits */
uint64_t usec = (uint64_t)ticks * 15625ul;
return (usec >> 9); /* equivalent to (usec / 512) */
}

inline static uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
/* return (usec * 15625) / 512; */
uint64_t usec = (uint64_t)ticks * 15625ul;
return (usec >> 9); /* equivalent to (usec / 512) */
return usec * XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}
#elif XTIMER_HZ == (80000000ul)
/* This is the most straightforward as the xtimer API is based around
* microseconds for representing time values. */
inline static uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
return ticks/XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

inline static uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
return ticks/XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

inline static uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
return usec*XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

inline static uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
return usec*XTIMER_USEC_TO_TICKS_FACTOR; /* no-op */
}

#else
/* No matching implementation found, try to give meaningful error messages */
#if ((XTIMER_HZ % 15625) == 0)
#error Unsupported hardware timer frequency (XTIMER_HZ), missing XTIMER_SHIFT in board.h? See xtimer.h documentation for more info
#else
#error Unknown hardware timer frequency (XTIMER_HZ), check board.h and/or add an implementation in sys/include/xtimer/tick_conversion.h
#endif
#endif

#ifdef __cplusplus
}
Expand Down

0 comments on commit 8030ca7

Please sign in to comment.