BTstack for Nucleo F401RE/FRDM-KL46Z example program
Dependencies: F401RE-USBHost mbed
The usage is the same as KL46Z-BTstack_example.
使い方はKL46Z-BTstack_exampleと同じです。
BTstack/run_loop.c@0:a05a07cd6fdf, 2014-06-09 (annotated)
- Committer:
- va009039
- Date:
- Mon Jun 09 09:03:25 2014 +0000
- Revision:
- 0:a05a07cd6fdf
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:a05a07cd6fdf | 1 | /* |
va009039 | 0:a05a07cd6fdf | 2 | * Copyright (C) 2009-2012 by Matthias Ringwald |
va009039 | 0:a05a07cd6fdf | 3 | * |
va009039 | 0:a05a07cd6fdf | 4 | * Redistribution and use in source and binary forms, with or without |
va009039 | 0:a05a07cd6fdf | 5 | * modification, are permitted provided that the following conditions |
va009039 | 0:a05a07cd6fdf | 6 | * are met: |
va009039 | 0:a05a07cd6fdf | 7 | * |
va009039 | 0:a05a07cd6fdf | 8 | * 1. Redistributions of source code must retain the above copyright |
va009039 | 0:a05a07cd6fdf | 9 | * notice, this list of conditions and the following disclaimer. |
va009039 | 0:a05a07cd6fdf | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
va009039 | 0:a05a07cd6fdf | 11 | * notice, this list of conditions and the following disclaimer in the |
va009039 | 0:a05a07cd6fdf | 12 | * documentation and/or other materials provided with the distribution. |
va009039 | 0:a05a07cd6fdf | 13 | * 3. Neither the name of the copyright holders nor the names of |
va009039 | 0:a05a07cd6fdf | 14 | * contributors may be used to endorse or promote products derived |
va009039 | 0:a05a07cd6fdf | 15 | * from this software without specific prior written permission. |
va009039 | 0:a05a07cd6fdf | 16 | * 4. Any redistribution, use, or modification is done solely for |
va009039 | 0:a05a07cd6fdf | 17 | * personal benefit and not for any commercial purpose or for |
va009039 | 0:a05a07cd6fdf | 18 | * monetary gain. |
va009039 | 0:a05a07cd6fdf | 19 | * |
va009039 | 0:a05a07cd6fdf | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
va009039 | 0:a05a07cd6fdf | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
va009039 | 0:a05a07cd6fdf | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
va009039 | 0:a05a07cd6fdf | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
va009039 | 0:a05a07cd6fdf | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
va009039 | 0:a05a07cd6fdf | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
va009039 | 0:a05a07cd6fdf | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
va009039 | 0:a05a07cd6fdf | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
va009039 | 0:a05a07cd6fdf | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
va009039 | 0:a05a07cd6fdf | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
va009039 | 0:a05a07cd6fdf | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
va009039 | 0:a05a07cd6fdf | 31 | * SUCH DAMAGE. |
va009039 | 0:a05a07cd6fdf | 32 | * |
va009039 | 0:a05a07cd6fdf | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
va009039 | 0:a05a07cd6fdf | 34 | * |
va009039 | 0:a05a07cd6fdf | 35 | */ |
va009039 | 0:a05a07cd6fdf | 36 | |
va009039 | 0:a05a07cd6fdf | 37 | /* |
va009039 | 0:a05a07cd6fdf | 38 | * run_loop.c |
va009039 | 0:a05a07cd6fdf | 39 | * |
va009039 | 0:a05a07cd6fdf | 40 | * Created by Matthias Ringwald on 6/6/09. |
va009039 | 0:a05a07cd6fdf | 41 | */ |
va009039 | 0:a05a07cd6fdf | 42 | |
va009039 | 0:a05a07cd6fdf | 43 | #include <btstack/run_loop.h> |
va009039 | 0:a05a07cd6fdf | 44 | |
va009039 | 0:a05a07cd6fdf | 45 | #include <stdio.h> |
va009039 | 0:a05a07cd6fdf | 46 | #include <stdlib.h> // exit() |
va009039 | 0:a05a07cd6fdf | 47 | |
va009039 | 0:a05a07cd6fdf | 48 | #include "run_loop_private.h" |
va009039 | 0:a05a07cd6fdf | 49 | |
va009039 | 0:a05a07cd6fdf | 50 | #include "debug.h" |
va009039 | 0:a05a07cd6fdf | 51 | #include "config.h" |
va009039 | 0:a05a07cd6fdf | 52 | |
va009039 | 0:a05a07cd6fdf | 53 | static run_loop_t * the_run_loop = NULL; |
va009039 | 0:a05a07cd6fdf | 54 | |
va009039 | 0:a05a07cd6fdf | 55 | extern const run_loop_t run_loop_embedded; |
va009039 | 0:a05a07cd6fdf | 56 | |
va009039 | 0:a05a07cd6fdf | 57 | #ifdef USE_POSIX_RUN_LOOP |
va009039 | 0:a05a07cd6fdf | 58 | extern run_loop_t run_loop_posix; |
va009039 | 0:a05a07cd6fdf | 59 | #endif |
va009039 | 0:a05a07cd6fdf | 60 | |
va009039 | 0:a05a07cd6fdf | 61 | #ifdef USE_COCOA_RUN_LOOP |
va009039 | 0:a05a07cd6fdf | 62 | extern run_loop_t run_loop_cocoa; |
va009039 | 0:a05a07cd6fdf | 63 | #endif |
va009039 | 0:a05a07cd6fdf | 64 | |
va009039 | 0:a05a07cd6fdf | 65 | // assert run loop initialized |
va009039 | 0:a05a07cd6fdf | 66 | void run_loop_assert(void){ |
va009039 | 0:a05a07cd6fdf | 67 | #ifndef EMBEDDED |
va009039 | 0:a05a07cd6fdf | 68 | if (!the_run_loop){ |
va009039 | 0:a05a07cd6fdf | 69 | log_error("ERROR: run_loop function called before run_loop_init!\n"); |
va009039 | 0:a05a07cd6fdf | 70 | exit(10); |
va009039 | 0:a05a07cd6fdf | 71 | } |
va009039 | 0:a05a07cd6fdf | 72 | #endif |
va009039 | 0:a05a07cd6fdf | 73 | } |
va009039 | 0:a05a07cd6fdf | 74 | |
va009039 | 0:a05a07cd6fdf | 75 | /** |
va009039 | 0:a05a07cd6fdf | 76 | * Add data_source to run_loop |
va009039 | 0:a05a07cd6fdf | 77 | */ |
va009039 | 0:a05a07cd6fdf | 78 | void run_loop_add_data_source(data_source_t *ds){ |
va009039 | 0:a05a07cd6fdf | 79 | run_loop_assert(); |
va009039 | 0:a05a07cd6fdf | 80 | the_run_loop->add_data_source(ds); |
va009039 | 0:a05a07cd6fdf | 81 | } |
va009039 | 0:a05a07cd6fdf | 82 | |
va009039 | 0:a05a07cd6fdf | 83 | /** |
va009039 | 0:a05a07cd6fdf | 84 | * Remove data_source from run loop |
va009039 | 0:a05a07cd6fdf | 85 | */ |
va009039 | 0:a05a07cd6fdf | 86 | int run_loop_remove_data_source(data_source_t *ds){ |
va009039 | 0:a05a07cd6fdf | 87 | run_loop_assert(); |
va009039 | 0:a05a07cd6fdf | 88 | return the_run_loop->remove_data_source(ds); |
va009039 | 0:a05a07cd6fdf | 89 | } |
va009039 | 0:a05a07cd6fdf | 90 | |
va009039 | 0:a05a07cd6fdf | 91 | /** |
va009039 | 0:a05a07cd6fdf | 92 | * Add timer to run_loop (keep list sorted) |
va009039 | 0:a05a07cd6fdf | 93 | */ |
va009039 | 0:a05a07cd6fdf | 94 | void run_loop_add_timer(timer_source_t *ts){ |
va009039 | 0:a05a07cd6fdf | 95 | run_loop_assert(); |
va009039 | 0:a05a07cd6fdf | 96 | the_run_loop->add_timer(ts); |
va009039 | 0:a05a07cd6fdf | 97 | } |
va009039 | 0:a05a07cd6fdf | 98 | |
va009039 | 0:a05a07cd6fdf | 99 | /** |
va009039 | 0:a05a07cd6fdf | 100 | * Remove timer from run loop |
va009039 | 0:a05a07cd6fdf | 101 | */ |
va009039 | 0:a05a07cd6fdf | 102 | int run_loop_remove_timer(timer_source_t *ts){ |
va009039 | 0:a05a07cd6fdf | 103 | run_loop_assert(); |
va009039 | 0:a05a07cd6fdf | 104 | return the_run_loop->remove_timer(ts); |
va009039 | 0:a05a07cd6fdf | 105 | } |
va009039 | 0:a05a07cd6fdf | 106 | |
va009039 | 0:a05a07cd6fdf | 107 | void run_loop_timer_dump(){ |
va009039 | 0:a05a07cd6fdf | 108 | run_loop_assert(); |
va009039 | 0:a05a07cd6fdf | 109 | the_run_loop->dump_timer(); |
va009039 | 0:a05a07cd6fdf | 110 | } |
va009039 | 0:a05a07cd6fdf | 111 | |
va009039 | 0:a05a07cd6fdf | 112 | /** |
va009039 | 0:a05a07cd6fdf | 113 | * Execute run_loop |
va009039 | 0:a05a07cd6fdf | 114 | */ |
va009039 | 0:a05a07cd6fdf | 115 | void run_loop_execute() { |
va009039 | 0:a05a07cd6fdf | 116 | run_loop_assert(); |
va009039 | 0:a05a07cd6fdf | 117 | the_run_loop->execute(); |
va009039 | 0:a05a07cd6fdf | 118 | } |
va009039 | 0:a05a07cd6fdf | 119 | |
va009039 | 0:a05a07cd6fdf | 120 | // init must be called before any other run_loop call |
va009039 | 0:a05a07cd6fdf | 121 | void run_loop_init(RUN_LOOP_TYPE type){ |
va009039 | 0:a05a07cd6fdf | 122 | #ifndef EMBEDDED |
va009039 | 0:a05a07cd6fdf | 123 | if (the_run_loop){ |
va009039 | 0:a05a07cd6fdf | 124 | log_error("ERROR: run loop initialized twice!\n"); |
va009039 | 0:a05a07cd6fdf | 125 | exit(10); |
va009039 | 0:a05a07cd6fdf | 126 | } |
va009039 | 0:a05a07cd6fdf | 127 | #endif |
va009039 | 0:a05a07cd6fdf | 128 | switch (type) { |
va009039 | 0:a05a07cd6fdf | 129 | #ifdef EMBEDDED |
va009039 | 0:a05a07cd6fdf | 130 | case RUN_LOOP_EMBEDDED: |
va009039 | 0:a05a07cd6fdf | 131 | the_run_loop = (run_loop_t*) &run_loop_embedded; |
va009039 | 0:a05a07cd6fdf | 132 | break; |
va009039 | 0:a05a07cd6fdf | 133 | #endif |
va009039 | 0:a05a07cd6fdf | 134 | #ifdef USE_POSIX_RUN_LOOP |
va009039 | 0:a05a07cd6fdf | 135 | case RUN_LOOP_POSIX: |
va009039 | 0:a05a07cd6fdf | 136 | the_run_loop = &run_loop_posix; |
va009039 | 0:a05a07cd6fdf | 137 | break; |
va009039 | 0:a05a07cd6fdf | 138 | #endif |
va009039 | 0:a05a07cd6fdf | 139 | #ifdef USE_COCOA_RUN_LOOP |
va009039 | 0:a05a07cd6fdf | 140 | case RUN_LOOP_COCOA: |
va009039 | 0:a05a07cd6fdf | 141 | the_run_loop = &run_loop_cocoa; |
va009039 | 0:a05a07cd6fdf | 142 | break; |
va009039 | 0:a05a07cd6fdf | 143 | #endif |
va009039 | 0:a05a07cd6fdf | 144 | default: |
va009039 | 0:a05a07cd6fdf | 145 | #ifndef EMBEDDED |
va009039 | 0:a05a07cd6fdf | 146 | log_error("ERROR: invalid run loop type %u selected!\n", type); |
va009039 | 0:a05a07cd6fdf | 147 | exit(10); |
va009039 | 0:a05a07cd6fdf | 148 | #endif |
va009039 | 0:a05a07cd6fdf | 149 | break; |
va009039 | 0:a05a07cd6fdf | 150 | } |
va009039 | 0:a05a07cd6fdf | 151 | the_run_loop->init(); |
va009039 | 0:a05a07cd6fdf | 152 | } |
va009039 | 0:a05a07cd6fdf | 153 |