From: Shinichiro Nakamura Date: Sun, 19 Aug 2012 09:49:44 +0000 (+0900) Subject: Ticket #29299 UZUME$B%W%i%C%H%U%)!<%`$N?7$7$$8+$;J}$N;n9T$r3+;O!#(B X-Git-Url: http://git.osdn.net/view?p=bluetank%2Fbluetank.git;a=commitdiff_plain;h=d3adba36b1bba2612beaf4c547bf1d391683b74a Ticket #29299 UZUME$B%W%i%C%H%U%)!<%`$N?7$7$$8+$;J}$N;n9T$r3+;O!#(B --- diff --git a/firm/bare_metal/ChangeLog b/firm/bare_metal/ChangeLog index 7e76230..2cfe86f 100644 --- a/firm/bare_metal/ChangeLog +++ b/firm/bare_metal/ChangeLog @@ -29,3 +29,7 @@ * ユティリティモジュールを追加した。 * 割り込み関数登録の実装を修正した。 + +2012-08-19 Shinichiro Nakamura + + * #29299 UZUMEぷらっとフォームの新しい見せ方を試行。 diff --git a/firm/bare_metal/Makefile b/firm/bare_metal/Makefile index a68195f..055f33b 100644 --- a/firm/bare_metal/Makefile +++ b/firm/bare_metal/Makefile @@ -6,7 +6,7 @@ PROJECT = bluetank # # Source files and search directories # -CSRC += lcd.c led.c main.c mmc.c pff.c twi.c ssm2603.c bfin_util.c +CSRC += lcd.c led.c main.c mmc.c pff.c twi.c ssm2603.c bfin_util.c uzume.c ASRC += VPATH = diff --git a/firm/bare_metal/README b/firm/bare_metal/README index 480e3b4..77a85c7 100644 --- a/firm/bare_metal/README +++ b/firm/bare_metal/README @@ -46,7 +46,7 @@ Trying to send autobaud ... OK! Trying to read autobaud ... OK! Checking autobaud ... OK! Autobaud result: 57600bps 36.864mhz (header:0xBF DLL:0x28 DLH:0x00 fin:0x00) -Sending blocks of DXE 1 ... OK! +Sending blocks of DXE 1 ... OK! You may want to run minicom or kermit now Quick tip: run 'ldr && minicom' diff --git a/firm/bare_metal/lcd.c b/firm/bare_metal/lcd.c index 6ccc1cf..0e92b2e 100644 --- a/firm/bare_metal/lcd.c +++ b/firm/bare_metal/lcd.c @@ -1,6 +1,7 @@ -#include "lcd.h" #include +#include "lcd.h" +#include "bfin_util.h" #define PORT_INIT() \ do { \ @@ -36,11 +37,7 @@ #define E_ON() (*pPORTFIO_SET = PF1) #define E_OFF() (*pPORTFIO_CLEAR = PF1) -#define DELAY_US(N) \ - do { \ - volatile int dlycnt; \ - for (dlycnt = 0; dlycnt < (N) * 100; dlycnt++) { asm("nop;"); } \ - } while (0) +#define DELAY_US(N) bfin_util_usleep(N) static void write_command(unsigned char c) { @@ -111,14 +108,14 @@ void lcd_clear(void) { RS_OFF(); write_command(0x01); - DELAY_US(2000); + DELAY_US(1640); } void lcd_cursor_at_home(void) { RS_OFF(); write_command(0x02); - DELAY_US(2000); + DELAY_US(1640); } void lcd_entry_mode_set(bool increment, bool shifted) @@ -127,7 +124,7 @@ void lcd_entry_mode_set(bool increment, bool shifted) write_command(0x04 | (increment ? (1 << 1) : (0 << 1)) | (shifted ? (1 << 0) : (0 << 0))); - DELAY_US(50); + DELAY_US(40); } void lcd_display(bool display, bool cursor, bool blink) @@ -137,7 +134,7 @@ void lcd_display(bool display, bool cursor, bool blink) | (display ? (1 << 2) : (0 << 2)) | (cursor ? (1 << 1) : (0 << 1)) | (blink ? (1 << 0) : (0 << 0))); - DELAY_US(50); + DELAY_US(40); } void lcd_cursor_shift(Direction dir) @@ -146,7 +143,7 @@ void lcd_cursor_shift(Direction dir) write_command(0x10 | (0 << 3) | ((Right == dir) ? (1 << 2) : (0 << 2))); - DELAY_US(50); + DELAY_US(40); } void lcd_display_shift(Direction dir) @@ -155,7 +152,7 @@ void lcd_display_shift(Direction dir) write_command(0x10 | (1 << 3) | ((Right == dir) ? (1 << 2) : (0 << 2))); - DELAY_US(50); + DELAY_US(40); } void lcd_goto(uint8_t x, uint8_t y) @@ -164,14 +161,14 @@ void lcd_goto(uint8_t x, uint8_t y) RS_OFF(); write_command(0x80 | (addr & 0x7f)); - DELAY_US(50); + DELAY_US(40); } void lcd_putc(char c) { RS_ON(); write_command(c); - DELAY_US(50); + DELAY_US(40); } void lcd_puts(char *str) diff --git a/firm/bare_metal/main.c b/firm/bare_metal/main.c index d04d479..1d1eb0e 100644 --- a/firm/bare_metal/main.c +++ b/firm/bare_metal/main.c @@ -4,236 +4,11 @@ * @author Copyright(C) 2012 Shinichiro Nakamura */ -#include -#include -#include -#include -#include -#include "lcd.h" -#include "led.h" -#include "pff.h" -#include "ssm2603.h" - -#define SCLOCK_HZ (100000000) /**< システムクロック(100MHz) */ -#define DMA_SAMPLE_SIZE (256) /**< 1回のサンプルサイズ */ - -typedef __attribute__((interrupt_handler)) void (*ex_handler_fn_gcc)(void); - -static void setup_pll(uint8_t mul_val, uint8_t div_val); -static void __attribute__((interrupt_handler)) sport_rx_isr(); -static void audio_effect(const int32_t* src, int32_t* des, int32_t count); - -/** - * SPORT受信バッファ(ダブルバッファ) - */ -static int32_t sport_buffer_rx[2][DMA_SAMPLE_SIZE]; -/** - * SPORT受信バッファ(ダブルバッファ) - */ -static int32_t sport_buffer_tx[2][DMA_SAMPLE_SIZE]; -/** - * DMAがどのバッファ使用をしているか - */ -static volatile int32_t bufidx_dma_target; -/** - * データ転送完了フラグ - */ -static volatile int32_t data_ready; - -static void setup_pll(uint8_t mul_val, uint8_t div_val) -{ - *pSIC_IWR = IWR_ENABLE(0); /* PLLのみIWRを許す */ - *pPLL_DIV = div_val; - *pPLL_CTL = (mul_val) << 9; - asm("cli r0; csync; idle; sti r0;": : :"R0"); - *pSIC_IWR = IWR_ENABLE_ALL; -} - -static void __attribute__((interrupt_handler)) sport_rx_isr() -{ - *pDMA1_IRQ_STATUS = DMA_DONE; - ssync(); - /* オーディオコーデックからデータ到着 */ - data_ready = 1; - /* DMAが使用するバッファを変更 */ - bufidx_dma_target = (bufidx_dma_target ^ 1) & 1; -} - -/** - * @brief オーディオ処理を実行する。 - * - * @param src 処理元バッファ。 - * @param des 処理後バッファ。 - */ -static void audio_effect(const int32_t *src, int32_t *des, int32_t count) -{ - memcpy(des, src, sizeof(int32_t) * count); -} - -static void vdsp_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn) -{ - uint32_t mask; - - if ((ik_emulation > kind) || (kind > ik_ivg15)) { - return; - } - - *((ex_handler_fn_gcc*)&(((uint32_t*)EVT0)[(int32_t)kind])) = fn; - mask = cli(); - mask |= 1u << (int32_t)kind; - sti(mask); -} +#include "uzume.h" int main(void) { - int32_t bufidx_dma_done; - FATFS fatfs; -#if 0 - DIR dir; - FILINFO finfo; -#endif - - /* - * PLLを設定する。 - */ - setup_pll(16, 4); - - /* - * LEDを初期化する。 - */ - led_init(); - led_write(LedTargetR, 1); - led_write(LedTargetG, 0); - - /* - * LCDを初期化する。 - */ - lcd_init(); - lcd_clear(); - lcd_goto(0, 0); - lcd_puts("BlueTank"); - lcd_goto(0, 1); - lcd_puts("Init...."); - - /* - * オーディオコーデックを初期化する。 - * 初期化された時点ではミュートされている。 - */ - ssm2603_init(); - - /* - * SDカードをマウントする。 - */ - if (pf_mount(&fatfs) == FR_OK) { - lcd_goto(0, 0); - lcd_puts("MT: OK "); - } else { - lcd_goto(0, 0); - lcd_puts("MT: FAIL"); - } - - /* - * バッファをクリアする。 - */ - memset(sport_buffer_rx, 0 , sizeof(sport_buffer_rx)); - memset(sport_buffer_tx, 0 , sizeof(sport_buffer_tx)); - bufidx_dma_target = 0; - data_ready = 0; - - /* - * 割り込みハンドラの登録。 - * IVG9が登録先。 - */ - vdsp_register_handler(ik_ivg9, sport_rx_isr); - *pSIC_IMASK |= IRQ_DMA1; - - /* - * SPORT RXの設定 - * 外部クロック、外部SYNC、MSB First - * 24ビットデータ、 ステレオ - */ - *pSPORT0_RCR1 = RFSR | RCKFE; - *pSPORT0_RCR2 = SLEN(31) | RSFSE; - - /* - * SPORT TXの設定 - * 外部クロック、外部SYNC、MSB First - * 24ビットデータ、 ステレオ - */ - *pSPORT0_TCR1 = TFSR | TCKFE; - *pSPORT0_TCR2 = SLEN(31) | TSFSE; - - /* - * DMA1(SPORT0 RX)の設定 - */ - *pDMA1_PERIPHERAL_MAP = 0x1000; - *pDMA1_CONFIG = FLOW_AUTO | DI_EN | DI_SEL | DMA2D | WDSIZE_32 | WNR; - *pDMA1_START_ADDR = sport_buffer_rx; - *pDMA1_X_COUNT = DMA_SAMPLE_SIZE; - *pDMA1_X_MODIFY = sizeof(int32_t); - *pDMA1_Y_COUNT = 2; - *pDMA1_Y_MODIFY = sizeof(int32_t); - - /* - * DMA2(SPORT0 TX)の設定 - */ - *pDMA2_PERIPHERAL_MAP = 0x2000; - *pDMA2_CONFIG = FLOW_AUTO | DMA2D | WDSIZE_32; - *pDMA2_START_ADDR = sport_buffer_tx; - *pDMA2_X_COUNT = DMA_SAMPLE_SIZE; - *pDMA2_X_MODIFY = sizeof(int32_t); - *pDMA2_Y_COUNT = 2; - *pDMA2_Y_MODIFY = sizeof(int32_t); - ssync(); - - /* - * DMAを有効 - */ - *pDMA1_IRQ_STATUS = DMA_DONE; - *pDMA1_CONFIG |= DMAEN; - *pDMA2_CONFIG |= DMAEN; - ssync(); - - /* - * SPORT0を有効 - */ - *pSPORT0_TCR1 |= TSPEN; - *pSPORT0_RCR1 |= RSPEN; - ssync(); - - /* - * 初期化の完了をユーザに通知する。 - */ - led_write(LedTargetR, 0); - led_write(LedTargetG, 1); - lcd_goto(0, 1); - lcd_puts("InitDone"); - - /* - * ミュートを解除する。 - */ - ssm2603_mute(false); - - while (1) { - asm("idle;"); - if (0 != data_ready) { - /* - * フラグをクリアする。 - */ - data_ready = 0; - - /* - * DMAが完了したバッファを使用してオーディオ処理を行なう。 - */ - bufidx_dma_done = bufidx_dma_target ^ 1; - audio_effect(sport_buffer_rx[bufidx_dma_done], sport_buffer_tx[bufidx_dma_done], DMA_SAMPLE_SIZE); - /* - * - */ - led_write(LedTargetR, 1); - } - } - + uzume_execute(); return 0; } diff --git a/firm/bare_metal/uzume.c b/firm/bare_metal/uzume.c new file mode 100644 index 0000000..68c4112 --- /dev/null +++ b/firm/bare_metal/uzume.c @@ -0,0 +1,237 @@ +/** + * @file main.c + * @brief BlueTank ACB-BF592 Application Sample Codes. + * @author Copyright(C) 2012 Shinichiro Nakamura + */ + +#include +#include +#include +#include +#include +#include "lcd.h" +#include "led.h" +#include "pff.h" +#include "ssm2603.h" + +#define SCLOCK_HZ (100000000) /**< システムクロック(100MHz) */ +#define DMA_SAMPLE_SIZE (256) /**< 1回のサンプルサイズ */ + +typedef __attribute__((interrupt_handler)) void (*ex_handler_fn_gcc)(void); + +static void setup_pll(uint8_t mul_val, uint8_t div_val); +static void __attribute__((interrupt_handler)) sport_rx_isr(); +static void audio_effect(const int32_t* src, int32_t* des, int32_t count); + +/** + * SPORT受信バッファ(ダブルバッファ) + */ +static int32_t sport_buffer_rx[2][DMA_SAMPLE_SIZE]; +/** + * SPORT受信バッファ(ダブルバッファ) + */ +static int32_t sport_buffer_tx[2][DMA_SAMPLE_SIZE]; +/** + * DMAがどのバッファ使用をしているか + */ +static volatile int32_t bufidx_dma_target; +/** + * データ転送完了フラグ + */ +static volatile int32_t data_ready; + +static void setup_pll(uint8_t mul_val, uint8_t div_val) +{ + *pSIC_IWR = IWR_ENABLE(0); /* PLLのみIWRを許す */ + *pPLL_DIV = div_val; + *pPLL_CTL = (mul_val) << 9; + asm("cli r0; csync; idle; sti r0;": : :"R0"); + *pSIC_IWR = IWR_ENABLE_ALL; +} + +static void __attribute__((interrupt_handler)) sport_rx_isr() +{ + *pDMA1_IRQ_STATUS = DMA_DONE; + ssync(); + /* オーディオコーデックからデータ到着 */ + data_ready = 1; + /* DMAが使用するバッファを変更 */ + bufidx_dma_target = (bufidx_dma_target ^ 1) & 1; +} + +/** + * @brief オーディオ処理を実行する。 + * + * @param src 処理元バッファ。 + * @param des 処理後バッファ。 + */ +static void audio_effect(const int32_t *src, int32_t *des, int32_t count) +{ + memcpy(des, src, sizeof(int32_t) * count); +} + +static void vdsp_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn) +{ + uint32_t mask; + + if ((ik_emulation > kind) || (kind > ik_ivg15)) { + return; + } + + *((ex_handler_fn_gcc*)&(((uint32_t*)EVT0)[(int32_t)kind])) = fn; + mask = cli(); + mask |= 1u << (int32_t)kind; + sti(mask); +} + +void uzume_execute(void) +{ + int32_t bufidx_dma_done; + FATFS fatfs; +#if 0 + DIR dir; + FILINFO finfo; +#endif + + /* + * PLLを設定する。 + */ + setup_pll(16, 4); + + /* + * LEDを初期化する。 + */ + led_init(); + led_write(LedTargetR, 1); + led_write(LedTargetG, 0); + + /* + * LCDを初期化する。 + */ + lcd_init(); + lcd_clear(); + lcd_goto(0, 0); + lcd_puts("BlueTank"); + lcd_goto(0, 1); + lcd_puts("Init...."); + + /* + * オーディオコーデックを初期化する。 + * 初期化された時点ではミュートされている。 + */ + ssm2603_init(); + + /* + * SDカードをマウントする。 + */ + if (pf_mount(&fatfs) == FR_OK) { + lcd_goto(0, 0); + lcd_puts("MT: OK "); + } else { + lcd_goto(0, 0); + lcd_puts("MT: FAIL"); + } + + /* + * バッファをクリアする。 + */ + memset(sport_buffer_rx, 0 , sizeof(sport_buffer_rx)); + memset(sport_buffer_tx, 0 , sizeof(sport_buffer_tx)); + bufidx_dma_target = 0; + data_ready = 0; + + /* + * 割り込みハンドラの登録。 + * IVG9が登録先。 + */ + vdsp_register_handler(ik_ivg9, sport_rx_isr); + *pSIC_IMASK |= IRQ_DMA1; + + /* + * SPORT RXの設定 + * 外部クロック、外部SYNC、MSB First + * 24ビットデータ、 ステレオ + */ + *pSPORT0_RCR1 = RFSR | RCKFE; + *pSPORT0_RCR2 = SLEN(31) | RSFSE; + + /* + * SPORT TXの設定 + * 外部クロック、外部SYNC、MSB First + * 24ビットデータ、 ステレオ + */ + *pSPORT0_TCR1 = TFSR | TCKFE; + *pSPORT0_TCR2 = SLEN(31) | TSFSE; + + /* + * DMA1(SPORT0 RX)の設定 + */ + *pDMA1_PERIPHERAL_MAP = 0x1000; + *pDMA1_CONFIG = FLOW_AUTO | DI_EN | DI_SEL | DMA2D | WDSIZE_32 | WNR; + *pDMA1_START_ADDR = sport_buffer_rx; + *pDMA1_X_COUNT = DMA_SAMPLE_SIZE; + *pDMA1_X_MODIFY = sizeof(int32_t); + *pDMA1_Y_COUNT = 2; + *pDMA1_Y_MODIFY = sizeof(int32_t); + + /* + * DMA2(SPORT0 TX)の設定 + */ + *pDMA2_PERIPHERAL_MAP = 0x2000; + *pDMA2_CONFIG = FLOW_AUTO | DMA2D | WDSIZE_32; + *pDMA2_START_ADDR = sport_buffer_tx; + *pDMA2_X_COUNT = DMA_SAMPLE_SIZE; + *pDMA2_X_MODIFY = sizeof(int32_t); + *pDMA2_Y_COUNT = 2; + *pDMA2_Y_MODIFY = sizeof(int32_t); + ssync(); + + /* + * DMAを有効 + */ + *pDMA1_IRQ_STATUS = DMA_DONE; + *pDMA1_CONFIG |= DMAEN; + *pDMA2_CONFIG |= DMAEN; + ssync(); + + /* + * SPORT0を有効 + */ + *pSPORT0_TCR1 |= TSPEN; + *pSPORT0_RCR1 |= RSPEN; + ssync(); + + /* + * 初期化の完了をユーザに通知する。 + */ + led_write(LedTargetR, 0); + led_write(LedTargetG, 1); + lcd_goto(0, 1); + lcd_puts("InitDone"); + + /* + * ミュートを解除する。 + */ + ssm2603_mute(false); + + while (1) { + asm("idle;"); + if (0 != data_ready) { + /* + * フラグをクリアする。 + */ + data_ready = 0; + + /* + * DMAが完了したバッファを使用してオーディオ処理を行なう。 + */ + bufidx_dma_done = bufidx_dma_target ^ 1; + audio_effect(sport_buffer_rx[bufidx_dma_done], sport_buffer_tx[bufidx_dma_done], DMA_SAMPLE_SIZE); + /* + * + */ + led_write(LedTargetR, 1); + } + } +} + diff --git a/firm/bare_metal/uzume.h b/firm/bare_metal/uzume.h new file mode 100644 index 0000000..dd9d957 --- /dev/null +++ b/firm/bare_metal/uzume.h @@ -0,0 +1,7 @@ +#ifndef UZUME_H +#define UZUME_H + +void uzume_execute(void); + +#endif +