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