Merge branch 'master' of gitorious.psi.ch:sls_det_software/sls_detector_software

This commit is contained in:
bergamaschi 2014-10-01 10:39:23 +02:00
commit 18188cd095
59 changed files with 4297 additions and 897 deletions

View File

@ -49,6 +49,7 @@ using namespace std;
#define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000400ULL
#define RECEIVER_DYNAMIC_RANGE 0x0000000000000800ULL
#define RECEIVER_TEN_GIGA 0x0000000000001000ULL
#define ALLTIMBITS_NOT_SET 0x0000000000002000ULL
// 0x00000000FFFFFFFFULL
/** @short class returning all error messages for error mask */
@ -146,6 +147,9 @@ public:
if(slsErrorMask&RECEIVER_TEN_GIGA)
retval.append("Could not enable/disable 10GbE in the receiver.\n");
if(slsErrorMask&ALLTIMBITS_NOT_SET)
retval.append("Could not set all trimbits to value.\n");
return retval;

View File

@ -177,7 +177,8 @@ enum networkParameter {
RECEIVER_HOSTNAME, /**< receiver IP/hostname */
RECEIVER_UDP_IP, /**< receiever UDP IP */
RECEIVER_UDP_PORT, /**< receiever UDP Port */
RECEIVER_UDP_MAC /**< receiever UDP MAC */
RECEIVER_UDP_MAC, /**< receiever UDP MAC */
RECEIVER_UDP_PORT2 /**< receiever UDP Port of second half module for eiger */
};
/**

View File

@ -89,7 +89,8 @@ enum {
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */
F_ENABLE_TEN_GIGA /**< enable 10Gbe */
F_ENABLE_TEN_GIGA, /**< enable 10Gbe */
F_SET_ALL_TRIMBITS /** < set all trimbits to this value */
/* Always append functions hereafter!!! */

View File

@ -0,0 +1,582 @@
/**
* @author Ian Johnson
* @version 1.0
*/
//return reversed 1 means good, 0 means failed
#include <stdio.h>
#include <stdlib.h>
#include "xfs_types.h"
#include "xparameters.h"
#include "Beb.h"
struct BebInfo beb_infos[10];
int bebInfoSize = 0;
struct LocalLinkInterface ll_beb_local,* ll_beb;
struct LocalLinkInterface ll_beb_new_memory_local,* ll_beb_new_memory;
struct udp_header_type udp_header;
int Beb_send_ndata;
unsigned int Beb_send_buffer_size;
unsigned int* Beb_send_data_raw;
unsigned int* Beb_send_data;
int Beb_recv_ndata;
unsigned int Beb_recv_buffer_size;
unsigned int* Beb_recv_data_raw;
unsigned int* Beb_recv_data;
short Beb_bit_mode;
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num){
bebInfo->beb_number=beb_num;
bebInfo->serial_address=0;
strcpy(bebInfo->src_mac_1GbE,"");
strcpy(bebInfo->src_mac_10GbE,"");
strcpy(bebInfo->src_ip_1GbE,"");
strcpy(bebInfo->src_ip_10GbE,"");
bebInfo->src_port_1GbE=bebInfo->src_port_10GbE=0;
}
int BebInfo_SetSerialAddress(struct BebInfo* bebInfo, unsigned int a){
//address pre shifted
if(a>0xff) return 0;
bebInfo->serial_address = 0x04000000 | ((a&0xff)<<16);
return 1;
}
int BebInfo_SetHeaderInfo(struct BebInfo* bebInfo, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port){
if(ten_gig){ strcpy(bebInfo->src_mac_10GbE,src_mac); strcpy(bebInfo->src_ip_10GbE,src_ip); bebInfo->src_port_10GbE = src_port;}
else { strcpy(bebInfo->src_mac_1GbE,src_mac); strcpy(bebInfo->src_ip_1GbE,src_ip); bebInfo->src_port_1GbE = src_port;}
return 1;
}
unsigned int BebInfo_GetBebNumber(struct BebInfo* bebInfo) {return bebInfo->beb_number;}
unsigned int BebInfo_GetSerialAddress(struct BebInfo* bebInfo) {return bebInfo->serial_address;}
char* BebInfo_GetSrcMAC(struct BebInfo* bebInfo, int ten_gig) {return ten_gig ? bebInfo->src_mac_10GbE : bebInfo->src_mac_1GbE;}
char* BebInfo_GetSrcIP(struct BebInfo* bebInfo, int ten_gig) {return ten_gig ? bebInfo->src_ip_10GbE : bebInfo->src_ip_1GbE;}
unsigned int BebInfo_GetSrcPort(struct BebInfo* bebInfo, int ten_gig) {return ten_gig ? bebInfo->src_port_10GbE : bebInfo->src_port_1GbE;}
void BebInfo_Print(struct BebInfo* bebInfo){
printf("\t%d) Beb Info.:\n",bebInfo->beb_number);
printf("\t\tSerial Add: 0x%x\n",bebInfo->serial_address);
printf("\t\tMAC 1GbE: %s\n",bebInfo->src_mac_1GbE);
printf("\t\tIP 1GbE: %s\n",bebInfo->src_ip_1GbE);
printf("\t\tport 1GbE: %d\n",bebInfo->src_port_1GbE);
printf("\t\tMAC 10GbE: %s\n",bebInfo->src_mac_10GbE);
printf("\t\tIP 10GbE: %s\n",bebInfo->src_ip_10GbE);
printf("\t\tport 10GbE: %d\n",bebInfo->src_port_10GbE);
}
void Beb_Beb(int arg1){
Beb_send_ndata = 0;
Beb_send_buffer_size = 1026;
Beb_send_data_raw = malloc((Beb_send_buffer_size+1) * sizeof(unsigned int));
Beb_send_data = &Beb_send_data_raw[1];
Beb_recv_ndata = 0;
Beb_recv_buffer_size = 1026;
Beb_recv_data_raw = malloc((Beb_recv_buffer_size+1) * sizeof(unsigned int));
Beb_recv_data = &Beb_recv_data_raw[1];
udp_header= (struct udp_header_type){
{0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC
{0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC
{0x08, 0x00},
{0x45},
{0x00},
{0x00, 0x00},
{0x00, 0x00},
{0x40},
{0x00},
{0xff},
{0x11},
{0x00, 0x00},
{129, 205, 205, 128}, // Src IP
{129, 205, 205, 122}, // Dst IP
{0x0f, 0xa1},
{0x13, 0x89},
{0x00, 0x00}, //{0x00, 0x11},
{0x00, 0x00}
};
if(!Beb_InitBebInfos()) exit(1);
printf("Printing Beb infos:\n");
unsigned int i;
for(i=1;i<bebInfoSize;i++) BebInfo_Print(&beb_infos[i]);
printf("\n");
Beb_bit_mode = 4;
ll_beb = &ll_beb_local;
Local_LocalLinkInterface1(ll_beb,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
Beb_SetByteOrder();
ll_beb_new_memory = &ll_beb_new_memory_local;
Local_LocalLinkInterface(ll_beb_new_memory);
if(!Local_InitNewMemory(ll_beb_new_memory,XPAR_PLB_LL_NEW_MEMORY, arg1))
printf("New Memory FAIL\n");
else
printf("New Memory OK\n");
}
void Beb_ClearBebInfos(){
unsigned int i;
//for(i=0;i<bebInfoSize;i++) free(beb_infos[i]);
bebInfoSize=0;
}
int Beb_InitBebInfos(){//file name at some point
Beb_ClearBebInfos();
struct BebInfo b0;
BebInfo_BebInfo(&b0,0);
if(BebInfo_SetSerialAddress(&b0,0xff)) { //all bebs for reset and possibly get request data?
beb_infos[bebInfoSize] = b0;
bebInfoSize++;
}
if(!Beb_ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0;
/*
//loop through file to fill vector.
BebInfo* b = new BebInfo(26);
b->SetSerialAddress(0); //0xc4000000
b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 GbE, ip address can be acquire from the network "arp"
b->SetHeaderInfo(1,"00:50:c2:46:d9:35","10.0.26.1",52000 + 26); //10 GbE, everything calculable/setable
beb_infos.push_back(b);
*/
return Beb_CheckSourceStuffBebInfo();
}
int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac, char* src_ip,unsigned int src_port){
//so that the values can be reset externally for now....
unsigned int i = Beb_GetBebInfoIndex(beb_number);
if(!i){ printf("returning 000\n");return 0;} //i must be greater than 0, zero is the global send
BebInfo_SetHeaderInfo(&beb_infos[i],ten_gig,src_mac,src_ip,src_port);
printf("Printing Beb info number (%d) :\n",i);
BebInfo_Print(&beb_infos[i]);
printf("\n");
return 1;
}
int Beb_ReadSetUpFromFile(char* file_name){
char line[100];
char str[100];
int i0,i1;
char mac0[50],mac1[50],ip0[50],ip1[0];
FILE* fp = fopen(file_name, "r");
if( fp == NULL ){
perror("Error while opening the beb setup file.\n");
return 0;
}
printf("Setting up beb side of detector:\n");
while ( fgets (line , 255 , fp) != NULL ){
if(strlen(line)<=1)
continue;
sscanf (line, "%s", str);
if (str[0]=='#')
continue;
if(!strcmp(str,"add_beb")){
if( sscanf (line,"%s %d %d %s %s %s %s",str,&i0,&i1,mac0,ip0,mac1,ip1) < 7){
printf("Error adding beb from %s.\n",file_name);
exit(0);
}
printf ("Read: %s %d %d %s %s %s %s\n", str,i0,i1,mac0,ip0,mac1,ip1);
if(Beb_GetBebInfoIndex(i0)){
printf("Error adding beb from %s, beb number %d already added.\n",file_name,i0);
exit(0);
}
struct BebInfo b0;
BebInfo_BebInfo(&b0,i0);
BebInfo_SetSerialAddress(&b0,i1);
BebInfo_SetHeaderInfo(&b0,0,mac0,ip0,42000+i0);
BebInfo_SetHeaderInfo(&b0,1,mac1,ip1,52000+i0);
beb_infos[bebInfoSize] = b0;
bebInfoSize++;
}
}
fclose(fp);
return 1;
}
int Beb_CheckSourceStuffBebInfo(){
unsigned int i;
for(i=1;i<bebInfoSize;i++){ //header stuff always starts from 1
if(!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]),0,"00:00:00:00:00:00","10.0.0.1",20000)||!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]),1,"00:00:00:00:00:00","10.0.0.1",20000)){
printf("Error in BebInfo for module number %d.\n",BebInfo_GetBebNumber(&beb_infos[i]));
BebInfo_Print(&beb_infos[i]);
return 0;
}
}
return 1;
}
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb){
if(!beb_numb) return 0;
unsigned int i;
for(i=1;i<bebInfoSize;i++)
if(beb_numb==BebInfo_GetBebNumber(&beb_infos[i]))
return i;
return 0;
}
int Beb_WriteTo(unsigned int index){
if(index>=bebInfoSize){
printf("WriteTo index error.\n");
return 0;
}
Beb_send_data_raw[0] = 0x90000000 | BebInfo_GetSerialAddress(&beb_infos[index]);
if(Local_Write(ll_beb,4,Beb_send_data_raw)!=4) return 0;
Beb_send_data_raw[0] = 0xc0000000;
if((Beb_send_ndata+1)*4!=Local_Write(ll_beb,(Beb_send_ndata+1)*4,Beb_send_data_raw)) return 0;
return 1;
}
void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d){
unsigned int i;
if(little_endian) for(i=0;i<n;i++) d[i] = (((d[i]&0xff)<<24) | ((d[i]&0xff00)<<8) | ((d[i]&0xff0000)>>8) | ((d[i]&0xff000000)>>24)); //little_endian
else for(i=0;i<n;i++) d[i] = (((d[i]&0xffff)<<16) | ((d[i]&0xffff0000)>>16));
}
int Beb_SetByteOrder(){
Beb_send_data_raw[0] = 0x8fff0000;
if(Local_Write(ll_beb,4,Beb_send_data_raw)!=4) return 0;
while((Local_Read(ll_beb,Beb_recv_buffer_size*4,Beb_recv_data_raw)/4)>0) printf("\t) Cleanning buffer ...\n");
if(bebInfoSize<2) return 0;
Beb_send_ndata = 3;
Beb_send_data[0] = 0x000c0000;
Beb_send_data[1] = 0;
Beb_send_data[2] = 0;
Beb_WriteTo(0);
//using little endian for data, big endian not fully tested, swap on 16 bit boundary.
Beb_send_ndata = 3;
Beb_send_data[0] = 0x000c0000;
Beb_send_data[1] = 1;
Beb_send_data[2] = 0;
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
Beb_WriteTo(0);
printf("\tSetting Byte Order .............. ok\n");
return 1;
}
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port){
unsigned int i = Beb_GetBebInfoIndex(beb_number);
if(!i) return 0; //i must be greater than 0, zero is the global send
Beb_send_ndata = 14;
Beb_send_data[0] = ten_gig ? 0x00020000 : 0x00010000; //write to fanout numbers 1 or 2
Beb_send_data[1] = ((header_number*8)<<16);
if(!Beb_SetHeaderData(beb_number,ten_gig,dst_mac,dst_ip,dst_port)) return 0;
Beb_SwapDataFun(1,12,&(Beb_send_data[2]));
if(!Beb_WriteTo(i)) return 0;
printf("dst_port:%d\n",dst_port);
return 1;
}
int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char* dst_mac, char* dst_ip, unsigned int dst_port){
unsigned int i = Beb_GetBebInfoIndex(beb_number);
if(!i) return 0; //i must be greater than 0, zero is the global send
return Beb_SetHeaderData1(BebInfo_GetSrcMAC(&beb_infos[i],ten_gig),BebInfo_GetSrcIP(&beb_infos[i],ten_gig),BebInfo_GetSrcPort(&beb_infos[i],ten_gig),dst_mac,dst_ip,dst_port);
}
int Beb_SetHeaderData1(char* src_mac, char* src_ip, unsigned int src_port, char* dst_mac, char* dst_ip, unsigned int dst_port){
/* example header*/
//static unsigned int* word_ptr = new unsigned int [16];
/*static*/
/*
udp_header_type udp_header = {
{0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC
{0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC
{0x08, 0x00},
{0x45},
{0x00},
{0x00, 0x00},
{0x00, 0x00},
{0x40},
{0x00},
{0xff},
{0x11},
{0x00, 0x00},
{129, 205, 205, 128}, // Src IP
{129, 205, 205, 122}, // Dst IP
{0x0f, 0xa1},
{0x13, 0x89},
{0x00, 0x00}, //{0x00, 0x11},
{0x00, 0x00}
};
*/
if(!Beb_SetMAC(src_mac,&(udp_header.src_mac[0]))) return 0;
printf("Setting Source MAC to %s\n",src_mac);
if(!Beb_SetIP(src_ip,&(udp_header.src_ip[0]))) return 0;
printf("Setting Source IP to %s\n",src_ip);
if(!Beb_SetPortNumber(src_port,&(udp_header.src_port[0]))) return 0;
printf("Setting Source port to %d\n",src_port);
if(!Beb_SetMAC(dst_mac,&(udp_header.dst_mac[0]))) return 0;
printf("Setting Destination MAC to %s\n",dst_mac);
if(!Beb_SetIP(dst_ip,&(udp_header.dst_ip[0]))) return 0;
printf("Setting Destination IP to %s\n",dst_ip);
if(!Beb_SetPortNumber(dst_port,&(udp_header.dst_port[0]))) return 0;
printf("Setting Destination port to %d\n",dst_port);
Beb_AdjustIPChecksum(&udp_header);
unsigned int* base_ptr = (unsigned int *) &udp_header;
unsigned int num_words = ( sizeof(struct udp_header_type) + 3 ) / 4;
// for(unsigned int i=0; i<num_words; i++) word_ptr[i] = base_ptr[i];
// for(unsigned int i=num_words; i<16; i++) word_ptr[i] = 0;
// return word_ptr;
unsigned int i;
for(i=0; i<num_words; i++) Beb_send_data[i+2] = base_ptr[i];
for(i=num_words; i<16; i++) Beb_send_data[i+2] = 0;
return 1;
}
int Beb_SetMAC(char* mac, uint8_t* dst_ptr){
char macVal[50];strcpy(macVal,mac);
int i = 0;
char *pch = strtok (macVal,":");
while (pch != NULL){
if(strlen(pch)!=2){
printf("Error: in mac address -> %s\n",macVal);
return 0;
}
int itemp;
sscanf(pch,"%x",&itemp);
dst_ptr[i] = (u_int8_t)itemp;
pch = strtok (NULL, ":");
i++;
}
return 1;
}
int Beb_SetIP(char* ip, uint8_t* dst_ptr){
char ipVal[50];strcpy(ipVal,ip);
int i = 0;
char *pch = strtok (ipVal,".");
while (pch != NULL){
if(((i!=3) && ((strlen(pch)>3) || (strlen(pch)<1))) || ((i==3)&&((strlen(pch)<1) || (strlen(pch) > 3)))){
printf("Error: in ip address -> %s\n",ipVal);
return 0;
}
int itemp;
sscanf(pch,"%d",&itemp);
dst_ptr[i] = (u_int8_t)itemp;
pch = strtok (NULL, ".");
i++;
}
return 1;
}
int Beb_SetPortNumber(unsigned int port_number, uint8_t* dst_ptr){
dst_ptr[0] = (port_number >> 8) & 0xff ;
dst_ptr[1] = port_number & 0xff;
return 1;
}
void Beb_AdjustIPChecksum(struct udp_header_type *ip){
unsigned char *cptr = (unsigned char *) ip->ver_headerlen;
ip->ip_header_checksum[0] = 0;
ip->ip_header_checksum[1] = 0;
ip->total_length[0] = 0;
ip->total_length[1] = 28; // IP + UDP Header Length
// calc ip checksum
unsigned int ip_checksum = 0;
unsigned int i;
for(i=0; i<10; i++){
ip_checksum += ( (cptr[2*i] << 8) + (cptr[2*i + 1]) );
if (ip_checksum & 0x00010000) ip_checksum = (ip_checksum + 1) & 0x0000ffff;
}
ip->ip_header_checksum[0] = (ip_checksum >> 8) & 0xff ;
ip->ip_header_checksum[1] = ip_checksum & 0xff ;
}
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty){
unsigned int i = Beb_GetBebInfoIndex(beb_number); //zero is the global send
Beb_send_ndata = 3;
if(left_right == 1) Beb_send_data[0] = 0x00040000;
else if(left_right == 2) Beb_send_data[0] = 0x00080000;
else if(left_right == 3) Beb_send_data[0] = 0x000c0000;
else return 0;
//packet_size/=2;
if(dst_number>0x3f) return 0;
if(packet_size>0x3ff) return 0;
if(npackets==0||npackets>0x100) return 0;
npackets--;
Beb_send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets;
Beb_send_data[2] = 0;
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
if(!Beb_WriteTo(i)) return 0;
return 1;
}
int Beb_SetUpTransferParameters(short the_bit_mode){
if(the_bit_mode!=4&&the_bit_mode!=8&&the_bit_mode!=16&&the_bit_mode!=32) return 0;
Beb_bit_mode = the_bit_mode;
//nimages = the_number_of_images;
// on_dst = 0;
return 1;
}
int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait){
if(dst_number>64) return 0;
unsigned int header_size = 4; //4*64 bits
unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets
unsigned int npackets = ten_gig ? Beb_bit_mode*4 : Beb_bit_mode*16;
int in_two_requests = (!ten_gig&&Beb_bit_mode==32);
if(in_two_requests) npackets/=2;
// printf("npackets:%d\n",npackets);
//usleep needed after acquisition start, else you miss the single images
usleep(1000);
//printf("beb no:%d left_right:%d ten_gig:%d dst_number:%d #images:%d header_size:%d test_just_send_out_packets_no_wait:%d\n",beb_number,left_right,ten_gig,dst_number,nimages, header_size,test_just_send_out_packets_no_wait);
//printf("here: "<<beb_number<<","<<left_right<<","<<ten_gig<<","<<dst_number<<","<<1<<","<<header_size<<","<<test_just_send_out_packets_no_wait\n");
/*
unsigned int i;
for(i=0;i<nimages;i++){
//header then data request
//usleep(10000);
if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,1,header_size,test_just_send_out_packets_no_wait)){printf("Send failed\n");return 0;}
//usleep(10000);
if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait)){printf("Send failed\n");return 0;}
// usleep(0);
if(in_two_requests){if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait)){printf("Send failed\n");return 0;}
}
}
*/
unsigned int i;
for(i=0;i<nimages;i++){
//header then data request
if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,1,header_size,test_just_send_out_packets_no_wait) ||
!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait) ||
(in_two_requests&&!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait))){
printf("SendMultiReadRequest failed\n");
return 0;
}
}
return 1;
}
int Beb_Test(unsigned int beb_number){
printf("Testing module number: %d\n",beb_number);
//int SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, string dst_mac, string dst_ip, unsigned int dst_port){
//SetUpUDPHeader(26,0,0,"60:fb:42:f4:e3:d2","129.129.205.186",22000);
unsigned int index = Beb_GetBebInfoIndex(beb_number);
if(!index){
printf("Error beb number (%d)not in list????\n",beb_number);
return 0;
}
unsigned int i;
for(i=0;i<64;i++){
if(!Beb_SetUpUDPHeader(beb_number,0,i,"60:fb:42:f4:e3:d2","129.129.205.186",22000+i)){
printf("Error setting up header table....\n");
return 0;
}
}
// SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);
for(i=0;i<64;i++){
if(!Beb_SendMultiReadRequest(beb_number,i%3+1,0,i,1,0,1)){
printf("Error requesting data....\n");
return 0;
}
}
return 1;
}

