From 829afdbecc9341530d78122da0bfbb6f98917994 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 6 Jan 2016 15:33:56 +0100 Subject: [PATCH] embedded_ -> run_loop_embedded_ --- platform/embedded/hci_transport_h4_dma.c | 4 +- .../embedded/hci_transport_h4_ehcill_dma.c | 8 +-- platform/embedded/run_loop_embedded.c | 56 +++++++++---------- port/arduino/BTstack.cpp | 4 +- port/pic32-harmony/src/btstack_port.c | 6 +- port/stm32-f103rb-nucleo/main.c | 4 +- src/hci.c | 4 +- src/hci_dump.c | 2 +- src/hci_transport.h | 5 ++ src/run_loop.h | 13 ++--- 10 files changed, 51 insertions(+), 55 deletions(-) diff --git a/platform/embedded/hci_transport_h4_dma.c b/platform/embedded/hci_transport_h4_dma.c index bd557a746..da8f6e634 100644 --- a/platform/embedded/hci_transport_h4_dma.c +++ b/platform/embedded/hci_transport_h4_dma.c @@ -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; diff --git a/platform/embedded/hci_transport_h4_ehcill_dma.c b/platform/embedded/hci_transport_h4_ehcill_dma.c index fe977d99d..b3bda545d 100644 --- a/platform/embedded/hci_transport_h4_ehcill_dma.c +++ b/platform/embedded/hci_transport_h4_ehcill_dma.c @@ -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; diff --git a/platform/embedded/run_loop_embedded.c b/platform/embedded/run_loop_embedded.c index a8653514b..91396db3c 100644 --- a/platform/embedded/run_loop_embedded.c +++ b/platform/embedded/run_loop_embedded.c @@ -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, }; diff --git a/port/arduino/BTstack.cpp b/port/arduino/BTstack.cpp index 4eda6a161..865f7eea2 100644 --- a/port/arduino/BTstack.cpp +++ b/port/arduino/BTstack.cpp @@ -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){ diff --git a/port/pic32-harmony/src/btstack_port.c b/port/pic32-harmony/src/btstack_port.c index c8d9293bb..ce42d5054 100644 --- a/port/pic32-harmony/src/btstack_port.c +++ b/port/pic32-harmony/src/btstack_port.c @@ -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(); } diff --git a/port/stm32-f103rb-nucleo/main.c b/port/stm32-f103rb-nucleo/main.c index bd09de43f..01bc33576 100644 --- a/port/stm32-f103rb-nucleo/main.c +++ b/port/stm32-f103rb-nucleo/main.c @@ -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 diff --git a/src/hci.c b/src/hci.c index 608408af0..b4324c1b9 100644 --- a/src/hci.c +++ b/src/hci.c @@ -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(); diff --git a/src/hci_dump.c b/src/hci_dump.c index ba7c0d1bc..8d2dd9369 100644 --- a/src/hci_dump.c +++ b/src/hci_dump.c @@ -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); diff --git a/src/hci_transport.h b/src/hci_transport.h index 51538352f..16732e258 100644 --- a/src/hci_transport.h +++ b/src/hci_transport.h @@ -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 diff --git a/src/run_loop.h b/src/run_loop.h index 063bc6e64..112e424ef 100644 --- a/src/run_loop.h +++ b/src/run_loop.h @@ -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