diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c index 312c9182e..1765f4662 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c @@ -1,6 +1,7 @@ //#define TESTADC #define TESTADC1 + //#define TIMEDBG #include "server_defs.h" #include "firmware_funcs.h" @@ -97,7 +98,11 @@ int phase_shift=0;//DEFAULT_PHASE_SHIFT; int ipPacketSize=DEFAULT_IP_PACKETSIZE; int udpPacketSize=DEFAULT_UDP_PACKETSIZE; +#ifndef NEW_PLL_RECONFIG u_int32_t clkDivider[2]={32,16}; +#else +u_int32_t clkDivider[2]={40,20}; +#endif int32_t clkPhase[2]={0,0}; u_int32_t adcDisableMask=0; @@ -436,10 +441,10 @@ void configurePll(int i) { // printf("PLL reconfig reset\N"); bus_w(PLL_CNTRL_REG,(1<65535 || st<-65535) return clkPhase[0]; - - printf("phase %d\n", st); - - clkPhase[1]=st-clkPhase[0]; - +#ifdef NEW_PLL_RECONFIG + printf("reset pll\n"); + bus_w(PLL_CNTRL_REG,((1<=0) { + + if (val<60) { + dacvalue=0; + val=60; + } else if (val>=200) { + dacvalue=0x1; + val=200; + } else { + dacvalue=1.+(200.-val)/alpha; + val=200.-(dacvalue-1)*alpha; + } + printf ("****************************** setting val %d, dacval %d\n",val, dacvalue); + offw=DAC_REG; + + ddx=8; csdx=10; cdx=9; + codata=((dacvalue)&0xff); + + + + + valw=0xffff; bus_w(offw,(valw)); // start point + valw=((valw&(~(0x1<>(7-i))&0x1)<>32)&0xFFFFFFFF; + vals[IPCHECKSUM_ADDR]=checksum; + vals[GBE_DELAY_ADDR]=0; + vals[GBE_RESERVED1_ADDR]=sourceport; + vals[GBE_RESERVED2_ADDR]=interface; + vals[DETECTOR_MAC_L_ADDR]=(sourcemac)&0xFFFFFFFF; + vals[DETECTOR_MAC_H_ADDR]=(sourcemac>>32)&0xFFFFFFFF; + vals[DETECTOR_IP_ADDR]=sourceip; + + for (ivar=0; ivarmac.mac_dest_mac1 =((macad>>(8*5))&0xFF);// 0x00; //pc7060 */ -/* mac_conf_regs->mac.mac_dest_mac2 =((macad>>(8*4))&0xFF);// 0x19; //pc7060 */ -/* mac_conf_regs->mac.mac_dest_mac3 =((macad>>(8*3))&0xFF);// 0x99; //pc7060 */ -/* mac_conf_regs->mac.mac_dest_mac4 =((macad>>(8*2))&0xFF);// 0x24; //pc7060 */ -/* mac_conf_regs->mac.mac_dest_mac5 =((macad>>(8*1))&0xFF);// 0xEB; //pc7060 */ -/* mac_conf_regs->mac.mac_dest_mac6 =((macad>>(8*0))&0xFF);// 0xEE; //pc7060 */ - -/* /\* */ -/* mac_conf_regs->mac.mac_src_mac1 = 0x00; */ -/* mac_conf_regs->mac.mac_src_mac2 = 0xAA; */ -/* mac_conf_regs->mac.mac_src_mac3 = 0xBB; */ -/* mac_conf_regs->mac.mac_src_mac4 = 0xCC; */ -/* mac_conf_regs->mac.mac_src_mac5 = 0xDD; */ -/* mac_conf_regs->mac.mac_src_mac6 = 0xEE; */ -/* *\/ */ -/* mac_conf_regs->mac.mac_src_mac1 =((detectormacad>>(8*5))&0xFF); */ -/* mac_conf_regs->mac.mac_src_mac2 =((detectormacad>>(8*4))&0xFF); */ -/* mac_conf_regs->mac.mac_src_mac3 =((detectormacad>>(8*3))&0xFF); */ -/* mac_conf_regs->mac.mac_src_mac4 =((detectormacad>>(8*2))&0xFF); */ -/* mac_conf_regs->mac.mac_src_mac5 =((detectormacad>>(8*1))&0xFF); */ -/* mac_conf_regs->mac.mac_src_mac6 =((detectormacad>>(8*0))&0xFF); */ -/* mac_conf_regs->mac.mac_ether_type = 0x0800; //ipv4 */ +} -/* mac_conf_regs->ip.ip_ver = 0x4; */ -/* mac_conf_regs->ip.ip_ihl = 0x5; */ -/* mac_conf_regs->ip.ip_tos = 0x0; */ -/* mac_conf_regs->ip.ip_len = ipPacketSize;//0x0522; // was 0x0526; */ -/* mac_conf_regs->ip.ip_ident = 0x0000; */ -/* mac_conf_regs->ip.ip_flag = 0x2; */ -/* mac_conf_regs->ip.ip_offset = 0x00; */ -/* mac_conf_regs->ip.ip_ttl = 0x70; */ -/* mac_conf_regs->ip.ip_protocol = 0x11; */ -/* mac_conf_regs->ip.ip_chksum = 0x0000 ; //6E42 now is automatically computed */ -/* mac_conf_regs->ip.ip_sourceip = detipad; //0x8181CA2E;129.129.202.46 */ -/* mac_conf_regs->ip.ip_destip = ipad; //CA57 */ - -/* //#ifdef VERBOSE */ -/* printf("mac_dest:%llx %x:%x:%x:%x:%x:%x\n", */ -/* macad, */ -/* mac_conf_regs->mac.mac_dest_mac1, */ -/* mac_conf_regs->mac.mac_dest_mac2, */ -/* mac_conf_regs->mac.mac_dest_mac3, */ -/* mac_conf_regs->mac.mac_dest_mac4, */ -/* mac_conf_regs->mac.mac_dest_mac5, */ -/* mac_conf_regs->mac.mac_dest_mac6); */ -/* printf("mac_src:%llx %x:%x:%x:%x:%x:%x\n", */ -/* detectormacad, */ -/* mac_conf_regs->mac.mac_src_mac1, */ -/* mac_conf_regs->mac.mac_src_mac2, */ -/* mac_conf_regs->mac.mac_src_mac3, */ -/* mac_conf_regs->mac.mac_src_mac4, */ -/* mac_conf_regs->mac.mac_src_mac5, */ -/* mac_conf_regs->mac.mac_src_mac6); */ -/* printf("ip_ttl:%x\n",mac_conf_regs->ip.ip_ttl); */ -/* printf("det_ip: %x %x\n",detipad, mac_conf_regs->ip.ip_sourceip); */ -/* printf("dest_ip: %x %x\n",ipad, mac_conf_regs->ip.ip_destip); */ - -/* //#endif */ - -/* //checksum */ -/* count=sizeof(mac_conf_regs->ip); */ -/* addr=&(mac_conf_regs->ip); */ -/* while( count > 1 ) { */ -/* sum += *addr++; */ -/* count -= 2; */ -/* } */ -/* if( count > 0 ) sum += *addr; // Add left-over byte, if any */ -/* while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits */ -/* checksum = (~sum)&0xffff; */ -/* mac_conf_regs->ip.ip_chksum = checksum; */ -/* //#ifdef VERBOSE */ -/* printf("IP header checksum is 0x%x s\n",(unsigned int)(checksum)); */ -/* //#endif */ - -/* mac_conf_regs->udp.udp_srcport = 0xE185; */ -/* mac_conf_regs->udp.udp_destport = udpport;//0xC351; */ -/* mac_conf_regs->udp.udp_len = udpPacketSize;//0x050E; //was 0x0512; */ -/* mac_conf_regs->udp.udp_chksum = 0x0000; */ - -/* #ifdef VERBOSE */ -/* printf("Configuring TSE\n"); */ -/* #endif */ -/* tse_conf_regs->rev = 0xA00; */ -/* tse_conf_regs->scratch = 0xCCCCCCCC; */ -/* tse_conf_regs->command_config = 0xB; */ -/* tse_conf_regs->mac_0 = 0x17231C00; */ -/* tse_conf_regs->mac_1 = 0xCB4A; */ -/* tse_conf_regs->frm_length = 0x5DC; //max frame length (1500 bytes) (was 0x41C) */ -/* tse_conf_regs->pause_quant = 0x0; */ -/* tse_conf_regs->rx_section_empty = 0x7F0; */ -/* tse_conf_regs->rx_section_full = 0x10; */ -/* tse_conf_regs->tx_section_empty = 0x3F8; //was 0x7F0; */ -/* tse_conf_regs->tx_section_full = 0x16; */ -/* tse_conf_regs->rx_almost_empty = 0x8; */ -/* tse_conf_regs->rx_almost_full = 0x8; */ -/* tse_conf_regs->tx_almost_empty = 0x8; */ -/* tse_conf_regs->tx_almost_full = 0x3; */ -/* tse_conf_regs->mdio_addr0 = 0x12; */ -/* tse_conf_regs->mdio_addr1 = 0x0; */ - -/* mac_conf_regs->cdone = 0xFFFFFFFF; */ -/* if(ival) */ -/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x2840,write shadow regs.. */ -/* else */ -/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x2840,write shadow regs.. */ - -/* val=bus_r(addrr); */ -/* #ifdef VERBOSE */ -/* printf("Value read from Multi-purpose Reg:%x\n",val); */ -/* #endif */ -/* // if(val!=0x2840) return -1; */ - -/* usleep(100000); */ - -/* if(ival) */ -/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT|DIGITAL_TEST_BIT)); //0x2820,write shadow regs.. */ -/* else */ -/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT)); //0x2820,write shadow regs.. */ - -/* val=bus_r(addrr); */ -/* #ifdef VERBOSE */ -/* printf("Value read from Multi-purpose Reg:%x\n",val); */ -/* #endif */ -/* // if(val!=0x2820) return -1; */ - -/* return adcConfigured; */ + + + +int configureMAC(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int sourceip,int ival,uint32_t destport) { +//int configureMAC(int ipad,long long int macad,long long int detectormacad, int detipad, int ival, int udpport){ + + uint32_t sourceport = 0x7e9a; // 0xE185; + int interface=0; + int ngb; +volatile u_int32_t conf= bus_r(CONFIG_REG); + + + + + +#ifdef NEW_GBE_INTERFACE + ngb=2; + printf("--------- New XGB interface\n"); +#else + ngb=1; + printf("********* Old XGB interface\n"); +#endif + + for (interface=0; interface 2500) + val=-1; + printf("%d mV is ",val); + if (val>0) + val=4095*val/2500; + printf("%d DACu\n", val); + } else if (val>4095) + val=-1; + + + retval=setDac(ind,val); + /* if(idac==HIGH_VOLTAGE) */ + /* retval=initHighVoltageByModule(val,imod); */ + /* else */ + /* retval=initDACbyIndexDACU(idac,val,imod); */ + } + else if (ind==ADC_VPP) { + printf("Setting ADC VPP to %d\n",val); + if (val>4 || val<0) + printf("Cannot set ADC VPP to %d\n",val); + else { + writeADC(0x18,val); + adcvpp=val; + } + retval=adcvpp;; - if (mV) { - if (val>2500) - val=-1; - printf("%d mV is ",val); - if (val>0) - val=4095*val/2500; - printf("%d DACu\n", val); - } else if (val>4095) - val=-1; - - - retval=setDac(ind,val); - /* if(idac==HIGH_VOLTAGE) */ - /* retval=initHighVoltageByModule(val,imod); */ - /* else */ - /* retval=initDACbyIndexDACU(idac,val,imod); */ - } - else if (ind==ADC_VPP) { - printf("Setting ADC VPP to %d\n",val); - if (val>4 || val<0) - printf("Cannot set ADC VPP to %d\n",val); - else { - writeADC(0x18,val); - adcvpp=val; - } - retval=adcvpp;; - - } + } else if (ind==HV_NEW ) + retval=initHighVoltageByModule(val,imod); + else + printf("**********No dac with index %d\n",ind); } } 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; */ - if (ind<16) { - if (mV) { + if (ind<16) { + if (mV) { + + printf("%d DACu is ",retval); + retval1=2500*retval/16535; + printf("%d mV \n",retval1); + } else + retval1=retval; + } else + retval1=retval; - printf("%d DACu is ",retval); - retval1=2500*retval/16535; - printf("%d mV \n",retval1); - } else - retval1=retval; - } - } #endif #ifdef VERBOSE @@ -2000,10 +1992,13 @@ int get_run_status(int file_des) { // else if(!(retval&RUNMACHINE_BUSY_BIT)){ //commented by Anna 24.10.2012 else if(!(retval&RUN_BUSY_BIT)){ // by Anna 24.10.2012 + if((retval&STOPPED_BIT) ){ // - //and readbusy=1, its last frame read - if((retval&READMACHINE_BUSY_BIT) ){ // + printf("-----------------------------------STOPPED--------------------------\n"); + s=STOPPED; + } else if((retval&READMACHINE_BUSY_BIT) ){ // ///and readbusy=1, its last frame read + printf("-----------------------------------READ MACHINE BUSY--------------------------\n"); @@ -2034,7 +2029,7 @@ int get_run_status(int file_des) { printf("-----------------------------------RUNNING-----------------------------------\n"); s=RUNNING; } - } + } }