From be2034095f3717e0725eab37089f6d1c24913051 Mon Sep 17 00:00:00 2001 From: suikan Date: Wed, 6 May 2015 16:27:12 +0900 Subject: [PATCH] =?utf8?q?DMA=E3=83=87=E3=82=A3=E3=82=BB=E3=83=BC=E3=83=96?= =?utf8?q?=E3=83=AB=E8=A9=A6=E9=A8=93=E3=81=AE=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- trx305/framework.c | 121 +++++++++++++++-------- trx305/framework.h | 4 +- trx305/kernel/config/blackfin/Makefile.config | 2 +- trx305/kernel/config/blackfin/trx_305/sys_defs.h | 2 +- 4 files changed, 83 insertions(+), 46 deletions(-) diff --git a/trx305/framework.c b/trx305/framework.c index 9e15bb2..689c835 100644 --- a/trx305/framework.c +++ b/trx305/framework.c @@ -25,18 +25,20 @@ struct dma_descripter{ unsigned short x_modify; }; + // フレームワークの作業用内部変数 static struct { - struct dma_descripter rx_dma_dsc[2]; - struct dma_descripter tx_dma_dsc[2]; + struct dma_descripter rx_dma_dsc[2]; // FPGAからのデータDMAデスクリプタ + struct dma_descripter tx_dma_dsc[2]; // FPGAへのデータDMAデスクリプタ - unsigned int rxif_buffer[2][RXIF_BUFSIZE]; - unsigned int af_buffer[2][AF_BUFSIZE]; + unsigned int rxif_buffer[2][RXIF_BUFSIZE]; // FPGAからのデータDMAバッファ + unsigned int af_buffer[2][AF_BUFSIZE]; // FPGAへのデータDMAバッファ int index; // パッカーが使う。現在のワードインデックスが0か1か - short wide_fm_i[WIDE_FM_OVERSAMPE]; - short wide_fm_q[WIDE_FM_OVERSAMPE]; - int wide_fm_index; + short wide_fm_i[WIDE_FM_OVERSAMPE]; // Wide FMを複数サンプルまとめて処理するためのバッファ + short wide_fm_q[WIDE_FM_OVERSAMPE]; // Wide FMを複数サンプルまとめて処理するためのバッファ + int wide_fm_index; // 次のバッファ格納位置。現在のバッファ長でもある。 } framework; + // ラジオアルゴリズムとのやりとりに使う変数 struct { unsigned short flags; unsigned short smeter; @@ -44,6 +46,13 @@ static struct { } radio; +static int debug_counter = 0; +static int debug_level = 0; +static int debug_tx_counter = 0; +static int debug_rx_counter = 0; + +#define DEBUGLOOP (31700) + /** * \brief RX_IF受信データの処理タスク @@ -58,12 +67,25 @@ void rx_if_task(VP_INT exinf) { int i; + // オーディオ送信プライマリチャンネルとセカンダリチャンネルデータ + unsigned int af_pri_ch, af_sec_ch; + vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (INT) exinf); syscall(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); + // データキューのプリフィル。半分まで詰める + for ( i=0; i DEBUGLOOP ){ + syslog( LOG_NOTICE, "AF LENGTH %d", debug_level); + debug_counter =0; + } +#endif }while (1); } @@ -385,6 +424,8 @@ void sport0_rx_int_handler(void) // ペリフェラルへの書き込みを待つ。 ssync(); + debug_rx_counter++; + } /** @@ -404,6 +445,12 @@ void sport0_tx_int_handler(void) // ペリフェラルへの書き込みを待つ。 ssync(); + debug_tx_counter++; + if ( debug_tx_counter > 31000) + { + syslog( LOG_INFO, "TX, SIC_ISR:x08", *pSIC_ISR ); + debug_tx_counter = 0; + } } /** @@ -464,24 +511,18 @@ static void init_sport0_rx(void) // 受信DMAデスクリプタを作る framework.rx_dma_dsc[0].next_descripter = &framework.rx_dma_dsc[1]; - framework.rx_dma_dsc[0].start_address = framework.rxif_buffer[0]; - framework.rx_dma_dsc[0].x_count = RXIF_BUFSIZE; - framework.rx_dma_dsc[0].x_modify = sizeof(framework.rxif_buffer[0][0]); - framework.rx_dma_dsc[0].config = - FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large - NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch - 1 << DI_EN_P | // DI_EN, 0:No interrupt at the end, 1:Interrupt at the end - 0 << DI_SEL_P | // DI_SEL, 0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop - 0 << RESTART_P | // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start - 0 << DMA2D_P | // DMA2D, 0:Linear DMA, 1:2D DMA - WDSIZE_32 | // WDSIZE, 0:8bit, 1:16bit, 2:32bit,3:reserved - 1 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory - 1 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA - framework.rx_dma_dsc[1].next_descripter = &framework.rx_dma_dsc[0]; + framework.rx_dma_dsc[1].start_address = framework.rxif_buffer[1]; + framework.rx_dma_dsc[0].start_address = framework.rxif_buffer[0]; + + framework.rx_dma_dsc[0].x_count = framework.rx_dma_dsc[1].x_count = RXIF_BUFSIZE; + + framework.rx_dma_dsc[0].x_modify = framework.rx_dma_dsc[1].x_modify = sizeof(framework.rxif_buffer[1][0]); + + framework.rx_dma_dsc[0].config = framework.rx_dma_dsc[1].config = FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch @@ -493,6 +534,7 @@ static void init_sport0_rx(void) 1 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory 1 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA + // SPORT0 受信DMAコントローラの初期状態設定 // ここではDMAをイネーブルにしない。また、バッファクリアする *pDMA1_CONFIG = @@ -555,24 +597,18 @@ static void init_sport0_tx(void) // である。rx_if_taskの初期化部でSPORT受信部を起動する際に、送信部の割り込みも // 有効にする。 framework.tx_dma_dsc[0].next_descripter = &framework.tx_dma_dsc[1]; - framework.tx_dma_dsc[0].start_address = framework.af_buffer[0]; - framework.tx_dma_dsc[0].x_count = RXIF_BUFSIZE; - framework.tx_dma_dsc[0].x_modify = sizeof(framework.af_buffer[0][0]); - framework.tx_dma_dsc[0].config = - FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large - NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch - 0 << DI_EN_P | // DI_EN, 0:No interrupt at the end, 1:Interrupt at the end - 0 << DI_SEL_P | // DI_SEL, 0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop - 0 << RESTART_P | // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start - 0 << DMA2D_P | // DMA2D, 0:Linear DMA, 1:2D DMA - WDSIZE_32 | // WDSIZE, 0:8bit, 1:16bit, 2:32bit,3:reserved - 0 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory - 1 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA - framework.tx_dma_dsc[1].next_descripter = &framework.tx_dma_dsc[0]; + + framework.tx_dma_dsc[0].start_address = framework.af_buffer[0]; framework.tx_dma_dsc[1].start_address = framework.af_buffer[1]; - framework.tx_dma_dsc[1].x_count = RXIF_BUFSIZE; - framework.tx_dma_dsc[1].x_modify = sizeof(framework.af_buffer[1][0]); + + framework.tx_dma_dsc[0].x_count = + framework.tx_dma_dsc[1].x_count = AF_BUFSIZE; + + framework.tx_dma_dsc[0].x_modify = + framework.tx_dma_dsc[1].x_modify = sizeof(framework.af_buffer[0][0]); + + framework.tx_dma_dsc[0].config = framework.tx_dma_dsc[1].config = FLOW_LARGE | // FLOW, 0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large NDSIZE_7 | // NDSIZE, the # of element of the next descripter to fetch @@ -584,6 +620,7 @@ static void init_sport0_tx(void) 0 << WNR_P | // WNR, 0:Read from memory, 1:Write to Memory 1 << 0 ; // DMA_EN, 0:Disable DMA, 1:Enable DMA + // SPORT0 送信DMAコントローラの初期状態設定 // ここではDMAをイネーブルにしない。また、バッファクリアする *pDMA2_CONFIG = diff --git a/trx305/framework.h b/trx305/framework.h index a2a47c9..a598313 100644 --- a/trx305/framework.h +++ b/trx305/framework.h @@ -104,11 +104,11 @@ * 領域が必要である。 * * なお、このソフトウェアは1サンプルあたり2[エントリ]をキューに格納するため、 - * キューの長さ[エントリ]は、割り込み周期[サンプル]の4四倍になる。 + * キューの長さ[エントリ]は、割り込み周期[サンプル]の四倍になる。 * * */ -#define AF_QUESIZE 32 /* 送受信タスクの間のキューの長さ。8サンプルが最長割り込み周期と仮定 */ +#define AF_QUESIZE 40 /* 送受信タスクの間のキューの長さ。8サンプルが最長割り込み周期と仮定してさらにマージンをもたせている */ #define WIDE_FM_OVERSAMPE 8 /* AF1サンプルあたりのWide FM サンプル数 */ diff --git a/trx305/kernel/config/blackfin/Makefile.config b/trx305/kernel/config/blackfin/Makefile.config index c6474b5..6dfb233 100644 --- a/trx305/kernel/config/blackfin/Makefile.config +++ b/trx305/kernel/config/blackfin/Makefile.config @@ -15,7 +15,7 @@ TARGET = bfin-elf # -fno-optimize-sibling-calls は、spurious_int_handler()を正常動作させるために必須。削除してはいけない。 # INCLUDES := $(INCLUDES) -I$(SRCDIR)/config/$(CPU) -COPTS := $(COPTS) -Wall -g2 -O -fno-optimize-sibling-calls +COPTS := $(COPTS) -Wall -g -O2 -fno-optimize-sibling-calls CDEFS := $(CDEFS) -D __ADSPLPBLACKFIN__ -DLABEL_ASM # diff --git a/trx305/kernel/config/blackfin/trx_305/sys_defs.h b/trx305/kernel/config/blackfin/trx_305/sys_defs.h index 4979b12..c9fe004 100644 --- a/trx305/kernel/config/blackfin/trx_305/sys_defs.h +++ b/trx305/kernel/config/blackfin/trx_305/sys_defs.h @@ -72,6 +72,6 @@ */ // #define DESTRUCTIVE_READ( iop ) (iop<(VP)0xF0000000) - +#define TCNT_SYSLOG_BUFFER 512 #endif /* _SYS_DEFS_H_ */ -- 2.11.0