change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

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