#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;
} while(tmp & 0x01000000);
return (values - start) - 1;
+#endif
+}
+
+void com_reset()
+{
+ setbitsPC(0x30000);
+ clrbitsPC(0x30000);
}
#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