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