From: hadaq Date: Sun, 22 May 2011 20:49:15 +0000 (+0000) Subject: pexor dma support added X-Git-Tag: v6.0~158 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=ee0513ab41633849af8ddea795873ab955be6d77;p=trbnettools.git pexor dma support added --- diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 06125b3..8e4a0fa 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -22,14 +22,15 @@ #ifndef HEXMODE #define HEXMODE 0 #endif - + static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.66 $"; +static const char trbcmd_version[] = "$Revision: 2.67 $"; #define BACKLOG 10 static uint16_t tcp_port = 55555; static int tcp_debug = 0; /* turn to 0 to suppress TCP/IP output */ +static int tcp_mode = 0; /* ---- User Buffer Size ------------------------------------------------ */ @@ -62,9 +63,9 @@ static void logError(int type, const char* format, ...) char* msgEnd = NULL; char* line = NULL; va_list args; - + va_start(args, format); - + if (scriptFile != NULL) { snprintf(fmt, 512, "Line #%d: %s", lineCtr, format); @@ -74,7 +75,7 @@ static void logError(int type, const char* format, ...) vsnprintf(msg, 4096, fmt, args); va_end(args); - msgEnd = msg + strlen(msg); + msgEnd = msg + strlen(msg); line = msg; do { char *p = strchr(line, '\n'); @@ -101,7 +102,6 @@ void usage(const char *progName) fprintf(stdout, " -d turn on Debugging Information\n"); fprintf(stdout, " level 1: TRB_Package debugging\n"); fprintf(stdout, " level 2: +FIFO debugging\n"); - fprintf(stdout, " -D FIFO DMA-Mode\n"); fprintf(stdout, " -H hex-mode: all arguments will be interpreted " "as hexadecimal-numbers\n"); @@ -135,14 +135,14 @@ void usage(const char *progName) "send trigger to RICH only\n", '%'); fprintf(stdout, " I -> " "read IPU data\n", '%'); - + fprintf(stdout, " setbit -> " "set bits of a register\n"); fprintf(stdout, " clearbit -> " "clear bits of a register\n"); fprintf(stdout, " loadbit -> " "load bits of a register\n"); - + fprintf(stdout, " reload -> " "reload FPGA\n"); fprintf(stdout, " reset -> " @@ -161,7 +161,7 @@ void usage(const char *progName) "disconnect from server\n" " " "(tcp-server mode only)\n\n"); - + fprintf(stdout, "Start as TCP/IP-Server:\n"); fprintf(stdout, "Usage: %s [-h] [-d] [-p portnumber] [-b] [-V] tcp\n", progName); @@ -191,15 +191,20 @@ int start(int argc, char **argv) int opt; int i; +#ifdef PEXOR + const char optString[] = "+hf:n:d:HMVD"; + pexor_dma = 1; +#else + const char optString[] = "+hf:n:d:HMV"; +#endif + + trb_debug = 0; for (i = 0; i < CMD_MAX_ARGS; i++) { cmd[i][0] = 0; } - - trb_debug = 0; - /* Parse Arguments */ optind = 1; - while ((opt = getopt(argc, argv, "+hf:n:d:DHMV")) != -1) { + while ((opt = getopt(argc, argv, optString)) != -1) { switch (opt) { case '?': usage(basename(argv[0])); @@ -216,9 +221,6 @@ int start(int argc, char **argv) case 'd': trb_debug = strtoul(optarg, NULL, 0); break; - case 'D': - trb_dma = 1; - break; case 'H': hexMode = 1; break; @@ -231,6 +233,11 @@ int start(int argc, char **argv) /* HighMem Setting */ USER_BUFFER_MAX_SIZE = 5242880; /* *4Bytes = 20MByte */ break; +#ifdef PEXOR + case 'D': + pexor_dma = 0; + break; +#endif default: break; } @@ -249,7 +256,10 @@ int start(int argc, char **argv) } } } - + if (tcp_mode == 0) { + if (init_ports() == -1) return -1; + } + /* Start repeat-loop */ while ((loop == -1) || (loopCtr++ < loop)) { ssize_t scriptStatus = 0; @@ -303,11 +313,11 @@ int start(int argc, char **argv) cmd[5], cmd[6], cmd[7], cmd[8], cmd[9]); for (i = 0, cmdLen = 0; i < CMD_MAX_ARGS; i++, cmdLen++) { - if (cmd[i][0] == '\0') - break; + if (cmd[i][0] == '\0') + break; } if (cmdLen == 0) { - /* Empty Line */ + /* Empty Line */ continue; } @@ -353,12 +363,12 @@ int start(int argc, char **argv) for (i = 0; i < status; i += 2) { fprintf(stdout, "0x%04x 0x%08x\n", data[i], data[i + 1]); } - + /* Check Status-Bits */ if (trb_errno == TRB_STATUS_WARNING) { logError(WARNING, "Status-Bit(s) have been set:\n%s\n", trb_termstr(trb_term)); - } + } } free(data); @@ -397,20 +407,20 @@ int start(int argc, char **argv) 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", + fprintf(stdout, "0x%04x 0x%08x 0x%04x\n", data[i], data[i + 1], data[i + 2]); } - + /* Check Status-Bits */ if (trb_errno == TRB_STATUS_WARNING) { logError(WARNING, "Status-Bit(s) have been set:\n%s\n", trb_termstr(trb_term)); - } + } } free(data); - + } else if (strncmp(cmd[0], "w", CMD_SIZE) == 0) { - + /*******************************************/ /* Register Write */ /*******************************************/ @@ -468,7 +478,7 @@ int start(int argc, char **argv) reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0); size = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0); option = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0); - + /* DEBUG Info */ if (trb_debug > 0) { fprintf(stderr, @@ -478,12 +488,12 @@ int start(int argc, char **argv) "size: 0x%04x, " "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_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(); @@ -506,7 +516,7 @@ int start(int argc, char **argv) (option == 0 ? reg_address + i : i), *p++); } - } + } /* Check Status-Bits */ if (trb_errno == TRB_STATUS_WARNING) { logError(WARNING, "Status-Bits are active:\n%s\n", @@ -514,9 +524,9 @@ int start(int argc, char **argv) } } free(data); - + } else if (strncmp(cmd[0], "rmt", CMD_SIZE) == 0) { - + /*******************************************/ /* Register Read Memory plus TimeStamp */ /*******************************************/ @@ -550,12 +560,12 @@ int start(int argc, char **argv) "size: 0x%04x, " "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_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(); @@ -587,7 +597,7 @@ int start(int argc, char **argv) } } free(data); - + } else if (strncmp(cmd[0], "wm", CMD_SIZE) == 0) { /*******************************************/ @@ -621,7 +631,7 @@ int start(int argc, char **argv) file = fopen(fileName, "r"); if (file == NULL) { logError(ERROR, "opening file '%s': %s\n", - fileName, strerror(errno)); + fileName, strerror(errno)); return -1; } } @@ -632,14 +642,14 @@ int start(int argc, char **argv) while (getline(&line, &len, file) != -1) { char* c = NULL; - + if (size >= dataSize) { dataSize += 64; data = (uint32_t *) realloc(data, sizeof(uint32_t) * dataSize); if (data == NULL) abort(); } - + /* Remove newline and comments */ if ((c = strchr(line, '\n')) != NULL) { *c = '\0'; @@ -647,7 +657,7 @@ int start(int argc, char **argv) if ((c = strchr(line, '#')) != NULL) { *c = '\0'; } - if (strlen(line) == 0) continue; + if (strlen(line) == 0) continue; data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0); } free(line); @@ -677,7 +687,7 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - + free(data); } else if (strncmp(cmd[0], "i", CMD_SIZE) == 0) { @@ -713,7 +723,7 @@ int start(int argc, char **argv) trb_strerror()); return -1; } else { - for (i = 0; + for (i = 0; ((i < (unsigned int)status) && (i < NUM_ENDPOINTS * 4)); i += 4) { fprintf(stdout, "0x%04x 0x%08x%08x 0x%02x\n", @@ -772,7 +782,7 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - + } else if (strncmp(cmd[0], "T", CMD_SIZE) == 0) { /*******************************************/ @@ -897,7 +907,7 @@ int start(int argc, char **argv) trb_termstr(trb_term)); } } - + } else if (strncmp(cmd[0], "TR", CMD_SIZE) == 0) { /*********************************************/ @@ -994,7 +1004,7 @@ int start(int argc, char **argv) "info: 0x%02x, " "number: 0x%04x\n", type, random, info, number); } - + buffer = (uint32_t *) malloc(sizeof(uint32_t) * USER_BUFFER_MAX_SIZE); if (buffer == NULL) abort(); @@ -1064,11 +1074,11 @@ int start(int argc, char **argv) if (trb_debug > 0) { fprintf(stderr, "Command: READ_FIFO_REGISTER: reg_address: " -#ifndef PEXOR +#ifndef PEXOR "0x%04x " #else "0x%08x " -#endif +#endif "\n", reg_address); } @@ -1079,8 +1089,8 @@ int start(int argc, char **argv) } else { fprintf(stdout, -#ifndef PEXOR - "0x%04x " +#ifndef PEXOR + "0x%04x " #else "0x%08x " #endif @@ -1099,12 +1109,12 @@ int start(int argc, char **argv) #else uint32_t reg_address = 0; #endif - + if (cmdLen != 3) { logError(ERROR, "Invalid command, try -h option\n"); return -1; } - + reg_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0); value = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0); @@ -1120,31 +1130,31 @@ int start(int argc, char **argv) #endif "value: 0x%08x\n", reg_address, value); } - + if (fpga_register_write(reg_address, value) == -1) { logError(ERROR, "fpga_register_write failed\n"); return -1; } - + } else if (strncmp(cmd[0], "setbit", CMD_SIZE) == 0) { - + /*******************************************/ /* Register Set Bits */ /*******************************************/ - + int status = 0; - + uint32_t bitMask; - + if (cmdLen != 4) { logError(ERROR, "Invalid command, try -h option\n"); return -1; } - + trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0); reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0); bitMask = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0); - + /* DEBUG Info */ if (trb_debug > 0) { fprintf(stderr, @@ -1152,7 +1162,7 @@ int start(int argc, char **argv) "reg_address: 0x%04x, bitMask: 0x%04x\n", trb_address, reg_address, bitMask); } - + status = trb_register_modify(trb_address, reg_address, 1, bitMask, 0); if (status == -1) { @@ -1160,26 +1170,26 @@ int start(int argc, char **argv) trb_strerror()); return -1; } - + } else if (strncmp(cmd[0], "clearbit", CMD_SIZE) == 0) { - + /*******************************************/ /* Register Clear Bits */ /*******************************************/ - + int status = 0; - + uint32_t bitMask; - + if (cmdLen != 4) { logError(ERROR, "Invalid command, try -h option\n"); return -1; } - + trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0); reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0); bitMask = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0); - + /* DEBUG Info */ if (trb_debug > 0) { fprintf(stderr, @@ -1187,37 +1197,37 @@ int start(int argc, char **argv) "reg_address: 0x%04x, bitMask: 0x%04x\n", trb_address, reg_address, bitMask); } - + status = trb_register_modify(trb_address, reg_address, 2, bitMask, 0); if (status == -1) { logError(ERROR, "clearbit of register failed: %s\n", trb_strerror()); - + return -1; } - + } else if (strncmp(cmd[0], "loadbit", CMD_SIZE) == 0) { - + /*******************************************/ /* Register Load Bits */ /*******************************************/ - + int status = 0; - + uint32_t bitMask; uint32_t bitValue; - + if (cmdLen != 5) { logError(ERROR, "Invalid command, try -h option\n"); return -1; } - + trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0); reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0); bitMask = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0); bitValue = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0); - + /* DEBUG Info */ if (trb_debug > 0) { fprintf(stderr, @@ -1225,7 +1235,7 @@ int start(int argc, char **argv) "reg_address: 0x%04x, bitMask: 0x%04x bitValue: 0x%04x\n", trb_address, reg_address, bitMask, bitValue); } - + status = trb_register_modify(trb_address, reg_address, 3, bitMask, bitValue); if (status == -1) { @@ -1233,7 +1243,7 @@ int start(int argc, char **argv) trb_strerror()); return -1; } - + } else { /*******************************************/ @@ -1288,8 +1298,6 @@ int main(int argc, char **argv) if (strcmp(argv[argc - 1], "tcp") != 0) { /* Run normal TRBCMD */ - if (init_ports() == -1) exit(EXIT_FAILURE); - if (start(argc, argv) == 0) { exit(EXIT_SUCCESS); } @@ -1301,7 +1309,8 @@ int main(int argc, char **argv) int yes = 1; int daemonMode = 0; int opt; - + tcp_mode = 1; + /* Parse Arguments */ optind = 1; while ((opt = getopt(argc, argv, "+hdVbp:")) != -1) { @@ -1318,8 +1327,8 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); break; case 'p': - tcp_port = strtol(optarg, NULL, 0); - break; + tcp_port = strtol(optarg, NULL, 0); + break; case 'd': tcp_debug = 1; break; @@ -1369,7 +1378,7 @@ int main(int argc, char **argv) my_addr.sin_port = htons(tcp_port); my_addr.sin_addr.s_addr = INADDR_ANY; memset(&(my_addr.sin_zero), 0, 8); - + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { perror("setsockopt() error!"); @@ -1397,9 +1406,9 @@ int main(int argc, char **argv) " to port %d [OK]\n\n", tcp_port); } - + if (init_ports() == -1) exit(EXIT_FAILURE); - + /* Enter an infinite loop to accept clients */ while (1) { socklen_t sin_size = sizeof(struct sockaddr_in); @@ -1432,20 +1441,20 @@ int main(int argc, char **argv) atexit(atexit0); clientout = fdopen(myFd, "a"); - + /* redirect output */ fclose(stdout); fclose(stderr); stdout = clientout; stderr = clientout; - + while (1) { int start_argc = 0; char *start_argv[256]; int start_arg = 0; char command[256] = ""; ssize_t msgLen = 0; - + msgLen = recv(myFd, (void *)command, 256, 0); if (msgLen == -1) { perror("Error recv"); @@ -1461,71 +1470,72 @@ int main(int argc, char **argv) fprintf(stderr, "%d: empty package\n", myPid); continue; } - - + + msgLen -= 2; command[msgLen] = '\0'; - + char *p; p = strpbrk( command, "#"); - if (p != NULL){ - fprintf(stdout, ">ERROR: The client transfered 2 commands as one."); - fprintf(clientout, "\n----------------------------\n\n"); - fflush(clientout); - if (tcp_debug > 0) { - fprintf(stderr, "%d: received: %i\n", myPid, (int)msgLen); - if (msgLen > 0) { - fprintf(stderr, "%d: command: ", myPid); - for (i = 1; i < (unsigned int)start_argc; i++) { - fprintf(stderr, "%s ", start_argv[i]); - } - fprintf(stderr, "\n"); - } - } - } - else{ - start_argv[start_argc++] = argv[0]; - for (i = 0; i < (unsigned int)msgLen; i++) { - if (isspace((int)command[i]) != 0) { - command[i] = '\0'; - } - if (command[i] != '\0') { - if (start_arg == 0) { - start_argv[start_argc++] = &command[i]; - start_arg = 1; - } else { - continue; - } - } else { - command[i] = '\0'; - start_arg = 0; - } - } - - if (tcp_debug > 0) { - fprintf(stderr, "%d: received: %i\n", myPid, (int)msgLen); - if (msgLen > 0) { - fprintf(stderr, "%d: command: ", myPid); - for (i = 1; i < (unsigned int)start_argc; i++) { - fprintf(stderr, "%s ", start_argv[i]); - } - fprintf(stderr, "\n"); - } - } - - /* Execute command */ - if (start_argc == 1) continue; - if ((strcmp(start_argv[1], "exit") == 0) || - (strcmp(start_argv[1], "quit") == 0)) { - if (tcp_debug > 0) { - fprintf(stderr, "%d: client disconnected\n", myPid); - } - exit(EXIT_SUCCESS); - } - - start(start_argc, start_argv); - fprintf(clientout, "\n----------------------------\n\n"); - fflush(clientout); + if (p != NULL){ + fprintf(stdout, + ">ERROR: The client transfered 2 commands as one."); + fprintf(clientout, "\n----------------------------\n\n"); + fflush(clientout); + if (tcp_debug > 0) { + fprintf(stderr, "%d: received: %i\n", myPid, (int)msgLen); + if (msgLen > 0) { + fprintf(stderr, "%d: command: ", myPid); + for (i = 1; i < (unsigned int)start_argc; i++) { + fprintf(stderr, "%s ", start_argv[i]); + } + fprintf(stderr, "\n"); + } + } + } + else{ + start_argv[start_argc++] = argv[0]; + for (i = 0; i < (unsigned int)msgLen; i++) { + if (isspace((int)command[i]) != 0) { + command[i] = '\0'; + } + if (command[i] != '\0') { + if (start_arg == 0) { + start_argv[start_argc++] = &command[i]; + start_arg = 1; + } else { + continue; + } + } else { + command[i] = '\0'; + start_arg = 0; + } + } + + if (tcp_debug > 0) { + fprintf(stderr, "%d: received: %i\n", myPid, (int)msgLen); + if (msgLen > 0) { + fprintf(stderr, "%d: command: ", myPid); + for (i = 1; i < (unsigned int)start_argc; i++) { + fprintf(stderr, "%s ", start_argv[i]); + } + fprintf(stderr, "\n"); + } + } + + /* Execute command */ + if (start_argc == 1) continue; + if ((strcmp(start_argv[1], "exit") == 0) || + (strcmp(start_argv[1], "quit") == 0)) { + if (tcp_debug > 0) { + fprintf(stderr, "%d: client disconnected\n", myPid); + } + exit(EXIT_SUCCESS); + } + + start(start_argc, start_argv); + fprintf(clientout, "\n----------------------------\n\n"); + fflush(clientout); } } }