Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
common/CallChain.cpp@566:85de60b2bbaf, 2015-06-15 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jun 15 13:15:08 2015 +0100
- Revision:
- 566:85de60b2bbaf
- Parent:
- 212:34d62c0b2af6
Synchronized with git revision bf69fa1cfc0d4d59173af0a2d235c2fbc179e45c
Full URL: https://github.com/mbedmicro/mbed/commit/bf69fa1cfc0d4d59173af0a2d235c2fbc179e45c/
commit c4bf11cb6a0f36a1aca90cce128d7a8292df5bda
Merge: 0d58363 77a973c
Author: Mihail Stoyanov <wm@smode.org>
Date: Mon Jun 15 14:41:28 2015 +0300
Merge branch 'master' of https://github.com/mbedmicro/mbed
Conflicts:
workspace_tools/targets.py
commit 0d58363887d11952b26dcefa3229a9a1457b155c
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 9 16:17:27 2015 +0300
Added Nordic license for the soft device
commit d504a3b58af390c779cb7383df2223d0a500f70a
Merge: 2c5aab7 8902229
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 9 16:14:47 2015 +0300
Merge branch 'master' of https://github.com/mbedmicro/mbed
commit 2c5aab74eba507d184b74166da059d4100841ff7
Author: Mihail Stoyanov <wm@smode.org>
Date: Wed Jun 3 20:44:25 2015 +0300
Add base MCU support for Cortex-M4. Tidy up targets.py
commit 59b868a517163bf8984baa6c87ad42f86af18391
Merge: 0e23067 927c31a
Author: Mihail Stoyanov <wm@smode.org>
Date: Wed Jun 3 20:39:56 2015 +0300
Merge branch 'master' of https://github.com/mbedmicro/mbed
commit 0e23067718c61808401311bb594ed25fb4ed62c6
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 2 16:08:08 2015 +0300
Add the Delta NNN40 platform to releases
commit 62a585dcda553b6e3b5c84e90a55b465f0894863
Merge: e1cd545 7a1d25e
Author: Mihail Stoyanov <wm@smode.org>
Date: Tue Jun 2 16:06:44 2015 +0300
Merge branch 'master' of https://github.com/mbedmicro/mbed
Conflicts:
workspace_tools/tests.py
commit e1cd545a9c92c4177f72da964d50d163dae5990f
Merge: 5c5e61f ffd5586
Author: Mihail Stoyanov <wm@smode.org>
Date: Thu May 7 13:07:48 2015 +0300
Merge branch 'master' of https://github.com/mbedmicro/mbed
commit 5c5e61f0ac38d91ad04738fd33af36f91452d984
Author: Mihail Stoyanov <wm@smode.org>
Date: Thu May 7 13:07:35 2015 +0300
Remove the Disco L053 from RTOS tests as it's not ready yet
commit e75efe346742fa22e124861fddf1b51c291f4219
Author: Mihail Stoyanov <wm@smode.org>
Date: Wed May 6 13:49:05 2015 +0300
Tidy up targets.py
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bogdanm | 15:4892fe388435 | 1 | #include "CallChain.h" |
| bogdanm | 15:4892fe388435 | 2 | #include "cmsis.h" |
| bogdanm | 15:4892fe388435 | 3 | |
| bogdanm | 15:4892fe388435 | 4 | namespace mbed { |
| bogdanm | 15:4892fe388435 | 5 | |
| mbed_official | 212:34d62c0b2af6 | 6 | CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) { |
| bogdanm | 15:4892fe388435 | 7 | _chain = new pFunctionPointer_t[size](); |
| bogdanm | 15:4892fe388435 | 8 | } |
| bogdanm | 15:4892fe388435 | 9 | |
| bogdanm | 15:4892fe388435 | 10 | CallChain::~CallChain() { |
| bogdanm | 15:4892fe388435 | 11 | clear(); |
| mbed_official | 212:34d62c0b2af6 | 12 | delete _chain; |
| bogdanm | 15:4892fe388435 | 13 | } |
| bogdanm | 15:4892fe388435 | 14 | |
| bogdanm | 15:4892fe388435 | 15 | pFunctionPointer_t CallChain::add(void (*function)(void)) { |
| bogdanm | 15:4892fe388435 | 16 | return common_add(new FunctionPointer(function)); |
| bogdanm | 15:4892fe388435 | 17 | } |
| bogdanm | 15:4892fe388435 | 18 | |
| bogdanm | 15:4892fe388435 | 19 | pFunctionPointer_t CallChain::add_front(void (*function)(void)) { |
| bogdanm | 15:4892fe388435 | 20 | return common_add_front(new FunctionPointer(function)); |
| bogdanm | 15:4892fe388435 | 21 | } |
| bogdanm | 15:4892fe388435 | 22 | |
| bogdanm | 15:4892fe388435 | 23 | int CallChain::size() const { |
| bogdanm | 15:4892fe388435 | 24 | return _elements; |
| bogdanm | 15:4892fe388435 | 25 | } |
| bogdanm | 15:4892fe388435 | 26 | |
| bogdanm | 15:4892fe388435 | 27 | pFunctionPointer_t CallChain::get(int i) const { |
| bogdanm | 15:4892fe388435 | 28 | if (i < 0 || i >= _elements) |
| bogdanm | 15:4892fe388435 | 29 | return NULL; |
| bogdanm | 15:4892fe388435 | 30 | return _chain[i]; |
| bogdanm | 15:4892fe388435 | 31 | } |
| bogdanm | 15:4892fe388435 | 32 | |
| bogdanm | 15:4892fe388435 | 33 | int CallChain::find(pFunctionPointer_t f) const { |
| bogdanm | 15:4892fe388435 | 34 | for (int i = 0; i < _elements; i++) |
| bogdanm | 15:4892fe388435 | 35 | if (f == _chain[i]) |
| bogdanm | 15:4892fe388435 | 36 | return i; |
| bogdanm | 15:4892fe388435 | 37 | return -1; |
| bogdanm | 15:4892fe388435 | 38 | } |
| bogdanm | 15:4892fe388435 | 39 | |
| bogdanm | 15:4892fe388435 | 40 | void CallChain::clear() { |
| bogdanm | 15:4892fe388435 | 41 | for(int i = 0; i < _elements; i ++) { |
| bogdanm | 15:4892fe388435 | 42 | delete _chain[i]; |
| bogdanm | 15:4892fe388435 | 43 | _chain[i] = NULL; |
| bogdanm | 15:4892fe388435 | 44 | } |
| bogdanm | 15:4892fe388435 | 45 | _elements = 0; |
| bogdanm | 15:4892fe388435 | 46 | } |
| bogdanm | 15:4892fe388435 | 47 | |
| bogdanm | 15:4892fe388435 | 48 | bool CallChain::remove(pFunctionPointer_t f) { |
| bogdanm | 15:4892fe388435 | 49 | int i; |
| bogdanm | 15:4892fe388435 | 50 | |
| bogdanm | 15:4892fe388435 | 51 | if ((i = find(f)) == -1) |
| bogdanm | 15:4892fe388435 | 52 | return false; |
| bogdanm | 15:4892fe388435 | 53 | if (i != _elements - 1) |
| bogdanm | 15:4892fe388435 | 54 | memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t)); |
| bogdanm | 15:4892fe388435 | 55 | delete f; |
| bogdanm | 15:4892fe388435 | 56 | _elements --; |
| bogdanm | 15:4892fe388435 | 57 | return true; |
| bogdanm | 15:4892fe388435 | 58 | } |
| bogdanm | 15:4892fe388435 | 59 | |
| bogdanm | 15:4892fe388435 | 60 | void CallChain::call() { |
| bogdanm | 15:4892fe388435 | 61 | for(int i = 0; i < _elements; i++) |
| bogdanm | 15:4892fe388435 | 62 | _chain[i]->call(); |
| bogdanm | 15:4892fe388435 | 63 | } |
| bogdanm | 15:4892fe388435 | 64 | |
| bogdanm | 15:4892fe388435 | 65 | void CallChain::_check_size() { |
| bogdanm | 15:4892fe388435 | 66 | if (_elements < _size) |
| bogdanm | 15:4892fe388435 | 67 | return; |
| bogdanm | 15:4892fe388435 | 68 | _size = (_size < 4) ? 4 : _size + 4; |
| bogdanm | 15:4892fe388435 | 69 | pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size](); |
| bogdanm | 15:4892fe388435 | 70 | memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t)); |
| bogdanm | 15:4892fe388435 | 71 | delete _chain; |
| bogdanm | 15:4892fe388435 | 72 | _chain = new_chain; |
| bogdanm | 15:4892fe388435 | 73 | } |
| bogdanm | 15:4892fe388435 | 74 | |
| bogdanm | 15:4892fe388435 | 75 | pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) { |
| bogdanm | 15:4892fe388435 | 76 | _check_size(); |
| bogdanm | 15:4892fe388435 | 77 | _chain[_elements] = pf; |
| bogdanm | 15:4892fe388435 | 78 | _elements ++; |
| bogdanm | 15:4892fe388435 | 79 | return pf; |
| bogdanm | 15:4892fe388435 | 80 | } |
| bogdanm | 15:4892fe388435 | 81 | |
| bogdanm | 15:4892fe388435 | 82 | pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) { |
| bogdanm | 15:4892fe388435 | 83 | _check_size(); |
| bogdanm | 15:4892fe388435 | 84 | memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t)); |
| bogdanm | 15:4892fe388435 | 85 | _chain[0] = pf; |
| bogdanm | 15:4892fe388435 | 86 | _elements ++; |
| bogdanm | 15:4892fe388435 | 87 | return pf; |
| bogdanm | 15:4892fe388435 | 88 | } |
| bogdanm | 15:4892fe388435 | 89 | |
| bogdanm | 15:4892fe388435 | 90 | } // namespace mbed |
