IBASE MRS-801-RE User Manual

Page 83

Advertising
background image

Copyright © 2013 IBASE Technology Inc. All Rights Reserved.

75

IBASE Technology Inc.

/* Walk the list of i2c busses, looking for the one with the

right name */

for (i = 0; adapters[i].name; i++) {

if (strcmp(adapters[i].name, bus_name) == 0) {

if (i2cbus >= 0) {

fprintf(stderr,

"Error: I2C bus name is not unique!\n");

i2cbus = -4;

goto done;

}

i2cbus = adapters[i].nr;

}

}

if (i2cbus == -1)

fprintf(stderr, "Error: I2C bus name doesn't match any "

"bus present!\n");

done:

free_adapters(adapters);

return i2cbus;

}

/*

* Parse an I2CBUS command line argument and return the corresponding

* bus number, or a negative value if the bus is invalid.

*/

int lookup_i2c_bus(const char *i2cbus_arg)

{

unsigned long i2cbus;

char *end;

i2cbus = strtoul(i2cbus_arg, &end, 0);

if (*end || !*i2cbus_arg) {

/* Not a number, maybe a name? */

return lookup_i2c_bus_by_name(i2cbus_arg);

}

if (i2cbus > 0xFFFFF) {

Advertising