ctb server: (bug fixes, udp sending feature instead of tcp, better debugging prints,

digital readout mode (fifoempty flag in status register is always up, so it is idle for this readout mode),
pattern loop bugs, max_pattern_length redefined in server side, do not update period for ctb and moench in setreceiver
This commit is contained in:
maliakal_d 2019-02-28 08:46:26 +01:00
parent 1fe473e830
commit f80483de6e
18 changed files with 378 additions and 103 deletions

View File

@ -58,7 +58,7 @@
#define STATUS_PLL_PHS_DN_MSK (0x00000001 << STATUS_PLL_PHS_DN_OFST)
#define STATUS_PT_CNTRL_STTS_OFF_OFST (24)
#define STATUS_PT_CNTRL_STTS_OFF_MSK (0x000000FF << STATUS_PT_CNTRL_STTS_OFF_OFST)
#define STATUS_IDLE_MSK (0x7FFFF)
#define STATUS_IDLE_MSK (0x6FFFF)
/* Look at me RO register TODO */
#define LOOK_AT_ME_REG (0x03 << MEM_MAP_SHIFT)
@ -364,6 +364,11 @@
/* Pattern Limit RW regiser */
#define PATTERN_LIMIT_REG (0x53 << MEM_MAP_SHIFT)
#define PATTERN_LIMIT_STRT_OFST (0)
#define PATTERN_LIMIT_STRT_MSK (0x0000FFFF << PATTERN_LIMIT_STRT_OFST)
#define PATTERN_LIMIT_STP_OFST (16)
#define PATTERN_LIMIT_STP_MSK (0x0000FFFF << PATTERN_LIMIT_STP_OFST)
/* Pattern Loop 0 Address RW regiser */
#define PATTERN_LOOP_0_ADDR_REG (0x54 << MEM_MAP_SHIFT)

View File

@ -0,0 +1 @@
../slsDetectorServer/UDPPacketHeaderGenerator.h

View File

@ -0,0 +1 @@
../slsDetectorServer/communication_funcs_UDP.h

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/ctbDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 40d15264c56a7a3b1a00291b0735dcec75a39f1d
Revision: 24
Repsitory UUID: 1fe473e830b937b05052fe69cb7bfccde451055a
Revision: 25
Branch: refactor
Last Changed Author: Dhanya_Thattil
Last Changed Rev: 4346
Last Changed Date: 2019-02-22 08:18:54.000000002 +0100 ./Makefile
Last Changed Rev: 4359
Last Changed Date: 2019-02-26 16:09:45.000000002 +0100 ./Makefile

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "40d15264c56a7a3b1a00291b0735dcec75a39f1d"
#define GITREPUUID "1fe473e830b937b05052fe69cb7bfccde451055a"
#define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4346
#define GITDATE 0x20190222
#define GITREV 0x4359
#define GITDATE 0x20190226
#define GITBRANCH "refactor"

View File

@ -23,7 +23,7 @@
// Global variable from slsDetectorServer_funcs
extern int debugflag;
extern int dataBytes;
extern uint16_t *ramValues;
extern char* ramValues;
int firmware_compatibility = OK;
int firmware_check_done = 0;
@ -576,6 +576,7 @@ int allocateRAM() {
"Probably cause: Memory Leak.\n"));
return FAIL;
}
FILE_LOG(logINFO, ("\tRAM allocated to %d bytes\n", dataBytes));
return OK;
}
@ -1501,7 +1502,7 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t
return OK;
#endif
FILE_LOG(logINFOBLUE, ("Configuring MAC\n"));
uint32_t sourceport = DEFAULT_TX_UDP_PORT;
/*uint32_t sourceport = DEFAULT_TX_UDP_PORT;
FILE_LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n",
(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff, sourceip));
@ -1559,9 +1560,9 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t
cleanFifos();//FIXME: resetPerpheral() for ctb?
resetPeripheral();
usleep(WAIT_TIME_CONFIGURE_MAC); /* todo maybe without */
usleep(WAIT_TIME_CONFIGURE_MAC); // todo maybe without
sendUDP(1);
*/sendUDP(0);
return OK;
}
@ -1710,7 +1711,7 @@ uint64_t writePatternIOControl(uint64_t word) {
set64BitReg(word, PATTERN_IO_CNTRL_LSB_REG, PATTERN_IO_CNTRL_MSB_REG);
}
uint64_t retval = get64BitReg(PATTERN_IO_CNTRL_LSB_REG, PATTERN_IO_CNTRL_MSB_REG);
FILE_LOG(logDEBUG1, ("I/O Control: 0x%llx\n", (long long int) retval));
FILE_LOG(logDEBUG1, (" I/O Control: 0x%llx\n", (long long int) retval));
return retval;
}
@ -1720,7 +1721,7 @@ uint64_t writePatternClkControl(uint64_t word) {
set64BitReg(word, PATTERN_IO_CLK_CNTRL_LSB_REG, PATTERN_IO_CLK_CNTRL_MSB_REG);
}
uint64_t retval = get64BitReg(PATTERN_IO_CLK_CNTRL_LSB_REG, PATTERN_IO_CLK_CNTRL_MSB_REG);
FILE_LOG(logDEBUG1, ("Clock Control: 0x%llx\n", (long long int) retval));
FILE_LOG(logDEBUG1, (" Clock Control: 0x%llx\n", (long long int) retval));
return retval;
}
@ -1732,7 +1733,7 @@ uint64_t readPatternWord(int addr) {
return -1;
}
FILE_LOG(logDEBUG1, ("Reading Pattern - Word (addr:0x%x)\n", addr));
FILE_LOG(logDEBUG1, (" Reading Pattern - Word (addr:0x%x)\n", addr));
uint32_t reg = PATTERN_CNTRL_REG;
// overwrite with only addr
@ -1746,7 +1747,7 @@ uint64_t readPatternWord(int addr) {
// read value
uint64_t retval = get64BitReg(PATTERN_OUT_LSB_REG, PATTERN_OUT_MSB_REG);
FILE_LOG(logDEBUG1, ("Word(addr:0x%x): 0x%llx\n", addr, (long long int) retval));
FILE_LOG(logDEBUG1, (" Word(addr:0x%x): 0x%llx\n", addr, (long long int) retval));
return retval;
}
@ -1768,7 +1769,7 @@ uint64_t writePatternWord(int addr, uint64_t word) {
// write word
set64BitReg(word, PATTERN_IN_LSB_REG, PATTERN_IN_MSB_REG);
FILE_LOG(logDEBUG1, ("Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(PATTERN_IN_LSB_REG, PATTERN_IN_MSB_REG)));
FILE_LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(PATTERN_IN_LSB_REG, PATTERN_IN_MSB_REG)));
// overwrite with only addr
bus_w(reg, ((addr << PATTERN_CNTRL_ADDR_OFST) & PATTERN_CNTRL_ADDR_MSK));
@ -1785,9 +1786,9 @@ uint64_t writePatternWord(int addr, uint64_t word) {
int setPatternWaitAddress(int level, int addr) {
// error (handled in tcp)
if (addr >= (MAX_PATTERN_LENGTH + 1)) {
if (addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern - Wait Address. Invalid addr 0x%x. "
"Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH + 1));
"Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
@ -1825,7 +1826,7 @@ int setPatternWaitAddress(int level, int addr) {
// get
uint32_t regval = bus_r((reg & mask) >> offset);
FILE_LOG(logDEBUG1, ("Wait Address (level:%d, addr:0x%x)\n", level, regval));
FILE_LOG(logDEBUG1, (" Wait Address (level:%d, addr:0x%x)\n", level, regval));
return regval;
}
@ -1860,7 +1861,7 @@ uint64_t setPatternWaitTime(int level, uint64_t t) {
// get
uint64_t regval = get64BitReg(regl, regm);
FILE_LOG(logDEBUG1, ("Wait Time (level:%d, t:%lld)\n", level, (long long int)regval));
FILE_LOG(logDEBUG1, (" Wait Time (level:%d, t:%lld)\n", level, (long long int)regval));
return regval;
}
@ -1868,16 +1869,16 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// level 0-2, addr upto patternlength + 1 (checked at tcp)
if ((level != -1) &&
(*startAddr >= 0 || *stopAddr > (MAX_PATTERN_LENGTH + 1))) {
(*startAddr > MAX_PATTERN_LENGTH || *stopAddr > MAX_PATTERN_LENGTH)) {
FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, level:%d, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
level, *startAddr, *stopAddr, MAX_PATTERN_LENGTH + 1));
level, *startAddr, *stopAddr, MAX_PATTERN_LENGTH));
}
//level -1, addr upto patternlength (checked at tcp)
else if ((level == -1) &&
(*startAddr >= 0 || *stopAddr > MAX_PATTERN_LENGTH)) {
FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, complete pattern, stopaddr:0x%x). "
(*startAddr > MAX_PATTERN_LENGTH || *stopAddr > MAX_PATTERN_LENGTH)) {
FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, complete pattern, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
*startAddr, *stopAddr, MAX_PATTERN_LENGTH));
}
@ -1918,6 +1919,10 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// complete pattern
addr = PATTERN_LIMIT_REG;
nLoopReg = -1;
startOffset = PATTERN_LIMIT_STRT_OFST;
startMask = PATTERN_LIMIT_STRT_MSK;
stopOffset = PATTERN_LIMIT_STP_OFST;
stopMask = PATTERN_LIMIT_STP_MSK;
break;
default:
// already checked at tcp interface
@ -1933,28 +1938,31 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// set iteration
if (*nLoop >= 0) {
FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop (level:%d, nLoop:%d)\n",
level, nLoop));
level, *nLoop));
bus_w(nLoopReg, *nLoop);
}
*nLoop = bus_r(nLoopReg);
}
// set start and stop addr
if (*startAddr == -1) {
*startAddr = ((bus_r(addr) >> startOffset) & startMask);
FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop Start Address (level:%d, startAddr:0x%x was -1)\n",
level, *startAddr));
}
if (*stopAddr == -1) {
*stopAddr = ((bus_r(addr) >> stopOffset) & stopMask);
FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop Stop Address (level:%d, stopAddr:0x%x, was -1)\n",
level, *stopAddr));
// set
if (*startAddr != -1 && *stopAddr != -1) {
// writing start and stop addr
FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n",
level, *startAddr, *stopAddr));
bus_w(addr, ((*startAddr << startOffset) & startMask) | ((*stopAddr << stopOffset) & stopMask));
FILE_LOG(logDEBUG1, ("Addr:0x%x, val:0x%x\n", addr, bus_r(addr)));
}
// writing start and stop addr
FILE_LOG(logINFO, ("Setting Pattern - Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n",
level, *startAddr, *stopAddr));
bus_w(addr, ((*startAddr << startOffset) & startMask) | ((*stopAddr << stopOffset) & stopMask));
// get
else {
*startAddr = ((bus_r(addr) & startMask) >> startOffset);
FILE_LOG(logDEBUG1, ("Getting Pattern - Pattern Loop Start Address (level:%d, Read startAddr:0x%x)\n",
level, *startAddr));
*stopAddr = ((bus_r(addr) & stopMask) >> stopOffset);
FILE_LOG(logDEBUG1, ("Getting Pattern - Pattern Loop Stop Address (level:%d, Read stopAddr:0x%x)\n",
level, *stopAddr));
}
}
@ -1977,9 +1985,6 @@ int startStateMachine(){
cleanFifos();
unsetFifoReadStrobes(); // FIXME: unnecessary to write bus_w(dumm, 0) as it is 0 in the beginnig and the strobes are always unset if set
// point the data pointer to the starting position of data
now_ptr = (char*)ramValues;
//start state machine
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STRT_ACQSTN_MSK | CONTROL_STRT_EXPSR_MSK);
bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STRT_ACQSTN_MSK & ~CONTROL_STRT_EXPSR_MSK);
@ -2070,10 +2075,10 @@ enum runStatus getRunStatus(){
return TRANSMITTING;
}
if (retval & STATUS_ALL_FF_EMPTY_MSK) {
/*if (retval & STATUS_ALL_FF_EMPTY_MSK) {
FILE_LOG(logINFOBLUE, ("Status: Transmitting (All fifo empty)\n"));
return TRANSMITTING;
}
}*/
if (! (retval & STATUS_IDLE_MSK)) {
FILE_LOG(logINFOBLUE, ("Status: Idle\n"));
@ -2095,7 +2100,6 @@ void readFrame(int *ret, char *mess) {
}
return;
#endif
// wait for status to be done
while(runBusy()){
usleep(500); // random
}
@ -2116,7 +2120,12 @@ void unsetFifoReadStrobes() {
bus_w(DUMMY_REG, bus_r(DUMMY_REG) & (~DUMMY_ANLG_FIFO_RD_STRBE_MSK) & (~DUMMY_DGTL_FIFO_RD_STRBE_MSK));
}
void readSample() {
void readSample(int ns) {
if (!(ns%1000)) {
FILE_LOG(logDEBUG2, ("Reading sample ns:%d (out of %d), fifodinstatus:0x%x\n",
ns, nSamples,
bus_r(FIFO_DIN_STATUS_REG)));
}
uint32_t addr = DUMMY_REG;
uint32_t fifoAddr = FIFO_DATA_REG;
@ -2157,7 +2166,6 @@ void readSample() {
// read digital output
if (digitalEnable) {
// read strobe to digital fifo
bus_w(addr, bus_r(addr) | DUMMY_DGTL_FIFO_RD_STRBE_MSK);
bus_w(addr, bus_r(addr) & (~DUMMY_DGTL_FIFO_RD_STRBE_MSK));
@ -2171,6 +2179,10 @@ void readSample() {
// only called for first sample
int checkDataPresent() {
uint32_t dataPresent = bus_r(LOOK_AT_ME_REG);
FILE_LOG(logDEBUG2, ("LookatMe:0x%x, status:0x%x\t, fifodinstatus:0x%x\n",
dataPresent,
bus_r(STATUS_REG),
bus_r(FIFO_DIN_STATUS_REG)));
// as long as fifo empty (keep checking)
while (!dataPresent) {
// acquisition done
@ -2179,8 +2191,8 @@ int checkDataPresent() {
dataPresent = bus_r(LOOK_AT_ME_REG);
// still no data
if (!dataPresent) {
FILE_LOG(logERROR, ("Acquisition Finished (State: 0x%08x), "
"but no frame found (Look_at_me: 0x%08x).\n", dataPresent));
FILE_LOG(logINFO, ("Acquisition Finished (State: 0x%08x), "
"no frame found .\n", bus_r(STATUS_REG)));
return FAIL;
}
// got data, exit
@ -2191,19 +2203,23 @@ int checkDataPresent() {
// check if fifo empty again
dataPresent = bus_r(LOOK_AT_ME_REG);
}
FILE_LOG(logDEBUG2, ("Got data, Lookatme:0x%x\n", dataPresent));
return OK;
}
int readFrameFromFifo() {
int ns = 0;
int ns = 0;
// point the data pointer to the starting position of data
now_ptr = ramValues;
// no data for this frame
if (checkDataPresent(ns) == FAIL) {
if (checkDataPresent() == FAIL) {
return FAIL;
}
// read Sample
while(ns < nSamples) {
// chceck if no data in fifo, return ns?//FIXME: ask Anna
readSample(ns);
ns++;
}
@ -2217,7 +2233,7 @@ uint32_t runBusy() {
return virtual_status;
#endif
uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK);
FILE_LOG(logDEBUG1, ("Status Register: %08x\n", s));
//FILE_LOG(logDEBUG1, ("Status Register: %08x\n", s));
return s;
}

View File

@ -8,7 +8,7 @@
#define REQRD_FRMWR_VRSN 0x181130
#define PROGRAMMING_MODE (0x2)
#define CTRL_SRVR_INIT_TIME_US (1000 * 1000)
#define CTRL_SRVR_INIT_TIME_US (1 * 1000 * 1000)
/* Struct Definitions */
typedef struct ip_header_struct {
@ -77,6 +77,7 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
#define VIO_MIN_MV (1200) // for fpga to function
/* Defines in the Firmware */
#define MAX_PATTERN_LENGTH (0xFFFF)
#define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo
#define WAIT_TIME_US_PLL (10 * 1000)
#define WAIT_TIME_US_STP_ACQ (100)
@ -87,7 +88,7 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
#define LSB_OF_64_BIT_REG_OFST (0)
#define BIT_32_MSK (0xFFFFFFFF)
#define IP_PACKETSIZE (0x2032)
#define IP_PACKETSIZE (1024 + 50)//(0x2032)
#define ADC_PORT_INVERT_VAL (0x453b2593)
#define MAXIMUM_ADC_CLK (40)
#define PLL_VCO_FREQ_MHZ (400)

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 031a11c4f7b25e8c14532976731aebdc0bb56fe7
Revision: 23
Repsitory UUID: 1fe473e830b937b05052fe69cb7bfccde451055a
Revision: 24
Branch: refactor
Last Changed Author: Dhanya_Thattil
Last Changed Rev: 4307
Last Changed Date: 2019-02-11 14:53:03.000000002 +0100 ./xparameters.h
Last Changed Rev: 4359
Last Changed Date: 2019-02-22 13:58:42.000000002 +0100 ./xparameters.h

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "031a11c4f7b25e8c14532976731aebdc0bb56fe7"
#define GITREPUUID "1fe473e830b937b05052fe69cb7bfccde451055a"
#define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4307
#define GITDATE 0x20190211
#define GITREV 0x4359
#define GITDATE 0x20190222
#define GITBRANCH "refactor"

View File

@ -56,6 +56,7 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8};
#define DAC_MAX_MV (2500)
/* Defines in the Firmware */
#define MAX_PATTERN_LENGTH (0xFFFF)
#define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo
#define WAIT_TIME_US_PLL (10 * 1000)
#define WAIT_TIME_US_STP_ACQ (100)

View File

@ -0,0 +1,115 @@
#pragma once
#include "logger.h"
#include "sls_detector_defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
extern const enum detectorType myDetectorType;
extern int nSamples;
extern int dataBytes;
extern int nframes;
extern char* ramValues;
#define UDP_PACKET_HEADER_VERSION (0x1)
#define UDP_PACKET_MAX_DATA_BYTES (1280)
uint32_t udpPacketNumber = 0;
uint64_t udpFrameNumber = 0;
int numSamplesPerPacket = 0;
int dataBytesPerSample = 0;
int dataBytesPerPacket = 0;
int udpHeaderOffset = 0;
uint32_t getUDPPacketNumber() {
return udpPacketNumber;
}
uint64_t getUDPFrameNumber() {
return udpFrameNumber;
}
void calculateDataBytesPerSample() {
dataBytesPerSample = dataBytes / nSamples;
numSamplesPerPacket = (double)UDP_PACKET_MAX_DATA_BYTES / (double)dataBytesPerSample;
dataBytesPerPacket = dataBytesPerSample * numSamplesPerPacket;
FILE_LOG(logDEBUG2, ("Databytes/Sample = %d, numSamples/Packet:%d dataBytes/Packet:%d\n",
dataBytesPerSample, numSamplesPerPacket, dataBytesPerPacket));
}
/**
* Called for each UDP packet header creation
*
*/
void createUDPPacketHeader(char* buffer, uint16_t id) {
memset(buffer, 0, sizeof(sls_detector_header));
sls_detector_header* header = (sls_detector_header*)(buffer);
header->modId = id;
// row and column remains 0 (only used by ctb now)
// uint64_t timestamp FIXME: needed?
header->detType = (uint16_t)myDetectorType;
header->version = UDP_PACKET_HEADER_VERSION;
// reset offset
udpHeaderOffset = 0;
// reset frame number
udpFrameNumber = 0;
}
int fillUDPPacket(char* buffer) {
FILE_LOG(logDEBUG2, ("Databytes:%d offset:%d\n", dataBytes, udpHeaderOffset));
// reached end of data for one frame
if (udpHeaderOffset >= dataBytes) {
// reset offset
udpHeaderOffset = 0;
return 0;
}
sls_detector_header* header = (sls_detector_header*)(buffer);
// first packet (update frame number)
if (udpHeaderOffset == 0) {
// increment frame number (starts at 1)
++udpFrameNumber;
header->frameNumber = udpFrameNumber;
udpPacketNumber = -1;
}
// increment udp packet number (starts at 0)
++udpPacketNumber;
// copy packet number
FILE_LOG(logDEBUG2, ("Creating packet number %d (fnum:%lld)\n", udpPacketNumber, (long long int) udpFrameNumber));
header->packetNumber = udpPacketNumber;
// calculate number of bytes to write
int numBytesToWrite = ((udpHeaderOffset + dataBytesPerPacket) <= dataBytes) ?
dataBytesPerPacket : (dataBytes - udpHeaderOffset);
// copy number of samples in current packet
header->reserved = (numBytesToWrite / dataBytesPerSample);
if (numBytesToWrite % dataBytesPerSample) {
FILE_LOG(logERROR, ("fillUDPPacketHeader: numBytesToWrite is not divisible by dataBytesPerSample! Calculation error\n"));
}
// copy date
memcpy(buffer + sizeof(sls_detector_header), ramValues + udpHeaderOffset, numBytesToWrite);
// increment offset
udpHeaderOffset += numBytesToWrite;
return numBytesToWrite + sizeof(sls_detector_header);
}

View File

@ -168,6 +168,7 @@ int mapCSP0(void) {
(long long unsigned int)CSP0BASE,
(long long unsigned int)(CSP0BASE+MEM_SIZE)));
FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
FILE_LOG(logINFO, ("looka t me Register: %08x\n", bus_r(LOOK_AT_ME_REG)));
}else
FILE_LOG(logINFO, ("Memory already mapped before\n"));
return OK;

View File

@ -12,8 +12,6 @@ typedef enum{
}intType;
int bindSocket(unsigned short int port_number);
int acceptConnection(int socketDescriptor);
void closeConnection(int file_Des);

View File

@ -0,0 +1,113 @@
#pragma once
#include "logger.h"
#include "sls_detector_defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
int udpSockfd = -1;
struct addrinfo* udpServerAddrInfo = 0;
unsigned short int udpDestinationPort = 0;
char udpDestinationIp[MAX_STR_LENGTH] = "";
//DEFAULT_TX_UDP_PORT;// src port
int setUDPDestinationDetails(const char* ip, unsigned short int port) {
udpDestinationPort = port;
size_t len = strlen(ip);
strncpy(udpDestinationIp, ip, len > MAX_STR_LENGTH ? MAX_STR_LENGTH : len );
if (udpServerAddrInfo) {
freeaddrinfo(udpServerAddrInfo);
udpServerAddrInfo = 0;
}
// convert ip to internet address
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = 0;
hints.ai_protocol = 0;
char sport[100];
memset(sport, 0, 100);
sprintf(sport, "%d", udpDestinationPort);
int err = getaddrinfo(udpDestinationIp, sport, &hints, &udpServerAddrInfo);
if (err != 0) {
FILE_LOG(logERROR, ("Failed to resolve remote socket address %s at port %d. "
"(Error code:%d, %s)\n", udpDestinationIp, udpDestinationPort, err, gai_strerror(err)));
return FAIL;
}
if (udpServerAddrInfo == NULL) {
FILE_LOG(logERROR, ("Failed to resolve remote socket address %s at port %d "
"(getaddrinfo returned NULL)\n", udpDestinationIp, udpDestinationPort));
udpServerAddrInfo = 0;
return FAIL;
}
return OK;
}
int createUDPSocket() {
if (!strlen(udpDestinationIp)) {
FILE_LOG(logERROR, ("No destination UDP ip specified.\n"));
return FAIL;
}
if (udpSockfd != -1) {
FILE_LOG(logERROR, ("Strange that Udp socket was still open. Closing it to create a new one\n"));
close(udpSockfd);
udpSockfd = -1;
}
// Creating socket file descriptor
udpSockfd = socket(udpServerAddrInfo->ai_family, udpServerAddrInfo->ai_socktype, udpServerAddrInfo->ai_protocol);
if (udpSockfd == -1 ) {
FILE_LOG(logERROR, ("UDP socket at port %d failed. (Error code:%d, %s)\n",
udpDestinationPort, errno, gai_strerror(errno)));
return FAIL;
}
FILE_LOG(logINFO, ("Udp client socket created for server (port %d, ip:%s)\n",
udpDestinationPort, udpDestinationIp));
// connecting allows to use "send/write" instead of "sendto", avoiding checking for server address for each packet
// using write without a connect will end in segv
if (connect(udpSockfd,udpServerAddrInfo->ai_addr, udpServerAddrInfo->ai_addrlen)==-1) {
FILE_LOG(logERROR, ("Could not connect to UDP server at ip:%s, port:%d. (Error code:%d, %s)\n",
udpDestinationIp, udpDestinationPort, errno, gai_strerror(errno)));
}
FILE_LOG(logINFO, ("Udp client socket connected\n",
udpDestinationPort, udpDestinationIp));
return OK;
}
int sendUDPPacket(const char* buf, int length) {
int n = write(udpSockfd, buf, length);
// udp sends atomically, no need to handle partial data
if (n == -1) {
FILE_LOG(logERROR, ("Could not send udp packet. (Error code:%d, %s)\n",
n, errno, gai_strerror(errno)));
} else {
FILE_LOG(logDEBUG2, ("%d bytes sent\n", n));
}
return n;
}
void closeUDPSocket() {
close(udpSockfd);
udpSockfd = -1;
if (udpServerAddrInfo) {
freeaddrinfo(udpServerAddrInfo);
udpServerAddrInfo = 0;
}
}

View File

@ -326,7 +326,7 @@ enum runStatus getRunStatus();
void readFrame(int *ret, char *mess);
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
void unsetFifoReadStrobes();
void readSample();
void readSample(int ns);
int checkDataPresent();
int readFrameFromFifo();
#endif

View File

@ -3,6 +3,13 @@
#include "communication_funcs.h"
#include "logger.h"
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
#include "communication_funcs_UDP.h"
#include "UDPPacketHeaderGenerator.h"
extern uint64_t udpFrameNumber;
extern uint32_t udpPacketNumber;
#endif
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
@ -37,8 +44,7 @@ int sockfd = 0;
int debugflag = 0;
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
int dataBytes = 0;
uint16_t *ramValues = 0;
int nframes = 0;
char* ramValues = 0;
#endif
// Local variables
@ -1372,9 +1378,6 @@ int start_acquisition(int file_des) {
FILE_LOG(logDEBUG1, ("Starting Acquisition\n"));
// only set
if (Server_VerifyLock() == OK) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
nframes = 0;
#endif
ret = startStateMachine();
if (ret == FAIL) {
sprintf(mess, "Could not start acquisition\n");
@ -1456,12 +1459,9 @@ int start_and_read_all(int file_des) {
FILE_LOG(logDEBUG1, ("Starting Acquisition and read all frames\n"));
// start state machine
FILE_LOG(logDEBUG1, ("Stopping Acquisition\n"));
FILE_LOG(logDEBUG1, ("Starting Acquisition\n"));
// only set
if (Server_VerifyLock() == OK) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
nframes = 0;
#endif
ret = startStateMachine();
if (ret == FAIL) {
sprintf(mess, "Could not start acquisition\n");
@ -1492,14 +1492,34 @@ int read_all(int file_des) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
// read from fifo enabled
if (!sendUDP(-1)) {
FILE_LOG(logDEBUG1, ("Reading from 1G UDP\n"));
if (setUDPDestinationDetails("129.129.205.171", 50001) == OK) { // 10g,1 g
if (createUDPSocket() == OK) {
char buffer[UDP_PACKET_MAX_DATA_BYTES + sizeof(sls_detector_header)];
createUDPPacketHeader(buffer, getHardwareSerialNumber());
calculateDataBytesPerSample();
// keep reading frames
while(readFrameFromFifo() == OK) {
int bytesToSend = 0;
int n = 0;
// fill packet with pnum, nsamples per packet and data
while((bytesToSend = fillUDPPacket(buffer))) {
n += sendUDPPacket(buffer, bytesToSend);
}
if (n >= dataBytes)
FILE_LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d bytes sent)\n",
udpFrameNumber, udpPacketNumber + 1, dataBytes, n));
}
closeUDPSocket();
}
}
// keep reading frames
while(readFrameFromFifo() == OK) {
// (to the receiver)
Server_SendResult(file_des, INT32, NO_UPDATE, ramValues, dataBytes);// (or get as arg first)send number of bytes (dataBytes) first //FIXME
FILE_LOG(logDEBUG1, ("Frame %d sent\n", nframes));
++nframes;
}
// finished readng frames
// frames left to give status
@ -1515,9 +1535,13 @@ int read_all(int file_des) {
Server_SendResult(file_des, INT32, UPDATE, NULL, 0); // to the client
}
// read from receiver
else
#endif
else {
FILE_LOG(logDEBUG1, ("Reading via UDP\n"));
readFrame(&ret, mess);
}
#else
readFrame(&ret, mess);
#endif
}
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
}
@ -2541,7 +2565,7 @@ int set_ctb_pattern(int file_des) {
#else
int addr = (int)args[0];
uint64_t word = args[1];
FILE_LOG(logDEBUG1, ("addr:0x%x word:0x%llx\n", addr, word));
FILE_LOG(logDEBUG1, (" addr:0x%x word:0x%llx\n", addr, word));
if ((word == -1) || (Server_VerifyLock() == OK)) {
@ -2558,21 +2582,21 @@ int set_ctb_pattern(int file_des) {
switch (addr) {
case -1:
strcpy(tempName, "Pattern (I/O Control Register)");
FILE_LOG(logDEBUG1, ("Setting %s to 0x%llx\n", tempName, (long long int) word));
FILE_LOG(logDEBUG1, (" Setting %s, word to 0x%llx\n", tempName, (long long int) word));
retval64 = writePatternIOControl(word);
break;
case -2:
strcpy(tempName, "Pattern (Clock Control Register)");
FILE_LOG(logDEBUG1, ("Setting %s to 0x%llx\n", tempName, (long long int) word));
FILE_LOG(logDEBUG1, (" Setting %s, word to 0x%llx\n", tempName, (long long int) word));
retval64 = writePatternClkControl(word);
break;
default:
sprintf(tempName, "Pattern (Word, addr:0x%x)", addr);
FILE_LOG(logDEBUG1, ("Setting %s to 0x%llx\n", tempName, (long long int) word));
FILE_LOG(logDEBUG1, (" Setting %s, word to 0x%llx\n", tempName, (long long int) word));
retval64 = writePatternWord(addr, word);
break;
}
FILE_LOG(logDEBUG1, ("%s: 0x%llx\n", tempName, (long long int)retval64));
FILE_LOG(logDEBUG1, (" %s: 0x%llx\n", tempName, (long long int)retval64));
validate64(word, retval64, tempName, HEX);
}
}
@ -2598,7 +2622,7 @@ int set_ctb_pattern(int file_des) {
int startAddr = (int)args[1];
int stopAddr = (int)args[2];
int numLoops = (int)args[3];
FILE_LOG(logDEBUG1, ("loopLevel:%d startAddr:0x%x stopAddr:0x%x numLoops:%d word:0x%llx\n", loopLevel, startAddr, stopAddr, numLoops));
FILE_LOG(logDEBUG1, (" loopLevel:%d startAddr:0x%x stopAddr:0x%x numLoops:%d\n", loopLevel, startAddr, stopAddr, numLoops));
if (loopLevel < -1 || loopLevel > 2) { // -1 complete pattern
ret = FAIL;
@ -2607,11 +2631,11 @@ int set_ctb_pattern(int file_des) {
}
// level 0-2, addr upto patternlength + 1
else if ((loopLevel != -1) && (startAddr > (MAX_PATTERN_LENGTH + 1) || stopAddr > (MAX_PATTERN_LENGTH + 1))) {
else if ((loopLevel != -1) && (startAddr > MAX_PATTERN_LENGTH || stopAddr > MAX_PATTERN_LENGTH )) {
ret = FAIL;
sprintf(mess, "Cannot set Pattern (Pattern Loop, level:%d, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
loopLevel, startAddr, stopAddr, MAX_PATTERN_LENGTH + 1);
loopLevel, startAddr, stopAddr, MAX_PATTERN_LENGTH);
FILE_LOG(logERROR, (mess));
}
@ -2650,26 +2674,26 @@ int set_ctb_pattern(int file_des) {
#else
int loopLevel = (int)args[0];
int addr = (int)args[1];
FILE_LOG(logDEBUG1, ("loopLevel:%d addr:0x%x\n", loopLevel, addr));
FILE_LOG(logDEBUG1, (" loopLevel:%d addr:0x%x\n", loopLevel, addr));
if ((addr == -1) || (Server_VerifyLock() == OK)) {
if (loopLevel < 0 || loopLevel > 2) {
ret = FAIL;
sprintf(mess, "Pattern (Wait Address) Level (0x%x) is not implemented for this detector\n", loopLevel);
FILE_LOG(logERROR,(mess));
} else if (addr > (MAX_PATTERN_LENGTH + 1)) {
} else if (addr > MAX_PATTERN_LENGTH) {
ret = FAIL;
sprintf(mess, "Cannot set Pattern (Wait Address, addr:0x%x). Addr must be less than 0x%x\n",
addr, MAX_PATTERN_LENGTH + 1);
addr, MAX_PATTERN_LENGTH);
FILE_LOG(logERROR, (mess));
} else {
char tempName[100];
memset(tempName, 0, 100);
sprintf(tempName, "Pattern (Wait Address, Level:%d)", loopLevel);
FILE_LOG(logDEBUG1, ("Setting %s to 0x%x\n", tempName, addr));
FILE_LOG(logDEBUG1, (" Setting %s to 0x%x\n", tempName, addr));
retval32 = setPatternWaitAddress(loopLevel, addr);
FILE_LOG(logDEBUG1, ("%s: 0x%x\n", tempName, retval32));
FILE_LOG(logDEBUG1, (" %s: 0x%x\n", tempName, retval32));
validate(addr, retval32, tempName, HEX);
}
}
@ -2693,7 +2717,7 @@ int set_ctb_pattern(int file_des) {
#else
int loopLevel = (int)args[0];
uint64_t timeval = args[1];
FILE_LOG(logDEBUG1, ("loopLevel:%d timeval:0x%lld\n", loopLevel, timeval));
FILE_LOG(logDEBUG1, (" loopLevel:%d timeval:0x%lld\n", loopLevel, timeval));
if ((timeval == -1) || (Server_VerifyLock() == OK)) {
if (loopLevel < 0 || loopLevel > 2) {
@ -2705,9 +2729,9 @@ int set_ctb_pattern(int file_des) {
memset(tempName, 0, 100);
sprintf(tempName, "Pattern (Wait Time, Level:%d)", loopLevel);
FILE_LOG(logDEBUG1, ("Setting %s to 0x%lld\n", tempName, (long long int)timeval));
FILE_LOG(logDEBUG1, (" Setting %s to 0x%lld\n", tempName, (long long int)timeval));
retval64 = setPatternWaitTime(loopLevel, timeval);
FILE_LOG(logDEBUG1, ("%s: 0x%lld\n", tempName, (long long int)retval64));
FILE_LOG(logDEBUG1, (" %s: 0x%lld\n", tempName, (long long int)retval64));
validate64(timeval, retval64, tempName, HEX);
}
}

View File

@ -2412,7 +2412,9 @@ std::string slsDetector::setReceiver(const std::string &receiverIP) {
overwriteFile(thisDetector->receiver_overWriteEnable);
setTimer(FRAME_PERIOD, thisDetector->timerValue[FRAME_PERIOD]);
setTimer(FRAME_NUMBER, thisDetector->timerValue[FRAME_NUMBER]);
setTimer(ACQUISITION_TIME, thisDetector->timerValue[ACQUISITION_TIME]);
if (thisDetector->myDetectorType != CHIPTESTBOARD && thisDetector->myDetectorType != MOENCH) {
setTimer(ACQUISITION_TIME, thisDetector->timerValue[ACQUISITION_TIME]);
}
if (thisDetector->myDetectorType == EIGER) {
setTimer(SUBFRAME_ACQUISITION_TIME,
thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]);

View File

@ -45,9 +45,6 @@ typedef int int32_t;
/** maximum unit size of program sent to detector */
#define MAX_FPGAPROGRAMSIZE (2 * 1024 *1024)
/** maximum pattern length */
#define MAX_PATTERN_LENGTH 65535
/** get flag form most functions */
#define GET_FLAG -1