View File

@ -8,98 +8,82 @@
#ifndef BEB_H
#define BEB_H
#include <string>
#include <vector>
#include "LocalLinkInterface.h"
class BebInfo{
private:
struct BebInfo{
unsigned int beb_number;
unsigned int serial_address;
std::string src_mac_1GbE;
std::string src_mac_10GbE;
std::string src_ip_1GbE;
std::string src_ip_10GbE;
char src_mac_1GbE[50];
char src_mac_10GbE[50];
char src_ip_1GbE[50];
char src_ip_10GbE[50];
unsigned int src_port_1GbE;
unsigned int src_port_10GbE;
public:
BebInfo(unsigned int beb_num);
~BebInfo(){};
bool SetSerialAddress(unsigned int add);
bool SetHeaderInfo(bool ten_gig, std::string src_mac, std::string src_ip, unsigned int src_port);//src_port fixed 42000+beb_number or 52000 + beb_number);
unsigned int GetBebNumber() {return beb_number;}
unsigned int GetSerialAddress() {return serial_address;}
std::string GetSrcMAC(bool ten_gig) {return ten_gig ? src_mac_10GbE : src_mac_1GbE;}
std::string GetSrcIP(bool ten_gig) {return ten_gig ? src_ip_10GbE : src_ip_1GbE;}
unsigned int GetSrcPort(bool ten_gig) {return ten_gig ? src_port_10GbE : src_port_1GbE;}
void Print();
};
class Beb{ //
private:
std::vector<BebInfo*> beb_infos;
void ClearBebInfos();
bool InitBebInfos();
bool ReadSetUpFromFile(std::string file_name);
bool CheckSourceStuffBebInfo();
unsigned int GetBebInfoIndex(unsigned int beb_numb);
LocalLinkInterface* ll;
LocalLinkInterface* new_memory;
int send_ndata;
unsigned int send_buffer_size;
unsigned int* send_data_raw;
unsigned int* send_data;
int recv_ndata;
unsigned int recv_buffer_size;
unsigned int* recv_data_raw;
unsigned int* recv_data;
bool WriteTo(unsigned int index);
bool SetMAC(std::string mac, unsigned char* dst_ptr);
bool SetIP(std::string ip, unsigned char* dst_ptr);
bool SetPortNumber(unsigned int port_number, unsigned char* dst_ptr);
void AdjustIPChecksum(udp_header_type *ip);
bool SetHeaderData(unsigned int beb_number, bool ten_gig, std::string dst_mac, std::string dst_ip, unsigned int dst_port);
bool SetHeaderData(std::string src_mac, std::string src_ip, unsigned int src_port, std::string dst_mac, std::string dst_ip, unsigned int dst_port);
void SwapDataFun(bool little_endian, unsigned int n, unsigned int *d);
bool SetByteOrder();
short bit_mode;
public:
Beb(int arg1);
virtual ~Beb();
bool SetBebSrcHeaderInfos(unsigned int beb_number, bool ten_gig, std::string src_mac, std::string src_ip, unsigned int src_port);
bool SetUpUDPHeader(unsigned int beb_number, bool ten_gig, unsigned int header_number, std::string dst_mac, std::string dst_ip, unsigned int dst_port);
bool SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, bool stop_read_when_fifo_empty=1);
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num);
void BebInfo_BebDstInfo(struct BebInfo* bebInfo, unsigned int beb_num);
int BebInfo_SetSerialAddress(struct BebInfo* bebInfo, unsigned int add);
int BebInfo_SetHeaderInfo(struct BebInfo* bebInfo, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port);//src_port fixed 42000+beb_number or 52000 + beb_number);
unsigned int BebInfo_GetBebNumber(struct BebInfo* bebInfo);
unsigned int BebInfo_GetSerialAddress(struct BebInfo* bebInfo);
char* BebInfo_GetSrcMAC(struct BebInfo* bebInfo, int ten_gig);
char* BebInfo_GetSrcIP(struct BebInfo* bebInfo, int ten_gig);
unsigned int BebInfo_GetSrcPort(struct BebInfo* bebInfo, int ten_gig);
void BebInfo_Print(struct BebInfo* bebInfo);
bool SetUpTransferParameters(short the_bit_mode);
bool RequestNImages(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int nimages, bool test_just_send_out_packets_no_wait=0); //all images go to the same destination!
bool Test(unsigned int beb_number);
};
void Beb_ClearBebInfos();
int Beb_InitBebInfos();
int Beb_ReadSetUpFromFile(char* file_name);
int Beb_CheckSourceStuffBebInfo();
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
int Beb_WriteTo(unsigned int index);
int Beb_SetMAC(char* mac, uint8_t* dst_ptr);
int Beb_SetIP(char* ip, uint8_t* dst_ptr);
int Beb_SetPortNumber(unsigned int port_number, uint8_t* dst_ptr);
void Beb_AdjustIPChecksum(struct udp_header_type *ip);
int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char* dst_mac, char* dst_ip, unsigned int dst_port);
int Beb_SetHeaderData1(char* src_mac, char* src_ip, unsigned int src_port, char* dst_mac, char* dst_ip, unsigned int dst_port);
void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d);
int Beb_SetByteOrder();
void Beb_Beb(int arg1);
int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port);
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port);
/*int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);*/
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty);
int Beb_SetUpTransferParameters(short the_bit_mode);
/*int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait=0); //all images go to the same destination!*/
int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait);
int Beb_Test(unsigned int beb_number);
#endif

View File

@ -4,7 +4,6 @@
* @version 1.0
*/
#include <netdb.h>
#include <stdio.h>
#include <string.h>
@ -12,11 +11,7 @@
#include "slsDetectorServer_defs.h" //include port number
struct sockaddr_in eiger_socket_addr;
int eiger_max_message_length = 1024;
char eiger_message[1024];
int eiger_message_length = 0;
int eiger_ret_val=0;
int eiger_nexposures = 1;
float eiger_exposuretime = 0;
@ -55,25 +50,9 @@ int EigerGetExternalGating(){return eiger_extgating;}
int EigerGetExternalGatingPolarity(){return eiger_extgatingpolarity;}
int EigerInit(){
static int passed = 0;
saved_trimbits[0] = -1;
if(!passed){
struct hostent *dst_host;
if((dst_host = gethostbyname("localhost")) == NULL){ //or look into getaddrinfo(3)
fprintf(stderr,"ERROR, no such host\n");
return 0;
}else{
//struct sockaddr_in eiger_socket_addr;
int port = FEB_PORT;
bzero((char *) &eiger_socket_addr, sizeof(eiger_socket_addr));
eiger_socket_addr.sin_family = AF_INET;
bcopy((char *)dst_host->h_addr,(char *)&eiger_socket_addr.sin_addr.s_addr,dst_host->h_length);
eiger_socket_addr.sin_port = htons(port);
passed = 1;
}
}
return passed;
}
@ -92,6 +71,7 @@ int EigerSendCMD(){
}
int n = write(sockfd,eiger_message,eiger_message_length);
int ret_length = read(sockfd,eiger_message,eiger_max_message_length);
close(sockfd);
@ -138,47 +118,80 @@ int EigerSetDAC(const char* iname,int v, int mV){
int EigerSetTrimbits(const int *data){
eiger_ret_val=0;
char tt[263681];
/*char tt[263681];
tt[263680]='\0';
int ip=0, ich=0;
int iy, ix;
int ichip;
// convert the trimbits from int32 to chars and add border pixels.
for(iy=0;iy<256;y++) {
for(iy=0;iy<256;iy++) {
for (ichip=0; ichip<4; ichip++) {
for(ix=0;ix<256;ix++) {
tt[ip++]=(char)(data[ich++]&(0x3f));
tt[ip++]=(char)((data[ich++]&(0x3f))+'0');
}
if (ichip<3) {
tt[ip++]=0;
tt[ip++]=0;
tt[ip++]=(char)(0+'0');
tt[ip++]=(char)(0+'0');
}
}
}
eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt);
memcpy(saved_trimbits,data,256*256*4*sizeof(int));
memcpy(saved_trimbits,data,256*256*4*sizeof(int));*/
eiger_message_length = sprintf(eiger_message,"settrimbits %d", 0);
return EigerSendCMD();
}
/* int EigerGetTrimbits(const int *data){ */
/* eiger_ret_val=0; */
/* char tt[263681]; */
/* tt[263680]='\0'; */
/* int ip=0, ich=0; */
/* int iy, ix; */
/* int ichip; */
/* eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt); */
/* memcpy(data,saved_trimbits,256*256*4*sizeof(int)); */
/* return EigerSendCMD(); */
/* } */
int EigerSetAllTrimbits(unsigned int value){
eiger_ret_val=0;
/*char tt[263681];
tt[263680]='\0';
int ip=0, ich=0;
int iy, ix;
int ichip;
int sl=0;
// convert the trimbits from int32 to chars and add border pixels.
for(iy=0;iy<256;iy++) {
for (ichip=0; ichip<4; ichip++) {
for(ix=0;ix<256;ix++) {
tt[ip++]=(char)((value&0x3f)+'0');
}
if (ichip<3) {
tt[ip++]=(char)(0+'0');
tt[ip++]=(char)(0+'0');
}
}
}
eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt);
for(iy=0;iy<256*256*4;++iy)
saved_trimbits[iy] = value;*/
eiger_message_length = sprintf(eiger_message,"setalltrimbits %d", value);
return EigerSendCMD();
}
int EigerGetTrimbits(const int *data){
eiger_ret_val=0;
/*char tt[263681];
tt[263680]='\0';
int ip=0, ich=0;
int iy, ix;
int ichip;
eiger_message_length = sprintf(eiger_message,"gettrimbits ");
memcpy(data,saved_trimbits,256*256*4*sizeof(int));*/
eiger_message_length = sprintf(eiger_message,"gettrimbits ");
return EigerSendCMD();
}

View File

@ -0,0 +1,334 @@
/**
* @author Ian Johnson
* @version 1.0
*/
/*#include <iostream>
#include <iomanip>*/
#include <stdio.h>
#include "xparameters.h"
#include "Feb.h"
Feb_Feb(){
Feb_nfebs = 0;
Feb_feb_numb = 0;
Feb_send_ndata = 0;
Feb_send_buffer_size = 1026;
Feb_send_data_raw = malloc((Feb_send_buffer_size+1)*sizeof(int));
Feb_send_data = &Feb_send_data_raw[1];
Feb_recv_ndata = 0;
Feb_recv_buffer_size = 1026;
Feb_recv_data_raw = malloc((Feb_recv_buffer_size+1)*sizeof(int));
Feb_recv_data = &Feb_recv_data_raw[1];
Local_LocalLinkInterface1(ll,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
}
/*
~Feb(){
delete ll;
if(feb_numb) delete [] feb_numb;
delete [] send_data_raw;
delete [] recv_data_raw;
}
*/
void Feb_SendCompleteFebList(unsigned int n,unsigned int* list){
unsigned int i;
if(Feb_feb_numb) free(Feb_feb_numb);
Feb_nfebs = n;
Feb_feb_numb = malloc(n*sizeof(unsigned int));
for(i=0;i<n;i++) Feb_feb_numb[i] = list[i];
}
int Feb_WriteTo(unsigned int ch){
if(ch>0xfff) return 0;
Feb_send_data_raw[0] = 0x90000000 | (ch<<16); //we
if(Local_Write(ll,4,Feb_send_data_raw)!=4) return 0;
Feb_send_data_raw[0] = 0xc0000000; //data
return 1;((Feb_send_ndata+1)*4==Local_Write(ll,(Feb_send_ndata+1)*4,Feb_send_data_raw));
}
int Feb_ReadFrom(unsigned int ch, unsigned int ntrys){
unsigned int t;
if(ch>=0xfff) return 0;
Feb_recv_data_raw[0] = 0xa0000000 | (ch<<16); //read data
Local_Write(ll,4,Feb_recv_data_raw);
usleep(20);
Feb_recv_ndata=-1;
for(t=0;t<ntrys;t++){
if((Feb_recv_ndata=Local_Read(ll,Feb_recv_buffer_size*4,Feb_recv_data_raw)/4)>0){
Feb_recv_ndata--;
break;
}
printf("\t Read try number: %d\n",t);
usleep(1000);
}
return (Feb_recv_ndata>=0);
}
void Feb_PrintData(){
int i;
printf("Sent data: %d\n",Feb_send_ndata);
for(i=0;i<Feb_send_ndata;i++) printf("\t%d)%d (0x%x)\n",i,Feb_send_data[i],Feb_send_data[i]);
printf("Receive data: %d\n",Feb_recv_ndata);
for(i=0;i<Feb_recv_ndata;i++) printf("\t%d)%d (0x%x)\n",i,Feb_recv_data[i],Feb_recv_data[i]);
printf("\n\n");
}
int Feb_CheckHeader(unsigned int valid_bit_mask, int print_error_info){
int header_returned_is_ok = (Feb_send_data[0] & valid_bit_mask)==(Feb_recv_data[0] & valid_bit_mask);
if(print_error_info && !header_returned_is_ok){
printf("Error: Command received not the same as command recieved.\n");
printf("\t\t Header sent: %d (0x%x) received: %d (0x%x)\n",Feb_send_data[0], Feb_send_data[0], Feb_recv_data[0], Feb_recv_data[0]);
if(Feb_send_ndata>1&&Feb_recv_ndata>1){
printf("\t\t Tail sent: %d (0x%x) receiver: %d (0x%x)\n",Feb_send_data[Feb_send_ndata-1],Feb_send_data[Feb_send_ndata-1],Feb_recv_data[Feb_recv_ndata-1],Feb_recv_data[Feb_recv_ndata-1]);
}else{
printf("Error printing tail, too little data nsent = 0x%x, nrecv = 0x%x.\n",Feb_send_ndata, Feb_recv_ndata);
}
Feb_PrintData();
}
return header_returned_is_ok;
}
int Feb_CheckTail(unsigned int valid_bit_mask){
if(Feb_send_ndata<=1&&Feb_recv_ndata<=1){
printf("Error checking tail, too little data nsent = %d, nrecv = %d.\n",Feb_send_ndata, Feb_recv_ndata);
return 0;
}
unsigned int the_tail = Feb_recv_data[Feb_recv_ndata-1]&valid_bit_mask;
if(the_tail!=0){
printf("Error returned in tail: 0x%x (%d)\n",the_tail,the_tail);
if(the_tail&0x10000000) printf("\t\tBusy flag address error.\n");
if(the_tail&0x20000000) printf("\t\tRead register address error.\n");
if(the_tail&0x40000000) printf("\t\tWrite register address error.\n");
if(the_tail&0x80000000) printf("\t\tBram number error.\n");
if(the_tail&0x08000000) printf("\t\tFifo to read from error.\n");
if(the_tail&0x3ff) printf("\t\tNumber of data send error.\n");
return 0; //error
}
return 1;
}
int Feb_CheckCommunication(){
Feb_send_data_raw[0] = 0x8fff0000; //rst-all serial coms and lls
if(Local_Write(ll,4,Feb_send_data_raw)!=4) return 0;
printf("CheckingCommunication ....\n");
while((Local_Read(ll,Feb_recv_buffer_size*4,Feb_recv_data_raw)/4)>0) printf("\t) Cleanning buffer ...\n");
return Feb_SetByteOrder();
}
int Feb_SetByteOrder(){
unsigned int i;
Feb_send_ndata = 2;
Feb_send_data[0] = 0; //header
Feb_send_data[1] = 0; //tail
unsigned int dst = 0xff;
for( i=0;i<Feb_nfebs;i++) dst = (dst | Feb_feb_numb[i]); //get sub dst bits (left right in this case)
int passed = Feb_WriteTo(dst);
for(i=0;i<Feb_nfebs;i++){
printf("\t%d) Set Byte Order .............. ",i);
unsigned int current_passed = Feb_ReadFrom(Feb_feb_numb[i],20)&&(Feb_recv_ndata==2)&&Feb_CheckHeader(0xffffffff,1);
if(current_passed) printf("passed.\n");
else printf("failed.\n");
passed&=current_passed;
}
printf("\n");
return passed;
}
/* feb_ needed
int Feb_CheckSubNumber(unsigned int Feb_sub_num){
if(sub_num>=nfebs){
cout<<"Error invalid sub number "<<sub_num<<" must be less than "<<nfebs<<"."<<endl;
return 0;
}
return 1;
}
int Feb_SetStartOnEndOnFebs(int sub_num_s, unsigned int& start_on, unsigned int& end_on){
// -1 means write to all
if(sub_num_s<=-2){
cout<<"Error bad subnumber "<<sub_num_s<<"."<<endl;
return 0;
}
start_on = sub_num_s!=-1 ? sub_num_s : 0;
end_on = sub_num_s!=-1 ? sub_num_s : nfebs - 1;
return Feb_CheckSubNumber(start_on);
}
*/
/*
int Feb_ReadRegister(unsigned int Feb_sub_num, unsigned int Feb_reg_num,unsigned int& Feb_value_read){
return Feb_ReadRegisters(Feb_sub_num,1,&Feb_reg_num,&Feb_value_read);
}
*/
int Feb_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read){
return Feb_ReadRegisters(sub_num,1,&reg_num,value_read);
}
int Feb_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read){
//here cout<<"Reading Register ...."<<endl;
unsigned int i;
nreads &= 0x3ff; //10 bits
if(!nreads||nreads>Feb_send_buffer_size-2) return 0;
Feb_send_ndata = nreads+2;
Feb_send_data[0] = 0x20000000 | nreads << 14; //cmd -> read "00" , nreads
for(i=0;i<nreads;i++) Feb_send_data[i+1]=reg_nums[i];
Feb_send_data[nreads+1] = 0; //tail
if(!Feb_WriteTo(sub_num)||!Feb_ReadFrom(sub_num,20)||Feb_recv_ndata!=(int)(nreads+2)||!Feb_CheckHeader(0xffffffff,1)||!Feb_CheckTail(0xffffffff)){
Feb_PrintData();
printf("Error reading register.\n");
return 0;
}
for(i=0;i<nreads;i++) values_read[i] = Feb_recv_data[i+1];
return 1;
}
int Feb_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address){
return Feb_WriteRegisters(sub_num,1,&reg_num,&value,&wait_on,&wait_on_address);
}
int Feb_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses){
unsigned int i;
// sub_num == 0xfff means write to all
nwrites &= 0x3ff; //10 bits
if(!nwrites||nwrites>Feb_send_buffer_size-2) return 0;
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
Feb_send_ndata = 2*nwrites+2;
Feb_send_data[0] = 0x80000000 | nwrites << 14; //cmd -> write nwrites and how many
Feb_send_data[2*nwrites+1] = 0; //tail
for(i=0;i<nwrites;i++) Feb_send_data[2*i+1] = 0x3fff&reg_nums[i]; // register address data_in(13 downto 0)
for(i=0;i<nwrites;i++) Feb_send_data[2*i+2] = values[i]; // value is data_in(31 downto 0)
// wait on busy data(28), address of busy flag data(27 downto 14)
if(wait_ons&&wait_on_addresses) for(i=0;i<nwrites;i++) Feb_send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
if(!Feb_WriteTo(sub_num)){
printf("%d) Error writing register(s).\n",sub_num);
Feb_PrintData();
return 0;
}
int passed = 1;
unsigned int n = (sub_num&0xff)==0xff ? Feb_nfebs : 1;
unsigned int* nums = (sub_num&0xff)==0xff ? Feb_feb_numb : &sub_num;
for(i=0;i<n;i++){
if((sub_num&0xf00&(nums[i]))==0) continue;
if(!Feb_ReadFrom(nums[i],20)||Feb_recv_ndata!=2||!Feb_CheckHeader(0xffffffff,1)){
printf("%d) Error writing register(s) response.\n",nums[i]);
Feb_PrintData();
passed = 0;
}else{
passed = passed && Feb_CheckTail(0xffffffff);
}
}
return passed;
}
int Feb_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
// -1 means write to all
unsigned int i;
mem_num &= 0x3f; //6 bits
start_address &= 0x3fff; //14 bits
nwrites &= 0x3ff; //10 bits
if(!nwrites||nwrites>Feb_send_buffer_size-2) return 0;
Feb_send_ndata = nwrites+2;
Feb_send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
Feb_send_data[nwrites+1] = 0; //tail
for(i=0;i<nwrites;i++) Feb_send_data[i+1] = values[i];
if(!Feb_WriteTo(sub_num)){
printf("%d) Error writing memory.\n",sub_num);
return 0;
}
int passed = 1;
unsigned int n = (sub_num&0xff)==0xff ? Feb_nfebs : 1;
unsigned int* nums = (sub_num&0xff)==0xff ? Feb_feb_numb : &sub_num;
for(i=0;i<n;i++){
if((sub_num&0xf00&(nums[i]))==0) continue;
if(!Feb_ReadFrom(nums[i],20)||Feb_recv_ndata!=2||!Feb_CheckHeader(0xffffffff,1)){
printf("%d) Error writing memory response. \n",nums[i]);
Feb_PrintData();
passed = 0;
}else{
passed = passed && Feb_CheckTail(0xffffffff);
}
}
// unsigned int n = sub_num==0xfff ? nfebs : 1;
// unsigned int* nums = sub_num==0xfff ? feb_numb : &sub_num;
// for(unsigned int i=0;i<n;i++){
return passed;
}
int Feb_Test(){//int sub_num_s, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
// -1 means write to all
unsigned int i;
unsigned int reg_nums[10]={0,1,2,3,1,2,3,1,2,3};
printf("Test\n\n\n\n");
unsigned int value = 0;
for(i=0;i<10;i++){
Feb_WriteRegister(0xfff,reg_nums[i%10],i,0,0);
Feb_ReadRegister(256,reg_nums[i%10],&value);
printf("%d %d\n",i,value);
Feb_ReadRegister(512,reg_nums[i%10],&value);
printf("%d %d\n",i,value);
Feb_WriteMemory(0xfff,0,0,10,reg_nums);
}
return 0;
}

