Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / apps / burn_dbsrx_eeprom.c
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "u2_init.h"
24 #include "i2c.h"
25 #include "usrp2_i2c_addr.h"
26 #include "mdelay.h"
27 #include "hal_io.h"
28 #include "nonstdio.h"
29 #include "bool.h"
30
31
32
33 int read_dboard_eeprom(int i2c_addr);
34
35
36 #define USRP_DBID_DBS_RX                 0x0002
37 #define USRP_DBID_DBS_RX_WITH_CLOCK_MOD  0x000d
38
39 const char dbs_rx_rev2_eeprom[] = {
40   0xdb, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18
44 };
45
46 #define LED_VALS   (LED_A | LED_B | LED_C | LED_D)
47 #define LED_MASK   (LED_A | LED_B | LED_C | LED_D)
48
49 int
50 main(void)
51 {
52   u2_init();
53
54   puts("\nburn_dbsrx_eeprom\n");
55
56   hal_set_leds(0, ~0);  // all off
57
58   int i2c_addr = I2C_ADDR_RX_A;
59   int dbid = read_dboard_eeprom(i2c_addr);
60   bool ok;
61   const char *msg = 0;
62
63   switch (dbid){
64   case -1:
65     msg = "No RX daughterboard found";
66     goto bad;
67
68   case -2:
69     msg = "Invalid RX EEPROM contents";
70     goto bad;
71
72   case USRP_DBID_DBS_RX_WITH_CLOCK_MOD:
73     msg = "RX Daughterboard already reports being a DBS RX w/ CLOCK_MOD";
74     goto good;
75
76   case USRP_DBID_DBS_RX:
77     // Says it's a DBS_RX, attempt to burn the EEPROM
78     ok = eeprom_write(i2c_addr, 0,
79                       dbs_rx_rev2_eeprom, sizeof(dbs_rx_rev2_eeprom));
80     if (ok){
81       msg = "Successfully programmed db as DBS RX Rev 2.1";
82       goto good;
83     }
84     else {
85       msg = "Failed to write daugherboard eeprom";
86       goto bad;
87     }
88
89   default:
90     msg = "Daughterboard is not a DBS RX; ignored";
91     goto bad;
92   }
93   
94  good:
95   puts(msg);
96   hal_set_leds(LED_VALS, LED_MASK);
97   while (1)
98     ;
99
100  bad:
101   puts(msg);
102   while(1){
103     hal_toggle_leds(LED_VALS);
104     mdelay(50);
105   }
106 }