Revision e4d3f63c host/lib/usrp/mboard_eeprom.cpp

b/host/lib/usrp/mboard_eeprom.cpp
1 1
//
2
// Copyright 2010-2011 Ettus Research LLC
2
// Copyright 2010-2012 Ettus Research LLC
3 3
//
4 4
// This program is free software: you can redistribute it and/or modify
5 5
// it under the terms of the GNU General Public License as published by
......
84 84
 **********************************************************************/
85 85
static const boost::uint8_t N100_EEPROM_ADDR = 0x50;
86 86

  
87
static const uhd::dict<std::string, boost::uint8_t> USRP_N100_OFFSETS = boost::assign::map_list_of
88
    ("hardware", 0x00)
89
    ("mac-addr", 0x02)
90
    ("ip-addr", 0x0C)
91
    //leave space here for other addresses (perhaps)
92
    ("revision", 0x12)
93
    ("product", 0x14)
94
    ("gpsdo", 0x17)
95
    ("serial", 0x18)
96
    ("name", 0x18 + SERIAL_LEN)
97
;
87
struct n100_eeprom_map{
88
    boost::uint16_t hardware;
89
    boost::uint8_t mac_addr[6];
90
    boost::uint32_t subnet;
91
    boost::uint32_t ip_addr;
92
    boost::uint16_t _pad0;
93
    boost::uint16_t revision;
94
    boost::uint16_t product;
95
    unsigned char _pad1;
96
    unsigned char gpsdo;
97
    unsigned char serial[SERIAL_LEN];
98
    unsigned char name[NAME_MAX_LEN];
99
    boost::uint32_t gateway;
100
};
98 101

  
99 102
enum n200_gpsdo_type{
100 103
    N200_GPSDO_NONE = 0,
......
105 108
static void load_n100(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){
106 109
    //extract the hardware number
107 110
    mb_eeprom["hardware"] = uint16_bytes_to_string(
108
        iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["hardware"], 2)
111
        iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, hardware), 2)
109 112
    );
110 113

  
111 114
    //extract the revision number
112 115
    mb_eeprom["revision"] = uint16_bytes_to_string(
113
        iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["revision"], 2)
116
        iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, revision), 2)
114 117
    );
115 118

  
116 119
    //extract the product code
117 120
    mb_eeprom["product"] = uint16_bytes_to_string(
118
        iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["product"], 2)
121
        iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, product), 2)
119 122
    );
120 123

  
121 124
    //extract the addresses
122 125
    mb_eeprom["mac-addr"] = mac_addr_t::from_bytes(iface.read_eeprom(
123
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["mac-addr"], 6
126
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, mac_addr), 6
124 127
    )).to_string();
125 128

  
126 129
    boost::asio::ip::address_v4::bytes_type ip_addr_bytes;
127
    byte_copy(iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["ip-addr"], 4), ip_addr_bytes);
130
    byte_copy(iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, ip_addr), 4), ip_addr_bytes);
128 131
    mb_eeprom["ip-addr"] = boost::asio::ip::address_v4(ip_addr_bytes).to_string();
129 132

  
133
    byte_copy(iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, subnet), 4), ip_addr_bytes);
134
    mb_eeprom["subnet"] = boost::asio::ip::address_v4(ip_addr_bytes).to_string();
135

  
136
    byte_copy(iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, gateway), 4), ip_addr_bytes);
137
    mb_eeprom["gateway"] = boost::asio::ip::address_v4(ip_addr_bytes).to_string();
138

  
130 139
    //gpsdo capabilities
131
    boost::uint8_t gpsdo_byte = iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["gpsdo"], 1).at(0);
140
    boost::uint8_t gpsdo_byte = iface.read_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, gpsdo), 1).at(0);
132 141
    switch(n200_gpsdo_type(gpsdo_byte)){
133 142
    case N200_GPSDO_INTERNAL: mb_eeprom["gpsdo"] = "internal"; break;
134 143
    case N200_GPSDO_ONBOARD: mb_eeprom["gpsdo"] = "onboard"; break;
......
137 146

  
138 147
    //extract the serial
139 148
    mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom(
140
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["serial"], SERIAL_LEN
149
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, serial), SERIAL_LEN
141 150
    ));
