OSDN Git Service

ここまでで、SPORT0受信DMAの連続動作及び割り込みのトリガ、割り込みハンドラの起動、割り込みハンドラからタスクへの通知が正常動作していることを確認済み。
[trx-305dsp/dsp.git] / trx305 / rx_if.c
1
2
3 #include <t_services.h>
4 #include <s_services.h>
5 #include "kernel_id.h"
6 #include "rx_if.h"
7 #include <cdefBF533.h>
8
9
10 #define PEEPINGTEST             // Define PEEPING test to see the top 4 of FIFO after enabling SPORT RX
11
12 #ifdef PEEPINGTEST
13 #define SLEEPDURATION 1000
14 #else
15 #define SLEEPDURATION 10
16 #endif
17
18 struct dma_descripter{
19     struct dma_descripter * next_descripter;
20     unsigned int * start_address;
21     unsigned short config;
22     unsigned short x_count;
23     unsigned short x_modify;
24 };
25
26 static struct dma_descripter rx_dma_dsc[2];
27
28 unsigned int rxif_buffer[2][RXIF_BUFSIZE];
29
30 /*
31  *  RX_IF受信データの処理タスク。
32  */
33 void rx_if_task(VP_INT exinf)
34 {
35
36     vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG));
37     syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (INT) exinf);
38
39     syscall(serial_ctl_por(TASK_PORTID,
40             (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));
41
42
43
44     syscall(ena_int(INTNO_SPORT0_RX));
45
46     *pSPORT0_TCR1 =
47             0 << 14 |   // TCKFE,   0:sample at down edge, 1:sample at up edge
48             0 << 13 |   // LATFS,   0:early frame sync, 1:late frame sync
49             0 << 12 |   // LTFS,    0:Active high TFS, 1:Active low TFS
50             0 << 11 |   // DITFS,   0:data dependent TFS generation, 1:data independent TFS generation
51             0 << 10 |   // TFSR,    0:TFS is not required every word, 1:TFS is required every word
52             0 << 9  |   // ITFS,    0:external TFS, 1:internal TFS
53             0 << 4  |   // TLSBIT,  0:MSB first transmission, 1:LSB first transmission
54             0 << 2  |   // TDTYPE   0:normal, 1:reserved, 2:u-law, 3:a-law
55             0 << 1  |   // ITCLK,   0:external clock generation, 1:internal clock generation
56             0 << 0  ;   // TSPEN    0:Tx disable, 1:Tx enable
57
58     *pSPORT0_TCR2 =
59             0 << 10 |   // TRFST,   0:left streo ch first, 1:right stereo ch first
60             0 << 9  |   // TSFESE,  0:normal frame sync, 1:LR frame clock
61             0 << 8  |   // TXSE,    0:secondary ch disable, 1:secondary ch enable
62             0 << 0  ;   // SLEN     0-1:not allowed,2-31:Serial word length - 1
63
64
65     *pSPORT0_RCR1 =
66             0 << 14 |   // RCKFE,   0:sample at down edge, 1:sample at up edge
67             0 << 13 |   // LARFS,   0:early frame sync, 1:late frame sync
68             0 << 12 |   // LRFS,    0:Active high RFS, 1:Active low RFS
69             1 << 10 |   // RFSR,    0:RFS is not required every word, 1:RFS is required every word
70             0 << 9  |   // IRFS,    0:external RFS, 1:internal RFS
71             0 << 4  |   // RLSBIT,  0:MSB first transmission, 1:LSB first transmission
72             0 << 2  |   // RDTYPE   0:zero fill, 1:sign extend, 2:u-law, 3:a-law
73             0 << 1  |   // IRCLK,   0:external clock generation, 1:internal clock generation
74             0 << 0  ;   // RSPEN    0:Rx disable, 1:Rx enable
75
76     *pSPORT0_RCR2 =
77             0 << 10 |   // RRFST,   0:left streo ch first, 1:right stereo ch first
78             0 << 9  |   // RSFESE,  0:normal frame sync, 1:LR frame clock
79             1 << 8  |   // RXSE,    0:secondary ch disable, 1:secondary ch enable
80            29 << 0  ;   // SLEN     0-1:not allowed,2-31:Serial word length - 1
81     ssync();
82
83
84
85         // 受信DMAデスクリプタを作る
86     rx_dma_dsc[0].next_descripter = &rx_dma_dsc[1];
87     rx_dma_dsc[0].start_address = rxif_buffer[0];
88     rx_dma_dsc[0].x_count = RXIF_BUFSIZE;
89     rx_dma_dsc[0].x_modify = sizeof(rxif_buffer[0][0]);
90     rx_dma_dsc[0].config =
91             FLOW_LARGE      |   // FLOW,    0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
92             NDSIZE_7        |   // NDSIZE,  the # of element of the next descripter to fetch
93             1 << DI_EN_P    |   // DI_EN,   0:No interrupt at the end, 1:Interrupt at the end
94             0 << DI_SEL_P   |   // DI_SEL,  0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
95             0 << RESTART_P  |   // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
96             0 << DMA2D_P    |   // DMA2D,   0:Linear DMA, 1:2D DMA
97             WDSIZE_32       |   // WDSIZE,  0:8bit, 1:16bit, 2:32bit,3:reserved
98             1 << WNR_P      |   // WNR,     0:Read from memory, 1:Write to Memory
99             1 << 0          ;   // DMA_EN,  0:Disable DMA, 1:Enable DMA
100
101     rx_dma_dsc[1].next_descripter = &rx_dma_dsc[0];
102     rx_dma_dsc[1].start_address = rxif_buffer[1];
103     rx_dma_dsc[1].x_count = RXIF_BUFSIZE;
104     rx_dma_dsc[1].x_modify = sizeof(rxif_buffer[1][0]);
105     rx_dma_dsc[1].config =
106             FLOW_LARGE      |   // FLOW,    0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
107             NDSIZE_7        |   // NDSIZE,  the # of element of the next descripter to fetch
108             1 << DI_EN_P    |   // DI_EN,   0:No interrupt at the end, 1:Interrupt at the end
109             0 << DI_SEL_P   |   // DI_SEL,  0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
110             0 << RESTART_P  |   // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
111             0 << DMA2D_P    |   // DMA2D,   0:Linear DMA, 1:2D DMA
112             WDSIZE_32       |   // WDSIZE,  0:8bit, 1:16bit, 2:32bit,3:reserved
113             1 << WNR_P      |   // WNR,     0:Read from memory, 1:Write to Memory
114             1 << 0          ;   // DMA_EN,  0:Disable DMA, 1:Enable DMA
115
116         // DMAコントローラの初期状態設定
117         // ここではDMAをイネーブルにしない。また、バッファクリアする
118     *pDMA1_CONFIG =
119             FLOW_LARGE      |   // FLOW,    0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
120             NDSIZE_7        |   // NDSIZE,  the # of element of the next descripter to fetch
121             1 << DI_EN_P    |   // DI_EN,   0:No interrupt at the end, 1:Interrupt at the end
122             0 << DI_SEL_P   |   // DI_SEL,  0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
123             1 << RESTART_P  |   // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
124             0 << DMA2D_P    |   // DMA2D,   0:Linear DMA, 1:2D DMA
125             WDSIZE_32       |   // WDSIZE,  0:8bit, 1:16bit, 2:32bit,3:reserved
126             1 << WNR_P      |   // WNR,     0:Read from memory, 1:Write to Memory
127             0 << 0          ;   // DMA_EN,  0:Disable DMA, 1:Enable DMA
128     *pDMA1_NEXT_DESC_PTR = &rx_dma_dsc[0];
129
130
131 #ifndef PEEPINGTEST
132     int count = 0, event = 0;
133 #endif
134
135
136         // RX受信を開始する
137     *pDMA1_CONFIG |= DMAEN;
138
139     *pSPORT0_RCR1 |= RSPEN;     // RX SPORT Enable
140     ssync();
141
142     int count = 0;
143
144     /*
145      *  メインループ
146      */
147     do {
148         long int rx[4];
149
150             // SPORT0受信DMAがバッファを埋めるのを待つ。
151         syscall(wai_sem(SEM_SPORT0_RX));
152
153         count++;
154         if ( count > 31500/(RXIF_BUFSIZE/4))
155         {
156             count = 0;
157                 // FIFOにデータがたまったはずである。
158                 // FIFOデータを読みだして下位2bitのみ表示する
159             rx[0] = rxif_buffer[0][0];    // 下位2bitのみ抽出
160             rx[1] = rxif_buffer[0][1];    // 下位2bitのみ抽出
161             rx[2] = rxif_buffer[0][2];    // 下位2bitのみ抽出
162             rx[3] = rxif_buffer[0][3];    // 下位2bitのみ抽出
163
164             syslog( LOG_NOTICE, "RX word : %08x,%08x,%08x,%08x", rx[0], rx[1], rx[2], rx[3] );
165
166         }
167
168
169
170
171
172     } while (1);
173
174     syslog(LOG_NOTICE, "Sample program ends.");
175     kernel_exit();
176 }
177
178
179 void sport0_rx_int_handler(void)
180 {
181         // DMA割り込みをクリアする。
182     *pDMA1_IRQ_STATUS = DMA_DONE;
183
184         // ペリフェラルへの書き込みを待つ。
185     ssync();
186
187         // タスクにSPORT0受信DMAのバッファが埋まったと知らせる。
188     isig_sem(SEM_SPORT0_RX);
189
190
191 }
192
193 void sport0_tx_int_handler(void)
194 {
195     *pDMA2_IRQ_STATUS = DMA_DONE;
196     ssync();
197
198
199 }
200
201
202 void init_peripherals(VP_INT p)
203 {
204     *pSPORT0_TCR1 = 0;
205     *pSPORT0_RCR1 = 0;
206     *pDMA1_CONFIG = 0;
207     *pDMA2_CONFIG = 0;
208     ssync();
209
210     return;
211 }