added prescaler for 16 bit pwm in LPC1347 target
Fork of mbed-dev by
common/CallChain.cpp@147:ba84b7dc41a7, 2016-09-10 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | #include "CallChain.h" |
<> | 144:ef7eb2e8f9f7 | 2 | #include "cmsis.h" |
<> | 144:ef7eb2e8f9f7 | 3 | #include "critical.h" |
<> | 144:ef7eb2e8f9f7 | 4 | |
<> | 144:ef7eb2e8f9f7 | 5 | namespace mbed { |
<> | 144:ef7eb2e8f9f7 | 6 | |
<> | 144:ef7eb2e8f9f7 | 7 | class CallChainLink { |
<> | 144:ef7eb2e8f9f7 | 8 | public: |
<> | 144:ef7eb2e8f9f7 | 9 | CallChainLink(): cb(), next(NULL) { |
<> | 144:ef7eb2e8f9f7 | 10 | // No work to do |
<> | 144:ef7eb2e8f9f7 | 11 | } |
<> | 144:ef7eb2e8f9f7 | 12 | |
<> | 144:ef7eb2e8f9f7 | 13 | CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) { |
<> | 144:ef7eb2e8f9f7 | 14 | // No work to do |
<> | 144:ef7eb2e8f9f7 | 15 | } |
<> | 144:ef7eb2e8f9f7 | 16 | Callback<void()> cb; |
<> | 144:ef7eb2e8f9f7 | 17 | CallChainLink * next; |
<> | 144:ef7eb2e8f9f7 | 18 | }; |
<> | 144:ef7eb2e8f9f7 | 19 | |
<> | 144:ef7eb2e8f9f7 | 20 | CallChain::CallChain(int size) : _chain(NULL) { |
<> | 144:ef7eb2e8f9f7 | 21 | // No work to do |
<> | 144:ef7eb2e8f9f7 | 22 | } |
<> | 144:ef7eb2e8f9f7 | 23 | |
<> | 144:ef7eb2e8f9f7 | 24 | CallChain::~CallChain() { |
<> | 144:ef7eb2e8f9f7 | 25 | clear(); |
<> | 144:ef7eb2e8f9f7 | 26 | } |
<> | 144:ef7eb2e8f9f7 | 27 | |
<> | 144:ef7eb2e8f9f7 | 28 | pFunctionPointer_t CallChain::add(Callback<void()> func) { |
<> | 144:ef7eb2e8f9f7 | 29 | CallChainLink *new_link = new CallChainLink(func); |
<> | 144:ef7eb2e8f9f7 | 30 | if (NULL == _chain) { |
<> | 144:ef7eb2e8f9f7 | 31 | _chain = new_link; |
<> | 144:ef7eb2e8f9f7 | 32 | return &new_link->cb; |
<> | 144:ef7eb2e8f9f7 | 33 | } |
<> | 144:ef7eb2e8f9f7 | 34 | |
<> | 144:ef7eb2e8f9f7 | 35 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 36 | while (true) { |
<> | 144:ef7eb2e8f9f7 | 37 | if (NULL == link->next) { |
<> | 144:ef7eb2e8f9f7 | 38 | link->next = new_link; |
<> | 144:ef7eb2e8f9f7 | 39 | return &new_link->cb; |
<> | 144:ef7eb2e8f9f7 | 40 | } |
<> | 144:ef7eb2e8f9f7 | 41 | link = link->next; |
<> | 144:ef7eb2e8f9f7 | 42 | } |
<> | 144:ef7eb2e8f9f7 | 43 | } |
<> | 144:ef7eb2e8f9f7 | 44 | |
<> | 144:ef7eb2e8f9f7 | 45 | pFunctionPointer_t CallChain::add_front(Callback<void()> func) { |
<> | 144:ef7eb2e8f9f7 | 46 | CallChainLink *link = new CallChainLink(func); |
<> | 144:ef7eb2e8f9f7 | 47 | link->next = _chain; |
<> | 144:ef7eb2e8f9f7 | 48 | _chain = link->next; |
<> | 144:ef7eb2e8f9f7 | 49 | return &link->cb; |
<> | 144:ef7eb2e8f9f7 | 50 | } |
<> | 144:ef7eb2e8f9f7 | 51 | |
<> | 144:ef7eb2e8f9f7 | 52 | int CallChain::size() const { |
<> | 144:ef7eb2e8f9f7 | 53 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 54 | int elements = 0; |
<> | 144:ef7eb2e8f9f7 | 55 | while (link != NULL) { |
<> | 144:ef7eb2e8f9f7 | 56 | elements++; |
<> | 144:ef7eb2e8f9f7 | 57 | link = link->next; |
<> | 144:ef7eb2e8f9f7 | 58 | } |
<> | 144:ef7eb2e8f9f7 | 59 | return elements; |
<> | 144:ef7eb2e8f9f7 | 60 | } |
<> | 144:ef7eb2e8f9f7 | 61 | |
<> | 144:ef7eb2e8f9f7 | 62 | pFunctionPointer_t CallChain::get(int idx) const { |
<> | 144:ef7eb2e8f9f7 | 63 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 64 | for (int i = 0; i < idx; i++) { |
<> | 144:ef7eb2e8f9f7 | 65 | if (NULL == link) { |
<> | 144:ef7eb2e8f9f7 | 66 | break; |
<> | 144:ef7eb2e8f9f7 | 67 | } |
<> | 144:ef7eb2e8f9f7 | 68 | link = link->next; |
<> | 144:ef7eb2e8f9f7 | 69 | } |
<> | 144:ef7eb2e8f9f7 | 70 | return &link->cb; |
<> | 144:ef7eb2e8f9f7 | 71 | } |
<> | 144:ef7eb2e8f9f7 | 72 | |
<> | 144:ef7eb2e8f9f7 | 73 | int CallChain::find(pFunctionPointer_t f) const { |
<> | 144:ef7eb2e8f9f7 | 74 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 75 | int i = 0; |
<> | 144:ef7eb2e8f9f7 | 76 | while (link != NULL) { |
<> | 144:ef7eb2e8f9f7 | 77 | if (f == &link->cb) { |
<> | 144:ef7eb2e8f9f7 | 78 | return i; |
<> | 144:ef7eb2e8f9f7 | 79 | } |
<> | 144:ef7eb2e8f9f7 | 80 | i++; |
<> | 144:ef7eb2e8f9f7 | 81 | link = link->next; |
<> | 144:ef7eb2e8f9f7 | 82 | } |
<> | 144:ef7eb2e8f9f7 | 83 | return -1; |
<> | 144:ef7eb2e8f9f7 | 84 | } |
<> | 144:ef7eb2e8f9f7 | 85 | |
<> | 144:ef7eb2e8f9f7 | 86 | void CallChain::clear() { |
<> | 144:ef7eb2e8f9f7 | 87 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 88 | _chain = NULL; |
<> | 144:ef7eb2e8f9f7 | 89 | while (link != NULL) { |
<> | 144:ef7eb2e8f9f7 | 90 | CallChainLink *temp = link->next; |
<> | 144:ef7eb2e8f9f7 | 91 | delete link; |
<> | 144:ef7eb2e8f9f7 | 92 | link = temp; |
<> | 144:ef7eb2e8f9f7 | 93 | } |
<> | 144:ef7eb2e8f9f7 | 94 | } |
<> | 144:ef7eb2e8f9f7 | 95 | |
<> | 144:ef7eb2e8f9f7 | 96 | bool CallChain::remove(pFunctionPointer_t f) { |
<> | 144:ef7eb2e8f9f7 | 97 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 98 | while (link != NULL) { |
<> | 144:ef7eb2e8f9f7 | 99 | if (f == &link->cb) { |
<> | 144:ef7eb2e8f9f7 | 100 | delete link; |
<> | 144:ef7eb2e8f9f7 | 101 | return true; |
<> | 144:ef7eb2e8f9f7 | 102 | } |
<> | 144:ef7eb2e8f9f7 | 103 | link = link->next; |
<> | 144:ef7eb2e8f9f7 | 104 | } |
<> | 144:ef7eb2e8f9f7 | 105 | return false; |
<> | 144:ef7eb2e8f9f7 | 106 | } |
<> | 144:ef7eb2e8f9f7 | 107 | |
<> | 144:ef7eb2e8f9f7 | 108 | void CallChain::call() { |
<> | 144:ef7eb2e8f9f7 | 109 | CallChainLink *link = _chain; |
<> | 144:ef7eb2e8f9f7 | 110 | while (link != NULL) { |
<> | 144:ef7eb2e8f9f7 | 111 | link->cb.call(); |
<> | 144:ef7eb2e8f9f7 | 112 | link = link->next; |
<> | 144:ef7eb2e8f9f7 | 113 | } |
<> | 144:ef7eb2e8f9f7 | 114 | } |
<> | 144:ef7eb2e8f9f7 | 115 | |
<> | 144:ef7eb2e8f9f7 | 116 | } // namespace mbed |