initial version of gotthard2

This commit is contained in:
2019-08-26 09:59:27 +02:00
parent 8ec0ac4eb3
commit 386b6601a8
11 changed files with 556 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
add_executable(gotthard2DetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
../slsDetectorServer/communication_funcs.c
)
include_directories(
../slsDetectorServer/
../../slsSupportLib/include
)
target_include_directories(gotthard2DetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(gotthard2DetectorServer_virtual
PUBLIC GOTTHARD2D VIRTUAL STOP_SERVER
)
target_link_libraries(gotthard2DetectorServer_virtual
PUBLIC pthread rt
)
set_target_properties(gotthard2DetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS gotthard2DetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,37 @@
current_dir = $(shell pwd)
main_server = ../slsDetectorServer/
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
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
OBJS = $(SRCS:.c=.o)
all: clean versioning $(PROGS)
boot: $(OBJS)
version_name=APIGOTTHARD2
version_path=slsDetectorServers/gotthard2DetectorServer
versioning:
cd ../../ && echo $(PWD) && echo `tput setaf 6; ./updateAPIVersion.sh $(version_name) $(version_path); tput sgr0;`
$(PROGS): $(OBJS)
# echo $(OBJS)
mkdir -p $(DESTDIR)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_server)*.o

View File

@@ -0,0 +1,33 @@
// stuff from Carlos
#pragma once
/* Definitions for FPGA*/
#define MEM_MAP_SHIFT 1
/* Status register */
#define STATUS_REG (0x01 << MEM_MAP_SHIFT)
/* Set Cycles 64 bit register */
#define SET_CYCLES_LSB_REG (0x02 << MEM_MAP_SHIFT)
#define SET_CYCLES_MSB_REG (0x03 << MEM_MAP_SHIFT)
/* Set Frames 64 bit register */
#define SET_FRAMES_LSB_REG (0x04 << MEM_MAP_SHIFT)
#define SET_FRAMES_MSB_REG (0x05 << MEM_MAP_SHIFT)
/* Set Period 64 bit register tT = T x 50 ns */
#define SET_PERIOD_LSB_REG (0x06 << MEM_MAP_SHIFT)
#define SET_PERIOD_MSB_REG (0x07 << MEM_MAP_SHIFT)
/* Set Exptime 64 bit register eEXP = Exp x 25 ns */
#define SET_EXPTIME_LSB_REG (0x08 << MEM_MAP_SHIFT)
#define SET_EXPTIME_MSB_REG (0x09 << MEM_MAP_SHIFT)
/* Get Cycles 64 bit register */
#define GET_CYCLES_LSB_REG (0x0A << MEM_MAP_SHIFT)
#define GET_CYCLES_MSB_REG (0x0B << MEM_MAP_SHIFT)
/* Get Frames 64 bit register */
#define GET_FRAMES_LSB_REG (0x0C << MEM_MAP_SHIFT)
#define GET_FRAMES_MSB_REG (0x0D << MEM_MAP_SHIFT)

View File

@@ -0,0 +1,375 @@
#include "slsDetectorFunctionList.h"
#include "versionAPI.h"
#include "clogger.h"
#ifdef VIRTUAL
#include "communication_funcs_UDP.h"
#include <pthread.h>
#include <time.h>
#endif
#include <string.h>
#include <unistd.h> // usleep
#include "blackfin.h"
// Global variable from slsDetectorServer_funcs
extern int debugflag;
int firmware_compatibility = OK;
int firmware_check_done = 0;
char firmware_message[MAX_STR_LENGTH];
#ifdef VIRTUAL
pthread_t pthread_virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
#endif
int isFirmwareCheckDone() {
return firmware_check_done;
}
int getFirmwareCheckResult(char** mess) {
*mess = firmware_message;
return firmware_compatibility;
}
void basictests() {
firmware_compatibility = OK;
firmware_check_done = 0;
memset(firmware_message, 0, MAX_STR_LENGTH);
#ifdef VIRTUAL
FILE_LOG(logINFOBLUE, ("******** Gotthard2 Virtual Server *****************\n"));
if (mapCSP0() == FAIL) {
strcpy(firmware_message,
"Could not map to memory. Dangerous to continue.\n");
FILE_LOG(logERROR, (firmware_message));
firmware_compatibility = FAIL;
firmware_check_done = 1;
return;
}
firmware_check_done = 1;
return;
#else
#endif
}
/* Ids */
int64_t getDetectorId(enum idMode arg){
int64_t retval = -1;
switch(arg){
case DETECTOR_SERIAL_NUMBER:
return getDetectorNumber();// or getDetectorMAC()
case DETECTOR_FIRMWARE_VERSION:
return getFirmwareVersion();
case SOFTWARE_FIRMWARE_API_VERSION:
return getFirmwareAPIVersion();
case DETECTOR_SOFTWARE_VERSION:
case CLIENT_SOFTWARE_API_VERSION:
return APIGOTTHARD2;
default:
return retval;
}
}
u_int64_t getFirmwareVersion() {
#ifdef VIRTUAL
return 0;
#endif
return 0;
}
u_int64_t getFirmwareAPIVersion() {
#ifdef VIRTUAL
return 0;
#endif
return 0;
}
u_int32_t getDetectorNumber(){
#ifdef VIRTUAL
return 0;
#endif
return 0;
}
u_int64_t getDetectorMAC() {
#ifdef VIRTUAL
return 0;
#else
char output[255],mac[255]="";
u_int64_t res=0;
FILE* sysFile = popen("ifconfig eth0 | grep HWaddr | cut -d \" \" -f 11", "r");
fgets(output, sizeof(output), sysFile);
pclose(sysFile);
//getting rid of ":"
char * pch;
pch = strtok (output,":");
while (pch != NULL){
strcat(mac,pch);
pch = strtok (NULL, ":");
}
sscanf(mac,"%llx",&res);
return res;
#endif
}
u_int32_t getDetectorIP(){
#ifdef VIRTUAL
return 0;
#endif
char temp[50]="";
u_int32_t res=0;
//execute and get address
char output[255];
FILE* sysFile = popen("ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2", "r");
fgets(output, sizeof(output), sysFile);
pclose(sysFile);
//converting IPaddress to hex.
char* pcword = strtok (output,".");
while (pcword != NULL) {
sprintf(output,"%02x",atoi(pcword));
strcat(temp,output);
pcword = strtok (NULL, ".");
}
strcpy(output,temp);
sscanf(output, "%x", &res);
//FILE_LOG(logINFO, ("ip:%x\n",res);
return res;
}
/* initialization */
void initControlServer(){
setupDetector();
}
void initStopServer() {
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
FILE_LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
}
/* set up detector */
void setupDetector() {
FILE_LOG(logINFO, ("This Server is for 1 Gotthard2 module \n"));
}
/* set parameters - dr, roi */
int setDynamicRange(int dr){
return -1;
}
/* parameters */
int64_t setTimer(enum timerIndex ind, int64_t val) {
int64_t retval = -1;
switch(ind){
case FRAME_NUMBER: // defined in sls_detector_defs.h (general)
if(val >= 0) {
FILE_LOG(logINFO, ("Setting #frames: %lld\n",(long long int)val));
}
retval = set64BitReg(val, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG); // defined in my RegisterDefs.h
FILE_LOG(logDEBUG1, ("Getting #frames: %lld\n", (long long int)retval));
break;
case ACQUISITION_TIME:
if(val >= 0){
FILE_LOG(logINFO, ("Setting exptime: %lldns\n", (long long int)val));
val *= (1E-3 * TEMP_CLK);
}
retval = set64BitReg(val, SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG) / (1E-3 * TEMP_CLK); // CLK defined in slsDetectorServer_defs.h
FILE_LOG(logDEBUG1, ("Getting exptime: %lldns\n", (long long int)retval));
break;
case FRAME_PERIOD:
if(val >= 0){
FILE_LOG(logINFO, ("Setting period: %lldns\n",(long long int)val));
val *= (1E-3 * TEMP_CLK);
}
retval = set64BitReg(val, SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG )/ (1E-3 * TEMP_CLK);
FILE_LOG(logDEBUG1, ("Getting period: %lldns\n", (long long int)retval));
break;
case CYCLES_NUMBER:
if(val >= 0) {
FILE_LOG(logINFO, ("Setting #cycles: %lld\n", (long long int)val));
}
retval = set64BitReg(val, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG);
FILE_LOG(logDEBUG1, ("Getting #cycles: %lld\n", (long long int)retval));
break;
default:
FILE_LOG(logERROR, ("Timer Index not implemented for this detector: %d\n", ind));
break;
}
return retval;
}
int validateTimer(enum timerIndex ind, int64_t val, int64_t retval) {
if (val < 0)
return OK;
switch(ind) {
case ACQUISITION_TIME:
case FRAME_PERIOD:
// convert to freq
val *= (1E-3 * TEMP_CLK);
// convert back to timer
val = (val) / (1E-3 * TEMP_CLK);
if (val != retval)
return FAIL;
break;
default:
break;
}
return OK;
}
int64_t getTimeLeft(enum timerIndex ind){
#ifdef VIRTUAL
return 0;
#endif
int64_t retval = -1;
switch(ind){
case FRAME_NUMBER:
retval = get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG);
FILE_LOG(logINFO, ("Getting number of frames left: %lld\n",(long long int)retval));
break;
case CYCLES_NUMBER:
retval = get64BitReg(GET_CYCLES_LSB_REG, GET_CYCLES_MSB_REG);
FILE_LOG(logINFO, ("Getting number of cycles left: %lld\n", (long long int)retval));
break;
default:
FILE_LOG(logERROR, ("Remaining Timer index not implemented for this detector: %d\n", ind));
break;
}
return -1;
}
int startStateMachine(){
#ifdef VIRTUAL
// create udp socket
if(createUDPSocket(0) != OK) {
return FAIL;
}
FILE_LOG(logINFOBLUE, ("starting state machine\n"));
// set status to running
virtual_status = 1;
virtual_stop = 0;
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
FILE_LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0;
return FAIL;
}
FILE_LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
return OK;
#endif
return OK;
}
#ifdef VIRTUAL
void* start_timer(void* arg) {
int64_t periodns = setTimer(FRAME_PERIOD, -1);
int numFrames = (setTimer(FRAME_NUMBER, -1) *
setTimer(CYCLES_NUMBER, -1) );
int64_t exp_ns = setTimer(ACQUISITION_TIME, -1);
int frameNr = 0;
// loop over number of frames
for(frameNr=0; frameNr!= numFrames; ++frameNr ) {
//check if virtual_stop is high, then break
// sleep for exposure time
struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin);
usleep(exp_ns / 1000);
clock_gettime(CLOCK_REALTIME, &end);
// calculate time left in period
int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 +
(end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime)
if (periodns > time_ns) {
usleep((periodns - time_ns)/ 1000);
}
// set register frames left
}
// set status to idle
virtual_status = 0;
return NULL;
}
#endif
int stopStateMachine(){
FILE_LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL
virtual_stop = 0;
return OK;
#endif
return OK;
}
enum runStatus getRunStatus(){
#ifdef VIRTUAL
if(virtual_status == 0){
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
}else{
FILE_LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING;
}
#endif
return IDLE;
}
void readFrame(int *ret, char *mess){
#ifdef VIRTUAL
FILE_LOG(logINFOGREEN, ("acquisition successfully finished\n"));
return;
#endif
}
/* common */
int calculateDataBytes(){
return 0;
}
int getTotalNumberOfChannels(){return ((int)getNumberOfChannelsPerChip() * (int)getNumberOfChips());}
int getNumberOfChips(){return NCHIP;}
int getNumberOfDACs(){return NDAC;}
int getNumberOfChannelsPerChip(){return NCHAN;}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "sls_detector_defs.h"
#include "RegisterDefs.h"
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
/* Hardware Definitions */
#define NCHAN (128)
#define NCHIP (10)
#define NDAC (16)
#define TEMP_CLK (20) /* MHz */