Skip to content

Commit

Permalink
FreeRTOS: btstack_run_loop_freertos_trigger_exit allows to request ru…
Browse files Browse the repository at this point in the history
…n loop exit

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
mringwal committed May 21, 2020
1 parent dc7f877 commit ab4f460
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- hfp_hf, hsp_hs: use eSCO params in accept sco connection only for incoming eSCO connections

### Added
- FreeRTOS: btstack_run_loop_freertos_trigger_exit allows to request run loop exit

### Changed
- L2CAP ERTM: send extended features request only once per HCI connection
Expand Down
10 changes: 10 additions & 0 deletions platform/freertos/btstack_run_loop_freertos.c
Expand Up @@ -105,6 +105,7 @@ static EventGroupHandle_t btstack_run_loop_event_group;
// the run loop
static btstack_linked_list_t timers;
static btstack_linked_list_t data_sources;
static bool run_loop_exit_requested;

static uint32_t btstack_run_loop_freertos_get_time_ms(void){
return hal_time_ms();
Expand Down Expand Up @@ -207,12 +208,18 @@ void btstack_run_loop_freertos_execute_code_on_main_thread_from_isr(void (*fn)(v
}
#endif

void btstack_run_loop_freertos_trigger_exit(void){
run_loop_exit_requested = true;
}

/**
* Execute run_loop
*/
static void btstack_run_loop_freertos_execute(void) {
log_debug("RL: execute");

run_loop_exit_requested = false;

while (true) {

// process data sources
Expand Down Expand Up @@ -253,6 +260,9 @@ static void btstack_run_loop_freertos_execute(void) {
ts->process(ts);
}

// exit triggered by btstack_run_loop_freertos_trigger_exit (from data source, timer, run on main thread)
if (run_loop_exit_requested) break;

// wait for timeout or event group/task notification
log_debug("RL: wait with timeout %u", (int) timeout_ms);
#ifdef HAVE_FREERTOS_TASK_NOTIFICATIONS
Expand Down
7 changes: 6 additions & 1 deletion platform/freertos/btstack_run_loop_freertos.h
Expand Up @@ -76,7 +76,12 @@ void btstack_run_loop_freertos_trigger(void);
* @brief Triggers processing of data sources from an ISR.
* Has to be called after enabling a poll data source to wake-pup run loop.
*/
void btstack_run_loop_freertos_trigger_from_isr(void);
void btstack_run_loop_freertos_trigger_from_isr(void);

/**
* @brief Triggers exit of run loop from BTstack main thread, causes call to btstack_run_loop_execute to return
*/
void btstack_run_loop_freertos_trigger_exit(void);

/* API_END */

Expand Down

0 comments on commit ab4f460

Please sign in to comment.