]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
fs_fpga.. removed, it all in trbnet.h now
authorhadaq <hadaq>
Mon, 7 Sep 2009 21:22:18 +0000 (21:22 +0000)
committerhadaq <hadaq>
Mon, 7 Sep 2009 21:22:18 +0000 (21:22 +0000)
libtrbnet/Makefile
libtrbnet/trbcmd.c
libtrbnet/trbnet.c
libtrbnet/trbnet.h

index ffc70ea2fd6464582b40169201880c3ec208ca3c..4ed2074f235e3b22ce45699f24659d535f57a008 100644 (file)
@@ -36,7 +36,7 @@ trbcmd.OBJS = trbcmd.o
 
 LIB_TARGETS = libtrbnet.a
 
-libtrbnet.OBJS = port.o fs_fpga_int_mem.o trberror.o trbnet.o
+libtrbnet.OBJS = port.o trberror.o trbnet.o
 
 # ------------ Suffix Rules -------------------------------------------
 
@@ -76,10 +76,9 @@ clean:
 
 port.o: port.h port.c
 
-fs_fpga_int_mem.o: fs_fpga_int_mem.h fs_fpga_int_mem.c port.h
-
 trberror.o: trberror.h trberror.c
 
-trbnet.o: trbnet.h trbnet.c trberror.h fs_fpga_int_mem.h port.h
+trbnet.o: trbnet.h trbnet.c trberror.h port.h
+
+trbcmd.o: trbcmd.c trbnet.h trberror.h 
 
-trbcmd.o: trbcmd.c trbnet.h trberror.h fs_fpga_int_mem.h
index 1628738149d15740f9a7b6e16a752d2368b90dda..c2fcb52cb18e7941f8afd71441ccbedf9fe69e25 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdint.h>
 #include <trbnet.h>
 #include <trberror.h>
-#include <fs_fpga_int_mem.h>
 
 #ifndef HEXMODE
 #define HEXMODE 0
@@ -17,7 +16,7 @@
 
 static int hexMode = HEXMODE;
 
-static const char trbcmd_version[] = "$Revision: 2.22 $";
+static const char trbcmd_version[] = "$Revision: 2.23 $";
 
 /* ------ MAIN ---------------------------------------------------------- */
 
@@ -424,7 +423,7 @@ int main(int argc, char ** argv)
           if (scriptFile != NULL) {
             fprintf(stderr, "Line #%d: ", lineCtr);
           }
-          trb_error("write_register-memory failed");
+          trb_error("write_register_memory failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
             exit(EXIT_FAILURE);
           }
@@ -668,7 +667,6 @@ int main(int argc, char ** argv)
         /* Flush FIFO Channel                      */
         /*******************************************/
     
-        int status;
         uint8_t channel = 0;
     
         if (cmdLen != 2) {
@@ -685,16 +683,14 @@ int main(int argc, char ** argv)
           fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel);
         }
     
-        status = trb_fifo_flush(channel);
-        if (status == -1) {
+        if (trb_fifo_flush(channel) == -1) {
           if (scriptFile != NULL) {
             fprintf(stderr, "Line #%d: ", lineCtr);
           }
-          trb_error("flush_channel failed");
-          if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
-            exit(EXIT_FAILURE);
-          }
+          trb_error("trb_fifo_flush failed");
+          exit(EXIT_FAILURE);
         }
+        
       } else if (strncmp(cmd[0], "R", CMD_SIZE) == 0) {
     
         /*******************************************/
@@ -722,9 +718,16 @@ int main(int argc, char ** argv)
                   reg_address);
         }
         
-        read32_from_FPGA(reg_address, &value);
+        if (fpga_register_read(reg_address, &value) == -1) {
+          if (scriptFile != NULL) {
+            fprintf(stderr, "Line #%d: ", lineCtr);
+          }
+          trb_error("fpga_register_read failed");
+          exit(EXIT_FAILURE);
+        }          
+        
         fprintf(stdout, "0x%04x  0x%08x\n", reg_address, value);
