From 3e9448fdc5ec0241284922139efa015760e78920 Mon Sep 17 00:00:00 2001 From: Ludwig Maier Date: Wed, 29 Jan 2014 23:59:04 +0100 Subject: [PATCH] trb_i2c modified --- trbrich/trb_i2c.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/trbrich/trb_i2c.c b/trbrich/trb_i2c.c index c2b0acf..02079d2 100644 --- a/trbrich/trb_i2c.c +++ b/trbrich/trb_i2c.c @@ -22,6 +22,9 @@ static uint16_t trb_i2c_register = 0x8040; 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] \n", @@ -29,7 +32,7 @@ void usage(const char *progName) 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"); @@ -83,7 +86,7 @@ typedef enum I2C_ERROR { } 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; @@ -117,7 +120,15 @@ static int readI2CRegister(uint16_t trb_address, int checkStatus, 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; } @@ -135,7 +146,7 @@ int main(int argc, char** argv) { int i; int spi_mode = 0; - unsigned int num_bytes = 0; + unsigned int num_bytes = 1; trb_debug = 0; /* Parse Arguments */ @@ -153,10 +164,11 @@ int main(int argc, char** argv) 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); @@ -279,7 +291,7 @@ int main(int argc, char** argv) /* 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)); @@ -310,7 +322,11 @@ int main(int argc, char** argv) /* 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); -- 2.43.0