]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
now toggle mode and cleanup
authorhadaq <hadaq>
Mon, 7 Sep 2009 15:42:43 +0000 (15:42 +0000)
committerhadaq <hadaq>
Mon, 7 Sep 2009 15:42:43 +0000 (15:42 +0000)
libtrbnet/fs_fpga_int_mem.c
libtrbnet/fs_fpga_int_mem.h

index 86fdfb5a9cef6c096e4cee8dd68ef0c5195a52f3..6202a2998d88d6d90ff745e4288e37ede9b5d029 100644 (file)
@@ -4,49 +4,49 @@
 
 #include "fs_fpga_int_mem.h"
 
-/* clean exit when Ctrl-C is pressed */
-void ctrl_c_catched()
-{
-  port_close_ports();
-#if DEBUG
-  fprintf(stderr, "got ctrl-c and close gpio\n");
-#endif
-  exit(0);
-}
+#define TOGGLE_BIT 0x10000
 
 /* writes a 32bit word to a given address on a given device */
 void write32_to_FPGA(uint16_t address, uint32_t value)
 {
+  uint32_t toggleBit = readPC() & TOGGLE_BIT; 
+  
   /* set address RW_WRITE */
-  set_value_single(address & 0x7fff);
-  set_value(value);
-  writePC(0x10000);
-  writePC(0);
+  writePC((address & 0x7fff) | (toggleBit ^ TOGGLE_BIT));
+  
+  /* write value */
+  writePC((value >> 16) | toggleBit);
+  writePC((value & 0xffff) | (toggleBit ^ TOGGLE_BIT));
 }
 
+
 /* reads a 32bit word from a given address on a given device */
 int read32_from_FPGA(uint16_t address, uint32_t* value)
 {
+  uint32_t toggleBit = readPC() & TOGGLE_BIT;
   /* set address RW_WRITE */
-  set_value_single(address | 0x8000);
-
+  writePC((address | 0x8000) | (toggleBit ^ TOGGLE_BIT));
+  
+  /* read value */
   *value = ((readPB() << 16));
-  writePC(0x10000);
-  writePC(0);
-  writePC(0x10000);
-  writePC(0);
+  writePC(toggleBit);
+  
   *value |= (readPB() & 0xffff);
-  writePC(0x10000);
-  writePC(0);
-
+  writePC(toggleBit ^ TOGGLE_BIT);
+  
   return 0;
 }
 
+
 /* reads a 32bit word from a given address on a given device */
 int read32_from_FPGA_dma(uint16_t fifo_address,
                          uint32_t* values, 
                          uint32_t size)
 {
+  return -1;
+
+#if 0
   uint32_t tmp;
   uint32_t *start = NULL;
     
@@ -67,4 +67,11 @@ int read32_from_FPGA_dma(uint16_t fifo_address,
   } while(tmp & 0x01000000);
   
   return (values - start) - 1;
+#endif
+}
+
+void com_reset()
+{
+  setbitsPC(0x30000);
+  clrbitsPC(0x30000);
 }
index 3081efba119a543f98a62cff0e17fd47f6fd935b..11f61b21ba999d708da0f8624746bb751ec961a7 100644 (file)
 #define FS_FPGA_INT_H
 
 #include <stdint.h>
-#include <port.h>
 
-#define RW_READ  1
-#define RW_WRITE 0
-
-void ctrl_c_catched();
+/* writes a 32bit word to a given address on a given device */
 void write32_to_FPGA(uint16_t address, uint32_t value);
+
+/* reads a 32bit word from a given address on a given device */
 int read32_from_FPGA(uint16_t address, uint32_t* value);
+
+/* do not use, not yet implemented, returns -1 always */
 int read32_from_FPGA_dma(uint16_t fifo_address,
                          uint32_t* values,
                          uint32_t size);
 
-/* rw strobe. Raises PC(16) for a short time */
-static inline void strobe()
-{
-  setbitsPC(0x10000);
-  clrbitsPC(0x10000);
-}
-
-/* sends reset for communication logic PC(17,16)=11 */
-static inline void com_reset()
-{
-  setbitsPC(0x30000);
-  clrbitsPC(0x30000);
-}
-
-/* waits until PB(16) goes high, maximum 100 cycles */
-static inline int wait_for_valid()
-{
-  unsigned int timeout = 0;
-
-#if DEBUG
-  fprintf(stderr, "is_valid PORT_B\n");
-#endif
-
-  do {
-    if ((readPB() & 0x10000) != 0) {
-      return 0;
-    }
-  } while (timeout++ < 100);
-
-  com_reset();
-#if DEBUG
-  fprintf(stderr, "Error, I didnt get 'is_valid'\n");
-#endif
-
-  return -1;
-}
-
-/* waits until PB(16) goes low, maximum 100 cycles */
-static inline int wait_for_not_valid()
-{
-  unsigned int timeout = 0;
-
-#if DEBUG
-  fprintf(stderr, "is_not_valid PORT_B\n");
-#endif
-
-  do {
-    if ((readPB() & 0x10000) == 0) {
-      return 0;
-    }
-  } while (timeout++ < 100);
-
-  com_reset();
-#if DEBUG
-  fprintf(stderr, "Error, I didnt get 'is_not_valid'\n");
-#endif
-
-  return -1;
-}
-
-/* sends two strobes, hsb then lsb of value */
-static inline void set_value(uint32_t value)
-{
-  writePC((value>>16)+0x10000);
-  writePC(0);
-  writePC((value & 0xffff) + 0x10000);
-  writePC(0);
-}
-
-/* sends one strobe, lsb of value only */
-static inline void set_value_single(uint16_t value)
-{
-  writePC(value + 0x10000);
-  writePC(0);
-}
-
-/* sends address to device, wrapper for set_value */
-static inline void set_address(uint8_t dir, uint16_t address)
-{
-
-  if (dir == RW_READ) {
-    set_value_single(address | 0x8000);
-  } else {
-    set_value_single(address & 0x7fff);
-  }
-}
+/* sends reset for communication logic PC(17, 16) = 11 */
+void com_reset();
 
 #endif