ads1115 only
Fork of mbed by
CallChain.h@122:f9eeca106725, 2016-07-07 (annotated)
- Committer:
- Kojto
- Date:
- Thu Jul 07 14:34:11 2016 +0100
- Revision:
- 122:f9eeca106725
- Parent:
- 85:024bf7f99721
- Child:
- 123:b0220dba8be7
Release 122 of the mbed library
Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 66:9c8f0e3462fb | 1 | /* mbed Microcontroller Library |
bogdanm | 66:9c8f0e3462fb | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 66:9c8f0e3462fb | 3 | * |
bogdanm | 66:9c8f0e3462fb | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 66:9c8f0e3462fb | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 66:9c8f0e3462fb | 6 | * You may obtain a copy of the License at |
bogdanm | 66:9c8f0e3462fb | 7 | * |
bogdanm | 66:9c8f0e3462fb | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 66:9c8f0e3462fb | 9 | * |
bogdanm | 66:9c8f0e3462fb | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 66:9c8f0e3462fb | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 66:9c8f0e3462fb | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 66:9c8f0e3462fb | 13 | * See the License for the specific language governing permissions and |
bogdanm | 66:9c8f0e3462fb | 14 | * limitations under the License. |
bogdanm | 66:9c8f0e3462fb | 15 | */ |
bogdanm | 66:9c8f0e3462fb | 16 | #ifndef MBED_CALLCHAIN_H |
bogdanm | 66:9c8f0e3462fb | 17 | #define MBED_CALLCHAIN_H |
bogdanm | 66:9c8f0e3462fb | 18 | |
Kojto | 122:f9eeca106725 | 19 | #include "Callback.h" |
bogdanm | 66:9c8f0e3462fb | 20 | #include <string.h> |
bogdanm | 66:9c8f0e3462fb | 21 | |
bogdanm | 66:9c8f0e3462fb | 22 | namespace mbed { |
bogdanm | 66:9c8f0e3462fb | 23 | |
bogdanm | 66:9c8f0e3462fb | 24 | /** Group one or more functions in an instance of a CallChain, then call them in |
bogdanm | 66:9c8f0e3462fb | 25 | * sequence using CallChain::call(). Used mostly by the interrupt chaining code, |
bogdanm | 66:9c8f0e3462fb | 26 | * but can be used for other purposes. |
bogdanm | 66:9c8f0e3462fb | 27 | * |
Kojto | 122:f9eeca106725 | 28 | * @Note Synchronization level: Not protected |
Kojto | 122:f9eeca106725 | 29 | * |
bogdanm | 66:9c8f0e3462fb | 30 | * Example: |
bogdanm | 66:9c8f0e3462fb | 31 | * @code |
bogdanm | 66:9c8f0e3462fb | 32 | * #include "mbed.h" |
bogdanm | 66:9c8f0e3462fb | 33 | * |
bogdanm | 66:9c8f0e3462fb | 34 | * CallChain chain; |
bogdanm | 66:9c8f0e3462fb | 35 | * |
bogdanm | 66:9c8f0e3462fb | 36 | * void first(void) { |
bogdanm | 66:9c8f0e3462fb | 37 | * printf("'first' function.\n"); |
bogdanm | 66:9c8f0e3462fb | 38 | * } |
bogdanm | 66:9c8f0e3462fb | 39 | * |
bogdanm | 66:9c8f0e3462fb | 40 | * void second(void) { |
bogdanm | 66:9c8f0e3462fb | 41 | * printf("'second' function.\n"); |
bogdanm | 66:9c8f0e3462fb | 42 | * } |
bogdanm | 66:9c8f0e3462fb | 43 | * |
bogdanm | 66:9c8f0e3462fb | 44 | * class Test { |
bogdanm | 66:9c8f0e3462fb | 45 | * public: |
bogdanm | 66:9c8f0e3462fb | 46 | * void f(void) { |
bogdanm | 66:9c8f0e3462fb | 47 | * printf("A::f (class member).\n"); |
bogdanm | 66:9c8f0e3462fb | 48 | * } |
bogdanm | 66:9c8f0e3462fb | 49 | * }; |
bogdanm | 66:9c8f0e3462fb | 50 | * |
bogdanm | 66:9c8f0e3462fb | 51 | * int main() { |
bogdanm | 66:9c8f0e3462fb | 52 | * Test test; |
bogdanm | 66:9c8f0e3462fb | 53 | * |
bogdanm | 66:9c8f0e3462fb | 54 | * chain.add(second); |
bogdanm | 66:9c8f0e3462fb | 55 | * chain.add_front(first); |
bogdanm | 66:9c8f0e3462fb | 56 | * chain.add(&test, &Test::f); |
bogdanm | 66:9c8f0e3462fb | 57 | * chain.call(); |
bogdanm | 66:9c8f0e3462fb | 58 | * } |
bogdanm | 66:9c8f0e3462fb | 59 | * @endcode |
bogdanm | 66:9c8f0e3462fb | 60 | */ |
bogdanm | 85:024bf7f99721 | 61 | |
Kojto | 122:f9eeca106725 | 62 | typedef Callback<void()> *pFunctionPointer_t; |
Kojto | 122:f9eeca106725 | 63 | class CallChainLink; |
bogdanm | 66:9c8f0e3462fb | 64 | |
bogdanm | 66:9c8f0e3462fb | 65 | class CallChain { |
bogdanm | 66:9c8f0e3462fb | 66 | public: |
bogdanm | 66:9c8f0e3462fb | 67 | /** Create an empty chain |
bogdanm | 66:9c8f0e3462fb | 68 | * |
bogdanm | 66:9c8f0e3462fb | 69 | * @param size (optional) Initial size of the chain |
bogdanm | 85:024bf7f99721 | 70 | */ |
bogdanm | 66:9c8f0e3462fb | 71 | CallChain(int size = 4); |
bogdanm | 66:9c8f0e3462fb | 72 | virtual ~CallChain(); |
bogdanm | 66:9c8f0e3462fb | 73 | |
bogdanm | 66:9c8f0e3462fb | 74 | /** Add a function at the end of the chain |
bogdanm | 66:9c8f0e3462fb | 75 | * |
Kojto | 122:f9eeca106725 | 76 | * @param func A pointer to a void function |
bogdanm | 66:9c8f0e3462fb | 77 | * |
bogdanm | 66:9c8f0e3462fb | 78 | * @returns |
Kojto | 122:f9eeca106725 | 79 | * The function object created for 'func' |
bogdanm | 66:9c8f0e3462fb | 80 | */ |
Kojto | 122:f9eeca106725 | 81 | pFunctionPointer_t add(Callback<void()> func); |
bogdanm | 66:9c8f0e3462fb | 82 | |
bogdanm | 66:9c8f0e3462fb | 83 | /** Add a function at the end of the chain |
bogdanm | 66:9c8f0e3462fb | 84 | * |
Kojto | 122:f9eeca106725 | 85 | * @param obj pointer to the object to call the member function on |
Kojto | 122:f9eeca106725 | 86 | * @param method pointer to the member function to be called |
bogdanm | 66:9c8f0e3462fb | 87 | * |
bogdanm | 66:9c8f0e3462fb | 88 | * @returns |
Kojto | 122:f9eeca106725 | 89 | * The function object created for 'obj' and 'method' |
bogdanm | 66:9c8f0e3462fb | 90 | */ |
Kojto | 122:f9eeca106725 | 91 | template<typename T, typename M> |
Kojto | 122:f9eeca106725 | 92 | pFunctionPointer_t add(T *obj, M method) { |
Kojto | 122:f9eeca106725 | 93 | return add(Callback<void()>(obj, method)); |
bogdanm | 66:9c8f0e3462fb | 94 | } |
bogdanm | 66:9c8f0e3462fb | 95 | |
bogdanm | 66:9c8f0e3462fb | 96 | /** Add a function at the beginning of the chain |
bogdanm | 66:9c8f0e3462fb | 97 | * |
Kojto | 122:f9eeca106725 | 98 | * @param func A pointer to a void function |
bogdanm | 66:9c8f0e3462fb | 99 | * |
bogdanm | 66:9c8f0e3462fb | 100 | * @returns |
Kojto | 122:f9eeca106725 | 101 | * The function object created for 'func' |
bogdanm | 66:9c8f0e3462fb | 102 | */ |
Kojto | 122:f9eeca106725 | 103 | pFunctionPointer_t add_front(Callback<void()> func); |
bogdanm | 85:024bf7f99721 | 104 | |
bogdanm | 66:9c8f0e3462fb | 105 | /** Add a function at the beginning of the chain |
bogdanm | 66:9c8f0e3462fb | 106 | * |
bogdanm | 66:9c8f0e3462fb | 107 | * @param tptr pointer to the object to call the member function on |
bogdanm | 66:9c8f0e3462fb | 108 | * @param mptr pointer to the member function to be called |
bogdanm | 66:9c8f0e3462fb | 109 | * |
bogdanm | 66:9c8f0e3462fb | 110 | * @returns |
bogdanm | 66:9c8f0e3462fb | 111 | * The function object created for 'tptr' and 'mptr' |
bogdanm | 66:9c8f0e3462fb | 112 | */ |
Kojto | 122:f9eeca106725 | 113 | template<typename T, typename M> |
Kojto | 122:f9eeca106725 | 114 | pFunctionPointer_t add_front(T *obj, M method) { |
Kojto | 122:f9eeca106725 | 115 | return add_front(Callback<void()>(obj, method)); |
bogdanm | 66:9c8f0e3462fb | 116 | } |
bogdanm | 66:9c8f0e3462fb | 117 | |
bogdanm | 66:9c8f0e3462fb | 118 | /** Get the number of functions in the chain |
bogdanm | 66:9c8f0e3462fb | 119 | */ |
bogdanm | 66:9c8f0e3462fb | 120 | int size() const; |
bogdanm | 66:9c8f0e3462fb | 121 | |
bogdanm | 66:9c8f0e3462fb | 122 | /** Get a function object from the chain |
bogdanm | 66:9c8f0e3462fb | 123 | * |
bogdanm | 66:9c8f0e3462fb | 124 | * @param i function object index |
bogdanm | 66:9c8f0e3462fb | 125 | * |
bogdanm | 66:9c8f0e3462fb | 126 | * @returns |
bogdanm | 66:9c8f0e3462fb | 127 | * The function object at position 'i' in the chain |
bogdanm | 66:9c8f0e3462fb | 128 | */ |
bogdanm | 66:9c8f0e3462fb | 129 | pFunctionPointer_t get(int i) const; |
bogdanm | 66:9c8f0e3462fb | 130 | |
bogdanm | 66:9c8f0e3462fb | 131 | /** Look for a function object in the call chain |
bogdanm | 66:9c8f0e3462fb | 132 | * |
bogdanm | 66:9c8f0e3462fb | 133 | * @param f the function object to search |
bogdanm | 66:9c8f0e3462fb | 134 | * |
bogdanm | 66:9c8f0e3462fb | 135 | * @returns |
bogdanm | 66:9c8f0e3462fb | 136 | * The index of the function object if found, -1 otherwise. |
bogdanm | 66:9c8f0e3462fb | 137 | */ |
bogdanm | 66:9c8f0e3462fb | 138 | int find(pFunctionPointer_t f) const; |
bogdanm | 66:9c8f0e3462fb | 139 | |
bogdanm | 66:9c8f0e3462fb | 140 | /** Clear the call chain (remove all functions in the chain). |
bogdanm | 66:9c8f0e3462fb | 141 | */ |
bogdanm | 66:9c8f0e3462fb | 142 | void clear(); |
bogdanm | 66:9c8f0e3462fb | 143 | |
bogdanm | 66:9c8f0e3462fb | 144 | /** Remove a function object from the chain |
bogdanm | 66:9c8f0e3462fb | 145 | * |
bogdanm | 66:9c8f0e3462fb | 146 | * @arg f the function object to remove |
bogdanm | 66:9c8f0e3462fb | 147 | * |
bogdanm | 66:9c8f0e3462fb | 148 | * @returns |
bogdanm | 66:9c8f0e3462fb | 149 | * true if the function object was found and removed, false otherwise. |
bogdanm | 66:9c8f0e3462fb | 150 | */ |
bogdanm | 66:9c8f0e3462fb | 151 | bool remove(pFunctionPointer_t f); |
bogdanm | 66:9c8f0e3462fb | 152 | |
bogdanm | 66:9c8f0e3462fb | 153 | /** Call all the functions in the chain in sequence |
bogdanm | 66:9c8f0e3462fb | 154 | */ |
bogdanm | 66:9c8f0e3462fb | 155 | void call(); |
bogdanm | 85:024bf7f99721 | 156 | |
bogdanm | 66:9c8f0e3462fb | 157 | #ifdef MBED_OPERATORS |
bogdanm | 66:9c8f0e3462fb | 158 | void operator ()(void) { |
bogdanm | 66:9c8f0e3462fb | 159 | call(); |
bogdanm | 66:9c8f0e3462fb | 160 | } |
bogdanm | 66:9c8f0e3462fb | 161 | pFunctionPointer_t operator [](int i) const { |
bogdanm | 66:9c8f0e3462fb | 162 | return get(i); |
bogdanm | 66:9c8f0e3462fb | 163 | } |
bogdanm | 66:9c8f0e3462fb | 164 | #endif |
bogdanm | 66:9c8f0e3462fb | 165 | |
bogdanm | 85:024bf7f99721 | 166 | /* disallow copy constructor and assignment operators */ |
bogdanm | 85:024bf7f99721 | 167 | private: |
bogdanm | 85:024bf7f99721 | 168 | CallChain(const CallChain&); |
bogdanm | 85:024bf7f99721 | 169 | CallChain & operator = (const CallChain&); |
Kojto | 122:f9eeca106725 | 170 | CallChainLink *_chain; |
bogdanm | 66:9c8f0e3462fb | 171 | }; |
bogdanm | 66:9c8f0e3462fb | 172 | |
bogdanm | 66:9c8f0e3462fb | 173 | } // namespace mbed |
bogdanm | 66:9c8f0e3462fb | 174 | |
bogdanm | 66:9c8f0e3462fb | 175 | #endif |
bogdanm | 66:9c8f0e3462fb | 176 |