mbed library sources with internal temperature sensor for nucleo f401
api/CallChain.h@0:7e2bd16f80af, 2015-01-17 (annotated)
- Committer:
- elessair
- Date:
- Sat Jan 17 18:03:58 2015 +0000
- Revision:
- 0:7e2bd16f80af
nucleo f401re internal temperature added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:7e2bd16f80af | 1 | /* mbed Microcontroller Library |
elessair | 0:7e2bd16f80af | 2 | * Copyright (c) 2006-2013 ARM Limited |
elessair | 0:7e2bd16f80af | 3 | * |
elessair | 0:7e2bd16f80af | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:7e2bd16f80af | 5 | * you may not use this file except in compliance with the License. |
elessair | 0:7e2bd16f80af | 6 | * You may obtain a copy of the License at |
elessair | 0:7e2bd16f80af | 7 | * |
elessair | 0:7e2bd16f80af | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:7e2bd16f80af | 9 | * |
elessair | 0:7e2bd16f80af | 10 | * Unless required by applicable law or agreed to in writing, software |
elessair | 0:7e2bd16f80af | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:7e2bd16f80af | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:7e2bd16f80af | 13 | * See the License for the specific language governing permissions and |
elessair | 0:7e2bd16f80af | 14 | * limitations under the License. |
elessair | 0:7e2bd16f80af | 15 | */ |
elessair | 0:7e2bd16f80af | 16 | #ifndef MBED_CALLCHAIN_H |
elessair | 0:7e2bd16f80af | 17 | #define MBED_CALLCHAIN_H |
elessair | 0:7e2bd16f80af | 18 | |
elessair | 0:7e2bd16f80af | 19 | #include "FunctionPointer.h" |
elessair | 0:7e2bd16f80af | 20 | #include <string.h> |
elessair | 0:7e2bd16f80af | 21 | |
elessair | 0:7e2bd16f80af | 22 | namespace mbed { |
elessair | 0:7e2bd16f80af | 23 | |
elessair | 0:7e2bd16f80af | 24 | /** Group one or more functions in an instance of a CallChain, then call them in |
elessair | 0:7e2bd16f80af | 25 | * sequence using CallChain::call(). Used mostly by the interrupt chaining code, |
elessair | 0:7e2bd16f80af | 26 | * but can be used for other purposes. |
elessair | 0:7e2bd16f80af | 27 | * |
elessair | 0:7e2bd16f80af | 28 | * Example: |
elessair | 0:7e2bd16f80af | 29 | * @code |
elessair | 0:7e2bd16f80af | 30 | * #include "mbed.h" |
elessair | 0:7e2bd16f80af | 31 | * |
elessair | 0:7e2bd16f80af | 32 | * CallChain chain; |
elessair | 0:7e2bd16f80af | 33 | * |
elessair | 0:7e2bd16f80af | 34 | * void first(void) { |
elessair | 0:7e2bd16f80af | 35 | * printf("'first' function.\n"); |
elessair | 0:7e2bd16f80af | 36 | * } |
elessair | 0:7e2bd16f80af | 37 | * |
elessair | 0:7e2bd16f80af | 38 | * void second(void) { |
elessair | 0:7e2bd16f80af | 39 | * printf("'second' function.\n"); |
elessair | 0:7e2bd16f80af | 40 | * } |
elessair | 0:7e2bd16f80af | 41 | * |
elessair | 0:7e2bd16f80af | 42 | * class Test { |
elessair | 0:7e2bd16f80af | 43 | * public: |
elessair | 0:7e2bd16f80af | 44 | * void f(void) { |
elessair | 0:7e2bd16f80af | 45 | * printf("A::f (class member).\n"); |
elessair | 0:7e2bd16f80af | 46 | * } |
elessair | 0:7e2bd16f80af | 47 | * }; |
elessair | 0:7e2bd16f80af | 48 | * |
elessair | 0:7e2bd16f80af | 49 | * int main() { |
elessair | 0:7e2bd16f80af | 50 | * Test test; |
elessair | 0:7e2bd16f80af | 51 | * |
elessair | 0:7e2bd16f80af | 52 | * chain.add(second); |
elessair | 0:7e2bd16f80af | 53 | * chain.add_front(first); |
elessair | 0:7e2bd16f80af | 54 | * chain.add(&test, &Test::f); |
elessair | 0:7e2bd16f80af | 55 | * chain.call(); |
elessair | 0:7e2bd16f80af | 56 | * } |
elessair | 0:7e2bd16f80af | 57 | * @endcode |
elessair | 0:7e2bd16f80af | 58 | */ |
elessair | 0:7e2bd16f80af | 59 | |
elessair | 0:7e2bd16f80af | 60 | typedef FunctionPointer* pFunctionPointer_t; |
elessair | 0:7e2bd16f80af | 61 | |
elessair | 0:7e2bd16f80af | 62 | class CallChain { |
elessair | 0:7e2bd16f80af | 63 | public: |
elessair | 0:7e2bd16f80af | 64 | /** Create an empty chain |
elessair | 0:7e2bd16f80af | 65 | * |
elessair | 0:7e2bd16f80af | 66 | * @param size (optional) Initial size of the chain |
elessair | 0:7e2bd16f80af | 67 | */ |
elessair | 0:7e2bd16f80af | 68 | CallChain(int size = 4); |
elessair | 0:7e2bd16f80af | 69 | virtual ~CallChain(); |
elessair | 0:7e2bd16f80af | 70 | |
elessair | 0:7e2bd16f80af | 71 | /** Add a function at the end of the chain |
elessair | 0:7e2bd16f80af | 72 | * |
elessair | 0:7e2bd16f80af | 73 | * @param function A pointer to a void function |
elessair | 0:7e2bd16f80af | 74 | * |
elessair | 0:7e2bd16f80af | 75 | * @returns |
elessair | 0:7e2bd16f80af | 76 | * The function object created for 'function' |
elessair | 0:7e2bd16f80af | 77 | */ |
elessair | 0:7e2bd16f80af | 78 | pFunctionPointer_t add(void (*function)(void)); |
elessair | 0:7e2bd16f80af | 79 | |
elessair | 0:7e2bd16f80af | 80 | /** Add a function at the end of the chain |
elessair | 0:7e2bd16f80af | 81 | * |
elessair | 0:7e2bd16f80af | 82 | * @param tptr pointer to the object to call the member function on |
elessair | 0:7e2bd16f80af | 83 | * @param mptr pointer to the member function to be called |
elessair | 0:7e2bd16f80af | 84 | * |
elessair | 0:7e2bd16f80af | 85 | * @returns |
elessair | 0:7e2bd16f80af | 86 | * The function object created for 'tptr' and 'mptr' |
elessair | 0:7e2bd16f80af | 87 | */ |
elessair | 0:7e2bd16f80af | 88 | template<typename T> |
elessair | 0:7e2bd16f80af | 89 | pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) { |
elessair | 0:7e2bd16f80af | 90 | return common_add(new FunctionPointer(tptr, mptr)); |
elessair | 0:7e2bd16f80af | 91 | } |
elessair | 0:7e2bd16f80af | 92 | |
elessair | 0:7e2bd16f80af | 93 | /** Add a function at the beginning of the chain |
elessair | 0:7e2bd16f80af | 94 | * |
elessair | 0:7e2bd16f80af | 95 | * @param function A pointer to a void function |
elessair | 0:7e2bd16f80af | 96 | * |
elessair | 0:7e2bd16f80af | 97 | * @returns |
elessair | 0:7e2bd16f80af | 98 | * The function object created for 'function' |
elessair | 0:7e2bd16f80af | 99 | */ |
elessair | 0:7e2bd16f80af | 100 | pFunctionPointer_t add_front(void (*function)(void)); |
elessair | 0:7e2bd16f80af | 101 | |
elessair | 0:7e2bd16f80af | 102 | /** Add a function at the beginning of the chain |
elessair | 0:7e2bd16f80af | 103 | * |
elessair | 0:7e2bd16f80af | 104 | * @param tptr pointer to the object to call the member function on |
elessair | 0:7e2bd16f80af | 105 | * @param mptr pointer to the member function to be called |
elessair | 0:7e2bd16f80af | 106 | * |
elessair | 0:7e2bd16f80af | 107 | * @returns |
elessair | 0:7e2bd16f80af | 108 | * The function object created for 'tptr' and 'mptr' |
elessair | 0:7e2bd16f80af | 109 | */ |
elessair | 0:7e2bd16f80af | 110 | template<typename T> |
elessair | 0:7e2bd16f80af | 111 | pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) { |
elessair | 0:7e2bd16f80af | 112 | return common_add_front(new FunctionPointer(tptr, mptr)); |
elessair | 0:7e2bd16f80af | 113 | } |
elessair | 0:7e2bd16f80af | 114 | |
elessair | 0:7e2bd16f80af | 115 | /** Get the number of functions in the chain |
elessair | 0:7e2bd16f80af | 116 | */ |
elessair | 0:7e2bd16f80af | 117 | int size() const; |
elessair | 0:7e2bd16f80af | 118 | |
elessair | 0:7e2bd16f80af | 119 | /** Get a function object from the chain |
elessair | 0:7e2bd16f80af | 120 | * |
elessair | 0:7e2bd16f80af | 121 | * @param i function object index |
elessair | 0:7e2bd16f80af | 122 | * |
elessair | 0:7e2bd16f80af | 123 | * @returns |
elessair | 0:7e2bd16f80af | 124 | * The function object at position 'i' in the chain |
elessair | 0:7e2bd16f80af | 125 | */ |
elessair | 0:7e2bd16f80af | 126 | pFunctionPointer_t get(int i) const; |
elessair | 0:7e2bd16f80af | 127 | |
elessair | 0:7e2bd16f80af | 128 | /** Look for a function object in the call chain |
elessair | 0:7e2bd16f80af | 129 | * |
elessair | 0:7e2bd16f80af | 130 | * @param f the function object to search |
elessair | 0:7e2bd16f80af | 131 | * |
elessair | 0:7e2bd16f80af | 132 | * @returns |
elessair | 0:7e2bd16f80af | 133 | * The index of the function object if found, -1 otherwise. |
elessair | 0:7e2bd16f80af | 134 | */ |
elessair | 0:7e2bd16f80af | 135 | int find(pFunctionPointer_t f) const; |
elessair | 0:7e2bd16f80af | 136 | |
elessair | 0:7e2bd16f80af | 137 | /** Clear the call chain (remove all functions in the chain). |
elessair | 0:7e2bd16f80af | 138 | */ |
elessair | 0:7e2bd16f80af | 139 | void clear(); |
elessair | 0:7e2bd16f80af | 140 | |
elessair | 0:7e2bd16f80af | 141 | /** Remove a function object from the chain |
elessair | 0:7e2bd16f80af | 142 | * |
elessair | 0:7e2bd16f80af | 143 | * @arg f the function object to remove |
elessair | 0:7e2bd16f80af | 144 | * |
elessair | 0:7e2bd16f80af | 145 | * @returns |
elessair | 0:7e2bd16f80af | 146 | * true if the function object was found and removed, false otherwise. |
elessair | 0:7e2bd16f80af | 147 | */ |
elessair | 0:7e2bd16f80af | 148 | bool remove(pFunctionPointer_t f); |
elessair | 0:7e2bd16f80af | 149 | |
elessair | 0:7e2bd16f80af | 150 | /** Call all the functions in the chain in sequence |
elessair | 0:7e2bd16f80af | 151 | */ |
elessair | 0:7e2bd16f80af | 152 | void call(); |
elessair | 0:7e2bd16f80af | 153 | |
elessair | 0:7e2bd16f80af | 154 | #ifdef MBED_OPERATORS |
elessair | 0:7e2bd16f80af | 155 | void operator ()(void) { |
elessair | 0:7e2bd16f80af | 156 | call(); |
elessair | 0:7e2bd16f80af | 157 | } |
elessair | 0:7e2bd16f80af | 158 | pFunctionPointer_t operator [](int i) const { |
elessair | 0:7e2bd16f80af | 159 | return get(i); |
elessair | 0:7e2bd16f80af | 160 | } |
elessair | 0:7e2bd16f80af | 161 | #endif |
elessair | 0:7e2bd16f80af | 162 | |
elessair | 0:7e2bd16f80af | 163 | private: |
elessair | 0:7e2bd16f80af | 164 | void _check_size(); |
elessair | 0:7e2bd16f80af | 165 | pFunctionPointer_t common_add(pFunctionPointer_t pf); |
elessair | 0:7e2bd16f80af | 166 | pFunctionPointer_t common_add_front(pFunctionPointer_t pf); |
elessair | 0:7e2bd16f80af | 167 | |
elessair | 0:7e2bd16f80af | 168 | pFunctionPointer_t* _chain; |
elessair | 0:7e2bd16f80af | 169 | int _size; |
elessair | 0:7e2bd16f80af | 170 | int _elements; |
elessair | 0:7e2bd16f80af | 171 | |
elessair | 0:7e2bd16f80af | 172 | /* disallow copy constructor and assignment operators */ |
elessair | 0:7e2bd16f80af | 173 | private: |
elessair | 0:7e2bd16f80af | 174 | CallChain(const CallChain&); |
elessair | 0:7e2bd16f80af | 175 | CallChain & operator = (const CallChain&); |
elessair | 0:7e2bd16f80af | 176 | }; |
elessair | 0:7e2bd16f80af | 177 | |
elessair | 0:7e2bd16f80af | 178 | } // namespace mbed |
elessair | 0:7e2bd16f80af | 179 | |
elessair | 0:7e2bd16f80af | 180 | #endif |
elessair | 0:7e2bd16f80af | 181 |