OSDN Git Service

アプリケーションをビルド可能になるよう調整。また、
[trx-305dsp/dsp.git] / trx305 / rx_if.c
1
2
3 #include <t_services.h>
4 #include "kernel_id.h"
5 #include "rx_if.h"
6 #include <cdefBF533.h>
7
8
9 #define PEEPINGTEST             // Define PEEPING test to see the top 4 of FIFO after enabling SPORT RX
10
11 #ifdef PEEPINGTEST
12 #define SLEEPDURATION 2000
13 #else
14 #define SLEEPDURATION 10
15 #endif
16
17 struct dma_descripter{
18     struct dma_descripter * next_descripter;
19     unsigned int * start_address;
20     unsigned short config;
21     unsigned short x_count;
22     unsigned short x_modify;
23 };
24
25 struct dma_descripter rx_dma_dsc0, rx_dma_dsc1;
26
27 #define BUFSIZE 64
28 unsigned int dummy_buffer0[BUFSIZE], dummy_buffer1[BUFSIZE];
29
30 /*
31  *  メインタスク
32  */
33 void main_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     act_tsk(TASK1);
45     act_tsk(TASK2);
46     act_tsk(TASK3);
47      */
48
49     *pSPORT0_TCR1 =
50             0 << 14 |   // TCKFE,   0:sample at down edge, 1:sample at up edge
51             0 << 13 |   // LATFS,   0:early frame sync, 1:late frame sync
52             0 << 12 |   // LTFS,    0:Active high TFS, 1:Active low TFS
53             0 << 11 |   // DITFS,   0:data dependent TFS generation, 1:data independent TFS generation
54             0 << 10 |   // TFSR,    0:TFS is not required every word, 1:TFS is required every word
55             0 << 9  |   // ITFS,    0:external TFS, 1:internal TFS
56             0 << 4  |   // TLSBIT,  0:MSB first transmission, 1:LSB first transmission
57             0 << 2  |   // TDTYPE   0:normal, 1:reserved, 2:u-law, 3:a-law
58             0 << 1  |   // ITCLK,   0:external clock generation, 1:internal clock generation
59             0 << 0  ;   // TSPEN    0:Tx disable, 1:Tx enable
60
61     *pSPORT0_TCR2 =
62             0 << 10 |   // TRFST,   0:left streo ch first, 1:right stereo ch first
63             0 << 9  |   // TSFESE,  0:normal frame sync, 1:LR frame clock
64             0 << 8  |   // TXSE,    0:secondary ch disable, 1:secondary ch enable
65             0 << 0  ;   // SLEN     0-1:not allowed,2-31:Serial word length - 1
66
67
68     *pSPORT0_RCR1 =
69             0 << 14 |   // RCKFE,   0:sample at down edge, 1:sample at up edge
70             0 << 13 |   // LARFS,   0:early frame sync, 1:late frame sync
71             0 << 12 |   // LRFS,    0:Active high RFS, 1:Active low RFS
72             1 << 10 |   // RFSR,    0:RFS is not required every word, 1:RFS is required every word
73             0 << 9  |   // IRFS,    0:external RFS, 1:internal RFS
74             0 << 4  |   // RLSBIT,  0:MSB first transmission, 1:LSB first transmission
75             0 << 2  |   // RDTYPE   0:zero fill, 1:sign extend, 2:u-law, 3:a-law
76             0 << 1  |   // IRCLK,   0:external clock generation, 1:internal clock generation
77             0 << 0  ;   // RSPEN    0:Rx disable, 1:Rx enable
78
79     *pSPORT0_RCR2 =
80             0 << 10 |   // RRFST,   0:left streo ch first, 1:right stereo ch first
81             0 << 9  |   // RSFESE,  0:normal frame sync, 1:LR frame clock
82             1 << 8  |   // RXSE,    0:secondary ch disable, 1:secondary ch enable
83            29 << 0  ;   // SLEN     0-1:not allowed,2-31:Serial word length - 1
84     ssync();
85
86
87
88         // 受信DMAデスクリプタを作る
89     rx_dma_dsc0.next_descripter = &rx_dma_dsc1;
90     rx_dma_dsc0.start_address = dummy_buffer0;
91     rx_dma_dsc0.x_count = BUFSIZE;
92     rx_dma_dsc0.x_modify = sizeof(dummy_buffer0[0]);
93     rx_dma_dsc0.config =
94             7 <<12 |        // FLOW,    0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
95             7 << 8 |        // NDSIZE,  the # of element of the next descripter to fetch
96             0 << 7 |        // DI_EN,   0:No interrupt at the end, 1:Interrupt at the end
97             1 << 6 |        // DI_SEL,  0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
98             1 << 5 |        // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
99             0 << 4 |        // DMA2D,   0:Linear DMA, 1:2D DMA
100             2 << 2 |        // WDSIZE,  0:8bit, 1:16bit, 2:32bit,3:reserved
101             1 << 1 |        // WNR,     0:Read from memory, 1:Write to Memory
102             1 << 0 ;        // DMA_EN,  0:Disable DMA, 1:Enable DMA
103
104     rx_dma_dsc1.next_descripter = &rx_dma_dsc0;
105     rx_dma_dsc1.start_address = dummy_buffer1;
106     rx_dma_dsc1.x_count = BUFSIZE;
107     rx_dma_dsc1.x_modify = sizeof(dummy_buffer1[0]);
108     rx_dma_dsc1.config =
109             7 <<12 |        // FLOW,    0:Stop, 1:Auto buffer, 4:Desc array, 6:Desc List small, 7:Desc, List, Large
110             7 << 8 |        // NDSIZE,  the # of element of the next descripter to fetch
111             0 << 7 |        // DI_EN,   0:No interrupt at the end, 1:Interrupt at the end
112             1 << 6 |        // DI_SEL,  0:Interrupt at the end of outer loop, 1:Interrupt at the end of inter loop
113             1 << 5 |        // RESTART, 0:Keep DMA FIFO before start, 1:Purge DMA FIFO before start
114             0 << 4 |        // DMA2D,   0:Linear DMA, 1:2D DMA
115             2 << 2 |        // WDSIZE,  0:8bit, 1:16bit, 2:32bit,3:reserved
116             1 << 1 |        // WNR,     0:Read from memory, 1:Write to Memory
117             1 << 0 ;        // DMA_EN,  0:Disable DMA, 1:Enable DMA
118
119
120
121 #ifndef PEEPINGTEST
122     int count = 0, event = 0;
123 #endif
124
125
126         // RX受信を開始する
127     *pDMA1_NEXT_DESC_PTR = & rx_dma_dsc0;
128     *pDMA1_CONFIG = rx_dma_dsc1.config;
129
130     *pSPORT0_RCR1 |= RSPEN;     // RX SPORT Enable
131     ssync();
132
133
134     /*
135      *  メインループ
136      */
137     do {
138         long int rx[4];
139
140             // 3mS スリープ
141         tslp_tsk(3);
142
143             // FIFOにデータがたまったはずである。
144             // FIFOデータを読みだして下位2bitのみ表示する
145         rx[0] = dummy_buffer0[0];    // 下位2bitのみ抽出
146         rx[1] = dummy_buffer0[1];    // 下位2bitのみ抽出
147         rx[2] = dummy_buffer0[2];    // 下位2bitのみ抽出
148         rx[3] = dummy_buffer0[3];    // 下位2bitのみ抽出
149
150 #ifndef PEEPINGTEST
151         *pSPORT0_RCR1 &= ~RSPEN;     // RX SPORT disable
152         if (rx[0] !=0)
153         {
154             event ++;
155 #endif
156             syslog( LOG_NOTICE, "RX word : %08x,%08x,%08x,%08x", rx[0], rx[1], rx[2], rx[3] );
157 #ifndef PEEPINGTEST
158         }
159         count++;
160         if (!( count % 1000 ))
161             syslog( LOG_NOTICE, "trial : %d, event : %d", count, event);
162 #endif
163             // スリープ
164         tslp_tsk(SLEEPDURATION);
165
166
167
168     } while (1);
169
170     syslog(LOG_NOTICE, "Sample program ends.");
171     kernel_exit();
172 }