From 234b9c6d1547cad09563a696e4a3ebb167b48b46 Mon Sep 17 00:00:00 2001 From: hadaq Date: Wed, 21 Oct 2009 00:29:56 +0000 Subject: [PATCH] added option BigMem -M --- libtrbnet/trbcmd.c | 320 ++++++++++++++++++++++++--------------------- 1 file changed, 171 insertions(+), 149 deletions(-) diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index dfd65ab..3db2cca 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -16,13 +16,12 @@ static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.30 $"; +static const char trbcmd_version[] = "$Revision: 2.31 $"; -/* ---- User Buffers --------------------------------------------------- */ +/* ---- User Buffer Size ----------------------------------------------- */ -#define NUM_ENDPOINTS 512 -#define READ_MEM_BUFFER_SIZE (NUM_ENDPOINTS * (0x3fff + 2)) -#define READ_IPU_BUFFER_SIZE (5 * 1024 * 1024) +static size_t NUM_ENDPOINTS = 1024; /* Maximum of 16KByte */ +static size_t USER_BUFFER_SIZE = 0; /* ------ MAIN ---------------------------------------------------------- */ @@ -34,6 +33,7 @@ void usage(const char *progName) printf(" -h give this help\n"); printf(" -f execute commands given in script-file\n"); printf(" -n repeat COMMAND number times, -1 = endless loop\n"); + printf(" -M turn on BigMemoryMode (TRB-Boards with > 32MByte Memory)\n"); printf(" -d turn on Debugging Information\n"); printf(" level 1: TRB_Package debugging\n"); printf(" level 2: +FIFO debugging\n"); @@ -84,12 +84,15 @@ int main(int argc, char ** argv) int loop = 1; int loopCtr = 0; int opt; + + /* LowMem Settings, i.e. 3 MBye maximum */ + USER_BUFFER_SIZE = 786432; /* 0xc000 * 4 Byte*/ trb_debug = 0; trb_lazy = 0; /* Parse Arguments */ - while ((opt = getopt(argc, argv, "+hf:n:d:DlHV")) != -1) { + while ((opt = getopt(argc, argv, "+hf:n:d:DlHMV")) != -1) { switch (opt) { case '?': usage(basename(argv[0])); @@ -120,6 +123,10 @@ int main(int argc, char ** argv) basename(argv[0]), trbcmd_version, trbnet_version); exit(EXIT_SUCCESS); break; + case 'M': + /* HighMem Setting, i.e. 20 MByte maximum 0x500000 * 4*/ + USER_BUFFER_SIZE = 5242880; + break; default: break; } @@ -235,7 +242,7 @@ int main(int argc, char ** argv) "value: 0x%08x\n", trb_address, reg_address, value); } - + if (trb_register_write(trb_address, reg_address, value) == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); @@ -244,17 +251,18 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } - + } else if (strncmp(cmd[0], "r", CMD_SIZE) == 0) { /*******************************************/ @@ -298,21 +306,24 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - for (i = 0; i < status; i += 2) { - fprintf(stdout, "0x%04x 0x%08x\n", - data[i], data[i + 1]); - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + for (i = 0; i < status; i += 2) { + fprintf(stdout, "0x%04x 0x%08x\n", + data[i], data[i + 1]); + } + + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } + + free(data); } else if (strncmp(cmd[0], "rm", CMD_SIZE) == 0) { @@ -354,45 +365,45 @@ int main(int argc, char ** argv) trb_address, reg_address, size, option); } - data = (uint32_t*)malloc(sizeof(uint32_t) * READ_MEM_BUFFER_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, READ_MEM_BUFFER_SIZE); + status = trb_register_read_mem(trb_address, reg_address, option, + size, data, USER_BUFFER_SIZE); if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); } trb_error("read_register_mem failed"); - if (data != NULL) free(data); if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Print data-buffer */ - p = data; - end = p + status; - while (p < end) { - len = (*p >> 16) & 0xffff; - fprintf(stdout, "0x%04x 0x%04x\n", (*p++) & 0xffff, len); - for (i = 0; (i < len) && (p < end); i++) { - fprintf(stdout, "0x%04x 0x%08x\n", - reg_address + i, *p++); + } else { + /* Print data-buffer */ + p = data; + end = p + status; + while (p < end) { + len = (*p >> 16) & 0xffff; + fprintf(stdout, "0x%04x 0x%04x\n", (*p++) & 0xffff, len); + for (i = 0; (i < len) && (p < end); i++) { + fprintf(stdout, "0x%04x 0x%08x\n", + reg_address + i, *p++); + } } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } - if (data != NULL) free(data); + free(data); + } else if (strncmp(cmd[0], "wm", CMD_SIZE) == 0) { /*******************************************/ @@ -446,7 +457,7 @@ int main(int argc, char ** argv) } data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0); } - if (line != NULL) free(line); + free(line); /* DEBUG Info */ if (trb_debug > 0) { @@ -461,8 +472,6 @@ int main(int argc, char ** argv) status = trb_register_write_mem(trb_address, reg_address, option, data, size); - if (data != NULL) free(data); - if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); @@ -471,17 +480,20 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } + free(data); + } else if (strncmp(cmd[0], "i", CMD_SIZE) == 0) { /*******************************************/ @@ -522,24 +534,26 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - for (i = 0; (i < status) && (i < 128); i += 4) { - fprintf(stdout, "0x%04x 0x%08x%08x 0x%02x\n", - uidBuffer[i + 3], - uidBuffer[i], - uidBuffer[i + 1], - uidBuffer[i + 2]); - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + for (i = 0; (i < status) && (i < 128); i += 4) { + fprintf(stdout, "0x%04x 0x%08x%08x 0x%02x\n", + uidBuffer[i + 3], + uidBuffer[i], + uidBuffer[i + 1], + uidBuffer[i + 2]); + } + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } + + free(uidBuffer); } else if (strncmp(cmd[0], "s", CMD_SIZE) == 0) { @@ -582,15 +596,16 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } } else if (strncmp(cmd[0], "T", CMD_SIZE) == 0) { @@ -637,15 +652,16 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } } else if (strncmp(cmd[0], "reset", CMD_SIZE) == 0) { @@ -682,14 +698,14 @@ int main(int argc, char ** argv) } trb_error("fpga_register_write failed"); exit(EXIT_FAILURE); - } - - if (fpga_register_write(0x10, 0x0000) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + if (fpga_register_write(0x10, 0x0000) == -1) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + trb_error("fpga_register_write failed"); + exit(EXIT_FAILURE); } - trb_error("fpga_register_write failed"); - exit(EXIT_FAILURE); } } else if (strncmp(cmd[0], "reload", CMD_SIZE) == 0) { @@ -723,15 +739,16 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } } else if (strncmp(cmd[0], "TR", CMD_SIZE) == 0) { @@ -781,15 +798,16 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } } else if (strncmp(cmd[0], "I", CMD_SIZE) == 0) { @@ -797,7 +815,7 @@ int main(int argc, char ** argv) /*******************************************/ /* IPU channel readout */ /*******************************************/ - + uint32_t *buffer = NULL; uint8_t type = 0; uint8_t random = 0; @@ -814,7 +832,7 @@ int main(int argc, char ** argv) } exit(EXIT_FAILURE); } - + type = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0) & 0x0f; random = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0); info = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0); @@ -831,11 +849,11 @@ int main(int argc, char ** argv) type, random, info, number); } - buffer = (uint32_t*)malloc(sizeof(uint32_t) * READ_IPU_BUFFER_SIZE); + buffer = (uint32_t*)malloc(sizeof(uint32_t) * USER_BUFFER_SIZE); if (buffer == NULL) abort(); status = trb_ipu_data_read(type, info, random, number, - buffer, READ_IPU_BUFFER_SIZE); + buffer, USER_BUFFER_SIZE); if (status == -1) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: ", lineCtr); @@ -844,29 +862,32 @@ int main(int argc, char ** argv) if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { exit(EXIT_FAILURE); } - } - - for (i = 0; i < status; i++) { - fprintf(stdout, "0x%08x\n", buffer[i]); - } + } else { + for (i = 0; i < status; i++) { + fprintf(stdout, "0x%08x\n", buffer[i]); + } - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } + free(buffer); + } else if (strncmp(cmd[0], "f", CMD_SIZE) == 0) { - + /*******************************************/ /* Flush FIFO Channel */ /*******************************************/ uint8_t channel = 0; - + if (cmdLen != 2) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); @@ -887,15 +908,16 @@ int main(int argc, char ** argv) } trb_error("trb_fifo_flush failed"); exit(EXIT_FAILURE); - } - - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); + } else { + /* Check Status-Bits */ + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + if (scriptFile != NULL) { + fprintf(stderr, "Line #%d: ", lineCtr); + } + fprintf(stderr, "WARNING Status-Bits:\n%s\n", + trb_strterm(trb_term)); } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", trb_strterm(trb_term)); } } else if (strncmp(cmd[0], "R", CMD_SIZE) == 0) { @@ -906,7 +928,7 @@ int main(int argc, char ** argv) uint32_t value = 0; uint16_t reg_address = 0; - + if (cmdLen != 2) { if (scriptFile != NULL) { fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); @@ -931,9 +953,9 @@ int main(int argc, char ** argv) } trb_error("fpga_register_read failed"); exit(EXIT_FAILURE); - } - - fprintf(stdout, "0x%04x 0x%08x\n", reg_address, value); + } else { + fprintf(stdout, "0x%04x 0x%08x\n", reg_address, value); + } } else if (strncmp(cmd[0], "W", CMD_SIZE) == 0) { @@ -993,7 +1015,7 @@ int main(int argc, char ** argv) if (scriptFile != NULL) { fclose(scriptFile); } - if (cmdLine != 0) free(cmdLine); + free(cmdLine); exit(EXIT_SUCCESS); } -- 2.43.0