mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-05 20:30:03 +02:00
Merge branch 'master' of gitorious.psi.ch:sls_det_software/sls_detector_software
This commit is contained in:
commit
e483141a15
@ -21,6 +21,44 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h> /* exit() */
|
||||
#include <string.h> /* memset(), memcpy() */
|
||||
#include <sys/utsname.h> /* uname() */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h> /* socket(), bind(),
|
||||
listen(), accept() */
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h> /* fork(), write(), close() */
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct ip_header_struct {
|
||||
u_int16_t ip_len;
|
||||
u_int8_t ip_tos;
|
||||
u_int8_t ip_ihl:4 ,ip_ver:4;
|
||||
u_int16_t ip_offset:13,ip_flag:3;
|
||||
u_int16_t ip_ident;
|
||||
u_int16_t ip_chksum;
|
||||
u_int8_t ip_protocol;
|
||||
u_int8_t ip_ttl;
|
||||
u_int32_t ip_sourceip;
|
||||
u_int32_t ip_destip;
|
||||
} ip_header;
|
||||
|
||||
|
||||
struct timeval tss,tse,tsss; //for timing
|
||||
|
||||
@ -47,8 +85,8 @@ int storeInRAM=0;
|
||||
int ROI_flag=0;
|
||||
int adcConfigured=-1;
|
||||
u_int16_t *ram_values=NULL;
|
||||
volatile char *now_ptr=NULL;
|
||||
volatile u_int16_t *values;
|
||||
char volatile *now_ptr=NULL;
|
||||
u_int32_t volatile *values;
|
||||
int ram_size=0;
|
||||
|
||||
int64_t totalTime=1;
|
||||
@ -87,79 +125,6 @@ const int nAdcs=NADC;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
ENEt conf structs
|
||||
*/
|
||||
typedef struct mac_header_struct{
|
||||
u_int8_t mac_dest_mac2;
|
||||
u_int8_t mac_dest_mac1;
|
||||
u_int8_t mac_dummy1;
|
||||
u_int8_t mac_dummy2;
|
||||
u_int8_t mac_dest_mac6;
|
||||
u_int8_t mac_dest_mac5;
|
||||
u_int8_t mac_dest_mac4;
|
||||
u_int8_t mac_dest_mac3;
|
||||
u_int8_t mac_src_mac4;
|
||||
u_int8_t mac_src_mac3;
|
||||
u_int8_t mac_src_mac2;
|
||||
u_int8_t mac_src_mac1;
|
||||
u_int16_t mac_ether_type;
|
||||
u_int8_t mac_src_mac6;
|
||||
u_int8_t mac_src_mac5;
|
||||
} mac_header;
|
||||
|
||||
typedef struct ip_header_struct {
|
||||
u_int16_t ip_len;
|
||||
u_int8_t ip_tos;
|
||||
u_int8_t ip_ihl:4 ,ip_ver:4;
|
||||
u_int16_t ip_offset:13,ip_flag:3;
|
||||
u_int16_t ip_ident;
|
||||
u_int16_t ip_chksum;
|
||||
u_int8_t ip_protocol;
|
||||
u_int8_t ip_ttl;
|
||||
u_int32_t ip_sourceip;
|
||||
u_int32_t ip_destip;
|
||||
} ip_header;
|
||||
|
||||
typedef struct udp_header_struct{
|
||||
u_int16_t udp_destport;
|
||||
u_int16_t udp_srcport;
|
||||
u_int16_t udp_chksum;
|
||||
u_int16_t udp_len;
|
||||
} udp_header;
|
||||
|
||||
typedef struct mac_conf_struct{
|
||||
mac_header mac;
|
||||
ip_header ip;
|
||||
udp_header udp;
|
||||
u_int32_t npack;
|
||||
u_int32_t lpack;
|
||||
u_int32_t npad;
|
||||
u_int32_t cdone;
|
||||
} mac_conf;
|
||||
|
||||
typedef struct tse_conf_struct{
|
||||
u_int32_t rev; //0x0
|
||||
u_int32_t scratch;
|
||||
u_int32_t command_config;
|
||||
u_int32_t mac_0; //0x3
|
||||
u_int32_t mac_1;
|
||||
u_int32_t frm_length;
|
||||
u_int32_t pause_quant;
|
||||
u_int32_t rx_section_empty; //0x7
|
||||
u_int32_t rx_section_full;
|
||||
u_int32_t tx_section_empty;
|
||||
u_int32_t tx_section_full;
|
||||
u_int32_t rx_almost_empty; //0xB
|
||||
u_int32_t rx_almost_full;
|
||||
u_int32_t tx_almost_empty;
|
||||
u_int32_t tx_almost_full;
|
||||
u_int32_t mdio_addr0; //0xF
|
||||
u_int32_t mdio_addr1;
|
||||
}tse_conf;
|
||||
|
||||
|
||||
|
||||
int mapCSP0(void) {
|
||||
printf("Mapping memory\n");
|
||||
#ifndef VIRTUAL
|
||||
@ -194,7 +159,7 @@ int mapCSP0(void) {
|
||||
|
||||
u_int32_t address;
|
||||
address = FIFO_DATA_REG;//_OFF;
|
||||
values=(u_int16_t*)(CSP0BASE+address*2);
|
||||
values=(u_int32_t*)(CSP0BASE+address*2);
|
||||
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
||||
printf("\n\n");
|
||||
return OK;
|
||||
@ -207,7 +172,7 @@ u_int16_t bus_r16(u_int32_t offset){
|
||||
}
|
||||
|
||||
u_int16_t bus_w16(u_int32_t offset, u_int16_t data) {
|
||||
volatile u_int16_t *ptr1;
|
||||
volatile u_int16_t *ptr1;
|
||||
ptr1=(u_int16_t*)(CSP0BASE+offset*2);
|
||||
*ptr1=data;
|
||||
return OK;
|
||||
@ -228,7 +193,7 @@ u_int16_t ram_r16(u_int32_t ramType, int adc, int adcCh, int Ch){
|
||||
}
|
||||
|
||||
u_int32_t bus_w(u_int32_t offset, u_int32_t data) {
|
||||
volatile u_int32_t *ptr1;
|
||||
volatile u_int32_t *ptr1;
|
||||
|
||||
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
|
||||
*ptr1=data;
|
||||
@ -238,8 +203,7 @@ u_int32_t bus_w(u_int32_t offset, u_int32_t data) {
|
||||
|
||||
|
||||
u_int32_t bus_r(u_int32_t offset) {
|
||||
volatile u_int32_t *ptr1;
|
||||
|
||||
volatile u_int32_t *ptr1;
|
||||
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
|
||||
return *ptr1;
|
||||
}
|
||||
@ -1614,199 +1578,257 @@ int setADC(int adc){
|
||||
}
|
||||
|
||||
|
||||
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){
|
||||
|
||||
int configureMAC(int ipad,long long int macad,long long int detectormacad, int detipad, int ival, int udpport){
|
||||
uint32_t sourceport = 0x7e9a; // 0xE185;
|
||||
//setheader(0xF452142F3200,0x00ad29ae39fd,0x0a000264,0x0A00020d ,0x8436, 0x7e9a);
|
||||
|
||||
/* void setheader(uint64_t destmac, uint64_t sourcemac, uint32_t destip, uint32_t sourceip, uint32_t destport, */
|
||||
/* uint32_t sourceport){ */
|
||||
|
||||
ip_header ip;
|
||||
int count;
|
||||
unsigned short *addr;
|
||||
long int sum = 0;
|
||||
long int checksum;
|
||||
|
||||
ip.ip_ver = 0x4;
|
||||
ip.ip_ihl = 0x5;
|
||||
ip.ip_tos = 0x0;
|
||||
ip.ip_len = 0x2032;//ipPacketSize;//fixed in firmware
|
||||
ip.ip_ident = 0x0000;
|
||||
ip.ip_flag = 0x2; //not nibble aligned (flag& offset
|
||||
ip.ip_offset = 0x000;
|
||||
ip.ip_ttl = 0x40;
|
||||
ip.ip_protocol = 0x11;
|
||||
ip.ip_chksum = 0x0000 ; // pseudo
|
||||
ip.ip_sourceip = sourceip;
|
||||
ip.ip_destip = destip;
|
||||
|
||||
|
||||
#ifdef DDEBUG
|
||||
printf("Chip of Intrst Reg:%x\n",bus_r(CHIP_OF_INTRST_REG));
|
||||
printf("IP Packet Size:%d\n",ipPacketSize);
|
||||
printf("UDP Packet Size:%d\n",udpPacketSize);
|
||||
#endif
|
||||
count=sizeof(ip);
|
||||
addr=&(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;
|
||||
|
||||
//configuring mac
|
||||
u_int32_t addrr=MULTI_PURPOSE_REG;
|
||||
u_int32_t offset=ENET_CONF_REG, offset2=TSE_CONF_REG;
|
||||
mac_conf *mac_conf_regs;
|
||||
tse_conf *tse_conf_regs;
|
||||
long int sum = 0;
|
||||
long int checksum;
|
||||
int count,val;
|
||||
unsigned short *addr;
|
||||
|
||||
mac_conf_regs=(mac_conf*)(CSP0BASE+offset*2);
|
||||
tse_conf_regs=(tse_conf*)(CSP0BASE+offset2*2);
|
||||
|
||||
#ifdef DDEBUG
|
||||
printf("***Configuring MAC*** \n");
|
||||
#endif
|
||||
|
||||
if(ival)
|
||||
bus_w(addrr,(RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset)
|
||||
else
|
||||
bus_w(addrr,RESET_BIT); //0x080,reset mac (reset)
|
||||
val=bus_r(addrr);
|
||||
#ifdef VERBOSE
|
||||
printf("Value read from Multi-purpose Reg:%x\n",val);
|
||||
#endif
|
||||
// if(val!=0x080) return -1;
|
||||
|
||||
usleep(500000);
|
||||
|
||||
if(ival)
|
||||
bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak)
|
||||
else
|
||||
bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x840,write shadow regs(enet reset,write bak)
|
||||
val=bus_r(addrr);
|
||||
#ifdef VERBOSE
|
||||
printf("Value read from Multi-purpose Reg:%x\n",val);
|
||||
#endif
|
||||
// if(val!=0x840) return -1;
|
||||
|
||||
if(ival)
|
||||
bus_w(addrr,(ENET_RESETN_BIT|DIGITAL_TEST_BIT)); //0x800,nreset phy(enet reset)
|
||||
else
|
||||
bus_w(addrr,ENET_RESETN_BIT); //0x800,nreset phy(enet reset)
|
||||
val=bus_r(addrr);
|
||||
#ifdef VERBOSE
|
||||
printf("Value read from Multi-purpose Reg:%x\n",val);
|
||||
#endif
|
||||
// if(val!=0x800) return -1;
|
||||
printf("IP checksum is 0x%x\n",checksum);
|
||||
|
||||
|
||||
mac_conf_regs->mac.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
|
||||
bus_w(DETECTORIP_AREG,sourceip);//detectorip_AReg_c
|
||||
bus_w(RX_UDP_AREG,destip);//rx_udpip_AReg_c
|
||||
|
||||
/*
|
||||
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
|
||||
bus_w(RX_UDPMACH_AREG,(destmac>>32)&0xFFFFFFFF);//rx_udpmacH_AReg_c
|
||||
bus_w(RX_UDPMACL_AREG,(destmac)&0xFFFFFFFF);//rx_udpmacL_AReg_c
|
||||
bus_w(DETECTORMACH_AREG,(sourcemac>>32)&0xFFFFFFFF);//detectormacH_AReg_c
|
||||
bus_w(DETECTORMACL_AREG,(sourcemac)&0xFFFFFFFF);//detectormacL_AReg_c
|
||||
bus_w(UDPPORTS_AREG,((destport&0xFFFF)<<16)+(sourceport&0xFFFF));//udpports_AReg_c
|
||||
bus_w(IPCHKSUM_AREG,(checksum&0xFFFF));//ipchksum_AReg_c
|
||||
|
||||
bus_w(CONTROL_REG,GB10_RESET_BIT);
|
||||
sleep(1);
|
||||
bus_w(CONTROL_REG,0);
|
||||
usleep(10000);
|
||||
bus_w(CONFIG_REG,GB10_NOT_CPU_BIT);
|
||||
printf("System status register is %08x\n",bus_r(SYSTEM_STATUS_REG));
|
||||
|
||||
return;
|
||||
/* } */
|
||||
|
||||
/* #ifdef DDEBUG */
|
||||
/* printf("Chip of Intrst Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); */
|
||||
/* printf("IP Packet Size:%d\n",ipPacketSize); */
|
||||
/* printf("UDP Packet Size:%d\n",udpPacketSize); */
|
||||
/* #endif */
|
||||
|
||||
/* //configuring mac */
|
||||
/* u_int32_t addrr=MULTI_PURPOSE_REG; */
|
||||
/* u_int32_t offset=ENET_CONF_REG, offset2=TSE_CONF_REG; */
|
||||
/* mac_conf *mac_conf_regs; */
|
||||
/* tse_conf *tse_conf_regs; */
|
||||
/* long int sum = 0; */
|
||||
/* long int checksum; */
|
||||
/* int count,val; */
|
||||
/* unsigned short *addr; */
|
||||
|
||||
/* mac_conf_regs=(mac_conf*)(CSP0BASE+offset*2); */
|
||||
/* tse_conf_regs=(tse_conf*)(CSP0BASE+offset2*2); */
|
||||
|
||||
/* #ifdef DDEBUG */
|
||||
/* printf("***Configuring MAC*** \n"); */
|
||||
/* #endif */
|
||||
|
||||
/* if(ival) */
|
||||
/* bus_w(addrr,(RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset) */
|
||||
/* else */
|
||||
/* bus_w(addrr,RESET_BIT); //0x080,reset mac (reset) */
|
||||
/* val=bus_r(addrr); */
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
|
||||
/* #endif */
|
||||
/* // if(val!=0x080) return -1; */
|
||||
|
||||
/* usleep(500000); */
|
||||
|
||||
/* if(ival) */
|
||||
/* bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak) */
|
||||
/* else */
|
||||
/* bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x840,write shadow regs(enet reset,write bak) */
|
||||
/* val=bus_r(addrr); */
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
|
||||
/* #endif */
|
||||
/* // if(val!=0x840) return -1; */
|
||||
|
||||
/* if(ival) */
|
||||
/* bus_w(addrr,(ENET_RESETN_BIT|DIGITAL_TEST_BIT)); //0x800,nreset phy(enet reset) */
|
||||
/* else */
|
||||
/* bus_w(addrr,ENET_RESETN_BIT); //0x800,nreset phy(enet reset) */
|
||||
/* val=bus_r(addrr); */
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
|
||||
/* #endif */
|
||||
/* // if(val!=0x800) return -1; */
|
||||
|
||||
|
||||
/* mac_conf_regs->mac.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
|
||||
/* 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);
|
||||
/* //#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
|
||||
/* //#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
|
||||
/* //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;
|
||||
/* 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;
|
||||
/* #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;
|
||||
/* 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..
|
||||
/* 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;
|
||||
/* val=bus_r(addrr); */
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
|
||||
/* #endif */
|
||||
/* // if(val!=0x2840) return -1; */
|
||||
|
||||
usleep(100000);
|
||||
/* 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..
|
||||
/* 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;
|
||||
/* val=bus_r(addrr); */
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
|
||||
/* #endif */
|
||||
/* // if(val!=0x2820) return -1; */
|
||||
|
||||
|
||||
|
||||
|
||||
return adcConfigured;
|
||||
/* return adcConfigured; */
|
||||
}
|
||||
|
||||
|
||||
@ -1981,20 +2003,24 @@ u_int32_t fifo_full(void)
|
||||
|
||||
u_int16_t* fifo_read_event(int ns)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
int i=0;//, j=0;
|
||||
/* volatile u_int16_t volatile *dum; */
|
||||
volatile u_int16_t a;
|
||||
// volatile u_int32_t volatile *dum;
|
||||
// volatile u_int32_t a;
|
||||
|
||||
bus_w16(DUMMY_REG,0); //
|
||||
/* #ifdef TIMEDBG */
|
||||
/* gettimeofday(&tse,NULL); */
|
||||
/* #endif */
|
||||
if (ns==0) {
|
||||
volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG);
|
||||
|
||||
bus_w(DUMMY_REG,0);
|
||||
while(t!=0xffffffff) {
|
||||
a=bus_r16(LOOK_AT_ME_REG);
|
||||
// volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG);
|
||||
// bus_w(DUMMY_REG,0);
|
||||
while(a==0) {
|
||||
if (runBusy()==0) {
|
||||
t = bus_r(LOOK_AT_ME_REG);
|
||||
if (t!=0xffffffff) {
|
||||
a = bus_r(LOOK_AT_ME_REG);
|
||||
if (a==0) {
|
||||
printf("no frame found and acquisition finished - exiting\n");
|
||||
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
||||
return NULL;
|
||||
@ -2003,10 +2029,10 @@ u_int16_t* fifo_read_event(int ns)
|
||||
break;
|
||||
}
|
||||
}
|
||||
t = bus_r(LOOK_AT_ME_REG);
|
||||
#ifdef VERBOSE
|
||||
a = bus_r(LOOK_AT_ME_REG);
|
||||
//#ifdef VERBOSE
|
||||
printf(".");
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
/* #ifdef TIMEDBG */
|
||||
/* // tsss=tss; */
|
||||
@ -2021,14 +2047,39 @@ u_int16_t* fifo_read_event(int ns)
|
||||
/* #else */
|
||||
|
||||
bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos
|
||||
bus_w16(DUMMY_REG,0);
|
||||
for (i=0; i<32; i++) {
|
||||
bus_w16(DUMMY_REG,i);
|
||||
// dum=((u_int16_t*)(now_ptr))+i;
|
||||
// *dum=bus_r16(FIFO_DATA_REG);
|
||||
//dum=;
|
||||
*(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG);
|
||||
}
|
||||
// bus_w16(DUMMY_REG,0);
|
||||
// for (i=0; i<32; i++) {
|
||||
bus_w16(DUMMY_REG,0); //
|
||||
for (i=0; i<16; i++) {
|
||||
|
||||
|
||||
// bus_w16(DUMMY_REG,i);
|
||||
// bus_r16(DUMMY_REG);
|
||||
/* dum=(((u_int16_t*)(now_ptr))+i); */
|
||||
/* *dum=bus_r16(FIFO_DATA_REG); */
|
||||
/* a=bus_r16(FIFO_DATA_REG); */
|
||||
//dum=(((u_int32_t*)(now_ptr))+i);
|
||||
|
||||
// a=*values;//bus_r(FIFO_DATA_REG);
|
||||
|
||||
*((u_int32_t*)now_ptr)=*values;//bus_r(FIFO_DATA_REG);
|
||||
|
||||
|
||||
if (i!=0 || ns!=0) {
|
||||
a=0;
|
||||
while (*((u_int32_t*)now_ptr)==*((u_int32_t*)(now_ptr)-1) && a<10) {
|
||||
|
||||
// printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1));
|
||||
*((u_int32_t*)now_ptr)=*values;
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
now_ptr+=4;
|
||||
bus_w16(DUMMY_REG,i+1);
|
||||
// *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG);
|
||||
}
|
||||
bus_w16(DUMMY_REG,0); //
|
||||
/* #ifdef TIMEDBG */
|
||||
|
||||
/* gettimeofday(&tss,NULL); */
|
||||
@ -2053,7 +2104,7 @@ u_int16_t* fifo_read_frame()
|
||||
int ns=0;
|
||||
now_ptr=(char*)ram_values;
|
||||
while(ns<nSamples && fifo_read_event(ns)) {
|
||||
now_ptr+=dataBytes;
|
||||
// now_ptr+=dataBytes;
|
||||
ns++;
|
||||
}
|
||||
#ifdef TIMEDBG
|
||||
@ -2158,6 +2209,7 @@ int setDynamicRange(int dr) {
|
||||
if (dr%16==0 && dr>0) {
|
||||
dynamicRange=16;
|
||||
nSamples=dr/16;
|
||||
bus_w(NSAMPLES_REG,nSamples);
|
||||
dataBytes=NMAXMOD*NCHIP*NCHAN*2;
|
||||
}
|
||||
allocateRAM();
|
||||
@ -2172,7 +2224,8 @@ int setDynamicRange(int dr) {
|
||||
|
||||
int getDynamicRange() {
|
||||
// dynamicRange=16;
|
||||
return dynamicRange*nSamples;
|
||||
nSamples=bus_r(NSAMPLES_REG);
|
||||
return dynamicRange*bus_r(NSAMPLES_REG);//nSamples;
|
||||
|
||||
}
|
||||
|
||||
@ -2222,7 +2275,7 @@ int setStoreInRAM(int b) {
|
||||
int allocateRAM() {
|
||||
size_t size;
|
||||
|
||||
|
||||
getDynamicRange();
|
||||
size=dataBytes*nSamples;
|
||||
|
||||
#ifdef VERBOSE
|
||||
|
@ -75,7 +75,8 @@ int initHighVoltage(int val,int imod);
|
||||
int initConfGain(int isettings,int val,int imod);
|
||||
|
||||
int setADC(int adc);
|
||||
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int udpport);
|
||||
//int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int udpport);
|
||||
int configureMAC(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int detipad,int ival,uint32_t destport);
|
||||
int getAdcConfigured();
|
||||
|
||||
|
||||
|
@ -160,6 +160,8 @@
|
||||
//user entered
|
||||
|
||||
|
||||
#define NSAMPLES_REG 95<<11
|
||||
|
||||
|
||||
|
||||
|
||||
@ -544,7 +546,7 @@
|
||||
--------------------------------------------- */
|
||||
#define IOSIGNALS_MASK 0xfffffffffffff
|
||||
#define ADC_ENABLE_BIT 63
|
||||
#define APATTERN_MASK 0x3ff
|
||||
#define APATTERN_MASK 0xffff
|
||||
#define ASTART_OFFSET 0
|
||||
#define ASTOP_OFFSET 16
|
||||
#define PATTERN_CTRL_WRITE_BIT 0
|
||||
|
@ -156,7 +156,7 @@ int init_detector(int b, int checkType) {
|
||||
strcpy(lastClientIP,"none");
|
||||
strcpy(thisClientIP,"none1");
|
||||
lockStatus=0;
|
||||
|
||||
// getDynamicRange();
|
||||
allocateRAM();
|
||||
return OK;
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ uint64_t iopat=0;
|
||||
uint64_t clkpat=0;
|
||||
|
||||
int iaddr=0;
|
||||
int waitaddr[3]={-1,-1,-1};
|
||||
int startloopaddr[3]={-1,-1,-1};
|
||||
int stoploopaddr[3]={-1,-1,-1};
|
||||
int waitaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS};
|
||||
int startloopaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS};
|
||||
int stoploopaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS};
|
||||
int start=0, stop=0;
|
||||
uint64_t waittime[3]={0,0,0};
|
||||
int nloop[3]={0,0,0};
|
||||
|
Loading…
x
Reference in New Issue
Block a user