Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,33 @@ typedef struct rt_channel *rt_channel_t;
/**@}*/
#endif /* RT_USING_DEVICE */

/* BITOPS */

#if defined (ARCH_CPU_64BIT)
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif
#define BITS_PER_LONG_LONG 64

#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))

#define BIT(nr) (1UL << (nr))
#define BIT_ULL(nr) (1ULL << (nr))
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))

#define GENMASK(h, l) \
(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))

#define GENMASK_ULL(h, l) \
(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))


#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions include/rtthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object));
* clock & timer interface
*/
rt_tick_t rt_tick_get(void);
rt_tick_t rt_delta_tick_get(rt_tick_t last_time);
void rt_tick_set(rt_tick_t tick);
void rt_tick_increase(void);
void rt_tick_increase_tick(rt_tick_t tick);
Expand Down
18 changes: 18 additions & 0 deletions src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ rt_tick_t rt_tick_get(void)
}
RTM_EXPORT(rt_tick_get);

/**
* @brief This function will return delta tick from last_time.
*
* @param last_time to consider
*
* @return Return delta tick.
*/
rt_tick_t rt_delta_tick_get(rt_tick_t last_time)
{
rt_tick_t tnow = rt_tick_get();
if (tnow >= last_time) {
return (tnow - last_time);
} else {
return (RT_TICK_MAX - last_time + tnow + 1);
}
}
RTM_EXPORT(rt_delta_tick_get);

/**
* @brief This function will set current tick.
*
Expand Down
Loading