Skip to content

Commit

Permalink
option to leave the radion::run() function when an interrupt occured
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenRobitzki committed Sep 4, 2023
1 parent c98229f commit 05256c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions bluetoe/bindings/nordic/include/bluetoe/nrf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace bluetoe
struct radio_option_meta_type : ::bluetoe::details::binding_option_meta_type {};
struct sleep_clock_source_meta_type : radio_option_meta_type {};
struct hfxo_startup_time_meta_type : radio_option_meta_type {};
struct leave_run_on_interrupt_type : radio_option_meta_type {};

static void start_high_frequency_clock()
{
Expand Down Expand Up @@ -213,6 +214,19 @@ namespace bluetoe
* @sa bluetoe::nrf::high_frequency_crystal_oscillator_startup_time
*/
using high_frequency_crystal_oscillator_startup_time_default = high_frequency_crystal_oscillator_startup_time< 300 >;

/**
* @brief configures the radio::run() function to return on every interrupt
*
* Usually, run() will return on a call to radio::wake(). With this option, run()
* will only block for a single call to the WFI ARM assembler instruction. Once that
* instruction returns, the function will be left.
*/
struct leave_run_on_interrupt {
/** @cond HIDDEN_SYMBOLS */
using meta_type = nrf_details::leave_run_on_interrupt_type;
/** @endcond */
};
}

namespace nrf_details
Expand Down
6 changes: 5 additions & 1 deletion bluetoe/bindings/nordic/nrf52/include/bluetoe/nrf52.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ namespace bluetoe

void run()
{
while ( !adv_received_ && !adv_timeout_ && !evt_timeout_ && !end_evt_ && wake_up_ == 0 )
static constexpr bool single_wfi = bluetoe::details::has_option<
nrf::leave_run_on_interrupt, RadioOptions... >::value;

while ( !single_wfi && !adv_received_ && !adv_timeout_ && !evt_timeout_ && !end_evt_ && wake_up_ == 0 )
__WFI();

// For every event, but the wakeup request, the radio should be in an idle state
Expand Down Expand Up @@ -971,6 +974,7 @@ namespace bluetoe
* bluetoe::nrf::sleep_clock_crystal_oscillator
* bluetoe::nrf::calibrated_sleep_clock
* bluetoe::nrf::synthesized_sleep_clock
* bluetoe::nrf::leave_run_on_interrupt
*/
template < class Server, typename ... Options >
using nrf52 = typename nrf52_details::link_layer_factory<
Expand Down

0 comments on commit 05256c4

Please sign in to comment.