eiger: deactivate at startup, hostname activates, config file for top or master, if none, reset to hardware, no binaries

This commit is contained in:
maliakal_d 2020-05-08 18:11:15 +02:00
parent 13c1f7c2d6
commit 30078d6c1f
8 changed files with 1333 additions and 1202 deletions

View File

@ -298,80 +298,97 @@ int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay) {
return OK; return OK;
} }
int Beb_SetTop(int val) { int Beb_SetTop(enum TOPINDEX ind) {
if (!Beb_activated) if (!Beb_activated)
return 0; return 0;
// mapping new memory
u_int32_t *csp0base = 0;
u_int32_t value = 0, ret = 1;
// open file pointer u_int32_t *csp0base = 0;
u_int32_t value = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) { if (fd < 0) {
LOG(logERROR, ("Set Top FAIL, could not open fd\n")); LOG(logERROR, ("Set Top FAIL, could not open fd in Beb\n"));
} else { return 0;
value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST);
switch (ind) {
case TOP_HARDWARE:
value &= ~BEB_CONFIG_OW_TOP_MSK;
break;
case OW_TOP:
value |= BEB_CONFIG_OW_TOP_MSK; value |= BEB_CONFIG_OW_TOP_MSK;
if (val) {
value |= BEB_CONFIG_TOP_MSK; value |= BEB_CONFIG_TOP_MSK;
} else { break;
case OW_BOTTOM:
value |= BEB_CONFIG_OW_TOP_MSK;
value &= ~BEB_CONFIG_TOP_MSK; value &= ~BEB_CONFIG_TOP_MSK;
break;
default:
LOG(logERROR, ("Unknown top index in Beb: %d\n", ind));
Beb_close(fd, csp0base);
return 0;
} }
char *top_names[] = {TOP_NAMES};
int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value);
if (newval != value) { if (newval != value) {
LOG(logERROR, ("Could not overwrite Top to %d\n", val)); LOG(logERROR,
} else { ("Could not set Top flag to %s in Beb\n", top_names[ind]));
ret = 0;
LOG(logINFOBLUE,
("Overwriting BEB Hardware: %s\n", (val ? "Top" : "Bottom")));
Beb_top = val;
}
}
// close file pointer
if (fd > 0)
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return 0;
}
LOG(logINFOBLUE, ("%s Top flag to %s in Beb\n",
(ind == TOP_HARDWARE ? "Resetting" : "Overwriting"),
top_names[ind]));
Beb_close(fd, csp0base);
return 1;
}
return ret; int Beb_SetMaster(enum MASTERINDEX ind) {
}
int Beb_SetMaster(int val) {
if (!Beb_activated) if (!Beb_activated)
return 0; return 0;
// mapping new memory
u_int32_t *csp0base = 0;
u_int32_t value = 0, ret = 1;
// open file pointer u_int32_t *csp0base = 0;
u_int32_t value = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) { if (fd < 0) {
LOG(logERROR, ("Set Master FAIL, could not open fd\n")); LOG(logERROR, ("Set Master FAIL, could not open fd in Beb\n"));
} else { return 0;
value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST);
value |= BEB_CONFIG_OW_MASTER_MSK;
if (val) {
value |= BEB_CONFIG_MASTER_MSK;
} else {
value &= ~BEB_CONFIG_MASTER_MSK;
} }
value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST);
switch (ind) {
case MASTER_HARDWARE:
value &= ~BEB_CONFIG_OW_MASTER_MSK;
break;
case OW_MASTER:
value |= BEB_CONFIG_OW_MASTER_MSK;
value |= BEB_CONFIG_MASTER_MSK;
break;
case OW_SLAVE:
value |= BEB_CONFIG_OW_MASTER_MSK;
value &= ~BEB_CONFIG_MASTER_MSK;
break;
default:
LOG(logERROR, ("Unknown master index in Beb: %d\n", ind));
Beb_close(fd, csp0base);
return 0;
}
char *master_names[] = {MASTER_NAMES};
int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value);
if (newval != value) { if (newval != value) {
LOG(logERROR, ("Could not overwrite Master to %d\n", val)); LOG(logERROR, ("Could not set Master flag to %s in Beb\n",
} else { master_names[ind]));
ret = 0;
LOG(logINFOBLUE,
("Overwriting BEB Hardware: %s\n", (val ? "Master" : "Slave")));
}
}
// close file pointer
if (fd > 0)
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return 0;
}
LOG(logINFOBLUE, ("%s Master flag to %s in Beb\n",
(ind == TOP_HARDWARE ? "Resetting" : "Overwriting"),
master_names[ind]));
return ret; Beb_close(fd, csp0base);
} return 1;
}
int Beb_Activate(int enable) { int Beb_Activate(int enable) {
// mapping new memory // mapping new memory
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
u_int32_t value = 0, ret = -1; u_int32_t value = 0, ret = -1;
@ -412,11 +429,11 @@ int Beb_Activate(int enable) {
Beb_activated = ret; Beb_activated = ret;
return ret; return ret;
} }
int Beb_GetActivate() { return Beb_activated; } int Beb_GetActivate() { return Beb_activated; }
int Beb_Set32bitOverflow(int val) { int Beb_Set32bitOverflow(int val) {
if (!Beb_activated) if (!Beb_activated)
return val; return val;
@ -430,7 +447,8 @@ int Beb_Set32bitOverflow(int val) {
// open file pointer // open file pointer
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) { if (fd < 0) {
LOG(logERROR, ("Could not read register to set overflow flag in 32 bit " LOG(logERROR,
("Could not read register to set overflow flag in 32 bit "
"mode. FAIL\n")); "mode. FAIL\n"));
return -1; return -1;
} else { } else {
@ -443,7 +461,8 @@ int Beb_Set32bitOverflow(int val) {
// set bit // set bit
valueread = Beb_Read32(csp0base, offset); valueread = Beb_Read32(csp0base, offset);
Beb_Write32(csp0base, offset, Beb_Write32(csp0base, offset,
valueread | ((val << FLOW_REG_OVERFLOW_32_BIT_OFST) & valueread |
((val << FLOW_REG_OVERFLOW_32_BIT_OFST) &
FLOW_REG_OVERFLOW_32_BIT_MSK)); FLOW_REG_OVERFLOW_32_BIT_MSK));
} }
@ -456,15 +475,15 @@ int Beb_Set32bitOverflow(int val) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return valueread; return valueread;
} }
int Beb_GetTenGigaFlowControl() { int Beb_GetTenGigaFlowControl() {
u_int32_t offset = FLOW_REG_OFFSET; u_int32_t offset = FLOW_REG_OFFSET;
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
LOG(logERROR, LOG(logERROR, ("Could not read register to get ten giga flow "
("Could not read register to get ten giga flow control. FAIL\n")); "control. FAIL\n"));
return -1; return -1;
} else { } else {
u_int32_t retval = Beb_Read32(csp0base, offset); u_int32_t retval = Beb_Read32(csp0base, offset);
@ -474,17 +493,17 @@ int Beb_GetTenGigaFlowControl() {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return retval; return retval;
} }
} }
int Beb_SetTenGigaFlowControl(int value) { int Beb_SetTenGigaFlowControl(int value) {
LOG(logINFO, ("Setting ten giga flow control to %d\n", value)); LOG(logINFO, ("Setting ten giga flow control to %d\n", value));
value = value == 0 ? 0 : 1; value = value == 0 ? 0 : 1;
u_int32_t offset = FLOW_REG_OFFSET; u_int32_t offset = FLOW_REG_OFFSET;
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
LOG(logERROR, LOG(logERROR, ("Could not read register to set ten giga flow "
("Could not read register to set ten giga flow control. FAIL\n")); "control. FAIL\n"));
return 0; return 0;
} else { } else {
// reset bit // reset bit
@ -501,9 +520,9 @@ int Beb_SetTenGigaFlowControl(int value) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return 1; return 1;
} }
} }
int Beb_GetTransmissionDelayFrame() { int Beb_GetTransmissionDelayFrame() {
u_int32_t offset = TXM_DELAY_FRAME_OFFSET; u_int32_t offset = TXM_DELAY_FRAME_OFFSET;
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
@ -516,12 +535,13 @@ int Beb_GetTransmissionDelayFrame() {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return retval; return retval;
} }
} }
int Beb_SetTransmissionDelayFrame(int value) { int Beb_SetTransmissionDelayFrame(int value) {
LOG(logINFO, ("Setting transmission delay frame to %d\n", value)); LOG(logINFO, ("Setting transmission delay frame to %d\n", value));
if (value < 0) { if (value < 0) {
LOG(logERROR, ("Invalid transmission delay frame value %d\n", value)); LOG(logERROR,
("Invalid transmission delay frame value %d\n", value));
return 0; return 0;
} }
u_int32_t offset = TXM_DELAY_FRAME_OFFSET; u_int32_t offset = TXM_DELAY_FRAME_OFFSET;
@ -536,44 +556,45 @@ int Beb_SetTransmissionDelayFrame(int value) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return 1; return 1;
} }
} }
int Beb_GetTransmissionDelayLeft() { int Beb_GetTransmissionDelayLeft() {
u_int32_t offset = TXM_DELAY_LEFT_OFFSET; u_int32_t offset = TXM_DELAY_LEFT_OFFSET;
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
LOG(logERROR, LOG(logERROR, ("Could not read register to get transmission delay "
("Could not read register to get transmission delay left. FAIL\n")); "left. FAIL\n"));
return -1; return -1;
} else { } else {
u_int32_t retval = Beb_Read32(csp0base, offset); u_int32_t retval = Beb_Read32(csp0base, offset);
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return retval; return retval;
} }
} }
int Beb_SetTransmissionDelayLeft(int value) { int Beb_SetTransmissionDelayLeft(int value) {
LOG(logINFO, ("Setting transmission delay left to %d\n", value)); LOG(logINFO, ("Setting transmission delay left to %d\n", value));
if (value < 0) { if (value < 0) {
LOG(logERROR, ("Invalid transmission delay left value %d\n", value)); LOG(logERROR,
("Invalid transmission delay left value %d\n", value));
return 0; return 0;
} }
u_int32_t offset = TXM_DELAY_LEFT_OFFSET; u_int32_t offset = TXM_DELAY_LEFT_OFFSET;
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
LOG(logERROR, LOG(logERROR, ("Could not read register to set transmission delay "
("Could not read register to set transmission delay left. FAIL\n")); "left. FAIL\n"));
return 0; return 0;
} else { } else {
Beb_Write32(csp0base, offset, value); Beb_Write32(csp0base, offset, value);
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return 1; return 1;
} }
} }
int Beb_GetTransmissionDelayRight() { int Beb_GetTransmissionDelayRight() {
u_int32_t offset = TXM_DELAY_RIGHT_OFFSET; u_int32_t offset = TXM_DELAY_RIGHT_OFFSET;
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
@ -586,12 +607,13 @@ int Beb_GetTransmissionDelayRight() {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return retval; return retval;
} }
} }
int Beb_SetTransmissionDelayRight(int value) { int Beb_SetTransmissionDelayRight(int value) {
LOG(logINFO, ("Setting transmission delay right to %d\n", value)); LOG(logINFO, ("Setting transmission delay right to %d\n", value));
if (value < 0) { if (value < 0) {
LOG(logERROR, ("Invalid transmission delay right value %d\n", value)); LOG(logERROR,
("Invalid transmission delay right value %d\n", value));
return 0; return 0;
} }
u_int32_t offset = TXM_DELAY_RIGHT_OFFSET; u_int32_t offset = TXM_DELAY_RIGHT_OFFSET;
@ -606,9 +628,9 @@ int Beb_SetTransmissionDelayRight(int value) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return 1; return 1;
} }
} }
int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) { int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) {
if (!Beb_activated) if (!Beb_activated)
return val; return val;
@ -630,7 +652,8 @@ int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) {
break; break;
default: default:
LOG(logERROR, ("Unrecognized mode in network parameter: %d\n", mode)); LOG(logERROR,
("Unrecognized mode in network parameter: %d\n", mode));
return -1; return -1;
} }
// open file pointer // open file pointer
@ -652,9 +675,9 @@ int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return valueread; return valueread;
} }
u_int32_t Beb_GetFirmwareRevision() { u_int32_t Beb_GetFirmwareRevision() {
// mapping new memory // mapping new memory
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
u_int32_t value = 0; u_int32_t value = 0;
@ -666,8 +689,8 @@ u_int32_t Beb_GetFirmwareRevision() {
} else { } else {
value = Beb_Read32(csp0base, FIRMWARE_VERSION_OFFSET); value = Beb_Read32(csp0base, FIRMWARE_VERSION_OFFSET);
if (!value) { if (!value) {
LOG(logERROR, LOG(logERROR, ("Firmware Revision Number does not exist in "
("Firmware Revision Number does not exist in this version\n")); "this version\n"));
} }
} }
@ -676,9 +699,9 @@ u_int32_t Beb_GetFirmwareRevision() {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return value; return value;
} }
u_int32_t Beb_GetFirmwareSoftwareAPIVersion() { u_int32_t Beb_GetFirmwareSoftwareAPIVersion() {
// mapping new memory // mapping new memory
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
u_int32_t value = 0; u_int32_t value = 0;
@ -690,7 +713,8 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion() {
} else { } else {
value = Beb_Read32(csp0base, FIRMWARESOFTWARE_API_OFFSET); value = Beb_Read32(csp0base, FIRMWARESOFTWARE_API_OFFSET);
if (!value) { if (!value) {
LOG(logERROR, ("Firmware Software API Version does not exist in " LOG(logERROR,
("Firmware Software API Version does not exist in "
"this version\n")); "this version\n"));
} }
} }
@ -700,9 +724,9 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion() {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
return value; return value;
} }
void Beb_ResetFrameNumber() { void Beb_ResetFrameNumber() {
if (!Beb_activated) if (!Beb_activated)
return; return;
@ -723,21 +747,22 @@ void Beb_ResetFrameNumber() {
// close file pointer // close file pointer
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
} }
} }
void Beb_ClearBebInfos() { void Beb_ClearBebInfos() {
// unsigned int i; // unsigned int i;
// for(i=0;i<bebInfoSize;i++) free(beb_infos[i]); // for(i=0;i<bebInfoSize;i++) free(beb_infos[i]);
bebInfoSize = 0; bebInfoSize = 0;
} }
int Beb_InitBebInfos() { // file name at some point int Beb_InitBebInfos() { // file name at some point
Beb_ClearBebInfos(); Beb_ClearBebInfos();
struct BebInfo b0; struct BebInfo b0;
BebInfo_BebInfo(&b0, 0); BebInfo_BebInfo(&b0, 0);
if (BebInfo_SetSerialAddress( if (BebInfo_SetSerialAddress(
&b0, 0xff)) { // all bebs for reset and possibly get request data? &b0,
0xff)) { // all bebs for reset and possibly get request data?
beb_infos[bebInfoSize] = b0; beb_infos[bebInfoSize] = b0;
bebInfoSize++; bebInfoSize++;
} }
@ -760,36 +785,39 @@ int Beb_InitBebInfos() { // file name at some point
bebInfoSize++; bebInfoSize++;
/* /*
//loop through file to fill vector. //loop through file to fill vector.
BebInfo* b = new BebInfo(26); BebInfo* b = new BebInfo(26);
b->SetSerialAddress(0); //0xc4000000 b->SetSerialAddress(0); //0xc4000000
b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 GbE, b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1
ip address can be acquire from the network "arp" 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, 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); everything calculable/setable beb_infos.push_back(b);
*/ */
return Beb_CheckSourceStuffBebInfo(); return Beb_CheckSourceStuffBebInfo();
} }
int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig,
char *src_mac, char *src_ip, char *src_mac, char *src_ip,
unsigned int src_port) { unsigned int src_port) {
// so that the values can be reset externally for now.... // so that the values can be reset externally for now....
unsigned int i = 1; /*Beb_GetBebInfoIndex(beb_number);*/ unsigned int i = 1; /*Beb_GetBebInfoIndex(beb_number);*/
/******* if (!i) return 0;****************************/ // i must be greater /******* if (!i) return 0;****************************/ // i must be
// than 0, zero is // greater than
// the global send // 0, zero is
BebInfo_SetHeaderInfo(&beb_infos[i], ten_gig, src_mac, src_ip, src_port); // the global
// send
BebInfo_SetHeaderInfo(&beb_infos[i], ten_gig, src_mac, src_ip,
src_port);
LOG(logINFO, ("Printing Beb info number (%d) :\n", i)); LOG(logINFO, ("Printing Beb info number (%d) :\n", i));
BebInfo_Print(&beb_infos[i]); BebInfo_Print(&beb_infos[i]);
return 1; return 1;
} }
int Beb_CheckSourceStuffBebInfo() { int Beb_CheckSourceStuffBebInfo() {
unsigned int i; unsigned int i;
for (i = 1; i < bebInfoSize; i++) { // header stuff always starts from 1 for (i = 1; i < bebInfoSize; i++) { // header stuff always starts from 1
if (!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 0, if (!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]), 0,
@ -803,23 +831,23 @@ int Beb_CheckSourceStuffBebInfo() {
} }
} }
return 1; return 1;
} }
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb) { unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb) {
/******************** if (!beb_numb) return /******************** if (!beb_numb) return
* 0;******************************/ * 0;******************************/
unsigned int i; unsigned int i;
for (i = 1; i < bebInfoSize; i++) for (i = 1; i < bebInfoSize; i++)
if (beb_numb == BebInfo_GetBebNumber(&beb_infos[i])) { if (beb_numb == BebInfo_GetBebNumber(&beb_infos[i])) {
LOG(logDEBUG1, LOG(logDEBUG1, ("*****found beb index:%d, for beb number:%d\n",
("*****found beb index:%d, for beb number:%d\n", i, beb_numb)); i, beb_numb));
return i; return i;
} }
LOG(logDEBUG1, ("*****Returning 0\n")); LOG(logDEBUG1, ("*****Returning 0\n"));
return 0; return 0;
} }
int Beb_WriteTo(unsigned int index) { int Beb_WriteTo(unsigned int index) {
if (!Beb_activated) if (!Beb_activated)
return 1; return 1;
@ -840,9 +868,9 @@ int Beb_WriteTo(unsigned int index) {
return 0; return 0;
return 1; return 1;
} }
void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d) { void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d) {
unsigned int i; unsigned int i;
if (little_endian) if (little_endian)
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
@ -852,13 +880,13 @@ void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d) {
else else
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
d[i] = (((d[i] & 0xffff) << 16) | ((d[i] & 0xffff0000) >> 16)); d[i] = (((d[i] & 0xffff) << 16) | ((d[i] & 0xffff0000) >> 16));
} }
int Beb_SetByteOrder() { return 1; } int Beb_SetByteOrder() { return 1; }
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig,
unsigned int header_number, char *dst_mac, char *dst_ip, unsigned int header_number, char *dst_mac,
unsigned int dst_port) { char *dst_ip, unsigned int dst_port) {
if (!Beb_activated) if (!Beb_activated)
return 1; return 1;
@ -879,14 +907,15 @@ int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig,
LOG(logERROR, ("Set up UDP Header FAIL\n")); LOG(logERROR, ("Set up UDP Header FAIL\n"));
} else { } else {
// read data // read data
memcpy(csp0base + header_number * 16, &udp_header, sizeof(udp_header)); memcpy(csp0base + header_number * 16, &udp_header,
sizeof(udp_header));
// close file pointer // close file pointer
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
} }
return 1; return 1;
} }
int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char *dst_mac, int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char *dst_mac,
char *dst_ip, unsigned int dst_port) { char *dst_ip, unsigned int dst_port) {
unsigned int i = 1; /*Beb_GetBebInfoIndex(beb_number);*/ unsigned int i = 1; /*Beb_GetBebInfoIndex(beb_number);*/
/***********************************if (!i) return 0; /***********************************if (!i) return 0;
@ -895,15 +924,15 @@ int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char *dst_mac,
BebInfo_GetSrcIP(&beb_infos[i], ten_gig), BebInfo_GetSrcIP(&beb_infos[i], ten_gig),
BebInfo_GetSrcPort(&beb_infos[i], ten_gig), BebInfo_GetSrcPort(&beb_infos[i], ten_gig),
dst_mac, dst_ip, dst_port); dst_mac, dst_ip, dst_port);
} }
int Beb_SetHeaderData1(char *src_mac, char *src_ip, unsigned int src_port, int Beb_SetHeaderData1(char *src_mac, char *src_ip, unsigned int src_port,
char *dst_mac, char *dst_ip, unsigned int dst_port) { char *dst_mac, char *dst_ip, unsigned int dst_port) {
/* example header*/ /* example header*/
// static unsigned int* word_ptr = new unsigned int [16]; // static unsigned int* word_ptr = new unsigned int [16];
/*static*/ /*static*/
/* /*
udp_header_type udp_header = { udp_header_type udp_header = {
{0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC {0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC
{0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC {0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC
{0x08, 0x00}, {0x08, 0x00},
@ -959,9 +988,9 @@ udp_header_type udp_header = {
Beb_send_data[i + 2] = 0; Beb_send_data[i + 2] = 0;
return 1; return 1;
} }
int Beb_SetMAC(char *mac, uint8_t *dst_ptr) { int Beb_SetMAC(char *mac, uint8_t *dst_ptr) {
char macVal[50]; char macVal[50];
strcpy(macVal, mac); strcpy(macVal, mac);
@ -980,9 +1009,9 @@ int Beb_SetMAC(char *mac, uint8_t *dst_ptr) {
i++; i++;
} }
return 1; return 1;
} }
int Beb_SetIP(char *ip, uint8_t *dst_ptr) { int Beb_SetIP(char *ip, uint8_t *dst_ptr) {
char ipVal[50]; char ipVal[50];
strcpy(ipVal, ip); strcpy(ipVal, ip);
int i = 0; int i = 0;
@ -1001,15 +1030,15 @@ int Beb_SetIP(char *ip, uint8_t *dst_ptr) {
i++; i++;
} }
return 1; return 1;
} }
int Beb_SetPortNumber(unsigned int port_number, uint8_t *dst_ptr) { int Beb_SetPortNumber(unsigned int port_number, uint8_t *dst_ptr) {
dst_ptr[0] = (port_number >> 8) & 0xff; dst_ptr[0] = (port_number >> 8) & 0xff;
dst_ptr[1] = port_number & 0xff; dst_ptr[1] = port_number & 0xff;
return 1; return 1;
} }
void Beb_AdjustIPChecksum(struct udp_header_type *ip) { void Beb_AdjustIPChecksum(struct udp_header_type * ip) {
unsigned char *cptr = (unsigned char *)ip->ver_headerlen; unsigned char *cptr = (unsigned char *)ip->ver_headerlen;
ip->ip_header_checksum[0] = 0; ip->ip_header_checksum[0] = 0;
@ -1028,12 +1057,12 @@ void Beb_AdjustIPChecksum(struct udp_header_type *ip) {
ip->ip_header_checksum[0] = (ip_checksum >> 8) & 0xff; ip->ip_header_checksum[0] = (ip_checksum >> 8) & 0xff;
ip->ip_header_checksum[1] = ip_checksum & 0xff; ip->ip_header_checksum[1] = ip_checksum & 0xff;
} }
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int Beb_SendMultiReadRequest(
int ten_gig, unsigned int dst_number, unsigned int beb_number, unsigned int left_right, int ten_gig,
unsigned int npackets, unsigned int packet_size, unsigned int dst_number, unsigned int npackets,
int stop_read_when_fifo_empty) { unsigned int packet_size, int stop_read_when_fifo_empty) {
// This is a dead function, will be removed in future // This is a dead function, will be removed in future
// ================================================== // ==================================================
@ -1075,9 +1104,9 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right,
} }
return 1; return 1;
} }
int Beb_SetUpTransferParameters(short the_bit_mode) { int Beb_SetUpTransferParameters(short the_bit_mode) {
if (the_bit_mode != 4 && the_bit_mode != 8 && the_bit_mode != 16 && if (the_bit_mode != 4 && the_bit_mode != 8 && the_bit_mode != 16 &&
the_bit_mode != 32) the_bit_mode != 32)
return 0; return 0;
@ -1087,9 +1116,9 @@ int Beb_SetUpTransferParameters(short the_bit_mode) {
// on_dst = 0; // on_dst = 0;
return 1; return 1;
} }
int Beb_StopAcquisition() { int Beb_StopAcquisition() {
if (!Beb_activated) if (!Beb_activated)
return 1; return 1;
@ -1120,9 +1149,9 @@ int Beb_StopAcquisition() {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
} }
return 1; return 1;
} }
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
unsigned int dst_number, unsigned int nimages, unsigned int dst_number, unsigned int nimages,
int test_just_send_out_packets_no_wait) { int test_just_send_out_packets_no_wait) {
if (!Beb_activated) if (!Beb_activated)
@ -1136,8 +1165,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
unsigned int nl = Beb_readNLines; unsigned int nl = Beb_readNLines;
unsigned int npackets = (nl * maxnp) / maxnl; unsigned int npackets = (nl * maxnp) / maxnl;
if ((nl * maxnp) % maxnl) { if ((nl * maxnp) % maxnl) {
LOG(logERROR, LOG(logERROR, ("Read N Lines is incorrect. Switching to Full Image "
("Read N Lines is incorrect. Switching to Full Image Readout\n")); "Readout\n"));
npackets = maxnp; npackets = maxnp;
} }
int in_two_requests = (npackets > MAX_PACKETS_PER_REQUEST) ? 1 : 0; int in_two_requests = (npackets > MAX_PACKETS_PER_REQUEST) ? 1 : 0;
@ -1148,7 +1177,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets
LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n")); LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n"));
LOG(logINFO, ("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, " LOG(logINFO,
("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, "
"Beb_bit_mode:%d, header_size:%d, nimages:%d, " "Beb_bit_mode:%d, header_size:%d, nimages:%d, "
"test_just_send_out_packets_no_wait:%d\n", "test_just_send_out_packets_no_wait:%d\n",
beb_number, ten_gig, dst_number, npackets, Beb_bit_mode, beb_number, ten_gig, dst_number, npackets, Beb_bit_mode,
@ -1222,9 +1252,9 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
{ {
int i; int i;
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
LOG(logDEBUG1, LOG(logDEBUG1, ("%X\n", Beb_Read32(csp0base,
("%X\n", Beb_Read32(csp0base, (LEFT_OFFSET +
(LEFT_OFFSET + i * 4)))); //*(ptrl+i)); i * 4)))); //*(ptrl+i));
LOG(logDEBUG1, ("%d\n", in_two_requests)); LOG(logDEBUG1, ("%d\n", in_two_requests));
} }
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
@ -1233,18 +1263,19 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
} }
return 1; return 1;
} }
int Beb_Test(unsigned int beb_number) { int Beb_Test(unsigned int beb_number) {
LOG(logINFO, ("Testing module number: %d\n", beb_number)); LOG(logINFO, ("Testing module number: %d\n", beb_number));
// int SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int // int SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int
// header_number, string dst_mac, string dst_ip, unsigned int dst_port) { // 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); // { SetUpUDPHeader(26,0,0,"60:fb:42:f4:e3:d2","129.129.205.186",22000);
unsigned int index = Beb_GetBebInfoIndex(beb_number); unsigned int index = Beb_GetBebInfoIndex(beb_number);
if (!index) { if (!index) {
LOG(logERROR, ("Error beb number (%d)not in list????\n", beb_number)); LOG(logERROR,
("Error beb number (%d)not in list????\n", beb_number));
return 0; return 0;
} }
@ -1257,22 +1288,24 @@ int Beb_Test(unsigned int beb_number) {
} }
} }
// SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, // SendMultiReadRequest(unsigned int beb_number, unsigned int
// int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned // left_right, int ten_gig, unsigned int dst_number, unsigned int
// int packet_size, int stop_read_when_fifo_empty=1); // npackets, unsigned int packet_size, int
// stop_read_when_fifo_empty=1);
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
if (!Beb_SendMultiReadRequest(beb_number, i % 3 + 1, 0, i, 1, 0, 1)) { if (!Beb_SendMultiReadRequest(beb_number, i % 3 + 1, 0, i, 1, 0,
1)) {
LOG(logERROR, ("Error requesting data....\n")); LOG(logERROR, ("Error requesting data....\n"));
return 0; return 0;
} }
} }
return 1; return 1;
} }
// Returns the FPGA temperature from the xps sysmon ip core // Returns the FPGA temperature from the xps sysmon ip core
// Temperature value is cropped and not well rounded // Temperature value is cropped and not well rounded
int Beb_GetBebFPGATemp() { int Beb_GetBebFPGATemp() {
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int temperature = 0; int temperature = 0;
@ -1284,7 +1317,8 @@ int Beb_GetBebFPGATemp() {
} else { } else {
// read data // read data
ret = Beb_Read32(csp0base, FPGA_TEMP_OFFSET); ret = Beb_Read32(csp0base, FPGA_TEMP_OFFSET);
temperature = ((((float)(ret) / 65536.0f) / 0.00198421639f) - 273.15f) * temperature =
((((float)(ret) / 65536.0f) / 0.00198421639f) - 273.15f) *
1000; // Static conversation, copied from xps sysmon 1000; // Static conversation, copied from xps sysmon
// standalone driver // standalone driver
// close file pointer // close file pointer
@ -1292,9 +1326,9 @@ int Beb_GetBebFPGATemp() {
} }
return temperature; return temperature;
} }
void Beb_SetDetectorNumber(uint32_t detid) { void Beb_SetDetectorNumber(uint32_t detid) {
if (!Beb_activated) if (!Beb_activated)
return; return;
@ -1308,9 +1342,9 @@ void Beb_SetDetectorNumber(uint32_t detid) {
} else { } else {
uint32_t value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST); uint32_t value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
value &= UDP_HEADER_X_MSK; // to keep previous x value value &= UDP_HEADER_X_MSK; // to keep previous x value
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, Beb_Write32(
value | csp0base, UDP_HEADER_A_LEFT_OFST,
((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)); value | ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_ID_MSK) != if ((value & UDP_HEADER_ID_MSK) !=
((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) { ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
@ -1318,9 +1352,9 @@ void Beb_SetDetectorNumber(uint32_t detid) {
} }
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
value &= UDP_HEADER_X_MSK; // to keep previous x value value &= UDP_HEADER_X_MSK; // to keep previous x value
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, Beb_Write32(
value | csp0base, UDP_HEADER_A_RIGHT_OFST,
((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)); value | ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_ID_MSK) != if ((value & UDP_HEADER_ID_MSK) !=
((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) { ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
@ -1329,21 +1363,21 @@ void Beb_SetDetectorNumber(uint32_t detid) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
} }
LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid)); LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid));
} }
int Beb_SetQuad(int value) { int Beb_SetQuad(int value) {
if (value < 0) if (value < 0)
return OK; return OK;
LOG(logINFO, ("Setting Quad to %d in Beb\n", value)); LOG(logINFO, ("Setting Quad to %d in Beb\n", value));
Beb_quadEnable = (value == 0 ? 0 : 1); Beb_quadEnable = (value == 0 ? 0 : 1);
return Beb_SetDetectorPosition(Beb_positions); return Beb_SetDetectorPosition(Beb_positions);
} }
int Beb_GetQuad() { return Beb_quadEnable; } int Beb_GetQuad() { return Beb_quadEnable; }
int *Beb_GetDetectorPosition() { return Beb_positions; } int *Beb_GetDetectorPosition() { return Beb_positions; }
int Beb_SetDetectorPosition(int pos[]) { int Beb_SetDetectorPosition(int pos[]) {
if (!Beb_activated) if (!Beb_activated)
return OK; return OK;
LOG(logINFO, ("Got Position values %d %d...\n", pos[0], pos[1])); LOG(logINFO, ("Got Position values %d %d...\n", pos[0], pos[1]));
@ -1377,7 +1411,8 @@ int Beb_SetDetectorPosition(int pos[]) {
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
value &= UDP_HEADER_ID_MSK; // to keep previous id value value &= UDP_HEADER_ID_MSK; // to keep previous id value
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST,
value | ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)); value |
((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_X_MSK) != if ((value & UDP_HEADER_X_MSK) !=
((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) { ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
@ -1389,7 +1424,8 @@ int Beb_SetDetectorPosition(int pos[]) {
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
value &= UDP_HEADER_ID_MSK; // to keep previous id value value &= UDP_HEADER_ID_MSK; // to keep previous id value
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST,
value | ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)); value |
((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_X_MSK) != if ((value & UDP_HEADER_X_MSK) !=
((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) { ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
@ -1402,11 +1438,13 @@ int Beb_SetDetectorPosition(int pos[]) {
value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST);
value &= UDP_HEADER_Z_MSK; // to keep previous z value value &= UDP_HEADER_Z_MSK; // to keep previous z value
Beb_Write32(csp0base, UDP_HEADER_B_LEFT_OFST, Beb_Write32(csp0base, UDP_HEADER_B_LEFT_OFST,
value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)); value |
((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST);
if ((value & UDP_HEADER_Y_MSK) != if ((value & UDP_HEADER_Y_MSK) !=
((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) { ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
LOG(logERROR, ("Could not set column position for left port\n")); LOG(logERROR,
("Could not set column position for left port\n"));
ret = FAIL; ret = FAIL;
} }
@ -1415,11 +1453,13 @@ int Beb_SetDetectorPosition(int pos[]) {
value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST);
value &= UDP_HEADER_Z_MSK; // to keep previous z value value &= UDP_HEADER_Z_MSK; // to keep previous z value
Beb_Write32(csp0base, UDP_HEADER_B_RIGHT_OFST, Beb_Write32(csp0base, UDP_HEADER_B_RIGHT_OFST,
value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)); value |
((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST);
if ((value & UDP_HEADER_Y_MSK) != if ((value & UDP_HEADER_Y_MSK) !=
((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) { ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
LOG(logERROR, ("Could not set column position for right port\n")); LOG(logERROR,
("Could not set column position for right port\n"));
ret = FAIL; ret = FAIL;
} }
@ -1434,15 +1474,15 @@ int Beb_SetDetectorPosition(int pos[]) {
} }
return ret; return ret;
} }
int Beb_SetStartingFrameNumber(uint64_t value) { int Beb_SetStartingFrameNumber(uint64_t value) {
if (!Beb_activated) { if (!Beb_activated) {
Beb_deactivatedStartFrameNumber = value; Beb_deactivatedStartFrameNumber = value;
return OK; return OK;
} }
LOG(logINFO, LOG(logINFO, ("Setting start frame number: %llu\n",
("Setting start frame number: %llu\n", (long long unsigned int)value)); (long long unsigned int)value));
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR);
@ -1464,9 +1504,9 @@ int Beb_SetStartingFrameNumber(uint64_t value) {
LOG(logINFO, ("Going to reset Frame Number\n")); LOG(logINFO, ("Going to reset Frame Number\n"));
Beb_ResetFrameNumber(); Beb_ResetFrameNumber();
return OK; return OK;
} }
int Beb_GetStartingFrameNumber(uint64_t *retval, int tengigaEnable) { int Beb_GetStartingFrameNumber(uint64_t * retval, int tengigaEnable) {
if (!Beb_activated) { if (!Beb_activated) {
*retval = Beb_deactivatedStartFrameNumber; *retval = Beb_deactivatedStartFrameNumber;
return OK; return OK;
@ -1496,13 +1536,14 @@ int Beb_GetStartingFrameNumber(uint64_t *retval, int tengigaEnable) {
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
if (left1g != right1g) { if (left1g != right1g) {
LOG(logERROR, ("Retrieved inconsistent frame numbers from 1g left " LOG(logERROR,
("Retrieved inconsistent frame numbers from 1g left "
"%llu and right %llu\n", "%llu and right %llu\n",
(long long int)left1g, (long long int)right1g)); (long long int)left1g, (long long int)right1g));
*retval = (left1g > right1g) *retval = (left1g > right1g)
? left1g ? left1g
: right1g; // give max to set it to when stopping acq : right1g; // give max to set it to when stopping
// & different value // acq & different value
return -2; // to differentiate between failed address mapping return -2; // to differentiate between failed address mapping
} }
*retval = left1g; *retval = left1g;
@ -1523,32 +1564,34 @@ int Beb_GetStartingFrameNumber(uint64_t *retval, int tengigaEnable) {
++right10g; // increment for firmware ++right10g; // increment for firmware
if (left10g != right10g) { if (left10g != right10g) {
LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left " LOG(logERROR,
("Retrieved inconsistent frame numbers from `0g left "
"%llu and right %llu\n", "%llu and right %llu\n",
(long long int)left10g, (long long int)right10g)); (long long int)left10g, (long long int)right10g));
*retval = (left10g > right10g) *retval = (left10g > right10g)
? left10g ? left10g
: right10g; // give max to set it to when stopping acq : right10g; // give max to set it to when stopping
// & different value // acq & different value
return -2; // to differentiate between failed address mapping return -2; // to differentiate between failed address mapping
} }
*retval = left10g; *retval = left10g;
} }
return OK; return OK;
} }
void Beb_SetReadNLines(int value) { Beb_readNLines = value; } void Beb_SetReadNLines(int value) { Beb_readNLines = value; }
uint16_t Beb_swap_uint16(uint16_t val) { return (val << 8) | (val >> 8); } uint16_t Beb_swap_uint16(uint16_t val) { return (val << 8) | (val >> 8); }
int Beb_open(u_int32_t **csp0base, u_int32_t offset) { int Beb_open(u_int32_t * *csp0base, u_int32_t offset) {
int fd = open("/dev/mem", O_RDWR | O_SYNC, 0); int fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) { if (fd == -1) {
LOG(logERROR, ("\nCan't find /dev/mem!\n")); LOG(logERROR, ("\nCan't find /dev/mem!\n"));
} else { } else {
LOG(logDEBUG1, ("/dev/mem opened\n")); LOG(logDEBUG1, ("/dev/mem opened\n"));
*csp0base = (u_int32_t *)mmap(0, BEB_MMAP_SIZE, PROT_READ | PROT_WRITE, *csp0base =
(u_int32_t *)mmap(0, BEB_MMAP_SIZE, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, fd, offset); MAP_FILE | MAP_SHARED, fd, offset);
if (*csp0base == MAP_FAILED) { if (*csp0base == MAP_FAILED) {
LOG(logERROR, ("\nCan't map memmory area!!\n")); LOG(logERROR, ("\nCan't map memmory area!!\n"));
@ -1557,23 +1600,24 @@ int Beb_open(u_int32_t **csp0base, u_int32_t offset) {
LOG(logDEBUG1, ("CSP0 mapped %p\n", (void *)*csp0base)); LOG(logDEBUG1, ("CSP0 mapped %p\n", (void *)*csp0base));
} }
return fd; return fd;
} }
u_int32_t Beb_Read32(u_int32_t *baseaddr, u_int32_t offset) { u_int32_t Beb_Read32(u_int32_t * baseaddr, u_int32_t offset) {
volatile u_int32_t value; volatile u_int32_t value;
value = *(u_int32_t *)(baseaddr + offset / (sizeof(u_int32_t))); value = *(u_int32_t *)(baseaddr + offset / (sizeof(u_int32_t)));
return value; return value;
} }
u_int32_t Beb_Write32(u_int32_t *baseaddr, u_int32_t offset, u_int32_t data) { u_int32_t Beb_Write32(u_int32_t * baseaddr, u_int32_t offset,
u_int32_t data) {
volatile u_int32_t *ptr1; volatile u_int32_t *ptr1;
ptr1 = (u_int32_t *)(baseaddr + offset / (sizeof(u_int32_t))); ptr1 = (u_int32_t *)(baseaddr + offset / (sizeof(u_int32_t)));
*ptr1 = data; *ptr1 = data;
return *ptr1; return *ptr1;
} }
void Beb_close(int fd, u_int32_t *csp0base) { void Beb_close(int fd, u_int32_t *csp0base) {
if (fd >= 0) if (fd >= 0)
close(fd); close(fd);
munmap(csp0base, BEB_MMAP_SIZE); munmap(csp0base, BEB_MMAP_SIZE);
} }

View File

@ -36,8 +36,8 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
void Beb_GetModuleConfiguration(int *master, int *top, int *normal); void Beb_GetModuleConfiguration(int *master, int *top, int *normal);
int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay); int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay);
int Beb_SetTop(int val); int Beb_SetTop(enum TOPINDEX ind);
int Beb_SetMaster(int val); int Beb_SetMaster(enum MASTERINDEX ind);
int Beb_Activate(int enable); int Beb_Activate(int enable);
int Beb_GetActivate(); int Beb_GetActivate();
int Beb_Set32bitOverflow(int val); int Beb_Set32bitOverflow(int val);

View File

@ -2459,7 +2459,7 @@ int Feb_Control_GetInterruptSubframe() {
return value[0]; return value[0];
} }
int Feb_Control_SetTop(int val, int left, int right) { int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right) {
uint32_t offset = DAQ_REG_HRDWRE; uint32_t offset = DAQ_REG_HRDWRE;
unsigned int addr[2] = {0, 0}; unsigned int addr[2] = {0, 0};
if (left) { if (left) {
@ -2468,68 +2468,89 @@ int Feb_Control_SetTop(int val, int left, int right) {
if (right) { if (right) {
addr[1] = Module_GetTopRightAddress(&modules[0]); addr[1] = Module_GetTopRightAddress(&modules[0]);
} }
char *top_names[] = {TOP_NAMES};
int i = 0; int i = 0;
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
if (addr[i] == 0) { if (addr[i] == 0) {
continue; continue;
} }
uint32_t regVal = 0; uint32_t value = 0;
if (!Feb_Interface_ReadRegister(addr[i], offset, &regVal)) { if (!Feb_Interface_ReadRegister(addr[i], offset, &value)) {
LOG(logERROR, ("Could not read %s DAQ_REG_HRDWRE reg\n", LOG(logERROR, ("Could not read %s Feb reg to set Top flag\n",
(i == 0 ? "left" : "right"))); (i == 0 ? "left" : "right")));
return 0; return 0;
} }
regVal |= DAQ_REG_HRDWRE_OW_TOP_MSK; switch (ind) {
if (val) { case TOP_HARDWARE:
regVal |= DAQ_REG_HRDWRE_TOP_MSK; value &= ~DAQ_REG_HRDWRE_OW_TOP_MSK;
} else { break;
regVal &= ~DAQ_REG_HRDWRE_TOP_MSK; case OW_TOP:
value |= DAQ_REG_HRDWRE_OW_TOP_MSK;
value |= DAQ_REG_HRDWRE_TOP_MSK;
break;
case OW_BOTTOM:
value |= DAQ_REG_HRDWRE_OW_TOP_MSK;
value &= ~DAQ_REG_HRDWRE_TOP_MSK;
break;
default:
LOG(logERROR, ("Unknown top index in Feb: %d\n", ind));
return 0;
} }
if (!Feb_Interface_WriteRegister(addr[i], offset, value, 0, 0)) {
if (!Feb_Interface_WriteRegister(addr[i], offset, regVal, 0, 0)) { LOG(logERROR, ("Could not set Top flag to %s in %s Feb\n", val,
LOG(logERROR, top_names[ind], (i == 0 ? "left" : "right")));
("Could not overwrite top %d to %s DAQ_REG_HRDWRE reg\n", val,
(i == 0 ? "left" : "right")));
return 0; return 0;
} }
} }
if (left && right) { if (left && right) {
LOG(logINFOBLUE, LOG(logINFOBLUE, ("%s Top flag to %s Feb\n",
("Overwriting FEB Hardware: %s\n", (val ? "Top" : "Bottom"))); (ind == TOP_HARDWARE ? "Resetting" : "Overwriting"),
top_names[ind]));
} }
return 1; return 1;
} }
int Feb_Control_SetMaster(int val) { int Feb_Control_SetMaster(enum MASTERINDEX ind) {
uint32_t offset = DAQ_REG_HRDWRE; uint32_t offset = DAQ_REG_HRDWRE;
unsigned int addr[2] = {0, 0}; unsigned int addr[2] = {0, 0};
addr[0] = Module_GetTopLeftAddress(&modules[0]); addr[0] = Module_GetTopLeftAddress(&modules[0]);
addr[1] = Module_GetTopRightAddress(&modules[0]); addr[1] = Module_GetTopRightAddress(&modules[0]);
char *master_names[] = {MASTER_NAMES};
int i = 0; int i = 0;
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
uint32_t regVal = 0; uint32_t value = 0;
if (!Feb_Interface_ReadRegister(addr[i], offset, &regVal)) { if (!Feb_Interface_ReadRegister(addr[i], offset, &value)) {
LOG(logERROR, ("Could not read %s DAQ_REG_HRDWRE reg\n", LOG(logERROR, ("Could not read %s Feb reg to set Master flag\n",
(i == 0 ? "left" : "right"))); (i == 0 ? "left" : "right")));
return 0; return 0;
} }
regVal |= DAQ_REG_HRDWRE_OW_MASTER_MSK; switch (ind) {
if (val) { case MASTER_HARDWARE:
regVal |= DAQ_REG_HRDWRE_MASTER_MSK; value &= ~DAQ_REG_HRDWRE_OW_MASTER_MSK;
} else { break;
regVal &= ~DAQ_REG_HRDWRE_MASTER_MSK; case OW_MASTER:
value |= DAQ_REG_HRDWRE_OW_MASTER_MSK;
value |= DAQ_REG_HRDWRE_MASTER_MSK;
break;
case OW_SLAVE:
value |= DAQ_REG_HRDWRE_OW_MASTER_MSK;
value &= ~DAQ_REG_HRDWRE_MASTER_MSK;
break;
default:
LOG(logERROR, ("Unknown master index in Feb: %d\n", ind));
Beb_close(fd, csp0base);
return 0;
} }
if (!Feb_Interface_WriteRegister(addr[i], offset, regVal, 0, 0)) { if (!Feb_Interface_WriteRegister(addr[i], offset, value, 0, 0)) {
LOG(logERROR, LOG(logERROR, ("Could not set Master flag to %s in %s Feb\n", val,
("Could not write master %d to %s DAQ_REG_HRDWRE reg\n", val, master_names[ind], (i == 0 ? "left" : "right")));
(i == 0 ? "left" : "right")));
return 0; return 0;
} }
} }
Feb_control_master = 1; LOG(logINFOBLUE, ("%s Master flag to %s Feb\n",
LOG(logINFOBLUE, (ind == MASTER_HARDWARE ? "Resetting" : "Overwriting"),
("Overwriting FEB Hardware: %s\n", (val ? "Master" : "Slave"))); master_names[ind]));
return 1; return 1;
} }

View File

@ -175,8 +175,8 @@ int Feb_Control_SoftwareTrigger();
int Feb_Control_SetInterruptSubframe(int val); int Feb_Control_SetInterruptSubframe(int val);
int Feb_Control_GetInterruptSubframe(); int Feb_Control_GetInterruptSubframe();
int Feb_Control_SetTop(int val, int left, int right); int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right);
int Feb_Control_SetMaster(int val); int Feb_Control_SetMaster(enum MASTERINDEX ind);
int Feb_Control_SetQuad(int val); int Feb_Control_SetQuad(int val);
int Feb_Control_SetReadNLines(int value); int Feb_Control_SetReadNLines(int value);
int Feb_Control_GetReadNLines(); int Feb_Control_GetReadNLines();

View File

@ -147,7 +147,7 @@
/** BEB Registers */ /** BEB Registers */
// module configuration - XPAR_PLB_GPIO_SYS_BASEADDR // module configuration - XPAR_PLB_GPIO_SYS_BASEADDR
#define BEB_CONFIG_OW_OFST (0x160) // 0x20 * 11 (P11) #define BEB_CONFIG_WR_OFST (0x160) // 0x20 * 11 (P11)
#define BEB_CONFIG_MASTER_OFST (0) #define BEB_CONFIG_MASTER_OFST (0)
#define BEB_CONFIG_MASTER_MSK (0x00000001 << BEB_CONFIG_MASTER_OFST) #define BEB_CONFIG_MASTER_MSK (0x00000001 << BEB_CONFIG_MASTER_OFST)
#define BEB_CONFIG_OW_MASTER_OFST (1) #define BEB_CONFIG_OW_MASTER_OFST (1)

View File

@ -1,2 +1,2 @@
top 0 top 1
master 0 master 1

View File

@ -309,6 +309,14 @@ u_int32_t getDetectorIP() {
/* initialization */ /* initialization */
void initControlServer() { void initControlServer() {
master = -1;
top = -1;
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (initError == OK) { if (initError == OK) {
getModuleConfiguration(); getModuleConfiguration();
@ -352,7 +360,15 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
master = -1;
top = -1;
#ifdef VIRTUAL #ifdef VIRTUAL
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
getModuleConfiguration(); getModuleConfiguration();
virtual_stop = 0; virtual_stop = 0;
if (!isControlServer) { if (!isControlServer) {
@ -362,6 +378,9 @@ void initStopServer() {
LOG(logINFORED, ("Deactivated!\n")); LOG(logINFORED, ("Deactivated!\n"));
return; return;
#else #else
// wait till control server has configured top/master
usleep(2 * 1000 * 1000);
getModuleConfiguration(); getModuleConfiguration();
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); Feb_Control_FebControl();
@ -382,22 +401,33 @@ void initStopServer() {
void getModuleConfiguration() { void getModuleConfiguration() {
#ifdef VIRTUAL #ifdef VIRTUAL
// if master not modified by config file
if (master == -1) {
#ifdef VIRTUAL_MASTER #ifdef VIRTUAL_MASTER
master = 1; master = 1;
top = 1;
#else #else
master = 0; master = 0;
#endif
}
// if top not modified by config file
if (top == -1) {
#ifdef VIRTUAL_MASTER
top = 1;
#else
#ifdef VIRTUAL_TOP #ifdef VIRTUAL_TOP
top = 1; top = 1;
#else #else
top = 0; top = 0;
#endif #endif
#endif #endif
}
#ifdef VIRTUAL_9M #ifdef VIRTUAL_9M
normal = 0; normal = 0;
#else #else
normal = 1; normal = 1;
#endif #endif
#else #else
// read detector id // read detector id
char output[255]; char output[255];
@ -411,10 +441,6 @@ void getModuleConfiguration() {
Beb_GetModuleConfiguration(&master, &top, &normal); Beb_GetModuleConfiguration(&master, &top, &normal);
#endif #endif
if (readConfigFile() == FAIL) {
return;
}
if (isControlServer) { if (isControlServer) {
LOG(logINFOBLUE, LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"), ("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
@ -476,7 +502,8 @@ int readConfigFile() {
break; break;
} }
#ifndef VIRTUAL #ifndef VIRTUAL
if (Beb_SetTop(top) == FAIL) { enum TOPINDEX ind = (top == 1 ? OW_TOP : OW_BOTTOM);
if (!Beb_SetTop(ind)) {
sprintf( sprintf(
initErrorMessage, initErrorMessage,
"Could not overwrite top to %d in Beb from on-board server " "Could not overwrite top to %d in Beb from on-board server "
@ -484,7 +511,7 @@ int readConfigFile() {
top, line); top, line);
break; break;
} }
if (Feb_Control_SetTop(top, 1, 1) == FAIL) { if (!Feb_Control_SetTop(ind, 1, 1)) {
sprintf( sprintf(
initErrorMessage, initErrorMessage,
"Could not overwrite top to %d in Feb from on-board server " "Could not overwrite top to %d in Feb from on-board server "
@ -506,7 +533,8 @@ int readConfigFile() {
break; break;
} }
#ifndef VIRTUAL #ifndef VIRTUAL
if (Beb_SetMaster(master) == FAIL) { enum MASTERINDEX ind = (master == 1 ? OW_MASTER : OW_SLAVE);
if (!Beb_SetMaster(ind)) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not overwrite master to %d in Beb from on-board " "Could not overwrite master to %d in Beb from on-board "
"server " "server "
@ -514,7 +542,7 @@ int readConfigFile() {
master, line); master, line);
break; break;
} }
if (Feb_Control_SetMaster(master) == FAIL) { if (!Feb_Control_SetMaster(ind)) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not overwrite master to %d in Feb from on-board " "Could not overwrite master to %d in Feb from on-board "
"server " "server "
@ -535,6 +563,39 @@ int readConfigFile() {
} }
} }
fclose(fd); fclose(fd);
// reset to hardware settings if not in config file (if overwritten)
#ifndef VIRTUAL
if (top == -1) {
if (!Beb_SetTop(TOP_HARDWARE)) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not reset Top flag to Beb hardware settings.\n");
return;
}
if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not reset Top flag to Feb hardware settings.\n");
return;
}
}
if (master == -1) {
if (!Beb_SetMaster(TOP_HARDWARE)) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not reset Master flag to Beb hardware settings.\n");
return;
}
if (!Feb_Control_SetMaster(TOP_HARDWARE)) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not reset Master flag to Feb hardware settings.\n");
return;
}
}
#endif
if (strlen(initErrorMessage)) { if (strlen(initErrorMessage)) {
initError = FAIL; initError = FAIL;
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));

View File

@ -62,6 +62,11 @@ enum ADCINDEX {
enum NETWORKINDEX { TXN_LEFT, TXN_RIGHT, TXN_FRAME, FLOWCTRL_10G }; enum NETWORKINDEX { TXN_LEFT, TXN_RIGHT, TXN_FRAME, FLOWCTRL_10G };
enum ROINDEX { E_PARALLEL, E_NON_PARALLEL }; enum ROINDEX { E_PARALLEL, E_NON_PARALLEL };
enum CLKINDEX { RUN_CLK, NUM_CLOCKS }; enum CLKINDEX { RUN_CLK, NUM_CLOCKS };
enum TOPINDEX { TOP_HARDWARE, OW_TOP, OW_BOTTOM };
#define TOP_NAMES "hardware", "top", "bottom"
enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE };
#define MASTER_NAMES "hardware", "master", "slave"
#define CLK_NAMES "run" #define CLK_NAMES "run"
/* Hardware Definitions */ /* Hardware Definitions */