Integrated program of 4 different kinds of application programs for processing sound signal. 4種類のサウンド信号処理を統合したプログラム.
Dependencies: F746_GUI F746_SAI_IO FrequencyResponseDrawer SD_PlayerSkeleton UIT_FFT_Real
mbed_src_STM32F7/common/InterruptManager.cpp@2:fcba17e3d573, 2016-09-26 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Sep 26 07:07:05 2016 +0000
- Revision:
- 2:fcba17e3d573
- Parent:
- mbed_src_STM/common/InterruptManager.cpp@0:224dccbc4edd
3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:224dccbc4edd | 1 | #include "cmsis.h" |
MikamiUitOpen | 0:224dccbc4edd | 2 | #if defined(NVIC_NUM_VECTORS) |
MikamiUitOpen | 0:224dccbc4edd | 3 | |
MikamiUitOpen | 0:224dccbc4edd | 4 | #include "InterruptManager.h" |
MikamiUitOpen | 0:224dccbc4edd | 5 | #include <string.h> |
MikamiUitOpen | 0:224dccbc4edd | 6 | |
MikamiUitOpen | 0:224dccbc4edd | 7 | #define CHAIN_INITIAL_SIZE 4 |
MikamiUitOpen | 0:224dccbc4edd | 8 | |
MikamiUitOpen | 0:224dccbc4edd | 9 | namespace mbed { |
MikamiUitOpen | 0:224dccbc4edd | 10 | |
MikamiUitOpen | 0:224dccbc4edd | 11 | typedef void (*pvoidf)(void); |
MikamiUitOpen | 0:224dccbc4edd | 12 | |
MikamiUitOpen | 0:224dccbc4edd | 13 | InterruptManager* InterruptManager::_instance = (InterruptManager*)NULL; |
MikamiUitOpen | 0:224dccbc4edd | 14 | |
MikamiUitOpen | 0:224dccbc4edd | 15 | InterruptManager* InterruptManager::get() { |
MikamiUitOpen | 0:224dccbc4edd | 16 | if (NULL == _instance) |
MikamiUitOpen | 0:224dccbc4edd | 17 | _instance = new InterruptManager(); |
MikamiUitOpen | 0:224dccbc4edd | 18 | return _instance; |
MikamiUitOpen | 0:224dccbc4edd | 19 | } |
MikamiUitOpen | 0:224dccbc4edd | 20 | |
MikamiUitOpen | 0:224dccbc4edd | 21 | InterruptManager::InterruptManager() { |
MikamiUitOpen | 0:224dccbc4edd | 22 | memset(_chains, 0, NVIC_NUM_VECTORS * sizeof(CallChain*)); |
MikamiUitOpen | 0:224dccbc4edd | 23 | } |
MikamiUitOpen | 0:224dccbc4edd | 24 | |
MikamiUitOpen | 0:224dccbc4edd | 25 | void InterruptManager::destroy() { |
MikamiUitOpen | 0:224dccbc4edd | 26 | // Not a good idea to call this unless NO interrupt at all |
MikamiUitOpen | 0:224dccbc4edd | 27 | // is under the control of the handler; otherwise, a system crash |
MikamiUitOpen | 0:224dccbc4edd | 28 | // is very likely to occur |
MikamiUitOpen | 0:224dccbc4edd | 29 | if (NULL != _instance) { |
MikamiUitOpen | 0:224dccbc4edd | 30 | delete _instance; |
MikamiUitOpen | 0:224dccbc4edd | 31 | _instance = (InterruptManager*)NULL; |
MikamiUitOpen | 0:224dccbc4edd | 32 | } |
MikamiUitOpen | 0:224dccbc4edd | 33 | } |
MikamiUitOpen | 0:224dccbc4edd | 34 | |
MikamiUitOpen | 0:224dccbc4edd | 35 | InterruptManager::~InterruptManager() { |
MikamiUitOpen | 0:224dccbc4edd | 36 | for(int i = 0; i < NVIC_NUM_VECTORS; i++) |
MikamiUitOpen | 0:224dccbc4edd | 37 | if (NULL != _chains[i]) |
MikamiUitOpen | 0:224dccbc4edd | 38 | delete _chains[i]; |
MikamiUitOpen | 0:224dccbc4edd | 39 | } |
MikamiUitOpen | 0:224dccbc4edd | 40 | |
MikamiUitOpen | 0:224dccbc4edd | 41 | bool InterruptManager::must_replace_vector(IRQn_Type irq) { |
MikamiUitOpen | 0:224dccbc4edd | 42 | int irq_pos = get_irq_index(irq); |
MikamiUitOpen | 0:224dccbc4edd | 43 | |
MikamiUitOpen | 0:224dccbc4edd | 44 | if (NULL == _chains[irq_pos]) { |
MikamiUitOpen | 0:224dccbc4edd | 45 | _chains[irq_pos] = new CallChain(CHAIN_INITIAL_SIZE); |
MikamiUitOpen | 0:224dccbc4edd | 46 | _chains[irq_pos]->add((pvoidf)NVIC_GetVector(irq)); |
MikamiUitOpen | 0:224dccbc4edd | 47 | return true; |
MikamiUitOpen | 0:224dccbc4edd | 48 | } |
MikamiUitOpen | 0:224dccbc4edd | 49 | return false; |
MikamiUitOpen | 0:224dccbc4edd | 50 | } |
MikamiUitOpen | 0:224dccbc4edd | 51 | |
MikamiUitOpen | 0:224dccbc4edd | 52 | pFunctionPointer_t InterruptManager::add_common(void (*function)(void), IRQn_Type irq, bool front) { |
MikamiUitOpen | 0:224dccbc4edd | 53 | int irq_pos = get_irq_index(irq); |
MikamiUitOpen | 0:224dccbc4edd | 54 | bool change = must_replace_vector(irq); |
MikamiUitOpen | 0:224dccbc4edd | 55 | |
MikamiUitOpen | 0:224dccbc4edd | 56 | pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(function) : _chains[irq_pos]->add(function); |
MikamiUitOpen | 0:224dccbc4edd | 57 | if (change) |
MikamiUitOpen | 0:224dccbc4edd | 58 | NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper); |
MikamiUitOpen | 0:224dccbc4edd | 59 | return pf; |
MikamiUitOpen | 0:224dccbc4edd | 60 | } |
MikamiUitOpen | 0:224dccbc4edd | 61 | |
MikamiUitOpen | 0:224dccbc4edd | 62 | bool InterruptManager::remove_handler(pFunctionPointer_t handler, IRQn_Type irq) { |
MikamiUitOpen | 0:224dccbc4edd | 63 | int irq_pos = get_irq_index(irq); |
MikamiUitOpen | 0:224dccbc4edd | 64 | |
MikamiUitOpen | 0:224dccbc4edd | 65 | if (NULL == _chains[irq_pos]) |
MikamiUitOpen | 0:224dccbc4edd | 66 | return false; |
MikamiUitOpen | 0:224dccbc4edd | 67 | if (!_chains[irq_pos]->remove(handler)) |
MikamiUitOpen | 0:224dccbc4edd | 68 | return false; |
MikamiUitOpen | 0:224dccbc4edd | 69 | // If there's a single function left in the chain, swith the interrupt vector |
MikamiUitOpen | 0:224dccbc4edd | 70 | // to call that function directly. This way we save both time and space. |
MikamiUitOpen | 0:224dccbc4edd | 71 | if (_chains[irq_pos]->size() == 1 && NULL != _chains[irq_pos]->get(0)->get_function()) { |
MikamiUitOpen | 0:224dccbc4edd | 72 | NVIC_SetVector(irq, (uint32_t)_chains[irq_pos]->get(0)->get_function()); |
MikamiUitOpen | 0:224dccbc4edd | 73 | delete _chains[irq_pos]; |
MikamiUitOpen | 0:224dccbc4edd | 74 | _chains[irq_pos] = (CallChain*) NULL; |
MikamiUitOpen | 0:224dccbc4edd | 75 | } |
MikamiUitOpen | 0:224dccbc4edd | 76 | return true; |
MikamiUitOpen | 0:224dccbc4edd | 77 | } |
MikamiUitOpen | 0:224dccbc4edd | 78 | |
MikamiUitOpen | 0:224dccbc4edd | 79 | void InterruptManager::irq_helper() { |
MikamiUitOpen | 0:224dccbc4edd | 80 | _chains[__get_IPSR()]->call(); |
MikamiUitOpen | 0:224dccbc4edd | 81 | } |
MikamiUitOpen | 0:224dccbc4edd | 82 | |
MikamiUitOpen | 0:224dccbc4edd | 83 | int InterruptManager::get_irq_index(IRQn_Type irq) { |
MikamiUitOpen | 0:224dccbc4edd | 84 | return (int)irq + NVIC_USER_IRQ_OFFSET; |
MikamiUitOpen | 0:224dccbc4edd | 85 | } |
MikamiUitOpen | 0:224dccbc4edd | 86 | |
MikamiUitOpen | 0:224dccbc4edd | 87 | void InterruptManager::static_irq_helper() { |
MikamiUitOpen | 0:224dccbc4edd | 88 | InterruptManager::get()->irq_helper(); |
MikamiUitOpen | 0:224dccbc4edd | 89 | } |
MikamiUitOpen | 0:224dccbc4edd | 90 | |
MikamiUitOpen | 0:224dccbc4edd | 91 | } // namespace mbed |
MikamiUitOpen | 0:224dccbc4edd | 92 | |
MikamiUitOpen | 0:224dccbc4edd | 93 | #endif |