View File

@ -10,53 +10,50 @@
#include "LocalLinkInterface.h"
class Feb{ //
private:
LocalLinkInterface* ll;
struct LocalLinkInterface* ll;
unsigned int nfebs;
unsigned int* feb_numb;
unsigned int Feb_nfebs;
unsigned int* Feb_feb_numb;
int send_ndata;
unsigned int send_buffer_size;
unsigned int* send_data_raw;
unsigned int* send_data;
int Feb_send_ndata;
unsigned int Feb_send_buffer_size;
unsigned int* Feb_send_data_raw;
unsigned int* Feb_send_data;
int recv_ndata;
unsigned int recv_buffer_size;
unsigned int* recv_data_raw;
unsigned int* recv_data;
int Feb_recv_ndata;
unsigned int Feb_recv_buffer_size;
unsigned int* Feb_recv_data_raw;
unsigned int* Feb_recv_data;
bool WriteTo(unsigned int ch);
bool ReadFrom(unsigned int ch, unsigned int ntrys=20);
bool CheckHeader(unsigned int valid_bit_mask=0xffffffff, bool print_error_info=1);
bool CheckTail(unsigned int valid_bit_mask=0xffffffff);
int Feb_WriteTo(unsigned int ch);
/*int Feb_ReadFrom(unsigned int Feb_ch, unsigned int Feb_ntrys=20);*/
int Feb_ReadFrom(unsigned int ch, unsigned int ntrys);
/* int Feb_CheckHeader(unsigned int Feb_valid_bit_mask=0xffffffff, int Feb_print_error_info=1);*/
int Feb_CheckHeader(unsigned int valid_bit_mask, int print_error_info);
/*int Feb_CheckTail(unsigned int Feb_valid_bit_mask=0xffffffff);*/
int Feb_CheckTail(unsigned int valid_bit_mask);
int Feb_SetByteOrder();
//int Feb_CheckSubNumber(unsigned int Feb_sub_num);
//int Feb_SetStartOnEndOnFebs(int Feb_sub_num_s, unsigned int& Feb_start_on, unsigned int& Feb_end_on);
void Feb_PrintData();
bool SetByteOrder();
//bool CheckSubNumber(unsigned int sub_num);
//bool SetStartOnEndOnFebs(int sub_num_s, unsigned int& start_on, unsigned int& end_on);
void PrintData();
Feb_Feb();
/*virtual ~Feb();*/
void Feb_SendCompleteFebList(unsigned int n,unsigned int* list);
int Feb_CheckCommunication();
/*int Feb_ReadRegister(unsigned int Feb_sub_num, unsigned int Feb_reg_num,unsigned int& Feb_value_read);*/
int Feb_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read);
int Feb_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
/*int WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on=0, unsigned int wait_on_address=0);*/
int Feb_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address);
/*int WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons=0, unsigned int* wait_on_addresses=0);*/
int Feb_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses);
int Feb_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
int Feb_Test();
public:
Feb();
virtual ~Feb();
void SendCompleteFebList(unsigned int n,unsigned int* list);
bool CheckCommunication();
bool ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int& value_read);
bool ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
bool WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, bool wait_on=0, unsigned int wait_on_address=0);
bool WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, bool* wait_ons=0, unsigned int* wait_on_addresses=0);
bool WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
bool Test();
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -78,7 +78,7 @@ FebControl::FebControl(){
staticBits=acquireNReadoutMode=triggerMode=externalEnableMode=subFrameMode=0;
trimbit_size=263680;
last_downloaded_trimbits = new unsigned char [trimbit_size];
last_downloaded_trimbits = new unsigned int [trimbit_size];
cout<<endl<<"Default Settings:"<<endl;
nimages = 1;
@ -697,67 +697,95 @@ float FebControl::GetDAC(string s){
}
*/
bool FebControl::SetTrimbits(unsigned int module_num, unsigned char *trimbits){
bool FebControl::SetTrimbits(unsigned int module_num, unsigned int *trimbits){
printf("Setting Trimbits\n");
unsigned int module_index=0;
if(!GetModuleIndex(module_num,module_index)){
cout<<"Warning could not set trimbits, bad module number."<<endl;
return 0;
}
//for (int iy=10000;iy<20020;++iy)//263681
//for (int iy=263670;iy<263680;++iy)//263681
// printf("%d:%c\t\t",iy,trimbits[iy]);
if(!Reset()) cout<<"Warning could not reset DAQ."<<endl;
for(int l_r=0;l_r<2;l_r++){ // l_r loop
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
if(!(WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8)&&SetCommandRegister(DAQ_SET_STATIC_BIT)&&StartDAQOnlyNWaitForFinish())){
cout<<"Could not select chips"<<endl;
return 0;
}
for(int row_set=0;row_set<16;row_set++){ //16 rows at a time
if(row_set==0){
if(!SetCommandRegister(DAQ_RESET_COMPLETELY|DAQ_SEND_A_TOKEN_IN|DAQ_LOAD_16ROWS_OF_TRIMBITS)){
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
return 0;
unsigned int module_index=0;
if(!GetModuleIndex(module_num,module_index)){
cout<<"Warning could not set trimbits, bad module number."<<endl;
return 0;
}
}else{
if(!SetCommandRegister(DAQ_LOAD_16ROWS_OF_TRIMBITS)){
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
return 0;
}
}
static unsigned int trimbits_to_load_l[1024];
static unsigned int trimbits_to_load_r[1024];
for(int row=0;row<16;row++){ //row loop
int offset = 2*32*row;
for(int sc=0;sc<32;sc++){ //supercolumn loop sc
int super_column_start_position_l = 1030*row + l_r *258 + sc*8;
int super_column_start_position_r = 1030*row + 516 + l_r *258 + sc*8;
int chip_sc = 31 - sc;
trimbits_to_load_l[offset+chip_sc] = 0;
trimbits_to_load_r[offset+chip_sc] = 0;
for(int i=0;i<8;i++){ // column loop i
trimbits_to_load_l[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])<<((7-i)*4);//low
trimbits_to_load_l[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])>>3)<<((7-i)*4);//upper
trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])<<((7-i)*4);//low
trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])>>3)<<((7-i)*4);//upper
} // end column loop i
} //end supercolumn loop sc
} //end row loop
if(!Reset()) cout<<"Warning could not reset DAQ."<<endl;
if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()) return 0;
} //end row_set loop (groups of 16 rows)
} // end l_r loop
for(int l_r=0;l_r<2;l_r++){ // l_r loop
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
if(!(WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8)&&SetCommandRegister(DAQ_SET_STATIC_BIT)&&StartDAQOnlyNWaitForFinish())){
cout<<"Could not select chips"<<endl;
return 0;
}
memcpy(last_downloaded_trimbits,trimbits,trimbit_size*sizeof(unsigned char));
for(int row_set=0;row_set<16;row_set++){ //16 rows at a time
if(row_set==0){
if(!SetCommandRegister(DAQ_RESET_COMPLETELY|DAQ_SEND_A_TOKEN_IN|DAQ_LOAD_16ROWS_OF_TRIMBITS)){
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
return 0;
}
}else{
if(!SetCommandRegister(DAQ_LOAD_16ROWS_OF_TRIMBITS)){
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
return 0;
}
}
return SetStaticBits(); //send the static bits
static unsigned int trimbits_to_load_l[1024];
static unsigned int trimbits_to_load_r[1024];
for(int row=0;row<16;row++){ //row loop
int offset = 2*32*row;
for(int sc=0;sc<32;sc++){ //supercolumn loop sc
int super_column_start_position_l = 1030*row + l_r *258 + sc*8;
int super_column_start_position_r = 1030*row + 516 + l_r *258 + sc*8;
/*
int super_column_start_position_l = 1024*row + l_r *256 + sc*8; //256 per row, 8 per super column
int super_column_start_position_r = 1024*row + 512 + l_r *256 + sc*8; //256 per row, 8 per super column
*/
int chip_sc = 31 - sc;
trimbits_to_load_l[offset+chip_sc] = 0;
trimbits_to_load_r[offset+chip_sc] = 0;
for(int i=0;i<8;i++){ // column loop i
trimbits_to_load_l[offset+chip_sc] |= ( 0x7 & trimbits[row_set*16480+super_column_start_position_l+i])<<((7-i)*4);//low
trimbits_to_load_l[offset+chip_sc+32] |= ((0x38 & trimbits[row_set*16480+super_column_start_position_l+i])>>3)<<((7-i)*4);//upper
trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[row_set*16480+super_column_start_position_r+i])<<((7-i)*4);//low
trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[row_set*16480+super_column_start_position_r+i])>>3)<<((7-i)*4);//upper
/*
trimbits_to_load_l[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])<<((7-i)*4);//low
trimbits_to_load_l[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])>>3)<<((7-i)*4);//upper
trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])<<((7-i)*4);//low
trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])>>3)<<((7-i)*4);//upper
*/
} // end column loop i
} //end supercolumn loop sc
} //end row loop
/*
if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()){
cout <<" some errror!"<< endl;
return 0;
}
*/
if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1023,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1023,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()){
cout <<" some errror!"<< endl;
return 0;
}
} //end row_set loop (groups of 16 rows)
} // end l_r loop
memcpy(last_downloaded_trimbits,trimbits,trimbit_size*sizeof(unsigned char));
return SetStaticBits(); //send the static bits
}
unsigned char* FebControl::GetTrimbits(){
unsigned int* FebControl::GetTrimbits(){
return last_downloaded_trimbits;
}
@ -1191,4 +1219,79 @@ bool FebControl::StopAcquisition(){
bool FebControl::LoadTrimbitFile(){
string filename = "/home/root/noise.snbeb040";
ifstream input_file;
int ndacs =16;
int dacs[ndacs];
unsigned int chanregs[trimbit_size];
input_file.open(filename.c_str() ,ifstream::binary);
if(!input_file.is_open()){
cout<<"Warning, could not open trimbit file: "<<filename<<endl;
exit(-1);
}
//dacs
for(int i=0;i<ndacs;++i){
input_file.read((char*) &dacs[i],sizeof(int));
cout << " dac " << i << ":"<< Module::dac_names[i] << ":" << dacs[i] << endl;
SetDAC(Module::dac_names[i],dacs[i]);
}
cout << "Loading trimbits from file " << filename << endl;
//trimbits
input_file.read((char*) chanregs,trimbit_size*sizeof(unsigned int));
if(input_file.eof()){
cout<<endl<<"Error, could not load trimbits end of file, "<<filename<<", reached."<<endl<<endl;
exit(-1);
}
input_file.close();
return SetTrimbits(0,chanregs);
}
bool FebControl::SaveTrimbitFile(){
string filename = "/home/root/noise.snbeb040";
ofstream output_file;
int ndacs =16;
int dacs[ndacs];
output_file.open(filename.c_str() ,ofstream::binary);
if(!output_file.is_open()){
cout<<"Warning, could not open trimbit file: "<<filename<<endl;
return 0;
}
cout << "Writing trimbits to file " << filename << endl;
//dacs
for(int i=0;i<ndacs;++i){
GetDAC(Module::dac_names[i], dacs[i]);
output_file.write((char*) &dacs[i],sizeof(int));
cout << " dac " << i << ":"<< Module::dac_names[i] << ":" << dacs[i] << endl;
}
//trimbits
output_file.write((char*) last_downloaded_trimbits,trimbit_size * sizeof(unsigned int));
output_file.close();
return 1;
}
bool FebControl::SaveAllTrimbitsTo(int value){
unsigned int chanregs[trimbit_size];
for(int i=0;i<trimbit_size;i++)
chanregs[i] = value;
return SetTrimbits(0,chanregs);
}

View File

@ -9,180 +9,175 @@
#define FEBCONTROL_H
#include <netinet/in.h>
#include <string>
#include <vector>
#include <stdlib.h>
//#include <string>
//#include <vector>
#include "FebInterface.h"
class Module{
private:
unsigned int module_number;
bool top_address_valid;
unsigned int top_left_address;
unsigned int top_right_address;
bool bottom_address_valid;
unsigned int bottom_left_address;
unsigned int bottom_right_address;
unsigned int idelay_top[4]; //ll,lr,rl,ll
unsigned int idelay_bottom[4]; //ll,lr,rl,ll
float high_voltage;
int* top_dac;
int* bottom_dac;
public:
Module(unsigned int number, unsigned int address_top); //for half module()
Module(unsigned int number, unsigned int address_top, unsigned int address_bottom);
~Module();
static const unsigned int ndacs;
static const std::string dac_names[16];
unsigned int GetModuleNumber() {return module_number;}
bool TopAddressIsValid() {return top_address_valid;}
unsigned int GetTopBaseAddress() {return (top_left_address&0xff);}
unsigned int GetTopLeftAddress() {return top_left_address;}
unsigned int GetTopRightAddress() {return top_right_address;}
unsigned int GetBottomBaseAddress() {return (bottom_left_address&0xff);}
bool BottomAddressIsValid() {return bottom_address_valid;}
unsigned int GetBottomLeftAddress() {return bottom_left_address;}
unsigned int GetBottomRightAddress() {return bottom_right_address;}
unsigned int SetTopIDelay(unsigned int chip,unsigned int value) { return TopAddressIsValid() &&chip<4 ? (idelay_top[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int GetTopIDelay(unsigned int chip) { return chip<4 ? idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int SetBottomIDelay(unsigned int chip,unsigned int value) { return BottomAddressIsValid() &&chip<4 ? (idelay_bottom[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int GetBottomIDelay(unsigned int chip) { return chip<4 ? idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
float SetHighVoltage(float value) { return TopAddressIsValid() ? (high_voltage=value) : -1;}
float GetHighVoltage() { return high_voltage;}
int SetTopDACValue(unsigned int i, int value) { return (i<ndacs && TopAddressIsValid()) ? (top_dac[i]=value) : -1;}
int GetTopDACValue(unsigned int i) { return (i<ndacs) ? top_dac[i]:-1;}
int SetBottomDACValue(unsigned int i, int value) { return (i<ndacs && BottomAddressIsValid()) ? (bottom_dac[i]=value) : -1;}
int GetBottomDACValue(unsigned int i) { return (i<ndacs) ? bottom_dac[i]:-1;}
struct Module{
unsigned int module_number;
int top_address_valid;
unsigned int top_left_address;
unsigned int top_right_address;
int bottom_address_valid;
unsigned int bottom_left_address;
unsigned int bottom_right_address;
unsigned int idelay_top[4]; //ll,lr,rl,ll
unsigned int idelay_bottom[4]; //ll,lr,rl,ll
float high_voltage;
int* top_dac;
int* bottom_dac;
};
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top);
void Module_ModuleBottom(struct Module* mod,unsigned int number, unsigned int address_bottom);
void Module_Module1(struct Module* mod,unsigned int number, unsigned int address_top, unsigned int address_bottom);
unsigned int Module_GetModuleNumber(struct Module* mod);
int Module_TopAddressIsValid(struct Module* mod);
unsigned int Module_GetTopBaseAddress(struct Module* mod);
unsigned int Module_GetTopLeftAddress(struct Module* mod) ;
unsigned int Module_GetTopRightAddress(struct Module* mod);
unsigned int Module_GetBottomBaseAddress(struct Module* mod);
int Module_BottomAddressIsValid(struct Module* mod);
unsigned int Module_GetBottomLeftAddress(struct Module* mod);
unsigned int Module_GetBottomRightAddress(struct Module* mod);
unsigned int Module_SetTopIDelay(struct Module* mod,unsigned int chip,unsigned int value);
unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) ;
unsigned int Module_SetBottomIDelay(struct Module* mod,unsigned int chip,unsigned int value);
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip);
class FebControl:private FebInterface{
float Module_SetHighVoltage(struct Module* mod,float value);
float Module_GetHighVoltage(struct Module* mod);
private:
std::vector<Module*> modules;
void ClearModules();
unsigned int staticBits; //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
unsigned int acquireNReadoutMode; //safe or parallel, half or full speed
unsigned int triggerMode; //internal timer, external start, external window, signal polarity (external trigger and enable)
unsigned int externalEnableMode; //external enabling engaged and it's polarity
unsigned int subFrameMode;
unsigned int photon_energy_eV;
unsigned int nimages;
float exposure_time_in_sec;
float exposure_period_in_sec;
unsigned int trimbit_size;
unsigned char* last_downloaded_trimbits;
void PrintModuleList();
bool GetModuleIndex(unsigned int module_number, unsigned int& module_index);
bool CheckModuleAddresses(Module* m);
bool AddModule(unsigned int module_number, unsigned int top_address);
bool AddModule(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, bool half_module=0);
bool GetDACNumber(std::string s, unsigned int& n);
bool SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int& value);
bool VoltageToDAC(float value, unsigned int& digital, unsigned int nsteps, float vmin, float vmax);
float DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
bool SendHighVoltage(unsigned int module_index, float& value);
bool SendIDelays(unsigned int dst_num, bool chip_lr, unsigned int channels, unsigned int ndelay_units);
bool SetStaticBits();
bool SetStaticBits(unsigned int the_static_bits);
bool SendBitModeToBebServer();
unsigned int ConvertTimeToRegister(float time_in_sec);
unsigned int AddressToAll();
bool SetCommandRegister(unsigned int cmd);
bool GetDAQStatusRegister(unsigned int dst_address, unsigned int &ret_status);
bool StartDAQOnlyNWaitForFinish(int sleep_time_us=5000);
bool ResetChipCompletely();
struct sockaddr_in serv_addr;
bool SetupSendToSocket(const char* ip_address_hostname, unsigned short int port);
int WriteNRead(char* message, int length, int max_length);
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetTopDACValue(struct Module* mod,unsigned int i);
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
public:
FebControl();
virtual ~FebControl();
bool Init();
bool ReadSetUpFileToAddModules(std::string file_name);
bool ReadSetUpFile(unsigned int module_num, std::string file_name);
bool CheckSetup();
unsigned int GetNModules();
unsigned int GetNHalfModules();
bool SetHighVoltage(float value);
bool SetHighVoltage(unsigned int module_num,float value);
bool SetPhotonEnergy(unsigned int full_energy_eV);
unsigned int GetPhotonEnergy(){return photon_energy_eV;}
bool SetIDelays(unsigned int module_num, unsigned int ndelay_units);
bool SetIDelays(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
bool DecodeDACString(std::string dac_str, unsigned int& module_index, bool& top, bool& bottom, unsigned int& dac_ch);
bool SetDAC(std::string s, int value, bool is_a_voltage_mv=0);
bool GetDAC(std::string s, int& ret_value, bool voltage_mv=0);
bool GetDACName(unsigned int dac_num, std::string &s);
bool SetTrimbits(unsigned int module_num, unsigned char* trimbits);
unsigned char* GetTrimbits();
bool Reset();
bool StartAcquisition();
bool StopAcquisition();
bool AcquisitionInProgress();
bool WaitForFinishedFlag(int sleep_time_us=5000);
void Feb_Control_ClearModules();
void Feb_Control_PrintModuleList();
int Feb_Control_GetModuleIndex(unsigned int module_number, unsigned int* module_index);
int Feb_Control_CheckModuleAddresses(struct Module* m);
int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address);
/*int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module=0);*/
int Feb_Control_AddModule1(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module);
int Feb_Control_GetDACNumber(char* s, unsigned int* n);
int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int* value);
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
int Feb_Control_SendHighVoltage(unsigned int module_index, float* value);
int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units);
int Feb_Control_SetStaticBits();
int Feb_Control_SetStaticBits1(unsigned int the_static_bits);
int Feb_Control_SendBitModeToBebServer();
unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec);
unsigned int Feb_Control_AddressToAll();
int Feb_Control_SetCommandRegister(unsigned int cmd);
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status);
/*int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us=5000);*/
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us);
int Feb_Control_ResetChipCompletely();
struct sockaddr_in Feb_Control_serv_addr;
/*
int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port);
int Feb_Control_WriteNRead(char* message, int length, int max_length);
*/
void Feb_Control_FebControl();
int Feb_Control_Init();
int Feb_Control_ReadSetUpFileToAddModules(char* file_name);
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name);
int Feb_Control_CheckSetup();
unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(float value);
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value);
int Feb_Control_SetPhotonEnergy(unsigned int full_energy_eV);
unsigned int Feb_Control_GetPhotonEnergy();
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch);
/*int Feb_Control_SetDAC(string s, int value, int is_a_voltage_mv=0);*/
int Feb_Control_SetDAC(char* s, int value, int is_a_voltage_mv);
/* int Feb_Control_GetDAC(string s, int* ret_value, int voltage_mv=0);*/
int Feb_Control_GetDAC(char* s, int* ret_value, int voltage_mv);
int Feb_Control_GetDACName(unsigned int dac_num,char* s);
int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int* trimbits);
unsigned int* Feb_Control_GetTrimbits();
/**Added by Dhanya */
int Feb_Control_SaveAllTrimbitsTo(int value);
int Feb_Control_Reset();
int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition();
int Feb_Control_AcquisitionInProgress();
/*int Feb_Control_WaitForFinishedFlag(int sleep_time_us=5000);*/
int Feb_Control_WaitForFinishedFlag(int sleep_time_us);
//functions for setting up exposure
void PrintAcquisitionSetup();
bool SetNExposures(unsigned int n_images);
unsigned int GetNExposures();
bool SetExposureTime(float the_exposure_time_in_sec);
float GetExposureTime();
bool SetExposurePeriod(float the_exposure_period_in_sec);
float GetExposurePeriod();
bool SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
unsigned int GetDynamicRange();
bool SetReadoutSpeed(unsigned int readout_speed=0); //0->full,1->half,2->quarter or 3->super_slow
bool SetReadoutMode(unsigned int readout_mode=0); //0->parallel,1->non-parallel,2-> safe_mode
bool SetTriggerMode(unsigned int trigger_mode=0, bool polarity=1);
bool SetExternalEnableMode(bool use_external_enable=0, bool polarity=1);
void Feb_Control_PrintAcquisitionSetup();
int Feb_Control_SetNExposures(unsigned int n_images);
unsigned int Feb_Control_GetNExposures();
int Feb_Control_SetExposureTime(double the_exposure_time_in_sec);
double Feb_Control_GetExposureTime();
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec);
double Feb_Control_GetExposurePeriod();
int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
unsigned int Feb_Control_GetDynamicRange();
/*int Feb_Control_SetReadoutSpeed(unsigned int readout_speed=0); //0->full,1->half,2->quarter or 3->super_slow*/
int Feb_Control_SetReadoutSpeed(unsigned int readout_speed); //0->full,1->half,2->quarter or 3->super_slow
/* int Feb_Control_SetReadoutMode(unsigned int readout_mode=0); //0->parallel,1->non-parallel,2-> safe_mode*/
int Feb_Control_SetReadoutMode(unsigned int readout_mode); //0->parallel,1->non-parallel,2-> safe_mode
/* int Feb_Control_SetTriggerMode(unsigned int trigger_mode=0, int polarity=1);*/
int Feb_Control_SetTriggerMode(unsigned int trigger_mode, int polarity);
/*int Feb_Control_SetExternalEnableMode(int use_external_enable=0, int polarity=1);*/
int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity);
//functions for testing
bool SetTestModeVariable(bool on=1);
bool GetTestModeVariable();
/*int Feb_Control_SetTestModeVariable(int on=1);*/
int Feb_Control_SetTestModeVariable(int on);
int Feb_Control_GetTestModeVariable();
};
#endif

