Power-efficient crank
This commit is contained in:
Родитель
231f3cae39
Коммит
9f1da7c39f
|
@ -27,6 +27,7 @@ static void update(srv_t *state) {
|
|||
static void maybe_init(srv_t *state) {
|
||||
if (state->is_streaming && !state->inited) {
|
||||
state->inited = true;
|
||||
tim_max_sleep = 1000;
|
||||
pin_setup_input(state->pin0, 1);
|
||||
pin_setup_input(state->pin1, 1);
|
||||
update(state);
|
||||
|
@ -36,7 +37,7 @@ static void maybe_init(srv_t *state) {
|
|||
void crank_process(srv_t *state) {
|
||||
maybe_init(state);
|
||||
|
||||
if (should_sample(&state->nextSample, 997) && state->inited)
|
||||
if (should_sample(&state->nextSample, 950) && state->inited)
|
||||
update(state);
|
||||
|
||||
sensor_process_simple(state, &state->sample, sizeof(state->sample));
|
||||
|
|
|
@ -39,3 +39,4 @@ void target_wait_cycles(int n);
|
|||
int target_in_irq(void);
|
||||
|
||||
extern uint8_t cpu_mhz;
|
||||
extern uint16_t tim_max_sleep;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
static volatile uint64_t timeoff;
|
||||
static volatile cb_t timer_cb;
|
||||
|
||||
uint16_t tim_max_sleep;
|
||||
|
||||
// takes around 1us
|
||||
uint64_t tim_get_micros() {
|
||||
while (1) {
|
||||
|
@ -42,6 +44,9 @@ void tim_set_timer(int delta, cb_t cb) {
|
|||
if (delta < 10)
|
||||
delta = 10;
|
||||
|
||||
if (tim_max_sleep && delta == 10000)
|
||||
delta = tim_max_sleep;
|
||||
|
||||
rtc_cancel_cb();
|
||||
target_disable_irq();
|
||||
timer_cb = cb;
|
||||
|
|
Загрузка…
Ссылка в новой задаче