mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 21:41:13 +00:00
add run_loop_get_time_ms() and implement in embedded, posix, and cocoa run loops
This commit is contained in:
parent
938049d77f
commit
ea2df9a562
@ -99,6 +99,12 @@ void run_loop_set_timer_handler(timer_source_t *ts, void (*process)(timer_source
|
||||
void run_loop_add_timer(timer_source_t *timer);
|
||||
int run_loop_remove_timer(timer_source_t *timer);
|
||||
|
||||
/**
|
||||
* @brief Get current time in ms
|
||||
* @note 32-bit ms counter will overflow after approx. 52 days
|
||||
*/
|
||||
uint32_t run_loop_get_time_ms(void);
|
||||
|
||||
/**
|
||||
* @brief Init must be called before any other run_loop call. Use RUN_LOOP_EMBEDDED for embedded devices.
|
||||
*/
|
||||
@ -120,6 +126,7 @@ int run_loop_remove_data_source(data_source_t *dataSource);
|
||||
*/
|
||||
void run_loop_execute(void);
|
||||
|
||||
|
||||
// hack to fix HCI timer handling
|
||||
#ifdef HAVE_TICK
|
||||
/**
|
||||
|
@ -52,6 +52,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static struct timeval init_tv;
|
||||
|
||||
static void theCFRunLoopTimerCallBack (CFRunLoopTimerRef timer,void *info){
|
||||
timer_source_t * ts = (timer_source_t*)info;
|
||||
ts->process(ts);
|
||||
@ -149,7 +151,18 @@ static void cocoa_set_timer(timer_source_t *a, uint32_t timeout_in_ms){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Queries the current time in ms since start
|
||||
*/
|
||||
static uint32_t cocoa_get_time_ms(void){
|
||||
struct timeval current_tv;
|
||||
gettimeofday(¤t_tv, NULL);
|
||||
return (current_tv.tv_sec - init_tv.tv_sec) * 1000
|
||||
+ (current_tv.tv_usec - init_tv.tv_usec) / 1000;
|
||||
}
|
||||
|
||||
void cocoa_init(void){
|
||||
gettimeofday(&init_tv, NULL);
|
||||
}
|
||||
|
||||
void cocoa_execute(void)
|
||||
@ -171,5 +184,6 @@ run_loop_t run_loop_cocoa = {
|
||||
&cocoa_remove_timer,
|
||||
&cocoa_execute,
|
||||
&cocoa_dump_timer,
|
||||
&cocoa_get_time_ms,
|
||||
};
|
||||
|
||||
|
@ -272,4 +272,5 @@ run_loop_t run_loop_posix = {
|
||||
&posix_remove_timer,
|
||||
&posix_execute,
|
||||
&posix_dump_timer,
|
||||
&posix_get_time_ms,
|
||||
};
|
||||
|
@ -120,6 +120,15 @@ int run_loop_remove_timer(timer_source_t *ts){
|
||||
return the_run_loop->remove_timer(ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current time in ms
|
||||
*/
|
||||
uint32_t run_loop_get_time_ms(void){
|
||||
run_loop_assert();
|
||||
return the_run_loop->get_time_ms();
|
||||
}
|
||||
|
||||
|
||||
void run_loop_timer_dump(void){
|
||||
run_loop_assert();
|
||||
the_run_loop->dump_timer();
|
||||
|
@ -268,4 +268,5 @@ const run_loop_t run_loop_embedded = {
|
||||
&embedded_remove_timer,
|
||||
&embedded_execute,
|
||||
&embedded_dump_timer,
|
||||
&embedded_get_time_ms,
|
||||
};
|
||||
|
@ -67,6 +67,7 @@ typedef struct {
|
||||
int (*remove_timer)(timer_source_t *timer);
|
||||
void (*execute)(void);
|
||||
void (*dump_timer)(void);
|
||||
uint32_t (*get_time_ms)(void);
|
||||
} run_loop_t;
|
||||
|
||||
#if defined __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user