added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
JojoS
Date:
Sat Sep 10 15:32:04 2016 +0000
Revision:
147:ba84b7dc41a7
Parent:
144:ef7eb2e8f9f7
added prescaler for 16 bit timers (solution as in LPC11xx), default prescaler 31 for max 28 ms period time

Who changed what in which revision?

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