2014-11-06 14:09:12 +00:00
% !TEX root = btstack_gettingstarted.tex
2015-04-09 15:11:48 +00:00
\section { Run Loop API}
2014-11-06 14:09:12 +00:00
\label { appendix:api_ run_ loop}
$ $
\begin { lstlisting}
2015-04-09 15:11:48 +00:00
/**
* @brief Set timer based on current time in milliseconds.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ set_ timer(timer_ source_ t *a, uint32_ t timeout_ in_ ms);
2015-04-09 15:11:48 +00:00
/**
* @brief Set callback that will be executed when timer expires.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ set_ timer_ handler(timer_ source_ t *ts, void (*process)(timer_ source_ t *_ ts));
2015-04-09 15:11:48 +00:00
/**
* @brief Add/Remove timer source.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ add_ timer(timer_ source_ t *timer);
int run_ loop_ remove_ timer(timer_ source_ t *timer);
2015-04-09 15:11:48 +00:00
/**
* @brief Init must be called before any other run_ loop call. Use RUN_ LOOP_ EMBEDDED for embedded devices.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ init(RUN_ LOOP_ TYPE type);
2015-04-09 15:11:48 +00:00
/**
* @brief Set data source callback.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ set_ data_ source_ handler(data_ source_ t *ds, int (*process)(data_ source_ t *_ ds));
2015-04-09 15:11:48 +00:00
/**
* @brief Add/Remove data source.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ add_ data_ source(data_ source_ t *dataSource);
int run_ loop_ remove_ data_ source(data_ source_ t *dataSource);
2015-04-09 15:11:48 +00:00
/**
* @brief Execute configured run loop. This function does not return.
*/
2014-11-06 14:09:12 +00:00
void run_ loop_ execute(void);
2015-04-09 12:49:03 +00:00
// hack to fix HCI timer handling
#ifdef HAVE_ TICK
2015-04-09 15:11:48 +00:00
/**
* @brief Sets how many milliseconds has one tick.
*/
2014-11-06 14:09:12 +00:00
uint32_ t embedded_ ticks_ for_ ms(uint32_ t time_ in_ ms);
2015-04-09 15:11:48 +00:00
/**
* @brief Queries the current time in ticks.
*/
2014-11-06 14:09:12 +00:00
uint32_ t embedded_ get_ ticks(void);
2015-04-09 15:11:48 +00:00
/**
* @brief Queries the current time in ms
*/
2015-04-09 12:49:03 +00:00
uint32_ t embedded_ get_ time_ ms(void);
2015-04-09 15:11:48 +00:00
/**
* @brief Allows to update BTstack system ticks based on another already existing clock.
*/
2015-04-09 12:49:03 +00:00
void embedded_ set_ ticks(uint32_ t ticks);
#endif
#ifdef EMBEDDED
2015-04-09 15:11:48 +00:00
/**
* @brief Sets an internal flag that is checked in the critical section just before entering sleep mode. Has to be called by the interrupt handler of a data source to signal the run loop that a new data is available.
*/
2015-04-09 12:49:03 +00:00
void embedded_ trigger(void);
2015-04-09 15:11:48 +00:00
/**
* @brief Execute run_ loop once. It can be used to integrate BTstack's timer and data source processing into a foreign run loop (it is not recommended).
*/
2015-04-09 12:49:03 +00:00
void embedded_ execute_ once(void);
#endif
2014-11-06 14:09:12 +00:00
\end { lstlisting}
2015-04-09 12:49:03 +00:00
\pagebreak