void GKI_run (void *p_task_id) { struct timespec delay; int err; volatile int * p_run_cond = &gki_cb.os.no_timer_suspend; #ifndef GKI_NO_TICK_STOP /* adjust btld scheduling scheme now */ gki_set_timer_scheduling(); /* register start stop function which disable timer loop in GKI_run() when no timers are * in any GKI/BTA/BTU this should save power when BTLD is idle! */ GKI_timer_queue_register_callback( gki_system_tick_start_stop_cback ); GKI_TRACE( "GKI_run(): Start/Stop GKI_timer_update_registered!" ); #endif #ifdef NO_GKI_RUN_RETURN pthread_attr_t timer_attr; shutdown_timer = 0; pthread_attr_init(&timer_attr); if (pthread_create( &timer_thread_id, &timer_attr, timer_thread, NULL) != 0 ) { GKI_ERROR_LOG("pthread_create failed to create timer_thread!\n\r"); return; } #else GKI_TRACE("GKI_run "); for (;;) { do { /* adjust hear bit tick in btld by changning TICKS_PER_SEC!!!!! this formula works only for * 1-1000ms heart beat units! */ delay.tv_sec = LINUX_SEC / 1000; delay.tv_nsec = 1000 * 1000 * (LINUX_SEC % 1000); /* [u]sleep can't be used because it uses SIGALRM */ do { err = nanosleep(&delay, &delay); } while (err < 0 && errno == EINTR); /* the unit should be alsways 1 (1 tick). only if you vary for some reason heart beat tick * e.g. power saving you may want to provide more ticks */ GKI_timer_update( 1 ); /* BT_TRACE_2( TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, "update: tv_sec: %d, tv_nsec: %d", delay.tv_sec, delay.tv_nsec ); */ } while ( GKI_TIMER_TICK_RUN_COND == *p_run_cond ); /* currently on reason to exit above loop is no_timer_suspend == GKI_TIMER_TICK_STOP_COND * block timer main thread till re-armed by */ GKI_TIMER_TRACE(">>> SUSPENDED GKI_timer_update()" ); pthread_mutex_lock( &gki_cb.os.gki_timer_mutex ); pthread_cond_wait( &gki_cb.os.gki_timer_cond, &gki_cb.os.gki_timer_mutex ); pthread_mutex_unlock( &gki_cb.os.gki_timer_mutex ); /* potentially we need to adjust os gki_cb.com.OSTicks */ GKI_TIMER_TRACE(">>> RESTARTED GKI_timer_update(): run_cond: %d", *p_run_cond ); } #endif return; }
void GKI_run(void) { /* adjust btld scheduling scheme now */ gki_set_timer_scheduling(); GKI_TRACE( "GKI_run(): Start/Stop GKI_timer_update_registered!" ); }