From 4d387d48ac917d09df13c20f54f1074439620847 Mon Sep 17 00:00:00 2001 From: hadaq Date: Mon, 7 Sep 2009 21:22:18 +0000 Subject: [PATCH] fs_fpga.. removed, it all in trbnet.h now --- libtrbnet/Makefile | 9 ++--- libtrbnet/trbcmd.c | 43 ++++++++++++++------- libtrbnet/trbnet.c | 94 +++++++++++++++++++++++++++++++++++++++++++++- libtrbnet/trbnet.h | 6 +++ 4 files changed, 131 insertions(+), 21 deletions(-) diff --git a/libtrbnet/Makefile b/libtrbnet/Makefile index ffc70ea..4ed2074 100644 --- a/libtrbnet/Makefile +++ b/libtrbnet/Makefile @@ -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 diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 1628738..c2fcb52 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -9,7 +9,6 @@ #include #include #include -#include #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 { diff --git a/libtrbnet/trbnet.c b/libtrbnet/trbnet.c index 0ed4309..67b94e5 100644 --- a/libtrbnet/trbnet.c +++ b/libtrbnet/trbnet.c @@ -1,4 +1,4 @@ -const char trbnet_version[] = "$Revision: 2.40 $"; +const char trbnet_version[] = "$Revision: 2.41 $"; #include #include @@ -10,7 +10,6 @@ const char trbnet_version[] = "$Revision: 2.40 $"; #include #include -#include #include #include @@ -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; +} diff --git a/libtrbnet/trbnet.h b/libtrbnet/trbnet.h index 82a2b57..64ff780 100644 --- a/libtrbnet/trbnet.h +++ b/libtrbnet/trbnet.h @@ -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 -- 2.43.0