mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-09 21:45:54 +00:00
implement sleep mode
This commit is contained in:
parent
e96f52b81b
commit
ccf81f4c49
@ -50,6 +50,7 @@
|
|||||||
#include <btstack/run_loop.h>
|
#include <btstack/run_loop.h>
|
||||||
#include <btstack/linked_list.h>
|
#include <btstack/linked_list.h>
|
||||||
#include <btstack/hal_tick.h>
|
#include <btstack/hal_tick.h>
|
||||||
|
#include <btstack/hal_cpu.h>
|
||||||
|
|
||||||
#include "run_loop_private.h"
|
#include "run_loop_private.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -64,6 +65,15 @@ static linked_list_t timers;
|
|||||||
static uint32_t system_ticks;
|
static uint32_t system_ticks;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int trigger_event_received = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* trigger run loop iteration
|
||||||
|
*/
|
||||||
|
void embedded_trigger(void){
|
||||||
|
trigger_event_received = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add data_source to run_loop
|
* Add data_source to run_loop
|
||||||
*/
|
*/
|
||||||
@ -109,7 +119,7 @@ int embedded_remove_timer(timer_source_t *ts){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void embedded_dump_timer(){
|
void embedded_dump_timer(){
|
||||||
#if 0
|
#ifdef ENABLE_LOG_INFO
|
||||||
linked_item_t *it;
|
linked_item_t *it;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (it = (linked_item_t *) timers; it ; it = it->next){
|
for (it = (linked_item_t *) timers; it ; it = it->next){
|
||||||
@ -143,13 +153,21 @@ void embedded_execute() {
|
|||||||
ts->process(ts);
|
ts->process(ts);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// race condition.. poll data source, IRQ occurs -> data source gets ready -> IDLE hook makes MCU sleep?
|
|
||||||
|
// disable IRQs and check if run loop iteration has been requested. if not, go to sleep
|
||||||
|
hal_cpu_disable_irqs();
|
||||||
|
if (trigger_event_received){
|
||||||
|
hal_cpu_enable_irqs_and_sleep();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hal_cpu_enable_irqs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TICK
|
#ifdef HAVE_TICK
|
||||||
static void embedded_tick_handler(void){
|
static void embedded_tick_handler(void){
|
||||||
system_ticks++;
|
system_ticks++;
|
||||||
|
trigger_event_received = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t embedded_get_ticks(void){
|
uint32_t embedded_get_ticks(void){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user