From: hadaq Date: Sat, 25 Feb 2012 20:36:27 +0000 (+0000) Subject: added function trb_nettrace X-Git-Tag: v6.0~64 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=f937ad51c6491fb858a283f90bcb209e05a6e806;p=trbnettools.git added function trb_nettrace --- diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 0ad76a7..d70ca8c 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -25,7 +25,7 @@ static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.78 $"; +static const char trbcmd_version[] = "$Revision: 2.79 $"; #define BACKLOG 10 static uint16_t tcp_port = 55555; @@ -142,7 +142,8 @@ void usage(const char *progName) "clear bits of a register\n"); fprintf(stdout, " loadbit -> " "load bits of a register\n"); - + fprintf(stdout, " nettrace -> " + "trace TRBNet-Path of an endpoint\n"); fprintf(stdout, " reload -> " "reload FPGA\n"); fprintf(stdout, " reset -> " @@ -357,6 +358,7 @@ int start(int argc, char **argv) buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_register failed: %s\n", trb_strerror()); + return -1; } else { for (i = 0; i < status; i += 2) { fprintf(stdout, "0x%04x 0x%08x\n", buffer[i], buffer[i + 1]); @@ -397,6 +399,7 @@ int start(int argc, char **argv) buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_register failed: %s\n", trb_strerror()); + return -1; } else { for (i = 0; i < status; i += 3) { fprintf(stdout, "0x%04x 0x%08x 0x%04x\n", @@ -1154,7 +1157,6 @@ int start(int argc, char **argv) if (status == -1) { logError(ERROR, "clearbit of register failed: %s\n", trb_strerror()); - return -1; } @@ -1194,7 +1196,40 @@ int start(int argc, char **argv) trb_strerror()); return -1; } + + } else if (strncmp(cmd[0], "nettrace", CMD_SIZE) == 0) { + + /*******************************************/ + /* Nettrace */ + /*******************************************/ + int status = 0; + + if (cmdLen != 2) { + logError(ERROR, "Invalid command, try -h option\n"); + return -1; + } + + trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0); + + /* DEBUG Info */ + if (trb_debug > 0) { + fprintf(stderr, + "Command: NETTRACE: trb_address: 0x%04x\n", + trb_address); + } + + status = trb_nettrace(trb_address, buffer, BUFFER_SIZE); + if (status == -1) { + logError(ERROR, "nettrace of trbaddress 0x%04x failed: %s\n", + trb_address, trb_strerror()); + return -1; + } + + for (i = 0; i < status; i += 2) { + fprintf(stdout, "0x%04x 0x%08x\n", buffer[i], buffer[i + 1]); + } + } else { /*******************************************/ diff --git a/libtrbnet/trbnet.c b/libtrbnet/trbnet.c index 42303bc..4a977ad 100644 --- a/libtrbnet/trbnet.c +++ b/libtrbnet/trbnet.c @@ -1,4 +1,4 @@ -const char trbnet_version[] = "$Revision: 4.16 $ Local"; +const char trbnet_version[] = "$Revision: 4.17 $ Local"; #include #include @@ -1461,6 +1461,8 @@ int trb_register_read(uint16_t trb_address, write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x00000000); write32_to_FPGA(CHANNEL_3_SENDER_CONTROL, CMD_REGISTER_READ); #else + + /* Send command to pexor driver */ pexorDescriptor.trb_address = trb_address; pexorDescriptor.reg_address = reg_address; @@ -2510,3 +2512,59 @@ int trb_register_modify(uint16_t trb_address, return 0; } + +int trb_nettrace(uint16_t trb_address, + uint32_t *data, + unsigned int dsize) +{ + static const size_t NUM_ENDPOINTS = 1024; + uint32_t *buffer = NULL; + int status = 0; + unsigned int i; + unsigned int ctr; + + trb_errno = TRB_NONE; + + if (lockPorts(1) == -1) return -1; + + buffer = (uint32_t *) malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 2); + if (buffer == NULL) abort(); + + /* DEBUG INFO */ + if (trb_debug > 0) { + fprintf(stderr, "nettrace started.\n"); + } + + if (trb_register_read(0xfffe, 0xa5, buffer, NUM_ENDPOINTS * 2) == -1) { + unlockPorts(1); + free(buffer); + return -1; + } + trb_register_read_mem(trb_address, 0, 0, 1, buffer, NUM_ENDPOINTS * 2); + + status = trb_register_read(0xfffe, 0xa5, buffer, NUM_ENDPOINTS * 2); + if (unlockPorts(1) == -1) return -1; + + if (status == -1) { + free(buffer); + return -1; + } + + ctr = 0; + for (i = 0; (i + 1) < status; i += 2) { + if (buffer[i + 1] == 0) { + fprintf(stderr, "hallo\n"); + continue; + } + if (ctr + 1 >= dsize) { + trb_errno = TRB_USER_BUFFER_OVF; + free(buffer); + return -1; + } + data[ctr++] = buffer[i]; + data[ctr++] = buffer[i + 1]; + } + + free(buffer); + return ctr; +} diff --git a/libtrbnet/trbnet.h b/libtrbnet/trbnet.h index ca26107..df2f6c8 100644 --- a/libtrbnet/trbnet.h +++ b/libtrbnet/trbnet.h @@ -88,6 +88,10 @@ int fpga_register_read(uint32_t reg_address, int fpga_register_write(uint32_t reg_address, uint32_t value); +int trb_nettrace(uint16_t trb_address, + uint32_t *data, + unsigned int dsize); + #ifdef PEXOR int fpga_register_read_mem(uint32_t reg_address, uint32_t* data,