View File

@ -0,0 +1,205 @@
/**
* @author Ian Johnson
* @version 1.0
*/
//#include <iostream>
//#include <iomanip>
//#include <unistd.h>
//#include <string.h>
//#include <sys/mman.h>
//#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include "xparameters.h"
#include "FebInterface.h"
struct LocalLinkInterface ll_local,* ll;
unsigned int Feb_Interface_nfebs;
unsigned int* Feb_Interface_feb_numb;
int Feb_Interface_send_ndata;
unsigned int Feb_Interface_send_buffer_size;
unsigned int* Feb_Interface_send_data_raw;
unsigned int* Feb_Interface_send_data;
int Feb_Interface_recv_ndata;
unsigned int Feb_Interface_recv_buffer_size;
unsigned int* Feb_Interface_recv_data_raw;
unsigned int* Feb_Interface_recv_data;
void Feb_Interface_FebInterface(){
ll = &ll_local;
Feb_Interface_nfebs = 0;
Feb_Interface_feb_numb = 0;
Feb_Interface_send_ndata = 0;
Feb_Interface_send_buffer_size = 1026;
Feb_Interface_send_data_raw = malloc((Feb_Interface_send_buffer_size+1) * sizeof(unsigned int));
Feb_Interface_send_data = &Feb_Interface_send_data_raw[1];
Feb_Interface_recv_ndata = 0;
Feb_Interface_recv_buffer_size = 1026;
Feb_Interface_recv_data_raw = malloc((Feb_Interface_recv_buffer_size+1) * sizeof(unsigned int));
Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1];
Local_LocalLinkInterface1(ll,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
}
void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list){
unsigned int i;
if(Feb_Interface_feb_numb) free(Feb_Interface_feb_numb);
Feb_Interface_nfebs = n;
Feb_Interface_feb_numb = malloc(n * sizeof(unsigned int));
for(i=0;i<n;i++) Feb_Interface_feb_numb[i] = list[i];
}
int Feb_Interface_WriteTo(unsigned int ch){
if(ch>0xfff) return 0;
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if(Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_data_raw[0] = 0x90000000 | (ch<<16);
if(Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_data_raw[0] = 0xc0000000;
return ((Feb_Interface_send_ndata+1)*4==Local_Write(ll,(Feb_Interface_send_ndata+1)*4,Feb_Interface_send_data_raw));
}
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys){
unsigned int t;
if(ch>=0xfff) return 0;
Feb_Interface_recv_data_raw[0] = 0xa0000000 | (ch<<16);
Local_Write(ll,4,Feb_Interface_recv_data_raw);
usleep(20);
Feb_Interface_recv_ndata=-1;
for(t=0;t<ntrys;t++){
if((Feb_Interface_recv_ndata=Local_Read(ll,Feb_Interface_recv_buffer_size*4,Feb_Interface_recv_data_raw)/4)>0){
Feb_Interface_recv_ndata--;
break;
}
usleep(1000);
}
return (Feb_Interface_recv_ndata>=0);
}
int Feb_Interface_SetByteOrder(){
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if(Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_ndata = 2;
Feb_Interface_send_data[0] = 0;
Feb_Interface_send_data[1] = 0;
unsigned int i;
unsigned int dst = 0xff;
for(i=0;i<Feb_Interface_nfebs;i++) dst = (dst | Feb_Interface_feb_numb[i]);
int passed = Feb_Interface_WriteTo(dst);
return passed;
}
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read){
return Feb_Interface_ReadRegisters(sub_num,1,&reg_num,value_read);
}
int Feb_Interface_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read){
//here cout<<"Reading Register ...."<<endl;
unsigned int i;
nreads &= 0x3ff;
if(!nreads||nreads>Feb_Interface_send_buffer_size-2) return 0;
Feb_Interface_send_ndata = nreads+2;
Feb_Interface_send_data[0] = 0x20000000 | nreads << 14;
for(i=0;i<nreads;i++) Feb_Interface_send_data[i+1]=reg_nums[i];
Feb_Interface_send_data[nreads+1] = 0;
if(!Feb_Interface_WriteTo(sub_num)||!Feb_Interface_ReadFrom(sub_num,20)||Feb_Interface_recv_ndata!=(int)(nreads+2)) return 0;
for(i=0;i<nreads;i++) values_read[i] = Feb_Interface_recv_data[i+1];
return 1;
}
int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address){
return Feb_Interface_WriteRegisters(sub_num,1,&reg_num,&value,&wait_on,&wait_on_address);
}
int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses){
unsigned int i;
nwrites &= 0x3ff; //10 bits
if(!nwrites||2*nwrites>Feb_Interface_send_buffer_size-2) return 0;
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
Feb_Interface_send_ndata = 2*nwrites+2;
Feb_Interface_send_data[0] = 0x80000000 | nwrites << 14;
Feb_Interface_send_data[2*nwrites+1] = 0;
for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+1] = 0x3fff&reg_nums[i];
for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+2] = values[i];
// wait on busy data(28), address of busy flag data(27 downto 14)
if(wait_ons&&wait_on_addresses) for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
if(!Feb_Interface_WriteTo(sub_num)) return 0;
return 1;
}
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
unsigned int max_single_packet_size = 352;
int passed=1;
unsigned int n_to_send = max_single_packet_size;
unsigned int ndata_sent = 0;
unsigned int ndata_countdown = nwrites;
while(ndata_countdown>0){
n_to_send = ndata_countdown<max_single_packet_size ? ndata_countdown:max_single_packet_size;
if(!Feb_Interface_WriteMemory(sub_num,mem_num,start_address,n_to_send,&(values[ndata_sent]))){passed=0; break;}
ndata_countdown-=n_to_send;
ndata_sent +=n_to_send;
start_address +=n_to_send;
usleep(0);//500 works
}
return passed;
}
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
// -1 means write to all
unsigned int i;
mem_num &= 0x3f;
start_address &= 0x3fff;
nwrites &= 0x3ff;
if(!nwrites||nwrites>Feb_Interface_send_buffer_size-2) {printf("error herer: nwrites:%d\n",nwrites);return 0;}//*d-1026
Feb_Interface_send_ndata = nwrites+2;//*d-1026
Feb_Interface_send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
Feb_Interface_send_data[nwrites+1] = 0;
for(i=0;i<nwrites;i++) Feb_Interface_send_data[i+1] = values[i];
if(!Feb_Interface_WriteTo(sub_num)) return 0;
return 1;
}

View File

@ -158,9 +158,9 @@ bool FebInterface::WriteMemory(unsigned int sub_num, unsigned int mem_num, unsig
mem_num &= 0x3f;
start_address &= 0x3fff;
nwrites &= 0x3ff;
if(!nwrites||nwrites>send_buffer_size-2) return 0;
if(!nwrites||nwrites>send_buffer_size-2) {cout<<"error herer: nwrites:"<<nwrites<<endl;return 0;}//*d-1026
send_ndata = nwrites+2;
send_ndata = nwrites+2;//*d-1025
send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
send_data[nwrites+1] = 0;
for(unsigned int i=0;i<nwrites;i++) send_data[i+1] = values[i];

View File

@ -10,44 +10,34 @@
#include "LocalLinkInterface.h"
class FebInterface{ //
private:
LocalLinkInterface* ll;
int Feb_Interface_WriteTo(unsigned int ch);
/*int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys=20);*/
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys);
void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list);
int Feb_Interface_SetByteOrder();
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read);
int Feb_Interface_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
/*int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on=0, unsigned int wait_on_address=0);*/
int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address);
/*int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons=0, unsigned int* wait_on_addresses=0);*/
int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses);
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
unsigned int nfebs;
unsigned int* feb_numb;
int send_ndata;
unsigned int send_buffer_size;
unsigned int* send_data_raw;
unsigned int* send_data;
int recv_ndata;
unsigned int recv_buffer_size;
unsigned int* recv_data_raw;
unsigned int* recv_data;
bool WriteTo(unsigned int ch);
bool ReadFrom(unsigned int ch, unsigned int ntrys=20);
public:
FebInterface();
virtual ~FebInterface();
void SendCompleteList(unsigned int n,unsigned int* list);
bool SetByteOrder();
bool ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int& value_read);
bool ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
bool WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, bool wait_on=0, unsigned int wait_on_address=0);
bool WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, bool* wait_ons=0, unsigned int* wait_on_addresses=0);
bool WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
};
#endif

View File

