This commit is contained in:
2021-08-13 17:10:46 +02:00
parent 2548a0bfec
commit 5790e4961b
23 changed files with 192 additions and 91 deletions

View File

@ -120,6 +120,7 @@ enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE };
#define MAX_TRIMBITS_VALUE (63)
#define MIN_ROWS_PER_READOUT (1)
#define MAX_ROWS_PER_READOUT (256)
#define MAX_PACKETS_PER_REQUEST (256)

View File

@ -167,6 +167,15 @@
#define ADC_PORT_INVERT_ADC_3_OFST (24)
#define ADC_PORT_INVERT_ADC_3_MSK (0x000000FF << ADC_PORT_INVERT_ADC_3_OFST)
/** Partial Readout Register */
#define PARTIAL_READOUT_REG (0x44 << MEM_MAP_SHIFT)
#define PARTIAL_READOUT_NUM_ROWS_OFST (0)
#define PARTIAL_READOUT_NUM_ROWS_MSK (0x0000003F << PARTIAL_READOUT_NUM_ROWS_OFST)
#define PARTIAL_READOUT_ENBL_OFST (7)
#define PARTIAL_READOUT_ENBL_MSK (0x00000001 << PARTIAL_READOUT_ENBL_OFST)
/* Configuration Register */
#define CONFIG_REG (0x4D << MEM_MAP_SHIFT)

View File

