mbed base bard check program for BlueTooth USB dongle module (3 switches, 6 leds, I2C LCD, A/D)
Fork of BTstack by
BTstack/run_loop.c@3:7b7d1273e2d5, 2016-10-17 (annotated)
- Committer:
- tamaki
- Date:
- Mon Oct 17 00:25:18 2016 +0000
- Revision:
- 3:7b7d1273e2d5
- Parent:
- 0:1ed23ab1345f
mbed base bard check program
; for BlueTooth USB dongle module
; (3 switches, 6 leds, I2C LCD, A/D)
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-2012 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 | * 4. Any redistribution, use, or modification is done solely for |
va009039 | 0:1ed23ab1345f | 17 | * personal benefit and not for any commercial purpose or for |
va009039 | 0:1ed23ab1345f | 18 | * monetary gain. |
va009039 | 0:1ed23ab1345f | 19 | * |
va009039 | 0:1ed23ab1345f | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
va009039 | 0:1ed23ab1345f | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
va009039 | 0:1ed23ab1345f | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
va009039 | 0:1ed23ab1345f | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
va009039 | 0:1ed23ab1345f | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
va009039 | 0:1ed23ab1345f | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
va009039 | 0:1ed23ab1345f | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
va009039 | 0:1ed23ab1345f | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
va009039 | 0:1ed23ab1345f | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
va009039 | 0:1ed23ab1345f | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
va009039 | 0:1ed23ab1345f | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
va009039 | 0:1ed23ab1345f | 31 | * SUCH DAMAGE. |
va009039 | 0:1ed23ab1345f | 32 | * |
va009039 | 0:1ed23ab1345f | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
va009039 | 0:1ed23ab1345f | 34 | * |
va009039 | 0:1ed23ab1345f | 35 | */ |
va009039 | 0:1ed23ab1345f | 36 | |
va009039 | 0:1ed23ab1345f | 37 | /* |
va009039 | 0:1ed23ab1345f | 38 | * run_loop.c |
va009039 | 0:1ed23ab1345f | 39 | * |
va009039 | 0:1ed23ab1345f | 40 | * Created by Matthias Ringwald on 6/6/09. |
va009039 | 0:1ed23ab1345f | 41 | */ |
va009039 | 0:1ed23ab1345f | 42 | |
va009039 | 0:1ed23ab1345f | 43 | #include <btstack/run_loop.h> |
va009039 | 0:1ed23ab1345f | 44 | |
va009039 | 0:1ed23ab1345f | 45 | #include <stdio.h> |
va009039 | 0:1ed23ab1345f | 46 | #include <stdlib.h> // exit() |
va009039 | 0:1ed23ab1345f | 47 | |
va009039 | 0:1ed23ab1345f | 48 | #include "run_loop_private.h" |
va009039 | 0:1ed23ab1345f | 49 | |
va009039 | 0:1ed23ab1345f | 50 | #include "debug.h" |
va009039 | 0:1ed23ab1345f | 51 | #include "config.h" |
va009039 | 0:1ed23ab1345f | 52 | |
va009039 | 0:1ed23ab1345f | 53 | static run_loop_t * the_run_loop = NULL; |
va009039 | 0:1ed23ab1345f | 54 | |
va009039 | 0:1ed23ab1345f | 55 | extern const run_loop_t run_loop_embedded; |
va009039 | 0:1ed23ab1345f | 56 | |
va009039 | 0:1ed23ab1345f | 57 | #ifdef USE_POSIX_RUN_LOOP |
va009039 | 0:1ed23ab1345f | 58 | extern run_loop_t run_loop_posix; |
va009039 | 0:1ed23ab1345f | 59 | #endif |
va009039 | 0:1ed23ab1345f | 60 | |
va009039 | 0:1ed23ab1345f | 61 | #ifdef USE_COCOA_RUN_LOOP |
va009039 | 0:1ed23ab1345f | 62 | extern run_loop_t run_loop_cocoa; |
va009039 | 0:1ed23ab1345f | 63 | #endif |
va009039 | 0:1ed23ab1345f | 64 | |
va009039 | 0:1ed23ab1345f | 65 | // assert run loop initialized |
va009039 | 0:1ed23ab1345f | 66 | void run_loop_assert(void){ |
va009039 | 0:1ed23ab1345f | 67 | #ifndef EMBEDDED |
va009039 | 0:1ed23ab1345f | 68 | if (!the_run_loop){ |
va009039 | 0:1ed23ab1345f | 69 | log_error("ERROR: run_loop function called before run_loop_init!\n"); |
va009039 | 0:1ed23ab1345f | 70 | exit(10); |
va009039 | 0:1ed23ab1345f | 71 | } |
va009039 | 0:1ed23ab1345f | 72 | #endif |
va009039 | 0:1ed23ab1345f | 73 | } |
va009039 | 0:1ed23ab1345f | 74 | |
va009039 | 0:1ed23ab1345f | 75 | /** |
va009039 | 0:1ed23ab1345f | 76 | * Add data_source to run_loop |
va009039 | 0:1ed23ab1345f | 77 | */ |
va009039 | 0:1ed23ab1345f | 78 | void run_loop_add_data_source(data_source_t *ds){ |
va009039 | 0:1ed23ab1345f | 79 | run_loop_assert(); |
va009039 | 0:1ed23ab1345f | 80 | the_run_loop->add_data_source(ds); |
va009039 | 0:1ed23ab1345f | 81 | } |
va009039 | 0:1ed23ab1345f | 82 | |
va009039 | 0:1ed23ab1345f | 83 | /** |
va009039 | 0:1ed23ab1345f | 84 | * Remove data_source from run loop |
va009039 | 0:1ed23ab1345f | 85 | */ |
va009039 | 0:1ed23ab1345f | 86 | int run_loop_remove_data_source(data_source_t *ds){ |
va009039 | 0:1ed23ab1345f | 87 | run_loop_assert(); |
va009039 | 0:1ed23ab1345f | 88 | return the_run_loop->remove_data_source(ds); |
va009039 | 0:1ed23ab1345f | 89 | } |
va009039 | 0:1ed23ab1345f | 90 | |
va009039 | 0:1ed23ab1345f | 91 | /** |
va009039 | 0:1ed23ab1345f | 92 | * Add timer to run_loop (keep list sorted) |
va009039 | 0:1ed23ab1345f | 93 | */ |
va009039 | 0:1ed23ab1345f | 94 | void run_loop_add_timer(timer_source_t *ts){ |
va009039 | 0:1ed23ab1345f | 95 | run_loop_assert(); |
va009039 | 0:1ed23ab1345f | 96 | the_run_loop->add_timer(ts); |
va009039 | 0:1ed23ab1345f | 97 | } |
va009039 | 0:1ed23ab1345f | 98 | |
va009039 | 0:1ed23ab1345f | 99 | /** |
va009039 | 0:1ed23ab1345f | 100 | * Remove timer from run loop |
va009039 | 0:1ed23ab1345f | 101 | */ |
va009039 | 0:1ed23ab1345f | 102 | int run_loop_remove_timer(timer_source_t *ts){ |
va009039 | 0:1ed23ab1345f | 103 | run_loop_assert(); |
va009039 | 0:1ed23ab1345f | 104 | return the_run_loop->remove_timer(ts); |
va009039 | 0:1ed23ab1345f | 105 | } |
va009039 | 0:1ed23ab1345f | 106 | |
va009039 | 0:1ed23ab1345f | 107 | void run_loop_timer_dump(){ |
va009039 | 0:1ed23ab1345f | 108 | run_loop_assert(); |
va009039 | 0:1ed23ab1345f | 109 | the_run_loop->dump_timer(); |
va009039 | 0:1ed23ab1345f | 110 | } |
va009039 | 0:1ed23ab1345f | 111 | |
va009039 | 0:1ed23ab1345f | 112 | /** |
va009039 | 0:1ed23ab1345f | 113 | * Execute run_loop |
va009039 | 0:1ed23ab1345f | 114 | */ |
va009039 | 0:1ed23ab1345f | 115 | void run_loop_execute() { |
va009039 | 0:1ed23ab1345f | 116 | run_loop_assert(); |
va009039 | 0:1ed23ab1345f | 117 | the_run_loop->execute(); |
va009039 | 0:1ed23ab1345f | 118 | } |
va009039 | 0:1ed23ab1345f | 119 | |
va009039 | 0:1ed23ab1345f | 120 | // init must be called before any other run_loop call |
va009039 | 0:1ed23ab1345f | 121 | void run_loop_init(RUN_LOOP_TYPE type){ |
va009039 | 0:1ed23ab1345f | 122 | #ifndef EMBEDDED |
va009039 | 0:1ed23ab1345f | 123 | if (the_run_loop){ |
va009039 | 0:1ed23ab1345f | 124 | log_error("ERROR: run loop initialized twice!\n"); |
va009039 | 0:1ed23ab1345f | 125 | exit(10); |
va009039 | 0:1ed23ab1345f | 126 | } |
va009039 | 0:1ed23ab1345f | 127 | #endif |
va009039 | 0:1ed23ab1345f | 128 | switch (type) { |
va009039 | 0:1ed23ab1345f | 129 | #ifdef EMBEDDED |
va009039 | 0:1ed23ab1345f | 130 | case RUN_LOOP_EMBEDDED: |
va009039 | 0:1ed23ab1345f | 131 | the_run_loop = (run_loop_t*) &run_loop_embedded; |
va009039 | 0:1ed23ab1345f | 132 | break; |
va009039 | 0:1ed23ab1345f | 133 | #endif |
va009039 | 0:1ed23ab1345f | 134 | #ifdef USE_POSIX_RUN_LOOP |
va009039 | 0:1ed23ab1345f | 135 | case RUN_LOOP_POSIX: |
va009039 | 0:1ed23ab1345f | 136 | the_run_loop = &run_loop_posix; |
va009039 | 0:1ed23ab1345f | 137 | break; |
va009039 | 0:1ed23ab1345f | 138 | #endif |
va009039 | 0:1ed23ab1345f | 139 | #ifdef USE_COCOA_RUN_LOOP |
va009039 | 0:1ed23ab1345f | 140 | case RUN_LOOP_COCOA: |
va009039 | 0:1ed23ab1345f | 141 | the_run_loop = &run_loop_cocoa; |
va009039 | 0:1ed23ab1345f | 142 | break; |
va009039 | 0:1ed23ab1345f | 143 | #endif |
va009039 | 0:1ed23ab1345f | 144 | default: |
va009039 | 0:1ed23ab1345f | 145 | #ifndef EMBEDDED |
va009039 | 0:1ed23ab1345f | 146 | log_error("ERROR: invalid run loop type %u selected!\n", type); |
va009039 | 0:1ed23ab1345f | 147 | exit(10); |
va009039 | 0:1ed23ab1345f | 148 | #endif |
va009039 | 0:1ed23ab1345f | 149 | break; |
va009039 | 0:1ed23ab1345f | 150 | } |
va009039 | 0:1ed23ab1345f | 151 | the_run_loop->init(); |
va009039 | 0:1ed23ab1345f | 152 | } |
va009039 | 0:1ed23ab1345f | 153 |