mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
common/CallChain.cpp@129:8a86d1aafce0, 2016-05-16 (annotated)
- Committer:
- mbed_official
- Date:
- Mon May 16 12:00:12 2016 +0100
- Revision:
- 129:8a86d1aafce0
- Parent:
- 0:9b334a45a8ff
- Child:
- 144:ef7eb2e8f9f7
Synchronized with git revision 1d1f7ab1330d44cc5697c682173f7090a7d6b1cb
Full URL: https://github.com/mbedmicro/mbed/commit/1d1f7ab1330d44cc5697c682173f7090a7d6b1cb/
* [STM32F4] Get PCLK1 clock and set initial CAN frequency
CAN bus opperates on APB1 peripheral clock due to that we need to get PCLK1 freq
in *can_frequency()* function to properly calculate CAN speed and reconfigure
BS1, BS2, SJW bits.
Also to fully communicate with other ST platform we set the initical CAN
frequency to 100kb/s to be able to work with the slowest platform which supports
CAN, which is NUCLEO_F303K8 (APB1 is 32MHz).
Change-Id: I10af3aa8d715dd61c9d1b216ef813193449fecbd
* [STM32F4] Fix for CAN2 interrupt index
CAN2 interrupt index was wrong leading to not properly registering interrupt.
Having this fix allow us to pass MBED_30 test.
Change-Id: I33f9ca7c81286f7746a8f8352619e213bdf9756a
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 |