Separate headers (#57)

* WIP, ctb

* WIP, eiger

* WIP, gotthard

* WIP, jungfrau

* WIP, gotthard2

* WIP, mythen3

* WIP, moench

* fixed gotthard apiversioning mismatch with gotthard2
This commit is contained in:
Dhanya Thattil 2019-08-30 11:17:37 +02:00 committed by GitHub
parent 49d47e633d
commit 0d35b966ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 945 additions and 564 deletions

View File

@ -1,31 +1,44 @@
add_executable(ctbDetectorServer
add_executable(ctbDetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/blackfin.c
../slsDetectorServer/src/common.c
../slsDetectorServer/src/commonServerFunctions.c
../slsDetectorServer/src/communication_funcs_UDP.c
../slsDetectorServer/src/UDPPacketHeaderGenerator.c
../slsDetectorServer/src/AD7689.c
../slsDetectorServer/src/AD9257.c
../slsDetectorServer/src/ALTERA_PLL.c
../slsDetectorServer/src/I2C.c
../slsDetectorServer/src/INA226.c
../slsDetectorServer/src/LTC2620.c
../slsDetectorServer/src/MAX1932.c
../slsDetectorServer/src/programfpga.c
)
include_directories(
../slsDetectorServer/
../slsDetectorServer/include
../../slsSupportLib/include
)
target_include_directories(ctbDetectorServer
target_include_directories(ctbDetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(ctbDetectorServer
target_compile_definitions(ctbDetectorServer_virtual
PUBLIC CHIPTESTBOARDD VIRTUAL STOP_SERVER
)
target_link_libraries(ctbDetectorServer
target_link_libraries(ctbDetectorServer_virtual
PUBLIC pthread rt
)
set_target_properties(ctbDetectorServer PROPERTIES
set_target_properties(ctbDetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS ctbDetectorServer
install(TARGETS ctbDetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -1,16 +1,19 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = ctbDetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programfpga.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
@ -30,9 +33,10 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
rm $(main_src)*.o
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o

View File

@ -4,19 +4,21 @@
#include "communication_funcs_UDP.h"
#include "UDPPacketHeaderGenerator.h"
#include "common.h"
#include "AD9257.h" // commonServerFunctions.h, blackfin.h, ansi.h
#include "AD7689.h" // slow adcs
#include "LTC2620.h" // dacs
#include "MAX1932.h" // hv
#include "INA226.h" // i2c
#include "ALTERA_PLL.h" // pll
#include <time.h>
#include "blackfin.h"
#ifndef VIRTUAL
#include "programfpga.h"
#else
#include "blackfin.h"
#endif
#include <string.h>
#include <unistd.h> // usleep
#ifdef VIRTUAL
#include <pthread.h>
#include <time.h>
#endif
@ -526,7 +528,7 @@ void setupDetector() {
{
int idac = 0;
for (idac = 0; idac < NDAC; ++idac) {
setDAC(idac, LTC2620_PWR_DOWN_VAL, 0); //has to be before setvchip
setDAC(idac, LTC2620_GetPowerDownValue(), 0); //has to be before setvchip
}
}
@ -1050,7 +1052,7 @@ enum detectorSettings getSettings() {
void setDAC(enum DACINDEX ind, int val, int mV) {
if (val < 0 && val != LTC2620_PWR_DOWN_VAL)
if (val < 0 && val != LTC2620_GetPowerDownValue())
return;
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
@ -1081,7 +1083,7 @@ int getDAC(enum DACINDEX ind, int mV) {
}
int getMaxDacSteps() {
return LTC2620_MAX_STEPS;
return LTC2620_GetMaxNumSteps();
}
int dacToVoltage(int dac) {
@ -1126,11 +1128,11 @@ int isVchipValid(int val) {
int getVchip() {
// not set yet
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_PWR_DOWN_VAL)
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_GetPowerDownValue())
return dacValues[D_PWR_CHIP];
int voltage = -1;
// dac to voltage
ConvertToDifferentRange(LTC2620_MAX_VAL, LTC2620_MIN_VAL, VCHIP_MIN_MV, VCHIP_MAX_MV,
ConvertToDifferentRange(LTC2620_GetMaxInput(), LTC2620_GetMinInput(), VCHIP_MIN_MV, VCHIP_MAX_MV,
dacValues[D_PWR_CHIP], &voltage);
return voltage;
}
@ -1140,12 +1142,12 @@ void setVchip(int val) {
if (val != -1) {
FILE_LOG(logINFOBLUE, ("Setting Vchip to %d mV\n", val));
int dacval = LTC2620_PWR_DOWN_VAL;
int dacval = LTC2620_GetPowerDownValue();
// validate & convert it to dac
if (val != LTC2620_PWR_DOWN_VAL) {
if (val != LTC2620_GetPowerDownValue()) {
// convert voltage to dac
if (ConvertToDifferentRange(VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_MAX_VAL, LTC2620_MIN_VAL, //min val is max V
if (ConvertToDifferentRange(VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_GetMaxInput(), LTC2620_GetMinInput(), //min val is max V
val, &dacval) == FAIL) {
FILE_LOG(logERROR, ("\tVChip %d mV invalid. Is not between %d and %d mV\n", val, VCHIP_MIN_MV, VCHIP_MAX_MV));
return;
@ -1238,7 +1240,7 @@ int isPowerValid(enum DACINDEX ind, int val) {
int min = (ind == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
// not power_rgltr_max because it is allowed only upto vchip max - 200
if (val != 0 && (val != LTC2620_PWR_DOWN_VAL) && (val < min || val > (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT))) {
if (val != 0 && (val != LTC2620_GetPowerDownValue()) && (val < min || val > (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT))) {
return 0;
}
return 1;
@ -1267,14 +1269,14 @@ int getPower(enum DACINDEX ind) {
}
// dac powered off
if (dacValues[ind] == LTC2620_PWR_DOWN_VAL) {
FILE_LOG(logWARNING, ("Power %d enabled, dac value %d, voltage at minimum or 0\n", ind, LTC2620_PWR_DOWN_VAL));
return LTC2620_PWR_DOWN_VAL;
if (dacValues[ind] == LTC2620_GetPowerDownValue()) {
FILE_LOG(logWARNING, ("Power %d enabled, dac value %d, voltage at minimum or 0\n", ind, LTC2620_GetPowerDownValue()));
return LTC2620_GetPowerDownValue();
}
// vchip not set, weird error, should not happen (as vchip set to max in the beginning)
// unless user set vchip to LTC2620_PWR_DOWN_VAL and then tried to get a power regulator value
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_PWR_DOWN_VAL) {
// unless user set vchip to LTC2620_GetPowerDownValue() and then tried to get a power regulator value
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_GetPowerDownValue()) {
FILE_LOG(logERROR, ("Cannot read power regulator %d (vchip not set)."
"Set a power regulator, which will also set vchip.\n"));
return -1;
@ -1282,7 +1284,7 @@ int getPower(enum DACINDEX ind) {
// convert dac to voltage
int retval = -1;
ConvertToDifferentRange(LTC2620_MAX_VAL, LTC2620_MIN_VAL, POWER_RGLTR_MIN, POWER_RGLTR_MAX,
ConvertToDifferentRange(LTC2620_GetMaxInput(), LTC2620_GetMinInput(), POWER_RGLTR_MIN, POWER_RGLTR_MAX,
dacValues[ind], &retval);
return retval;
}
@ -1322,7 +1324,7 @@ void setPower(enum DACINDEX ind, int val) {
// power down dac
FILE_LOG(logDEBUG1, ("Powering off P%d (DAC %d)\n", adcIndex, ind));
setDAC(ind, LTC2620_PWR_DOWN_VAL, 0);
setDAC(ind, LTC2620_GetPowerDownValue(), 0);
// set vchip
setVchip(vchip);
@ -1333,15 +1335,15 @@ void setPower(enum DACINDEX ind, int val) {
//(power off is anyway done with power enable)
if (val == 0)
val = LTC2620_PWR_DOWN_VAL;
val = LTC2620_GetPowerDownValue();
// convert it to dac (power off is anyway done with power enable)
if (val != LTC2620_PWR_DOWN_VAL) {
if (val != LTC2620_GetPowerDownValue()) {
FILE_LOG(logDEBUG1, ("Convert Power of %d mV to dac units\n", val));
int dacval = -1;
// convert voltage to dac
if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_MAX_VAL, LTC2620_MIN_VAL,
if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_GetMaxInput(), LTC2620_GetMinInput(),
val, &dacval) == FAIL) {
FILE_LOG(logERROR, ("\tPower index %d of value %d mV invalid. Is not between %d and %d mV\n",
ind, val, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT));

View File

@ -1,62 +1,64 @@
set(src
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/communication_funcs_UDP.c
../slsDetectorServer/src/common.c
)
include_directories(
../slsDetectorServer
../slsDetectorServer/include
../../slsSupportLib/include
)
add_executable(eigerDetectorServerMaster
add_executable(eigerDetectorServerMaster_virtual
${src}
)
target_include_directories(eigerDetectorServerMaster
target_include_directories(eigerDetectorServerMaster_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(eigerDetectorServerMaster
target_compile_definitions(eigerDetectorServerMaster_virtual
PUBLIC EIGERD PCCOMPILE STOP_SERVER
PUBLIC VIRTUAL DVIRTUAL_9M
PUBLIC VIRTUAL_MASTER
)
target_link_libraries(eigerDetectorServerMaster
target_link_libraries(eigerDetectorServerMaster_virtual
PUBLIC pthread rt
)
set_target_properties(eigerDetectorServerMaster PROPERTIES
set_target_properties(eigerDetectorServerMaster_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS eigerDetectorServerMaster
install(TARGETS eigerDetectorServerMaster_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
add_executable(eigerDetectorServerSlave
add_executable(eigerDetectorServerSlave_virtual
${src}
)
target_include_directories(eigerDetectorServerSlave
target_include_directories(eigerDetectorServerSlave_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(eigerDetectorServerSlave
target_compile_definitions(eigerDetectorServerSlave_virtual
PUBLIC EIGERD PCCOMPILE STOP_SERVER
PUBLIC VIRTUAL DVIRTUAL_9M
)
target_link_libraries(eigerDetectorServerSlave
target_link_libraries(eigerDetectorServerSlave_virtual
PUBLIC pthread rt
)
set_target_properties(eigerDetectorServerSlave PROPERTIES
set_target_properties(eigerDetectorServerSlave_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS eigerDetectorServerSlave
install(TARGETS eigerDetectorServerSlave_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -1,17 +1,20 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = powerpc-4xx-softfloat-
BLACKFIN_CC = bfin-uclinux-gcc
CC = $(CROSS)gcc
CFLAGS += -Wall -DEIGERD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DEIGERD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = eigerDetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c
SRCS = slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c
SRCS += $(main_src)communication_funcs.c $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs_UDP.c $(main_src)common.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS) #hv9m_blackfin_server

View File

@ -1,12 +1,14 @@
add_executable(gotthard2DetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/blackfin.c
../slsDetectorServer/src/communication_funcs_UDP.c
)
include_directories(
../slsDetectorServer/
../slsDetectorServer/include
../../slsSupportLib/include
)

View File

@ -1,16 +1,19 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DGOTTHARD2D -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DGOTTHARD2D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = gotthard2DetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
@ -29,9 +32,10 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
rm $(main_src)*.o
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o

View File

@ -1,15 +1,19 @@
#include "slsDetectorFunctionList.h"
#include "versionAPI.h"
#include "clogger.h"
#include "blackfin.h"
#ifdef VIRTUAL
#include "communication_funcs_UDP.h"
#endif
#include <string.h>
#include <unistd.h> // usleep
#ifdef VIRTUAL
#include <pthread.h>
#include <time.h>
#endif
#include <string.h>
#include <unistd.h> // usleep
#include "blackfin.h"
// Global variable from slsDetectorServer_funcs

View File

@ -1,31 +1,37 @@
add_executable(gotthardDetectorServer
add_executable(gotthardDetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/blackfin.c
../slsDetectorServer/src/AD9252.c
../slsDetectorServer/src/AD9257.c
../slsDetectorServer/src/LTC2620.c
../slsDetectorServer/src/common.c
../slsDetectorServer/src/commonServerFunctions.c
)
include_directories(
../slsDetectorServer/
../slsDetectorServer/include
../../slsSupportLib/include
)
target_include_directories(gotthardDetectorServer
target_include_directories(gotthardDetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(gotthardDetectorServer
target_compile_definitions(gotthardDetectorServer_virtual
PUBLIC GOTTHARDD VIRTUAL STOP_SERVER
)
target_link_libraries(gotthardDetectorServer
target_link_libraries(gotthardDetectorServer_virtual
PUBLIC pthread rt
)
set_target_properties(gotthardDetectorServer PROPERTIES
set_target_properties(gotthardDetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS gotthardDetectorServer
install(TARGETS gotthardDetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -1,19 +1,20 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DGOTTHARDD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DGOTTHARDD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = gotthardDetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)AD9252.c $(main_src)AD9257.c $(main_src)LTC2620.c $(main_src)common.c $(main_src)commonServerFunctions.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
boot: $(OBJS)
@ -30,9 +31,10 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
rm $(main_src)*.o
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o

View File

@ -6,13 +6,16 @@
#include "AD9257.h" // commonServerFunctions.h, blackfin.h, ansi.h
#include "AD9252.h" // old board compatibility
#include "LTC2620.h" // dacs
#ifdef VIRTUAL
#include "blackfin.h"
#include "string.h"
#include <unistd.h> // usleep
#ifdef VIRTUAL
#include <pthread.h>
#include <time.h>
#endif
#include "string.h"
// Variables that will be exported
int phaseShift = DEFAULT_PHASE_SHIFT;
@ -1091,7 +1094,7 @@ int getDAC(enum DACINDEX ind, int mV) {
}
int getMaxDacSteps() {
return LTC2620_MAX_STEPS;
return LTC2620_GetMaxNumSteps();
}
@ -1377,7 +1380,7 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t
FILE_LOG(logDEBUG1, ("\tWrite back released. MultiPurpose reg: 0x%x\n", bus_r(addr)));
FILE_LOG(logDEBUG1, ("\tConfiguring MAC CONF\n"));
mac_conf *mac_conf_regs = (mac_conf*)(CSP0BASE + ENET_CONF_REG * 2); // direct write
mac_conf *mac_conf_regs = (mac_conf*)(Blackfin_getBaseAddress() + ENET_CONF_REG * 2); // direct write
mac_conf_regs->mac.mac_dest_mac1 = ((destmac >> (8 * 5)) & 0xFF);
mac_conf_regs->mac.mac_dest_mac2 = ((destmac >> (8 * 4)) & 0xFF);
mac_conf_regs->mac.mac_dest_mac3 = ((destmac >> (8 * 3)) & 0xFF);
@ -1415,7 +1418,7 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t
mac_conf_regs->udp.udp_chksum = 0x0000;
FILE_LOG(logDEBUG1, ("\tConfiguring TSE\n"));
tse_conf *tse_conf_regs = (tse_conf*)(CSP0BASE + TSE_CONF_REG * 2); // direct write
tse_conf *tse_conf_regs = (tse_conf*)(Blackfin_getBaseAddress() + TSE_CONF_REG * 2); // direct write
tse_conf_regs->rev = 0xA00;
tse_conf_regs->scratch = 0xCCCCCCCC;
tse_conf_regs->command_config = 0xB;

View File

@ -1,31 +1,40 @@
add_executable(jungfrauDetectorServer
add_executable(jungfrauDetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/blackfin.c
../slsDetectorServer/src/common.c
../slsDetectorServer/src/commonServerFunctions.c
../slsDetectorServer/src/AD9257.c
../slsDetectorServer/src/ALTERA_PLL.c
../slsDetectorServer/src/LTC2620.c
../slsDetectorServer/src/MAX1932.c
../slsDetectorServer/src/programfpga.c
../slsDetectorServer/src/communication_funcs_UDP.c
)
include_directories(
../slsDetectorServer/
../slsDetectorServer/include
../../slsSupportLib/include
)
target_include_directories(jungfrauDetectorServer
target_include_directories(jungfrauDetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(jungfrauDetectorServer
target_compile_definitions(jungfrauDetectorServer_virtual
PUBLIC JUNGFRAUD VIRTUAL STOP_SERVER
)
target_link_libraries(jungfrauDetectorServer
target_link_libraries(jungfrauDetectorServer_virtual
PUBLIC pthread rt
)
set_target_properties(jungfrauDetectorServer PROPERTIES
set_target_properties(jungfrauDetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS jungfrauDetectorServer
install(TARGETS jungfrauDetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -1,16 +1,19 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DJUNGFRAUD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DJUNGFRAUD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = jungfrauDetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programfpga.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
@ -29,9 +32,10 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
rm $(main_src)*.o
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o

View File

@ -6,13 +6,17 @@
#include "LTC2620.h" // dacs
#include "MAX1932.h" // hv
#include "ALTERA_PLL.h" // pll
#include "blackfin.h"
#include "common.h"
#ifndef VIRTUAL
#include "programfpga.h"
#else
#include "communication_funcs_UDP.h"
#include "blackfin.h"
#endif
#include <string.h>
#include <unistd.h> // usleep
#ifdef VIRTUAL
#include <pthread.h>
#include <time.h>
#endif
@ -921,7 +925,7 @@ int getDAC(enum DACINDEX ind, int mV) {
}
int getMaxDacSteps() {
return LTC2620_MAX_STEPS;
return LTC2620_GetMaxNumSteps();
}
int getADC(enum ADCINDEX ind){
@ -1057,7 +1061,7 @@ void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, uint64_
// calculate rxr endpoint offset
addr += (iRxEntry * RXR_ENDPOINT_OFST);
// get struct memory
udp_header *udp = (udp_header*) (CSP0BASE + addr * 2);
udp_header *udp = (udp_header*) (Blackfin_getBaseAddress() + addr * 2);
memset(udp, 0, sizeof(udp_header));
// mac addresses

View File

@ -1,31 +1,41 @@
add_executable(moenchDetectorServer
add_executable(moenchDetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/blackfin.c
../slsDetectorServer/src/common.c
../slsDetectorServer/src/commonServerFunctions.c
../slsDetectorServer/src/communication_funcs_UDP.c
../slsDetectorServer/src/UDPPacketHeaderGenerator.c
../slsDetectorServer/src/AD9257.c
../slsDetectorServer/src/ALTERA_PLL.c
../slsDetectorServer/src/LTC2620.c
../slsDetectorServer/src/MAX1932.c
../slsDetectorServer/src/programfpga.c
)
include_directories(
../slsDetectorServer/
../slsDetectorServer/include
../../slsSupportLib/include
)
target_include_directories(moenchDetectorServer
target_include_directories(moenchDetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(moenchDetectorServer
target_compile_definitions(moenchDetectorServer_virtual
PUBLIC MOENCHD VIRTUAL STOP_SERVER
)
target_link_libraries(moenchDetectorServer
target_link_libraries(moenchDetectorServer_virtual
PUBLIC pthread rt
)
set_target_properties(moenchDetectorServer PROPERTIES
set_target_properties(moenchDetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS moenchDetectorServer
install(TARGETS moenchDetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -1,16 +1,19 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DMOENCHD -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DMOENCHD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = moenchDetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programfpga.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
@ -29,9 +32,10 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
rm $(main_src)*.o
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o

View File

@ -8,12 +8,14 @@
#include "LTC2620.h" // dacs
#include "MAX1932.h" // hv
#include "ALTERA_PLL.h" // pll
#include "blackfin.h"
#ifndef VIRTUAL
#include "programfpga.h"
#else
#include "blackfin.h"
#endif
#include <string.h>
#include <unistd.h> // usleep
#ifdef VIRTUAL
#include <pthread.h>
#include <time.h>
#endif

View File

@ -1,12 +1,14 @@
add_executable(mythen3DetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
../slsDetectorServer/src/slsDetectorServer.c
../slsDetectorServer/src/slsDetectorServer_funcs.c
../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/blackfin.c
../slsDetectorServer/src/communication_funcs_UDP.c
)
include_directories(
../slsDetectorServer/
../slsDetectorServer/include
../../slsSupportLib/include
)

View File

@ -1,16 +1,19 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
main_inc = ../slsDetectorServer/include/
main_src = ../slsDetectorServer/src/
support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DMYTHEN3D -DSTOP_SERVER -I$(main_server) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DMYTHEN3D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm
PROGS = mythen3DetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
@ -29,9 +32,10 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
rm $(main_src)*.o
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o

View File

@ -1,15 +1,17 @@
#include "slsDetectorFunctionList.h"
#include "versionAPI.h"
#include "clogger.h"
#include "blackfin.h"
#ifdef VIRTUAL
#include "communication_funcs_UDP.h"
#endif
#include <string.h>
#include <unistd.h> // usleep
#ifdef VIRTUAL
#include <pthread.h>
#include <time.h>
#endif
#include <string.h>
#include <unistd.h> // usleep
#include "blackfin.h"
// Global variable from slsDetectorServer_funcs

View File

@ -0,0 +1,49 @@
#pragma once
#include <inttypes.h>
/**
* Set Defines
* @param reg spi register
* @param roreg spi readout register
* @param cmsk conversion mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
*/
void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst);
/**
* Disable SPI
*/
void AD7689_Disable();
/**
* Set SPI reg value
* @param codata value to be set
*/
void AD7689_Set(uint32_t codata);
/**
* Get SPI reg value
* @returns SPI reg value
*/
uint16_t AD7689_Get();
/**
* Get temperature
* @returns temperature in °C
*/
int AD7689_GetTemperature();
/**
* Reads channels voltage
* @param ichan channel number from 0 to 7
* @returns channel voltage in mV
*/
int AD7689_GetChannel(int ichan);
/**
* Configure
*/
void AD7689_Configure();

View File

@ -0,0 +1,29 @@
#pragma once
#include <inttypes.h>
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
*/
void AD9252_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst);
/**
* Disable SPI
*/
void AD9252_Disable();
/**
* Set SPI reg value
* @param codata value to be set
*/
void AD9252_Set(int addr, int val);
/**
* Configure
*/
void AD9252_Configure();

View File

@ -0,0 +1,41 @@
#pragma once
#include <inttypes.h>
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
*/
void AD9257_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst);
/**
* Disable SPI
*/
void AD9257_Disable() ;
/**
* Get vref voltage
*/
int AD9257_GetVrefVoltage(int mV);
/**
* Set vref voltage
* @param val voltage to be set (0 for 1.0V, 1 for 1.14V, 2 for 1.33V, 3 for 1.6V, 4 for 2.0V
* @returns ok or fail
*/
int AD9257_SetVrefVoltage(int val, int mV);
/**
* Set SPI reg value
* @param codata value to be set
*/
void AD9257_Set(int addr, int val);
/**
* Configure
*/
void AD9257_Configure();

View File

@ -0,0 +1,54 @@
#pragma once
#include <inttypes.h>
/**
* Set Defines
* @param creg control register
* @param preg parameter register
* @param rprmsk reconfig parameter reset mask
* @param wpmsk write parameter mask
* @param prmsk pll reset mask
* @param amsk address mask
* @param aofst address offset
*/
void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32_t wpmsk, uint32_t prmsk, uint32_t amsk, int aofst);
/**
* Reset only PLL
*/
void ALTERA_PLL_ResetPLL ();
/**
* Reset PLL Reconfiguration and PLL
*/
void ALTERA_PLL_ResetPLLAndReconfiguration ();
/**
* Set PLL Reconfig register
* @param reg register
* @param val value
*/
void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val);
/**
* Write Phase Shift
* @param phase phase shift
* @param clkIndex clock index
* @param pos 1 if up down direction of shift is positive, else 0
*/
void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos);
/**
* Set PLL mode register to polling mode
*/
void ALTERA_PLL_SetModePolling();
/**
* Calculate and write output frequency
* @param clkIndex clock index
* @param pllVCOFreqMhz PLL VCO Frequency in Mhz
* @param value frequency to set to
* @param frequency set
*/
int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value);

View File

@ -0,0 +1,38 @@
#pragma once
#include <inttypes.h>
/**
* Configure the I2C core,
* Enable core and
* Calibrate the calibration register for current readout
* @param creg control register (defined in RegisterDefs.h)
* @param sreg status register (defined in RegisterDefs.h)
* @param rreg rx data fifo register (defined in RegisterDefs.h)
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
* @param slreg scl low count register (defined in RegisterDefs.h)
* @param shreg scl high count register (defined in RegisterDefs.h)
* @param sdreg sda hold register (defined in RegisterDefs.h)
* @param treg transfer command fifo register (defined in RegisterDefs.h)
*/
void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
uint32_t rreg, uint32_t rlvlreg,
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg);
/**
* Read register
* @param deviceId device Id
* @param addr register address
* @returns value read from register
*/
uint32_t I2C_Read(uint32_t devId, uint32_t addr);
/**
* Write register (16 bit value)
* @param deviceId device Id
* @param addr register address
* @param data data to be written (16 bit)
*/
void I2C_Write(uint32_t devId, uint32_t addr, uint16_t data);

View File

@ -0,0 +1,39 @@
#pragma once
#include <inttypes.h>
/**
* Configure the I2C core and Enable core
* @param rOhm shunt resister value in Ohms (defined in slsDetectorServer_defs.h)
* @param creg control register (defined in RegisterDefs.h)
* @param sreg status register (defined in RegisterDefs.h)
* @param rreg rx data fifo register (defined in RegisterDefs.h)
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
* @param slreg scl low count register (defined in RegisterDefs.h)
* @param shreg scl high count register (defined in RegisterDefs.h)
* @param sdreg sda hold register (defined in RegisterDefs.h)
* @param treg transfer command fifo register (defined in RegisterDefs.h)
*/
void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
uint32_t rreg, uint32_t rlvlreg,
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg);
/**
* Calibrate resolution of current register
* @param deviceId device Id (defined in slsDetectorServer_defs.h)
*/
void INA226_CalibrateCurrentRegister(uint32_t deviceId);
/**
* Read voltage of device
* @param deviceId device Id
* @returns voltage in mV
*/
int INA226_ReadVoltage(uint32_t deviceId);
/**
* Read current
* @param deviceId device Id
* @returns current in mA
*/
int INA226_ReadCurrent(uint32_t deviceId);

View File

@ -0,0 +1,115 @@
#pragma once
#include <inttypes.h>
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
* @param nd total number of dacs for this board (for dac channel and daisy chain chip id)
* @param minMV minimum voltage determined by hardware
* @param maxMV maximum voltage determined by hardware
*/
void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int nd, int minMV, int maxMV);
/**
* Disable SPI
*/
void LTC2620_Disable();
/**
* Get power down value
*/
int LTC2620_GetPowerDownValue();
/**
* Get minimum input value for dac
*/
int LTC2620_GetMinInput();
/**
* Get maximum input value for dac
*/
int LTC2620_GetMaxInput();
/**
* Get max number of steps
*/
int LTC2620_GetMaxNumSteps();
/**
* Convert voltage to dac units
* @param voltage value in mv
* @param dacval pointer to value converted to dac units
* @returns FAIL when voltage outside limits, OK if conversion successful
*/
int LTC2620_VoltageToDac(int voltage, int* dacval);
/**
* Convert dac units to voltage
* @param dacval dac units
* @param voltage pointer to value converted to mV
* @returns FAIL when voltage outside limits, OK if conversion successful
*/
int LTC2620_DacToVoltage(int dacval, int* voltage);
/**
* Set a single chip (all non ctb detectors use this)
* when max dac is 8
* @param cmd command
* @param data dac value to be set
* @param dacaddr dac channel number in chip
*/
void LTC2620_SetSingle(int cmd, int data, int dacaddr);
/**
* bit bang the data into all the chips daisy fashion
* @param valw current value of register while bit banging
* @param val data to be sent (data, dac addr and command)
*/
void LTC2620_SendDaisyData(uint32_t* valw, uint32_t val);
/**
* Set a single chip (all non ctb detectors use this)
* when max dac is 8
* @param cmd command
* @param data dac value to be set
* @param dacaddr dac channel number in chip
* @param chipIndex index of the chip
*/
void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex);
/**
* Sets a single chip (LTC2620_SetSingle) or multiple chip (LTC2620_SetDaisy)
* multiple chip is only for ctb where the multiple chips are connected in daisy fashion
* @param cmd command to send
* @param data dac value to be set
* @param dacaddr dac channel number for the chip
* @param chipIndex the chip to be set
*/
void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex);
/**
* Configure (obtains dacaddr, command and ichip and calls LTC2620_Set)
*/
void LTC2620_Configure();
/**
* Set Dac (obtains dacaddr, command and ichip and calls LTC2620_Set)
* @param dacnum dac number
* @param data dac value to set
*/
void LTC2620_SetDAC (int dacnum, int data);
/**
* Set dac in dac units or mV
* @param dacnum dac index
* @param val value in dac units or mV
* @param mV 0 for dac units and 1 for mV unit
* @param dacval pointer to value in dac units
* @returns OK or FAIL for success of operation
*/
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval);

View File

@ -0,0 +1,31 @@
#pragma once
#include <inttypes.h>
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
* @param minMV minimum voltage determined by hardware
* @param maxMV maximum voltage determined by hardware
*/
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst,
int minMV, int maxMV);
/**
* Disable SPI
*/
void MAX1932_Disable();
/**
* Set value
* @param val value to set
* @return OK or FAIL
*/
int MAX1932_Set (int val) ;

View File

@ -0,0 +1,26 @@
#pragma once
#include <inttypes.h>
/**
* Get current udp packet number
*/
uint32_t getUDPPacketNumber();
/**
* Get current udp frame number
*/
uint64_t getUDPFrameNumber();
/**
* Called for each UDP packet header creation
* @param buffer pointer to header
* @param id module id
*/
void createUDPPacketHeader(char* buffer, uint16_t id);
/**
* fill up the udp packet with data till its full
* @param buffer pointer to memory
*/
int fillUDPPacket(char* buffer);

View File

@ -0,0 +1,105 @@
#pragma once
#include <sys/types.h>
#include <inttypes.h>
/** I2C defines */
#define I2C_CLOCK_MHZ (131.25)
/**
* Write into a 16 bit register
* @param offset address offset
* @param data 16 bit data
*/
void bus_w16(u_int32_t offset, u_int16_t data);
/**
* Read from a 16 bit register
* @param offset address offset
* @retuns 16 bit data read
*/
u_int16_t bus_r16(u_int32_t offset);
/**
* Write into a 32 bit register
* @param offset address offset
* @param data 32 bit data
*/
void bus_w(u_int32_t offset, u_int32_t data);
/**
* Read from a 32 bit register
* @param offset address offset
* @retuns 32 bit data read
*/
u_int32_t bus_r(u_int32_t offset);
/**
* Read from a 64 bit register
* @param aLSB LSB offset address
* @param aMSB MSB offset address
* @returns 64 bit data read
*/
int64_t get64BitReg(int aLSB, int aMSB);
/**
* Write into a 64 bit register
* @param value 64 bit data
* @param aLSB LSB offset address
* @param aMSB MSB offset address
* @returns 64 bit data read
*/
int64_t set64BitReg(int64_t value, int aLSB, int aMSB);
/**
* Read unsigned 64 bit from a 64 bit register
* @param aLSB LSB offset address
* @param aMSB MSB offset address
* @returns unsigned 64 bit data read
*/
uint64_t getU64BitReg(int aLSB, int aMSB);
/**
* Write unsigned 64 bit into a 64 bit register
* @param value unsigned 64 bit data
* @param aLSB LSB offset address
* @param aMSB MSB offset address
*/
void setU64BitReg(uint64_t value, int aLSB, int aMSB);
/**
* Read from a 32 bit register (literal register value provided by client)
* @param offset address offset
* @retuns 32 bit data read
*/
u_int32_t readRegister(u_int32_t offset);
/**
* Write into a 32 bit register (literal register value provided by client)
* @param offset address offset
* @param data 32 bit data
*/
u_int32_t writeRegister(u_int32_t offset, u_int32_t data);
/**
* Read from a 16 bit register (literal register value provided by client)
* @param offset address offset
* @retuns 16 bit data read
*/
u_int32_t readRegister16(u_int32_t offset);
/**
* Write into a 16 bit register (literal register value provided by client)
* @param offset address offset
* @param data 16 bit data
*/
u_int32_t writeRegister16(u_int32_t offset, u_int32_t data);
/**
* Get base address for memory copy
*/
uint64_t Blackfin_getBaseAddress();
/**
* Map FPGA
*/
int mapCSP0(void);

View File

@ -0,0 +1,14 @@
#pragma once
/**
* Convert a value from a range to a different range (eg voltage to dac or vice versa)
* @param inputMin input minimum
* @param inputMax input maximum
* @param outputMin output minimum
* @param outputMax output maximum
* @param inputValue input value
* @param outputValue pointer to output value
* @returns FAIL if input value is out of bounds, else OK
*/
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
int inputValue, int* outputValue);

View File

@ -0,0 +1,15 @@
#pragma once
#include <inttypes.h>
void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit);
void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit);
void sendDataToSPI (uint32_t* valw, uint32_t addr, uint32_t val, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset);
uint32_t receiveDataFromSPI (uint32_t* valw, uint32_t addr, int numbitstoreceive, uint32_t clkmask, uint32_t readaddr) ;
void serializeToSPI(uint32_t addr, uint32_t val, uint32_t csmask, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset, int convBit);
uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive, uint32_t clkmask, uint32_t digoutmask, uint32_t readaddr, int convBit);

View File

@ -0,0 +1,34 @@
#pragma once
/**
* Get UDP socket desicriptor
* @param udp port index
*/
int getUdPSocketDescriptor(int index);
/**
* Set udp destination
* @param index udp port index
* @param ip udp destination ip
* @param port udp destination port
*/
int setUDPDestinationDetails(int index, const char* ip, unsigned short int port);
/**
* Create udp socket
* @param index udp port index
*/
int createUDPSocket(int index);
/**
* Writes to socket file descriptor
* @param index udp port index
* @param buf pointer to memory to write
* @param length length of buffer to write to socket
*/
int sendUDPPacket(int index, const char* buf, int length);
/**
* Close udp socket
* @index udp port index
*/
void closeUDPSocket(int index);

View File

@ -0,0 +1,52 @@
#pragma once
#include <stdio.h>
/**
* Define GPIO pins if not defined
*/
void defineGPIOpins();
/**
* Notify FPGA to not touch flash
*/
void FPGAdontTouchFlash();
/**
* Notify FPGA to program from flash
*/
void FPGATouchFlash();
/**
* Reset FPGA
*/
void resetFPGA();
/**
* Erasing flash
*/
void eraseFlash();
/**
* Open the drive to copy program and
* notify FPGA not to touch the program
* @param filefp pointer to flash
* @return 0 for success, 1 for fail (cannot open file for writing program)
*/
int startWritingFPGAprogram(FILE** filefp);
/**
* When done writing the program, close file pointer and
* notify FPGA to pick up the program from flash
* @param filefp pointer to flash
*/
void stopWritingFPGAprogram(FILE* filefp);
/**
* Write FPGA Program to flash
* @param fpgasrc source program
* @param fsize size of program
* @param filefp pointer to flash
* @return 0 for success, 1 for fail (cannot write)
*/
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp);

View File

@ -1,7 +1,9 @@
#pragma once
#include "AD7689.h"
#include "commonServerFunctions.h" // blackfin.h, ansi.h
#include "common.h"
#include "blackfin.h"
#include "clogger.h"
/* AD7689 ADC DEFINES */
@ -69,7 +71,7 @@
#define AD7689_INT_MAX_STEPS (0xFFFF + 1)
#define AD7689_TMP_C_FOR_1_MV (25.00 / 283.00)
// Definitions from the fpga
uint32_t AD7689_Reg = 0x0;
uint32_t AD7689_ROReg = 0x0;
uint32_t AD7689_CnvMask = 0x0;
@ -77,15 +79,6 @@ uint32_t AD7689_ClkMask = 0x0;
uint32_t AD7689_DigMask = 0x0;
int AD7689_DigOffset = 0x0;
/**
* Set Defines
* @param reg spi register
* @param roreg spi readout register
* @param cmsk conversion mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
*/
void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
FILE_LOG(logDEBUG, ("AD7689: reg:0x%x roreg:0x%x cmsk:0x%x clkmsk:0x%x dmsk:0x%x dofst:%d\n",
reg, roreg, cmsk, clkmsk, dmsk, dofst));
@ -97,9 +90,6 @@ void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clk
AD7689_DigOffset = dofst;
}
/**
* Disable SPI
*/
void AD7689_Disable() {
bus_w(AD7689_Reg, (bus_r(AD7689_Reg)
&~(AD7689_CnvMask)
@ -107,30 +97,18 @@ void AD7689_Disable() {
&~(AD7689_DigMask)));
}
/**
* Set SPI reg value
* @param codata value to be set
*/
void AD7689_Set(u_int32_t codata) {
void AD7689_Set(uint32_t codata) {
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Writing 0x%08x to Config Reg\n", codata));
serializeToSPI(AD7689_Reg, codata, AD7689_CnvMask, AD7689_ADC_CFG_NUMBITS,
AD7689_ClkMask, AD7689_DigMask, AD7689_DigOffset, 1);
}
/**
* Get SPI reg value
* @returns SPI reg value
*/
uint16_t AD7689_Get() {
FILE_LOG(logINFO, ("\tGetting ADC SPI Register.\n"));
return (uint16_t)serializeFromSPI(AD7689_Reg, AD7689_CnvMask, AD7689_ADC_DATA_NUMBITS,
AD7689_ClkMask, AD7689_DigMask, AD7689_ROReg, 1);
}
/**
* Get temperature
* @returns temperature in °C
*/
int AD7689_GetTemperature() {
AD7689_Set(
// read back
@ -167,11 +145,6 @@ int AD7689_GetTemperature() {
}
/**
* Reads channels voltage
* @param ichan channel number from 0 to 7
* @returns channel voltage in mV
*/
int AD7689_GetChannel(int ichan) {
// filter channels val
if (ichan < 0 || ichan >= AD7689_NUM_CHANNELS) {
@ -209,9 +182,6 @@ int AD7689_GetChannel(int ichan) {
return retval;
}
/**
* Configure
*/
void AD7689_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));

View File

@ -1,9 +1,7 @@
#pragma once
#include "AD9252.h"
#include "commonServerFunctions.h" // blackfin.h, ansi.h
#ifdef GOTTHARDD
#include <unistd.h>
#endif
#include "blackfin.h"
#include "clogger.h"
/* AD9252 ADC DEFINES */
#define AD9252_ADC_NUMBITS (24)
@ -100,20 +98,13 @@
#define AD9252_OUT_CLK_600_VAL ((0xa << AD9252_OUT_CLK_OFST) & AD9252_OUT_CLK_MSK)
#define AD9252_OUT_CLK_660_VAL ((0xb << AD9252_OUT_CLK_OFST) & AD9252_OUT_CLK_MSK) // 0xb - 0xf is 660
// defines from the fpga
uint32_t AD9252_Reg = 0x0;
uint32_t AD9252_CsMask = 0x0;
uint32_t AD9252_ClkMask = 0x0;
uint32_t AD9252_DigMask = 0x0;
int AD9252_DigOffset = 0x0;
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
*/
void AD9252_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
AD9252_Reg = reg;
AD9252_CsMask = cmsk;
@ -122,9 +113,6 @@ void AD9252_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dm
AD9252_DigOffset = dofst;
}
/**
* Disable SPI
*/
void AD9252_Disable() {
bus_w(AD9252_Reg, (bus_r(AD9252_Reg)
| AD9252_CsMask
@ -132,10 +120,6 @@ void AD9252_Disable() {
&~(AD9252_DigMask));
}
/**
* Set SPI reg value
* @param codata value to be set
*/
void AD9252_Set(int addr, int val) {
u_int32_t codata;
@ -145,9 +129,6 @@ void AD9252_Set(int addr, int val) {
AD9252_ClkMask, AD9252_DigMask, AD9252_DigOffset, 0);
}
/**
* Configure
*/
void AD9252_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring ADC9252:\n"));

View File

@ -1,9 +1,8 @@
#pragma once
#include "AD9257.h"
#include "commonServerFunctions.h" // blackfin.h, ansi.h
#ifdef GOTTHARDD
#include <unistd.h>
#endif
#include "blackfin.h"
#include "clogger.h"
#include "sls_detector_defs.h"
/* AD9257 ADC DEFINES */
#define AD9257_ADC_NUMBITS (24)
@ -126,6 +125,7 @@
#define AD9257_VREF_1_6_VAL ((0x3 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
#define AD9257_VREF_2_0_VAL ((0x4 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
// defines from the fpga
uint32_t AD9257_Reg = 0x0;
uint32_t AD9257_CsMask = 0x0;
uint32_t AD9257_ClkMask = 0x0;
@ -133,14 +133,6 @@ uint32_t AD9257_DigMask = 0x0;
int AD9257_DigOffset = 0x0;
int AD9257_VrefVoltage = 0;
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
*/
void AD9257_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
AD9257_Reg = reg;
AD9257_CsMask = cmsk;
@ -149,9 +141,6 @@ void AD9257_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dm
AD9257_DigOffset = dofst;
}
/**
* Disable SPI
*/
void AD9257_Disable() {
bus_w(AD9257_Reg, (bus_r(AD9257_Reg)
| AD9257_CsMask
@ -159,9 +148,6 @@ void AD9257_Disable() {
& ~(AD9257_DigMask));
}
/**
* Get vref voltage
*/
int AD9257_GetVrefVoltage(int mV) {
if (mV == 0)
return AD9257_VrefVoltage;
@ -182,11 +168,6 @@ int AD9257_GetVrefVoltage(int mV) {
}
}
/**
* Set vref voltage
* @param val voltage to be set (0 for 1.0V, 1 for 1.14V, 2 for 1.33V, 3 for 1.6V, 4 for 2.0V
* @returns ok or fail
*/
int AD9257_SetVrefVoltage(int val, int mV) {
int mode = val;
// convert to mode
@ -240,10 +221,6 @@ int AD9257_SetVrefVoltage(int val, int mV) {
return OK;
}
/**
* Set SPI reg value
* @param codata value to be set
*/
void AD9257_Set(int addr, int val) {
u_int32_t codata;
@ -253,9 +230,6 @@ void AD9257_Set(int addr, int val) {
AD9257_ClkMask, AD9257_DigMask, AD9257_DigOffset, 0);
}
/**
* Configure
*/
void AD9257_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring ADC9257:\n"));

View File

@ -1,4 +1,6 @@
#pragma once
#include "ALTERA_PLL.h"
#include "clogger.h"
#include "blackfin.h"
#include <unistd.h> // usleep
@ -72,6 +74,7 @@
#define ALTERA_PLL_WAIT_TIME_US (10 * 1000)
// defines from the fpga
uint32_t ALTERA_PLL_Cntrl_Reg = 0x0;
uint32_t ALTERA_PLL_Param_Reg = 0x0;
uint32_t ALTERA_PLL_Cntrl_RcnfgPrmtrRstMask = 0x0;
@ -81,16 +84,6 @@ uint32_t ALTERA_PLL_Cntrl_AddrMask = 0x0;
int ALTERA_PLL_Cntrl_AddrOfst = 0;
/**
* Set Defines
* @param creg control register
* @param preg parameter register
* @param rprmsk reconfig parameter reset mask
* @param wpmsk write parameter mask
* @param prmsk pll reset mask
* @param amsk address mask
* @param aofst address offset
*/
void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32_t wpmsk, uint32_t prmsk, uint32_t amsk, int aofst) {
ALTERA_PLL_Cntrl_Reg = creg;
ALTERA_PLL_Param_Reg = preg;
@ -101,9 +94,6 @@ void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32
ALTERA_PLL_Cntrl_AddrOfst = aofst;
}
/**
* Reset only PLL
*/
void ALTERA_PLL_ResetPLL () {
FILE_LOG(logINFO, ("Resetting only PLL\n"));
@ -119,9 +109,6 @@ void ALTERA_PLL_ResetPLL () {
}
/**
* Reset PLL Reconfiguration and PLL
*/
void ALTERA_PLL_ResetPLLAndReconfiguration () {
FILE_LOG(logINFO, ("Resetting PLL and Reconfiguration\n"));
@ -130,12 +117,6 @@ void ALTERA_PLL_ResetPLLAndReconfiguration () {
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) & ~ALTERA_PLL_Cntrl_RcnfgPrmtrRstMask & ~ALTERA_PLL_Cntrl_PLLRstMask);
}
/**
* Set PLL Reconfig register
* @param reg register
* @param val value
*/
void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val) {
FILE_LOG(logDEBUG1, ("Setting PLL Reconfig Reg, reg:0x%x, val:0x%x)\n", reg, val));
@ -164,12 +145,6 @@ void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val) {
usleep(ALTERA_PLL_WAIT_TIME_US);
}
/**
* Write Phase Shift
* @param phase phase shift
* @param clkIndex clock index
* @param pos 1 if up down direction of shift is positive, else 0
*/
void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
FILE_LOG(logINFO, ("\tWriting PLL Phase Shift\n"));
uint32_t value = (((phase << ALTERA_PLL_SHIFT_NUM_SHIFTS_OFST) & ALTERA_PLL_SHIFT_NUM_SHIFTS_MSK) |
@ -182,21 +157,11 @@ void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_PHASE_SHIFT_REG, value);
}
/**
* Set PLL mode register to polling mode
*/
void ALTERA_PLL_SetModePolling() {
FILE_LOG(logINFO, ("\tSetting Polling Mode\n"));
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_MODE_REG, ALTERA_PLL_MODE_PLLNG_MD_VAL);
}
/**
* Calculate and write output frequency
* @param clkIndex clock index
* @param pllVCOFreqMhz PLL VCO Frequency in Mhz
* @param value frequency to set to
* @param frequency set
*/
int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value) {
FILE_LOG(logDEBUG1, ("C%d: Setting output frequency to %d (pllvcofreq: %dMhz)\n", clkIndex, value, pllVCOFreqMhz));

View File

@ -1,6 +1,7 @@
#pragma once
#include "I2C.h"
#include "blackfin.h"
#include "clogger.h"
#include <unistd.h> // usleep
/**
@ -86,6 +87,7 @@
//#define I2C_RX_DATA_FIFO_LVL_OFST (0)
//#define I2C_RX_DATA_FIFO_LVL_MSK (0x000000FF << I2C_RX_DATA_FIFO_LVL_OFST)
// defines in the fpga
uint32_t I2C_Control_Reg = 0x0;
uint32_t I2C_Status_Reg = 0x0;
uint32_t I2C_Rx_Data_Fifo_Reg = 0x0;
@ -95,19 +97,7 @@ uint32_t I2C_Scl_High_Count_Reg = 0x0;
uint32_t I2C_Sda_Hold_Reg = 0x0;
uint32_t I2C_Transfer_Command_Fifo_Reg = 0x0;
/**
* Configure the I2C core,
* Enable core and
* Calibrate the calibration register for current readout
* @param creg control register (defined in RegisterDefs.h)
* @param sreg status register (defined in RegisterDefs.h)
* @param rreg rx data fifo register (defined in RegisterDefs.h)
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
* @param slreg scl low count register (defined in RegisterDefs.h)
* @param shreg scl high count register (defined in RegisterDefs.h)
* @param sdreg sda hold register (defined in RegisterDefs.h)
* @param treg transfer command fifo register (defined in RegisterDefs.h)
*/
void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
uint32_t rreg, uint32_t rlvlreg,
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
@ -160,12 +150,6 @@ void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
//The INA226 supports the transmission protocol for fast mode (1 kHz to 400 kHz) and high-speed mode (1 kHz to 2.94 MHz).
}
/**
* Read register
* @param deviceId device Id
* @param addr register address
* @returns value read from register
*/
uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
FILE_LOG(logDEBUG2, (" ================================================\n"));
FILE_LOG(logDEBUG2, (" Reading from I2C device 0x%x and reg 0x%x\n", devId, addr));
@ -222,12 +206,6 @@ uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
return retval;
}
/**
* Write register (16 bit value)
* @param deviceId device Id
* @param addr register address
* @param data data to be written (16 bit)
*/
void I2C_Write(uint32_t devId, uint32_t addr, uint16_t data) {
FILE_LOG(logDEBUG2, (" ================================================\n"));
FILE_LOG(logDEBUG2, (" Writing to I2C (Device:0x%x, reg:0x%x, data:%d)\n", devId, addr, data));

View File

@ -1,6 +1,8 @@
#pragma once
#include "INA226.h"
#include "I2C.h"
#include "clogger.h"
#include "common.h"
#include "math.h"
/**
@ -52,24 +54,12 @@
/** get current unit */
#define INA226_getConvertedCurrentUnits(shuntV, calibReg) ((double)shuntV * (double)calibReg / (double)2048)
// defines from the fpga
double INA226_Shunt_Resistor_Ohm = 0.0;
int INA226_Calibration_Register_Value = 0;
#define INA226_CALIBRATION_CURRENT_TOLERANCE (1.2268)
/**
* Configure the I2C core and Enable core
* @param rOhm shunt resister value in Ohms (defined in slsDetectorServer_defs.h)
* @param creg control register (defined in RegisterDefs.h)
* @param sreg status register (defined in RegisterDefs.h)
* @param rreg rx data fifo register (defined in RegisterDefs.h)
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
* @param slreg scl low count register (defined in RegisterDefs.h)
* @param shreg scl high count register (defined in RegisterDefs.h)
* @param sdreg sda hold register (defined in RegisterDefs.h)
* @param treg transfer command fifo register (defined in RegisterDefs.h)
*/
void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
uint32_t rreg, uint32_t rlvlreg,
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
@ -80,10 +70,6 @@ void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
I2C_ConfigureI2CCore(creg, sreg, rreg, rlvlreg, slreg, shreg, sdreg, treg);
}
/**
* Calibrate resolution of current register
* @param deviceId device Id (defined in slsDetectorServer_defs.h)
*/
void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
FILE_LOG(logINFO, ("Calibrating Current Register for Device ID: 0x%x\n", deviceId));
// get calibration value based on shunt resistor
@ -104,11 +90,6 @@ void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
}
}
/**
* Read voltage of device
* @param deviceId device Id
* @returns voltage in mV
*/
int INA226_ReadVoltage(uint32_t deviceId) {
FILE_LOG(logDEBUG1, (" Reading voltage\n"));
uint32_t regval = I2C_Read(deviceId, INA226_BUS_VOLTAGE_REG);
@ -129,11 +110,6 @@ int INA226_ReadVoltage(uint32_t deviceId) {
return voltagemV;
}
/**
* Read current
* @param deviceId device Id
* @returns current in mA
*/
int INA226_ReadCurrent(uint32_t deviceId) {
FILE_LOG(logDEBUG1, (" Reading current\n"));

View File

@ -1,7 +1,9 @@
#pragma once
#include "LTC2620.h"
#include "commonServerFunctions.h" // blackfin.h, ansi.h
#include "common.h"
#include "blackfin.h"
#include "clogger.h"
#include "sls_detector_defs.h"
#include <string.h>
@ -29,6 +31,11 @@
#define LTC2620_MAX_VAL (4095) // 12 bits
#define LTC2620_MAX_STEPS (LTC2620_MAX_VAL + 1)
#ifdef CHIPTESTBOARDD
#include "slsDetectorServer_defs.h"
#endif
// defines from the fpga
uint32_t LTC2620_Reg = 0x0;
uint32_t LTC2620_CsMask = 0x0;
uint32_t LTC2620_ClkMask = 0x0;
@ -38,17 +45,6 @@ int LTC2620_Ndac = 0;
int LTC2620_MinVoltage = 0;
int LTC2620_MaxVoltage = 0;
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
* @param nd total number of dacs for this board (for dac channel and daisy chain chip id)
* @param minMV minimum voltage determined by hardware
* @param maxMV maximum voltage determined by hardware
*/
void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int nd, int minMV, int maxMV) {
LTC2620_Reg = reg;
LTC2620_CsMask = cmsk;
@ -60,10 +56,6 @@ void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t d
LTC2620_MaxVoltage = maxMV;
}
/**
* Disable SPI
*/
void LTC2620_Disable() {
bus_w(LTC2620_Reg, (bus_r(LTC2620_Reg)
| LTC2620_CsMask
@ -71,40 +63,34 @@ void LTC2620_Disable() {
& ~(LTC2620_DigMask));
}
int LTC2620_GetPowerDownValue() {
return LTC2620_PWR_DOWN_VAL;
}
int LTC2620_GetMinInput() {
return LTC2620_MIN_VAL;
}
int LTC2620_GetMaxInput() {
return LTC2620_MAX_VAL;
}
int LTC2620_GetMaxNumSteps() {
return LTC2620_MAX_STEPS;
}
/**
* Convert voltage to dac units
* @param voltage value in mv
* @param dacval pointer to value converted to dac units
* @returns FAIL when voltage outside limits, OK if conversion successful
*/
int LTC2620_VoltageToDac(int voltage, int* dacval) {
return ConvertToDifferentRange(LTC2620_MinVoltage, LTC2620_MaxVoltage,
LTC2620_MIN_VAL, LTC2620_MAX_VAL,
voltage, dacval);
}
/**
* Convert dac units to voltage
* @param dacval dac units
* @param voltage pointer to value converted to mV
* @returns FAIL when voltage outside limits, OK if conversion successful
*/
int LTC2620_DacToVoltage(int dacval, int* voltage) {
return ConvertToDifferentRange( LTC2620_MIN_VAL, LTC2620_MAX_VAL,
LTC2620_MinVoltage, LTC2620_MaxVoltage,
dacval, voltage);
}
/**
* Set a single chip (all non ctb detectors use this)
* when max dac is 8
* @param cmd command
* @param data dac value to be set
* @param dacaddr dac channel number in chip
*/
void LTC2620_SetSingle(int cmd, int data, int dacaddr) {
FILE_LOG(logDEBUG2, ("(Single) dac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd));
@ -117,26 +103,11 @@ void LTC2620_SetSingle(int cmd, int data, int dacaddr) {
LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset, 0);
}
/**
* bit bang the data into all the chips daisy fashion
* @param valw current value of register while bit banging
* @param val data to be sent (data, dac addr and command)
*/
void LTC2620_SendDaisyData(uint32_t* valw, uint32_t val) {
sendDataToSPI(valw, LTC2620_Reg, val, LTC2620_DAISY_CHAIN_NUMBITS,
LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset);
}
/**
* Set a single chip (all non ctb detectors use this)
* when max dac is 8
* @param cmd command
* @param data dac value to be set
* @param dacaddr dac channel number in chip
* @param chipIndex index of the chip
*/
void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
int nchip = LTC2620_Ndac / LTC2620_NUMCHANNELS;
@ -189,15 +160,6 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0);
}
/**
* Sets a single chip (LTC2620_SetSingle) or multiple chip (LTC2620_SetDaisy)
* multiple chip is only for ctb where the multiple chips are connected in daisy fashion
* @param cmd command to send
* @param data dac value to be set
* @param dacaddr dac channel number for the chip
* @param chipIndex the chip to be set
*/
void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) {
FILE_LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex));
FILE_LOG(logDEBUG2, (" ================================================\n"));
@ -210,10 +172,6 @@ void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) {
FILE_LOG(logDEBUG2, (" ================================================\n"));
}
/**
* Configure (obtains dacaddr, command and ichip and calls LTC2620_Set)
*/
void LTC2620_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring LTC2620\n"));
@ -230,12 +188,6 @@ void LTC2620_Configure(){
LTC2620_Set(cmd, data, addr, -1);
}
/**
* Set Dac (obtains dacaddr, command and ichip and calls LTC2620_Set)
* @param dacnum dac number
* @param data dac value to set
*/
void LTC2620_SetDAC (int dacnum, int data) {
FILE_LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
// LTC2620 index
@ -258,14 +210,6 @@ void LTC2620_SetDAC (int dacnum, int data) {
LTC2620_Set(cmd, data, addr, ichip);
}
/**
* Set dac in dac units or mV
* @param dacnum dac index
* @param val value in dac units or mV
* @param mV 0 for dac units and 1 for mV unit
* @param dacval pointer to value in dac units
* @returns OK or FAIL for success of operation
*/
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
// validate index

View File

@ -1,6 +1,9 @@
#pragma once
#include "MAX1932.h"
#include "commonServerFunctions.h" // blackfin.h, ansi.h
#include "blackfin.h"
#include "clogger.h"
#include "common.h"
#include "sls_detector_defs.h"
/* MAX1932 HV DEFINES */
@ -12,6 +15,7 @@
#define MAX1932_MAX_DAC_VAL (0x1)
#define MAX1932_POWER_OFF_DAC_VAL (0x0)
// defines from the fpga
uint32_t MAX1932_Reg = 0x0;
uint32_t MAX1932_CsMask = 0x0;
uint32_t MAX1932_ClkMask = 0x0;
@ -20,17 +24,6 @@ int MAX1932_DigOffset = 0x0;
int MAX1932_MinVoltage = 0;
int MAX1932_MaxVoltage = 0;
/**
* Set Defines
* @param reg spi register
* @param cmsk chip select mask
* @param clkmsk clock output mask
* @param dmsk digital output mask
* @param dofst digital output offset
* @param minMV minimum voltage determined by hardware
* @param maxMV maximum voltage determined by hardware
*/
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst,
int minMV, int maxMV) {
FILE_LOG(logINFOBLUE, ("Configuring High Voltage\n"));
@ -43,10 +36,6 @@ void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t d
MAX1932_MaxVoltage = maxMV;
}
/**
* Disable SPI
*/
void MAX1932_Disable() {
bus_w(MAX1932_Reg, (bus_r(MAX1932_Reg)
| MAX1932_CsMask
@ -54,12 +43,6 @@ void MAX1932_Disable() {
& ~(MAX1932_DigMask));
}
/**
* Set value
* @param val value to set
* @return OK or FAIL
*/
int MAX1932_Set (int val) {
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
if (val < 0)

View File

@ -1,9 +1,7 @@
#pragma once
#include "UDPPacketHeaderGenerator.h"
#include "clogger.h"
#include "sls_detector_defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@ -38,11 +36,6 @@ uint64_t getUDPFrameNumber() {
return udpFrameNumber;
}
/**
* Called for each UDP packet header creation
*
*/
void createUDPPacketHeader(char* buffer, uint16_t id) {
memset(buffer, 0, sizeof(sls_detector_header));
sls_detector_header* header = (sls_detector_header*)(buffer);
@ -60,7 +53,6 @@ void createUDPPacketHeader(char* buffer, uint16_t id) {
udpFrameNumber = 0;
}
int fillUDPPacket(char* buffer) {
FILE_LOG(logDEBUG2, ("Analog (databytes:%d, offset:%d)\n Digital (databytes:%d offset:%d)\n",
analogDataBytes, analogOffset, digitalDataBytes, digitalOffset));

View File

@ -1,70 +1,42 @@
#pragma once
#include "blackfin.h"
#include "RegisterDefs.h"
#include "sls_detector_defs.h"
#include "ansi.h"
#include "clogger.h"
#include <fcntl.h> // open
#include <sys/mman.h> // mmap
/* global variables */
u_int64_t CSP0BASE = 0;
#define CSP0 0x20200000
#define MEM_SIZE 0x100000
/** I2C defines */
#define I2C_CLOCK_MHZ (131.25)
/**
* Write into a 16 bit register
* @param offset address offset
* @param data 16 bit data
*/
void bus_w16(u_int32_t offset, u_int16_t data) {
volatile u_int16_t *ptr1;
ptr1=(u_int16_t*)(CSP0BASE+offset*2);
*ptr1=data;
}
/**
* Read from a 16 bit register
* @param offset address offset
* @retuns 16 bit data read
*/
u_int16_t bus_r16(u_int32_t offset){
volatile u_int16_t *ptr1;
ptr1=(u_int16_t*)(CSP0BASE+offset*2);
return *ptr1;
}
/**
* Write into a 32 bit register
* @param offset address offset
* @param data 32 bit data
*/
void bus_w(u_int32_t offset, u_int32_t data) {
volatile u_int32_t *ptr1;
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
*ptr1=data;
}
/**
* Read from a 32 bit register
* @param offset address offset
* @retuns 32 bit data read
*/
u_int32_t bus_r(u_int32_t offset) {
volatile u_int32_t *ptr1;
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
return *ptr1;
}
/**
* Read from a 64 bit register
* @param aLSB LSB offset address
* @param aMSB MSB offset address
* @returns 64 bit data read
*/
int64_t get64BitReg(int aLSB, int aMSB){
int64_t v64;
u_int32_t vLSB,vMSB;
@ -76,13 +48,6 @@ int64_t get64BitReg(int aLSB, int aMSB){
return v64;
}
/**
* Write into a 64 bit register
* @param value 64 bit data
* @param aLSB LSB offset address
* @param aMSB MSB offset address
* @returns 64 bit data read
*/
int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
int64_t v64;
u_int32_t vLSB,vMSB;
@ -97,71 +62,35 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
}
/**
* Read unsigned 64 bit from a 64 bit register
* @param aLSB LSB offset address
* @param aMSB MSB offset address
* @returns unsigned 64 bit data read
*/
uint64_t getU64BitReg(int aLSB, int aMSB){
uint64_t retval = bus_r(aMSB);
retval = (retval << 32) | bus_r(aLSB);
return retval;
}
/**
* Write unsigned 64 bit into a 64 bit register
* @param value unsigned 64 bit data
* @param aLSB LSB offset address
* @param aMSB MSB offset address
*/
void setU64BitReg(uint64_t value, int aLSB, int aMSB){
bus_w(aLSB, value & (0xffffffff));
bus_w(aMSB, (value >> 32) & (0xffffffff));
}
/**
* Read from a 32 bit register (literal register value provided by client)
* @param offset address offset
* @retuns 32 bit data read
*/
u_int32_t readRegister(u_int32_t offset) {
return bus_r(offset << MEM_MAP_SHIFT);
}
/**
* Write into a 32 bit register (literal register value provided by client)
* @param offset address offset
* @param data 32 bit data
*/
u_int32_t writeRegister(u_int32_t offset, u_int32_t data) {
bus_w(offset << MEM_MAP_SHIFT, data);
return readRegister(offset);
}
/**
* Read from a 16 bit register (literal register value provided by client)
* @param offset address offset
* @retuns 16 bit data read
*/
u_int32_t readRegister16(u_int32_t offset) {
return (u_int32_t)bus_r16(offset << MEM_MAP_SHIFT);
}
/**
* Write into a 16 bit register (literal register value provided by client)
* @param offset address offset
* @param data 16 bit data
*/
u_int32_t writeRegister16(u_int32_t offset, u_int32_t data) {
bus_w16(offset << MEM_MAP_SHIFT, (u_int16_t)data);
return readRegister16(offset);
}
/**
* Map FPGA
*/
int mapCSP0(void) {
// if not mapped
if (CSP0BASE == 0) {
@ -195,3 +124,8 @@ int mapCSP0(void) {
FILE_LOG(logINFO, ("Memory already mapped before\n"));
return OK;
}
uint64_t Blackfin_getBaseAddress() {
return CSP0BASE;
}

View File

@ -1,15 +1,7 @@
#pragma once
#include "common.h"
#include "clogger.h"
#include "sls_detector_defs.h"
/**
* Convert a value from a range to a different range (eg voltage to dac or vice versa)
* @param inputMin input minimum
* @param inputMax input maximum
* @param outputMin output minimum
* @param outputMax output maximum
* @param inputValue input value
* @param outputValue pointer to output value
* @returns FAIL if input value is out of bounds, else OK
*/
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
int inputValue, int* outputValue) {
FILE_LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",

View File

@ -1,6 +1,7 @@
#pragma once
#include "commonServerFunctions.h"
#include "blackfin.h"
#include "clogger.h"
#include <unistd.h> // usleep
void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit) {

View File

@ -1,9 +1,7 @@
#pragma once
#include "communication_funcs_UDP.h"
#include "clogger.h"
#include "sls_detector_defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

View File

@ -1,6 +1,7 @@
#pragma once
#include "programfpga.h"
#include "ansi.h"
#include "clogger.h"
#include "slsDetectorServer_defs.h"
#include <unistd.h> // usleep
#include <string.h>
@ -12,10 +13,6 @@
int gpioDefined = 0;
char mtdvalue[MTDSIZE] = {0};
/**
* Define GPIO pins if not defined
*/
void defineGPIOpins(){
if (!gpioDefined) {
//define the gpio pins
@ -29,27 +26,17 @@ void defineGPIOpins(){
}else FILE_LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
}
/**
* Notify FPGA to not touch flash
*/
void FPGAdontTouchFlash(){
//tell FPGA to not touch flash
system("echo 0 > /sys/class/gpio/gpio9/value");
//usleep(100*1000);
}
/**
* Notify FPGA to program from flash
*/
void FPGATouchFlash(){
//tell FPGA to touch flash to program itself
system("echo 1 > /sys/class/gpio/gpio9/value");
}
/**
* Reset FPGA
*/
void resetFPGA(){
FILE_LOG(logINFOBLUE, ("Reseting FPGA\n"));
FPGAdontTouchFlash();
@ -57,9 +44,6 @@ void resetFPGA(){
usleep(CTRL_SRVR_INIT_TIME_US);
}
/**
* Erasing flash
*/
void eraseFlash(){
FILE_LOG(logDEBUG1, ("Erasing Flash\n"));
char command[255];
@ -69,12 +53,6 @@ void eraseFlash(){
FILE_LOG(logINFO, ("Flash erased\n"));
}
/**
* Open the drive to copy program and
* notify FPGA not to touch the program
* @param filefp pointer to flash
* @return 0 for success, 1 for fail (cannot open file for writing program)
*/
int startWritingFPGAprogram(FILE** filefp){
FILE_LOG(logDEBUG1, ("Start Writing of FPGA program\n"));
@ -114,11 +92,6 @@ int startWritingFPGAprogram(FILE** filefp){
return 0;
}
/**
* When done writing the program, close file pointer and
* notify FPGA to pick up the program from flash
* @param filefp pointer to flash
*/
void stopWritingFPGAprogram(FILE* filefp){
FILE_LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
@ -147,14 +120,6 @@ void stopWritingFPGAprogram(FILE* filefp){
FILE_LOG(logINFO, ("FPGA has picked up the program from flash\n"));
}
/**
* Write FPGA Program to flash
* @param fpgasrc source program
* @param fsize size of program
* @param filefp pointer to flash
* @return 0 for success, 1 for fail (cannot write)
*/
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp){
FILE_LOG(logDEBUG1, ("Writing of FPGA Program\n"
"\taddress of fpgasrc:%p\n"

View File

@ -4,9 +4,9 @@
#define APIRECEIVER 0x190722
#define APIGUI 0x190723
#define APIMOENCH 0x190820
#define APICTB 0x190821
#define APIGOTTHARD 0x190821
#define APIJUNGFRAU 0x190821
#define APIMYTHEN3 0x190822
#define APIEIGER 0x190823
#define APIEIGER 0x190826
#define APICTB 0x190826
#define APIJUNGFRAU 0x190826
#define APIMYTHEN3 0x190826
#define APIGOTTHARD 0x190826
#define APIGOTTHARD2 0x190826