-      
+        
       } else if (strncmp(cmd[0], "W", CMD_SIZE) == 0) {
     
         /*******************************************/
@@ -748,14 +751,26 @@ int main(int argc, char ** argv)
 
         if (trb_debug > 0) {
           fprintf(stderr, 
-                  "Command: READ_FIFO_REGISTER:"
+                  "Command: WRITE_FIFO_REGISTER:"
                   "reg_address: 0x%04x, "
                   "value: 0x%08x\n",
                   reg_address, value);
         }
       
-        write32_to_FPGA(reg_address, value);
+        if (fpga_register_write(reg_address, value) == -1) {
+          if (scriptFile != NULL) {
+            fprintf(stderr, "Line #%d: ", lineCtr);
+          }
+          trb_error("fpga_register_write failed");
+          exit(EXIT_FAILURE);
+        }
+              
       } else {
+        
+        /*******************************************/
+        /* Not a valid command */    
+        /*******************************************/
+            
         if (scriptFile != NULL) {
           fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
         } else {
index 0ed4309ccd3118ee5011e5c9c8eddc1a829b1adf..67b94e5533726bdbbb6b8ef039848a22cdbb3687 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 2.40 $";
+const char trbnet_version[] = "$Revision: 2.41 $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -10,7 +10,6 @@ const char trbnet_version[] = "$Revision: 2.40 $";
 #include <sys/sem.h>
 #include <errno.h>
 
-#include <fs_fpga_int_mem.h>
 #include <port.h>
 #include <trberror.h>
 
@@ -190,6 +189,57 @@ typedef enum {
   Status_Ch3_NoData = 5                  /* nomoredata                  */
 } Status_CH3;
 
+/* ------ Internal Functions FPGA Access -------------------------------- */
+
+#define FIFO_TOGGLE_BIT 0x10000
+
+static uint32_t fifoToggleBit = 0;
+
+
+static inline void write32_to_FPGA(uint16_t address, uint32_t value)
+{
+  /* writes a 32bit word to a given address on a given device */
+  
+  /* set address RW_WRITE */
+  writePC((address & 0x7fff) | (fifoToggleBit ^ FIFO_TOGGLE_BIT));
+  
+  /* write value */
+  writePC((value >> 16) | fifoToggleBit);
+  fifoToggleBit ^= FIFO_TOGGLE_BIT;
+  writePC((value & 0xffff) | fifoToggleBit);
+}
+
+
+static inline void read32_from_FPGA(uint16_t address, uint32_t* value)
+{
+  /* reads a 32bit word from a given address on a given device */
+  
+  /* set address RW_READ */
+  writePC((address | 0x8000) | (fifoToggleBit ^ FIFO_TOGGLE_BIT));
+  
+  /* read value */
+  *value = ((readPB() << 16));
+  writePC(fifoToggleBit);
+
+  fifoToggleBit ^= FIFO_TOGGLE_BIT;
+  *value |= (readPB() & 0xffff);
+  writePC(fifoToggleBit);
+}
+
+static inline int read32_from_FPGA_dma(uint16_t fifo_address,
+                         uint32_t* values, 
+                         uint32_t size)
+{
+  /* Do Not Used */
+  return -1;
+}
+
+static void com_reset()
+{
+  setbitsPC(0x30000);
+  clrbitsPC(0x30000);
+}
+
 /* ------ Internal Functions -------------------------------------------- */
 
 static void TRB_Package_dump(const TRB_Package* pkg)
@@ -841,6 +891,9 @@ static int lockPorts()
   /* Block Signals */
   sigprocmask(SIG_BLOCK, &blockSet, &blockSetOld);
 
+  /* Get FifoToggleBit-Status, needed by read32_from_FPGA ... */
+  fifoToggleBit = readPC() & FIFO_TOGGLE_BIT;
+  
   return 0;
 }
 
@@ -905,6 +958,7 @@ int init_ports()
     }
   }
   
+  /* Do we really need this, Jan??  */
   com_reset();
 
   return 0;
@@ -1427,3 +1481,39 @@ int trb_send_trigger_rich(uint8_t trg_input,
 
   return 0;
 }
+
+int fpga_register_read(uint16_t reg_address, uint32_t* value)
+{
+  trb_errno = TRB_NONE;
+  
+  if (lockPorts() == -1) return -1;
+  
+  /* DEBUG INFO */
+  if (trb_debug > 0) {
+    fprintf(stderr, "fpga_register_read started.\n");
+  }
+  
+  read32_from_FPGA(reg_address, value);
+
+  if (unlockPorts() == -1) return -1;
+
+  return 0;
+}
+
+int fpga_register_write(uint16_t reg_address, uint32_t value)
+{
+  trb_errno = TRB_NONE;
+  
+  if (lockPorts() == -1) return -1;
+  
+  /* DEBUG INFO */
+  if (trb_debug > 0) {
+    fprintf(stderr, "fpga_register_write started.\n");
+  }
+  
+  write32_to_FPGA(reg_address, value);
+
+  if (unlockPorts() == -1) return -1;
+
+  return 0;
+}
index 82a2b571da846bed69fcd89c9f0e23a202254edb..64ff78083a13f12febbfd94bc54384f10d7f8e9b 100644 (file)
@@ -63,8 +63,14 @@ int trb_send_trigger_rich(uint8_t input,
                           uint8_t random,
                           uint16_t number);
 
+int fpga_register_read(uint16_t reg_address, uint32_t* value);
+
+int fpga_register_write(uint16_t reg_address, uint32_t value);
+
 int trb_fifo_flush(uint8_t channel);
 
+
+
 /* ---------------------------------------------------------------------- */
 
 /* This library provides several function to access the trbnet on a