xref: /btstack/platform/embedded/btstack_run_loop_embedded.h (revision b7d596c10400c99fd8b20da2d70dfd98f9886e1b)
1*b7d596c1SMatthias Ringwald /*
2*b7d596c1SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3*b7d596c1SMatthias Ringwald  *
4*b7d596c1SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*b7d596c1SMatthias Ringwald  * modification, are permitted provided that the following conditions
6*b7d596c1SMatthias Ringwald  * are met:
7*b7d596c1SMatthias Ringwald  *
8*b7d596c1SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*b7d596c1SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*b7d596c1SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*b7d596c1SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*b7d596c1SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*b7d596c1SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*b7d596c1SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*b7d596c1SMatthias Ringwald  *    from this software without specific prior written permission.
16*b7d596c1SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*b7d596c1SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18*b7d596c1SMatthias Ringwald  *    monetary gain.
19*b7d596c1SMatthias Ringwald  *
20*b7d596c1SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*b7d596c1SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*b7d596c1SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*b7d596c1SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24*b7d596c1SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*b7d596c1SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*b7d596c1SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*b7d596c1SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*b7d596c1SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*b7d596c1SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*b7d596c1SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*b7d596c1SMatthias Ringwald  * SUCH DAMAGE.
32*b7d596c1SMatthias Ringwald  *
33*b7d596c1SMatthias Ringwald  * Please inquire about commercial licensing options at
34*b7d596c1SMatthias Ringwald  * [email protected]
35*b7d596c1SMatthias Ringwald  *
36*b7d596c1SMatthias Ringwald  */
37*b7d596c1SMatthias Ringwald 
38*b7d596c1SMatthias Ringwald /*
39*b7d596c1SMatthias Ringwald  *  run_loop_embedded.h
40*b7d596c1SMatthias Ringwald  *  Functionality special to the embedded run loop
41*b7d596c1SMatthias Ringwald  */
42*b7d596c1SMatthias Ringwald 
43*b7d596c1SMatthias Ringwald #ifndef __RUN_LOOP_EMBEDDED_H
44*b7d596c1SMatthias Ringwald #define __RUN_LOOP_EMBEDDED_H
45*b7d596c1SMatthias Ringwald 
46*b7d596c1SMatthias Ringwald #include "btstack-config.h"
47*b7d596c1SMatthias Ringwald #include "btstack_linked_list.h"
48*b7d596c1SMatthias Ringwald 
49*b7d596c1SMatthias Ringwald #ifdef HAVE_TIME
50*b7d596c1SMatthias Ringwald #include <sys/time.h>
51*b7d596c1SMatthias Ringwald #endif
52*b7d596c1SMatthias Ringwald #include <stdint.h>
53*b7d596c1SMatthias Ringwald 
54*b7d596c1SMatthias Ringwald #if defined __cplusplus
55*b7d596c1SMatthias Ringwald extern "C" {
56*b7d596c1SMatthias Ringwald #endif
57*b7d596c1SMatthias Ringwald 
58*b7d596c1SMatthias Ringwald /**
59*b7d596c1SMatthias Ringwald  * Provide run_loop_embedded instance
60*b7d596c1SMatthias Ringwald  */
61*b7d596c1SMatthias Ringwald const run_loop_t * run_loop_embedded_get_instance(void);
62*b7d596c1SMatthias Ringwald 
63*b7d596c1SMatthias Ringwald // hack to fix HCI timer handling
64*b7d596c1SMatthias Ringwald #ifdef HAVE_TICK
65*b7d596c1SMatthias Ringwald /**
66*b7d596c1SMatthias Ringwald  * @brief Sets how many milliseconds has one tick.
67*b7d596c1SMatthias Ringwald  */
68*b7d596c1SMatthias Ringwald uint32_t run_loop_embedded_ticks_for_ms(uint32_t time_in_ms);
69*b7d596c1SMatthias Ringwald /**
70*b7d596c1SMatthias Ringwald  * @brief Queries the current time in ticks.
71*b7d596c1SMatthias Ringwald  */
72*b7d596c1SMatthias Ringwald uint32_t run_loop_embedded_get_ticks(void);
73*b7d596c1SMatthias Ringwald #endif
74*b7d596c1SMatthias Ringwald 
75*b7d596c1SMatthias Ringwald #ifdef EMBEDDED
76*b7d596c1SMatthias Ringwald /**
77*b7d596c1SMatthias Ringwald  * @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.
78*b7d596c1SMatthias Ringwald  */
79*b7d596c1SMatthias Ringwald void run_loop_embedded_trigger(void);
80*b7d596c1SMatthias Ringwald /**
81*b7d596c1SMatthias Ringwald  * @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).
82*b7d596c1SMatthias Ringwald  */
83*b7d596c1SMatthias Ringwald void run_loop_embedded_execute_once(void);
84*b7d596c1SMatthias Ringwald #endif
85*b7d596c1SMatthias Ringwald 
86*b7d596c1SMatthias Ringwald /* API_END */
87*b7d596c1SMatthias Ringwald 
88*b7d596c1SMatthias Ringwald #if defined __cplusplus
89*b7d596c1SMatthias Ringwald }
90*b7d596c1SMatthias Ringwald #endif
91*b7d596c1SMatthias Ringwald 
92*b7d596c1SMatthias Ringwald #endif // __RUN_LOOP_EMBEDDED_H
93