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 ---------------------------------------------------------- */
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");
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]));
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;
}
"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);
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) {
/*******************************************/
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) {
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) {
/*******************************************/
}
data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0);
}
- if (line != NULL) free(line);
+ free(line);
/* DEBUG Info */
if (trb_debug > 0) {
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);
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) {
/*******************************************/
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) {
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) {
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) {
}
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) {
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) {
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) {
/*******************************************/
/* IPU channel readout */
/*******************************************/
-
+
uint32_t *buffer = NULL;
uint8_t type = 0;
uint8_t random = 0;
}
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);
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);
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);
}
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) {
uint32_t value = 0;
uint16_t reg_address = 0;
-
+
if (cmdLen != 2) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
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) {
if (scriptFile != NULL) {
fclose(scriptFile);
}
- if (cmdLine != 0) free(cmdLine);
+ free(cmdLine);
exit(EXIT_SUCCESS);
}