OSDN Git Service

SPORT RXの試験。FPGAとの通信に成功した。
[trx-305dsp/dsp.git] / trx305 / test.c
1
2
3 #include <t_services.h>
4 #include "kernel_id.h"
5 #include "test.h"
6 #include <cdefBF533.h>
7
8 /*
9  *  並行実行されるタスクへのメッセージ領域
10  */
11 char    message[3];
12
13 /*
14  *  ループ回数
15  */
16 UW  task_loop;      /* タスク内でのループ回数 */
17 UW  tex_loop;       /* 例外処理ルーチン内でのループ回数 */
18
19 /*
20  *  並行実行されるタスク
21  */
22 void task(VP_INT exinf)
23 {
24     INT     n = 0;
25     INT     tskno = (INT) exinf;
26
27         syslog(LOG_NOTICE, "task%d is running (%03d).   %s",
28                     tskno, ++n);
29
30 }
31
32 /*
33  *  並行して実行されるタスク用のタスク例外処理ルーチン
34  */
35 void tex_routine(TEXPTN texptn, VP_INT exinf)
36 {
37     INT tskno = (INT) exinf;
38
39     syslog(LOG_NOTICE, "task%d receives exception 0x%04x. ",
40                     tskno, texptn);
41
42  }
43
44 /*
45  *  CPU例外ハンドラ
46  */
47 #ifdef CPUEXC1
48
49 void
50 cpuexc_handler(VP p_excinf)
51 {
52
53     syslog(LOG_NOTICE, "CPU exception handler (p_excinf = %08p).",
54                             p_excinf);
55
56 }
57
58 #endif /* CPUEXC1 */
59
60 /*
61  *  周期ハンドラ
62  *
63  *  HIGH_PRIORITY,MID_PRIORITY,LOW_PRIORITY の各優先度のレディキュー
64  *  を回転させる.
65  */
66 void cyclic_handler(VP_INT exinf)
67 {
68
69 }
70
71 /*
72  *  メインタスク
73  */
74 void main_task(VP_INT exinf)
75 {
76     unsigned short dummy;
77
78     vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG));
79     syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (INT) exinf);
80
81     syscall(serial_ctl_por(TASK_PORTID,
82             (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));
83
84     /*
85      *  タスクの起動
86     act_tsk(TASK1);
87     act_tsk(TASK2);
88     act_tsk(TASK3);
89      */
90
91     *pSPORT0_TCR1 =
92             0 << 14 |   // TCKFE,   0:sample at down edge, 1:sample at up edge
93             0 << 13 |   // LATFS,   0:early frame sync, 1:late frame sync
94             0 << 12 |   // LTFS,    0:Active high TFS, 1:Active low TFS
95             0 << 11 |   // DITFS,   0:data dependent TFS generation, 1:data independent TFS generation
96             0 << 10 |   // TFSR,    0:TFS is not required every word, 1:TFS is required every word
97             0 << 9  |   // ITFS,    0:external TFS, 1:internal TFS
98             0 << 4  |   // TLSBIT,  0:MSB first transmission, 1:LSB first transmission
99             0 << 2  |   // TDTYPE   0:normal, 1:reserved, 2:u-law, 3:a-law
100             0 << 1  |   // ITCLK,   0:external clock generation, 1:internal clock generation
101             0 << 0  ;   // TSPEN    0:Tx disable, 1:Tx enable
102
103     *pSPORT0_TCR2 =
104             0 << 10 |   // TRFST,   0:left streo ch first, 1:right stereo ch first
105             0 << 9  |   // TSFESE,  0:normal frame sync, 1:LR frame clock
106             0 << 8  |   // TXSE,    0:secondary ch disable, 1:secondary ch enable
107             0 << 0  ;   // SLEN     0-1:not allowed,2-31:Serial word length - 1
108
109
110     *pSPORT0_RCR1 =
111             0 << 14 |   // RCKFE,   0:sample at down edge, 1:sample at up edge
112             0 << 13 |   // LARFS,   0:early frame sync, 1:late frame sync
113             0 << 12 |   // LRFS,    0:Active high RFS, 1:Active low RFS
114             1 << 10 |   // RFSR,    0:RFS is not required every word, 1:RFS is required every word
115             0 << 9  |   // IRFS,    0:external RFS, 1:internal RFS
116             0 << 4  |   // RLSBIT,  0:MSB first transmission, 1:LSB first transmission
117             0 << 2  |   // RDTYPE   0:zero fill, 1:sign extend, 2:u-law, 3:a-law
118             0 << 1  |   // IRCLK,   0:external clock generation, 1:internal clock generation
119             0 << 0  ;   // RSPEN    0:Rx disable, 1:Rx enable
120
121     *pSPORT0_RCR2 =
122             0 << 10 |   // RRFST,   0:left streo ch first, 1:right stereo ch first
123             0 << 9  |   // RSFESE,  0:normal frame sync, 1:LR frame clock
124             1 << 8  |   // RXSE,    0:secondary ch disable, 1:secondary ch enable
125            29 << 0  ;   // SLEN     0-1:not allowed,2-31:Serial word length - 1
126     ssync();
127
128     /*
129     syslog( LOG_NOTICE, "SPORT0_Disable " );
130     syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
131     syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
132
133     syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
134 */
135
136     int count = 0, event = 0;
137
138
139         // RX FIFOが空になるまで読み捨てる
140     while( *pSPORT0_STAT & RXNE)
141         dummy = *pSPORT0_RX32;
142 /*
143         *pSPORT0_RCR1 &= ~RSPEN;     // RX SPORT disable
144         syslog( LOG_NOTICE, "FIFO Cleared. FIFO must be empty");
145         syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
146 */
147     /*
148      *  メインループ
149      */
150     do {
151         long int rx[4];
152
153             // RX受信を開始する
154         *pSPORT0_RCR1 |= RSPEN;     // RX SPORT Enable
155         ssync();
156         /*
157         syslog( LOG_NOTICE, "SPORT0_Enabled" );
158         syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
159         syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
160 */
161             // 3mS スリープ
162         tslp_tsk(3);
163
164             // FIFOにデータがたまったはずである。
165         /*
166         syslog( LOG_NOTICE, "SPORT0_Disabled. FIFO must be full " );
167         syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
168         syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
169
170         syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
171 */
172             // FIFOデータを読みだして下位2bitのみ表示する
173         rx[0] = *pSPORT0_RX32 & 0x3;    // 下位2bitのみ抽出
174         rx[1] = *pSPORT0_RX32 & 0x3;    // 下位2bitのみ抽出
175         rx[2] = *pSPORT0_RX32 & 0x3;    // 下位2bitのみ抽出
176         rx[3] = *pSPORT0_RX32 & 0x3;    // 下位2bitのみ抽出
177         *pSPORT0_RCR1 &= ~RSPEN;     // RX SPORT disable
178   //      syslog( LOG_NOTICE, "FIFO Read. FIFO must be empty");
179         if (rx[0] !=0)
180         {
181             event ++;
182             syslog( LOG_NOTICE, "RX word : %d,%d,%d,%d", rx[0], rx[1], rx[2], rx[3] );
183         }
184         count++;
185         if (!( count % 1000 ))
186             syslog( LOG_NOTICE, "trial : %d, event : %d", count, event);
187     //    syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
188  //       syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
189    //     syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
190
191             // RX受信を終了する。FIFOにはデータがたまっているはずである。
192         *pSPORT0_RCR1 &= ~RSPEN;     // RX SPORT disable
193         ssync();
194         /*
195         syslog( LOG_NOTICE, "SPORT0 dsiabled");
196         syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
197         syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
198         syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
199 */
200             // 1秒スリープ
201         tslp_tsk(10);
202
203             // RX FIFOが空になるまで読み捨てる
204         while( *pSPORT0_STAT & RXNE)
205             dummy = *pSPORT0_RX32;
206
207
208     } while (1);
209
210     syslog(LOG_NOTICE, "Sample program ends.");
211     kernel_exit();
212 }