static const unsigned int timeout = 1000;
+static int multBytes = 0;
+
+
void usage(const char *progName)
{
printf("Usage: %s [-h] [-d] [-b numBytes] [-d level] [-V] <COMMAND>\n",
printf("Options:\n");
printf(" -h give this help\n");
printf(" -s SPI Mode\n");
- printf(" -b number of bytes to be read 1..4\n");
+ printf(" -b number of bytes to be read 1..4 (default 1)\n");
printf(" -d turn on Debugging Information\n");
printf(" -V Version number\n");
printf("\nCommands:\n");
} I2C_STATUS_BITS;
static int readI2CRegister(uint16_t trb_address, int checkStatus,
- uint32_t* buffer, unsigned int bufferSize)
+ uint32_t* buffer, unsigned int bufferSize)
{
unsigned int ctr = 0;
int status;
error = 1;
}
}
-
+
+ if (multBytes == 1) {
+ if ((status = trb_register_read(trb_address, trb_i2c_register + 1,
+ buffer, BUFFER_SIZE)) == -1) {
+ trb_error("Error reading in multByte Mode");
+ return -1;
+ }
+ }
+
return error == 0 ? status : -1;
}
{
int i;
int spi_mode = 0;
- unsigned int num_bytes = 0;
+ unsigned int num_bytes = 1;
trb_debug = 0;
/* Parse Arguments */
break;
case 'b':
num_bytes = strtoul(optarg, NULL, 0);
- if (num_bytes > 4) {
+ if (!((num_bytes > 0) && (num_bytes <= 4))) {
usage(basename(argv[0]));
exit(EXIT_FAILURE);
}
+ multBytes = 1;
break;
case 'd':
trb_debug = strtoul(optarg, NULL, 0);
/* Read Value */
if (spi_mode == 0) {
- value = num_bytes == 0
+ value = multBytes == 0
? (0xff000000 | (i2c_chip << 16) | (i2c_register << 8))
: (0xc0000000 | (num_bytes << 24) |
(i2c_chip << 16) | (i2c_register << 8));
/* Print results */
for (i = 0; i < status; i += 2) {
- printf("0x%04x 0x%02x\n", buffer[i], buffer[i + 1] & 0xff);
+ if (multBytes == 0) {
+ printf("0x%04x 0x%02x\n", buffer[i], buffer[i + 1] & 0xff);
+ } else {
+ printf("0x%04x 0x%08x\n", buffer[i], buffer[i + 1]);
+ }
}
free(buffer);