3 * @author Copyright(C) 2012 Shinichiro Nakamura
4 * @brief BlueTank ACB-BF592 Application Sample Codes.
8 * ===============================================================
10 * ===============================================================
11 * Copyright (c) 2012 Shinichiro Nakamura
13 * Permission is hereby granted, free of charge, to any person
14 * obtaining a copy of this software and associated documentation
15 * files (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use,
17 * copy, modify, merge, publish, distribute, sublicense, and/or
18 * sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
27 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
33 * ===============================================================
38 #include <cdefBF592-A.h>
40 #include <sys/exception.h>
50 #define SCLOCK_HZ (100000000) /**< システムクロック(100MHz) */
51 #define DMA_SAMPLE_SIZE (256) /**< 1回のサンプルサイズ */
53 typedef __attribute__((interrupt_handler)) void (*ex_handler_fn_gcc)(void);
55 static void setup_pll(uint8_t mul_val, uint8_t div_val);
56 static void __attribute__((interrupt_handler)) sport_rx_isr();
59 * SPORT受信バッファ(ダブルバッファ)
61 static int32_t sport_buffer_rx[2][DMA_SAMPLE_SIZE];
63 * SPORT受信バッファ(ダブルバッファ)
65 static int32_t sport_buffer_tx[2][DMA_SAMPLE_SIZE];
69 static volatile int32_t bufidx_dma_target;
73 static volatile int32_t data_ready;
75 static void setup_pll(uint8_t mul_val, uint8_t div_val)
77 *pSIC_IWR = IWR_ENABLE(0); /* PLLのみIWRを許す */
79 *pPLL_CTL = (mul_val) << 9;
80 asm("cli r0; csync; idle; sti r0;": : :"R0");
81 *pSIC_IWR = IWR_ENABLE_ALL;
84 static void __attribute__((interrupt_handler)) sport_rx_isr()
86 *pDMA1_IRQ_STATUS = DMA_DONE;
88 /* オーディオコーデックからデータ到着 */
91 bufidx_dma_target = (bufidx_dma_target ^ 1) & 1;
94 static void vdsp_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn)
98 if ((ik_emulation > kind) || (kind > ik_ivg15)) {
102 *((ex_handler_fn_gcc*)&(((uint32_t*)EVT0)[(int32_t)kind])) = fn;
104 mask |= 1u << (int32_t)kind;
108 void uzume_init(UZUME *p, void *user_data)
118 p->user_data = user_data;
138 lcd_puts("BlueTank");
140 lcd_puts(" UZUME! ");
144 * 初期化された時点ではミュートされている。
149 * I2C ROMモジュールを初期化する。
161 memset(sport_buffer_rx, 0 , sizeof(sport_buffer_rx));
162 memset(sport_buffer_tx, 0 , sizeof(sport_buffer_tx));
163 bufidx_dma_target = 0;
170 vdsp_register_handler(ik_ivg9, sport_rx_isr);
171 *pSIC_IMASK |= IRQ_DMA1;
175 * 外部クロック、外部SYNC、MSB First
178 *pSPORT0_RCR1 = RFSR | RCKFE;
179 *pSPORT0_RCR2 = SLEN(31) | RSFSE;
183 * 外部クロック、外部SYNC、MSB First
186 *pSPORT0_TCR1 = TFSR | TCKFE;
187 *pSPORT0_TCR2 = SLEN(31) | TSFSE;
192 *pDMA1_PERIPHERAL_MAP = 0x1000;
193 *pDMA1_CONFIG = FLOW_AUTO | DI_EN | DI_SEL | DMA2D | WDSIZE_32 | WNR;
194 *pDMA1_START_ADDR = sport_buffer_rx;
195 *pDMA1_X_COUNT = DMA_SAMPLE_SIZE;
196 *pDMA1_X_MODIFY = sizeof(int32_t);
198 *pDMA1_Y_MODIFY = sizeof(int32_t);
203 *pDMA2_PERIPHERAL_MAP = 0x2000;
204 *pDMA2_CONFIG = FLOW_AUTO | DMA2D | WDSIZE_32;
205 *pDMA2_START_ADDR = sport_buffer_tx;
206 *pDMA2_X_COUNT = DMA_SAMPLE_SIZE;
207 *pDMA2_X_MODIFY = sizeof(int32_t);
209 *pDMA2_Y_MODIFY = sizeof(int32_t);
215 *pDMA1_IRQ_STATUS = DMA_DONE;
216 *pDMA1_CONFIG |= DMAEN;
217 *pDMA2_CONFIG |= DMAEN;
223 *pSPORT0_TCR1 |= TSPEN;
224 *pSPORT0_RCR1 |= RSPEN;
238 void uzume_set_effect(UZUME *p, UZUME_EFFECT_FUNC effect)
243 void uzume_set_system(UZUME *p, UZUME_SYSTEM_FUNC system)
248 void uzume_execute(UZUME *p)
252 int32_t bufidx_dma_done;
259 lcd_font_init(&fontset);
260 for (i = 0; i < (int)LCD_FONT_CHARS; i++) {
261 for (j = 0; j < i + 1; j++) {
262 lcd_font_draw_line(&fontset, (UserFont)i, 0, (7 - j), 4, (7 - j), 1);
265 lcd_font_setup_all(&fontset);
268 * Draw the text string.
270 for (i = 0; i < 8; i++) {
271 lcdbuf[i] = 0x08 + i;
277 lcd_puts("[MENU 1]");
278 lcd_puts("[MENU 2]");
279 lcd_puts("[MENU 3]");
280 lcd_puts("[MENU 4]");
284 if (0 != data_ready) {
291 * DMAが完了したバッファを使用してオーディオ処理を行なう。
293 bufidx_dma_done = bufidx_dma_target ^ 1;
294 if (p->effect != NULL) {
297 sport_buffer_rx[bufidx_dma_done],
298 sport_buffer_tx[bufidx_dma_done],
302 if (p->system != NULL) {