142 151

  
143 152
    //extract the name
144 153
    mb_eeprom["name"] = bytes_to_string(iface.read_eeprom(
145
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["name"], NAME_MAX_LEN
154
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, name), NAME_MAX_LEN
146 155
    ));
147 156

  
148 157
    //Empty serial correction: use the mac address to determine serial.
......
158 167
static void store_n100(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){
159 168
    //parse the revision number
160 169
    if (mb_eeprom.has_key("hardware")) iface.write_eeprom(
161
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["hardware"],
170
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, hardware),
162 171
        string_to_uint16_bytes(mb_eeprom["hardware"])
163 172
    );
164 173

  
165 174
    //parse the revision number
166 175
    if (mb_eeprom.has_key("revision")) iface.write_eeprom(
167
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["revision"],
176
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, revision),
168 177
        string_to_uint16_bytes(mb_eeprom["revision"])
169 178
    );
170 179

  
171 180
    //parse the product code
172 181
    if (mb_eeprom.has_key("product")) iface.write_eeprom(
173
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["product"],
182
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, product),
174 183
        string_to_uint16_bytes(mb_eeprom["product"])
175 184
    );
176 185

  
177 186
    //store the addresses
178 187
    if (mb_eeprom.has_key("mac-addr")) iface.write_eeprom(
179
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["mac-addr"],
188
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, mac_addr),
180 189
        mac_addr_t::from_string(mb_eeprom["mac-addr"]).to_bytes()
181 190
    );
182 191

  
183 192
    if (mb_eeprom.has_key("ip-addr")){
184 193
        byte_vector_t ip_addr_bytes(4);
185 194
        byte_copy(boost::asio::ip::address_v4::from_string(mb_eeprom["ip-addr"]).to_bytes(), ip_addr_bytes);
186
        iface.write_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["ip-addr"], ip_addr_bytes);
195
        iface.write_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, ip_addr), ip_addr_bytes);
196
    }
197

  
198
    if (mb_eeprom.has_key("subnet")){
199
        byte_vector_t ip_addr_bytes(4);
200
        byte_copy(boost::asio::ip::address_v4::from_string(mb_eeprom["subnet"]).to_bytes(), ip_addr_bytes);
201
        iface.write_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, subnet), ip_addr_bytes);
202
    }
203

  
204
    if (mb_eeprom.has_key("gateway")){
205
        byte_vector_t ip_addr_bytes(4);
206
        byte_copy(boost::asio::ip::address_v4::from_string(mb_eeprom["gateway"]).to_bytes(), ip_addr_bytes);
207
        iface.write_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, gateway), ip_addr_bytes);
187 208
    }
188 209

  
189 210
    //gpsdo capabilities
......
191 212
        boost::uint8_t gpsdo_byte = N200_GPSDO_NONE;
192 213
        if (mb_eeprom["gpsdo"] == "internal") gpsdo_byte = N200_GPSDO_INTERNAL;
193 214
        if (mb_eeprom["gpsdo"] == "onboard") gpsdo_byte = N200_GPSDO_ONBOARD;
194
        iface.write_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["gpsdo"], byte_vector_t(1, gpsdo_byte));
215
        iface.write_eeprom(N100_EEPROM_ADDR, offsetof(n100_eeprom_map, gpsdo), byte_vector_t(1, gpsdo_byte));
195 216
    }
196 217

  
197 218
    //store the serial
198 219
    if (mb_eeprom.has_key("serial")) iface.write_eeprom(
199
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["serial"],
220
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, serial),
200 221
        string_to_bytes(mb_eeprom["serial"], SERIAL_LEN)
201 222
    );
202 223

  
203 224
    //store the name
204 225
    if (mb_eeprom.has_key("name")) iface.write_eeprom(
205
        N100_EEPROM_ADDR, USRP_N100_OFFSETS["name"],
226
        N100_EEPROM_ADDR, offsetof(n100_eeprom_map, name),
206 227
        string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN)
207 228
    );
208 229
}

Also available in: Unified diff