From: hadaq Date: Wed, 1 Feb 2012 12:34:13 +0000 (+0000) Subject: userBuffer now static, no more mallocs X-Git-Tag: v6.0~76 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=ac02ec674472b9ba9ce2e918d55b2d9b2e352e50;p=trbnettools.git userBuffer now static, no more mallocs --- diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 6590b70..0ad76a7 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -25,7 +25,7 @@ static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.77 $"; +static const char trbcmd_version[] = "$Revision: 2.78 $"; #define BACKLOG 10 static uint16_t tcp_port = 55555; @@ -34,8 +34,8 @@ static int tcp_mode = 0; /* ---- User Buffer Size ------------------------------------------------ */ -static const size_t NUM_ENDPOINTS = 1024; /* Maximum of 16KByte */ -static size_t USER_BUFFER_MAX_SIZE = 4194304; /* *4Bytes = 5MByte */ +static size_t BUFFER_SIZE = 4194304; /* 4MByte */ +static uint32_t buffer[4194304]; /* ---- Error Handling -------------------------------------------------- */ @@ -336,8 +336,7 @@ int start(int argc, char **argv) /*******************************************/ int status = 0; - uint32_t *data = NULL; - int i; + int i; if (cmdLen != 3) { logError(ERROR, "Invalid command, try -h option\n"); @@ -354,17 +353,13 @@ int start(int argc, char **argv) "reg_address: 0x%04x\n", trb_address, reg_address); } - 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); + buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_register failed: %s\n", trb_strerror()); } else { for (i = 0; i < status; i += 2) { - fprintf(stdout, "0x%04x 0x%08x\n", data[i], data[i + 1]); + fprintf(stdout, "0x%04x 0x%08x\n", buffer[i], buffer[i + 1]); } /* Check Status-Bits */ @@ -373,7 +368,6 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - free(data); } else if (strncmp(cmd[0], "rt", CMD_SIZE) == 0) { @@ -382,7 +376,6 @@ int start(int argc, char **argv) /*******************************************/ int status = 0; - uint32_t *data = NULL; int i; if (cmdLen != 3) { @@ -400,18 +393,14 @@ int start(int argc, char **argv) "reg_address: 0x%04x\n", trb_address, reg_address); } - data = (uint32_t *) malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 3); - if (data == NULL) - abort(); - status = trb_registertime_read(trb_address, reg_address, - data, NUM_ENDPOINTS * 3); + buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_register failed: %s\n", trb_strerror()); } else { for (i = 0; i < status; i += 3) { fprintf(stdout, "0x%04x 0x%08x 0x%04x\n", - data[i], data[i + 1], data[i + 2]); + buffer[i], buffer[i + 1], buffer[i + 2]); } /* Check Status-Bits */ @@ -420,7 +409,6 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - free(data); } else if (strncmp(cmd[0], "w", CMD_SIZE) == 0) { @@ -462,11 +450,9 @@ int start(int argc, char **argv) /* Register Read Memory */ /*******************************************/ - uint32_t *data = NULL; uint16_t size = 0; uint8_t option = 0; int status; - size_t USER_BUFFER_SIZE = 0; const uint32_t *p; const uint32_t *end = NULL; unsigned int len; @@ -492,24 +478,15 @@ int start(int argc, char **argv) "option: %d\n", trb_address, reg_address, size, option); } - USER_BUFFER_SIZE = - (NUM_ENDPOINTS * size + NUM_ENDPOINTS) < USER_BUFFER_MAX_SIZE - ? NUM_ENDPOINTS * size + NUM_ENDPOINTS - : USER_BUFFER_MAX_SIZE; - - data = (uint32_t *) malloc(sizeof(uint32_t) * USER_BUFFER_SIZE); - if (data == NULL) - abort(); - status = trb_register_read_mem(trb_address, reg_address, option, - size, data, USER_BUFFER_SIZE); + size, buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_register_mem failed: %s\n", trb_strerror()); return -1; } else { /* Print data-buffer */ - p = data; + p = buffer; end = p + status; while (p < end) { len = (*p >> 16) & 0xffff; @@ -526,7 +503,6 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - free(data); } else if (strncmp(cmd[0], "rmt", CMD_SIZE) == 0) { @@ -534,11 +510,9 @@ int start(int argc, char **argv) /* Register Read Memory plus TimeStamp */ /*******************************************/ - uint32_t *data = NULL; uint16_t size = 0; uint8_t option = 0; int status; - size_t USER_BUFFER_SIZE = 0; const uint32_t *p; const uint32_t *end = NULL; unsigned int len; @@ -564,24 +538,15 @@ int start(int argc, char **argv) "option: %d\n", trb_address, reg_address, size, option); } - USER_BUFFER_SIZE = - (NUM_ENDPOINTS * size * 2 + NUM_ENDPOINTS) < USER_BUFFER_MAX_SIZE - ? NUM_ENDPOINTS * size * 2 + NUM_ENDPOINTS - : USER_BUFFER_MAX_SIZE; - - data = (uint32_t *) malloc(sizeof(uint32_t) * USER_BUFFER_SIZE); - if (data == NULL) - abort(); - status = trb_registertime_read_mem(trb_address, reg_address, option, - size, data, USER_BUFFER_SIZE); + size, buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_registertime_mem failed: %s\n", trb_strerror()); return -1; } else { /* Print data-buffer */ - p = data; + p = buffer; end = p + status; while (p < end) { len = (*p >> 16) & 0xffff; @@ -599,7 +564,6 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - free(data); } else if (strncmp(cmd[0], "wm", CMD_SIZE) == 0) { @@ -699,7 +663,6 @@ int start(int argc, char **argv) /* ReadUId */ /*******************************************/ - uint32_t *uidBuffer = NULL; int status; unsigned int i; @@ -716,22 +679,16 @@ int start(int argc, char **argv) "Command: READ_UID: trb_address: 0x%04x\n", trb_address); } - uidBuffer = (uint32_t *) malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 4); - if (uidBuffer == NULL) - abort(); - - status = trb_read_uid(trb_address, uidBuffer, NUM_ENDPOINTS * 4); + status = trb_read_uid(trb_address, buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_uid failed: %s\n", trb_strerror()); return -1; } else { - for (i = 0; - ((i < (unsigned int)status) && (i < NUM_ENDPOINTS * 4)); - i += 4) { + for (i = 0; i < status; i += 4) { fprintf(stdout, "0x%04x 0x%08x%08x 0x%02x\n", - uidBuffer[i + 3], - uidBuffer[i], uidBuffer[i + 1], uidBuffer[i + 2]); + buffer[i + 3], + buffer[i], buffer[i + 1], buffer[i + 2]); } /* Check Status-Bits */ if (trb_errno == TRB_STATUS_WARNING) { @@ -739,9 +696,6 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - - free(uidBuffer); - } else if (strncmp(cmd[0], "s", CMD_SIZE) == 0) { /*******************************************/ @@ -1008,12 +962,8 @@ int start(int argc, char **argv) "number: 0x%04x\n", type, random, info, number); } - buffer = (uint32_t *) malloc(sizeof(uint32_t) * USER_BUFFER_MAX_SIZE); - if (buffer == NULL) - abort(); - status = trb_ipu_data_read(type, info, random, number, - buffer, USER_BUFFER_MAX_SIZE); + buffer, BUFFER_SIZE); if (status == -1) { logError(ERROR, "read_ipu_data failed: %s\n", trb_strerror()); @@ -1029,8 +979,6 @@ int start(int argc, char **argv) } } - free(buffer); - } else if (strncmp(cmd[0], "f", CMD_SIZE) == 0) { /*******************************************/