From b1d6019d4c7b278dd43dab0f4a262d90f2da33a9 Mon Sep 17 00:00:00 2001 From: hadaq Date: Tue, 20 Oct 2009 21:27:59 +0000 Subject: [PATCH] updated user-buffer handling --- libtrbnet/trbcmd.c | 51 +++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 15677cf..46bc0a8 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -16,7 +16,13 @@ static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.28 $"; +static const char trbcmd_version[] = "$Revision: 2.29 $"; + +/* ---- User Buffers --------------------------------------------------- */ + +#define NUM_ENDPOINTS 512 +#define READ_MEM_BUFFER_SIZE (NUM_ENDPOINTS * (32768 + 2)) +#define READ_IPU_BUFFER_SIZE (10 * 1024) /* ------ MAIN ---------------------------------------------------------- */ @@ -64,7 +70,6 @@ void usage(const char *progName) #define CMD_SIZE 256 #define CMD_MAX_NUM 10 -#define READ_MEM_SIZE 1048576 int main(int argc, char ** argv) { @@ -257,7 +262,7 @@ int main(int argc, char ** argv) /*******************************************/ int status = 0; - uint32_t data[256]; + uint32_t *data = NULL; int i; if (cmdLen != 3) { @@ -279,8 +284,12 @@ int main(int argc, char ** argv) "reg_address: 0x%04x\n", trb_address, reg_address); } - - status = trb_register_read(trb_address, reg_address, data, 256); + + data = (uint32_t*) malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 2); + if (data == NULL) abort(); + + status = trb_register_read(trb_address, reg_address, + data, NUM_ENDPOINTS * 2); if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); @@ -345,11 +354,12 @@ int main(int argc, char ** argv) trb_address, reg_address, size, option); } - if ((data = malloc(sizeof(uint32_t) * READ_MEM_SIZE)) == NULL) abort(); + data = (uint32_t*)malloc(sizeof(uint32_t) * READ_MEM_BUFFER_SIZE); + if (data == NULL) abort(); status = trb_register_read_mem(trb_address, reg_address, option, - size, data, READ_MEM_SIZE); + size, data, READ_MEM_BUFFER_SIZE); if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); @@ -425,13 +435,14 @@ int main(int argc, char ** argv) } } - if ((data = malloc(sizeof(uint32_t) * dataSize)) == NULL) abort(); + data = (uint32_t*)malloc(sizeof(uint32_t) * dataSize); + if (data == NULL) abort(); + while (getline(&line, &len, file) != -1) { if (size >= dataSize) { dataSize += 64; - if ((data = realloc(data, sizeof(uint32_t) * dataSize)) == NULL) { - abort(); - } + data = (uint32_t*)realloc(data, sizeof(uint32_t) * dataSize); + if (data == NULL) abort(); } data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0); } @@ -477,7 +488,7 @@ int main(int argc, char ** argv) /* ReadUId */ /*******************************************/ - uint32_t uidBuffer[512]; + uint32_t *uidBuffer = NULL; int status; int i; @@ -498,8 +509,11 @@ int main(int argc, char ** argv) "Command: READ_UID: trb_address: 0x%04x\n", trb_address); } - - status = trb_read_uid(trb_address, uidBuffer, 128); + + uidBuffer = (uint32_t*)malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 4); + if (uidBuffer == NULL) abort(); + + status = trb_read_uid(trb_address, uidBuffer, NUM_ENDPOINTS * 4); if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); @@ -784,7 +798,7 @@ int main(int argc, char ** argv) /* IPU channel readout */ /*******************************************/ - uint32_t buffer[4096]; + uint32_t *buffer = NULL; uint8_t type = 0; uint8_t random = 0; uint8_t info = 0; @@ -816,7 +830,12 @@ int main(int argc, char ** argv) "number: 0x%04x\n", type, random, info, number); } - status = trb_ipu_data_read(type, info, random, number, buffer, 4096); + + buffer = (uint32_t*)malloc(sizeof(uint32_t) * READ_IPU_BUFFER_SIZE); + if (buffer == NULL) abort(); + + status = trb_ipu_data_read(type, info, random, number, + buffer, READ_IPU_BUFFER_SIZE); if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); -- 2.43.0