Output the audio signal with filtering by graphic equalizer in the *.wav file on the SD card using onboard CODEC. SD カードの *.wav ファイルのオーディオ信号をグラフィック・イコライザを通して,ボードに搭載されているCODEC で出力する.

Dependencies:   F746_GUI F746_SAI_IO SD_PlayerSkeleton FrequencyResponseDrawer

Committer:
MikamiUitOpen
Date:
Sun Oct 02 06:33:59 2016 +0000
Revision:
16:cbb726ac20d8
17

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 16:cbb726ac20d8 1 #include "cmsis.h"
MikamiUitOpen 16:cbb726ac20d8 2 #if defined(NVIC_NUM_VECTORS)
MikamiUitOpen 16:cbb726ac20d8 3
MikamiUitOpen 16:cbb726ac20d8 4 #include "InterruptManager.h"
MikamiUitOpen 16:cbb726ac20d8 5 #include <string.h>
MikamiUitOpen 16:cbb726ac20d8 6
MikamiUitOpen 16:cbb726ac20d8 7 #define CHAIN_INITIAL_SIZE 4
MikamiUitOpen 16:cbb726ac20d8 8
MikamiUitOpen 16:cbb726ac20d8 9 namespace mbed {
MikamiUitOpen 16:cbb726ac20d8 10
MikamiUitOpen 16:cbb726ac20d8 11 typedef void (*pvoidf)(void);
MikamiUitOpen 16:cbb726ac20d8 12
MikamiUitOpen 16:cbb726ac20d8 13 InterruptManager* InterruptManager::_instance = (InterruptManager*)NULL;
MikamiUitOpen 16:cbb726ac20d8 14
MikamiUitOpen 16:cbb726ac20d8 15 InterruptManager* InterruptManager::get() {
MikamiUitOpen 16:cbb726ac20d8 16 if (NULL == _instance)
MikamiUitOpen 16:cbb726ac20d8 17 _instance = new InterruptManager();
MikamiUitOpen 16:cbb726ac20d8 18 return _instance;
MikamiUitOpen 16:cbb726ac20d8 19 }
MikamiUitOpen 16:cbb726ac20d8 20
MikamiUitOpen 16:cbb726ac20d8 21 InterruptManager::InterruptManager() {
MikamiUitOpen 16:cbb726ac20d8 22 memset(_chains, 0, NVIC_NUM_VECTORS * sizeof(CallChain*));
MikamiUitOpen 16:cbb726ac20d8 23 }
MikamiUitOpen 16:cbb726ac20d8 24
MikamiUitOpen 16:cbb726ac20d8 25 void InterruptManager::destroy() {
MikamiUitOpen 16:cbb726ac20d8 26 // Not a good idea to call this unless NO interrupt at all
MikamiUitOpen 16:cbb726ac20d8 27 // is under the control of the handler; otherwise, a system crash
MikamiUitOpen 16:cbb726ac20d8 28 // is very likely to occur
MikamiUitOpen 16:cbb726ac20d8 29 if (NULL != _instance) {
MikamiUitOpen 16:cbb726ac20d8 30 delete _instance;
MikamiUitOpen 16:cbb726ac20d8 31 _instance = (InterruptManager*)NULL;
MikamiUitOpen 16:cbb726ac20d8 32 }
MikamiUitOpen 16:cbb726ac20d8 33 }
MikamiUitOpen 16:cbb726ac20d8 34
MikamiUitOpen 16:cbb726ac20d8 35 InterruptManager::~InterruptManager() {
MikamiUitOpen 16:cbb726ac20d8 36 for(int i = 0; i < NVIC_NUM_VECTORS; i++)
MikamiUitOpen 16:cbb726ac20d8 37 if (NULL != _chains[i])
MikamiUitOpen 16:cbb726ac20d8 38 delete _chains[i];
MikamiUitOpen 16:cbb726ac20d8 39 }
MikamiUitOpen 16:cbb726ac20d8 40
MikamiUitOpen 16:cbb726ac20d8 41 bool InterruptManager::must_replace_vector(IRQn_Type irq) {
MikamiUitOpen 16:cbb726ac20d8 42 int irq_pos = get_irq_index(irq);
MikamiUitOpen 16:cbb726ac20d8 43
MikamiUitOpen 16:cbb726ac20d8 44 if (NULL == _chains[irq_pos]) {
MikamiUitOpen 16:cbb726ac20d8 45 _chains[irq_pos] = new CallChain(CHAIN_INITIAL_SIZE);
MikamiUitOpen 16:cbb726ac20d8 46 _chains[irq_pos]->add((pvoidf)NVIC_GetVector(irq));
MikamiUitOpen 16:cbb726ac20d8 47 return true;
MikamiUitOpen 16:cbb726ac20d8 48 }
MikamiUitOpen 16:cbb726ac20d8 49 return false;
MikamiUitOpen 16:cbb726ac20d8 50 }
MikamiUitOpen 16:cbb726ac20d8 51
MikamiUitOpen 16:cbb726ac20d8 52 pFunctionPointer_t InterruptManager::add_common(void (*function)(void), IRQn_Type irq, bool front) {
MikamiUitOpen 16:cbb726ac20d8 53 int irq_pos = get_irq_index(irq);
MikamiUitOpen 16:cbb726ac20d8 54 bool change = must_replace_vector(irq);
MikamiUitOpen 16:cbb726ac20d8 55
MikamiUitOpen 16:cbb726ac20d8 56 pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(function) : _chains[irq_pos]->add(function);
MikamiUitOpen 16:cbb726ac20d8 57 if (change)
MikamiUitOpen 16:cbb726ac20d8 58 NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper);
MikamiUitOpen 16:cbb726ac20d8 59 return pf;
MikamiUitOpen 16:cbb726ac20d8 60 }
MikamiUitOpen 16:cbb726ac20d8 61
MikamiUitOpen 16:cbb726ac20d8 62 bool InterruptManager::remove_handler(pFunctionPointer_t handler, IRQn_Type irq) {
MikamiUitOpen 16:cbb726ac20d8 63 int irq_pos = get_irq_index(irq);
MikamiUitOpen 16:cbb726ac20d8 64
MikamiUitOpen 16:cbb726ac20d8 65 if (NULL == _chains[irq_pos])
MikamiUitOpen 16:cbb726ac20d8 66 return false;
MikamiUitOpen 16:cbb726ac20d8 67 if (!_chains[irq_pos]->remove(handler))
MikamiUitOpen 16:cbb726ac20d8 68 return false;
MikamiUitOpen 16:cbb726ac20d8 69 // If there's a single function left in the chain, swith the interrupt vector
MikamiUitOpen 16:cbb726ac20d8 70 // to call that function directly. This way we save both time and space.
MikamiUitOpen 16:cbb726ac20d8 71 if (_chains[irq_pos]->size() == 1 && NULL != _chains[irq_pos]->get(0)->get_function()) {
MikamiUitOpen 16:cbb726ac20d8 72 NVIC_SetVector(irq, (uint32_t)_chains[irq_pos]->get(0)->get_function());
MikamiUitOpen 16:cbb726ac20d8 73 delete _chains[irq_pos];
MikamiUitOpen 16:cbb726ac20d8 74 _chains[irq_pos] = (CallChain*) NULL;
MikamiUitOpen 16:cbb726ac20d8 75 }
MikamiUitOpen 16:cbb726ac20d8 76 return true;
MikamiUitOpen 16:cbb726ac20d8 77 }
MikamiUitOpen 16:cbb726ac20d8 78
MikamiUitOpen 16:cbb726ac20d8 79 void InterruptManager::irq_helper() {
MikamiUitOpen 16:cbb726ac20d8 80 _chains[__get_IPSR()]->call();
MikamiUitOpen 16:cbb726ac20d8 81 }
MikamiUitOpen 16:cbb726ac20d8 82
MikamiUitOpen 16:cbb726ac20d8 83 int InterruptManager::get_irq_index(IRQn_Type irq) {
MikamiUitOpen 16:cbb726ac20d8 84 return (int)irq + NVIC_USER_IRQ_OFFSET;
MikamiUitOpen 16:cbb726ac20d8 85 }
MikamiUitOpen 16:cbb726ac20d8 86
MikamiUitOpen 16:cbb726ac20d8 87 void InterruptManager::static_irq_helper() {
MikamiUitOpen 16:cbb726ac20d8 88 InterruptManager::get()->irq_helper();
MikamiUitOpen 16:cbb726ac20d8 89 }
MikamiUitOpen 16:cbb726ac20d8 90
MikamiUitOpen 16:cbb726ac20d8 91 } // namespace mbed
MikamiUitOpen 16:cbb726ac20d8 92
MikamiUitOpen 16:cbb726ac20d8 93 #endif