From: hadaq Date: Fri, 23 Apr 2010 18:51:28 +0000 (+0000) Subject: increased buffer_size X-Git-Tag: v6.0~275 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=57d85d13d83a8bf25bb234886ffab736940e4a10;p=trbnettools.git increased buffer_size --- diff --git a/trbrich/trb_i2c.c b/trbrich/trb_i2c.c index a6e1ad9..2960f29 100644 --- a/trbrich/trb_i2c.c +++ b/trbrich/trb_i2c.c @@ -9,9 +9,9 @@ #include #include -#define BUFFER_SIZE 4096 +#define BUFFER_SIZE (6 * 4096) -static const char trb_i2c_version[] = "$Revision: 1.5 $"; +static const char trb_i2c_version[] = "$Revision: 1.6 $"; static const uint16_t trb_i2c_register = 0x8040; @@ -130,7 +130,6 @@ int main(int argc, char** argv) int i; trb_debug = 0; - trb_lazy = 0; /* Parse Arguments */ while ((i = getopt(argc, argv, "+hd:V")) != -1) { @@ -168,7 +167,7 @@ int main(int argc, char** argv) /* I2C write */ /*************************************************/ - uint32_t buffer[BUFFER_SIZE]; + uint32_t *buffer = NULL; uint32_t value = 0; uint16_t trb_address = 0; uint8_t i2c_chip = 0; @@ -181,6 +180,9 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE); + if (buffer == NULL) abort(); + trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); i2c_chip = (uint8_t)strtoul(argv[optind + 2], NULL, 0); i2c_register = (uint8_t)strtoul(argv[optind + 3], NULL, 0); @@ -188,6 +190,7 @@ int main(int argc, char** argv) /* Check whether I2C is ready */ if (readI2CRegister(trb_address, 0, buffer, BUFFER_SIZE) == -1) { + free(buffer); exit(EXIT_FAILURE); } @@ -196,6 +199,7 @@ int main(int argc, char** argv) if (trb_register_write(trb_address, trb_i2c_register, value) == -1) { trb_error("Error writing value"); clearI2C(trb_address); + free(buffer); exit(EXIT_FAILURE); } @@ -203,21 +207,24 @@ int main(int argc, char** argv) if ((status = readI2CRegister(trb_address, 1, buffer, BUFFER_SIZE)) == -1) { clearI2C(trb_address); + free(buffer); exit(EXIT_FAILURE); } /* Clear IC2 bus */ if (clearI2C(trb_address) == -1) { + free(buffer); exit(EXIT_FAILURE); } + free(buffer); } else if (strcmp(argv[optind], "r") == 0) { /*************************************************/ /* I2C read */ /*************************************************/ - uint32_t buffer[BUFFER_SIZE]; + uint32_t *buffer = NULL; int status = 0; uint16_t trb_address = 0; uint32_t value = 0; @@ -230,7 +237,10 @@ int main(int argc, char** argv) usage(argv[0]); exit(EXIT_FAILURE); } - + + buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE); + if (buffer == NULL) abort(); + trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); i2c_chip = (uint8_t)strtoul(argv[optind + 2], NULL, 0); i2c_register = (uint8_t)strtoul(argv[optind + 3], NULL, 0); @@ -238,6 +248,7 @@ int main(int argc, char** argv) /* Check whether I2C is ready */ if (readI2CRegister(trb_address, 0, buffer, BUFFER_SIZE) == -1) { trb_error("I2C not ready"); + free(buffer); exit(EXIT_FAILURE); } @@ -246,6 +257,7 @@ int main(int argc, char** argv) if (trb_register_write(trb_address, trb_i2c_register, value) == -1) { trb_error("Error reading value"); clearI2C(trb_address); + free(buffer); exit(EXIT_FAILURE); } @@ -253,11 +265,13 @@ int main(int argc, char** argv) if ((status = readI2CRegister(trb_address, 1, buffer, BUFFER_SIZE)) == -1) { clearI2C(trb_address); + free(buffer); exit(EXIT_FAILURE); } /* Clear IC2 bus */ if (clearI2C(trb_address) == -1) { + free(buffer); exit(EXIT_FAILURE); } @@ -266,6 +280,7 @@ int main(int argc, char** argv) printf("0x%04x 0x%02x\n", buffer[i], buffer[i + 1] & 0xff); } + free(buffer); } else if (strcmp(argv[optind], "c") == 0) { /*************************************************/