Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystem TB6612FNG2 mbed
BTstack/btstack/run_loop.h@0:de03cbbcd0ff, 2015-11-30 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Mon Nov 30 09:32:15 2015 +0000
- Revision:
- 0:de03cbbcd0ff
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 1 | /* | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | * Copyright (C) 2009 by Matthias Ringwald | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | * | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | * Redistribution and use in source and binary forms, with or without | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | * modification, are permitted provided that the following conditions | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | * are met: | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | * | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | * 1. Redistributions of source code must retain the above copyright | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | * notice, this list of conditions and the following disclaimer. | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | * 2. Redistributions in binary form must reproduce the above copyright | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | * notice, this list of conditions and the following disclaimer in the | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | * documentation and/or other materials provided with the distribution. | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | * 3. Neither the name of the copyright holders nor the names of | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | * contributors may be used to endorse or promote products derived | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | * from this software without specific prior written permission. | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | * | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | * SUCH DAMAGE. | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | * | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | */ | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | /* | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | * run_loop.h | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | * | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | * Created by Matthias Ringwald on 6/6/09. | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | */ | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | #pragma once | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | #include "config.h" | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | #include "btstack/linked_list.h" | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | #include <stdint.h> | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | #ifdef HAVE_TIME | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | #include <sys/time.h> | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | #if defined __cplusplus | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | extern "C" { | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 52 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 53 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 54 | typedef enum { | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 55 | RUN_LOOP_POSIX = 1, | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 56 | RUN_LOOP_COCOA, | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 57 | RUN_LOOP_EMBEDDED | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 58 | } RUN_LOOP_TYPE; | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 59 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 60 | typedef struct data_source { | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 61 | linked_item_t item; | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 62 | int fd; // <-- file descriptor to watch or 0 | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 63 | int (*process)(struct data_source *ds); // <-- do processing | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 64 | } data_source_t; | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 65 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 66 | typedef struct timer { | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 67 | linked_item_t item; | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 68 | #ifdef HAVE_TIME | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 69 | struct timeval timeout; // <-- next timeout | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 70 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 71 | #ifdef HAVE_TICK | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 72 | uint32_t timeout; // timeout in system ticks | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 73 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 74 | void (*process)(struct timer *ts); // <-- do processing | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 75 | } timer_source_t; | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 76 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 77 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 78 | // set timer based on current time | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 79 | void run_loop_set_timer(timer_source_t *a, uint32_t timeout_in_ms); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 80 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 81 | // add/remove timer_source | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 82 | void run_loop_add_timer(timer_source_t *timer); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 83 | int run_loop_remove_timer(timer_source_t *timer); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 84 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 85 | // init must be called before any other run_loop call | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 86 | void run_loop_init(RUN_LOOP_TYPE type); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 87 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 88 | // add/remove data_source | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 89 | void run_loop_add_data_source(data_source_t *dataSource); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 90 | int run_loop_remove_data_source(data_source_t *dataSource); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 91 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 92 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 93 | // execute configured run_loop | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 94 | void run_loop_execute(void); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 95 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 96 | // hack to fix HCI timer handling | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 97 | #ifdef HAVE_TICK | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 98 | uint32_t embedded_get_ticks(void); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 99 | uint32_t embedded_ticks_for_ms(uint32_t time_in_ms); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 100 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 101 | #ifdef EMBEDDED | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 102 | void embedded_trigger(void); | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 103 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 104 | #if defined __cplusplus | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 105 | } | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 106 | #endif | 
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 107 |