@ -30,6 +30,8 @@ enum cmd_string {evNotFound,
evSetDACValue,evGetDACValue,evSetDACVoltage,evGetDACVoltage,evSetHighVoltage,//evGetHighVoltage,
evSetTrimBits,
evSetAllTrimBits,
evGetTrimBits,
//evLoadTrimBitFile,
evSetBitMode,
@ -63,6 +65,8 @@ void init(){
enum_map["getdacvoltage"] = evGetDACVoltage;
enum_map["sethighvoltage"] = evSetHighVoltage;
enum_map["settrimbits"] = evSetTrimBits;
enum_map["setalltrimbits"] = evSetAllTrimBits;
enum_map["gettrimbits"] = evGetTrimBits;
// enum_map["loadtrimbitfile"] = evLoadTrimBitFile;
enum_map["setbitmode"] = evSetBitMode;
enum_map["setphotonenergy"] = evSetPhotonEnergy;
@ -116,8 +120,8 @@ int main(int argc, char* argv[]){
if(!SetupListenSocket(port_number)) return 1;
int length=1000;
char data[1000];
int length=270000;
char data[270000];
int stop = 0;
time_t rawtime;
@ -126,13 +130,14 @@ int main(int argc, char* argv[]){
while(!stop){
cout<<endl<<"\n\n\n\nWaiting for command -> "<<flush;
/*cout<<"Waiting for command -> "<<flush;*/
int nread = AccpetConnectionAndWaitForData(data,length);
if(nread<=0) return 0;
time(&rawtime); timeinfo=localtime(&rawtime);
cout<<asctime(timeinfo);
cout<<" Command received: "<<data<<endl<<endl;
/*cout<<" Command received: "<<data<<endl;*/
@ -140,13 +145,15 @@ int main(int argc, char* argv[]){
float v[4];//,v2,v3,v4,v5;
int n[5];
string cmd = GetNextString(data,1);
int ret_val = 1;
string return_message = "\n\n\tCommand recieved: ";
string return_message = "";/*\n\n\tCommand recieved: ";
return_message.append(data);
return_message.append("\n");
*/
int return_start_pos;
while(cmd.length()>0){
int ret_parameter = 0;
@ -209,7 +216,7 @@ int main(int argc, char* argv[]){
tmp_str[0] = GetNextString(data);
if(tmp_str[0].length()>0&&feb_controler->GetDAC(tmp_str[0],ret_parameter)){
return_message.append("\tExecuted: GetDACValue "); return_message.append(tmp_str[0]+" -> ");AddNumber(return_message,ret_parameter); return_message.append(" mV\n");
return_message.append("\tExecuted: GetDACValue "); return_message.append(tmp_str[0]+" -> ");AddNumber(return_message,ret_parameter); return_message.append("\n");
ret_val = 0;
}else{
return_message.append("\tError executing: GetDACValue <dac_name>\n");
@ -257,16 +264,48 @@ int main(int argc, char* argv[]){
break;
case evSetTrimBits :
/*if(tmp_str[0].length()>0&&feb_controler->SetDynamicRange(n[0])){*/
feb_controler->SetTrimbits(0,(unsigned char*)data);
return_message.append("\tExecuted: SetTrimBits "); AddNumber(return_message,n[0]); return_message.append("\n");
ret_val = 0;
/*}else{
return_message.append("\tError executing: SetTrimBits \n");
ret_val = 1;
} */
tmp_str[0] = GetNextString(data);
if(feb_controler->LoadTrimbitFile()){
/* if(1){*/
/*tmp_str[0] = GetNextString(data);
feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));*/
return_message.append("\tExecuted: SetTrimBits\n");
ret_val = 0;
}else{
return_message.append("\tError executing: SetTrimBits \n");
ret_val = 1;
}
break;
case evSetAllTrimBits :
tmp_str[0] = GetNextString(data);
n[0] = atoi(tmp_str[0].data());
if(feb_controler->SaveAllTrimbitsTo(n[0])){
/*feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));*/
/*if(1){*/
return_message.append("\tExecuted: SetAllTrimBits\n");
ret_val = 0;
}else{
return_message.append("\tError executing: SetAllTrimBits \n");
ret_val = 1;
}
break;
case evGetTrimBits :
if(feb_controler->SaveTrimbitFile()){
/*if(1){*/
/*tmp_str[0] = GetNextString(data);
feb_controler->GetTrimbits();*/
return_message.append("\tExecuted: GetTrimBits\n");
ret_val = 0;
}else{
return_message.append("\tError executing: GetTrimBits \n");
ret_val = 1;
}
break;
// case evLoadTrimBitFile :
case evSetBitMode :
@ -455,11 +494,11 @@ int main(int argc, char* argv[]){
cmd = GetNextString(data);
}
return_message.append("\n\n\n");
/*return_message.append("\n\n\n");*/
AddNumber(return_message,ret_val,0,1);
cout<<return_message.c_str()<<endl;
cout<<"\treturn: "<<ret_val<<endl;
cout<<return_message.c_str()<<"\t\t";
cout<<"return: "<<ret_val<<endl;
if(!WriteNClose(return_message.c_str(),return_message.length())) return 0;
}

View File

@ -0,0 +1,87 @@
//Class initially from Gerd and was called mmap_test.c
//return reversed 1 means good, 0 means failed
//#include <stdio.h>
//#include <unistd.h>
//#include <string.h>
//#include <sys/mman.h>
//#include <fcntl.h>
#include "HardwareIO.h"
xfs_u8 HWIO_xfs_in8(xfs_u32 InAddress)
{
/* read the contents of the I/O location and then synchronize the I/O
* such that the I/O operation completes before proceeding on
*/
xfs_u8 IoContents;
__asm__ volatile ("eieio; lbz %0,0(%1)":"=r" (IoContents):"b"
(InAddress));
return IoContents;
}
/*****************************************************************************/
xfs_u16 HWIO_xfs_in16(xfs_u32 InAddress)
{
/* read the contents of the I/O location and then synchronize the I/O
* such that the I/O operation completes before proceeding on
*/
xfs_u16 IoContents;
__asm__ volatile ("eieio; lhz %0,0(%1)":"=r" (IoContents):"b"
(InAddress));
return IoContents;
}
/*****************************************************************************/
xfs_u32 HWIO_xfs_in32(xfs_u32 InAddress)
{
/* read the contents of the I/O location and then synchronize the I/O
* such that the I/O operation completes before proceeding on
*/
xfs_u32 IoContents;
__asm__ volatile ("eieio; lwz %0,0(%1)":"=r" (IoContents):"b"
(InAddress));
return IoContents;
}
/*****************************************************************************/
void HWIO_xfs_out8(xfs_u32 OutAddress, xfs_u8 Value)
{
/* write the contents of the I/O location and then synchronize the I/O
* such that the I/O operation completes before proceeding on
*/
__asm__ volatile ("stb %0,0(%1); eieio"::"r" (Value), "b"(OutAddress));
}
/*****************************************************************************/
void HWIO_xfs_out16(xfs_u32 OutAddress, xfs_u16 Value)
{
/* write the contents of the I/O location and then synchronize the I/O
* such that the I/O operation completes before proceeding on
*/
__asm__ volatile ("sth %0,0(%1); eieio"::"r" (Value), "b"(OutAddress));
}
/*****************************************************************************/
void HWIO_xfs_out32(xfs_u32 OutAddress, xfs_u32 Value)
{
/* write the contents of the I/O location and then synchronize the I/O
* such that the I/O operation completes before proceeding on
*/
__asm__ volatile ("stw %0,0(%1); eieio"::"r" (Value), "b"(OutAddress));
}

View File

@ -7,24 +7,20 @@
#include "xfs_types.h"
class HardwareIO{ //
protected:
xfs_u8 xfs_in8(xfs_u32 InAddress);
xfs_u16 xfs_in16(xfs_u32 InAddress);
xfs_u32 xfs_in32(xfs_u32 InAddress);
void xfs_out8(xfs_u32 OutAddress, xfs_u8 Value);
void xfs_out16(xfs_u32 OutAddress, xfs_u16 Value);
void xfs_out32(xfs_u32 OutAddress, xfs_u32 Value);
public:
HardwareIO(){};
virtual ~HardwareIO(){};
xfs_u8 HWIO_xfs_in8(xfs_u32 InAddress);
xfs_u16 HWIO_xfs_in16(xfs_u32 InAddress);
xfs_u32 HWIO_xfs_in32(xfs_u32 InAddress);
void HWIO_xfs_out8(xfs_u32 OutAddress, xfs_u8 Value);
void HWIO_xfs_out16(xfs_u32 OutAddress, xfs_u16 Value);
void HWIO_xfs_out32(xfs_u32 OutAddress, xfs_u32 Value);
};
#endif

View File

@ -0,0 +1,280 @@
//Class initially from Gerd and was called mmap_test.c
//return reversed 1 means good, 0 means failed
#include <stdio.h>
#include <unistd.h>
//#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "HardwareMMappingDefs.h"
#include "LocalLinkInterface.h"
Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr){
// printf("\n v 1 \n");
printf("Initialize PLB LL FIFOs\n");
ll->ll_fifo_base=0;
ll->ll_fifo_ctrl_reg=0;
if(Local_Init(ll,ll_fifo_badr)){
Local_Reset(ll);
printf("\tFIFO Status : 0x%08x\n",Local_StatusVector(ll));
}else printf("\tError LocalLink Mappping : 0x%08x\n",ll_fifo_badr);
printf("\n\n");
}
/*~LocalLinkInterface(){};*/
Local_LocalLinkInterface(struct LocalLinkInterface* ll){
printf("Initialize new memory\n");
}
int Local_InitNewMemory (struct LocalLinkInterface* ll,unsigned int addr, int ifg){
unsigned int CSP0BASE;
int fd;
/*fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) {
printf("\nCan't find /dev/mem!\n");
return 0;
}
printf("/dev/mem opened\n");
CSP0BASE = (u_int32_t)mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, addr);
if (CSP0BASE == (u_int32_t)MAP_FAILED) {
printf("\nCan't map memmory area!!\n");
return 0;
}
printf("CSP0 mapped\n");
volatile u_int8_t *ptr1;
ptr1=(u_int8_t*)(CSP0BASE);
printf("pointer val=%x\n",(void*)ptr1);
printf("ifg_control=%02x\n",*ptr1);
*ptr1=ifg;
printf("ifg_control new=%02x\n",*ptr1);
close(fd);
*/
return 1;
}
int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr){
int fd;
void *plb_ll_fifo_ptr;
if ((fd=open("/dev/mem", O_RDWR)) < 0){
fprintf(stderr, "Could not open /dev/mem\n");
return 0;
}
plb_ll_fifo_ptr = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, ll_fifo_badr);
close(fd);
if (plb_ll_fifo_ptr == MAP_FAILED){
perror ("mmap");
return 0;
}
ll->ll_fifo_base = (xfs_u32) plb_ll_fifo_ptr;
ll->ll_fifo_ctrl_reg = 0;
return 1;
}
int Local_Reset(struct LocalLinkInterface* ll){
return Local_Reset1(ll,PLB_LL_FIFO_CTRL_RESET_STD);
}
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask){
ll->ll_fifo_ctrl_reg |= rst_mask;
printf("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
ll->ll_fifo_ctrl_reg &= (~rst_mask);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
// printf("FIFO CTRL Address: 0x%08x\n FIFO CTRL Register: 0x%08x\n",PLB_LL_FIFO_REG_CTRL,plb_ll_fifo[PLB_LL_FIFO_REG_CTRL]);
return 1;
}
unsigned int Local_StatusVector(struct LocalLinkInterface* ll){
return HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
}
int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer){
// note: buffer must be word (4 byte) aligned
// frame_len in byte
int vacancy=0;
int i;
int words_send = 0;
int last_word;
unsigned int *word_ptr;
unsigned int fifo_ctrl;
xfs_u32 status;
if (buffer_len < 1) return -1;
last_word = (buffer_len-1)/4;
word_ptr = (unsigned int *)buffer;
while (words_send <= last_word)
{
while (!vacancy)//wait for Fifo to be empty again
{
status = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
if((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
}
//Just to know: #define PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS 100
for (i=0; ((i<PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS) && (words_send <= last_word)); i++)
{
fifo_ctrl = 0;
if (words_send == 0)
{
fifo_ctrl = PLB_LL_FIFO_CTRL_LL_SOF;//announce the start of file
}
if (words_send == last_word)
{
fifo_ctrl |= (PLB_LL_FIFO_CTRL_LL_EOF | (( (buffer_len-1)<<PLB_LL_FIFO_CTRL_LL_REM_SHIFT) & PLB_LL_FIFO_CTRL_LL_REM) );
}
Local_ctrl_reg_write_mask(ll,PLB_LL_FIFO_CTRL_LL_MASK,fifo_ctrl);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_FIFO,word_ptr[words_send++]);
}
}
return buffer_len;
}
int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer){
static unsigned int buffer_ptr = 0;
// note: buffer must be word (4 byte) aligned
// frame_len in byte
int len;
unsigned int *word_ptr;
unsigned int status;
volatile unsigned int fifo_val;
int sof = 0;
word_ptr = (unsigned int *)buffer;
do
{
status = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
if (!(status & PLB_LL_FIFO_STATUS_EMPTY))
{
if (status & PLB_LL_FIFO_STATUS_LL_SOF)
{
if (buffer_ptr)
{
buffer_ptr = 0;
return -1; // buffer overflow
}
// printf(">>>> SOF\n\r");
buffer_ptr = 0;
sof = 1;
}
fifo_val = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_FIFO); //read from fifo
if ((buffer_ptr > 0) || sof)
{
if ( (buffer_len >> 2) > buffer_ptr)
{
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
}
else
{
buffer_ptr = 0;
return -2; // buffer overflow
}
if (status & PLB_LL_FIFO_STATUS_LL_EOF)
{
len = (buffer_ptr << 2) -3 + ( (status & PLB_LL_FIFO_STATUS_LL_REM)>>PLB_LL_FIFO_STATUS_LL_REM_SHIFT );
// printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len);
buffer_ptr = 0;
return len;
}
}
}
}
while(!(status & PLB_LL_FIFO_STATUS_EMPTY));
return 0;
}
int Local_ctrl_reg_write_mask(struct LocalLinkInterface* ll,unsigned int mask, unsigned int val){
// printf("Fifo CTRL Reg(1): 0x%08x\n",plb_ll_fifo_ctrl_reg);
ll->ll_fifo_ctrl_reg &= (~mask);
//printf("Fifo CTRL Reg(2): 0x%08x\n",plb_ll_fifo_ctrl_reg);
ll->ll_fifo_ctrl_reg |= ( mask & val);
// printf("Fifo CTRL Reg: 0x%08x\n",plb_ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
// printf("Fifo STAT Reg: 0x%08x\n", plb_ll_fifo[PLB_LL_FIFO_REG_STATUS]);
return 1;
}
int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer){
int len;
unsigned int rec_buff_len = 4096;
unsigned int rec_buffer[4097];
Local_Write(ll,buffer_len,buffer);
usleep(10000);
do{
len = Local_Read(ll,rec_buff_len,rec_buffer);
printf("receive length: %i\n",len);
if (len > 0){
rec_buffer[len]=0;
printf((char*) rec_buffer);
printf("\n");
}
} while(len > 0);
printf("\n\n\n\n");
return 1;
}
void Local_llfifo_print_frame(struct LocalLinkInterface* ll,unsigned char* fbuff, int len){
int i;
printf("\n\r----Frame of len : %d Byte\n\r",len);
for(i=0;i<len;i++){
printf("0x%02x ",fbuff[i] );
if ((i&0xf) == 0x7) printf(" ");
if ((i&0xf) == 0xf) printf("\n\r");
}
printf("\n\r");
}

View File

@ -7,41 +7,44 @@
#include "xfs_types.h"
#include "HardwareIO.h"
class LocalLinkInterface: public HardwareIO{ //
/*class LocalLinkInterface: public HardwareIO{ //*/
private:
struct LocalLinkInterface{
xfs_u32 ll_fifo_base;
unsigned int ll_fifo_ctrl_reg;
};
bool Init(unsigned int ll_fifo_badr);
bool Reset(unsigned int rst_mask);
bool ctrl_reg_write_mask(unsigned int mask, unsigned int val);
void llfifo_print_frame(unsigned char* fbuff, int len);
public:
LocalLinkInterface(unsigned int ll_fifo_badr);
virtual ~LocalLinkInterface();
int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr);
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask);
unsigned int StatusVector();
bool Reset();
int Write(unsigned int buffer_len, void *buffer);
int Read(unsigned int buffer_len, void *buffer);
int Local_ctrl_reg_write_mask(struct LocalLinkInterface* ll,unsigned int mask, unsigned int val);
void Local_llfifo_print_frame(struct LocalLinkInterface* ll,unsigned char* fbuff, int len);
int Test(unsigned int buffer_len, void *buffer);
LocalLinkInterface();
int InitNewMemory (unsigned int addr, int ifg);
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr);
/* virtual ~LocalLinkInterface();*/
unsigned int Local_StatusVector(struct LocalLinkInterface* ll);
int Local_Reset(struct LocalLinkInterface* ll);
int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
void Local_LocalLinkInterface(struct LocalLinkInterface* ll);
int Local_InitNewMemory (struct LocalLinkInterface* ll,unsigned int addr, int ifg);
/*
bool FiFoReset(unsigned int numb);
int FiFoReset(unsigned int numb);
int FifoSend(unsigned int numb, unsigned int frame_len, void *buffer);
int FifoReceive(unsigned int numb, unsigned int frame_len, void *buffer);
int FifoTest(unsigned int numb,unsigned int send_len, char *send_str);
*/
};
#endif

10
slsDetectorSoftware/eigerDetectorServer/Makefile Normal file → Executable file
View File

@ -8,14 +8,14 @@ DESTDIR ?= bin
INSTMODE = 0777
SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c
SRC_CLNT2 = FebServer.cxx FebControl.cxx FebInterface.cxx LocalLinkInterface.cxx HardwareIO.cxx
SRC_CLNT3 = BebServer.cxx Beb.cxx LocalLinkInterface.cxx HardwareIO.cxx
SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c FebControl.c Beb.c HardwareIO.c LocalLinkInterface.c Feb.c FebInterface.c
#SRC_CLNT2 = FebServer.cxx FebControl.cxx FebInterface.cxx LocalLinkInterface.cxx HardwareIO.cxx
#SRC_CLNT3 = BebServer.cxx Beb.cxx LocalLinkInterface.cxx HardwareIO.cxx
OBJS = $(SRC_CLNT:.c=.o)
all: clean $(PROGS) feb_debug beb_debug
all: clean $(PROGS) #feb_debug beb_debug
boot: $(OBJS)

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/eigerDetectorServer
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/eigerDetectorServer
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
Revision: 75
Branch: separate_receiver
Repsitory UUID: c31619c88e5690230fcd389dc18f9139295c442c
Revision: 91
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 14
Last Changed Date: 2014-06-03 12:26:45 +0200
Last Changed Rev: 280
Last Changed Date: 2014-09-09 15:43:18 +0200

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/eigerDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
//#define SVNREV 0x14
#define SVNREPUUID "c31619c88e5690230fcd389dc18f9139295c442c"
//#define SVNREV 0x280
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "Maliakal_Dhanya"
#define SVNREV 0x14
#define SVNDATE 0x20140603
#define SVNREV 0x280
#define SVNDATE 0x20140909
//

View File

