From 13c77badbee49ff7a84d8d2956868b8a7830774d Mon Sep 17 00:00:00 2001 From: hadaq Date: Wed, 19 Aug 2009 17:53:10 +0000 Subject: [PATCH] update, bug fixes --- trbrich/pulser.c | 8 ++++---- trbrich/trb_i2c.c | 29 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/trbrich/pulser.c b/trbrich/pulser.c index 3457ab8..48e5190 100644 --- a/trbrich/pulser.c +++ b/trbrich/pulser.c @@ -51,7 +51,7 @@ void usage(const char *progName) int main(int argc, char ** argv) { char hldFileName[256] = "pulser.hld"; - uint16_t trgNumber = 0; + unsigned int trgNumber = 0; uint8_t triggerType = 0; uint8_t input = 0; unsigned int numEvts = UINT_MAX; @@ -131,7 +131,7 @@ int main(int argc, char ** argv) size = trb_ipu_data_read(triggerType, 0xcc, 0xdd, 0xaabb, buffer, bufferSize); if (size == -1) { - fprintf(stderr, "Error IPU Read\n"); + trb_error("Error IPU Read"); exit(EXIT_FAILURE); } @@ -141,11 +141,11 @@ int main(int argc, char ** argv) exit(EXIT_FAILURE); } len = ((buffer[1] >> 16) & 0xffff) + 2; - if (len >= size) { + if (len != size) { fprintf(stderr, "DHRD len error, len=%d size=%d\n", len, size); exit(EXIT_FAILURE); } - /*fprintf(stderr, "number padding zeros: %d\n", size - len);*/ + if (writeToStdout == 1) { fprintf(stdout, "Trigger# %d\n", trgNumber); for (i = 0; i < len; i++) { diff --git a/trbrich/trb_i2c.c b/trbrich/trb_i2c.c index 150cf39..3cf7ef2 100644 --- a/trbrich/trb_i2c.c +++ b/trbrich/trb_i2c.c @@ -14,7 +14,7 @@ static const uint16_t trb_i2c_register = 0x8040; -static const unsigned int timeout = 100; +static const unsigned int timeout = 1000; void usage(const char *progName) { @@ -80,23 +80,21 @@ static int readI2CRegister(uint16_t trb_address, int checkStatus, int error = 0; int i; - while ((status = trb_register_read(trb_address, trb_i2c_register, - buffer, BUFFER_SIZE)) == -1) { - ctr++; + /* Wait until NoMoreData is withdrawn */ + do { + if ((status = trb_register_read(trb_address, trb_i2c_register, + buffer, BUFFER_SIZE)) == -1) { + trb_error("Error I2C not ready"); + return -1; + } + /* Check timeout */ if (ctr >= timeout) { fprintf(stderr, "Error I2C not ready, timeout\n"); return -1; } - - /* check trb_statusbits == no_more_data --> continue */ - if ((trb_errno == TRB_TERM_ERRBIT) && - (((trb_statusbits >> 16) & 0x0004) != 0)) { - continue; - } - trb_error("Error I2C not ready"); - return -1; - } + ctr++; + } while (trb_term.status_channel != 0); if (checkStatus == 0) return status; @@ -232,6 +230,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"); exit(EXIT_FAILURE); } @@ -242,14 +241,14 @@ int main(int argc, char** argv) clearI2C(trb_address); exit(EXIT_FAILURE); } - + /* Wait for ACK */ if ((status = readI2CRegister(trb_address, 1, buffer, BUFFER_SIZE)) == -1) { clearI2C(trb_address); exit(EXIT_FAILURE); } - + /* Clear IC2 bus */ if (clearI2C(trb_address) == -1) { exit(EXIT_FAILURE); -- 2.43.0