Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / apps / ibs_tx_test.c
1 #include "u2_init.h"
2 #include "memory_map.h"
3 #include "spi.h"
4 #include "hal_io.h"
5 #include "buffer_pool.h"
6 #include "nonstdio.h"
7
8 // Globals
9 #define EMPTY 0
10 #define FILLING 1
11 #define FULL 2
12 #define EMPTYING 3
13
14 #define PORT 2    // ethernet = 2, serdes = 0
15 int dsp_rx_buf, dsp_tx_buf, serdes_rx_buf, serdes_tx_buf;
16 int dsp_rx_idle, dsp_tx_idle, serdes_rx_idle, serdes_tx_idle;
17
18 int buffer_state[4];
19
20 static void
21 wait_until_status_nonzero(void)
22 {
23   while (buffer_pool_status->status == 0)
24     ;
25 }
26
27 int
28 main(void)
29 {
30   int i;
31   
32   u2_init();
33   
34   dsp_tx_regs->freq = 0;
35   dsp_tx_regs->scale_iq = (1 << 16) | 1;
36   dsp_tx_regs->interp_rate = 8;
37
38   // Write data to be sent into the first buffer
39   volatile unsigned int *buffer0 = buffer_ram(0);
40   volatile unsigned int *buffer1 = buffer_ram(1);
41   
42
43   putstr("Starting to fill in RAM\n");
44   for(i=0;i<512;i++) 
45     buffer0[i] = i;
46   putstr("Filled in RAM\n");
47   
48   buffer0[0] = 7; // start and end of buffer, send immediately
49   buffer0[1] = 0x0000;  // start time
50   bp_clear_buf(0);
51   bp_send_from_buf(0, 1, 1, 0, 9);
52   while (buffer_pool_status->status == 0)
53     ;
54   while(timer_regs -> time < 0x6000)
55     {}
56
57   buffer0[0] = 3; // start and end of buffer
58   buffer0[1] = 0x8000;  // start time
59   bp_clear_buf(0);
60   bp_send_from_buf(0, 1, 1, 0, 9);
61   while (buffer_pool_status->status == 0)
62     ;
63   while(timer_regs -> time < 0x8400)
64     {}
65
66   buffer0[0] = 3; // start and end of buffer
67   buffer0[1] = 0x8800;  // start time
68   bp_clear_buf(0);
69   bp_send_from_buf(0, 1, 1, 0, 9);
70   while (buffer_pool_status->status == 0)
71     ;
72   while(timer_regs -> time < 0x9000)
73     {}
74
75   buffer0[0] = 0x2;  // not last
76   buffer0[1] = 0x9100;  // start time
77   bp_clear_buf(0);
78   bp_send_from_buf(0, 1, 1, 0, 9);
79   while (buffer_pool_status->status == 0)
80     ;
81   buffer0[0] = 0x1;  // last
82   buffer0[1] = 0x0000;  // start time
83   bp_clear_buf(0);
84   bp_send_from_buf(0, 1, 1, 0, 9);
85   while (buffer_pool_status->status == 0)
86     ;
87
88   
89   buffer0[0] = 0x3;  // first and last
90   buffer0[1] = 0x8000;  // Time in the past
91   bp_clear_buf(0);
92   bp_send_from_buf(0, 1, 1, 0, 9);
93   while (buffer_pool_status->status == 0)
94     ;
95
96   /*
97   buffer0[0] = 0x2; // not last
98   buffer0[1] = 0x9600;  // start time
99   bp_clear_buf(0);
100   bp_send_from_buf(0, 1, 1, 0, 9);
101   while (buffer_pool_status->status == 0)
102     ;
103   */
104
105   while(timer_regs -> time < 0xa000)
106     {}
107
108   putstr("Done\n");
109
110   while(1)
111     {}
112   hal_finish();
113   
114   // Send a bunch, let them pile up in FIFO
115   bp_send_from_buf(0, 2, 1, 21, 80);    wait_until_status_nonzero();
116   bp_clear_buf(0);
117   putstr("First add'l TX done\n");
118   bp_send_from_buf(0, 2, 1, 81, 288);   wait_until_status_nonzero();
119   bp_clear_buf(0);
120   bp_send_from_buf(0, 2, 1, 289, 292);  wait_until_status_nonzero();
121   bp_clear_buf(0);
122   bp_send_from_buf(0, 2, 1, 293, 326);  wait_until_status_nonzero();
123   bp_clear_buf(0);
124   bp_send_from_buf(0, 2, 1, 327, 399);  wait_until_status_nonzero();
125   bp_clear_buf(0);
126   bp_send_from_buf(0, 2, 1, 400, 511);  wait_until_status_nonzero();
127   bp_clear_buf(0);
128   putstr("All add'l TX done\n");
129   
130   bp_receive_to_buf(1, 2, 1, 21, 80);   wait_until_status_nonzero();
131   bp_clear_buf(1);
132   putstr("First add'l RX done\n");
133   bp_receive_to_buf(1, 2, 1, 81, 288);  wait_until_status_nonzero();
134   bp_clear_buf(1);
135   bp_receive_to_buf(1, 2, 1, 289, 292); wait_until_status_nonzero();
136   bp_clear_buf(1);
137   bp_receive_to_buf(1, 2, 1, 293, 326); wait_until_status_nonzero();
138   bp_clear_buf(1);
139   bp_receive_to_buf(1, 2, 1, 327, 399); wait_until_status_nonzero();
140   bp_clear_buf(1);
141   bp_receive_to_buf(1, 2, 1, 400, 511); wait_until_status_nonzero();
142   bp_clear_buf(1);
143   putstr("All add'l RX done\n");
144
145   for(i=0;i<512;i++)
146     if(buffer0[i] != buffer1[i]) {
147       putstr("ERROR at location: ");
148       puthex_nl(i);
149       putstr("Value sent: ");
150       puthex_nl(buffer0[i]);
151       putstr("Value rcvd: ");
152       puthex_nl(buffer1[i]);
153       //break;
154     }
155   
156   putstr("Done Testing\n");
157   
158   hal_finish();
159   return 1;
160 }