From 2825464df5671aacecc056a12733b3086c413cbb Mon Sep 17 00:00:00 2001 From: hadaq Date: Tue, 26 May 2009 17:50:47 +0000 Subject: [PATCH] - trigger send function now without slow-control-channel - new trigger function for RICH only - read-uid now tells sourceAddress of board --- libtrbnet/pulser.c | 2 +- libtrbnet/trbcmd.c | 749 ++++++++++++++++++++++--------------------- libtrbnet/trberror.c | 6 +- libtrbnet/trberror.h | 4 +- libtrbnet/trbnet.c | 53 ++- libtrbnet/trbnet.h | 10 +- 6 files changed, 454 insertions(+), 370 deletions(-) diff --git a/libtrbnet/pulser.c b/libtrbnet/pulser.c index 59f0a3f..df519fa 100644 --- a/libtrbnet/pulser.c +++ b/libtrbnet/pulser.c @@ -110,7 +110,7 @@ int main(int argc, char ** argv) sigprocmask(SIG_BLOCK, &blockSet, NULL); /* Send Trigger and get Data */ - if (trb_send_trigger(0, 0, 0xcc, 0xdd, 0xaabb) != -1) { + if (trb_send_trigger_rich(0, 0, 0xcc, 0xdd, 0xaabb) != -1) { exit(EXIT_FAILURE); } diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 2b32427..7134d3c 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -33,24 +33,24 @@ void usage(const char *progName) printf(" -H hex-mode: all following arguments will be interpreted " "as hexadecimal\n numbers\n"); printf("Commands:\n"); - printf(" r -> read register\n"); - printf(" w -> write register\n"); - printf(" rm " - "-> read register-memory\n"); - printf(" wm " - "-> write to register-memory from ASCII-file ('-' = stdin)\n"); - printf(" i -> read unique ID\n"); - printf(" s -> set trb-address\n"); - printf(" T -> trigger by " - "slowcontrol\n"); - printf(" I -> read IPU data " - "slowcontrol\n"); - printf(" f -> flush FIFO of " + printf(" r -> read register\n"); + printf(" w -> write register\n"); + printf(" rm -> read " + "register-memory\n"); + printf(" wm -> write to " + "register-memory from ASCII-file ('-' = stdin)\n"); + printf(" i -> read unique ID\n"); + printf(" s -> set trb-address\n"); + printf(" T -> send trigger\n"); + printf(" TR -> send trigger to " + "RICH only\n"); + printf(" I -> read IPU data\n"); + printf(" f -> flush FIFO of " "channel\n"); - printf(" R -> " + printf(" R -> " "read register of the FPGA" " \n"); - printf(" W -> " + printf(" W -> " "write to register of the FPGA" " \n"); } @@ -105,411 +105,446 @@ int main(int argc, char ** argv) while ((repeat == -1) || (cmdCtr++ < repeat)) { - if (strcmp(argv[optind], "w") == 0) { + if (strcmp(argv[optind], "w") == 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 (argc - optind != 4) { + 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(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); - /* 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) { + trb_error("write failed"); + exit(EXIT_FAILURE); + } + } else if (strcmp(argv[optind], "r") == 0) { - /*******************************************/ - /* Register Read */ - /*******************************************/ + /*******************************************/ + /* Register Read */ + /*******************************************/ - int status = 0; - uint32_t data[256]; + int status = 0; + uint32_t data[256]; - if (argc - optind != 3) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + if (argc - optind != 3) { + 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); + trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0); + reg_address = strtoul(argv[optind + 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); - } + /* 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); - } + 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) { + 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) { - /*******************************************/ - /* Register Read Memory */ - /*******************************************/ + /*******************************************/ + /* Register Read Memory */ + /*******************************************/ - uint32_t *data = NULL; - uint16_t size = 0; - uint8_t option = 0; - int status; - unsigned int i; + uint32_t *data = NULL; + uint16_t size = 0; + uint8_t option = 0; + int status; + unsigned int i; - if (argc - optind != 5) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + 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); - 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(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); + } - if ((data = malloc(sizeof(uint32_t) * size)) == NULL) abort(); + if ((data = malloc(sizeof(uint32_t) * 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, data, size); + if (status == -1) { + trb_error("read_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]); - } + 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; + 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; - 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 (argc - optind != 5) { + usage(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(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"); + 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); - } + + 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(); + } + } + 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); + 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) { + if (status == -1) { + trb_error("write register-memory failed"); + exit(EXIT_FAILURE); + } + } else if (strcmp(argv[optind], "i") == 0) { - /*******************************************/ - /* ReadUId */ - /*******************************************/ + /*******************************************/ + /* ReadUId */ + /*******************************************/ - uint32_t uidBuffer[128]; - unsigned int size; + uint32_t uidBuffer[512]; + unsigned int size; - if (argc - optind != 2) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + if (argc - optind != 2) { + usage(argv[0]); + exit(EXIT_FAILURE); + } - trb_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0); + trb_address = strtoul(argv[optind + 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) { + trb_error("read_uid failed"); + exit(EXIT_FAILURE); + } - for (i = 0; (i < size) && (i < 128); i += 3) { - fprintf(stdout, "%s%08x%08x %s%02x\n", - hexMode == 1 ? "" : "0x", - uidBuffer[i], - uidBuffer[i + 1], - hexMode == 1 ? "" : "0x", - uidBuffer[i + 2]); - } - } else if (strcmp(argv[optind], "s") == 0) { - - /*******************************************/ - /* SetAddress */ - /*******************************************/ + 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) { - uint64_t uid = 0; - uint8_t endpoint = 0; - uint16_t trb_address = 0; + /*******************************************/ + /* SetAddress */ + /*******************************************/ - if (argc - optind != 4) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + uint64_t uid = 0; + uint8_t endpoint = 0; + uint16_t trb_address = 0; - 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); - } - - 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 (argc - optind != 4) { + usage(argv[0]); + exit(EXIT_FAILURE); + } - /*******************************************/ - /* Fake trigger function (ADCM specific) */ - /*******************************************/ + 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); + } - uint8_t input = 0; - uint8_t type = 0; - uint8_t random = 0; - uint8_t info = 0; - uint16_t number = 0; + if (trb_set_address(uid, endpoint, trb_address) == -1) { + trb_error("set_address failed"); + exit(EXIT_FAILURE); + } + } else if (strcmp(argv[optind], "T") == 0) { + + /*******************************************/ + /* 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); + } + + 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); + } - if (argc - optind != 6) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + 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 (argc - optind != 6) { + usage(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(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); + } - if (trb_send_trigger(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) { + 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 (argc - optind != 5) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + 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); - } + 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); + } - for (i = 0; i < size; i++) { - fprintf(stdout, "0x%08x\n", buffer[i]); - } - } else if (strcmp(argv[optind], "f") == 0) { + for (i = 0; i < size; i++) { + fprintf(stdout, "0x%08x\n", buffer[i]); + } + } else if (strcmp(argv[optind], "f") == 0) { - /*******************************************/ - /* Flush FIFO Channel */ - /*******************************************/ + /*******************************************/ + /* Flush FIFO Channel */ + /*******************************************/ - int status; - uint8_t channel = 0; + int status; + uint8_t channel = 0; - if (argc - optind != 2) { - usage(argv[0]); - exit(EXIT_FAILURE); - } + if (argc - optind != 2) { + usage(argv[0]); + exit(EXIT_FAILURE); + } - channel = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0); - if (trb_debug > 0) { - fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel); - } + channel = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0); + if (trb_debug > 0) { + fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel); + } - status = trb_fifo_flush(channel); - if (status == -1) { - trb_error("flush channel failed"); - exit(EXIT_FAILURE); - } - } else if (strcmp(argv[optind], "R") == 0) { + status = trb_fifo_flush(channel); + if (status == -1) { + trb_error("flush channel failed"); + exit(EXIT_FAILURE); + } + } else if (strcmp(argv[optind], "R") == 0) { - /*******************************************/ - /* Read FIFO Register */ - /*******************************************/ + /*******************************************/ + /* Read FIFO Register */ + /*******************************************/ - uint32_t value = 0; - uint16_t reg_address = 0; + uint32_t value = 0; + uint16_t reg_address = 0; - if (argc - optind != 2) { - usage(argv[0]); - exit(EXIT_FAILURE); - } - reg_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0); + if (argc - optind != 2) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + reg_address = strtoul(argv[optind + 1], NULL, hexMode == 1 ? 16 : 0); - read32_from_FPGA(reg_address, &value); - fprintf(stdout, "%s%04x %s%04x\n", - hexMode == 1 ? "" : "0x", reg_address, - hexMode == 1 ? "" : "0x", value); + 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) { + } else if (strcmp(argv[optind], "W") == 0) { - /*******************************************/ - /* Write FIFO Register */ - /*******************************************/ + /*******************************************/ + /* Write FIFO Register */ + /*******************************************/ - uint32_t value = 0; - uint16_t reg_address = 0; + uint32_t value = 0; + uint16_t reg_address = 0; - if (argc - optind != 3) { + 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); + + /* + fprintf(stdout, "%s%04x %s%04x\n", + hexMode == 1 ? "" : "0x", reg_address, + hexMode == 1 ? "" : "0x", value); + */ + } else { 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); - - /* - fprintf(stdout, "%s%04x %s%04x\n", - hexMode == 1 ? "" : "0x", reg_address, - hexMode == 1 ? "" : "0x", value); - */ - } else { - usage(argv[0]); - exit(EXIT_FAILURE); - } } /* end repeat loop */ diff --git a/libtrbnet/trberror.c b/libtrbnet/trberror.c index ef6bb1d..b84938a 100644 --- a/libtrbnet/trberror.c +++ b/libtrbnet/trberror.c @@ -43,10 +43,12 @@ const char* trb_strerror(int errno) "TERMINATION ErrorBit(s) set", "Invalid TRB-Address", "Invalid Data-Buffer Length", - "Endpoint not reached" + "Endpoint not reached", + "DMA not available (check whether module 'can_module.ko' is loaded)", + "DMA-Timeout" }; - if (errno < 18) { + if (errno < 20) { return errorstring[errno]; } else { return "Unknown Errno"; diff --git a/libtrbnet/trberror.h b/libtrbnet/trberror.h index bf75584..c9947e7 100644 --- a/libtrbnet/trberror.h +++ b/libtrbnet/trberror.h @@ -21,7 +21,9 @@ typedef enum { TRB_TERM_ERRBIT = 14, TRB_INVALID_ADDRESS = 15, TRB_INVALID_LENGTH = 16, - TRB_ENDPOINT_NOT_REACHED = 17 + TRB_ENDPOINT_NOT_REACHED = 17, + TRB_DMA_UNAVAILABLE = 18, + TRB_DMA_TIMEOUT = 19 } TRB_ERROR; extern int trb_errno; diff --git a/libtrbnet/trbnet.c b/libtrbnet/trbnet.c index 120624e..2556fe2 100644 --- a/libtrbnet/trbnet.c +++ b/libtrbnet/trbnet.c @@ -575,6 +575,7 @@ static int trb_fifo_read(uint8_t channel, { static uint32_t uidLow; static uint32_t uidHigh; + static uint32_t sourceAddress; switch (headerType) { case HEADER_HDR: @@ -583,6 +584,7 @@ static int trb_fifo_read(uint8_t channel, trb_errno = TRB_FIFO_INVALID_CONTENT; return -1; } + sourceAddress = (uint32_t)package.F0; break; case HEADER_DAT: @@ -596,10 +598,11 @@ static int trb_fifo_read(uint8_t channel, if ((packageCtr - endPointCtr * 3) == 2) { if ((dataCtr + 3) < size) { - /* store uid and endPoint in userDataBuffer */ + /* 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); @@ -913,7 +916,7 @@ int trb_read_uid(uint16_t trb_address, status = trb_fifo_read(3, FIFO_MODE_UID, (uint32_t*)uidBuffer, size); - if ((status > 0) && (status % 3 != 0)) { + if ((status > 0) && (status % 4 != 0)) { trb_errno = TRB_INVALID_PKG_NUMBER; return -1; } @@ -1014,14 +1017,52 @@ int trb_ipu_data_read(uint8_t type, } -int trb_send_trigger(uint8_t trg_input, - uint8_t type, +int trb_send_trigger(uint8_t type, uint8_t trg_info, uint8_t trg_random, uint16_t trg_number) { int status; + /* Init transfer trigger */ + if (trb_init_transfer(0) == -1) { + return -1; + } + + /* DEBUG INFO */ + if (trb_debug > 0) { + fprintf(stderr, "Init_Transfer done.\n"); + } + + /* Prepare trigger channel */ + write32_to_FPGA(CHANNEL_0_SENDER_ERROR, (((uint32_t)trg_info << 24) | + ((uint32_t)trg_random << 16) | + ((uint32_t)trg_number) + )); + + /* Send trigger */ + write32_to_FPGA(CHANNEL_0_SENDER_CONTROL, + SHORT_TRANSFER | (uint32_t)(type & 0x0f)); + + if (trb_debug > 0) { + fprintf(stderr, "trigger started.\n"); + } + + /* Check for replay packets (trigger) */ + status = trb_fifo_read(0, FIFO_MODE_NONE, NULL, 0); + if (status == -1) return -1; + + return 0; +} + +int trb_send_trigger_rich(uint8_t trg_input, + uint8_t type, + uint8_t trg_info, + uint8_t trg_random, + uint16_t trg_number) +{ + int status; + /* Init transfer slowcontrol */ if (trb_init_transfer(3) == -1) { return -1; @@ -1044,11 +1085,11 @@ int trb_send_trigger(uint8_t trg_input, )); /* Prepare slowcontrol channel */ - write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, 0x0000ffff);/* all boards */ + write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, 0x0000fffb); /* RICH Subnet only */ write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000); write32_to_FPGA(CHANNEL_3_SENDER_DATA, (0x8080 | (uint32_t)trg_input)); write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x0000dead); /*fake data is */ - write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x0000beef); /* discarded at ADCM */ + write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x0000beef); /* discarded at ADCM */ write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x00000000); /* Send both fake trigger and LVL1 information */ diff --git a/libtrbnet/trbnet.h b/libtrbnet/trbnet.h index 3eee0b8..8106585 100644 --- a/libtrbnet/trbnet.h +++ b/libtrbnet/trbnet.h @@ -49,13 +49,17 @@ int trb_ipu_data_read(uint8_t type, uint32_t* data, unsigned int size); - -int trb_send_trigger(uint8_t input, - uint8_t type, +int trb_send_trigger(uint8_t type, uint8_t info, uint8_t random, uint16_t number); +int trb_send_trigger_rich(uint8_t input, + uint8_t type, + uint8_t info, + uint8_t random, + uint16_t number); + /* ---------------------------------------------------------------------- */ /************************************************************************/ -- 2.43.0