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 /* General C++ Object Thunking class
MikamiUitOpen 16:cbb726ac20d8 2 *
MikamiUitOpen 16:cbb726ac20d8 3 * - allows direct callbacks to non-static C++ class functions
MikamiUitOpen 16:cbb726ac20d8 4 * - keeps track for the corresponding class instance
MikamiUitOpen 16:cbb726ac20d8 5 * - supports an optional context parameter for the called function
MikamiUitOpen 16:cbb726ac20d8 6 * - ideally suited for class object receiving interrupts (NVIC_SetVector)
MikamiUitOpen 16:cbb726ac20d8 7 *
MikamiUitOpen 16:cbb726ac20d8 8 * Copyright (c) 2014-2015 ARM Limited
MikamiUitOpen 16:cbb726ac20d8 9 *
MikamiUitOpen 16:cbb726ac20d8 10 * Licensed under the Apache License, Version 2.0 (the "License");
MikamiUitOpen 16:cbb726ac20d8 11 * you may not use this file except in compliance with the License.
MikamiUitOpen 16:cbb726ac20d8 12 * You may obtain a copy of the License at
MikamiUitOpen 16:cbb726ac20d8 13 *
MikamiUitOpen 16:cbb726ac20d8 14 * http://www.apache.org/licenses/LICENSE-2.0
MikamiUitOpen 16:cbb726ac20d8 15 *
MikamiUitOpen 16:cbb726ac20d8 16 * Unless required by applicable law or agreed to in writing, software
MikamiUitOpen 16:cbb726ac20d8 17 * distributed under the License is distributed on an "AS IS" BASIS,
MikamiUitOpen 16:cbb726ac20d8 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikamiUitOpen 16:cbb726ac20d8 19 * See the License for the specific language governing permissions and
MikamiUitOpen 16:cbb726ac20d8 20 * limitations under the License.
MikamiUitOpen 16:cbb726ac20d8 21 */
MikamiUitOpen 16:cbb726ac20d8 22 #ifndef __CTHUNK_H__
MikamiUitOpen 16:cbb726ac20d8 23 #define __CTHUNK_H__
MikamiUitOpen 16:cbb726ac20d8 24
MikamiUitOpen 16:cbb726ac20d8 25 #define CTHUNK_ADDRESS 1
MikamiUitOpen 16:cbb726ac20d8 26
MikamiUitOpen 16:cbb726ac20d8 27 #if (defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)) && ! defined(__CORTEX_A9)
MikamiUitOpen 16:cbb726ac20d8 28 #define CTHUNK_VARIABLES volatile uint32_t code[1]
MikamiUitOpen 16:cbb726ac20d8 29 /**
MikamiUitOpen 16:cbb726ac20d8 30 * CTHUNK disassembly for Cortex-M3/M4 (thumb2):
MikamiUitOpen 16:cbb726ac20d8 31 * * ldm.w pc,{r0,r1,r2,pc}
MikamiUitOpen 16:cbb726ac20d8 32 *
MikamiUitOpen 16:cbb726ac20d8 33 * This instruction loads the arguments for the static thunking function to r0-r2, and
MikamiUitOpen 16:cbb726ac20d8 34 * branches to that function by loading its address into PC.
MikamiUitOpen 16:cbb726ac20d8 35 *
MikamiUitOpen 16:cbb726ac20d8 36 * This is safe for both regular calling and interrupt calling, since it only touches scratch registers
MikamiUitOpen 16:cbb726ac20d8 37 * which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
MikamiUitOpen 16:cbb726ac20d8 38 */
MikamiUitOpen 16:cbb726ac20d8 39 #define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F
MikamiUitOpen 16:cbb726ac20d8 40
MikamiUitOpen 16:cbb726ac20d8 41 #elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0) || defined(__CORTEX_A9)
MikamiUitOpen 16:cbb726ac20d8 42 /*
MikamiUitOpen 16:cbb726ac20d8 43 * CTHUNK disassembly for Cortex M0 (thumb):
MikamiUitOpen 16:cbb726ac20d8 44 * * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
MikamiUitOpen 16:cbb726ac20d8 45 * * movs r4,#4 set up address to load arguments from (immediately following this code block) (1)
MikamiUitOpen 16:cbb726ac20d8 46 * * add r4,pc set up address to load arguments from (immediately following this code block) (2)
MikamiUitOpen 16:cbb726ac20d8 47 * * ldm r4!,{r0,r1,r2,r3} load arguments for static thunk function
MikamiUitOpen 16:cbb726ac20d8 48 * * blx r3 call static thunk function
MikamiUitOpen 16:cbb726ac20d8 49 * * pop {r0,r1,r2,r3,r4,pc} restore scratch registers and return from function
MikamiUitOpen 16:cbb726ac20d8 50 */
MikamiUitOpen 16:cbb726ac20d8 51 #define CTHUNK_VARIABLES volatile uint32_t code[3]
MikamiUitOpen 16:cbb726ac20d8 52 #define CTHUNK_ASSIGMENT do { \
MikamiUitOpen 16:cbb726ac20d8 53 m_thunk.code[0] = 0x2404B51F; \
MikamiUitOpen 16:cbb726ac20d8 54 m_thunk.code[1] = 0xCC0F447C; \
MikamiUitOpen 16:cbb726ac20d8 55 m_thunk.code[2] = 0xBD1F4798; \
MikamiUitOpen 16:cbb726ac20d8 56 } while (0)
MikamiUitOpen 16:cbb726ac20d8 57
MikamiUitOpen 16:cbb726ac20d8 58 #else
MikamiUitOpen 16:cbb726ac20d8 59 #error "Target is not currently suported."
MikamiUitOpen 16:cbb726ac20d8 60 #endif
MikamiUitOpen 16:cbb726ac20d8 61
MikamiUitOpen 16:cbb726ac20d8 62 /* IRQ/Exception compatible thunk entry function */
MikamiUitOpen 16:cbb726ac20d8 63 typedef void (*CThunkEntry)(void);
MikamiUitOpen 16:cbb726ac20d8 64
MikamiUitOpen 16:cbb726ac20d8 65 template<class T>
MikamiUitOpen 16:cbb726ac20d8 66 class CThunk
MikamiUitOpen 16:cbb726ac20d8 67 {
MikamiUitOpen 16:cbb726ac20d8 68 public:
MikamiUitOpen 16:cbb726ac20d8 69 typedef void (T::*CCallbackSimple)(void);
MikamiUitOpen 16:cbb726ac20d8 70 typedef void (T::*CCallback)(void* context);
MikamiUitOpen 16:cbb726ac20d8 71
MikamiUitOpen 16:cbb726ac20d8 72 inline CThunk(T *instance)
MikamiUitOpen 16:cbb726ac20d8 73 {
MikamiUitOpen 16:cbb726ac20d8 74 init(instance, NULL, NULL);
MikamiUitOpen 16:cbb726ac20d8 75 }
MikamiUitOpen 16:cbb726ac20d8 76
MikamiUitOpen 16:cbb726ac20d8 77 inline CThunk(T *instance, CCallback callback)
MikamiUitOpen 16:cbb726ac20d8 78 {
MikamiUitOpen 16:cbb726ac20d8 79 init(instance, callback, NULL);
MikamiUitOpen 16:cbb726ac20d8 80 }
MikamiUitOpen 16:cbb726ac20d8 81
MikamiUitOpen 16:cbb726ac20d8 82 ~CThunk() {
MikamiUitOpen 16:cbb726ac20d8 83
MikamiUitOpen 16:cbb726ac20d8 84 }
MikamiUitOpen 16:cbb726ac20d8 85
MikamiUitOpen 16:cbb726ac20d8 86 inline CThunk(T *instance, CCallbackSimple callback)
MikamiUitOpen 16:cbb726ac20d8 87 {
MikamiUitOpen 16:cbb726ac20d8 88 init(instance, (CCallback)callback, NULL);
MikamiUitOpen 16:cbb726ac20d8 89 }
MikamiUitOpen 16:cbb726ac20d8 90
MikamiUitOpen 16:cbb726ac20d8 91 inline CThunk(T &instance, CCallback callback)
MikamiUitOpen 16:cbb726ac20d8 92 {
MikamiUitOpen 16:cbb726ac20d8 93 init(instance, callback, NULL);
MikamiUitOpen 16:cbb726ac20d8 94 }
MikamiUitOpen 16:cbb726ac20d8 95
MikamiUitOpen 16:cbb726ac20d8 96 inline CThunk(T &instance, CCallbackSimple callback)
MikamiUitOpen 16:cbb726ac20d8 97 {
MikamiUitOpen 16:cbb726ac20d8 98 init(instance, (CCallback)callback, NULL);
MikamiUitOpen 16:cbb726ac20d8 99 }
MikamiUitOpen 16:cbb726ac20d8 100
MikamiUitOpen 16:cbb726ac20d8 101 inline CThunk(T &instance, CCallback callback, void* context)
MikamiUitOpen 16:cbb726ac20d8 102 {
MikamiUitOpen 16:cbb726ac20d8 103 init(instance, callback, context);
MikamiUitOpen 16:cbb726ac20d8 104 }
MikamiUitOpen 16:cbb726ac20d8 105
MikamiUitOpen 16:cbb726ac20d8 106 inline void callback(CCallback callback)
MikamiUitOpen 16:cbb726ac20d8 107 {
MikamiUitOpen 16:cbb726ac20d8 108 m_callback = callback;
MikamiUitOpen 16:cbb726ac20d8 109 }
MikamiUitOpen 16:cbb726ac20d8 110
MikamiUitOpen 16:cbb726ac20d8 111 inline void callback(CCallbackSimple callback)
MikamiUitOpen 16:cbb726ac20d8 112 {
MikamiUitOpen 16:cbb726ac20d8 113 m_callback = (CCallback)callback;
MikamiUitOpen 16:cbb726ac20d8 114 }
MikamiUitOpen 16:cbb726ac20d8 115
MikamiUitOpen 16:cbb726ac20d8 116 inline void context(void* context)
MikamiUitOpen 16:cbb726ac20d8 117 {
MikamiUitOpen 16:cbb726ac20d8 118 m_thunk.context = (uint32_t)context;
MikamiUitOpen 16:cbb726ac20d8 119 }
MikamiUitOpen 16:cbb726ac20d8 120
MikamiUitOpen 16:cbb726ac20d8 121 inline void context(uint32_t context)
MikamiUitOpen 16:cbb726ac20d8 122 {
MikamiUitOpen 16:cbb726ac20d8 123 m_thunk.context = context;
MikamiUitOpen 16:cbb726ac20d8 124 }
MikamiUitOpen 16:cbb726ac20d8 125
MikamiUitOpen 16:cbb726ac20d8 126 inline uint32_t entry(void)
MikamiUitOpen 16:cbb726ac20d8 127 {
MikamiUitOpen 16:cbb726ac20d8 128 return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
MikamiUitOpen 16:cbb726ac20d8 129 }
MikamiUitOpen 16:cbb726ac20d8 130
MikamiUitOpen 16:cbb726ac20d8 131 /* get thunk entry point for connecting rhunk to an IRQ table */
MikamiUitOpen 16:cbb726ac20d8 132 inline operator CThunkEntry(void)
MikamiUitOpen 16:cbb726ac20d8 133 {
MikamiUitOpen 16:cbb726ac20d8 134 return (CThunkEntry)entry();
MikamiUitOpen 16:cbb726ac20d8 135 }
MikamiUitOpen 16:cbb726ac20d8 136
MikamiUitOpen 16:cbb726ac20d8 137 /* get thunk entry point for connecting rhunk to an IRQ table */
MikamiUitOpen 16:cbb726ac20d8 138 inline operator uint32_t(void)
MikamiUitOpen 16:cbb726ac20d8 139 {
MikamiUitOpen 16:cbb726ac20d8 140 return entry();
MikamiUitOpen 16:cbb726ac20d8 141 }
MikamiUitOpen 16:cbb726ac20d8 142
MikamiUitOpen 16:cbb726ac20d8 143 /* simple test function */
MikamiUitOpen 16:cbb726ac20d8 144 inline void call(void)
MikamiUitOpen 16:cbb726ac20d8 145 {
MikamiUitOpen 16:cbb726ac20d8 146 (((CThunkEntry)(entry()))());
MikamiUitOpen 16:cbb726ac20d8 147 }
MikamiUitOpen 16:cbb726ac20d8 148
MikamiUitOpen 16:cbb726ac20d8 149 private:
MikamiUitOpen 16:cbb726ac20d8 150 T* m_instance;
MikamiUitOpen 16:cbb726ac20d8 151 volatile CCallback m_callback;
MikamiUitOpen 16:cbb726ac20d8 152
MikamiUitOpen 16:cbb726ac20d8 153 // TODO: this needs proper fix, to refactor toolchain header file and all its use
MikamiUitOpen 16:cbb726ac20d8 154 // PACKED there is not defined properly for IAR
MikamiUitOpen 16:cbb726ac20d8 155 #if defined (__ICCARM__)
MikamiUitOpen 16:cbb726ac20d8 156 typedef __packed struct
MikamiUitOpen 16:cbb726ac20d8 157 {
MikamiUitOpen 16:cbb726ac20d8 158 CTHUNK_VARIABLES;
MikamiUitOpen 16:cbb726ac20d8 159 volatile uint32_t instance;
MikamiUitOpen 16:cbb726ac20d8 160 volatile uint32_t context;
MikamiUitOpen 16:cbb726ac20d8 161 volatile uint32_t callback;
MikamiUitOpen 16:cbb726ac20d8 162 volatile uint32_t trampoline;
MikamiUitOpen 16:cbb726ac20d8 163 } CThunkTrampoline;
MikamiUitOpen 16:cbb726ac20d8 164 #else
MikamiUitOpen 16:cbb726ac20d8 165 typedef struct
MikamiUitOpen 16:cbb726ac20d8 166 {
MikamiUitOpen 16:cbb726ac20d8 167 CTHUNK_VARIABLES;
MikamiUitOpen 16:cbb726ac20d8 168 volatile uint32_t instance;
MikamiUitOpen 16:cbb726ac20d8 169 volatile uint32_t context;
MikamiUitOpen 16:cbb726ac20d8 170 volatile uint32_t callback;
MikamiUitOpen 16:cbb726ac20d8 171 volatile uint32_t trampoline;
MikamiUitOpen 16:cbb726ac20d8 172 } __attribute__((__packed__)) CThunkTrampoline;
MikamiUitOpen 16:cbb726ac20d8 173 #endif
MikamiUitOpen 16:cbb726ac20d8 174
MikamiUitOpen 16:cbb726ac20d8 175 static void trampoline(T* instance, void* context, CCallback* callback)
MikamiUitOpen 16:cbb726ac20d8 176 {
MikamiUitOpen 16:cbb726ac20d8 177 if(instance && *callback) {
MikamiUitOpen 16:cbb726ac20d8 178 (static_cast<T*>(instance)->**callback)(context);
MikamiUitOpen 16:cbb726ac20d8 179 }
MikamiUitOpen 16:cbb726ac20d8 180 }
MikamiUitOpen 16:cbb726ac20d8 181
MikamiUitOpen 16:cbb726ac20d8 182 volatile CThunkTrampoline m_thunk;
MikamiUitOpen 16:cbb726ac20d8 183
MikamiUitOpen 16:cbb726ac20d8 184 inline void init(T *instance, CCallback callback, void* context)
MikamiUitOpen 16:cbb726ac20d8 185 {
MikamiUitOpen 16:cbb726ac20d8 186 /* remember callback - need to add this level of redirection
MikamiUitOpen 16:cbb726ac20d8 187 as pointer size for member functions differs between platforms */
MikamiUitOpen 16:cbb726ac20d8 188 m_callback = callback;
MikamiUitOpen 16:cbb726ac20d8 189
MikamiUitOpen 16:cbb726ac20d8 190 /* populate thunking trampoline */
MikamiUitOpen 16:cbb726ac20d8 191 CTHUNK_ASSIGMENT;
MikamiUitOpen 16:cbb726ac20d8 192 m_thunk.context = (uint32_t)context;
MikamiUitOpen 16:cbb726ac20d8 193 m_thunk.instance = (uint32_t)instance;
MikamiUitOpen 16:cbb726ac20d8 194 m_thunk.callback = (uint32_t)&m_callback;
MikamiUitOpen 16:cbb726ac20d8 195 m_thunk.trampoline = (uint32_t)&trampoline;
MikamiUitOpen 16:cbb726ac20d8 196
MikamiUitOpen 16:cbb726ac20d8 197 #if defined(__CORTEX_A9)
MikamiUitOpen 16:cbb726ac20d8 198 /* Data cache clean */
MikamiUitOpen 16:cbb726ac20d8 199 /* Cache control */
MikamiUitOpen 16:cbb726ac20d8 200 {
MikamiUitOpen 16:cbb726ac20d8 201 uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
MikamiUitOpen 16:cbb726ac20d8 202 uint32_t end_addr = (uint32_t)&m_thunk + sizeof(m_thunk);
MikamiUitOpen 16:cbb726ac20d8 203 uint32_t addr;
MikamiUitOpen 16:cbb726ac20d8 204
MikamiUitOpen 16:cbb726ac20d8 205 /* Data cache clean and invalid */
MikamiUitOpen 16:cbb726ac20d8 206 for (addr = start_addr; addr < end_addr; addr += 0x20) {
MikamiUitOpen 16:cbb726ac20d8 207 __v7_clean_inv_dcache_mva((void *)addr);
MikamiUitOpen 16:cbb726ac20d8 208 }
MikamiUitOpen 16:cbb726ac20d8 209 /* Instruction cache invalid */
MikamiUitOpen 16:cbb726ac20d8 210 __v7_inv_icache_all();
MikamiUitOpen 16:cbb726ac20d8 211 __ca9u_inv_tlb_all();
MikamiUitOpen 16:cbb726ac20d8 212 __v7_inv_btac();
MikamiUitOpen 16:cbb726ac20d8 213 }
MikamiUitOpen 16:cbb726ac20d8 214 #endif
MikamiUitOpen 16:cbb726ac20d8 215 __ISB();
MikamiUitOpen 16:cbb726ac20d8 216 __DSB();
MikamiUitOpen 16:cbb726ac20d8 217 }
MikamiUitOpen 16:cbb726ac20d8 218 };
MikamiUitOpen 16:cbb726ac20d8 219
MikamiUitOpen 16:cbb726ac20d8 220 #endif/*__CTHUNK_H__*/