@ -6,13 +6,18 @@
#include <string.h>
#include "slsDetectorFunctionList.h"
#include "gitInfoEiger.h"
#include "EigerHighLevelFunctions.c"
#include "EigerBackEndFunctions.c"
/*#include "EigerHighLevelFunctions.c"
#include "EigerBackEndFunctions.c"*/
#include "FebControl.h"
#include "Beb.h"
enum detectorSettings thisSettings;
const char* dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};
//static const string dacNames[16] = {"Svp","Svn","Vtr","Vrf","Vrs","Vtgstv","Vcmp_ll","Vcmp_lr","Cal","Vcmp_rl","Vcmp_rr","Rxb_rb","Rxb_lb","Vcp","Vcn","Vis"};
sls_detector_module *detectorModules=NULL;
@ -22,12 +27,39 @@ dacs_t *detectorDacs=NULL;
dacs_t *detectorAdcs=NULL;
int eiger_highvoltage = 0;
int eiger_iodelay = 0;
int eiger_photonenergy = 0;
int eiger_dynamicrange = 0;
int eiger_readoutmode = 0;
int eiger_readoutspeed = 0;
int eiger_triggermode = 0;
int eiger_extgating = 0;
int eiger_extgatingpolarity = 0;
int eiger_nexposures = 1;
int eiger_ncycles = 1;
int send_to_ten_gig = 0;
int ndsts_in_use=32;
unsigned int nimages_per_request=1;
int on_dst=0;
int dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int default_dac_values[16] = {0,2000,2000,1250,700,1278,500,500,2000,500,500,550,550,100,1000,775};
int initDetector(){
int imod,i,n;
n = getNModBoard(1);
printf("This is the EIGER Server\n");
printf("This is the EIGER Server of revision %llx\n", getDetectorId(DETECTOR_SOFTWARE_VERSION));
//#ifdef VERBOSE
printf("Board is for %d half modules\n",n);
@ -70,12 +102,17 @@ int initDetector(){
sAdc=noneSelected;
*/
Feb_Interface_FebInterface();
Feb_Control_FebControl();
printf("FEb control constructor done\n");
Beb_Beb(-1);
printf("BEB constructor done\n");
//get dac values
int retval[2];
for(i=0;i<(detectorModules)->ndac;i++){
setDAC((enum detDacIndex)i,-1,(detectorModules)->module,0,retval);
(detectorModules)->dacs[i] = retval[0];
}
for(i=0;i<(detectorModules)->ndac;i++)
setDAC((enum detDacIndex)i,default_dac_values[i],(detectorModules)->module,0,retval);
/* initialize dynamic range etc. */
@ -83,7 +120,7 @@ int initDetector(){
//set number of frames to 1
setTimer(FRAME_NUMBER,1);
setTimer(ACQUISITION_TIME,1E9);
setTimer(ACQUISITION_TIME,1E9);
setTimer(FRAME_PERIOD,1E9);
setDynamicRange(16);
setThresholdEnergy(8000,0);
setReadOutFlags(PARALLEL);
@ -93,6 +130,7 @@ int initDetector(){
setTiming(AUTO_TIMING);
int enable[2] = {0,1};
setExternalGating(enable);//disable external gating
return 1;
}
@ -141,6 +179,7 @@ int64_t getDetectorId(enum idMode arg){
int getDetectorNumber(){
int res=0;
char hostname[100];
if (gethostname(hostname, sizeof hostname) == 0)
@ -159,8 +198,13 @@ int getDetectorNumber(){
pclose(sysFile);
sscanf(output,"%x",&res);
return res;
*/
/*
int res=0;
char hostname[100] = "beb000";
sscanf(hostname,"%x",&res);
return res;
*/
}
@ -220,8 +264,21 @@ int detectorTest( enum digitalTestMode arg){
void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){
if(ind == VTHRESHOLD){
setDAC(VCMP_LL,val,imod,mV,retval);
setDAC(VCMP_LR,val,imod,mV,retval);
setDAC(VCMP_RL,val,imod,mV,retval);
ind = VCMP_RR;
}
char iname[10];
strcpy(iname,EigerGetDACName((int)ind));
if(((int)ind>=0)&&((int)ind<NDAC))
strcpy(iname,dac_names[(int)ind]);
else{
printf("dac value outside range:%d\n",(int)ind);
strcpy(iname,dac_names[0]);
}
#ifdef VERBOSE
if(val >= 0)
printf("Setting dac %d: %s to %d ",ind, iname,val);
@ -233,9 +290,12 @@ void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){
printf("in dac units\n");
#endif
if(val >= 0)
EigerSetDAC(iname,val,mV);
retval[0] = EigerGetDAC(iname);
retval[1] = EigerGetDACmV(iname);
Feb_Control_SetDAC(iname,val,mV);
int k;
Feb_Control_GetDAC(iname, &k,0);
retval[0] = k;
Feb_Control_GetDAC(iname,&k,1);
retval[1] = k;
(detectorModules)->dacs[ind] = retval[0];
@ -245,9 +305,10 @@ void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){
int setHighVolage(int val, int imod){
if(val!=-1){
printf(" Setting High Voltage: %d\n",val);
EigerSetHighVoltage(val);
if(Feb_Control_SetHighVoltage(val))
eiger_highvoltage = val;
}
return EigerGetHighVoltage();
return eiger_highvoltage;
}
@ -260,29 +321,33 @@ int getADC(enum detDacIndex ind, int imod){
int setIODelay(int val, int imod){
if(val!=-1){
printf(" Setting IO Delay: %d\n",val);
EigerSetIODelay(val);
if(Feb_Control_SetIDelays(0,val))
eiger_iodelay = val;
}
return EigerGetIODelay();
return eiger_iodelay;
}
int enableTenGigabitEthernet(int val){
if(val!=-1){
if(val>0)
SetTenGigbaBitEthernet(1);
send_to_ten_gig = 1;
else
SetTenGigbaBitEthernet(0);
send_to_ten_gig = 0;
//configuremac called from client
}
return GetTenGigbaBitEthernet();
#ifdef VERBOSE
printf("10Gbe:%d\n",send_to_ten_gig);
#endif
return send_to_ten_gig;
}
int setModule(sls_detector_module myMod){
int retval[2];
#ifdef VERBOSE
//#ifdef VERBOSE
printf("Setting module with settings %d\n",myMod.reg);
#endif
//#endif
int i;
for(i=0;i<myMod.ndac;i++)
setDAC((enum detDacIndex)i,myMod.dacs[i],myMod.module,0,retval);
@ -291,17 +356,66 @@ int setModule(sls_detector_module myMod){
// thisSettings = (enum detectorSettings)myMod.reg;
// thisSettings = 0;
setSettings( (enum detectorSettings)myMod.reg); // put the settings in the module register?!?!?
/** set trimbits*/
if (detectorModules)
copyModule(detectorModules,&myMod);
setSettings( (enum detectorSettings)myMod.reg,-1); // put the settings in the module register?!?!?
//includ gap pixels
int offset = 0;
unsigned int tt[263680];
int iy,ichip,ix,ip=0,ich=0;
for(iy=0;iy<256;iy++) {
for (ichip=0; ichip<4; ichip++) {
for(ix=0;ix<256;ix++) {
tt[ip++]=myMod.chanregs[ich++];
}
if (ichip<3) {
tt[ip++]=0;
tt[ip++]=0;
}
}
}
Feb_Control_SetTrimbits(0,tt);
return 0;
}
int getModule(sls_detector_module *myMod){
int i;
int retval[2];
//dacs
for(i=0;i<NDAC;i++)
setDAC((enum detDacIndex)i,-1,-1,0,retval);
//trimbits
unsigned int* tt;
tt = Feb_Control_GetTrimbits();
//exclude gap pixels
int offset = 0;
int iy,ichip,ix,ip=0,ich=0;
for(iy=0;iy<256;iy++) {
for (ichip=0; ichip<4; ichip++) {
for(ix=0;ix<256;ix++) {
myMod->chanregs[ich++]=tt[ip++];
}
if (ichip<3) {
ip++;
ip++;
}
}
}
//copy to local copy as well
if (detectorModules)
copyModule(myMod,detectorModules);/*copyModule(myMod,detectorModules+iMod);*/
copyModule(myMod,detectorModules);
else
return FAIL;
return OK;
@ -314,14 +428,15 @@ int getModule(sls_detector_module *myMod){
int getThresholdEnergy(int imod){
printf(" Getting Threshold energy\n");
return EigerGetPhotonEnergy();
return eiger_photonenergy;
}
int setThresholdEnergy(int thr, int imod){
printf(" Setting threshold energy:%d\n",thr);
EigerSetPhotonEnergy(thr);
return EigerGetPhotonEnergy();
if(Feb_Control_SetPhotonEnergy(thr))
eiger_photonenergy = thr;
return getThresholdEnergy(imod);
}
@ -338,27 +453,61 @@ enum detectorSettings setSettings(enum detectorSettings sett, int imod){
int startStateMachine(){
printf("Going to start acquisition\n");
EigerStartAcquisition();
RequestImages();
return OK;
if(Feb_Control_StartAcquisition()){
//RequestImages();
int ret_val = 0;
dst_requested[0] = 1;
while(dst_requested[on_dst]){
//waits on data
if((ret_val = (!Beb_RequestNImages(0,1,send_to_ten_gig,on_dst,nimages_per_request,0)||
!Beb_RequestNImages(0,2,send_to_ten_gig,0x20|on_dst,nimages_per_request,0))))
break;
dst_requested[on_dst++]=0;
on_dst%=ndsts_in_use;
}
if(ret_val)
return FAIL;
else
return OK;
}
return FAIL;
}
int stopStateMachine(){
printf("Going to stop acquisition\n");
EigerStopAcquisition();
return OK;
if(Feb_Control_StopAcquisition())
return OK;
return FAIL;
}
int startReadOut(){
RequestImages();
//RequestImages();
int ret_val = 0;
dst_requested[0] = 1;
while(dst_requested[on_dst]){
//waits on data
if((ret_val = (!Beb_RequestNImages(0,1,send_to_ten_gig,on_dst,nimages_per_request,0)||
!Beb_RequestNImages(0,2,send_to_ten_gig,0x20|on_dst,nimages_per_request,0))))
break;
dst_requested[on_dst++]=0;
on_dst%=ndsts_in_use;
}
if(ret_val)
return FAIL;
else
return OK;
return OK;
}
enum runStatus getRunStatus(){
int i = EigerRunStatus();
int i = Feb_Control_AcquisitionInProgress();
if(i== 0){
printf("IDLE\n");
return IDLE;
@ -371,13 +520,8 @@ enum runStatus getRunStatus(){
char *readFrame(int *ret, char *mess){
EigerWaitForAcquisitionFinish();
/*
int i = EigerRunStatus();
while(i){
i = EigerRunStatus();
usleep(1000);
}*/
if(!Feb_Control_WaitForFinishedFlag(5000))
printf("error in waiting for finished flag\n");
*ret = (int)FINISHED;
return NULL;
}
@ -394,19 +538,27 @@ int64_t setTimer(enum timerIndex ind, int64_t val){
case FRAME_NUMBER:
if(val >= 0){
printf(" Setting number of frames: %d\n",(unsigned int)val);
EigerSetNumberOfExposures((unsigned int)val);
SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles());
}return EigerGetNumberOfExposures();
if(Feb_Control_SetNExposures((unsigned int)val)*eiger_ncycles){
eiger_nexposures = val;
//SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles());
on_dst = 0;
int i;
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
ndsts_in_use = 1;
nimages_per_request = eiger_nexposures * eiger_ncycles;
}
}return eiger_nexposures;
case ACQUISITION_TIME:
if(val >= 0){
printf(" Setting exp time: %fs\n",val/(1E9));
EigerSetExposureTime(val/(1E9));
}return (EigerGetExposureTime()*(1E9));
Feb_Control_SetExposureTime(val/(1E9));
}
return (Feb_Control_GetExposureTime()*(1E9));
case FRAME_PERIOD:
if(val >= 0){
printf(" Setting acq period: %fs\n",val/(1E9));
EigerSetExposurePeriod(val/(1E9));
}return (EigerGetExposurePeriod()*(1E9));
Feb_Control_SetExposurePeriod(val/(1E9));
}return (Feb_Control_GetExposurePeriod()*(1E9));
/* case DELAY_AFTER_TRIGGER:
if(val >= 0)
EigerSetNumberOfExposures((unsigned int)val);
@ -424,9 +576,15 @@ int64_t setTimer(enum timerIndex ind, int64_t val){
case CYCLES_NUMBER:
if(val >= 0){
printf(" Setting number of triggers: %d\n",(unsigned int)val);
EigerSetNumberOfCycles((unsigned int)val);
SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles());
}return EigerGetNumberOfCycles();
if(Feb_Control_SetNExposures((unsigned int)val*eiger_nexposures)){
eiger_ncycles = val;
//SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles());
on_dst = 0;
int i;
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
nimages_per_request = eiger_nexposures * eiger_ncycles;
}
}return eiger_ncycles;
default:
printf("unknown timer index: %d\n",ind);
break;
@ -446,18 +604,23 @@ int64_t getTimeLeft(enum timerIndex ind){
int setDynamicRange(int dr){
int r;
if(dr > 0){
printf(" Setting dynamic range: %d\n",dr);
EigerSetDynamicRange(dr);
EigerSetBitMode(dr);
if(Feb_Control_SetDynamicRange(dr)){
//EigerSetBitMode(dr);
on_dst = 0;
int i;
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
if(Beb_SetUpTransferParameters(dr))
eiger_dynamicrange = dr;
else printf("ERROR:Could not set bit mode in the back end\n");
}
}
//make sure back end and front end have the same bit mode
r= EigerGetDynamicRange();
if(r != EigerGetBitMode())
EigerSetBitMode(r);
dr= Feb_Control_GetDynamicRange();
return r;
return dr;
}
@ -472,9 +635,10 @@ enum readOutFlags setReadOutFlags(enum readOutFlags val){
default: val=0; break;
}
printf(" Setting Read out Flag: %d\n",val);
EigerSetReadoutMode(val);
if(Feb_Control_SetReadoutMode(val))
eiger_readoutmode = val;
}
switch(EigerGetReadoutMode()){
switch(eiger_readoutmode){
case 0: ret=PARALLEL; break;
case 1: ret=NONPARALLEL; break;
case 2: ret=SAFE; break;
@ -496,9 +660,10 @@ int setROI(int n, ROI arg[], int *retvalsize, int *ret){
int setSpeed(enum speedVariable arg, int val){
if(val != -1){
printf(" Setting Read out Speed: %d\n",val);
EigerSetReadoutSpeed(val);
if(Feb_Control_SetReadoutSpeed(val))
eiger_readoutspeed = val;
}
return EigerGetReadoutSpeed();
return eiger_readoutspeed;
}
@ -508,10 +673,59 @@ int executeTrimming(enum trimMode mode, int par1, int par2, int imod){
}
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int ival){
EigerSetupTableEntryLeft(ipad, macad, detectormacadd, detipad, udpport);
EigerSetupTableEntryRight(ipad, macad, detectormacadd, detipad, udpport);
SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles());
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int udpport2, int ival){
char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50];
int src_port = 0xE185;
int dst_port = udpport;
sprintf(src_ip,"%d.%d.%d.%d",(detipad>>24)&0xff,(detipad>>16)&0xff,(detipad>>8)&0xff,(detipad)&0xff);
sprintf(dst_ip,"%d.%d.%d.%d",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff);
sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((detectormacadd>>40)&0xFF),
(unsigned int)((detectormacadd>>32)&0xFF),
(unsigned int)((detectormacadd>>24)&0xFF),
(unsigned int)((detectormacadd>>16)&0xFF),
(unsigned int)((detectormacadd>>8)&0xFF),
(unsigned int)((detectormacadd>>0)&0xFF));
sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((macad>>40)&0xFF),
(unsigned int)((macad>>32)&0xFF),
(unsigned int)((macad>>24)&0xFF),
(unsigned int)((macad>>16)&0xFF),
(unsigned int)((macad>>8)&0xFF),
(unsigned int)((macad>>0)&0xFF));
printf("src_port:%d\n",src_port);
printf("dst_port:%d\n",dst_port);
printf("src_ip:%s\n",src_ip);
printf("dst_ip:%s\n",dst_ip);
printf("src_mac:%s\n",src_mac);
printf("dst_mac:%s\n\n",dst_mac);
int beb_num = 34;
int header_number = 0;
int i=0;
/* for(i=0;i<32;i++){/** modified for Aldo*/
if(Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) &&
Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port))
printf("set up left ok\n");
else return -1;
/*}*/
header_number = 32;
dst_port = udpport2;
/*for(i=0;i<32;i++){*//** modified for Aldo*/
if(Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) &&
Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port))
printf("set up right ok\n");
else return -1;
/*}*/
on_dst = 0;
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
nimages_per_request=eiger_nexposures * eiger_ncycles;
return 0;
}
@ -598,6 +812,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){
}
int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();};//NCHIP*NCHAN*nModBoard;}
int getTotalNumberOfChips(){return 4;};//NCHIP*nModBoard;}
int getTotalNumberOfModules(){return 1;}//nModBoard;}
@ -640,10 +855,11 @@ enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
case GATE_FIX_NUMBER: ret = 3; break;
}
printf(" Setting Triggering Mode: %d\n",(int)ret);
EigerSetTriggerMode(ret);
if(Feb_Control_SetTriggerMode(ret,1))
eiger_triggermode = ret;
}
ret = EigerGetTriggerMode();
ret = eiger_triggermode;
switch((int)ret){
case 0: ret = AUTO_TIMING; break;
case 2: ret = TRIGGER_EXPOSURE; break;
@ -658,10 +874,13 @@ enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
void setExternalGating(int enable[]){
if(enable>=0)
EigerSetExternalGating(enable[0], enable[1]);//enable = 0 or 1, polarity = 0 or 1 , where 1 is positive
enable[0] = EigerGetExternalGatingPolarity();
enable[1] = EigerGetExternalGating();
if(enable>=0){
Feb_Control_SetExternalEnableMode(enable[0], enable[1]);//enable = 0 or 1, polarity = 0 or 1 , where 1 is positive
eiger_extgating = enable[0];
eiger_extgatingpolarity = enable[1];
}
enable[0] = eiger_extgating;
enable[1] = eiger_extgatingpolarity;
}
@ -675,6 +894,22 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg){
return NO_SYNCHRONIZATION;
}
void setAllTrimbits(int val){
int ichan;
if(Feb_Control_SaveAllTrimbitsTo(val)){
#ifdef VERBOSE
printf("Copying register %x value %d\n",destMod->reg,val);
#endif
if (detectorModules){
for (ichan=0; ichan<(detectorModules->nchan); ichan++) {
*((detectorModules->chanregs)+ichan)=val;
}
}
}else printf("error in setting all trimbits to value\n");
}
int getAllTrimbits(){
return *((detectorModules->chanregs));
}
#endif

View File

@ -35,6 +35,6 @@
#define DYNAMIC_RANGE 16
enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS};
enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD};
#endif /* SLSDETECTORSERVER_DEFS_H_ */

View File

@ -1,6 +1,8 @@
#ifndef __XFS_TYPES_H__
#define __XFS_TYPES_H__
//#include "types.h"
#include <stdint.h>
/******************************************************************************/
/* types */
/******************************************************************************/
@ -15,33 +17,33 @@ typedef signed char xfs_i8;
// UDP Header
typedef struct
struct udp_header_type
{
// ethternet frame (14 byte)
unsigned char dst_mac[6];
unsigned char src_mac[6];
unsigned char len_type[2];
uint8_t dst_mac[6];
uint8_t src_mac[6];
uint8_t len_type[2];
// ip header (20 byte)
unsigned char ver_headerlen[1];
unsigned char service_type[1];
unsigned char total_length[2];
unsigned char identification[2];
unsigned char flags[1];
unsigned char frag_offset[1];
unsigned char time_to_live[1];
unsigned char protocol[1];
unsigned char ip_header_checksum[2];
unsigned char src_ip[4];
unsigned char dst_ip[4];
uint8_t ver_headerlen[1];
uint8_t service_type[1];
uint8_t total_length[2];
uint8_t identification[2];
uint8_t flags[1];
uint8_t frag_offset[1];
uint8_t time_to_live[1];
uint8_t protocol[1];
uint8_t ip_header_checksum[2];
uint8_t src_ip[4];
uint8_t dst_ip[4];
// udp header (8 byte)
unsigned char src_port[2];
unsigned char dst_port[2];
unsigned char udp_message_len[2];
unsigned char udp_checksum[2];
uint8_t src_port[2];
uint8_t dst_port[2];
uint8_t udp_message_len[2];
uint8_t udp_checksum[2];
} udp_header_type;
};

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
Revision: 833
Branch: separate_receiver
Repsitory UUID: c31619c88e5690230fcd389dc18f9139295c442c
Revision: 852
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 833
Last Changed Date: 2014-06-03 12:26:45 +0200
Last Changed Rev: 852
Last Changed Date: 2014-09-09 15:43:18 +0200

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/gotthardDetectorServer
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/gotthardDetectorServer
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
Revision: 169
Branch: separate_receiver
Repsitory UUID: c31619c88e5690230fcd389dc18f9139295c442c
Revision: 173
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 14
Last Changed Date: 2014-06-03 12:26:45 +0200
Last Changed Rev: 280
Last Changed Date: 2014-09-09 15:43:18 +0200

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/gotthardDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
//#define SVNREV 0x14
#define SVNREPUUID "c31619c88e5690230fcd389dc18f9139295c442c"
//#define SVNREV 0x280
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "Maliakal_Dhanya"
#define SVNREV 0x14
#define SVNDATE 0x20140603
#define SVNREV 0x280
#define SVNDATE 0x20140909
//

View File

