/**
 * Execute run_loop once
 */
void embedded_execute_once(void) {
    data_source_t *ds;

    // process data sources
    data_source_t *next;
    for (ds = (data_source_t *) data_sources; ds != NULL ; ds = next){
        next = (data_source_t *) ds->item.next; // cache pointer to next data_source to allow data source to remove itself
        ds->process(ds);
    }
    
#ifdef HAVE_TICK
    // process timers
    while (timers) {
        timer_source_t *ts = (timer_source_t *) timers;
        if (ts->timeout > system_ticks) break;
        run_loop_remove_timer(ts);
        ts->process(ts);
    }
#endif
    
    // disable IRQs and check if run loop iteration has been requested. if not, go to sleep
    hal_cpu_disable_irqs();
    if (trigger_event_received){
        trigger_event_received = 0;
        hal_cpu_enable_irqs();
    } else {
        hal_cpu_enable_irqs_and_sleep();
    }
}
Пример #2
0
/**
 * Execute run_loop
 */
void embedded_execute(void) {
    data_source_t *ds;

    while (1) {
        USBHostTasks();

        // process data sources
        data_source_t *next;
        for (ds = (data_source_t *) data_sources; ds != NULL ; ds = next){
            next = (data_source_t *) ds->item.next; // cache pointer to next data_source to allow data source to remove itself
            ds->process(ds);
        }

#ifdef HAVE_TICK
        // process timers
        while (timers) {
            timer_source_t *ts = (timer_source_t *) timers;
            if (ts->timeout > system_ticks) break;
            run_loop_remove_timer(ts);
            ts->process(ts);
        }
#endif

#if	USE_SPP_SERVER || USE_DUALSHOCK3_RUMBLE
		sendchar();
#endif

        // disable IRQs and check if run loop iteration has been requested. if not, go to sleep
#if	0
        hal_cpu_disable_irqs();
        if (trigger_event_received){
            hal_cpu_enable_irqs_and_sleep();
            continue;
        }
        hal_cpu_enable_irqs();
#else
		Idle();
#endif
#ifndef	__DEBUG
		if(!deviceAddress){
			Reset();
		}
#endif
    }
}
/**
 * Execute run_loop once
 */
void btstack_run_loop_embedded_execute_once(void) {
    btstack_data_source_t *ds;

    // process data sources
    btstack_data_source_t *next;
    for (ds = (btstack_data_source_t *) data_sources; ds != NULL ; ds = next){
        next = (btstack_data_source_t *) ds->item.next; // cache pointer to next data_source to allow data source to remove itself
        if (ds->flags & DATA_SOURCE_CALLBACK_POLL){
            ds->process(ds, DATA_SOURCE_CALLBACK_POLL);
        }
    }
    
#ifdef TIMER_SUPPORT

#ifdef HAVE_EMBEDDED_TICK
    uint32_t now = system_ticks;
#endif
#ifdef HAVE_EMBEDDED_TIME_MS
    uint32_t now = hal_time_ms();
#endif

    // process timers
    while (timers) {
        btstack_timer_source_t *ts = (btstack_timer_source_t *) timers;
        uint32_t timeout_low = ts->timeout;
        int      timeout_high = btstack_run_loop_embedded_reconstruct_higher_bits(now, timeout_low);
        if (timeout_high > 0 || ((timeout_high == 0) && (timeout_low > now))) break;
        btstack_run_loop_remove_timer(ts);
        ts->process(ts);
    }
#endif
    
    // disable IRQs and check if run loop iteration has been requested. if not, go to sleep
    hal_cpu_disable_irqs();
    if (trigger_event_received){
        trigger_event_received = 0;
        hal_cpu_enable_irqs();
    } else {
        hal_cpu_enable_irqs_and_sleep();
    }
}