basic tcp communication with writing /reading to fpga PLB_LL_FIFO_REG_CTRL works

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@441 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-01-29 16:34:02 +00:00
parent 11924d1a51
commit 1ee23e21d5
8 changed files with 112 additions and 37 deletions

View File

@ -1,5 +1,5 @@
CC = powerpc-4xx-softfloat-gcc
CLAGS += -Wall -DVIRTUAL -DDACS_INT -DSLS_DETECTOR_FUNCTION_LIST -DEIGERD
CLAGS += -Wall -DDACS_INT -DSLS_DETECTOR_FUNCTION_LIST -DEIGERD #-DVIRTUAL
LDLIBS += -lm
PROGS = eigerDetectorServer

View File

@ -10,7 +10,7 @@
#include "sls_detector_defs.h"
#define CSP0 0x90000000
#define CSP0 0xC4100000
#define MEM_SIZE 0xFFFFFFF

View File

@ -30,7 +30,7 @@ int main(int argc, char *argv[])
portno = DEFAULT_PORTNO;
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
printf("opening control server on port %d\n",portno );
system(cmd);
/* system(cmd);*/
b=1;
} else {
portno = DEFAULT_PORTNO+1;

View File

@ -81,26 +81,41 @@ int init_detector(int b) {
return OK;
}
int swap_int32(int val)
{
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF );
return (val << 16) | ((val >> 16) & 0xFFFF);
}
int64_t swap_int64(int64_t val)
{
val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL );
val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL );
return (val << 32) | ((val >> 32) & 0xFFFFFFFFULL);
}
int decode_function(int file_des) {
int fnum,n;
int retval=FAIL;
#ifdef VERBOSE
//#ifdef VERBOSE
printf( "receive data\n");
#endif
//#endif
n = receiveDataOnly(file_des,&fnum,sizeof(fnum));
fnum=swap_int32(fnum);
if (n <= 0) {
printf("ERROR reading from socket %d, %d %d\n", n, fnum, file_des);
#ifdef VERBOSE
printf("ERROR reading from socket %d, %x %d\n", n, fnum, file_des);
#endif
return FAIL;
}
#ifdef VERBOSE
else
printf("size of data received %d\n",n);
#endif
#ifdef VERBOSE
//#ifdef VERBOSE
printf( "calling function fnum = %d %x\n",fnum,flist[fnum]);
#endif
//#endif
if (fnum<0 || fnum>255)
fnum=255;
retval=(*flist[fnum])(file_des);
@ -268,6 +283,7 @@ int get_detector_type(int file_des) {
n += sendDataOnly(file_des,&retval,sizeof(retval));
if (retval!=FAIL) {
/* send return argument */
ret=swap_int32(ret);
n += sendDataOnly(file_des,&ret,sizeof(ret));
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
@ -703,6 +719,8 @@ int write_register(int file_des) {
sprintf(mess,"Can't write to register\n");
n = receiveDataOnly(file_des,arg,sizeof(arg));
arg[0]=swap_int32(arg[0]);
arg[1]=swap_int32(arg[1]);
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
@ -712,19 +730,21 @@ int write_register(int file_des) {
#ifdef VERBOSE
printf("writing to register 0x%x data 0x%x\n", addr, val);
#endif
#endif
if (differentClients==1 && lockStatus==1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else
retval=bus_w(addr,val);
} else{
ret=bus_w(addr,val);
if(ret==OK)
retval=bus_r(addr);
}
#ifdef VERBOSE
printf("Data set to 0x%x\n", retval);
#endif
#endif
if (retval==val) {
ret=OK;
if (differentClients)
@ -739,6 +759,7 @@ int write_register(int file_des) {
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret!=FAIL) {
/* send return argument */
retval=swap_int32(retval);
n += sendDataOnly(file_des,&retval,sizeof(retval));
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
@ -761,6 +782,7 @@ int read_register(int file_des) {
sprintf(mess,"Can't read register\n");
n = receiveDataOnly(file_des,&arg,sizeof(arg));
arg=swap_int32(arg);
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
@ -768,17 +790,15 @@ int read_register(int file_des) {
addr=arg;
#ifdef VERBOSE
printf("reading register 0x%x\n", addr);
#endif
#endif
retval=bus_r(addr);
#ifdef VERBOSE
printf("Returned value 0x%x\n", retval);
#endif
#endif
if (ret==FAIL) {
ret=FAIL;
printf("Reading register 0x%x failed\n", addr);
@ -791,6 +811,7 @@ int read_register(int file_des) {
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret!=FAIL) {
/* send return argument */
retval=swap_int32(retval);
n += sendDataOnly(file_des,&retval,sizeof(retval));
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
@ -1858,12 +1879,14 @@ int set_timer(int file_des) {
sprintf(mess,"can't set timer\n");
n = receiveDataOnly(file_des,&ind,sizeof(ind));
ind=swap_int32(ind);
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
n = receiveDataOnly(file_des,&tns,sizeof(tns));
tns=swap_int64(tns);
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
@ -1873,9 +1896,9 @@ int set_timer(int file_des) {
printf(mess);
}
#ifdef VERBOSE
//#ifdef VERBOSE
printf("setting timer %d to %lld ns\n",ind,tns);
#endif
//#endif
if (ret==OK) {
if (differentClients==1 && lockStatus==1 && tns!=-1) {
@ -1884,7 +1907,7 @@ int set_timer(int file_des) {
} else {
switch(ind) {
case FRAME_NUMBER:
retval=setFrames(tns);
retval=setFrames(tns);retval=swap_int64(retval);
break;
case ACQUISITION_TIME:
retval=setExposureTime(tns);

View File

@ -13,6 +13,9 @@ int sockfd;
int function_table();
int swap_int32(int val);
int64_t swap_int64(int64_t val);
int decode_function(int);
//if b>0 all the detector must be initialized, otherwise it is just the stop server

View File

@ -10,7 +10,9 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h> //PROT_READ,PROT_WRITE,MAP_FILE,MAP_SHARED,MAP_FAILED
#include <fcntl.h> //O_RDWR
u_int32_t CSP0BASE;
@ -40,13 +42,47 @@ const int nAdcs = NADC;
int64_t dummy=0;
/* Gerd example
if ((fd=open("/dev/mem", O_RDWR)) < 0){
printf("Cant find /dev/mem!\n");
return FAIL;
}
printf("/dev/mem opened\n");
void *plb_ll_fifo_ptr;
plb_ll_fifo_ptr = mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, CSP0);
if (plb_ll_fifo_ptr == MAP_FAILED){
printf("\nCan't map memmory area!!\n");
return FAIL;
}
CSP0BASE = (u_int32_t) plb_ll_fifo_ptr;
//plb_ll_fifo_ctrl_reg = 0;
*/
int mapCSP0(void) {
int fd;
printf("Mapping memory\n");
#ifdef VIRTUAL
CSP0BASE = (u_int32_t)malloc(MEM_SIZE);
printf("memory allocated\n");
#else
if ((fd=open("/dev/mem", O_RDWR | O_SYNC)) < 0){
printf("Cant find /dev/mem!\n");
return FAIL;
}
printf("/dev/mem opened\n");
CSP0BASE = (u_int32_t)mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0);
if (CSP0BASE == (u_int32_t)MAP_FAILED) {
printf("\nCan't map memmory area!!\n");
return FAIL;
}
#endif
printf("CSPOBASE is 0x%x \n",CSP0BASE);
printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE);
return OK;
@ -54,19 +90,31 @@ int mapCSP0(void) {
u_int32_t bus_w(u_int32_t offset, u_int32_t data) {
volatile u_int32_t *ptr1;
//u_int32_t bus_w(u_int32_t offset, u_int32_t data) {
u_int32_t bus_w(u_int32_t offset, u_int8_t data) {
__asm__ volatile ("stw %0,0(%1); eieio"::"r" (data), "b"(CSP0BASE+4*offset));
/* volatile u_int32_t *ptr1;
ptr1=(u_int32_t*)(CSP0BASE+offset);
*ptr1=data;
*ptr1=data;*/
return OK;
}
u_int32_t bus_r(u_int32_t offset) {
u_int32_t bus_r(u_int32_t offset) {//plb_ll_fifo_base+4*REG,val
u_int32_t ptr1;
__asm__ volatile ("eieio; lwz %0,0(%1)":"=r" (ptr1):"b"
(CSP0BASE+4*offset));
return ptr1;
/*
volatile u_int32_t *ptr1;
ptr1=(u_int32_t*)(CSP0BASE+offset);
return *ptr1;
*/
}
@ -101,10 +149,10 @@ int64_t get64BitReg(int aLSB, int aMSB){
}
int64_t setFrames(int64_t value){
int64_t setFrames(int64_t value){//dummy = value;return dummy;
return set64BitReg(value, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG);
}
int64_t getFrames(){
int64_t getFrames(){//return dummy;
return get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG);
}
@ -164,7 +212,7 @@ int64_t setProbes(int64_t value){
return 0;
}
int64_t getProbes(){
return 0;
return 0;
}

View File

@ -17,7 +17,8 @@
//memory
int mapCSP0(void);
u_int32_t bus_w(u_int32_t offset, u_int32_t data);
u_int32_t bus_w(u_int32_t offset, u_int8_t data);
//u_int32_t bus_w(u_int32_t offset, u_int32_t data);
u_int32_t bus_r(u_int32_t offset);

View File

@ -5,8 +5,8 @@
#include "slsDetectorFunctionList.h"/*#include "slsDetector_firmware.h" for the time being*/
#include "slsDetectorServer_defs.h"
#include <stdio.h>
#include <stdlib.h>
//#include <stdio.h>
//#include <stdlib.h>
int sockfd;
@ -14,13 +14,13 @@ int main(int argc, char *argv[])
{
int portno;
int retval=0;
int sd,fd;
// int sd,fd;
portno = DEFAULT_PORTNO;
sd=bindSocket(portno); //defined in communication_funcs
if (getServerError(sd)) //defined in communication_funcs
bindSocket(portno); //defined in communication_funcs
if (getServerError()) //defined in communication_funcs
return -1;
@ -33,12 +33,12 @@ int main(int argc, char *argv[])
#ifdef VERY_VERBOSE
printf("Stop server: waiting for client call\n");
#endif
fd=acceptConnection(sd); //defined in communication_funcs
acceptConnection(); //defined in communication_funcs
retval=stopStateMachine();//defined in slsDetectorFirmare_funcs
closeConnection(fd); //defined in communication_funcs
closeConnection(); //defined in communication_funcs
}
exitServer(sd); //defined in communication_funcs
exitServer(); //defined in communication_funcs
printf("Goodbye!\n");
return 0;