mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-25 09:35:42 +00:00
embedded_ -> run_loop_embedded_
This commit is contained in:
parent
a135f527a4
commit
829afdbecc
@ -205,7 +205,7 @@ static void h4_block_received(void){
|
||||
h4_state = H4_PACKET_RECEIVED;
|
||||
bytes_to_read = 0;
|
||||
// trigger run loop
|
||||
embedded_trigger();
|
||||
run_loop_embedded_trigger();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -224,7 +224,7 @@ static void h4_block_sent(void){
|
||||
case TX_W4_PACKET_SENT:
|
||||
tx_state = TX_DONE;
|
||||
// trigger run loop
|
||||
embedded_trigger();
|
||||
run_loop_embedded_trigger();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -281,7 +281,7 @@ static void h4_block_received(void){
|
||||
bytes_to_read = 0;
|
||||
|
||||
// trigger run loop - necessary for use in low power modes
|
||||
embedded_trigger();
|
||||
run_loop_embedded_trigger();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -315,7 +315,7 @@ static void ehcill_sleep_ack_timer_setup(void){
|
||||
ehcill_sleep_ack_timer.process = &ehcill_sleep_ack_timer_handler;
|
||||
run_loop_set_timer(&ehcill_sleep_ack_timer, 50);
|
||||
run_loop_add_timer(&ehcill_sleep_ack_timer);
|
||||
embedded_trigger();
|
||||
run_loop_embedded_trigger();
|
||||
}
|
||||
|
||||
static void ehcill_reactivate_rx(void){
|
||||
@ -363,7 +363,7 @@ static void h4_block_sent(void){
|
||||
// trigger run loop
|
||||
tx_state = TX_DONE;
|
||||
tx_send_packet_sent = 1;
|
||||
embedded_trigger();
|
||||
run_loop_embedded_trigger();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -382,7 +382,7 @@ static void h4_block_sent(void){
|
||||
echill_send_wakeup_ind();
|
||||
}
|
||||
// trigger run loop
|
||||
embedded_trigger();
|
||||
run_loop_embedded_trigger();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -91,21 +91,21 @@ static int trigger_event_received = 0;
|
||||
/**
|
||||
* Add data_source to run_loop
|
||||
*/
|
||||
static void embedded_add_data_source(data_source_t *ds){
|
||||
static void run_loop_embedded_add_data_source(data_source_t *ds){
|
||||
linked_list_add(&data_sources, (linked_item_t *) ds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove data_source from run loop
|
||||
*/
|
||||
static int embedded_remove_data_source(data_source_t *ds){
|
||||
static int run_loop_embedded_remove_data_source(data_source_t *ds){
|
||||
return linked_list_remove(&data_sources, (linked_item_t *) ds);
|
||||
}
|
||||
|
||||
// set timer
|
||||
static void embedded_set_timer(timer_source_t *ts, uint32_t timeout_in_ms){
|
||||
static void run_loop_embedded_set_timer(timer_source_t *ts, uint32_t timeout_in_ms){
|
||||
#ifdef HAVE_TICK
|
||||
uint32_t ticks = embedded_ticks_for_ms(timeout_in_ms);
|
||||
uint32_t ticks = run_loop_embedded_ticks_for_ms(timeout_in_ms);
|
||||
if (ticks == 0) ticks++;
|
||||
// time until next tick is < hal_tick_get_tick_period_in_ms() and we don't know, so we add one
|
||||
ts->timeout = system_ticks + 1 + ticks;
|
||||
@ -118,7 +118,7 @@ static void embedded_set_timer(timer_source_t *ts, uint32_t timeout_in_ms){
|
||||
/**
|
||||
* Add timer to run_loop (keep list sorted)
|
||||
*/
|
||||
static void embedded_add_timer(timer_source_t *ts){
|
||||
static void run_loop_embedded_add_timer(timer_source_t *ts){
|
||||
#ifdef TIMER_SUPPORT
|
||||
linked_item_t *it;
|
||||
for (it = (linked_item_t *) &timers; it->next ; it = it->next){
|
||||
@ -139,7 +139,7 @@ static void embedded_add_timer(timer_source_t *ts){
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static int embedded_remove_timer(timer_source_t *ts){
|
||||
static int run_loop_embedded_remove_timer(timer_source_t *ts){
|
||||
#ifdef TIMER_SUPPORT
|
||||
return linked_list_remove(&timers, (linked_item_t *) ts);
|
||||
#else
|
||||
@ -147,7 +147,7 @@ static int embedded_remove_timer(timer_source_t *ts){
|
||||
#endif
|
||||
}
|
||||
|
||||
static void embedded_dump_timer(void){
|
||||
static void run_loop_embedded_dump_timer(void){
|
||||
#ifdef TIMER_SUPPORT
|
||||
#ifdef ENABLE_LOG_INFO
|
||||
linked_item_t *it;
|
||||
@ -163,7 +163,7 @@ static void embedded_dump_timer(void){
|
||||
/**
|
||||
* Execute run_loop once
|
||||
*/
|
||||
void embedded_execute_once(void) {
|
||||
void run_loop_embedded_execute_once(void) {
|
||||
data_source_t *ds;
|
||||
|
||||
// process data sources
|
||||
@ -202,32 +202,28 @@ void embedded_execute_once(void) {
|
||||
/**
|
||||
* Execute run_loop
|
||||
*/
|
||||
static void embedded_execute(void) {
|
||||
static void run_loop_embedded_execute(void) {
|
||||
while (1) {
|
||||
embedded_execute_once();
|
||||
run_loop_embedded_execute_once();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_TICK
|
||||
static void embedded_tick_handler(void){
|
||||
static void run_loop_embedded_tick_handler(void){
|
||||
system_ticks++;
|
||||
trigger_event_received = 1;
|
||||
}
|
||||
|
||||
uint32_t embedded_get_ticks(void){
|
||||
uint32_t run_loop_embedded_get_ticks(void){
|
||||
return system_ticks;
|
||||
}
|
||||
|
||||
void embedded_set_ticks(uint32_t ticks){
|
||||
system_ticks = ticks;
|
||||
}
|
||||
|
||||
uint32_t embedded_ticks_for_ms(uint32_t time_in_ms){
|
||||
uint32_t run_loop_embedded_ticks_for_ms(uint32_t time_in_ms){
|
||||
return time_in_ms / hal_tick_get_tick_period_in_ms();
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint32_t embedded_get_time_ms(void){
|
||||
static uint32_t run_loop_embedded_get_time_ms(void){
|
||||
#ifdef HAVE_TIME_MS
|
||||
return hal_time_ms();
|
||||
#endif
|
||||
@ -241,11 +237,11 @@ static uint32_t embedded_get_time_ms(void){
|
||||
/**
|
||||
* trigger run loop iteration
|
||||
*/
|
||||
void embedded_trigger(void){
|
||||
void run_loop_embedded_trigger(void){
|
||||
trigger_event_received = 1;
|
||||
}
|
||||
|
||||
static void embedded_init(void){
|
||||
static void run_loop_embedded_init(void){
|
||||
|
||||
data_sources = NULL;
|
||||
|
||||
@ -256,18 +252,18 @@ static void embedded_init(void){
|
||||
#ifdef HAVE_TICK
|
||||
system_ticks = 0;
|
||||
hal_tick_init();
|
||||
hal_tick_set_handler(&embedded_tick_handler);
|
||||
hal_tick_set_handler(&run_loop_embedded_tick_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
const run_loop_t run_loop_embedded = {
|
||||
&embedded_init,
|
||||
&embedded_add_data_source,
|
||||
&embedded_remove_data_source,
|
||||
&embedded_set_timer,
|
||||
&embedded_add_timer,
|
||||
&embedded_remove_timer,
|
||||
&embedded_execute,
|
||||
&embedded_dump_timer,
|
||||
&embedded_get_time_ms,
|
||||
&run_loop_embedded_init,
|
||||
&run_loop_embedded_add_data_source,
|
||||
&run_loop_embedded_remove_data_source,
|
||||
&run_loop_embedded_set_timer,
|
||||
&run_loop_embedded_add_timer,
|
||||
&run_loop_embedded_remove_timer,
|
||||
&run_loop_embedded_execute,
|
||||
&run_loop_embedded_dump_timer,
|
||||
&run_loop_embedded_get_time_ms,
|
||||
};
|
||||
|
@ -40,7 +40,7 @@
|
||||
#define PIN_LED 13
|
||||
|
||||
// prototypes
|
||||
extern "C" void embedded_execute_once(void);
|
||||
extern "C" void run_loop_embedded_execute_once(void);
|
||||
extern "C" void hal_uart_dma_process(void);
|
||||
|
||||
enum {
|
||||
@ -819,7 +819,7 @@ void BTstackManager::loop(void){
|
||||
// process data from/to Bluetooth module
|
||||
hal_uart_dma_process();
|
||||
// BTstack Run Loop
|
||||
embedded_execute_once();
|
||||
run_loop_embedded_execute_once();
|
||||
}
|
||||
|
||||
void BTstackManager::bleStartScanning(void){
|
||||
|
@ -78,8 +78,8 @@ void hal_tick_set_handler(void (*handler)(void)){
|
||||
}
|
||||
|
||||
static void msleep(uint32_t delay) {
|
||||
uint32_t wake = embedded_get_ticks() + delay / hal_tick_get_tick_period_in_ms();
|
||||
while (wake > embedded_get_ticks()){
|
||||
uint32_t wake = run_loop_embedded_get_ticks() + delay / hal_tick_get_tick_period_in_ms();
|
||||
while (wake > run_loop_embedded_get_ticks()){
|
||||
SYS_Tasks();
|
||||
};
|
||||
}
|
||||
@ -250,6 +250,6 @@ void BTSTACK_Tasks(void){
|
||||
}
|
||||
|
||||
// BTstack Run Loop
|
||||
embedded_execute_once();
|
||||
run_loop_embedded_execute_once();
|
||||
}
|
||||
|
||||
|
@ -112,8 +112,8 @@ void sys_tick_handler(void){
|
||||
}
|
||||
|
||||
static void msleep(uint32_t delay) {
|
||||
uint32_t wake = embedded_get_ticks() + delay / hal_tick_get_tick_period_in_ms();
|
||||
while (wake > embedded_get_ticks());
|
||||
uint32_t wake = run_loop_embedded_get_ticks() + delay / hal_tick_get_tick_period_in_ms();
|
||||
while (wake > run_loop_embedded_get_ticks());
|
||||
}
|
||||
|
||||
// hal_led.h implementation
|
||||
|
@ -203,7 +203,7 @@ static void hci_connection_timeout_handler(timer_source_t *timer){
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_TICK
|
||||
if (embedded_get_ticks() > connection->timestamp + embedded_ticks_for_ms(HCI_CONNECTION_TIMEOUT_MS)){
|
||||
if (run_loop_embedded_ticks_for_ms() > connection->timestamp + run_loop_embedded_ticks_for_ms(HCI_CONNECTION_TIMEOUT_MS)){
|
||||
// connections might be timed out
|
||||
hci_emit_l2cap_check_timeout(connection);
|
||||
}
|
||||
@ -223,7 +223,7 @@ static void hci_connection_timestamp(hci_connection_t *connection){
|
||||
gettimeofday(&connection->timestamp, NULL);
|
||||
#endif
|
||||
#ifdef HAVE_TICK
|
||||
connection->timestamp = embedded_get_ticks();
|
||||
connection->timestamp = run_loop_embedded_get_ticks();
|
||||
#endif
|
||||
#ifdef HAVE_TIME_MS
|
||||
connection->timestamp = run_loop_get_time_ms();
|
||||
|
@ -154,7 +154,7 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
|
||||
|
||||
#ifdef EMBEDDED
|
||||
// #ifdef HAVE_TICK
|
||||
// uint32_t time_ms = embedded_get_time_ms();
|
||||
// uint32_t time_ms = run_loop_embedded_get_time_ms();
|
||||
// printf("[%06u] ", time_ms);
|
||||
// #endif
|
||||
printf_packet(packet_type, in, packet, len);
|
||||
|
@ -69,6 +69,11 @@ typedef struct {
|
||||
} hci_transport_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
const char *device_name;
|
||||
uint32_t baudrate_init; // initial baud rate
|
||||
uint32_t baudrate_main; // = 0: same as initial baudrate
|
||||
|
@ -131,31 +131,26 @@ int run_loop_remove_data_source(data_source_t *dataSource);
|
||||
*/
|
||||
void run_loop_execute(void);
|
||||
|
||||
|
||||
// hack to fix HCI timer handling
|
||||
#ifdef HAVE_TICK
|
||||
/**
|
||||
* @brief Sets how many milliseconds has one tick.
|
||||
*/
|
||||
uint32_t embedded_ticks_for_ms(uint32_t time_in_ms);
|
||||
uint32_t run_loop_embedded_ticks_for_ms(uint32_t time_in_ms);
|
||||
/**
|
||||
* @brief Queries the current time in ticks.
|
||||
*/
|
||||
uint32_t embedded_get_ticks(void);
|
||||
/**
|
||||
* @brief Allows to update BTstack system ticks based on another already existing clock.
|
||||
*/
|
||||
void embedded_set_ticks(uint32_t ticks);
|
||||
uint32_t run_loop_embedded_get_ticks(void);
|
||||
#endif
|
||||
#ifdef EMBEDDED
|
||||
/**
|
||||
* @brief Sets an internal flag that is checked in the critical section just before entering sleep mode. Has to be called by the interrupt handler of a data source to signal the run loop that a new data is available.
|
||||
*/
|
||||
void embedded_trigger(void);
|
||||
void run_loop_embedded_trigger(void);
|
||||
/**
|
||||
* @brief Execute run_loop once. It can be used to integrate BTstack's timer and data source processing into a foreign run loop (it is not recommended).
|
||||
*/
|
||||
void embedded_execute_once(void);
|
||||
void run_loop_embedded_execute_once(void);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WICED
|
||||
|
Loading…
x
Reference in New Issue
Block a user