@ -480,6 +480,7 @@ void setupDetector() {
setFilterCell(DEFAULT_FILTER_CELL);
}
disableCurrentSource();
setPartialReadout(MAX_ROWS_PER_READOUT);
}
int resetToDefaultDacs(int hardReset) {
@ -1596,6 +1597,39 @@ int *getDetectorPosition() { return detPos; }
/* jungfrau specific - powerchip, autocompdisable, asictimer, clockdiv, pll,
* flashing fpga */
int setPartialReadout(int value) {
if (value < 0 || (value % PARTIAL_READOUT_MULTIPLE != 0))
return FAIL;
// regval is numpackets - 1
int regval = (value / PARTIAL_READOUT_MULTIPLE) - 1;
uint32_t addr = PARTIAL_READOUT_REG;
LOG(logINFO, ("Setting Partial Readout: %d (regval:%d)\n", value, regval));
bus_w(addr, bus_r(addr) &~PARTIAL_READOUT_NUM_ROWS_MSK);
bus_w(addr, bus_r(addr) | ((regval << PARTIAL_READOUT_NUM_ROWS_OFST) & PARTIAL_READOUT_NUM_ROWS_MSK));
if (value == MAX_ROWS_PER_READOUT) {
LOG(logINFO, ("Disabling Partial Readout\n"));
bus_w(addr, bus_r(addr) &~PARTIAL_READOUT_ENBL_MSK);
} else {
LOG(logINFO, ("Enabling Partial Readout\n"));
bus_w(addr, bus_r(addr) | PARTIAL_READOUT_ENBL_MSK);
}
return OK;
}
int getPartialReadout() {
int enable = (bus_r(PARTIAL_READOUT_REG) & PARTIAL_READOUT_ENBL_MSK);
int regval = ((bus_r(PARTIAL_READOUT_REG) & PARTIAL_READOUT_NUM_ROWS_MSK) >> PARTIAL_READOUT_NUM_ROWS_OFST);
int maxRegval = (MAX_ROWS_PER_READOUT/ PARTIAL_READOUT_MULTIPLE) - 1;
if ((regval == maxRegval && enable) || (regval != maxRegval && !enable)) {
return -1;
}
return (regval + 1) * PARTIAL_READOUT_MULTIPLE;
}
void initReadoutConfiguration() {
LOG(logINFO, ("Initializing Readout Configuration:\n"
@ -2263,6 +2297,8 @@ void *start_timer(void *arg) {
return NULL;
}
int transmissionDelayUs = getTransmissionDelayFrame() * 1000;
int numInterfaces = getNumberofUDPInterfaces();
int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * getNumTriggers() *
@ -2271,17 +2307,36 @@ void *start_timer(void *arg) {
const int npixels = 256 * 256 * 8;
const int dataSize = 8192;
const int packetsize = dataSize + sizeof(sls_detector_header);
const int packetsPerFrame = numInterfaces == 1 ? 128 : 64;
int transmissionDelayUs = getTransmissionDelayFrame() * 1000;
int maxPacketsPerFrame = 128;
int maxRows = MAX_ROWS_PER_READOUT;
if (numInterfaces == 2) {
maxPacketsPerFrame /= 2;
maxRows /= 2;
}
int partialReadout = getPartialReadout();
if (partialReadout == -1) {
partialReadout = MAX_ROWS_PER_READOUT;
}
const int packetsPerFrame = (maxPacketsPerFrame * partialReadout) / maxRows;
//LOG(logINFOBLUE, ("packetsperframe:%d numFrames:%d partial:%d maxpacketsperframe:%d maxrows:%d \n", packetsPerFrame, numFrames, partialReadout, maxPacketsPerFrame, maxRows));
// starting packet number
//const int startPnum = (128 / 2) - ()
// Generate data
char imageData[DATA_BYTES];
memset(imageData, 0, DATA_BYTES);
const int pixelsPerPacket = dataSize / 2;
int pixelVal = 0;
for (int i = 0; i < npixels; ++i) {
// avoiding gain also being divided when gappixels enabled in call
// back
if (i > 0 && i % pixelsPerPacket == 0) {
++pixelVal;
}
*((uint16_t *)(imageData + i * sizeof(uint16_t))) =
virtual_image_test_mode ? 0x0FFE : (uint16_t)i;
virtual_image_test_mode ? 0x0FFE : (uint16_t)pixelVal;
}
// Send data
@ -2289,7 +2344,6 @@ void *start_timer(void *arg) {
uint64_t frameNr = 0;
getNextFrameNumber(&frameNr);
for (int iframes = 0; iframes != numFrames; ++iframes) {
usleep(transmissionDelayUs);
// check if manual stop

View File

@ -114,6 +114,9 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS };
#define DAC_MIN_MV (0)
#define DAC_MAX_MV (2500)
#define MAX_FILTER_CELL_VAL (12)
#define MIN_ROWS_PER_READOUT (8)
#define MAX_ROWS_PER_READOUT (512)
#define PARTIAL_READOUT_MULTIPLE (8) //512 rows/128packets * 2 interfaces
/* Defines in the Firmware */
#define MAX_TIMESLOT_VAL (0x1F)

View File

@ -449,6 +449,8 @@ void setDigitalIODelay(uint64_t pinMask, int delay);
// jungfrau specific - powerchip, autocompdisable, clockdiv, asictimer, clock,
// pll, flashing firmware
#ifdef JUNGFRAUD
int setPartialReadout(int value);
int getPartialReadout();
void initReadoutConfiguration();
int powerChip(int on);
int isChipConfigured();

View File

@ -4726,7 +4726,7 @@ int set_partial_readout(int file_des) {
return printSocketReadError();
LOG(logDEBUG1, ("Setting partial readout: %u\n", arg));
#ifndef EIGERD
#if !defined(EIGERD) && !defined(JUNGFRAUD)
functionNotImplemented();
#else
// only set
@ -4734,11 +4734,12 @@ int set_partial_readout(int file_des) {
if (arg <= 0 || arg > MAX_ROWS_PER_READOUT) {
ret = FAIL;
sprintf(mess,
"Could not set partial readout. Must be between 1 "
"Could not set partial readout. Must be between %d "
"and %d\n",
MAX_ROWS_PER_READOUT);
MIN_ROWS_PER_READOUT, MAX_ROWS_PER_READOUT);
LOG(logERROR, (mess));
} else {
#ifdef EIGERD
int dr = setDynamicRange(GET_FLAG);
int isTenGiga = enableTenGigabitEthernet(GET_FLAG);
unsigned int maxnl = MAX_ROWS_PER_READOUT;
@ -4753,7 +4754,16 @@ int set_partial_readout(int file_des) {
arg, dr, isTenGiga ? "enabled" : "disabled", arg, maxnp,
maxnl);
LOG(logERROR, (mess));
} else {
} else
#elif JUNGFRAU
if (arg % PARTIAL_READOUT_MULTIPLE != 0) {
ret = FAIL;
sprintf(mess,
"Could not set %d partial readout. %d must be a multiple of %d\n", arg, PARTIAL_READOUT_MULTIPLE);
LOG(logERROR, (mess));
} else
#endif
{
if (setPartialReadout(arg) == FAIL) {
ret = FAIL;
sprintf(mess, "Could not set partial readout to %d.\n", arg);
@ -4783,7 +4793,7 @@ int get_partial_readout(int file_des) {
LOG(logDEBUG1, ("Getting partial readout\n"));
#ifndef EIGERD
#if !defined(EIGERD) && !defined(JUNGFRAUD)
functionNotImplemented();
#else
// get only