void usage(const char *progName)
{
- printf("Usage: %s [-h] [-n number] [-d level] [-H] <COMMAND>\n", progName);
+ printf("Usage: %s [-h] [-f script-file] [-n number] [-d level] "
+ "[-H] <COMMAND>\n", progName);
printf("Options:\n");
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(" -d turn on Debugging Information\n");
printf(" level 1: TRB_Package debugging\n");
printf(" -D FIFO DMA-Mode\n");
printf(" -l lazy-mode: skip most consistency-checks of packages\n");
printf(" -H hex-mode: all following arguments will be interpreted "
- "as hexadecimal\n numbers\n");
- printf("Commands:\n");
+ "as hexadecimal-numbers\n");
+ printf("\nCommands:\n");
printf(" r <trbaddress> <register> -> read register\n");
printf(" w <trbaddress> <register> <data> -> write register\n");
printf(" rm <trbaddress> <register> <size> <mode> -> read "
" \n");
}
+#define CMD_SIZE 256
+#define CMD_MAX_NUM 10
+#define READ_MEM_SIZE 1048576
+
int main(int argc, char ** argv)
{
+ FILE *scriptFile = NULL;
+ char scriptFileName[256] = "";
+ char cmd[CMD_MAX_NUM][CMD_SIZE];
+ char *cmdLine = NULL;
+ unsigned int cmdLen = 0;
uint16_t trb_address = 0;
uint16_t reg_address = 0;
- int cmdCtr = 0;
- int repeat = 1;
+ int loop = 1;
+ int loopCtr = 0;
int i;
trb_debug = 0;
trb_lazy = 0;
/* Parse Arguments */
- while ((i = getopt(argc, argv, "+hn:d:DlH")) != -1) {
+ while ((i = getopt(argc, argv, "+hf:n:d:DlH")) != -1) {
switch (i) {
case '?':
usage(basename(argv[0]));
case 'h':
usage(basename(argv[0]));
exit(EXIT_SUCCESS);
+ case 'f':
+ strncpy(scriptFileName, optarg, 256);
+ break;
case 'n':
- repeat = strtol(optarg, NULL, 0);
+ loop = strtol(optarg, NULL, 0);
break;
case 'd':
trb_debug = strtoul(optarg, NULL, 0);
}
}
- /* open port */
- init_ports();
-
- if (argc - optind < 1) {
- usage(basename(argv[0]));
- exit(EXIT_FAILURE);
+ /* Open scriptFile if requested */
+ if (strlen(scriptFileName) > 0) {
+ if (strncmp(scriptFileName, "-", 256) == 0) {
+ scriptFile = stdin;
+ fprintf(stderr, "name: %s\n", "STDIN");
+ } else {
+ scriptFile = fopen(scriptFileName, "r");
+ if (scriptFile == NULL) {
+ perror("Error opening ScriptFile");
+ fprintf(stderr, "name: '%s'\n", scriptFileName);
+ exit(EXIT_FAILURE);
+ }
+ }
}
+
+ /* Open ports */
+ init_ports();
- while ((repeat == -1) || (cmdCtr++ < repeat)) {
-
- if (strcmp(argv[optind], "w") == 0) {
+ /* Start repeat-loop */
+ while ((loop == -1) || (loopCtr++ < loop)) {
+ unsigned int lineCtr = 0;
+ ssize_t scriptStatus = 0;
+
+ /* Start script-file-loop */
+ while (scriptStatus != -1) {
+ if (scriptFile == NULL) {
+ /* Get command from function-call */
+ unsigned int i;
+ cmdLen = argc - optind;
+ for (i = 0; (i < cmdLen) && (i < CMD_MAX_NUM); i++) {
+ strncpy(cmd[i], argv[optind + i], CMD_SIZE);
+ }
+ scriptStatus = -1;
+ } else {
+ /* Get next command from file */
+ char *c = NULL;
+ size_t len = 0;
+ unsigned int i;
+
+ lineCtr++;
+ /* Initialize */
+ for (i = 0; i < CMD_MAX_NUM; i++) {
+ cmd[i][0] = '\0';
+ }
+
+ if ((scriptStatus = getline(&cmdLine, &len, scriptFile)) == -1) {
+ if (feof(scriptFile) != 0) {
+ /* EOF reached */
+ rewind(scriptFile);
+ continue;
+ } else {
+ /* Error reading line */
+ fprintf(stderr, "Error reading script-file\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /* Remove newline and comments */
+ if ((c = strchr(cmdLine, '\n')) != NULL) {
+ *c = '\0';
+ }
+ if ((c = strchr(cmdLine, '#')) != NULL) {
+ *c = '\0';
+ }
+
+ /* Split up cmdLine */
+ sscanf(cmdLine, "%s %s %s %s %s %s %s %s %s %s",
+ cmd[0], cmd[1], cmd[2], cmd[3], cmd[4],
+ cmd[5], cmd[6], cmd[7], cmd[8], cmd[9]);
+
+ for (i = 0, cmdLen = 0; i < CMD_MAX_NUM; i++, cmdLen++) {
+ if (cmd[i][0] == '\0') break;
+ }
+ if (cmdLen == 0) {
+ /* Empty Line */
+ continue;
+ }
+ printf("#Line %d: %s\n", lineCtr, cmdLine);
+ }
+
+ if (strncmp(cmd[0], "w", CMD_SIZE) == 0) {
- /*******************************************/
- /* Register Write */
- /*******************************************/
+ /*******************************************/
+ /* Register Write */
+ /*******************************************/
- uint32_t value = 0;
+ uint32_t value = 0;
- if (argc - optind != 4) {
- usage(basename(argv[0]));
- exit(EXIT_FAILURE);
- }
+ if (cmdLen != 4) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- reg_address = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
- value = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
+ trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
+ value = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: WRITE: trb_address: 0x%04x, reg_address: 0x%04x, "
- "value: 0x%08x\n",
- trb_address, reg_address, value);
- }
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: WRITE: trb_address: 0x%04x, reg_address: 0x%04x, "
+ "value: 0x%08x\n",
+ trb_address, reg_address, value);
+ }
- if (trb_register_write(trb_address, reg_address, value) == -1) {
- trb_error("write failed");
- exit(EXIT_FAILURE);
- }
- } else if (strcmp(argv[optind], "r") == 0) {
+ if (trb_register_write(trb_address, reg_address, value) == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("write_register failed");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strncmp(cmd[0], "r", CMD_SIZE) == 0) {
- /*******************************************/
- /* Register Read */
- /*******************************************/
+ /*******************************************/
+ /* Register Read */
+ /*******************************************/
- int status = 0;
- uint32_t data[256];
-
- if (argc - optind != 3) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ int status = 0;
+ uint32_t data[256];
+
+ if (cmdLen != 3) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- reg_address = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
+ trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: READ: trb_address: 0x%04x, "
- "reg_address: 0x%04x\n",
- trb_address, reg_address);
- }
-
- status = trb_register_read(trb_address, reg_address, data, 256);
- if (status == -1) {
- trb_error("read failed");
- exit(EXIT_FAILURE);
- }
-
- for (i = 0; i < status; i += 2) {
- fprintf(stdout, "%s%04x %s%08x\n",
- hexMode == 1 ? "" : "0x",
- data[i],
- hexMode == 1 ? "" : "0x",
- data[i + 1]);
- }
- } else if (strcmp(argv[optind], "rm") == 0) {
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: READ: trb_address: 0x%04x, "
+ "reg_address: 0x%04x\n",
+ trb_address, reg_address);
+ }
- /*******************************************/
- /* Register Read Memory */
- /*******************************************/
+ status = trb_register_read(trb_address, reg_address, data, 256);
+ if (status == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("read_register failed");
+ exit(EXIT_FAILURE);
+ }
- uint32_t *data = NULL;
- uint16_t size = 0;
- uint8_t option = 0;
- int status;
- unsigned int i;
+ for (i = 0; i < status; i += 2) {
+ fprintf(stdout, "0x%04x 0x%08x\n",
+ data[i], data[i + 1]);
+ }
+ } else if (strncmp(cmd[0], "rm", CMD_SIZE) == 0) {
+
+ /*******************************************/
+ /* Register Read Memory */
+ /*******************************************/
+
+ uint32_t *data = NULL;
+ uint16_t size = 0;
+ uint8_t option = 0;
+ int status;
+ const uint32_t* p;
+ const uint32_t* end = NULL;
+ unsigned int len;
+ unsigned int i;
- if (argc - optind != 5) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ if (cmdLen != 5) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- reg_address = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
- size = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
- option = strtoul(argv[optind + 4], NULL, hexMode == 1 ? 16 : 0);
-
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: READ_MEM: trb_address: 0x%04x, "
- "reg_address: 0x%04x, "
- "size: 0x%04x, "
- "option: %d\n",
- trb_address, reg_address, size, option);
- }
+ trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ 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,
+ "Command: READ_MEM: "
+ "trb_address: 0x%04x, "
+ "reg_address: 0x%04x, "
+ "size: 0x%04x, "
+ "option: %d\n",
+ trb_address, reg_address, size, option);
+ }
- if ((data = malloc(sizeof(uint32_t) * size)) == NULL) abort();
+ if ((data = malloc(sizeof(uint32_t) * READ_MEM_SIZE)) == NULL) abort();
- status =
- trb_register_read_mem(trb_address, reg_address, option, data, size);
- if (status == -1) {
- trb_error("read_mem failed");
- if (data != NULL) free(data);
- exit(EXIT_FAILURE);
- }
+ status =
+ trb_register_read_mem(trb_address, reg_address, option,
+ size, data, READ_MEM_SIZE);
+ if (status == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("read_register_mem failed");
+ if (data != NULL) free(data);
+ exit(EXIT_FAILURE);
+ }
- for (i = 0; i < status; i++) {
- fprintf(stdout, "%s%04x %s%08x\n",
- hexMode == 1 ? "" : "0x", reg_address + i,
- hexMode == 1 ? "" : "0x", data[i]);
- }
-
- if (data != NULL) free(data);
- } else if (strcmp(argv[optind], "wm") == 0) {
-
- /*******************************************/
- /* Register Write Memory */
- /*******************************************/
-
- FILE *file = NULL;
- uint32_t *data = NULL;
- unsigned int dataSize = 64;
- char *buffer = NULL;
- size_t len = 0;
- char *fileName = NULL;
- uint8_t option = 0;
- unsigned int size = 0;
- int status;
+ /* 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++);
+ }
+ }
+
+ if (data != NULL) free(data);
+ } else if (strncmp(cmd[0], "wm", CMD_SIZE) == 0) {
+
+ /*******************************************/
+ /* Register Write Memory */
+ /*******************************************/
+
+ FILE *file = NULL;
+ uint32_t *data = NULL;
+ unsigned int dataSize = 64;
+ char *line = NULL;
+ size_t len = 0;
+ char *fileName = NULL;
+ uint8_t option = 0;
+ unsigned int size = 0;
+ int status;
- if (argc - optind != 5) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- reg_address = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
- option = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
- fileName = argv[optind + 4];
-
- /* Open inputFile and read Data into buffer */
- if (strcmp(fileName, "-") == 0) {
- file = stdin;
- } else {
- file = fopen(fileName, "r");
- if (file == NULL) {
- perror("Error opening file");
+ if (cmdLen != 5) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
exit(EXIT_FAILURE);
}
- }
- if ((data = malloc(sizeof(uint32_t) * dataSize)) == NULL) abort();
- while (getline(&buffer, &len, file) != -1) {
- if (size >= dataSize) {
- dataSize += 64;
- if ((data = realloc(data, sizeof(uint32_t) * dataSize)) == NULL) {
- abort();
+ trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
+ option = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
+ fileName = cmd[4];
+
+ /* Open inputFile and read Data into buffer */
+ if (strncmp(fileName, "-", CMD_SIZE) == 0) {
+ file = stdin;
+ } else {
+ file = fopen(fileName, "r");
+ if (file == NULL) {
+ perror("Error opening file");
+ exit(EXIT_FAILURE);
}
}
- data[size++] = strtoul(buffer, NULL, hexMode == 1 ? 16 : 0);
- }
- if (buffer != NULL) free(buffer);
-
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: WRITE_MEM: trb_address: 0x%04x, "
- "reg_address: 0x%04x, "
- "option: %d, "
- "size: 0x%04x\n",
- trb_address, reg_address, option, size);
- }
-
- status = trb_register_write_mem(trb_address, reg_address, option,
- data, size);
- if (data != NULL) free(data);
-
- if (status == -1) {
- trb_error("write register-memory failed");
- exit(EXIT_FAILURE);
- }
- } else if (strcmp(argv[optind], "i") == 0) {
-
- /*******************************************/
- /* ReadUId */
- /*******************************************/
- uint32_t uidBuffer[512];
- unsigned int size;
+ if ((data = malloc(sizeof(uint32_t) * dataSize)) == NULL) abort();
+ while (getline(&line, &len, file) != -1) {
+ if (size >= dataSize) {
+ dataSize += 64;
+ if ((data = realloc(data, sizeof(uint32_t) * dataSize)) == NULL) {
+ abort();
+ }
+ }
+ data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0);
+ }
+ if (line != NULL) free(line);
+
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: WRITE_MEM: trb_address: 0x%04x, "
+ "reg_address: 0x%04x, "
+ "option: %d, "
+ "file: '%s', "
+ "size: 0x%04x\n",
+ trb_address, reg_address, option, fileName, size);
+ }
+
+ status = trb_register_write_mem(trb_address, reg_address, option,
+ data, size);
+ if (data != NULL) free(data);
- if (argc - optind != 2) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ if (status == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("write_register-memory failed");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strncmp(cmd[0], "i", CMD_SIZE) == 0) {
+
+ /*******************************************/
+ /* ReadUId */
+ /*******************************************/
+
+ uint32_t uidBuffer[512];
+ unsigned int size;
+
+ if (cmdLen != 2) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
+ trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: READ_UID: trb_address: 0x%04x\n",
- trb_address);
- }
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: READ_UID: trb_address: 0x%04x\n",
+ trb_address);
+ }
- size = trb_read_uid(trb_address, uidBuffer, 128);
- if (size == -1) {
- trb_error("read_uid failed");
- exit(EXIT_FAILURE);
- }
+ size = trb_read_uid(trb_address, uidBuffer, 128);
+ if (size == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("read_uid failed");
+ continue;
+ exit(EXIT_FAILURE);
+ }
- for (i = 0; (i < size) && (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]);
- }
- } else if (strcmp(argv[optind], "s") == 0) {
+ for (i = 0; (i < size) && (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]);
+ }
+ } else if (strncmp(cmd[0], "s", CMD_SIZE) == 0) {
- /*******************************************/
- /* SetAddress */
- /*******************************************/
+ /*******************************************/
+ /* SetAddress */
+ /*******************************************/
- uint64_t uid = 0;
- uint8_t endpoint = 0;
- uint16_t trb_address = 0;
+ uint64_t uid = 0;
+ uint8_t endpoint = 0;
+ uint16_t trb_address = 0;
- if (argc - optind != 4) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ if (cmdLen != 4) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- uid = strtoull(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- endpoint = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
- trb_address = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
-
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: SET_ADDRESS: "
- "uid: 0x%016llx, "
- "endpoint: 0x%02x, "
- "trb_address: 0x%04x\n",
- uid, endpoint, trb_address);
- }
+ uid = strtoull(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ endpoint = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
+ trb_address = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
+
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: SET_ADDRESS: "
+ "uid: 0x%016llx, "
+ "endpoint: 0x%02x, "
+ "trb_address: 0x%04x\n",
+ uid, endpoint, trb_address);
+ }
- if (trb_set_address(uid, endpoint, trb_address) == -1) {
- trb_error("set_address failed");
- exit(EXIT_FAILURE);
- }
- } else if (strcmp(argv[optind], "T") == 0) {
+ if (trb_set_address(uid, endpoint, trb_address) == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("set_address failed");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strncmp(cmd[0], "T", CMD_SIZE) == 0) {
- /*******************************************/
- /* Send Trigger */
- /*******************************************/
+ /*******************************************/
+ /* Send Trigger */
+ /*******************************************/
- uint8_t type;
- uint8_t random = 0;
- uint8_t info = 0;
- uint16_t number = 0;
-
- if (argc - optind != 5) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ uint8_t type;
+ uint8_t random = 0;
+ uint8_t info = 0;
+ uint16_t number = 0;
+
+ if (cmdLen != 5) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- type = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
- random = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
- info = strtoul(argv[optind + 4], NULL, hexMode == 1 ? 16 : 0);
- number = strtoul(argv[optind + 5], NULL, hexMode == 1 ? 16 : 0);
-
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: SEND_TRIGGER: "
- "type: 0x%01x, "
- "random: 0x%02x, "
- "info: 0x%02x, "
- "number: 0x%04x\n",
- type, random, info, number);
- }
+ type = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
+ random = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
+ info = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
+ number = strtoul(cmd[5], NULL, hexMode == 1 ? 16 : 0);
+
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: SEND_TRIGGER: "
+ "type: 0x%01x, "
+ "random: 0x%02x, "
+ "info: 0x%02x, "
+ "number: 0x%04x\n",
+ type, random, info, number);
+ }
- if (trb_send_trigger(type, info, random, number) == -1) {
- trb_error("send trigger failed");
- exit(EXIT_FAILURE);
- }
- } else if (strcmp(argv[optind], "TR") == 0) {
-
- /*********************************************/
- /* Send Fake trigger function to RICH Subnet */
- /*********************************************/
-
- uint8_t input = 0;
- uint8_t type = 0;
- uint8_t random = 0;
- uint8_t info = 0;
- uint16_t number = 0;
+ if (trb_send_trigger(type, info, random, number) == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("send_trigger failed");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strncmp(cmd[0], "TR", CMD_SIZE) == 0) {
+
+ /*********************************************/
+ /* Send Fake trigger function to RICH Subnet */
+ /*********************************************/
+
+ uint8_t input = 0;
+ uint8_t type = 0;
+ uint8_t random = 0;
+ uint8_t info = 0;
+ uint16_t number = 0;
- if (argc - optind != 6) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ if (cmdLen != 6) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- input = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0) & 0x03;
- type = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
- random = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
- info = strtoul(argv[optind + 4], NULL, hexMode == 1 ? 16 : 0);
- number = strtoul(argv[optind + 5], NULL, hexMode == 1 ? 16 : 0);
-
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: SEND_TRIGGER: "
- "input: 0x%01x, "
- "type: 0x%01x, "
- "random: 0x%02x, "
- "info: 0x%02x, "
- "number: 0x%04x\n",
- input, type, random, info, number);
- }
+ input = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0) & 0x03;
+ type = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
+ random = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
+ info = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
+ number = strtoul(cmd[5], NULL, hexMode == 1 ? 16 : 0);
+
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: SEND_TRIGGER: "
+ "input: 0x%01x, "
+ "type: 0x%01x, "
+ "random: 0x%02x, "
+ "info: 0x%02x, "
+ "number: 0x%04x\n",
+ input, type, random, info, number);
+ }
- if (trb_send_trigger_rich(input, type, info, random, number) == -1) {
- trb_error("send trigger failed");
- exit(EXIT_FAILURE);
- }
- } else if (strcmp(argv[optind], "I") == 0) {
-
- /*******************************************/
- /* IPU channel readout */
- /*******************************************/
-
- uint32_t buffer[4096];
- uint8_t type = 0;
- uint8_t random = 0;
- uint8_t info = 0;
- uint16_t number = 0;
- int size = 0;
+ if (trb_send_trigger_rich(input, type, info, random, number) == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("send_trigger failed");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strncmp(cmd[0], "I", CMD_SIZE) == 0) {
+
+ /*******************************************/
+ /* IPU channel readout */
+ /*******************************************/
+
+ uint32_t buffer[4096];
+ uint8_t type = 0;
+ uint8_t random = 0;
+ uint8_t info = 0;
+ uint16_t number = 0;
+ int size = 0;
- if (argc - optind != 5) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- type = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
- random = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
- info = strtoul(argv[optind + 3], NULL, hexMode == 1 ? 16 : 0);
- number = strtoul(argv[optind + 4], NULL, hexMode == 1 ? 16 : 0);
-
- /* DEBUG Info */
- if (trb_debug > 0) {
- fprintf(stderr,
- "Command: READ_IPU_DATA: "
- "type: 0x%01x, "
- "random: 0x%02x, "
- "info: 0x%02x, "
- "number: 0x%04x\n",
- type, random, info, number);
- }
- size = trb_ipu_data_read(type, info, random, number, buffer, 4096);
- if (size == -1) {
- trb_error("ipu read data failed");
- exit(EXIT_FAILURE);
- }
+ if (cmdLen != 5) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- for (i = 0; i < size; i++) {
- fprintf(stdout, "0x%08x\n", buffer[i]);
- }
- } else if (strcmp(argv[optind], "f") == 0) {
+ 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);
+ number = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
+
+ /* DEBUG Info */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: READ_IPU_DATA: "
+ "type: 0x%01x, "
+ "random: 0x%02x, "
+ "info: 0x%02x, "
+ "number: 0x%04x\n",
+ type, random, info, number);
+ }
+ size = trb_ipu_data_read(type, info, random, number, buffer, 4096);
+ if (size == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("read_ipu_data failed");
+ exit(EXIT_FAILURE);
+ }
- /*******************************************/
- /* Flush FIFO Channel */
- /*******************************************/
+ for (i = 0; i < size; i++) {
+ fprintf(stdout, "0x%08x\n", buffer[i]);
+ }
+ } else if (strncmp(cmd[0], "f", CMD_SIZE) == 0) {
- int status;
- uint8_t channel = 0;
+ /*******************************************/
+ /* Flush FIFO Channel */
+ /*******************************************/
- if (argc - optind != 2) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
+ int status;
+ uint8_t channel = 0;
- channel = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- if (trb_debug > 0) {
- fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel);
- }
+ if (cmdLen != 2) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
- status = trb_fifo_flush(channel);
- if (status == -1) {
- trb_error("flush channel failed");
- exit(EXIT_FAILURE);
- }
- } else if (strcmp(argv[optind], "R") == 0) {
+ channel = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ if (trb_debug > 0) {
+ fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel);
+ }
- /*******************************************/
- /* Read FIFO Register */
- /*******************************************/
+ status = trb_fifo_flush(channel);
+ if (status == -1) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: ", lineCtr);
+ }
+ trb_error("flush_channel failed");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strncmp(cmd[0], "R", CMD_SIZE) == 0) {
- uint32_t value = 0;
- uint16_t reg_address = 0;
+ /*******************************************/
+ /* Read FIFO Register */
+ /*******************************************/
- if (argc - optind != 2) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
- reg_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
+ uint32_t value = 0;
+ uint16_t reg_address = 0;
- read32_from_FPGA(reg_address, &value);
- fprintf(stdout, "%s%04x %s%04x\n",
- hexMode == 1 ? "" : "0x", reg_address,
- hexMode == 1 ? "" : "0x", value);
-
- } else if (strcmp(argv[optind], "W") == 0) {
+ if (cmdLen != 2) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
+
+ reg_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: READ_FIFO_REGISTER:"
+ "reg_address: 0x%04x\n",
+ reg_address);
+ }
- /*******************************************/
- /* Write FIFO Register */
- /*******************************************/
+ read32_from_FPGA(reg_address, &value);
+ fprintf(stdout, "0x%04x 0x%08x\n", reg_address, value);
+
+ } else if (strncmp(cmd[0], "W", CMD_SIZE) == 0) {
- uint32_t value = 0;
- uint16_t reg_address = 0;
+ /*******************************************/
+ /* Write FIFO Register */
+ /*******************************************/
- if (argc - optind != 3) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
- reg_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0);
- value = strtoul(argv[optind + 2], NULL, hexMode == 1 ? 16 : 0);
-
- write32_to_FPGA(reg_address, value);
+ uint32_t value = 0;
+ uint16_t reg_address = 0;
- /*
- fprintf(stdout, "%s%04x %s%04x\n",
- hexMode == 1 ? "" : "0x", reg_address,
- hexMode == 1 ? "" : "0x", value);
- */
- } else {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
+ if (cmdLen != 3) {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
+
+ reg_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+ value = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
- } /* end repeat loop */
+ if (trb_debug > 0) {
+ fprintf(stderr,
+ "Command: READ_FIFO_REGISTER:"
+ "reg_address: 0x%04x, "
+ "value: 0x%08x\n",
+ reg_address, value);
+ }
+
+ write32_to_FPGA(reg_address, value);
+ } else {
+ if (scriptFile != NULL) {
+ fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
+ } else {
+ usage(basename(argv[0]));
+ }
+ exit(EXIT_FAILURE);
+ }
+ } /* End script-file-loop */
+
+ } /* End repeat-loop */
+
+ /* Cleanup */
+ if (scriptFile != NULL) {
+ fclose(scriptFile);
+ }
+ if (cmdLine != 0) free(cmdLine);
+
exit(EXIT_SUCCESS);
}
static int trb_fifo_read(uint8_t channel,
int mode,
uint32_t data[],
- unsigned int size)
+ unsigned int dsize)
{
static uint32_t dataBuffer[DATA_BUFFER_SIZE];
uint32_t *tmp = dataBuffer;
fprintf(stderr, "-------------------------------------------------\n");
}
- /* First package (TRB-Header), headerType must be HDR or TRM */
+ /* First package: headerType must be HDR or TRM */
if (trb_lazy == 0) {
if (packageCtr == 0) {
if (!((headerType == HEADER_HDR) | (headerType == HEADER_TRM))) {
}
/* Get Data F0 - F3 and store it in User-Data-Buffer if requested */
- if (headerType != HEADER_TRM) {
- switch (mode) {
+ switch (mode) {
+
+ case FIFO_MODE_NONE:
+ break;
+
+ case FIFO_MODE_REG_READ:
+
+ switch (headerType) {
+ case HEADER_HDR:
+ if ((packageCtr - endPointCtr * 2) != 0) {
+ trb_fifo_flush(channel);
+ trb_errno = TRB_FIFO_INVALID_CONTENT;
+ return -1;
+ }
+ if (dataCtr < dsize) {
+ data[dataCtr++] = (uint32_t)package.F0;
+ } else {
+ trb_fifo_flush(channel);
+ trb_errno = TRB_USER_BUFFER_OVF;
+ return -1;
+ }
+ break;
+
+ case HEADER_DAT:
+ if ((packageCtr - endPointCtr * 2) != 1) {
+ trb_fifo_flush(channel);
+ trb_errno = TRB_FIFO_INVALID_CONTENT;
+ return -1;
+ }
+ if (dataCtr < dsize) {
+ data[dataCtr++] = (((uint32_t)package.F1 << 16) |
+ ((uint32_t)package.F2));
+ endPointCtr++;
+ } else {
+ trb_fifo_flush(channel);
+ trb_errno = TRB_USER_BUFFER_OVF;
+ return -1;
+ }
+ break;
- case FIFO_MODE_NONE:
+ case HEADER_TRM:
break;
- case FIFO_MODE_REG_READ:
-
+ default:
+ trb_fifo_flush(channel);
+ trb_errno = TRB_FIFO_INVALID_CONTENT;
+ return -1;
+ }
+
+ break;
+
+ case FIFO_MODE_REG_READ_MEM:
+ {
+ static uint32_t* lastHeader = NULL;
+ static uint32_t memLen = 0;
+
switch (headerType) {
case HEADER_HDR:
- if ((packageCtr - endPointCtr * 2) != 0) {
- trb_fifo_flush(channel);
- trb_errno = TRB_FIFO_INVALID_CONTENT;
- return -1;
- }
- if (dataCtr < size) {
+ if (dataCtr < dsize) {
+ if (lastHeader != NULL) {
+ *lastHeader |= (memLen << 16);
+ }
+ memLen = 0;
+ lastHeader = &data[dataCtr];
data[dataCtr++] = (uint32_t)package.F0;
} else {
trb_fifo_flush(channel);
trb_errno = TRB_USER_BUFFER_OVF;
- return -1;
+ fprintf(stderr, "HEADER\n");
+ return -1;
}
break;
case HEADER_DAT:
- if ((packageCtr - endPointCtr * 2) != 1) {
- trb_fifo_flush(channel);
- trb_errno = TRB_FIFO_INVALID_CONTENT;
- }
- if (dataCtr < size) {
+ if (dataCtr < dsize) {
data[dataCtr++] = (((uint32_t)package.F1 << 16) |
((uint32_t)package.F2));
- endPointCtr++;
+ memLen++;
} else {
trb_fifo_flush(channel);
trb_errno = TRB_USER_BUFFER_OVF;
- return -1;
+ return -1;
+ }
+ break;
+
+ case HEADER_TRM:
+ if (lastHeader != NULL) {
+ *lastHeader |= (memLen << 16);
}
break;
trb_errno = TRB_FIFO_INVALID_CONTENT;
return -1;
}
+ }
+ break;
- break;
-
- case FIFO_MODE_REG_READ_MEM:
- if (packageCtr > 0) {
- if (headerType != HEADER_DAT) {
- trb_fifo_flush(channel);
- trb_errno = TRB_FIFO_INVALID_CONTENT;
- return -1;
- }
- if (dataCtr < size) {
- data[dataCtr++] = (((uint32_t)package.F1 << 16) |
- ((uint32_t)package.F2));
- } else {
- trb_fifo_flush(channel);
- trb_errno = TRB_USER_BUFFER_OVF;
- return -1;
- }
+ case FIFO_MODE_REG_WRITE:
+ if (headerType == HEADER_TRM) break;
+
+ if (packageCtr > 1) {
+ trb_fifo_flush(channel);
+ trb_errno = TRB_INVALID_PKG_NUMBER;
+ return -1;
+ }
+ break;
+
+ case FIFO_MODE_IPU_DATA:
+ if (headerType == HEADER_TRM) break;
+
+ if ((headerType == HEADER_DAT) && (packageCtr > 0)) {
+ if (headerType != HEADER_DAT) {
+ trb_fifo_flush(channel);
+ trb_errno = TRB_FIFO_INVALID_CONTENT;
+ return -1;
}
- break;
-
- case FIFO_MODE_REG_WRITE:
- if (packageCtr > 1) {
+ if ((dataCtr + 1) < dsize) {
+ data[dataCtr++] = (((uint32_t)package.F0 << 16) |
+ ((uint32_t)package.F1));
+ data[dataCtr++] = (((uint32_t)package.F2 << 16) |
+ ((uint32_t)package.F3));
+ } else {
trb_fifo_flush(channel);
- trb_errno = TRB_INVALID_PKG_NUMBER;
+ trb_errno = TRB_USER_BUFFER_OVF;
return -1;
}
- break;
+ }
+ break;
+
+ case FIFO_MODE_UID:
+ {
+ static uint32_t uidLow;
+ static uint32_t uidHigh;
+ static uint32_t sourceAddress;
- case FIFO_MODE_IPU_DATA:
- if (packageCtr > 0) {
- if (headerType != HEADER_DAT) {
+ switch (headerType) {
+ case HEADER_HDR:
+ if ((packageCtr - endPointCtr * 3) != 0) {
trb_fifo_flush(channel);
trb_errno = TRB_FIFO_INVALID_CONTENT;
return -1;
}
- if ((dataCtr + 1) < size) {
- data[dataCtr++] = (((uint32_t)package.F0 << 16) |
- ((uint32_t)package.F1));
- data[dataCtr++] = (((uint32_t)package.F2 << 16) |
- ((uint32_t)package.F3));
- } else {
- trb_fifo_flush(channel);
- trb_errno = TRB_USER_BUFFER_OVF;
- return -1;
+ sourceAddress = (uint32_t)package.F0;
+ break;
+
+ case HEADER_DAT:
+ if ((packageCtr - endPointCtr * 3) == 1) {
+ uidHigh = (((uint32_t)package.F0 << 0) |
+ ((uint32_t)package.F1 << 16));
+ uidLow = (((uint32_t)package.F2 << 0) |
+ ((uint32_t)package.F3 << 16));
+ break;
}
- }
- break;
-
- case FIFO_MODE_UID:
- {
- static uint32_t uidLow;
- static uint32_t uidHigh;
- static uint32_t sourceAddress;
- switch (headerType) {
- case HEADER_HDR:
- if ((packageCtr - endPointCtr * 3) != 0) {
+ if ((packageCtr - endPointCtr * 3) == 2) {
+ if ((dataCtr + 3) < dsize) {
+ /* store uid, endPoint and sourceAddress in userDataBuffer */
+ data[dataCtr++] = uidLow;
+ data[dataCtr++] = uidHigh;
+ data[dataCtr++] = (uint32_t)package.F0;
+ data[dataCtr++] = (uint32_t)sourceAddress;
+ endPointCtr++;
+ } else {
trb_fifo_flush(channel);
- trb_errno = TRB_FIFO_INVALID_CONTENT;
+ trb_errno = TRB_USER_BUFFER_OVF;
return -1;
}
- sourceAddress = (uint32_t)package.F0;
break;
-
- case HEADER_DAT:
- if ((packageCtr - endPointCtr * 3) == 1) {
- uidHigh = (((uint32_t)package.F0 << 0) |
- ((uint32_t)package.F1 << 16));
- uidLow = (((uint32_t)package.F2 << 0) |
- ((uint32_t)package.F3 << 16));
- break;
- }
-
- if ((packageCtr - endPointCtr * 3) == 2) {
- if ((dataCtr + 3) < size) {
- /* store uid, endPoint and sourceAddress in userDataBuffer */
- data[dataCtr++] = uidLow;
- data[dataCtr++] = uidHigh;
- data[dataCtr++] = (uint32_t)package.F0;
- data[dataCtr++] = (uint32_t)sourceAddress;
- endPointCtr++;
- } else {
- trb_fifo_flush(channel);
- trb_errno = TRB_USER_BUFFER_OVF;
- return -1;
- }
- break;
- }
-
- default:
- trb_fifo_flush(channel);
- trb_errno = TRB_FIFO_INVALID_CONTENT;
- return -1;
}
+ case HEADER_TRM:
+ break;
+
+ default:
+ trb_fifo_flush(channel);
+ trb_errno = TRB_FIFO_INVALID_CONTENT;
+ return -1;
}
- break;
+ }
+ break;
- case FIFO_MODE_SET_ADDRESS:
- if ((packageCtr == 1) && (headerType == HEADER_DAT)) {
- if (package.F0 != NET_ACKADDRESS) {
- trb_fifo_flush(channel);
- return -1;
- }
- }
-
- if (packageCtr > 1) {
+ case FIFO_MODE_SET_ADDRESS:
+ if (headerType == HEADER_TRM) break;
+
+ if ((packageCtr == 1) && (headerType == HEADER_DAT)) {
+ if (package.F0 != NET_ACKADDRESS) {
trb_fifo_flush(channel);
- trb_errno = TRB_INVALID_PKG_NUMBER;
return -1;
}
-
- dataCtr++;
- break;
-
- default:
+ }
+
+ if (packageCtr > 1) {
trb_fifo_flush(channel);
- trb_errno = TRB_FIFO_INVALID_MODE;
+ trb_errno = TRB_INVALID_PKG_NUMBER;
return -1;
}
+
+ dataCtr++;
+ break;
+
+ default:
+ trb_fifo_flush(channel);
+ trb_errno = TRB_FIFO_INVALID_MODE;
+ return -1;
}
}
int trb_register_read(uint16_t trb_address,
uint16_t reg_address,
uint32_t *data,
- unsigned int size)
+ unsigned int dsize)
{
int status = 0;
fprintf(stderr, "CMD_REGISTER_READ started.\n");
}
- status = trb_fifo_read(3, FIFO_MODE_REG_READ, data, size);
+ status = trb_fifo_read(3, FIFO_MODE_REG_READ, data, dsize);
if ((status > 0) && (status % 2 != 0)) {
trb_errno = TRB_INVALID_PKG_NUMBER;
int trb_register_read_mem(uint16_t trb_address,
uint16_t reg_address,
uint8_t option,
+ uint16_t size,
uint32_t *data,
- uint16_t size)
+ unsigned int dsize)
{
uint16_t length;
+ int status;
+ const uint32_t *p = NULL;
+ const uint32_t *end = NULL;
- /* Do not allow broadcasts within this function */
- if (trb_address >= 0xff00) {
- trb_errno = TRB_INVALID_ADDRESS;
- return -1;
- }
/* check size and set reading-mode */
length = size & 0x7fff;
fprintf(stderr, "CMD_REGISTER_READ_MEM started.\n");
}
- return trb_fifo_read(3, FIFO_MODE_REG_READ_MEM, data, size);
+ status = trb_fifo_read(3, FIFO_MODE_REG_READ_MEM, data, dsize);
+
+ if (status == -1) return status;
+
+ /* Check size */
+ p = data;
+ end = p + status;
+ while (p < end) {
+ uint16_t len;
+ len = (*p >> 16) & 0xffff;
+ if (len > size) {
+ trb_errno = TRB_READMEM_INVALID_SIZE;
+ fprintf(stderr, "fuck fuck %d %d\n", size, len);
+ return -1;
+ }
+ p += len + 1;
+ }
+
+ return status;
}
int trb_register_write(uint16_t trb_address,
uint16_t reg_address,
uint8_t option,
const uint32_t *data,
- uint16_t size)
+ uint16_t dsize)
{
uint16_t config;
uint16_t i;
/* check size and set write-mode */
- config = size & 0x7fff;
- if ((size == 0) || (size != config)) {
+ config = dsize & 0x7fff;
+ if ((dsize == 0) || (dsize != config)) {
trb_errno = TRB_INVALID_LENGTH;
return -1;
}
write32_to_FPGA(CHANNEL_3_SENDER_DATA, config);
write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x00000000);
write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x00000000);
- for (i = 0; i < size; i++) {
+ for (i = 0; i < dsize; i++) {
write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x00000000);
write32_to_FPGA(CHANNEL_3_SENDER_DATA, (data[i] >> 16) & 0xffff);
write32_to_FPGA(CHANNEL_3_SENDER_DATA, data[i] & 0xffff);
int trb_read_uid(uint16_t trb_address,
uint32_t* uidBuffer,
- unsigned int size)
+ unsigned int dsize)
{
int status;
fprintf(stderr, "CMD_READ_UNIQUE_ID started.\n");
}
- status = trb_fifo_read(3, FIFO_MODE_UID, (uint32_t*)uidBuffer, size);
+ status = trb_fifo_read(3, FIFO_MODE_UID, (uint32_t*)uidBuffer, dsize);
if ((status > 0) && (status % 4 != 0)) {
trb_errno = TRB_INVALID_PKG_NUMBER;
/* DEBUG INFO */
if (trb_debug > 0) {
- fprintf(stderr, "CMD_SETADDRESS started.\n");
+ fprintf(stderr, "CMD_SETADDRESS started.\n");
}
status = trb_fifo_read(3, FIFO_MODE_SET_ADDRESS, NULL, 0);
uint8_t trg_random,
uint16_t trg_number,
uint32_t *data,
- unsigned int size)
+ unsigned int dsize)
{
int status;
fprintf(stderr, "CMD_IPU_DATA_READ started.\n");
}
- status = trb_fifo_read(1, FIFO_MODE_IPU_DATA, data, size);
+ status = trb_fifo_read(1, FIFO_MODE_IPU_DATA, data, dsize);
return status;
}