mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
client: removed slsDetectorutils and postprocessing. yet to compile, yet to add detpos index for every multi sls detector command and call from command interface, removed multiple threading, yet to interface with eriks single template for multiple threading
This commit is contained in:
141
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/AD9257.h
Executable file
141
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/AD9257.h
Executable file
@ -0,0 +1,141 @@
|
||||
#ifndef AD9257_H
|
||||
#define AD9257_H
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include "commonServerFunctions.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* AD9257 ADC DEFINES */
|
||||
#define AD9257_ADC_NUMBITS (24)
|
||||
|
||||
#define AD9257_DEV_IND_2_REG (0x04)
|
||||
#define AD9257_CHAN_H_OFST (0)
|
||||
#define AD9257_CHAN_H_MSK (0x00000001 << AD9257_CHAN_H_OFST)
|
||||
#define AD9257_CHAN_G_OFST (1)
|
||||
#define AD9257_CHAN_G_MSK (0x00000001 << AD9257_CHAN_G_OFST)
|
||||
#define AD9257_CHAN_F_OFST (2)
|
||||
#define AD9257_CHAN_F_MSK (0x00000001 << AD9257_CHAN_F_OFST)
|
||||
#define AD9257_CHAN_E_OFST (3)
|
||||
#define AD9257_CHAN_E_MSK (0x00000001 << AD9257_CHAN_E_OFST)
|
||||
|
||||
#define AD9257_DEV_IND_1_REG (0x05)
|
||||
#define AD9257_CHAN_D_OFST (0)
|
||||
#define AD9257_CHAN_D_MSK (0x00000001 << AD9257_CHAN_D_OFST)
|
||||
#define AD9257_CHAN_C_OFST (1)
|
||||
#define AD9257_CHAN_C_MSK (0x00000001 << AD9257_CHAN_C_OFST)
|
||||
#define AD9257_CHAN_B_OFST (2)
|
||||
#define AD9257_CHAN_B_MSK (0x00000001 << AD9257_CHAN_B_OFST)
|
||||
#define AD9257_CHAN_A_OFST (3)
|
||||
#define AD9257_CHAN_A_MSK (0x00000001 << AD9257_CHAN_A_OFST)
|
||||
#define AD9257_CLK_CH_DCO_OFST (4)
|
||||
#define AD9257_CLK_CH_DCO_MSK (0x00000001 << AD9257_CLK_CH_DCO_OFST)
|
||||
#define AD9257_CLK_CH_IFCO_OFST (5)
|
||||
#define AD9257_CLK_CH_IFCO_MSK (0x00000001 << AD9257_CLK_CH_IFCO_OFST)
|
||||
|
||||
#define AD9257_POWER_MODE_REG (0x08)
|
||||
#define AD9257_POWER_INTERNAL_OFST (0)
|
||||
#define AD9257_POWER_INTERNAL_MSK (0x00000003 << AD9257_POWER_INTERNAL_OFST)
|
||||
#define AD9257_INT_RESET_VAL (0x3)
|
||||
#define AD9257_INT_CHIP_RUN_VAL (0x0)
|
||||
#define AD9257_POWER_EXTERNAL_OFST (5)
|
||||
#define AD9257_POWER_EXTERNAL_MSK (0x00000001 << AD9257_POWER_EXTERNAL_OFST)
|
||||
#define AD9257_EXT_FULL_POWER_VAL (0x0)
|
||||
#define AD9257_EXT_STANDBY_VAL (0x1)
|
||||
|
||||
#define AD9257_OUT_MODE_REG (0x14)
|
||||
#define AD9257_OUT_FORMAT_OFST (0)
|
||||
#define AD9257_OUT_FORMAT_MSK (0x00000001 << AD9257_OUT_FORMAT_OFST)
|
||||
#define AD9257_OUT_BINARY_OFST_VAL (0)
|
||||
#define AD9257_OUT_TWOS_COMPL_VAL (1)
|
||||
#define AD9257_OUT_LVDS_OPT_OFST (6)
|
||||
#define AD9257_OUT_LVDS_OPT_MSK (0x00000001 << AD9257_OUT_LVDS_OPT_OFST)
|
||||
#define AD9257_OUT_LVDS_ANSI_VAL (0)
|
||||
#define AD9257_OUT_LVDS_IEEE_VAL (1)
|
||||
|
||||
#define AD9257_OUT_PHASE_REG (0x16)
|
||||
#define AD9257_OUT_CLK_OFST (0)
|
||||
#define AD9257_OUT_CLK_MSK (0x0000000F << AD9257_OUT_CLK_OFST)
|
||||
#define AD9257_OUT_CLK_60_VAL (0x1)
|
||||
#define AD9257_IN_CLK_OFST (4)
|
||||
#define AD9257_IN_CLK_MSK (0x00000007 << AD9257_IN_CLK_OFST)
|
||||
#define AD9257_IN_CLK_0_VAL (0x0)
|
||||
|
||||
#define AD9257_VREF_REG (0x18)
|
||||
#define AD9257_VREF_OFST (0)
|
||||
#define AD9257_VREF_MSK (0x00000003 << AD9257_VREF_OFST)
|
||||
#define AD9257_VREF_1_33_VAL (0x2)
|
||||
|
||||
#define AD9257_TEST_MODE_REG (0x0D)
|
||||
#define AD9257_OUT_TEST_OFST (0)
|
||||
#define AD9257_OUT_TEST_MSK (0x0000000F << AD9257_OUT_TEST_OFST)
|
||||
#define AD9257_NONE_VAL (0x0)
|
||||
#define AD9257_MIXED_BIT_FREQ_VAL (0xC)
|
||||
#define AD9257_TEST_RESET_SHORT_GEN (4)
|
||||
#define AD9257_TEST_RESET_LONG_GEN (5)
|
||||
#define AD9257_USER_IN_MODE_OFST (6)
|
||||
#define AD9257_USER_IN_MODE_MSK (0x00000003 << AD9257_USER_IN_MODE_OFST)
|
||||
|
||||
|
||||
void setAdc(int addr, int val) {
|
||||
|
||||
u_int32_t codata;
|
||||
codata = val + (addr << 8);
|
||||
printf(" Setting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr);
|
||||
serializeToSPI(ADC_SPI_REG, codata, ADC_SERIAL_CS_OUT_MSK, AD9257_ADC_NUMBITS,
|
||||
ADC_SERIAL_CLK_OUT_MSK, ADC_SERIAL_DATA_OUT_MSK, ADC_SERIAL_DATA_OUT_OFST);
|
||||
}
|
||||
|
||||
void prepareADC(){
|
||||
printf("\n\nPreparing ADC ... \n");
|
||||
|
||||
//power mode reset
|
||||
printf("power mode reset:\n");
|
||||
setAdc(AD9257_POWER_MODE_REG,
|
||||
(AD9257_INT_RESET_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK);
|
||||
|
||||
//power mode chip run
|
||||
printf("power mode chip run:\n");
|
||||
setAdc(AD9257_POWER_MODE_REG,
|
||||
(AD9257_INT_CHIP_RUN_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK);
|
||||
|
||||
//output clock phase
|
||||
printf("output clock phase:\n");
|
||||
setAdc(AD9257_OUT_PHASE_REG,
|
||||
(AD9257_OUT_CLK_60_VAL << AD9257_OUT_CLK_OFST) & AD9257_OUT_CLK_MSK);
|
||||
|
||||
// lvds-iee reduced , binary offset
|
||||
printf("lvds-iee reduced, binary offset:\n");
|
||||
setAdc(AD9257_OUT_MODE_REG,
|
||||
(AD9257_OUT_LVDS_IEEE_VAL << AD9257_OUT_LVDS_OPT_OFST) & AD9257_OUT_LVDS_OPT_MSK);
|
||||
|
||||
// all devices on chip to receive next command
|
||||
printf("all devices on chip to receive next command:\n");
|
||||
setAdc(AD9257_DEV_IND_2_REG,
|
||||
AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK);
|
||||
setAdc(AD9257_DEV_IND_1_REG,
|
||||
AD9257_CHAN_D_MSK | AD9257_CHAN_C_MSK | AD9257_CHAN_B_MSK | AD9257_CHAN_A_MSK |
|
||||
AD9257_CLK_CH_DCO_MSK | AD9257_CLK_CH_IFCO_MSK);
|
||||
|
||||
// vref 1.33
|
||||
printf("vref 1.33:\n");
|
||||
setAdc(AD9257_VREF_REG,
|
||||
(AD9257_VREF_1_33_VAL << AD9257_VREF_OFST) & AD9257_VREF_MSK);
|
||||
|
||||
// no test mode
|
||||
printf("no test mode:\n");
|
||||
setAdc(AD9257_TEST_MODE_REG,
|
||||
(AD9257_NONE_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK);
|
||||
|
||||
#ifdef TESTADC
|
||||
printf("***************************************** *******\n");
|
||||
printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n");
|
||||
printf("***************************************** *******\n");
|
||||
// mixed bit frequency test mode
|
||||
printf("mixed bit frequency test mode:\n");
|
||||
setAdc(AD9257_TEST_MODE_REG,
|
||||
(AD9257_MIXED_BIT_FREQ_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif //AD9257_H
|
@ -0,0 +1,26 @@
|
||||
CC = gcc
|
||||
CLAGS += -Wall -DVIRTUAL -DDACS_INT -DGENERICD # -DSLS_DETECTOR_FUNCTION_LIST
|
||||
LDLIBS += -lm
|
||||
|
||||
PROGS = genericDetectorServer
|
||||
DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
SRC_CLNT = slsDetectorServer.c slsDetectorServer_funcs.c communication_funcs.c slsDetectorFunctionList.c
|
||||
OBJS = $(SRC_CLNT:.cpp=.o)
|
||||
|
||||
|
||||
|
||||
all: clean $(PROGS)
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
$(PROGS):
|
||||
echo $(OBJS)
|
||||
mkdir -p $(DESTDIR)
|
||||
$(CC) $(SRC_CLNT) $(CLAGS) $(LDLIBS) -o $@
|
||||
mv $(PROGS) $(DESTDIR)
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf $(DESTDIR)/$(PROGS) *.o
|
162
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/blackfin.h
Executable file
162
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/blackfin.h
Executable file
@ -0,0 +1,162 @@
|
||||
#ifndef BLACKFIN_H
|
||||
#define BLACKFIN_H
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h> // open
|
||||
#include <sys/mman.h> // mmap
|
||||
|
||||
|
||||
/* global variables */
|
||||
u_int64_t CSP0BASE = 0;
|
||||
#define CSP0 0x20200000
|
||||
#define MEM_SIZE 0x100000
|
||||
#define MEM_MAP_SHIFT 1
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
vLSB=bus_r(aLSB);
|
||||
vMSB=bus_r(aMSB);
|
||||
v64=vMSB;
|
||||
v64=(v64<<32) | vLSB;
|
||||
printf(" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64);
|
||||
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;
|
||||
if (value!=-1) {
|
||||
vLSB=value&(0xffffffff);
|
||||
bus_w(aLSB,vLSB);
|
||||
v64=value>> 32;
|
||||
vMSB=v64&(0xffffffff);
|
||||
bus_w(aMSB,vMSB);
|
||||
}
|
||||
return get64BitReg(aLSB, 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Map FPGA
|
||||
*/
|
||||
int mapCSP0(void) {
|
||||
// if not mapped
|
||||
if (CSP0BASE == 0) {
|
||||
printf("Mapping memory\n");
|
||||
#ifdef VIRTUAL
|
||||
CSP0BASE = malloc(MEM_SIZE);
|
||||
if (CSP0BASE == NULL) {
|
||||
cprintf(BG_RED, "Error: Could not allocate virtual memory.\n");
|
||||
return FAIL;
|
||||
}
|
||||
printf("memory allocated\n");
|
||||
#else
|
||||
int fd;
|
||||
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
|
||||
if (fd == -1) {
|
||||
cprintf(BG_RED, "Error: Can't find /dev/mem\n");
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("/dev/mem opened\n");
|
||||
#endif
|
||||
CSP0BASE = mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0);
|
||||
if (CSP0BASE == MAP_FAILED) {
|
||||
cprintf(BG_RED, "Error: Can't map memmory area\n");
|
||||
return FAIL;
|
||||
}
|
||||
#endif
|
||||
printf("CSPOBASE mapped from 0x%llx to 0x%llx\n",
|
||||
(long long unsigned int)CSP0BASE,
|
||||
(long long unsigned int)(CSP0BASE+MEM_SIZE));
|
||||
printf("Status Register: %08x\n",bus_r(STATUS_REG));
|
||||
|
||||
}else
|
||||
printf("Memory already mapped before\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
#endif //BLACKFIN_H
|
@ -0,0 +1,73 @@
|
||||
#ifndef COMMON_SERVER_FUNCTIONS_H
|
||||
#define COMMON_SERVER_FUNCTIONS_H
|
||||
|
||||
#ifndef GOTTHARDD //gotthard already had bus_w etc defined in its firmware_funcs.c (not yet made with common files)
|
||||
#include "blackfin.h"
|
||||
#endif
|
||||
|
||||
/* global variables */
|
||||
|
||||
void SPIChipSelect (u_int32_t* valw, u_int32_t addr, u_int32_t csmask) {
|
||||
|
||||
// start point
|
||||
(*valw) = 0xffffffff; // old board compatibility (not using specific bits)
|
||||
bus_w (addr, (*valw));
|
||||
|
||||
// chip sel bar down
|
||||
(*valw) &= ~csmask; /* todo with test: done a bit different, not with previous value */
|
||||
bus_w (addr, (*valw));
|
||||
}
|
||||
|
||||
|
||||
void SPIChipDeselect (u_int32_t* valw, u_int32_t addr, u_int32_t csmask, u_int32_t clkmask) {
|
||||
// chip sel bar up
|
||||
(*valw) |= csmask; /* todo with test: not done for spi */
|
||||
bus_w (addr, (*valw));
|
||||
|
||||
//clk down
|
||||
(*valw) &= ~clkmask;
|
||||
bus_w (addr, (*valw));
|
||||
|
||||
// stop point = start point of course
|
||||
(*valw) = 0xffffffff; // old board compatibility (not using specific bits)
|
||||
bus_w (addr, (*valw));
|
||||
}
|
||||
|
||||
void sendDataToSPI (u_int32_t* valw, u_int32_t addr, u_int32_t val, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
|
||||
int i = 0;
|
||||
for (i = 0; i < numbitstosend; ++i) {
|
||||
|
||||
// clk down
|
||||
(*valw) &= ~clkmask;
|
||||
bus_w (addr, (*valw));
|
||||
|
||||
// write data (i)
|
||||
(*valw) = (((*valw) & ~digoutmask) + // unset bit
|
||||
(((val >> (numbitstosend - 1 - i)) & 0x1) << digofset)); // each bit from val starting from msb
|
||||
bus_w (addr, (*valw));
|
||||
|
||||
// clk up
|
||||
(*valw) |= clkmask ;
|
||||
bus_w (addr, (*valw));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
|
||||
#ifdef VERBOSE
|
||||
if (numbitstosend == 16)
|
||||
printf("Writing to SPI Register: 0x%04x\n",val);
|
||||
else
|
||||
printf("Writing to SPI Register: 0x%08x\n", val);
|
||||
#endif
|
||||
|
||||
u_int32_t valw;
|
||||
|
||||
SPIChipSelect (&valw, addr, csmask);
|
||||
|
||||
sendDataToSPI(&valw, addr, val, numbitstosend, clkmask, digoutmask, digofset);
|
||||
|
||||
SPIChipDeselect(&valw, addr, csmask, clkmask);
|
||||
}
|
||||
|
||||
#endif //COMMON_SERVER_FUNCTIONS_H
|
@ -0,0 +1 @@
|
||||
../commonFiles/communication_funcs.c
|
@ -0,0 +1 @@
|
||||
../commonFiles/communication_funcs.h
|
190
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/programfpga.h
Executable file
190
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/programfpga.h
Executable file
@ -0,0 +1,190 @@
|
||||
#ifndef PROGRAM_FPGA_H
|
||||
#define PROGRAM_FPGA_H
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> // usleep
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* global variables */
|
||||
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
||||
int gpioDefined=0;
|
||||
#define MTDSIZE 10
|
||||
char mtdvalue[MTDSIZE];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Define GPIO pins if not defined
|
||||
*/
|
||||
void defineGPIOpins(){
|
||||
if (!gpioDefined) {
|
||||
//define the gpio pins
|
||||
system("echo 7 > /sys/class/gpio/export");
|
||||
system("echo 9 > /sys/class/gpio/export");
|
||||
//define their direction
|
||||
system("echo in > /sys/class/gpio/gpio7/direction");
|
||||
system("echo out > /sys/class/gpio/gpio9/direction");
|
||||
printf("gpio pins defined\n");
|
||||
gpioDefined = 1;
|
||||
}else printf("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(){
|
||||
cprintf(BLUE,"\n*** Reseting FPGA ***\n");
|
||||
FPGAdontTouchFlash();
|
||||
FPGATouchFlash();
|
||||
usleep(CTRL_SRVR_INIT_TIME_US);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erasing flash
|
||||
*/
|
||||
void eraseFlash(){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nErasing Flash\n");
|
||||
#endif
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"flash_eraseall %s",mtdvalue);
|
||||
system(command);
|
||||
printf("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){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nStart Writing of FPGA program\n");
|
||||
#endif
|
||||
|
||||
//getting the drive
|
||||
char output[255];
|
||||
memset(output, 0, 255);
|
||||
FILE* fp = popen("awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
|
||||
if (fp == NULL) {
|
||||
cprintf(RED,"popen returned NULL. Need that to get mtd drive.\n");
|
||||
return 1;
|
||||
}
|
||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||
cprintf(RED,"fgets returned NULL. Need that to get mtd drive.\n");
|
||||
return 1;
|
||||
}
|
||||
pclose(fp);
|
||||
//cprintf(RED,"output: %s\n", output);
|
||||
memset(mtdvalue, 0, MTDSIZE);
|
||||
strcpy(mtdvalue,"/dev/");
|
||||
char* pch = strtok(output,":");
|
||||
if(pch == NULL){
|
||||
cprintf(RED,"Could not get mtd value\n");
|
||||
return 1;
|
||||
}
|
||||
strcat(mtdvalue,pch);
|
||||
printf ("\nFlash drive found: %s\n",mtdvalue);
|
||||
|
||||
FPGAdontTouchFlash();
|
||||
|
||||
//writing the program to flash
|
||||
*filefp = fopen(mtdvalue, "w");
|
||||
if(*filefp == NULL){
|
||||
cprintf(RED,"Unable to open %s in write mode\n",mtdvalue);
|
||||
return 1;
|
||||
}
|
||||
printf("Flash ready for writing\n");
|
||||
|
||||
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){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nStopping of writing FPGA program\n");
|
||||
#endif
|
||||
|
||||
int wait = 0;
|
||||
if(filefp!= NULL){
|
||||
fclose(filefp);
|
||||
wait = 1;
|
||||
}
|
||||
|
||||
//touch and program
|
||||
FPGATouchFlash();
|
||||
|
||||
if(wait){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for FPGA to program from flash\n");
|
||||
#endif
|
||||
//waiting for success or done
|
||||
char output[255];
|
||||
int res=0;
|
||||
while(res == 0){
|
||||
FILE* sysFile = popen("cat /sys/class/gpio/gpio7/value", "r");
|
||||
fgets(output, sizeof(output), sysFile);
|
||||
pclose(sysFile);
|
||||
sscanf(output,"%d",&res);
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("gpi07 returned %d\n",res);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
printf("FPGA has picked up the program from flash\n\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){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nWriting of FPGA Program\n");
|
||||
cprintf(BLUE,"address of fpgasrc:%p\n",(void *)fpgasrc);
|
||||
cprintf(BLUE,"fsize:%lu\n",fsize);
|
||||
cprintf(BLUE,"pointer:%p\n",(void*)filefp);
|
||||
#endif
|
||||
|
||||
if(fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp )!= fsize){
|
||||
cprintf(RED,"Could not write FPGA source to flash (size:%lu)\n", fsize);
|
||||
return 1;
|
||||
}
|
||||
#ifdef VERY_VERBOSE
|
||||
cprintf(BLUE, "program written to flash\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif //PROGRAM_FPGA_H
|
@ -0,0 +1,838 @@
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
|
||||
#include "slsDetectorFunctionList.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
const int nChans=NCHAN;
|
||||
const int nChips=NCHIP;
|
||||
const int nDacs=NDAC;
|
||||
const int nAdcs=NADC;
|
||||
const int allSelected=-2;
|
||||
const int noneSelected=-1;
|
||||
|
||||
sls_detector_module *detectorModules=NULL;
|
||||
int *detectorChips=NULL;
|
||||
int *detectorChans=NULL;
|
||||
dacs_t *detectorDacs=NULL;
|
||||
dacs_t *detectorAdcs=NULL;
|
||||
|
||||
int nModY = NMAXMOD;
|
||||
int nModX = NMAXMOD;
|
||||
int dynamicRange= DYNAMIC_RANGE;
|
||||
int dataBytes = NMAXMOD*NCHIP*NCHAN*2;
|
||||
int masterMode = NO_MASTER;
|
||||
int syncMode = NO_SYNCHRONIZATION;
|
||||
int timingMode = AUTO_TIMING;
|
||||
|
||||
|
||||
|
||||
enum detectorSettings thisSettings;
|
||||
int sChan, sChip, sMod, sDac, sAdc;
|
||||
int nModBoard;
|
||||
extern int dataBytes;
|
||||
|
||||
|
||||
int initializeDetectorStructure(){
|
||||
|
||||
int imod;
|
||||
int n=getNModBoard(X)*getNModBoard(Y);
|
||||
#ifdef VERBOSE
|
||||
printf("Board is for %d modules\n",n);
|
||||
#endif
|
||||
detectorModules=malloc(n*sizeof(sls_detector_module));
|
||||
detectorChips=malloc(n*NCHIP*sizeof(int));
|
||||
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
||||
detectorDacs=malloc(n*NDAC*sizeof(int));
|
||||
detectorAdcs=malloc(n*NADC*sizeof(int));
|
||||
#ifdef VERBOSE
|
||||
printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n));
|
||||
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP));
|
||||
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN));
|
||||
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*NDAC));
|
||||
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*NADC));
|
||||
#endif
|
||||
for (imod=0; imod<n; imod++) {
|
||||
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
|
||||
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
|
||||
(detectorModules+imod)->chipregs=detectorChips+imod*NCHIP;
|
||||
(detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN;
|
||||
(detectorModules+imod)->ndac=NDAC;
|
||||
(detectorModules+imod)->nadc=NADC;
|
||||
(detectorModules+imod)->nchip=NCHIP;
|
||||
(detectorModules+imod)->nchan=NCHIP*NCHAN;
|
||||
(detectorModules+imod)->module=imod;
|
||||
(detectorModules+imod)->gain=0;
|
||||
(detectorModules+imod)->offset=0;
|
||||
(detectorModules+imod)->reg=0;
|
||||
/* initialize registers, dacs, retrieve sn, adc values etc */
|
||||
}
|
||||
thisSettings=UNINITIALIZED;
|
||||
sChan=noneSelected;
|
||||
sChip=noneSelected;
|
||||
sMod=noneSelected;
|
||||
sDac=noneSelected;
|
||||
sAdc=noneSelected;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int setupDetector(){
|
||||
//testFpga();
|
||||
//testRAM();
|
||||
|
||||
//setSettings(GET_SETTINGS,-1);
|
||||
//setFrames(1);
|
||||
//setTrains(1);
|
||||
//setExposureTime(1e6);
|
||||
//setPeriod(1e9);
|
||||
//setDelay(0);
|
||||
//setGates(0);
|
||||
|
||||
//setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
|
||||
//setMaster(GET_MASTER);
|
||||
//setSynchronization(GET_SYNCHRONIZATION_MODE);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int setNMod(int nm, enum dimension dim){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getNModBoard(enum dimension arg){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int64_t getModuleId(enum idMode arg, int imod){
|
||||
//DETECTOR_SERIAL_NUMBER
|
||||
//DETECTOR_FIRMWARE_VERSION
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int64_t getDetectorId(enum idMode arg){
|
||||
//DETECTOR_SOFTWARE_VERSION defined in slsDetector_defs.h?
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int moduleTest( enum digitalTestMode arg, int imod){
|
||||
//template testShiftIn from mcb_funcs.c
|
||||
|
||||
//CHIP_TEST
|
||||
//testShiftIn
|
||||
//testShiftOut
|
||||
//testShiftStSel
|
||||
//testDataInOutMux
|
||||
//testExtPulseMux
|
||||
//testOutMux
|
||||
//testFpgaMux
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int detectorTest( enum digitalTestMode arg){
|
||||
//templates from firmware_funcs.c
|
||||
|
||||
//DETECTOR_FIRMWARE_TEST:testFpga()
|
||||
//DETECTOR_MEMORY_TEST:testRAM()
|
||||
//DETECTOR_BUS_TEST:testBus()
|
||||
//DETECTOR_SOFTWARE_TEST:testFpga()
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double setDAC(enum dacIndex ind, double val, int imod){
|
||||
//template initDACbyIndexDACU from mcb_funcs.c
|
||||
|
||||
//check that slsDetectorServer_funcs.c set_dac() has all the specific dac enums
|
||||
//set dac and write to a register in fpga to remember dac value when server restarts
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double getADC(enum dacIndex ind, int imod){
|
||||
//get adc value
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int setChannel(sls_detector_channel myChan){
|
||||
//template initChannelByNumber() from mcb_funcs.c
|
||||
|
||||
return myChan.reg;
|
||||
}
|
||||
|
||||
|
||||
int getChannel(sls_detector_channel *myChan){
|
||||
//template getChannelbyNumber() from mcb_funcs.c
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int setChip(sls_detector_chip myChip){
|
||||
//template initChipbyNumber() from mcb_funcs.c
|
||||
return myChip.reg;
|
||||
}
|
||||
|
||||
|
||||
int getChip(sls_detector_chip *myChip){
|
||||
//template getChipbyNumber() from mcb_funcs.c
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
int setModule(sls_detector_module myChan){
|
||||
//template initModulebyNumber() from mcb_funcs.c
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getModule(sls_detector_module *myChan){
|
||||
//template getModulebyNumber() from mcb_funcs.c
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
int getThresholdEnergy(int imod){
|
||||
//template getThresholdEnergy() from mcb_funcs.c
|
||||
//depending on settings
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int setThresholdEnergy(int thr, int imod){
|
||||
//template getThresholdEnergy() from mcb_funcs.c
|
||||
//depending on settings
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum detectorSettings setSettings(enum detectorSettings sett, int imod){
|
||||
//template setSettings() from mcb_funcs.c
|
||||
//reads the dac registers from fpga to confirm which settings, if weird, undefined
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int startStateMachine(){
|
||||
//template startStateMachine() from firmware_funcs.c
|
||||
/*
|
||||
fifoReset();
|
||||
now_ptr=(char*)ram_values;
|
||||
//send start acquisition to fpga
|
||||
*/
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int stopStateMachine(){
|
||||
//template stopStateMachine() from firmware_funcs.c
|
||||
// send stop to fpga
|
||||
//if status = busy after 500us, return FAIL
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int startReadOut(){
|
||||
//template startReadOut() from firmware_funcs.c
|
||||
//send fpga start readout
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
//template runState() from firmware_funcs.c
|
||||
//get status from fpga
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
char *readFrame(int *ret, char *mess){
|
||||
//template fifo_read_event() from firmware_funcs.c
|
||||
//checks if state machine running and if fifo has data(look_at_me_reg) and accordingly reads frame
|
||||
// memcpy(now_ptr, values, dataBytes);
|
||||
//returns ptr to values
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int64_t setTimer(enum timerIndex ind, int64_t val){
|
||||
//template setDelay() from firmware_funcs.c
|
||||
//writes to reg
|
||||
//FRAME_NUMBER
|
||||
//ACQUISITION_TIME
|
||||
//FRAME_PERIOD
|
||||
//DELAY_AFTER_TRIGGER
|
||||
//GATES_NUMBER
|
||||
//PROBES_NUMBER
|
||||
//CYCLES_NUMBER
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t getTimeLeft(enum timerIndex ind){
|
||||
//template getDelay() from firmware_funcs.c
|
||||
//reads from reg
|
||||
//FRAME_NUMBER
|
||||
//ACQUISITION_TIME
|
||||
//FRAME_PERIOD
|
||||
//DELAY_AFTER_TRIGGER
|
||||
//GATES_NUMBER
|
||||
//PROBES_NUMBER
|
||||
//CYCLES_NUMBER
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int setDynamicRange(int dr){
|
||||
//template setDynamicRange() from firmware_funcs.c
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
enum readOutFlags setReadOutFlags(enum readOutFlags val){
|
||||
//template setStoreInRAM from firmware_funcs.c
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int setROI(int n, ROI arg[], int *retvalsize, int *ret){
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int setSpeed(enum speedVariable arg, int val){
|
||||
//template setClockDivider() from firmware_funcs.c
|
||||
//CLOCK_DIVIDER
|
||||
//WAIT_STATES
|
||||
//SET_SIGNAL_LENGTH
|
||||
//TOT_CLOCK_DIVIDER
|
||||
//TOT_DUTY_CYCLE
|
||||
|
||||
//returns eg getClockDivider from firmware_funcs.c
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int executeTrimming(enum trimMode mode, int par1, int par2, int imod){
|
||||
// template trim_with_noise from trimming_funcs.c
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb){
|
||||
//detector specific.
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int loadImage(enum imageType index, char *imageVals){
|
||||
//detector specific.
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int readCounterBlock(int startACQ, char *counterVals){
|
||||
//detector specific.
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
int resetCounterBlock(int startACQ){
|
||||
//detector specific.
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
int startReceiver(int d){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int calibratePedestal(int frames){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int calculateDataBytes(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getTotalNumberOfChannels(){return 0;}
|
||||
int getTotalNumberOfChips(){return 0;}
|
||||
int getTotalNumberOfModules(){return 0;}
|
||||
int getNumberOfChannelsPerChip(){return 0;}
|
||||
int getNumberOfChannelsPerModule(){return 0;}
|
||||
int getNumberOfChipsPerModule(){return 0;}
|
||||
int getNumberOfDACsPerModule(){return 0;}
|
||||
int getNumberOfADCsPerModule(){return 0;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum externalSignalFlag getExtSignal(int signalindex){
|
||||
//template getExtSignal from firmware_funcs.c
|
||||
//return signals[signalindex];
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag){
|
||||
//template setExtSignal from firmware_funcs.c
|
||||
|
||||
//in short..sets signals array, checks if agrees with timing mode, writes to fpga reg, calls synchronization and then settiming
|
||||
/*
|
||||
if (signalindex>=0 && signalindex<4) {
|
||||
signals[signalindex]=flag;
|
||||
#ifdef VERBOSE
|
||||
printf("settings signal variable number %d to value %04x\n", signalindex, signals[signalindex]);
|
||||
#endif
|
||||
// if output signal, set it!
|
||||
switch (flag) {
|
||||
case GATE_IN_ACTIVE_HIGH:
|
||||
case GATE_IN_ACTIVE_LOW:
|
||||
if (timingMode==GATE_FIX_NUMBER || timingMode==GATE_WITH_START_TRIGGER)//timingMode = AUTO_TIMING by default and is set in setTiming()
|
||||
setFPGASignal(signalindex,flag); //not implemented here, checks if flag within limits and writes to fpga reg
|
||||
else
|
||||
setFPGASignal(signalindex,SIGNAL_OFF);
|
||||
break;
|
||||
case TRIGGER_IN_RISING_EDGE:
|
||||
case TRIGGER_IN_FALLING_EDGE:
|
||||
if (timingMode==TRIGGER_EXPOSURE || timingMode==GATE_WITH_START_TRIGGER)
|
||||
setFPGASignal(signalindex,flag);
|
||||
else
|
||||
setFPGASignal(signalindex,SIGNAL_OFF);
|
||||
break;
|
||||
case RO_TRIGGER_IN_RISING_EDGE:
|
||||
case RO_TRIGGER_IN_FALLING_EDGE:
|
||||
if (timingMode==BURST_TRIGGER)
|
||||
setFPGASignal(signalindex,flag);
|
||||
else
|
||||
setFPGASignal(signalindex,SIGNAL_OFF);
|
||||
break;
|
||||
case MASTER_SLAVE_SYNCHRONIZATION:
|
||||
setSynchronization(syncMode);//syncmode = NO_SYNCHRONIZATION by default and set with this function
|
||||
break;
|
||||
default:
|
||||
setFPGASignal(signalindex,mode);
|
||||
}
|
||||
|
||||
setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
|
||||
}
|
||||
*/
|
||||
return getExtSignal(signalindex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
|
||||
//template setTiming from firmware_funcs.c
|
||||
//template getFPGASignal from firmware_funcs.c
|
||||
|
||||
|
||||
//getFPGASignal(signalindex) used later on in this fucntion
|
||||
//gets flag from fpga reg, checks if flag within limits,
|
||||
//if( flag=SIGNAL_OFF and signals[signalindex]==MASTER_SLAVE_SYNCHRONIZATION), return -1, (ensures masterslaveflag !=off now)
|
||||
//else return flag
|
||||
|
||||
int ret=GET_EXTERNAL_COMMUNICATION_MODE;
|
||||
//sets timingmode variable
|
||||
//ensures that the signals are in acceptance with timing mode and according sets the timing mode
|
||||
/*
|
||||
int g=-1, t=-1, rot=-1;
|
||||
|
||||
int i;
|
||||
|
||||
switch (ti) {
|
||||
case AUTO_TIMING:
|
||||
timingMode=ti;
|
||||
// disable all gates/triggers in except if used for master/slave synchronization
|
||||
for (i=0; i<4; i++) {
|
||||
if (getFPGASignal(i)>0 && getFPGASignal(i)<GATE_OUT_ACTIVE_HIGH && signals[i]!=MASTER_SLAVE_SYNCHRONIZATION)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
}
|
||||
break;
|
||||
|
||||
case TRIGGER_EXPOSURE:
|
||||
timingMode=ti;
|
||||
// if one of the signals is configured to be trigger, set it and unset possible gates
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,signals[i]);
|
||||
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
else if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case TRIGGER_READOUT:
|
||||
timingMode=ti;
|
||||
// if one of the signals is configured to be trigger, set it and unset possible gates
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,signals[i]);
|
||||
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
}
|
||||
break;
|
||||
|
||||
case GATE_FIX_NUMBER:
|
||||
timingMode=ti;
|
||||
// if one of the signals is configured to be trigger, set it and unset possible gates
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||
setFPGASignal(i,signals[i]);
|
||||
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case GATE_WITH_START_TRIGGER:
|
||||
timingMode=ti;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||
setFPGASignal(i,signals[i]);
|
||||
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||
setFPGASignal(i,signals[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]!=MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (getFPGASignal(i)==RO_TRIGGER_IN_RISING_EDGE || getFPGASignal(i)==RO_TRIGGER_IN_FALLING_EDGE)
|
||||
rot=i;
|
||||
else if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH || getFPGASignal(i)==GATE_IN_ACTIVE_LOW)
|
||||
g=i;
|
||||
else if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE || getFPGASignal(i)==TRIGGER_IN_FALLING_EDGE)
|
||||
t=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (g>=0 && t>=0 && rot<0) {
|
||||
ret=GATE_WITH_START_TRIGGER;
|
||||
} else if (g<0 && t>=0 && rot<0) {
|
||||
ret=TRIGGER_EXPOSURE;
|
||||
} else if (g>=0 && t<0 && rot<0) {
|
||||
ret=GATE_FIX_NUMBER;
|
||||
} else if (g<0 && t<0 && rot>0) {
|
||||
ret=TRIGGER_READOUT;
|
||||
} else if (g<0 && t<0 && rot<0) {
|
||||
ret=AUTO_TIMING;
|
||||
}
|
||||
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum masterFlags setMaster(enum masterFlags arg){
|
||||
//template setMaster from firmware_funcs.c
|
||||
/*
|
||||
int i;
|
||||
switch(f) {
|
||||
case NO_MASTER:
|
||||
// switch of gates or triggers
|
||||
masterMode=NO_MASTER;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IS_MASTER:
|
||||
// configure gate or trigger out
|
||||
masterMode=IS_MASTER;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
switch (syncMode) {
|
||||
case NO_SYNCHRONIZATION:
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
break;
|
||||
case MASTER_GATES:
|
||||
setFPGASignal(i,GATE_OUT_ACTIVE_HIGH);
|
||||
break;
|
||||
case MASTER_TRIGGERS:
|
||||
setFPGASignal(i,TRIGGER_OUT_RISING_EDGE);
|
||||
break;
|
||||
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||
setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IS_SLAVE:
|
||||
// configure gate or trigger in
|
||||
masterMode=IS_SLAVE;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
switch (syncMode) {
|
||||
case NO_SYNCHRONIZATION:
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
break;
|
||||
case MASTER_GATES:
|
||||
setFPGASignal(i,GATE_IN_ACTIVE_HIGH);
|
||||
break;
|
||||
case MASTER_TRIGGERS:
|
||||
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||
break;
|
||||
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
;
|
||||
}
|
||||
|
||||
switch(masterMode) {
|
||||
case NO_MASTER:
|
||||
return NO_MASTER;
|
||||
|
||||
|
||||
case IS_MASTER:
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
switch (syncMode) {
|
||||
case NO_SYNCHRONIZATION:
|
||||
return IS_MASTER;
|
||||
case MASTER_GATES:
|
||||
if (getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH)
|
||||
return IS_MASTER;
|
||||
else
|
||||
return NO_MASTER;
|
||||
case MASTER_TRIGGERS:
|
||||
if (getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE)
|
||||
return IS_MASTER;
|
||||
else
|
||||
return NO_MASTER;
|
||||
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||
if (getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE)
|
||||
return IS_MASTER;
|
||||
else
|
||||
return NO_MASTER;
|
||||
default:
|
||||
return NO_MASTER;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
case IS_SLAVE:
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
switch (syncMode) {
|
||||
case NO_SYNCHRONIZATION:
|
||||
return IS_SLAVE;
|
||||
case MASTER_GATES:
|
||||
if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH)
|
||||
return IS_SLAVE;
|
||||
else
|
||||
return NO_MASTER;
|
||||
case MASTER_TRIGGERS:
|
||||
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||
if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
|
||||
return IS_SLAVE;
|
||||
else
|
||||
return NO_MASTER;
|
||||
default:
|
||||
return NO_MASTER;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
return NO_MASTER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum synchronizationMode setSynchronization(enum synchronizationMode arg){
|
||||
/*
|
||||
int i;
|
||||
|
||||
switch(s) {
|
||||
case NO_SYNCHRONIZATION:
|
||||
syncMode=NO_SYNCHRONIZATION;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
setFPGASignal(i,SIGNAL_OFF);
|
||||
}
|
||||
}
|
||||
break;
|
||||
// disable external signals?
|
||||
case MASTER_GATES:
|
||||
// configure gate in or out
|
||||
syncMode=MASTER_GATES;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (masterMode==IS_MASTER)
|
||||
setFPGASignal(i,GATE_OUT_ACTIVE_HIGH);
|
||||
else if (masterMode==IS_SLAVE)
|
||||
setFPGASignal(i,GATE_IN_ACTIVE_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case MASTER_TRIGGERS:
|
||||
// configure trigger in or out
|
||||
syncMode=MASTER_TRIGGERS;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (masterMode==IS_MASTER)
|
||||
setFPGASignal(i,TRIGGER_OUT_RISING_EDGE);
|
||||
else if (masterMode==IS_SLAVE)
|
||||
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||
// configure trigger in or out
|
||||
syncMode=SLAVE_STARTS_WHEN_MASTER_STOPS;
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (masterMode==IS_MASTER)
|
||||
setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE);
|
||||
else if (masterMode==IS_SLAVE)
|
||||
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
//do nothing
|
||||
;
|
||||
}
|
||||
|
||||
switch (syncMode) {
|
||||
|
||||
case NO_SYNCHRONIZATION:
|
||||
return NO_SYNCHRONIZATION;
|
||||
|
||||
case MASTER_GATES:
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (masterMode==IS_MASTER && getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH)
|
||||
return MASTER_GATES;
|
||||
else if (masterMode==IS_SLAVE && getFPGASignal(i)==GATE_IN_ACTIVE_HIGH)
|
||||
return MASTER_GATES;
|
||||
}
|
||||
}
|
||||
return NO_SYNCHRONIZATION;
|
||||
|
||||
case MASTER_TRIGGERS:
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (masterMode==IS_MASTER && getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE)
|
||||
return MASTER_TRIGGERS;
|
||||
else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
|
||||
return MASTER_TRIGGERS;
|
||||
}
|
||||
}
|
||||
return NO_SYNCHRONIZATION;
|
||||
|
||||
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||
for (i=0; i<4; i++) {
|
||||
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||
if (masterMode==IS_MASTER && getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE)
|
||||
return SLAVE_STARTS_WHEN_MASTER_STOPS;
|
||||
else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
|
||||
return SLAVE_STARTS_WHEN_MASTER_STOPS;
|
||||
}
|
||||
}
|
||||
return NO_SYNCHRONIZATION;
|
||||
|
||||
default:
|
||||
return NO_SYNCHRONIZATION;
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
return NO_SYNCHRONIZATION;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,292 @@
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
#ifndef SLS_DETECTOR_FUNCTION_LIST_H
|
||||
#define SLS_DETECTOR_FUNCTION_LIST_H
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
#include "slsDetectorServer_defs.h" // DAC_INDEX, ADC_INDEX, also include RegisterDefs.h
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> // FILE
|
||||
|
||||
|
||||
/****************************************************
|
||||
This functions are used by the slsDetectroServer_funcs interface.
|
||||
Here are the definitions, but the actual implementation should be done for each single detector.
|
||||
|
||||
****************************************************/
|
||||
|
||||
|
||||
// basic tests
|
||||
#if defined(EIGERD) || defined(JUNGFRAUD) || defined(GOTTHARD)
|
||||
int isFirmwareCheckDone();
|
||||
int getFirmwareCheckResult(char** mess);
|
||||
#endif
|
||||
|
||||
void checkFirmwareCompatibility(int flag);
|
||||
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
|
||||
int checkType();
|
||||
u_int32_t testFpga(void);
|
||||
int testBus(void);
|
||||
#endif
|
||||
|
||||
#if defined(MYTHEND) || defined(JUNGFRAUD) || defined(MYTHEN3D)
|
||||
int moduleTest( enum digitalTestMode arg, int imod);
|
||||
#endif
|
||||
#if defined(MYTHEND) || defined(JUNGFRAUD)
|
||||
int detectorTest( enum digitalTestMode arg);
|
||||
#endif
|
||||
|
||||
// Ids
|
||||
int64_t getDetectorId(enum idMode arg);
|
||||
u_int64_t getFirmwareVersion();
|
||||
#ifdef MYTHEND
|
||||
int64_t getModuleId(enum idMode arg, int imod);
|
||||
#elif JUNGFRAUD
|
||||
u_int64_t getFirmwareAPIVersion();
|
||||
u_int16_t getHardwareVersionNumber();
|
||||
u_int16_t getHardwareSerialNumber();
|
||||
#endif
|
||||
#ifndef MYTHEN3D
|
||||
u_int32_t getDetectorNumber();
|
||||
#endif
|
||||
u_int64_t getDetectorMAC();
|
||||
u_int32_t getDetectorIP();
|
||||
|
||||
|
||||
// initialization
|
||||
void initControlServer();
|
||||
void initStopServer();
|
||||
#ifdef EIGERD
|
||||
void getModuleConfiguration();
|
||||
#endif
|
||||
|
||||
// set up detector
|
||||
void allocateDetectorStructureMemory();
|
||||
void setupDetector();
|
||||
#ifdef JUNGFRAUD
|
||||
int setDefaultDacs();
|
||||
#endif
|
||||
|
||||
|
||||
// advanced read/write reg
|
||||
#ifndef EIGERD
|
||||
extern u_int32_t writeRegister(u_int32_t offset, u_int32_t data); // blackfin.h
|
||||
extern u_int32_t readRegister(u_int32_t offset); // blackfin.h
|
||||
#else
|
||||
uint32_t writeRegister(uint32_t offset, uint32_t data);
|
||||
uint32_t readRegister(uint32_t offset);
|
||||
#endif
|
||||
|
||||
|
||||
// firmware functions (resets)
|
||||
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
|
||||
int powerChip (int on);
|
||||
void cleanFifos();
|
||||
void resetCore();
|
||||
void resetPeripheral();
|
||||
#endif
|
||||
#ifdef MYTHEN3D
|
||||
int getPhase(int i);
|
||||
int configurePhase(int val, enum CLKINDEX i);
|
||||
int configureFrequency(int val, int i);
|
||||
#elif JUNGFRAUD
|
||||
int autoCompDisable(int on);
|
||||
int adcPhase(int st);
|
||||
int getPhase();
|
||||
void configureASICTimer();
|
||||
#endif
|
||||
|
||||
// parameters - nmod, dr, roi
|
||||
int setNMod(int nm, enum dimension dim); // mythen specific, but for detector compatibility as a get
|
||||
int getNModBoard(enum dimension arg); // mythen specific, but for detector compatibility as a get
|
||||
int setDynamicRange(int dr);
|
||||
#ifdef GOTTHARD
|
||||
int setROI(int n, ROI arg[], int *retvalsize, int *ret);
|
||||
#endif
|
||||
|
||||
// parameters - readout
|
||||
int setSpeed(enum speedVariable arg, int val);
|
||||
#if defined(EIGERD) || defined(MYTHEND)
|
||||
enum readOutFlags setReadOutFlags(enum readOutFlags val);
|
||||
#endif
|
||||
#ifdef MYTHEND
|
||||
int executeTrimming(enum trimMode mode, int par1, int par2, int imod);
|
||||
#endif
|
||||
|
||||
// parameters - timer
|
||||
#ifdef JUNGFRAUD
|
||||
int selectStoragecellStart(int pos);
|
||||
#endif
|
||||
int64_t setTimer(enum timerIndex ind, int64_t val);
|
||||
int64_t getTimeLeft(enum timerIndex ind);
|
||||
|
||||
|
||||
// parameters - channel, chip, module, settings
|
||||
#ifdef MYTHEND
|
||||
int setChannel(sls_detector_channel myChan);
|
||||
int getChannel(sls_detector_channel *myChan);
|
||||
int setChip(sls_detector_chip myChip);
|
||||
int getChip(sls_detector_chip *myChip);
|
||||
#endif
|
||||
#ifdef EIGERD
|
||||
int setModule(sls_detector_module myMod, int delay);
|
||||
#else
|
||||
int setModule(sls_detector_module myMod);
|
||||
#endif
|
||||
int getModule(sls_detector_module *myMod);
|
||||
enum detectorSettings setSettings(enum detectorSettings sett, int imod);
|
||||
enum detectorSettings getSettings();
|
||||
|
||||
|
||||
// parameters - threshold
|
||||
#if defined(MYTHEND) || defined(EIGERD)
|
||||
int getThresholdEnergy(int imod);
|
||||
int setThresholdEnergy(int ev, int imod);
|
||||
#endif
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
|
||||
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset);
|
||||
void initDac(int dacnum);
|
||||
int voltageToDac(int value);
|
||||
int dacToVoltage(unsigned int digital);
|
||||
#endif
|
||||
#ifdef MYTHEN3D
|
||||
int setPower(enum DACINDEX ind, int val);
|
||||
int powerToDac(int value, int chip);
|
||||
int dacToPower(int value, int chip);
|
||||
#endif
|
||||
|
||||
#ifdef JUNGFRAUD
|
||||
extern void setAdc(int addr, int val); // AD9257.h
|
||||
#endif
|
||||
|
||||
void setDAC(enum DACINDEX ind, int val, int imod, int mV, int retval[]);
|
||||
#ifdef MYTHEN3D
|
||||
int getVLimit();
|
||||
void setDacRegister(int dacnum,int dacvalue);
|
||||
int getDacRegister(int dacnum);
|
||||
#endif
|
||||
#ifndef MYTHEN3D
|
||||
int getADC(enum ADCINDEX ind, int imod);
|
||||
#endif
|
||||
|
||||
#if !defined(MYTHEN3D) && !defined(MYTHEND)
|
||||
int setHighVoltage(int val);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// parameters - timing, extsig
|
||||
#ifdef MYTHEND
|
||||
enum externalSignalFlag getExtSignal(int signalindex);
|
||||
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag);
|
||||
#endif
|
||||
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg);
|
||||
|
||||
// configure mac
|
||||
#ifdef JUNGFRAUD
|
||||
long int calcChecksum(int sourceip, int destip);
|
||||
#endif
|
||||
#if !defined(MYTHEN3D) && !defined(MYTHEND)
|
||||
int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2, int ival);
|
||||
#endif
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
int setDetectorPosition(int pos[]);
|
||||
#endif
|
||||
|
||||
|
||||
// very detector specific
|
||||
|
||||
// gotthard specific - image, pedestal
|
||||
#ifdef GOTTHARDD
|
||||
int loadImage(enum imageType index, char *imageVals);
|
||||
int readCounterBlock(int startACQ, char *counterVals);
|
||||
int resetCounterBlock(int startACQ);
|
||||
int calibratePedestal(int frames);
|
||||
|
||||
// jungfrau specific - pll, flashing firmware
|
||||
#elif defined(JUNGFRAUD) || defined(MYTHEN3D)
|
||||
void resetPLL();
|
||||
u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val);
|
||||
void configurePll();
|
||||
int setThresholdTemperature(int val);
|
||||
int setTemperatureControl(int val);
|
||||
int setTemperatureEvent(int val);
|
||||
extern void eraseFlash(); // programfpga.h
|
||||
extern int startWritingFPGAprogram(FILE** filefp); // programfpga.h
|
||||
extern void stopWritingFPGAprogram(FILE* filefp); // programfpga.h
|
||||
extern int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp); // programfpga.h
|
||||
|
||||
// eiger specific - iodelay, 10g, pulse, rate, temp, activate, delay nw parameter
|
||||
#elif EIGERD
|
||||
int setIODelay(int val, int imod);
|
||||
int enableTenGigabitEthernet(int val);
|
||||
int setCounterBit(int val);
|
||||
int pulsePixel(int n, int x, int y);
|
||||
int pulsePixelNMove(int n, int x, int y);
|
||||
int pulseChip(int n);
|
||||
int64_t setRateCorrection(int64_t custom_tau_in_nsec);
|
||||
int getRateCorrectionEnable();
|
||||
int getDefaultSettingsTau_in_nsec();
|
||||
void setDefaultSettingsTau_in_nsec(int t);
|
||||
int64_t getCurrentTau();
|
||||
void setExternalGating(int enable[]);
|
||||
int setAllTrimbits(int val);
|
||||
int getAllTrimbits();
|
||||
int getBebFPGATemp();
|
||||
int activate(int enable);
|
||||
#endif
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
int setNetworkParameter(enum NETWORKINDEX mode, int value);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// aquisition
|
||||
#if defined(EIGERD) || defined(GOTTHARD)
|
||||
int prepareAcquisition();
|
||||
#endif
|
||||
int startStateMachine();
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg);
|
||||
#endif
|
||||
int stopStateMachine();
|
||||
#ifdef EIGERD
|
||||
int softwareTrigger();
|
||||
#endif
|
||||
#ifndef JUNGFRAUD
|
||||
int startReadOut();
|
||||
#endif
|
||||
enum runStatus getRunStatus();
|
||||
void readFrame(int *ret, char *mess);
|
||||
#ifdef JUNGFRAUD
|
||||
u_int32_t runBusy(void);
|
||||
#endif
|
||||
|
||||
|
||||
//common
|
||||
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
|
||||
int calculateDataBytes();
|
||||
int getTotalNumberOfChannels();
|
||||
int getTotalNumberOfChips();
|
||||
int getTotalNumberOfModules();
|
||||
int getNumberOfChannelsPerModule();
|
||||
int getNumberOfChipsPerModule();
|
||||
int getNumberOfDACsPerModule();
|
||||
int getNumberOfADCsPerModule();
|
||||
#ifdef EIGERD
|
||||
int getNumberOfGainsPerModule();
|
||||
int getNumberOfOffsetsPerModule();
|
||||
#endif
|
||||
int getNumberOfChannelsPerChip();
|
||||
|
||||
// sync
|
||||
enum masterFlags setMaster(enum masterFlags arg);
|
||||
enum synchronizationMode setSynchronization(enum synchronizationMode arg);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
138
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/slsDetectorServer.c
Executable file
138
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/slsDetectorServer.c
Executable file
@ -0,0 +1,138 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include "communication_funcs.h"
|
||||
#include "slsDetectorServer_funcs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int sockfd;
|
||||
|
||||
|
||||
void error(char *msg){
|
||||
perror(msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int portno = DEFAULT_PORTNO;
|
||||
int retval = OK;
|
||||
int sd, fd;
|
||||
int debugflag = 0;
|
||||
int controlserver = 1;
|
||||
|
||||
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||
// subsequent read/write to socket gives error - must handle locally
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// circumvent the basic tests
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if(!strcasecmp(argv[i],"-stopserver")) {
|
||||
cprintf(BLUE,"Detected stop server\n");
|
||||
controlserver = 0;
|
||||
}
|
||||
else if(!strcasecmp(argv[i],"-devel")){
|
||||
cprintf(BLUE,"Detected developer mode\n");
|
||||
debugflag = 1;
|
||||
}
|
||||
#ifdef JUNGFRAUD
|
||||
else if(!strcasecmp(argv[i],"-update")){
|
||||
cprintf(BLUE,"Detected update mode\n");
|
||||
debugflag = PROGRAMMING_MODE;
|
||||
}
|
||||
#endif
|
||||
else if(strchr(argv[i],'-') != NULL) {
|
||||
cprintf(RED,"cannot scan program argument %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STOP_SERVER
|
||||
char cmd[100];
|
||||
memset(cmd, 0, 100);
|
||||
#endif
|
||||
if (controlserver) {
|
||||
portno = DEFAULT_PORTNO;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
"********* opening control server on port %d **********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
#ifdef STOP_SERVER
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < argc; ++i)
|
||||
sprintf(cmd, "%s %s", cmd, argv[i]);
|
||||
sprintf(cmd,"%s -stopserver&", cmd);
|
||||
cprintf(BLUE,"cmd:%s\n", cmd);
|
||||
system(cmd);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
portno = DEFAULT_PORTNO+1;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
"*********** opening stop server on port %d ***********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
}
|
||||
|
||||
setModeFlag(debugflag); //defined in slsDetectorServer_funcs
|
||||
init_detector(controlserver); //defined in slsDetectorServer_funcs
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
sockfd=sd;
|
||||
if (getServerError(sd)) { //defined in communication_funcs
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* assign function table */
|
||||
function_table(); //defined in slsDetectorServer_funcs
|
||||
#ifdef VERBOSE
|
||||
printf("function table assigned \n");
|
||||
#endif
|
||||
|
||||
if (controlserver)
|
||||
printf("\nControl Server Ready...\n\n");
|
||||
else
|
||||
printf("\nStop Server Ready...\n\n");
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for client call\n");
|
||||
#endif
|
||||
fd=acceptConnection(sockfd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Conenction accepted\n");
|
||||
#endif
|
||||
if (fd>0) {
|
||||
retval=decode_function(fd); //defined in slsDetectorServer_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("function executed\n");
|
||||
#endif
|
||||
closeConnection(fd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("connection closed\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
exitServer(sockfd); //defined in communication_funcs
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* slsDetectorServer_defs.h
|
||||
*
|
||||
* Created on: Jan 24, 2013
|
||||
* Author: l_maliakal_d
|
||||
*/
|
||||
|
||||
#ifndef SLSDETECTORSERVER_DEFS_H_
|
||||
#define SLSDETECTORSERVER_DEFS_H_
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/** This is only an example file!!! */
|
||||
|
||||
/*
|
||||
#define GOODBYE (-200)
|
||||
enum DAC_INDEX {examplesdac}
|
||||
|
||||
Hardware Definitions
|
||||
#define NMAXMOD (1)
|
||||
#define NMOD (1)
|
||||
#define NCHAN (256 * 256)
|
||||
#define NCHIP (4)
|
||||
#define NADC (0)
|
||||
#define NDAC (16)
|
||||
#define NGAIN (0)
|
||||
#define NOFFSET (0)
|
||||
*/
|
||||
|
||||
#endif /* SLSDETECTORSERVER_DEFS_H_ */
|
5928
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c
Executable file
5928
slsDetectorSoftware/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c
Executable file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,101 @@
|
||||
#ifndef SERVER_FUNCS_H
|
||||
#define SERVER_FUNCS_H
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// initialization functions
|
||||
int printSocketReadError();
|
||||
void setModeFlag(int);
|
||||
void basictests();
|
||||
void init_detector(int);
|
||||
int decode_function(int);
|
||||
const char* getFunctionName(enum detFuncs func);
|
||||
void function_table();
|
||||
int M_nofunc(int);
|
||||
int M_nofuncMode(int);
|
||||
|
||||
// functions called by client
|
||||
int exec_command(int);
|
||||
int get_error(int);
|
||||
int get_detector_type(int);
|
||||
int set_number_of_modules(int);
|
||||
int get_max_number_of_modules(int);
|
||||
int set_external_signal_flag(int);
|
||||
int set_external_communication_mode(int);
|
||||
int get_id(int);
|
||||
int digital_test(int);
|
||||
int analog_test(int);
|
||||
int enable_analog_out(int);
|
||||
int calibration_pulse(int);
|
||||
int set_dac(int);
|
||||
int get_adc(int);
|
||||
int write_register(int);
|
||||
int read_register(int);
|
||||
int write_memory(int);
|
||||
int read_memory(int);
|
||||
int set_channel(int);
|
||||
int get_channel(int);
|
||||
int set_all_channels(int);
|
||||
int set_chip(int);
|
||||
int get_chip(int);
|
||||
int set_all_chips(int);
|
||||
int set_module(int);
|
||||
int get_module(int);
|
||||
int set_all_modules(int);
|
||||
int set_settings(int);
|
||||
int get_threshold_energy(int);
|
||||
int set_threshold_energy(int);
|
||||
int start_acquisition(int);
|
||||
int stop_acquisition(int);
|
||||
int start_readout(int);
|
||||
int get_run_status(int);
|
||||
int start_and_read_all(int);
|
||||
int read_frame(int);
|
||||
int read_all(int);
|
||||
int set_timer(int);
|
||||
int get_time_left(int);
|
||||
int set_dynamic_range(int);
|
||||
int set_readout_flags(int);
|
||||
int set_roi(int);
|
||||
int set_speed(int);
|
||||
int execute_trimming(int);
|
||||
int exit_server(int);
|
||||
int lock_server(int);
|
||||
int get_last_client_ip(int);
|
||||
int set_port(int);
|
||||
int update_client(int);
|
||||
int send_update(int);
|
||||
int configure_mac(int);
|
||||
int load_image(int);
|
||||
int set_master(int);
|
||||
int set_synchronization(int);
|
||||
int read_counter_block(int);
|
||||
int reset_counter_block(int);
|
||||
int calibrate_pedestal(int);
|
||||
int enable_ten_giga(int);
|
||||
int set_all_trimbits(int);
|
||||
int set_ctb_pattern(int);
|
||||
int write_adc_register(int);
|
||||
int set_counter_bit(int);
|
||||
int pulse_pixel(int);
|
||||
int pulse_pixel_and_move(int);
|
||||
int pulse_chip(int);
|
||||
int set_rate_correct(int);
|
||||
int get_rate_correct(int);
|
||||
int set_network_parameter(int);
|
||||
int program_fpga(int);
|
||||
int reset_fpga(int);
|
||||
int power_chip(int);
|
||||
int set_activate(int);
|
||||
int prepare_acquisition(int);
|
||||
int cleanup_acquisition(int);
|
||||
int threshold_temp(int);
|
||||
int temp_control(int);
|
||||
int temp_event(int);
|
||||
int auto_comp_disable(int);
|
||||
int storage_cell_start(int);
|
||||
int check_version(int);
|
||||
int software_trigger(int);
|
||||
|
||||
#endif
|
@ -0,0 +1,46 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
#include "communication_funcs.h"
|
||||
|
||||
#include "slsDetectorFunctionList.h"/*#include "slsDetector_firmware.h" for the time being*/
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int sockfd;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno;
|
||||
int retval=0;
|
||||
int sd,fd;
|
||||
|
||||
portno = DEFAULT_PORTNO;
|
||||
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
if (getServerError(sd)) //defined in communication_funcs
|
||||
return -1;
|
||||
|
||||
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Stop server: waiting for client call\n");
|
||||
#endif
|
||||
fd=acceptConnection(sd); //defined in communication_funcs
|
||||
retval=stopStateMachine();//defined in slsDetectorFirmare_funcs
|
||||
closeConnection(fd); //defined in communication_funcs
|
||||
}
|
||||
|
||||
exitServer(sd); //defined in communication_funcs
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
../commonFiles/sls_detector_defs.h
|
@ -0,0 +1 @@
|
||||
../commonFiles/sls_detector_funcs.h
|
Reference in New Issue
Block a user