btstack_util: add btstack_time16_delta for 16-bit timers

This commit is contained in:
Matthias Ringwald 2022-09-02 10:38:27 +02:00
parent c28332930a
commit a9d566f789
2 changed files with 15 additions and 2 deletions

View File

@ -177,13 +177,20 @@ uint32_t btstack_max(uint32_t a, uint32_t b){
} }
/** /**
* @brief Calculate delta between two points in time * @brief Calculate delta between two uint32_t points in time
* @return time_a - time_b - result > 0 if time_a is newer than time_b * @return time_a - time_b - result > 0 if time_a is newer than time_b
*/ */
int32_t btstack_time_delta(uint32_t time_a, uint32_t time_b){ int32_t btstack_time_delta(uint32_t time_a, uint32_t time_b){
return (int32_t)(time_a - time_b); return (int32_t)(time_a - time_b);
} }
/**
* @brief Calculate delta between two uint16_t points in time
* @return time_a - time_b - result > 0 if time_a is newer than time_b
*/
int16_t btstack_time16_delta(uint16_t time_a, uint16_t time_b){
return (int16_t)(time_a - time_b);
}
char char_for_nibble(int nibble){ char char_for_nibble(int nibble){

View File

@ -88,11 +88,17 @@ uint32_t btstack_min(uint32_t a, uint32_t b);
uint32_t btstack_max(uint32_t a, uint32_t b); uint32_t btstack_max(uint32_t a, uint32_t b);
/** /**
* @brief Calculate delta between two points in time * @brief Calculate delta between two uint32_t points in time
* @return time_a - time_b - result > 0 if time_a is newer than time_b * @return time_a - time_b - result > 0 if time_a is newer than time_b
*/ */
int32_t btstack_time_delta(uint32_t time_a, uint32_t time_b); int32_t btstack_time_delta(uint32_t time_a, uint32_t time_b);
/**
* @brief Calculate delta between two uint16_t points in time
* @return time_a - time_b - result > 0 if time_a is newer than time_b
*/
int16_t btstack_time16_delta(uint16_t time_a, uint16_t time_b);
/** /**
* @brief Read 16/24/32 bit little endian value from buffer * @brief Read 16/24/32 bit little endian value from buffer
* @param buffer * @param buffer