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-dev by
common/CallChain.cpp@107:414e9c822e99, 2016-04-05 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Apr 05 18:15:12 2016 +0100
- Revision:
- 107:414e9c822e99
- Parent:
- 0:9b334a45a8ff
- Child:
- 144:ef7eb2e8f9f7
Synchronized with git revision dd3c5f7fa8473776950ec6e15c0e4adedb21cf2f
Full URL: https://github.com/mbedmicro/mbed/commit/dd3c5f7fa8473776950ec6e15c0e4adedb21cf2f/
* * Base Commit for SAMG55J19. No errors and no implementations.
* * Added gpio files.
* * Added pinmap files.
* * Base commit for usticker implementation.
* * Added gcc_arm export functionality
* * added files for usticker.
* added template file for samd55j19
* * GPIO IRQ base commit.
* * updated with changes in gpio irq driver.
* * Reverted back unexpected commit in SAM0 gpio driver.
* * updated gpio_irq driver.
* * correction in gpio and gpio_irq drivers.
* added support for some test for gpio.
* * base commit for peripheralpins for usart.
* update in serial apis.
* * updated serial apis.
* * updated serial apis and test.
* * update serial apis for asynch apis.
* * updated peripheral pins for i2c and spi.
* added test support for serial flow control
* * Base commit for low power ticker implementation.
* * base commit for port apis.
* update in lp ticker apis.
* * Added test support for port.
* * base commit for sleep apis.
* * Base commit for spi.
* * updated with corrections in gpio irq.
* usticker file updated with latest source.
* * updated with corrections for unexpected board reset.
* updated gpio irq apis and added test for the same.
* * updated sleep api for deepsleep.
* * updated serial apis.
* Added uc_ticker and SPI api implementations
* Removed unused SPI pin map
* Updated review feedback
* * implemented lpticker with TC module.
* updated files for KnR Coding Statndard.
* updated serial and usticker apis.
* * Base commit for AnalogueIn apis.
* * RTC apis base commit without implementation.
* * Updated with corrections in lpticker implementations.
* * Added implementation for rtc apis.
* * updated with implementations for pwm.
* changed usticker from TC0 to TC1.
* Added I2C support
* * removed setvector usage from usticker and lpticker implementations
* added tests for SAMG55J19
* * Removed unwanted .o and .d files.
* Updated I2C files for KnR Coding Standards.
* Update for reducing compiler warnings in peripheralpins,c
* Updated with PWM free implementation.
* * Removed unwanted headers file inclusion.
* Compiler warning corrections in serial_api.c
* * Updated ADC with 16 bit mode initialization and code refinements.
* Updated PWM with code refinements.
* Updated I2C review feedback and fixed style
* Updated target name for SAMG55
* * Added Test Support for I2C with AT30TSE75X and Added Support for SAMG55J19 in atmelstudio project exporter
* * Added Test Support for I2C with AT30TSE75X and Added Support for SAMG55J19 in atmelstudio project exporter
* Used NVIC_SetVector for interrupt callback
* Removed Target macro define in test
* Updated test cases to have SAMG55 support
* * Updated with corrections in Serial and SPI asynchronous implementations.
* Updated deepsleep api implementation
* Merged LP_Ticker with latest code from mbed 3.0 repository.
* * updated with corrections in I2C Asynch implementation.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bogdanm | 0:9b334a45a8ff | 1 | #include "CallChain.h" |
| bogdanm | 0:9b334a45a8ff | 2 | #include "cmsis.h" |
| bogdanm | 0:9b334a45a8ff | 3 | |
| bogdanm | 0:9b334a45a8ff | 4 | namespace mbed { |
| bogdanm | 0:9b334a45a8ff | 5 | |
| bogdanm | 0:9b334a45a8ff | 6 | CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) { |
| bogdanm | 0:9b334a45a8ff | 7 | _chain = new pFunctionPointer_t[size](); |
| bogdanm | 0:9b334a45a8ff | 8 | } |
| bogdanm | 0:9b334a45a8ff | 9 | |
| bogdanm | 0:9b334a45a8ff | 10 | CallChain::~CallChain() { |
| bogdanm | 0:9b334a45a8ff | 11 | clear(); |
| bogdanm | 0:9b334a45a8ff | 12 | delete _chain; |
| bogdanm | 0:9b334a45a8ff | 13 | } |
| bogdanm | 0:9b334a45a8ff | 14 | |
| bogdanm | 0:9b334a45a8ff | 15 | pFunctionPointer_t CallChain::add(void (*function)(void)) { |
| bogdanm | 0:9b334a45a8ff | 16 | return common_add(new FunctionPointer(function)); |
| bogdanm | 0:9b334a45a8ff | 17 | } |
| bogdanm | 0:9b334a45a8ff | 18 | |
| bogdanm | 0:9b334a45a8ff | 19 | pFunctionPointer_t CallChain::add_front(void (*function)(void)) { |
| bogdanm | 0:9b334a45a8ff | 20 | return common_add_front(new FunctionPointer(function)); |
| bogdanm | 0:9b334a45a8ff | 21 | } |
| bogdanm | 0:9b334a45a8ff | 22 | |
| bogdanm | 0:9b334a45a8ff | 23 | int CallChain::size() const { |
| bogdanm | 0:9b334a45a8ff | 24 | return _elements; |
| bogdanm | 0:9b334a45a8ff | 25 | } |
| bogdanm | 0:9b334a45a8ff | 26 | |
| bogdanm | 0:9b334a45a8ff | 27 | pFunctionPointer_t CallChain::get(int i) const { |
| bogdanm | 0:9b334a45a8ff | 28 | if (i < 0 || i >= _elements) |
| bogdanm | 0:9b334a45a8ff | 29 | return NULL; |
| bogdanm | 0:9b334a45a8ff | 30 | return _chain[i]; |
| bogdanm | 0:9b334a45a8ff | 31 | } |
| bogdanm | 0:9b334a45a8ff | 32 | |
| bogdanm | 0:9b334a45a8ff | 33 | int CallChain::find(pFunctionPointer_t f) const { |
| bogdanm | 0:9b334a45a8ff | 34 | for (int i = 0; i < _elements; i++) |
| bogdanm | 0:9b334a45a8ff | 35 | if (f == _chain[i]) |
| bogdanm | 0:9b334a45a8ff | 36 | return i; |
| bogdanm | 0:9b334a45a8ff | 37 | return -1; |
| bogdanm | 0:9b334a45a8ff | 38 | } |
| bogdanm | 0:9b334a45a8ff | 39 | |
| bogdanm | 0:9b334a45a8ff | 40 | void CallChain::clear() { |
| bogdanm | 0:9b334a45a8ff | 41 | for(int i = 0; i < _elements; i ++) { |
| bogdanm | 0:9b334a45a8ff | 42 | delete _chain[i]; |
| bogdanm | 0:9b334a45a8ff | 43 | _chain[i] = NULL; |
| bogdanm | 0:9b334a45a8ff | 44 | } |
| bogdanm | 0:9b334a45a8ff | 45 | _elements = 0; |
| bogdanm | 0:9b334a45a8ff | 46 | } |
| bogdanm | 0:9b334a45a8ff | 47 | |
| bogdanm | 0:9b334a45a8ff | 48 | bool CallChain::remove(pFunctionPointer_t f) { |
| bogdanm | 0:9b334a45a8ff | 49 | int i; |
| bogdanm | 0:9b334a45a8ff | 50 | |
| bogdanm | 0:9b334a45a8ff | 51 | if ((i = find(f)) == -1) |
| bogdanm | 0:9b334a45a8ff | 52 | return false; |
| bogdanm | 0:9b334a45a8ff | 53 | if (i != _elements - 1) |
| bogdanm | 0:9b334a45a8ff | 54 | memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t)); |
| bogdanm | 0:9b334a45a8ff | 55 | delete f; |
| bogdanm | 0:9b334a45a8ff | 56 | _elements --; |
| bogdanm | 0:9b334a45a8ff | 57 | return true; |
| bogdanm | 0:9b334a45a8ff | 58 | } |
| bogdanm | 0:9b334a45a8ff | 59 | |
| bogdanm | 0:9b334a45a8ff | 60 | void CallChain::call() { |
| bogdanm | 0:9b334a45a8ff | 61 | for(int i = 0; i < _elements; i++) |
| bogdanm | 0:9b334a45a8ff | 62 | _chain[i]->call(); |
| bogdanm | 0:9b334a45a8ff | 63 | } |
| bogdanm | 0:9b334a45a8ff | 64 | |
| bogdanm | 0:9b334a45a8ff | 65 | void CallChain::_check_size() { |
| bogdanm | 0:9b334a45a8ff | 66 | if (_elements < _size) |
| bogdanm | 0:9b334a45a8ff | 67 | return; |
| bogdanm | 0:9b334a45a8ff | 68 | _size = (_size < 4) ? 4 : _size + 4; |
| bogdanm | 0:9b334a45a8ff | 69 | pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size](); |
| bogdanm | 0:9b334a45a8ff | 70 | memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t)); |
| bogdanm | 0:9b334a45a8ff | 71 | delete _chain; |
| bogdanm | 0:9b334a45a8ff | 72 | _chain = new_chain; |
| bogdanm | 0:9b334a45a8ff | 73 | } |
| bogdanm | 0:9b334a45a8ff | 74 | |
| bogdanm | 0:9b334a45a8ff | 75 | pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) { |
| bogdanm | 0:9b334a45a8ff | 76 | _check_size(); |
| bogdanm | 0:9b334a45a8ff | 77 | _chain[_elements] = pf; |
| bogdanm | 0:9b334a45a8ff | 78 | _elements ++; |
| bogdanm | 0:9b334a45a8ff | 79 | return pf; |
| bogdanm | 0:9b334a45a8ff | 80 | } |
| bogdanm | 0:9b334a45a8ff | 81 | |
| bogdanm | 0:9b334a45a8ff | 82 | pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) { |
| bogdanm | 0:9b334a45a8ff | 83 | _check_size(); |
| bogdanm | 0:9b334a45a8ff | 84 | memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t)); |
| bogdanm | 0:9b334a45a8ff | 85 | _chain[0] = pf; |
| bogdanm | 0:9b334a45a8ff | 86 | _elements ++; |
| bogdanm | 0:9b334a45a8ff | 87 | return pf; |
| bogdanm | 0:9b334a45a8ff | 88 | } |
| bogdanm | 0:9b334a45a8ff | 89 | |
| bogdanm | 0:9b334a45a8ff | 90 | } // namespace mbed |
