]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
- trigger send function now without slow-control-channel
authorhadaq <hadaq>
Tue, 26 May 2009 17:50:47 +0000 (17:50 +0000)
committerhadaq <hadaq>
Tue, 26 May 2009 17:50:47 +0000 (17:50 +0000)
- new trigger function for RICH only
- read-uid now tells sourceAddress of board

libtrbnet/pulser.c
libtrbnet/trbcmd.c
libtrbnet/trberror.c
libtrbnet/trberror.h
libtrbnet/trbnet.c
libtrbnet/trbnet.h

index 59f0a3f671fa19c7827a2a12a2edf40f28b9ef97..df519fa99f61be73a7e54f8a41305909ae0fa6dd 100644 (file)
@@ -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);
     }
     
index 2b324271a274aaf33e58a2f9bcfa53c8aee694ea..7134d3c6d31a01695a04e7d12ee9f7e2b2eab649 100644 (file)
@@ -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 <trbaddress> <register>                 -> read register\n");
-  printf("   w <trbaddress> <register> <data>          -> write register\n");
-  printf("   rm <trbaddress> <register> <size> <mode>  "
-         "-> read register-memory\n");
-  printf("   wm <trbaddress> <register> <mode> <file>  "
-         "-> write to register-memory from ASCII-file ('-' = stdin)\n");
-  printf("   i <trbaddress>                            -> read unique ID\n");
-  printf("   s <uid> <endpoint> <trbaddress>           -> set trb-address\n");
-  printf("   T <input> <type> <random> <info> <number> -> trigger by "
-         "slowcontrol\n");
-  printf("   I <type> <random> <info> <number>         -> read IPU data "
-         "slowcontrol\n");
-  printf("   f <channel>                               -> flush FIFO of "
+  printf("   r <trbaddress> <register>                  -> read register\n");
+  printf("   w <trbaddress> <register> <data>           -> write register\n");
+  printf("   rm <trbaddress> <register> <size> <mode>   -> read "
+         "register-memory\n");
+  printf("   wm <trbaddress> <register> <mode> <file>   -> write to "
+         "register-memory from ASCII-file ('-' = stdin)\n");
+  printf("   i <trbaddress>                             -> read unique ID\n");
+  printf("   s <uid> <endpoint> <trbaddress>            -> set trb-address\n");
+  printf("   T <type> <random> <info> <number>          -> send trigger\n");
+  printf("   TR <input> <type> <random> <info> <number> -> send trigger to " 
+         "RICH only\n");
+  printf("   I <type> <random> <info> <number>          -> read IPU data\n");
+  printf("   f <channel>                                -> flush FIFO of "
          "channel\n");
-  printf("   R <register>                              -> "
+  printf("   R <register>                               -> "
          "read register of the FPGA"
          "  \n");
-  printf("   W <register> <value>                      -> "
+  printf("   W <register> <value>                       -> "
          "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 */ 
index ef6bb1dbb3ce932be69a62d91bbbb8422bc7b2b8..b84938a843ce2348854d339a7abff28e7b999925 100644 (file)
@@ -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";
index bf75584fc361643380c00a95e57c7bf48432d360..c9947e786d305d9275dce433cd7f0439b480f737 100644 (file)
@@ -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;
index 120624e57bb99906a38b30478c5a1156f4b7c560..2556fe2edbece5adc13f3a2d1566ed89e172f4ef 100644 (file)
@@ -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 */
index 3eee0b82b4ef1eb954924ed18a8d02e7197c04d6..8106585ad716086913f06c710d1cfe5625fee59d 100644 (file)
@@ -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);
+
 /* ---------------------------------------------------------------------- */
 
 /************************************************************************/