Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / apps / burnrev40.c
1 /*
2  * Copyright 2007,2008 Free Software Foundation, Inc.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include "u2_init.h"
23 #include "memory_map.h"
24 #include "spi.h"
25 #include "hal_io.h"
26 #include "buffer_pool.h"
27 #include "pic.h"
28 #include "bool.h"
29 #include "ethernet.h"
30 #include "nonstdio.h"
31 #include "usrp2_eth_packet.h"
32 #include "dbsm.h"
33 #include "app_common_v2.h"
34 #include "memcpy_wa.h"
35 #include <stddef.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <i2c.h>
39 #include <usrp2_i2c_addr.h>
40 #include <clocks.h>
41 #include "sd.h"
42 #include "mdelay.h"
43
44 #define HW_REV_MAJOR 4
45 #define HW_REV_MINOR 0
46
47 int test_ram()
48 {
49   int i,j,k;
50   output_regs->ram_page = 1<<10;
51   
52   extram[0] = 0xDEADBEEF;
53   extram[1] = 0xF00D1234;
54   extram[7] = 0x76543210;
55   
56   output_regs->ram_page = 2<<10;
57   extram[7] = 0x55555555;
58   extram[1] = 0xaaaaaaaa;
59   extram[0] = 0xeeeeeeee;
60   
61   output_regs->ram_page = 1<<10;
62   
63   i = extram[0];
64   k = extram[1];
65   j = extram[7];
66   
67   if((i != 0xDEADBEEF)||(j!=0x76543210)||(k!=0xF00D1234)) {
68     puts("RAM FAIL1!\n");
69     puthex32_nl(i);
70     puthex32_nl(j);
71     puthex32_nl(k);
72     return 0;
73   }
74   
75   output_regs->ram_page = 2<<10;
76
77   j = extram[7];
78   k = extram[1];
79   i = extram[0];
80
81   if((i != 0xeeeeeeee)||(j!=0x55555555)||(k!=0xaaaaaaaa)) {
82     puts("RAM FAIL2!\n");
83     puthex32_nl(i);
84     puthex32_nl(j);
85     puthex32_nl(k);
86     return 0;
87   }
88   return 1;
89 }
90
91 int test_sd()
92 {
93   int i = sd_init();
94   if(i==0) {
95     puts("FAILED INIT of Card\n");
96     return 0;
97   }
98   
99   unsigned char buf[512];
100   i = sd_read_block(2048,buf);
101   if(i == 0) {
102     puts("READ Command Rejected\n");
103     return 0;
104   }
105   if((buf[0]==0xb8)&&(buf[1]==0x08)&&(buf[2]==0x00)&&(buf[3]==0x50))
106     ;
107   else {
108     puts("Read bad data from SD Card\n");
109     return 0;
110   }
111   return 1;
112 }
113
114 int
115 main(void)
116 {
117   u2_init();
118
119   putstr("\nFactory Test, Board Rev 4.0\n");
120
121   bool ok = true;
122   unsigned char maj = HW_REV_MAJOR;
123   unsigned char min = HW_REV_MINOR;
124   ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_REV_MSB, &maj, 1);
125   ok &= eeprom_write(I2C_ADDR_MBOARD, MBOARD_REV_LSB, &min, 1);
126
127   putstr("\nset_hw_rev\n");
128   if (ok)
129     printf("OK: set h/w rev to %d.%d\n", HW_REV_MAJOR, HW_REV_MINOR);
130   else {
131     printf("FAILED to set h/w rev to %d.%d\n", HW_REV_MAJOR, HW_REV_MINOR);
132     hal_finish();
133     return 0;
134   }
135
136   if(test_sd())
137     puts("SD OK\n");
138   else {
139     puts("SD FAIL\n");
140     //hal_finish();
141     //return 0;
142   }
143   if(test_ram())
144     puts("RAM OK\n");
145   else {
146     puts("RAM FAIL\n");
147     hal_finish();
148     return 0;
149   }
150
151   print_mac_addr(ethernet_mac_addr()->addr);
152   newline();
153
154   clocks_mimo_config(MC_WE_LOCK_TO_SMA);
155
156   while (!clocks_lock_detect()) {
157     puts("No Lock");
158     mdelay(1000);
159   }
160   puts("Clock Locked\n");
161
162 }