@ -1012,7 +1012,7 @@ int set_dac(int file_des) {
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret!=FAIL) {
/* send return argument */
n += sendDataOnly(file_des,&retval,sizeof(retval));
n += sendDataOnly(file_des,retval,sizeof(retval));
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
}
@ -2547,7 +2547,7 @@ int update_client(int file_des) {
int configure_mac(int file_des) {
int ret=OK;
char arg[5][50];
char arg[6][50];
int n;
int imod=0;//should be in future sent from client as -1, arg[2]
@ -2572,7 +2572,7 @@ int configure_mac(int file_des) {
sscanf(arg[2], "%x", &udpport);
sscanf(arg[3], "%llx", &idetectormacadd);
sscanf(arg[4], "%x", &detipad);
//arg[5] is udpport2 for eiger
#ifdef VERBOSE
int i;
printf("\ndigital_test_bit in server %d\t",digitalTestBit);

View File

@ -51,7 +51,6 @@ int masterMode=NO_MASTER, syncMode=NO_SYNCHRONIZATION, timingMode=AUTO_TIMING;
enum externalSignalFlag signals[4]={EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF};
int withGotthard = 0;
#ifdef MCB_FUNCS
extern const int nChans;
@ -286,10 +285,7 @@ int cleanFifo(){
printf("Cleaning FIFO\n");
addr=ADC_SYNC_REG;
if(withGotthard)
adc_sync = GOTTHARD_ADCSYNC_VAL;
else
adc_sync = ADCSYNC_VAL;
adc_sync = ADCSYNC_VAL;
reg = bus_r(addr) & CLEAN_FIFO_MASK;
@ -1404,19 +1400,7 @@ int setADC(int adc){
setDAQRegister();//token timing
cleanFifo();//adc sync
//with gotthard module
if(withGotthard){
//set packet size
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask
nchips = GOTTHARDNCHIP;
nchans = GOTTHARDNCHAN;
mask = ACTIVE_ADC_MASK;
}
//with moench module all adc
else{/* if(adc==-1){*/
/* if(adc==-1){*/
//set packet size
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
@ -1424,7 +1408,7 @@ int setADC(int adc){
nchips = NCHIP;
nchans = NCHANS;
mask = ACTIVE_ADC_MASK;
}/*
/*
//with moench module 1 adc -- NOT IMPLEMENTED
else{
ipPacketSize= ADC1_IP_PACKETSIZE;

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/moenchDetectorServer
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/moenchDetectorServer
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
Revision: 55
Branch: separate_receiver
Repsitory UUID: c31619c88e5690230fcd389dc18f9139295c442c
Revision: 58
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 14
Last Changed Date: 2014-06-03 12:26:45 +0200
Last Changed Rev: 280
Last Changed Date: 2014-09-09 15:43:18 +0200

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/moenchDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
//#define SVNREV 0x14
#define SVNREPUUID "c31619c88e5690230fcd389dc18f9139295c442c"
//#define SVNREV 0x280
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "Maliakal_Dhanya"
#define SVNREV 0x14
#define SVNDATE 0x20140603
#define SVNREV 0x280
#define SVNDATE 0x20140909
//

View File

@ -513,7 +513,6 @@ int set_one_dac(int imod) {
bit=value & (1<<(15-ibit));
if (bit) {
putout("0000010001000000",imod);
putout("0000011001000000",imod);
putout("0000010001000000",imod);
#ifdef DEBUGOUT
fprintf(stdout,"1");
@ -551,15 +550,15 @@ int initDACbyIndex(int ind,int val, int imod) {
int ref=partref[ind];
int r1=partr1[ind];
int r2=partr2[ind];
int retval[2];
v=(val+(val-ref)*r1/r2)*DAC_DR/DAC_MAX;
v=initDACbyIndexDACU(ind,v,imod);
v=initDACbyIndexDACU(ind,v,imod,0,retval);
return (v*DAC_MAX/DAC_DR+ref*r1/r2)/(1+r1/r2);
}
int initDACbyIndexDACU(int ind, int val, int imod) {
int initDACbyIndexDACU(int ind, int val, int imod, int mV, int retval[]) {
// const double daccs[NDAC]=DACCS;
// const double dacaddr[NDAC]=DACADDR;
@ -568,6 +567,8 @@ int initDACbyIndexDACU(int ind, int val, int imod) {
// int addr=dacaddr[ind];
// int iv;
int im;
if(mV)
val = (val*4096)/2500;
if (val>=0)
initDAC(ind,val, imod);
@ -598,124 +599,12 @@ int initDACbyIndexDACU(int ind, int val, int imod) {
#ifdef VERBOSE
printf("returning %d\n",setDACRegister(ind, -1, 0));
#endif
return setDACRegister(ind, -1, 0);
retval[0] = setDACRegister(ind, -1, 0);
retval[1] = (retval[0]*2500)/4096;
return retval[0];
}
}
int getThresholdEnergy() {
double g[3]=DEFAULTGAIN;
double o[3]=DEFAULTOFFSET;
double myg=-1, myo=-1;
// int dacu;
int imod;
int ethr=-1;
int ret=FAIL;
if (detectorModules) {
// for (imod=0; imod<getNModBoard(); imod++) {
for (imod=0; imod<nModX; imod++) {
#ifdef VERBOSE
printf("module=%d settings=%d, gain=%f, offset=%f\n",imod,thisSettings, (detectorModules+imod)->gain,(detectorModules+imod)->offset);
#endif
if ((detectorModules+imod)->gain>0)
myg=(detectorModules+imod)->gain;
else {
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
// else
//myg=-1;
}
if ((detectorModules+imod)->offset>0)
myo=(detectorModules+imod)->offset;
else {
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
// else
//myo=-1;
}
if (myg>0 && myo>0) {
//ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg;
ethr=(myo-setDACRegister(VDAC0,-1,imod))*1000/myg;//edited by dhanya
// else
// ethr=-1;
}
#ifdef VERBOSE
//printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]);
printf("module=%d gain=%f, offset=%f, dacu=%d\n",imod, myg, myo,(int)(setDACRegister(VDAC0,-1,imod)));//edited by dhanya
printf("Threshold energy of module %d is %d eV\n", imod, ethr);
#endif
if (imod==0)
ret=ethr;
else {
if (ethr>(ret+100) || ethr<(ret-100))
return FAIL;
}
}
}
return ret;
}
int setThresholdEnergy(int ethr) {
double g[3]=DEFAULTGAIN;
double o[3]=DEFAULTOFFSET;
double myg=-1, myo=-1;
int dacu;
int imod;
int ret=ethr;
setSettings(GET_SETTINGS,-1);//-1 added by dhanya
if (thisSettings>=0 || thisSettings<3){
myg=g[thisSettings];
myo=o[thisSettings];
}
for (imod=0; imod<nModX; imod++) {
if (detectorModules) {
if ((detectorModules+imod)->gain>0)
myg=(detectorModules+imod)->gain;
else
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
else
myg=-1;
if ((detectorModules+imod)->offset>0)
myo=(detectorModules+imod)->offset;
else
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
else
myo=-1;
} else {
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
else
myo=-1;
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
else
myg=-1;
}
if (myg>0 && myo>0) {
dacu=myo-myg*((double)ethr)/1000.;
#ifdef VERBOSE
printf("module %d (%x): gain %f, off %f, energy %d eV, dac %d\n",imod,(unsigned int)((detectorModules+imod)),(detectorModules+imod)->gain,(detectorModules+imod)->offset, ethr,dacu);
#endif
} else {
dacu=ethr;
#ifdef VERBOSE
printf("could not set threshold energy for module %d, settings %d (offset is %f; gain is %f)\n",imod,thisSettings,myo,myg);
#endif
}
initDACbyIndexDACU(VDAC0, dacu, imod); ///needs to be fixed dhanya
}
return ret;
}
int getDACbyIndexDACU(int ind, int imod) {
/*
@ -2585,19 +2474,9 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret){
int i,adc;
ROI temp;
/*
if(n>=0){
//clear rois
for(i=0;i<MAX_ROIS;i++)
rois[i]=temp;
/*ideal way to set roi
for(i=0;i<n;i++)
rois[i]=arg[i];
nROI = n;
*/
if(n==0)
adc=-1;
else{
@ -2633,7 +2512,7 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret){
//set adc of interest
setADC(adc);
}
}*/
//#ifdef VERBOSE
printf("Rois:\n");

View File

@ -109,10 +109,9 @@ int initDAC(int dac_addr, int value,int imod );
int initDACs(int* v,int imod );
int setSettings(int i,int imod);
int initDACbyIndex(int ind,int val, int imod);
int initDACbyIndexDACU(int ind,int val, int imod);
int initDACbyIndexDACU(int ind,int val, int imod, int mV, int retval[]);
int getDACbyIndexDACU(int ind, int imod);
int getThresholdEnergy();
int setThresholdEnergy(int ethr);
/* Other DAC index routines*/
int getTemperatureByModule(int tempSensor, int imod);

View File

@ -25,7 +25,6 @@ int main(int argc, char *argv[])
int retval=OK;
int sd, fd;
int iarg;
int checkType = 1;
for(iarg=1; iarg<argc; iarg++){
@ -40,20 +39,6 @@ int main(int argc, char *argv[])
return 1;
}
}
else if(!strcasecmp(argv[iarg],"-test")){
if(argc==iarg+1){
printf("No test condition given. Exiting.\n");
return 1;
}
if(!strcasecmp(argv[iarg+1],"with_gotthard")){
checkType = 0;
}else{
printf("could not decode test condition. Possible arguments: with_gotthard. Exiting\n");
return 1;
}
}
}
@ -71,10 +56,7 @@ int main(int argc, char *argv[])
//control server
else {
portno = DEFAULT_PORTNO;
if(checkType)
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
else
sprintf(cmd,"%s %d stopserver -test with_gotthard &",argv[0],DEFAULT_PORTNO+1);
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
printf("\n\nControl Server\nOpening control server on port %d\n",portno );
//printf("\n\ncmd:%s\n",cmd);
@ -83,7 +65,7 @@ int main(int argc, char *argv[])
}
init_detector(b, checkType);
init_detector(b);
sd=bindSocket(portno);

View File

@ -16,9 +16,7 @@
#define NDAC 8
#define NADC 1
/**when moench readout tested with gotthard module*/
#define GOTTHARDNCHAN 128
#define GOTTHARDNCHIP 10

View File

@ -54,10 +54,8 @@ char mess[1000];
int digitalTestBit = 0;
extern int withGotthard;
int init_detector(int b, int checkType) {
int init_detector(int b) {
if (mapCSP0()==FAIL) { printf("Could not map memory\n");
exit(1);
}
@ -69,21 +67,13 @@ int init_detector(int b, int checkType) {
//confirm if it is really moench
if(((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) != MOENCH_MODULE ){
if(checkType){
printf("This is a Gotthard detector. Exiting Moench Server.\n\n");
exit(-1);
}
//no check required as specified in command line arguments
else if(b){
printf("***This is a GOTTHARD detector with %d chips per module***\n",GOTTHARDNCHIP);
printf("***Assuming this to be a MOENCH detector***\n");
}
withGotthard = 1;
} else if(b){
printf("***This is a MOENCH detector with %d chips per module***\n",NCHIP);
printf("This is a Gotthard detector. Exiting Moench Server.\n\n");
exit(-1);
}
if (b) {
printf("***This is a MOENCH detector with %d chips per module***\n",NCHIP);
#ifdef MCB_FUNCS
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
initDetector();
@ -914,13 +904,15 @@ int read_register(int file_des) {
int set_dac(int file_des) {
//default:all mods
int retval;
int retval[2];retval[1]=-1;
int temp;
int ret=OK;
int arg[3];
enum dacIndex ind;
int imod;
int n;
int val;
int mV;
int idac=0;
sprintf(mess,"Can't set DAC\n");
@ -932,6 +924,7 @@ int set_dac(int file_des) {
}
ind=arg[0];
imod=arg[1];
mV=arg[2];
n = receiveDataOnly(file_des,&val,sizeof(val));
if (n < 0) {
@ -990,45 +983,50 @@ int set_dac(int file_des) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if(idac==HIGH_VOLTAGE)
retval=initHighVoltageByModule(val,imod);
else
retval=initDACbyIndexDACU(idac,val,imod);
if(idac==HIGH_VOLTAGE){
retval[0]=initHighVoltageByModule(val,imod);
ret=FAIL;
if(retval[0]==-2)
strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200");
else if(retval[0]==-3)
strcpy(mess,"Weird value read back or it has not been set yet\n");
else
ret=OK;
}else{
initDACbyIndexDACU(idac,val,imod,mV,retval);
ret=FAIL;
if(mV)
temp = retval[1];
else
temp = retval[0];
if ((abs(temp-val)<=3) || val==-1) {
ret=OK;
#ifdef VERBOSE
printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]);
#endif
}
}
}
}
if(ret==OK){
ret=FAIL;
if(idac==HIGH_VOLTAGE){
if(retval==-2)
strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200");
else if(retval==-3)
strcpy(mess,"Weird value read back or it has not been set yet\n");
else
ret=OK;
}//since v r saving only msb
else if ((retval-val)<=3 || val==-1)
ret=OK;
}
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, temp);
else{
if (differentClients)
ret=FORCE_UPDATE;
}
/* send answer */
/* send OK/failed */
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret!=FAIL) {
/* send return argument */
n += sendDataOnly(file_des,&retval,sizeof(retval));
n += sendDataOnly(file_des,retval,sizeof(retval));
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
}
@ -1610,7 +1608,7 @@ int get_threshold_energy(int file_des) {
n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/
return OK;
return ret;
}
@ -1631,7 +1629,7 @@ int set_threshold_energy(int file_des) {
n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/
return OK;
return ret;
}
@ -2631,7 +2629,7 @@ int update_client(int file_des) {
int configure_mac(int file_des) {
int ret=OK;
char arg[5][50];
char arg[6][50];
int n;
int imod=0;//should be in future sent from client as -1, arg[2]
@ -2656,7 +2654,7 @@ int configure_mac(int file_des) {
sscanf(arg[2], "%x", &udpport);
sscanf(arg[3], "%llx", &idetectormacadd);
sscanf(arg[4], "%x", &detipad);
//arg[5] is for eiger
#ifdef VERBOSE
int i;
printf("\ndigital_test_bit in server %d\t",digitalTestBit);

View File

@ -23,7 +23,7 @@ int sockfd;
int function_table();
int decode_function(int);
int init_detector(int,int);
int init_detector(int);
int M_nofunc(int);
int exit_server(int);

View File

@ -351,56 +351,71 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
void multiSlsDetector::updateOffsets(){
int offsetX=0,offsetY=0,numX,numY;
int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X];
int maxChanY = thisMultiDetector->maxNumberOfChannelsPerDetector[Y];
cout << "Updating multi detector offsets" << endl;
thisMultiDetector->numberOfChannel[X] = 0;
thisMultiDetector->maxNumberOfChannel[X] = 0;
thisMultiDetector->numberOfChannel[Y] = 0;
thisMultiDetector->maxNumberOfChannel[Y] = 0;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
thisMultiDetector->offsetX[i] = offsetX;
thisMultiDetector->offsetY[i] = offsetY;
cout << endl << "Updating multi detector offsets" << endl;
cout << "Detector at position: " << i << " x offset:" << offsetX << " y offset:" << offsetY << endl;
int offsetX=0, offsetY=0, numX=0, numY=0, maxX=0, maxY=0;
int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X];
int maxChanY = thisMultiDetector->maxNumberOfChannelsPerDetector[Y];
thisMultiDetector->numberOfChannel[X] = 0;
thisMultiDetector->maxNumberOfChannel[X] = 0;
thisMultiDetector->numberOfChannel[Y] = 0;
thisMultiDetector->maxNumberOfChannel[Y] = 0;
numX = detectors[i]->getMaxNumberOfChannels(X);
numY = detectors[i]->getMaxNumberOfChannels(Y);
//0th position
if (detectors[0]){
offsetX = thisMultiDetector->offsetX[0] = 0;
offsetY = thisMultiDetector->offsetY[0] = 0;
numX = thisMultiDetector->numberOfChannel[X] = detectors[0]->getTotalNumberOfChannels(X);
numY = thisMultiDetector->numberOfChannel[Y] = detectors[0]->getTotalNumberOfChannels(Y);
maxX = thisMultiDetector->maxNumberOfChannel[X] = detectors[0]->getMaxNumberOfChannels(X);
maxY = thisMultiDetector->maxNumberOfChannel[Y] = detectors[0]->getMaxNumberOfChannels(Y);
offsetX += numX;
if ((maxChanX == -1) || ((maxChanX > 0) && (offsetX < maxChanX))){
thisMultiDetector->numberOfChannel[X] += detectors[i]->getTotalNumberOfChannels(X);
thisMultiDetector->maxNumberOfChannel[X] += numX;
//the first time y should be added but offset not increased
if (thisMultiDetector->numberOfChannel[Y] == 0){
if ((maxChanY == -1) || ((maxChanY > 0) && (numY < maxChanY))){
thisMultiDetector->numberOfChannel[Y] += detectors[i]->getTotalNumberOfChannels(Y);
thisMultiDetector->maxNumberOfChannel[Y] += numY;
}else{
cout<<"Detector at position " << i << "exceeds maximum channels allowed for complete detector set in y dimension also!" << endl;
thisMultiDetector->numberOfChannel[Y] += detectors[i]->getTotalNumberOfChannels(Y);
thisMultiDetector->maxNumberOfChannel[Y] += numY;
}
}
}else{
offsetX = 0;
thisMultiDetector->numberOfChannel[X] = 0;
thisMultiDetector->maxNumberOfChannel[X] = 0;
offsetY += numY;
if ((maxChanY == -1) || ((maxChanY > 0) && (offsetY < maxChanY))){
thisMultiDetector->numberOfChannel[Y] += detectors[i]->getTotalNumberOfChannels(Y);
thisMultiDetector->maxNumberOfChannel[Y] += numY;
}else{
cout<<"Detector at position " << i << "exceeds maximum channels allowed for complete detector set in y dimension also!" << endl;
thisMultiDetector->numberOfChannel[Y] += detectors[i]->getTotalNumberOfChannels(Y);
thisMultiDetector->maxNumberOfChannel[Y] += numY;
}
}
}
}
cout << "Detector at position 0: x offset:" << offsetX << " y offset:" << offsetY << endl;
}
for (int i=1; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
//incrementing in x direction
if ((maxChanX == -1) || ((maxChanX > 0) && ((offsetX + numX) < maxChanX))){
offsetX += detectors[i]->getMaxNumberOfChannels(X);
maxX += detectors[i]->getMaxNumberOfChannels(X);
numX += detectors[i]->getTotalNumberOfChannels(X);
}
//incrementing in y direction
else{
offsetX = 0;
numX = 0;
maxX = 0;
thisMultiDetector->maxNumberOfChannel[X] = 0;
offsetY += detectors[i]->getMaxNumberOfChannels(Y);
if ((maxChanY == -1) || ((maxChanY > 0) && (offsetY <= maxChanY))){
numY += detectors[i]->getTotalNumberOfChannels(Y);
maxY += detectors[i]->getMaxNumberOfChannels(Y);
}else{
cout<<"Detector at position " << i << "exceeds maximum channels allowed for complete detector set in y dimension also!" << endl;
numY += detectors[i]->getTotalNumberOfChannels(Y);
maxY += detectors[i]->getMaxNumberOfChannels(Y);
}
}
thisMultiDetector->offsetX[i] = offsetX;
thisMultiDetector->offsetY[i] = offsetY;
cout << "Detector at position: " << i << " x offset:" << thisMultiDetector->offsetX[i] << " y offset:" << thisMultiDetector->offsetY[i] << endl;
if(numX > thisMultiDetector->numberOfChannel[X])
thisMultiDetector->numberOfChannel[X] = numX;
if(numY > thisMultiDetector->numberOfChannel[Y])
thisMultiDetector->numberOfChannel[Y] = numY;
if(maxX > thisMultiDetector->maxNumberOfChannel[X])
thisMultiDetector->maxNumberOfChannel[X] = maxX;
if(maxY > thisMultiDetector->maxNumberOfChannel[Y])
thisMultiDetector->maxNumberOfChannel[Y] = maxY;
}
}
cout << "Number of Channels in X direction:" << thisMultiDetector->numberOfChannel[X] << endl;
cout << "Number of Channels in Y direction:" << thisMultiDetector->numberOfChannel[Y] << endl << endl;
}
string multiSlsDetector::setHostname(const char* name, int pos){
@ -1182,6 +1197,16 @@ int multiSlsDetector::startAcquisition(){
int i=0;
int ret=OK, ret1=OK;
if (detectors[0]) {
ret=detectors[0]->startAcquisition();
if(detectors[0]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret!=OK)
ret1=FAIL;
}
/*
for (i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (i!=thisMultiDetector->masterPosition)
if (detectors[i]) {
@ -1201,7 +1226,7 @@ int multiSlsDetector::startAcquisition(){
if (ret!=OK)
ret1=FAIL;
}
}
}*/
return ret1;
};
@ -1213,6 +1238,8 @@ int multiSlsDetector::stopAcquisition(){
int i=0;
int ret=OK, ret1=OK;
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
@ -3474,11 +3501,13 @@ int multiSlsDetector::getMaxMods() {
int multiSlsDetector::getTotalNumberOfChannels(){thisMultiDetector->numberOfChannels=0; for (int id=0; id< thisMultiDetector->numberOfDetectors; id++) thisMultiDetector->numberOfChannels+=detectors[id]->getTotalNumberOfChannels(); return thisMultiDetector->numberOfChannels;};
int multiSlsDetector::getTotalNumberOfChannels(dimension d){thisMultiDetector->numberOfChannel[d]=0; for (int id=0; id< thisMultiDetector->numberOfDetectors; id++) thisMultiDetector->numberOfChannel[d]+=detectors[id]->getTotalNumberOfChannels(d); return thisMultiDetector->numberOfChannel[d];};
//int multiSlsDetector::getTotalNumberOfChannels(dimension d){thisMultiDetector->numberOfChannel[d]=0; for (int id=0; id< thisMultiDetector->numberOfDetectors; id++) thisMultiDetector->numberOfChannel[d]+=detectors[id]->getTotalNumberOfChannels(d); return thisMultiDetector->numberOfChannel[d];};
int multiSlsDetector::getTotalNumberOfChannels(dimension d){updateOffsets();return thisMultiDetector->numberOfChannel[d];};
int multiSlsDetector::getMaxNumberOfChannels(){thisMultiDetector->maxNumberOfChannels=0; for (int id=0; id< thisMultiDetector->numberOfDetectors; id++) thisMultiDetector->maxNumberOfChannels+=detectors[id]->getMaxNumberOfChannels();return thisMultiDetector->maxNumberOfChannels;};
int multiSlsDetector::getMaxNumberOfChannels(dimension d){thisMultiDetector->maxNumberOfChannel[d]=0; for (int id=0; id< thisMultiDetector->numberOfDetectors; id++) thisMultiDetector->maxNumberOfChannel[d]+=detectors[id]->getMaxNumberOfChannels(d);return thisMultiDetector->maxNumberOfChannel[d];};
// int multiSlsDetector::getMaxNumberOfChannels(dimension d){thisMultiDetector->maxNumberOfChannel[d]=0; for (int id=0; id< thisMultiDetector->numberOfDetectors; id++) thisMultiDetector->maxNumberOfChannel[d]+=detectors[id]->getMaxNumberOfChannels(d);return thisMultiDetector->maxNumberOfChannel[d];};
int multiSlsDetector::getMaxNumberOfChannels(dimension d){updateOffsets();return thisMultiDetector->maxNumberOfChannel[d];};
@ -3721,6 +3750,36 @@ int multiSlsDetector::saveSettingsFile(string fname, int imod) {
int multiSlsDetector::setAllTrimbits(int val, int imod){
int ret=-100, ret1,id, im;
if (decodeNMod(imod, id, im)>=0) {
if (detectors[id]) {
ret1=detectors[id]->setAllTrimbits(val,im);
if(detectors[id]->getErrorMask())
setErrorMask(getErrorMask()|(1<<id));
}
}
else if (imod<0) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setAllTrimbits(val,imod);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
}
}
return ret;
}
int multiSlsDetector::loadCalibrationFile(string fname, int imod) {
int id, im, ret;
@ -4390,7 +4449,7 @@ slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout(){
}
}
*stoppedFlag=1;
/**stoppedFlag=1;*/
return s;
}

View File

@ -474,6 +474,14 @@ class multiSlsDetector : public slsDetectorUtils {
int saveSettingsFile(string fname, int nmod=0);
/** sets all the trimbits to a particular value
\param val trimbit value
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
int setAllTrimbits(int val, int imod=-1);
/** loads the modules calibration data reading from a file - file name extension is automatically generated! */
int loadCalibrationFile(string fname, int nmod=0);

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/mythenDetectorServer
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/mythenDetectorServer
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
Revision: 87
Branch: separate_receiver
Repsitory UUID: c31619c88e5690230fcd389dc18f9139295c442c
Revision: 90
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 14
Last Changed Date: 2014-06-03 12:26:45 +0200
Last Changed Rev: 280
Last Changed Date: 2014-09-09 15:43:18 +0200

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/mythenDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
//#define SVNREV 0x14
#define SVNREPUUID "c31619c88e5690230fcd389dc18f9139295c442c"
//#define SVNREV 0x280
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "Maliakal_Dhanya"
#define SVNREV 0x14
#define SVNDATE 0x20140603
#define SVNREV 0x280
#define SVNDATE 0x20140909
//

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURLLIB "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git"
//#define SVNREPPATH ""
#define SVNREPUUIDLIB "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
//#define SVNREV 0x833
#define SVNREPUUIDLIB "c31619c88e5690230fcd389dc18f9139295c442c"
//#define SVNREV 0x852
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTHLIB "Maliakal_Dhanya"
#define SVNREVLIB 0x833
#define SVNDATELIB 0x20140603
#define SVNREVLIB 0x852
#define SVNDATELIB 0x20140909
//

View File

@ -488,6 +488,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->receiverTCPPort=DEFAULT_PORTNO+2;
/** set receiver udp port */
thisDetector->receiverUDPPort=DEFAULT_UDP_PORTNO;
/** set receiver udp port for Eiger */
thisDetector->receiverUDPPort2=DEFAULT_UDP_PORTNO+1;
/** set receiver ip address/hostname */
strcpy(thisDetector->receiver_hostname,"none");
/** set receiver udp ip address */
@ -3561,9 +3563,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
if (t>=0)
thisDetector->timerValue[index]=t;
}
//#ifdef VERBOSE
#ifdef VERBOSE
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
//#endif
#endif
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
setDynamicRange();
@ -4838,6 +4840,15 @@ char* slsDetector::setNetworkParameter(networkParameter index, string value) {
sscanf(value.c_str(),"%d",&i);
setReceiverUDPPort(i);
return getReceiverUDPPort();
case RECEIVER_UDP_PORT2:
sscanf(value.c_str(),"%d",&i);
if(thisDetector->myDetectorType == EIGER)
setReceiverUDPPort2(i);
else
setReceiverUDPPort(i);
if(thisDetector->myDetectorType == EIGER)
return getReceiverUDPPort2();
return getReceiverUDPPort();
default:
return ("unknown network parameter");
}
@ -4867,6 +4878,9 @@ char* slsDetector::getNetworkParameter(networkParameter index) {
case RECEIVER_UDP_PORT:
return getReceiverUDPPort();
break;
case RECEIVER_UDP_PORT2:
return getReceiverUDPPort2();
break;
default:
return ("unknown network parameter");
}
@ -5012,14 +5026,17 @@ int slsDetector::setReceiverUDPPort(int udpport){
return thisDetector->receiverUDPPort;
}
int slsDetector::setReceiverUDPPort2(int udpport){
thisDetector->receiverUDPPort2 = udpport;
return thisDetector->receiverUDPPort2;
}
int slsDetector::setUDPConnection(){
int ret = FAIL;
int fnum = F_SETUP_RECEIVER_UDP;
char args[2][MAX_STR_LENGTH];
char args[3][MAX_STR_LENGTH];
char retval[MAX_STR_LENGTH]="";
@ -5043,9 +5060,11 @@ int slsDetector::setUDPConnection(){
//copy arguments to args[][]
strcpy(args[0],thisDetector->receiverUDPIP);
sprintf(args[1],"%d",thisDetector->receiverUDPPort);
sprintf(args[2],"%d",thisDetector->receiverUDPPort2);
#ifdef VERBOSE
std::cout << "Receiver udp ip address: " << thisDetector->receiverUDPIP << std::endl;
std::cout << "Receiver udp port: " << thisDetector->receiverUDPPort << std::endl;
std::cout << "Receiver udp port2: " << thisDetector->receiverUDPPort2 << std::endl;
#endif
//set up receiver for UDP Connection and get receivermac address
@ -5084,7 +5103,7 @@ int slsDetector::configureMAC(){
int ret=FAIL;
int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME;
char mess[100];
char arg[5][50];
char arg[6][50];
char cword[50]="", *pcword;
string sword;
int retval=-1;
@ -5112,6 +5131,7 @@ int slsDetector::configureMAC(){
sprintf(arg[2],"%x",thisDetector->receiverUDPPort);
strcpy(arg[3],thisDetector->detectorMAC);
strcpy(arg[4],thisDetector->detectorIP);
sprintf(arg[5],"%x",thisDetector->receiverUDPPort2);
#ifdef VERBOSE
std::cout<< "Configuring MAC"<< std::endl;
@ -5174,6 +5194,9 @@ int slsDetector::configureMAC(){
#ifdef VERBOSE
std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl;
#endif
#ifdef VERBOSE
std::cout<<"receiver udp port2:"<<arg[5]<<"."<<std::endl;
#endif
//send to server
if (thisDetector->onlineFlag==ONLINE_FLAG) {
@ -5680,8 +5703,8 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
myMod=readSettingsFile(fn, thisDetector->myDetectorType);
if (myMod) {
myMod->module=im;
//settings is saved in myMod.reg for gotthard or moench
if((thisDetector->myDetectorType==GOTTHARD)||(thisDetector->myDetectorType==MOENCH))
//settings is saved in myMod.reg for all except mythen
if(thisDetector->myDetectorType!=MYTHEN)
myMod->reg=thisDetector->currentSettings;
setModule(*myMod);
deleteModule(myMod);
@ -5719,6 +5742,41 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
int slsDetector::setAllTrimbits(int val, int imod){
int fnum=F_SET_ALL_TRIMBITS;
int retval;
char mess[100];
int ret=OK;
#ifdef VERBOSE
std::cout<< "Setting all trimbits to "<< val << std::endl;
#endif
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&val,sizeof(val));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET));
} else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
}
controlSocket->Disconnect();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
#ifdef VERBOSE
std::cout<< "All trimbits were set to "<< retval << std::endl;
#endif
return retval;
}
int slsDetector::loadCalibrationFile(string fname, int imod) {

View File

@ -240,6 +240,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int receiverTCPPort;
/** is the port used to communicate between detector and the receiver*/
int receiverUDPPort;
/** is the port used to communicate between second half module of Eiger detector and the receiver*/
int receiverUDPPort2;
/** ip address of the receiver for the detector to send packets to**/
char receiverUDPIP[MAX_STR_LENGTH];
/** mac address of receiver for the detector to send packets to **/
@ -510,6 +512,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
int saveSettingsFile(string fname, int imod=-1);
/** sets all the trimbits to a particular value
\param val trimbit value
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
int setAllTrimbits(int val, int imod=-1);
/** loads the modules calibration data reading from a file
\param fname file name . If not specified, extension is automatically generated!
@ -1596,6 +1605,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
char* getReceiverUDPMAC() {return thisDetector->receiverUDPMAC;};
/** returns the receiver UDP IP address \sa sharedSlsDetector */
char* getReceiverUDPPort() {char *c= new char[MAX_STR_LENGTH];sprintf(c,"%d",thisDetector->receiverUDPPort); return c;};
/** returns the receiver UDP2 for Eiger IP address \sa sharedSlsDetector */
char* getReceiverUDPPort2() {char *c= new char[MAX_STR_LENGTH];sprintf(c,"%d",thisDetector->receiverUDPPort2); return c;};
/** validates the format of detector MAC address and sets it \sa sharedSlsDetector */
char* setDetectorMAC(string detectorMAC);
@ -1609,6 +1620,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
char* setReceiverUDPMAC(string udpmac);
/** sets the receiver udp port \sa sharedSlsDetector */
int setReceiverUDPPort(int udpport);
/** sets the receiver udp port2 for Eiger \sa sharedSlsDetector */
int setReceiverUDPPort2(int udpport);
/** Sets the read receiver frequency
if Receiver read upon gui request, readRxrFrequency=0,

View File

@ -427,7 +427,10 @@ int slsDetectorActions::executeScan(int level, int istep) {
break;
case trimbitsScan:
trimbit=(int)currentScanVariable[level];
setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan
if(getDetectorsType() == EIGER)
setAllTrimbits(trimbit);
else
setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan
break;
case positionScan:
//check if channels are connected!

View File

@ -197,6 +197,18 @@ class slsDetectorActions : public virtual slsDetectorBase
*/
virtual dacs_t setDAC(dacs_t val, dacIndex index , int mV, int imod=-1)=0;
/** sets all the trimbits to a particular value
\param val trimbit value
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
virtual int setAllTrimbits(int val, int imod=-1)=0;
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type
*/
virtual detectorType getDetectorsType(int pos=-1)=0;
virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0;
virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0;

View File

@ -344,6 +344,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++;
descrToFuncMap[i].m_pFuncName="rx_udpport2"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++;
descrToFuncMap[i].m_pFuncName="detectormac"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++;
@ -497,6 +501,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
i++;
descrToFuncMap[i].m_pFuncName="trimval"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
i++;
descrToFuncMap[i].m_pFuncName="pedestal"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
@ -2461,6 +2468,12 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
if (!(sscanf(args[1],"%d",&i)))
return ("cannot parse argument") + string(args[1]);
}
} else if (cmd=="rx_udpport2") {
t=RECEIVER_UDP_PORT2;
if (action==PUT_ACTION){
if (!(sscanf(args[1],"%d",&i)))
return ("cannot parse argument") + string(args[1]);
}
} else return ("unknown network parameter")+cmd;
if (action==PUT_ACTION)
@ -2482,6 +2495,7 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti
os << "rx_udpip ip \n sets receiver udp ip to ip"<< std::endl;
os << "rx_udpmac mac \n sets receiver udp mac to mac"<< std::endl;
os << "rx_udpport port \n sets receiver udp port to port"<< std::endl;
os << "rx_udpport2 port \n sets receiver udp port to port. For Eiger, it is the second half module and for other detectors, same as rx_udpport"<< std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "detectormac \n gets detector mac "<< std::endl;
@ -2489,6 +2503,8 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti
os << "rx_hostname \n gets receiver ip "<< std::endl;
os << "rx_udpmac \n gets receiver udp mac "<< std::endl;
os << "rx_udpport \n gets receiver udp port "<< std::endl;
os << "rx_udpport2 \n gets receiver udp port. For Eiger, it is the second half module and for other detectors, same as rx_udpport"<< std::endl;
}
return os.str();
@ -2912,6 +2928,15 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
myDet->saveSettingsFile(sval, -1);
return string("done");
} else if (cmd=="trimval") {
if (action==PUT_ACTION){
if (sscanf(args[1],"%d",&val))
myDet->setAllTrimbits(val);
else
return string("invalid trimbit value ")+cmd;
}
sprintf(ans,"%d",myDet->setAllTrimbits(-1));
return ans;
} else if (cmd=="pedestal") {
if (action==GET_ACTION)
return string("cannot get");
@ -2935,6 +2960,7 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) {
os << "threshold eV\n sets the detector threshold in eV"<< std::endl;
os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl;
os << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl;
os << "trimval i \n sets all the trimbits to i" << std::endl;
os << "pedestal i \n starts acquisition for i frames, calculates pedestal and writes back to fpga."<< std::endl;
}
@ -2942,6 +2968,7 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) {
os << "settings \n gets the settings of the detector"<< std::endl;
os << "threshold V\n gets the detector threshold"<< std::endl;
os << "trimbits [fname]\n returns the trimfile loaded on the detector. If fname is specified the trimbits are saved to file. If no extension is specified, the serial number of each module will be attached."<< std::endl;
os << "trimval \n returns the value all trimbits are set to. If they are different, returns -1." << std::endl;
}
return os.str();

View File

@ -490,6 +490,14 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/
virtual int saveSettingsFile(string fname, int imod=-1)=0;
/** sets all the trimbits to a particular value
\param val trimbit value
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
virtual int setAllTrimbits(int val, int imod=-1)=0;
/**

View File

@ -241,7 +241,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
case EIGER:
infile.open(myfname.c_str(),ifstream::binary);
if (infile.is_open()) {
infile.read((char*) myMod->dacs,sizeof(int)*(myMod->ndac));
infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
#ifdef VERBOSE
for(int i=0;i<myMod->ndac;i++)
@ -381,7 +381,7 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
for(int i=0;i<mod.ndac;i++)
std::cout << "dac " << i << ":" << mod.dacs[i] << std::endl;
#endif
outfile.write((char*)mod.dacs, sizeof(int)*(mod.ndac));
outfile.write((char*)mod.dacs, sizeof(dacs_t)*(mod.ndac));
outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan));
outfile.close();

View File

@ -461,7 +461,7 @@ void* postProcessing::processData(int delflag) {
*/
int progress = 0;
int progress = -1;
char currentfName[MAX_STR_LENGTH]="";
int currentfIndex = -1;
bool newData = false;
@ -502,6 +502,7 @@ void* postProcessing::processData(int delflag) {
if (dataReady){
//for random reads, ask only if it has new data
if(!newData){
if(currentfIndex > progress)
@ -525,13 +526,12 @@ void* postProcessing::processData(int delflag) {
currentfIndex = -1;
cout<<"****Detector Data returned is NULL***"<<endl;
}
if(nthframe){
/*if(nthframe){
if((currentfIndex == -1) || (currentfIndex == progress))
currentfIndex = -1;
else
progress = currentfIndex;
}
}*/
//not garbage frame
if (currentfIndex >= 0) {

View File

@ -95,7 +95,7 @@ int executeTrimming(enum trimMode mode, int par1, int par2, int imod);
#ifndef MYTHEND
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int ival);
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int udpport2, int ival);
#endif
#ifdef GOTTHARDD
@ -128,6 +128,8 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg);
#ifdef EIGERD
void setExternalGating(int enable[]);
void setAllTrimbits(int val);
int getAllTrimbits();
#endif

View File

@ -24,14 +24,16 @@ int main(int argc, char *argv[]){
int sd, fd;
#ifdef STOP_SERVER
char cmd[100];
if (argc==1) {
#endif
if (argc==1) {
//#endif
portno = DEFAULT_PORTNO;
printf("opening control server on port %d\n",portno );
b=1;
#ifdef STOP_SERVER
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
system(cmd);
#endif
} else {
portno = DEFAULT_PORTNO+1;
if ( sscanf(argv[1],"%d",&portno) ==0) {
@ -41,7 +43,7 @@ int main(int argc, char *argv[]){
printf("opening stop server on port %d\n",portno);
b=0;
}
#endif
//#endif
init_detector(b); //defined in slsDetectorServer_funcs

View File

@ -52,6 +52,12 @@ int init_detector(int b) {
#ifdef SLS_DETECTOR_FUNCTION_LIST
initDetector();
#endif
}else{
Feb_Interface_FebInterface();
Feb_Control_FebControl();
printf("FEb control constructor done\n");
/* Beb_Beb(-1);
printf("BEB constructor done\n");*/
}
strcpy(mess,"dummy message");
strcpy(lastClientIP,"none");
@ -157,7 +163,7 @@ int function_table() {
flist[F_STOP_RECEIVER]=&stop_receiver;
flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal;
flist[F_ENABLE_TEN_GIGA]=&enable_ten_giga;
flist[F_SET_ALL_TRIMBITS]=&set_all_trimbits;
#ifdef VERBOSE
@ -1116,6 +1122,12 @@ int set_dac(int file_des) {
break;
#endif
#ifdef EIGERD
case TRIMBIT_SIZE:
idac = VTR;
break;
case THRESHOLD:
idac = VTHRESHOLD;
break;
case E_SvP:
idac = SVP;
break;
@ -1970,8 +1982,9 @@ int set_settings(int file_des) {
}
imod=arg[1];
isett=arg[0];
printf("isett:%d, imod =%d\n",isett,imod);
#ifdef VERBOSE
printf("In set_settings, isett:%d, imod =%d\n",isett,imod);
#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (imod>=getTotalNumberOfModules()) {
ret=FAIL;
@ -2262,11 +2275,11 @@ int get_run_status(int file_des) {
enum runStatus s;
sprintf(mess,"getting run status\n");
#ifdef VERBOSE
//#ifdef VERBOSE
printf("Getting status\n");
#endif
//#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
s= getRunStatus();
s= getRunStatus();printf("status:%d\n");
#endif
if (ret!=OK) {
@ -2452,6 +2465,7 @@ int set_timer(int file_des) {
sprintf(mess, "could not allocate RAM for %lld frames\n", tns);
}
#endif
if (differentClients)
ret=FORCE_UPDATE;
}
@ -2709,6 +2723,7 @@ int set_roi(int file_des) {
#ifndef GOTTHARDD
ret = FAIL;
strcpy(mess,"Not applicable/implemented for this detector\n");
printf("Error:Set ROI-%s",mess);
#else
#ifdef VERBOSE
printf("Setting ROI to:");
@ -2948,11 +2963,11 @@ int execute_trimming(int file_des) {
int configure_mac(int file_des) {
int configure_mac(int file_des) {printf("in hereeeeee\n");
int retval=-100;
int ret=OK,ret1=OK;
char arg[5][50];
char arg[6][50];
int n;
#ifndef MYTHEND
@ -2961,9 +2976,10 @@ int configure_mac(int file_des) {
long long int imacadd;
long long int idetectormacadd;
int udpport;
int udpport2;
int detipad;
#endif
printf("111\n");
sprintf(mess,"Can't configure MAC\n");
n = receiveData(file_des,arg,sizeof(arg),OTHER);
@ -2971,7 +2987,7 @@ int configure_mac(int file_des) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
printf("222\n");
#ifdef MYTHEND
ret = FAIL;
strcpy(mess,"Not applicable/implemented for this detector\n");
@ -2981,7 +2997,7 @@ int configure_mac(int file_des) {
sscanf(arg[2], "%x", &udpport);
sscanf(arg[3], "%llx", &idetectormacadd);
sscanf(arg[4], "%x", &detipad);
sscanf(arg[5], "%x", &udpport2);
#ifdef SLS_DETECTOR_FUNCTION_LIST
@ -2991,7 +3007,8 @@ int configure_mac(int file_des) {
printf("mess:%s\n",mess);
}
#endif
#ifdef VERBOSE
printf("333\n");
//#ifdef VERBOSE
int i;
/*printf("\ndigital_test_bit in server %d\t",digitalTestBit);for gotthard*/
printf("\nipadd %x\t",ipad);
@ -3004,21 +3021,24 @@ int configure_mac(int file_des) {
for (i=0;i<6;i++)
printf("detector mac adress %d is 0x%x \n",6-i,(unsigned int)(((idetectormacadd>>(8*i))&0xFF)));
printf("detipad %x\n",detipad);
printf("udp port2:0x%x\n",udpport2);
printf("\n");
printf("Configuring MAC of module %d at port %x\n", imod, udpport);
#endif
printf("ret:%d\n",ret);
//#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (ret==OK) {
if(getRunStatus() == RUNNING)
if(getRunStatus() == RUNNING){
stopStateMachine();
retval=configureMAC(ipad,imacadd,idetectormacadd,detipad,udpport,0); /*digitalTestBit);*/
}
retval=configureMAC(ipad,imacadd,idetectormacadd,detipad,udpport,udpport2,0); /*digitalTestBit);*/
if(retval==-1) ret=FAIL;
}
#endif
#ifdef VERBOSE
//#ifdef VERBOSE
printf("Configured MAC with retval %d\n", retval);
#endif
//#endif
if (ret==FAIL) {
printf("configuring MAC of mod %d failed\n", imod);
}
@ -3396,9 +3416,9 @@ int enable_ten_giga(int file_des) {
}
/* execute action */
if(ret != FAIL){
//#ifdef VERBOSE
#ifdef VERBOSE
printf("Enabling 10Gbe :%d \n",arg);
//#endif
#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
retval=enableTenGigabitEthernet(arg);
if((arg != -1) && (retval != arg))
@ -3420,3 +3440,60 @@ int enable_ten_giga(int file_des) {
/*return ok/fail*/
return ret;
}
int set_all_trimbits(int file_des){
int retval;
int arg;
int n;
int ret=OK,ret1=OK;
sprintf(mess,"can't set sll trimbits\n");
n = receiveData(file_des,&arg,sizeof(arg),INT32);
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
#ifdef VERBOSE
printf("setting all trimbits to %d\n",arg);
#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else {
if(arg < -1){
ret = FAIL;
strcpy(mess,"Cant set trimbits to this value\n");
}else {
if(arg >= 0)
setAllTrimbits(arg);
retval = getAllTrimbits();
}
}
#endif
if (ret==OK) {
if (arg!=-1 && arg!=retval) {
ret=FAIL;
sprintf(mess,"Could not set all trimbits: should be %d but is %d\n", arg, retval);
}else if (differentClients)
ret=FORCE_UPDATE;
}
//ret could be swapped during sendData
ret1 = ret;
n = sendData(file_des,&ret1,sizeof(ret),INT32);
if (ret==FAIL) {
n = sendData(file_des,mess,sizeof(mess),OTHER);
} else {
n = sendData(file_des,&retval,sizeof(retval),INT32);
}
return ret;
}

View File

@ -81,5 +81,6 @@ int start_receiver(int);
int stop_receiver(int);
int calibrate_pedestal(int);
int enable_ten_giga(int);
int set_all_trimbits(int);
#endif

View File

@ -40,8 +40,8 @@ int receiverInterface::sendString(int fnum, char retval[], char arg[]){
int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[2][MAX_STR_LENGTH]){
char args[2][MAX_STR_LENGTH];
int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[3][MAX_STR_LENGTH]){
char args[3][MAX_STR_LENGTH];
int ret = slsDetectorDefs::FAIL;
char mess[100] = "";

View File

@ -56,7 +56,7 @@ public:
* @param arg value to send
* \returns success of operation
*/
int sendUDPDetails(int fnum, char retval[], char arg[2][MAX_STR_LENGTH]);
int sendUDPDetails(int fnum, char retval[], char arg[3][MAX_STR_LENGTH]);
/**