IBASE SMARC Evaluation Kit User Manual
Page 73
Copyright © 2013 IBASE Technology Inc. All Rights Reserved.
47
IBASE Technology Inc.
char *end;
const char *maskp = NULL;
int res, i2cbus, address, size, file;
int value, daddress, vmask = 0;
char filename[20];
int pec = 0;
int flags = 0;
int force = 0, yes = 0, version = 0, readback = 0;
unsigned char block[I2C_SMBUS_BLOCK_MAX];
int len;
/* handle (optional) flags first */
while (1+flags < argc && argv[1+flags][0] == '-') {
switch (argv[1+flags][1]) {
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
case 'm':
if (2+flags < argc)
maskp = argv[2+flags];
flags++;
break;
case 'r': readback = 1; break;
default:
fprintf(stderr, "Error: Unsupported option "
"\"%s\"!\n", argv[1+flags]);
help();
exit(1);
}
flags++;
}
if (version) {
fprintf(stderr, "i2cset version %s\n", VERSION);
exit(0);
}
if (argc < flags + 4)
help();
i2cbus = lookup_i2c_bus(argv[flags+1]);
if (i2cbus < 0)
help();
address = parse_i2c_address(argv[flags+2]);
if (address < 0)
help();
daddress = strtol(argv[flags+3], &end, 0);
if (*end || daddress < 0 || daddress > 0xff) {
fprintf(stderr, "Error: Data address invalid!\n");
help();
}
/* check for command/mode */
if (argc == flags + 4) {
/* Implicit "c" */
size = I2C_SMBUS_BYTE;
} else if (argc == flags + 5) {
/* "c", "cp", or implicit "b" */
if (!strcmp(argv[flags+4], "c")
|| !strcmp(argv[flags+4], "cp")) {
size = I2C_SMBUS_BYTE;
pec = argv[flags+4][1] == 'p';
} else {
size = I2C_SMBUS_BYTE_DATA;
}
} else {
/* All other commands */
if (strlen(argv[argc-1]) > 2
|| (strlen(argv[argc-1]) == 2 && argv[argc-1][1] != 'p')) {