mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 00:00:02 +02:00
gotthard2 and mythen3: programming fpga, reboot; jungfrau, ctb: modified programming (#74)
This commit is contained in:
parent
7d7302a90c
commit
5ca3a1b685
@ -15,7 +15,7 @@ add_executable(ctbDetectorServer_virtual
|
||||
../slsDetectorServer/src/INA226.c
|
||||
../slsDetectorServer/src/LTC2620.c
|
||||
../slsDetectorServer/src/MAX1932.c
|
||||
../slsDetectorServer/src/programfpga.c
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -12,7 +12,7 @@ DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
SRCS = slsDetectorFunctionList.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programfpga.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
|
Binary file not shown.
@ -13,7 +13,7 @@
|
||||
#include "ALTERA_PLL.h" // pll
|
||||
#include "blackfin.h"
|
||||
#ifndef VIRTUAL
|
||||
#include "programfpga.h"
|
||||
#include "programFpgaBlackfin.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
@ -10,6 +10,7 @@ add_executable(gotthard2DetectorServer_virtual
|
||||
../slsDetectorServer/src/LTC2620_Driver.c
|
||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||
../slsDetectorServer/src/ASIC_Driver.c
|
||||
../slsDetectorServer/src/programFpgaNios.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -12,7 +12,7 @@ DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
SRCS = slsDetectorFunctionList.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)common.c $(main_src)DAC6571.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)ASIC_Driver.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)common.c $(main_src)DAC6571.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)ASIC_Driver.c $(main_src)/programFpgaNios.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
|
Binary file not shown.
@ -8,7 +8,9 @@
|
||||
#include "common.h"
|
||||
#include "ALTERA_PLL_CYCLONE10.h"
|
||||
#include "ASIC_Driver.h"
|
||||
#ifdef VIRTUAL
|
||||
#ifndef VIRTUAL
|
||||
#include "programFpgaNios.h"
|
||||
#else
|
||||
#include "communication_funcs_UDP.h"
|
||||
#endif
|
||||
|
||||
@ -252,7 +254,7 @@ u_int16_t getHardwareVersionNumber() {
|
||||
#ifdef VIRTUAL
|
||||
return 0;
|
||||
#endif
|
||||
return ((bus_r(MCB_SERIAL_NO_REG)));// & HARDWARE_VERSION_NUM_MSK) >> HARDWARE_VERSION_NUM_OFST);
|
||||
return ((bus_r(MCB_SERIAL_NO_REG) & MCB_SERIAL_NO_VRSN_MSK) >> MCB_SERIAL_NO_VRSN_OFST);
|
||||
}
|
||||
|
||||
u_int32_t getDetectorNumber(){
|
||||
@ -314,10 +316,14 @@ u_int32_t getDetectorIP(){
|
||||
/* initialization */
|
||||
|
||||
void initControlServer(){
|
||||
CreateNotificationForCriticalTasks();
|
||||
if (initError == OK) {
|
||||
setupDetector();
|
||||
}
|
||||
initCheckDone = 1;
|
||||
if (initError == OK) {
|
||||
NotifyServerStartSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
void initStopServer() {
|
||||
|
Binary file not shown.
@ -10,7 +10,7 @@ add_executable(jungfrauDetectorServer_virtual
|
||||
../slsDetectorServer/src/ALTERA_PLL.c
|
||||
../slsDetectorServer/src/LTC2620.c
|
||||
../slsDetectorServer/src/MAX1932.c
|
||||
../slsDetectorServer/src/programfpga.c
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
)
|
||||
|
||||
|
@ -12,7 +12,7 @@ DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
SRCS = slsDetectorFunctionList.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programfpga.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
|
Binary file not shown.
@ -9,7 +9,7 @@
|
||||
#include "blackfin.h"
|
||||
#include "common.h"
|
||||
#ifndef VIRTUAL
|
||||
#include "programfpga.h"
|
||||
#include "programFpgaBlackfin.h"
|
||||
#else
|
||||
#include "communication_funcs_UDP.h"
|
||||
#endif
|
||||
@ -67,7 +67,6 @@ void basictests() {
|
||||
}
|
||||
return;
|
||||
#else
|
||||
|
||||
defineGPIOpins();
|
||||
resetFPGA();
|
||||
if (mapCSP0() == FAIL) {
|
||||
|
@ -12,7 +12,7 @@ add_executable(moenchDetectorServer_virtual
|
||||
../slsDetectorServer/src/ALTERA_PLL.c
|
||||
../slsDetectorServer/src/LTC2620.c
|
||||
../slsDetectorServer/src/MAX1932.c
|
||||
../slsDetectorServer/src/programfpga.c
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -12,7 +12,7 @@ DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
SRCS = slsDetectorFunctionList.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programfpga.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "ALTERA_PLL.h" // pll
|
||||
#include "blackfin.h"
|
||||
#ifndef VIRTUAL
|
||||
#include "programfpga.h"
|
||||
#include "programFpgaBlackfin.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
@ -9,6 +9,7 @@ add_executable(mythen3DetectorServer_virtual
|
||||
../slsDetectorServer/src/common.c
|
||||
../slsDetectorServer/src/LTC2620_Driver.c
|
||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||
../slsDetectorServer/src/programFpgaNios.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -12,7 +12,7 @@ DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
SRCS = slsDetectorFunctionList.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c
|
||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programFpgaNios.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
|
Binary file not shown.
@ -7,7 +7,9 @@
|
||||
#include "common.h"
|
||||
#include "RegisterDefs.h"
|
||||
#include "ALTERA_PLL_CYCLONE10.h"
|
||||
#ifdef VIRTUAL
|
||||
#ifndef VIRTUAL
|
||||
#include "programFpgaNios.h"
|
||||
#else
|
||||
#include "communication_funcs_UDP.h"
|
||||
#endif
|
||||
|
||||
@ -249,7 +251,7 @@ u_int32_t getDetectorNumber(){
|
||||
#ifdef VIRTUAL
|
||||
return 0;
|
||||
#endif
|
||||
return bus_r(MCB_SERIAL_NO_REG);
|
||||
return ((bus_r(MCB_SERIAL_NO_REG) & MCB_SERIAL_NO_VRSN_MSK) >> MCB_SERIAL_NO_VRSN_OFST);
|
||||
}
|
||||
|
||||
|
||||
@ -303,10 +305,14 @@ u_int32_t getDetectorIP(){
|
||||
/* initialization */
|
||||
|
||||
void initControlServer(){
|
||||
CreateNotificationForCriticalTasks();
|
||||
if (initError == OK) {
|
||||
setupDetector();
|
||||
}
|
||||
initCheckDone = 1;
|
||||
if (initError == OK) {
|
||||
NotifyServerStartSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
void initStopServer() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Define GPIO pins if not defined
|
||||
@ -49,4 +50,4 @@ void stopWritingFPGAprogram(FILE* filefp);
|
||||
* @param filefp pointer to flash
|
||||
* @return 0 for success, 1 for fail (cannot write)
|
||||
*/
|
||||
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp);
|
||||
int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp);
|
46
slsDetectorServers/slsDetectorServer/include/programFpgaNios.h
Executable file
46
slsDetectorServers/slsDetectorServer/include/programFpgaNios.h
Executable file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/** Notify microcontroller of successful server start up */
|
||||
void NotifyServerStartSuccess();
|
||||
|
||||
/** create notification file to notify watchdog of critical tasks (to not shutdown) */
|
||||
void CreateNotificationForCriticalTasks();
|
||||
|
||||
/** write 1 to notification file to postpone shut down process if requested*/
|
||||
void NotifyCriticalTask();
|
||||
|
||||
/** write 0 to notification file to allow shut down process if requested */
|
||||
void NotifyCriticalTaskDone();
|
||||
|
||||
/** reset fpga and controller(only implemented for >= v1.1 boards) */
|
||||
void rebootControllerAndFPGA();
|
||||
|
||||
/** finds the right mtd drive
|
||||
* @param mess error message
|
||||
* @returns ok or fail
|
||||
*/
|
||||
int findFlash(char* mess);
|
||||
|
||||
/** erase flash */
|
||||
void eraseFlash();
|
||||
|
||||
/** erase and write flash
|
||||
* @param mess error message
|
||||
* @param fpgasrc program source
|
||||
* @param fsize file size
|
||||
* @returns ok or fail
|
||||
*/
|
||||
int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize);
|
||||
|
||||
/**
|
||||
* Write FPGA Program to flash
|
||||
* @param mess error message
|
||||
* @param fpgasrc source program
|
||||
* @param fsize size of program
|
||||
* @param filefp pointer to flash
|
||||
* @return ok or fail
|
||||
*/
|
||||
int writeFPGAProgram(char* mess, char* fpgasrc, uint64_t fsize, FILE* filefp);
|
@ -366,10 +366,10 @@ int getFrequency(enum CLKINDEX ind);
|
||||
void configureSyncFrequency(enum CLKINDEX ind);
|
||||
void setPipeline(enum CLKINDEX ind, int val);
|
||||
int getPipeline(enum CLKINDEX ind);
|
||||
extern void eraseFlash(); // programfpga.h
|
||||
extern int startWritingFPGAprogram(FILE** filefp); // programfpga.h
|
||||
extern void stopWritingFPGAprogram(FILE* filefp); // programfpga.h
|
||||
extern int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp); // programfpga.h
|
||||
extern void eraseFlash(); // programFpgaBlackfin.h
|
||||
extern int startWritingFPGAprogram(FILE** filefp); // programFpgaBlackfin.h
|
||||
extern void stopWritingFPGAprogram(FILE* filefp); // programFpgaBlackfin.h
|
||||
extern int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp); // programFpgaBlackfin.h
|
||||
// patterns
|
||||
uint64_t writePatternIOControl(uint64_t word);
|
||||
uint64_t writePatternClkControl(uint64_t word);
|
||||
@ -401,10 +401,10 @@ int validatePhaseinDegrees(enum CLKINDEX ind, int val, int retval);
|
||||
int setThresholdTemperature(int val);
|
||||
int setTemperatureControl(int val);
|
||||
int setTemperatureEvent(int val);
|
||||
extern void eraseFlash(); // programfpga.h
|
||||
extern int startWritingFPGAprogram(FILE** filefp); // programfpga.h
|
||||
extern void stopWritingFPGAprogram(FILE* filefp); // programfpga.h
|
||||
extern int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp); // programfpga.h
|
||||
extern void eraseFlash(); // programFpgaBlackfin.h
|
||||
extern int startWritingFPGAprogram(FILE** filefp); // programFpgaBlackfin.h
|
||||
extern void stopWritingFPGAprogram(FILE* filefp); // programFpgaBlackfin.h
|
||||
extern int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp); // programFpgaBlackfin.h
|
||||
void alignDeserializer();
|
||||
|
||||
// eiger specific - iodelay, pulse, rate, temp, activate, delay nw parameter
|
||||
@ -480,7 +480,15 @@ enum burstMode getBurstMode();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
extern void NotifyServerStartSuccess();
|
||||
extern void CreateNotificationForCriticalTasks();
|
||||
extern void rebootControllerAndFPGA(); // programFpgaNios.h
|
||||
extern int findFlash(char* mess); // programFpgaNios.h
|
||||
extern void eraseFlash(); // programFpgaNios.h
|
||||
extern int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize); // programFpgaNios.h
|
||||
extern int writeFPGAProgram(char* mess, char* fpgasrc, uint64_t fsize, FILE* filefp); // programFpgaNios.h
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
|
@ -20,6 +20,9 @@ void validate64(int64_t arg, int64_t retval, char* modename, enum numberMode num
|
||||
int executeCommand(char* command, char* result, enum TLogLevel level);
|
||||
int M_nofunc(int);
|
||||
int M_nofuncMode(int);
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
extern void rebootControllerAndFPGA();
|
||||
#endif
|
||||
|
||||
// functions called by client
|
||||
int exec_command(int);
|
||||
|
@ -28,14 +28,14 @@ void ASIC_Driver_SetDefines(char* driverfname) {
|
||||
int ASIC_Driver_Set (int index, int length, char* buffer) {
|
||||
char fname[MAX_STR_LENGTH];
|
||||
sprintf(fname, "%s%d", ASIC_Driver_DriverFileName, index + 1);
|
||||
FILE_LOG(logDEBUG1, ("\t[chip index: %d, length: %d, fname: %s]\n", index, length, fname));
|
||||
FILE_LOG(logDEBUG2, ("\t[chip index: %d, length: %d, fname: %s]\n", index, length, fname));
|
||||
{
|
||||
FILE_LOG(logDEBUG1, ("\t[values: \n"));
|
||||
FILE_LOG(logDEBUG2, ("\t[values: \n"));
|
||||
int i;
|
||||
for (i = 0; i < length; ++i) {
|
||||
FILE_LOG(logDEBUG1, ("\t%d: 0x%02hhx\n", i, buffer[i]));
|
||||
FILE_LOG(logDEBUG2, ("\t%d: 0x%02hhx\n", i, buffer[i]));
|
||||
}
|
||||
FILE_LOG(logDEBUG1, ("\t]\n"));
|
||||
FILE_LOG(logDEBUG2, ("\t]\n"));
|
||||
}
|
||||
|
||||
#ifdef VIRTUAL
|
||||
|
@ -252,8 +252,9 @@ void closeConnection(int file_des) {
|
||||
}
|
||||
|
||||
void exitServer(int socketDescriptor) {
|
||||
if (socketDescriptor >= 0)
|
||||
if (socketDescriptor >= 0) {
|
||||
close(socketDescriptor);
|
||||
}
|
||||
FILE_LOG(logINFO, ("Closing %s server\n", (isControlServer ? "control":"stop")));
|
||||
FD_CLR(socketDescriptor, &readset);
|
||||
isock--;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "programfpga.h"
|
||||
#include "programFpgaBlackfin.h"
|
||||
#include "ansi.h"
|
||||
#include "clogger.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
@ -57,6 +57,12 @@ int startWritingFPGAprogram(FILE** filefp){
|
||||
FILE_LOG(logDEBUG1, ("Start Writing of FPGA program\n"));
|
||||
|
||||
//getting the drive
|
||||
//root:/> cat /proc/mtd
|
||||
//dev: size erasesize name
|
||||
//mtd0: 00040000 00020000 "bootloader(nor)"
|
||||
//mtd1: 00100000 00020000 "linux kernel(nor)"
|
||||
//mtd2: 002c0000 00020000 "file system(nor)"
|
||||
//mtd3: 01000000 00010000 "bitfile(spi)"
|
||||
char output[255];
|
||||
memset(output, 0, 255);
|
||||
FILE* fp = popen("awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
|
||||
@ -120,14 +126,14 @@ void stopWritingFPGAprogram(FILE* filefp){
|
||||
FILE_LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
||||
}
|
||||
|
||||
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp){
|
||||
int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp){
|
||||
FILE_LOG(logDEBUG1, ("Writing of FPGA Program\n"
|
||||
"\taddress of fpgasrc:%p\n"
|
||||
"\tfsize:%lu\n\tpointer:%p\n",
|
||||
(void *)fpgasrc, fsize, (void*)filefp));
|
||||
"\tfsize:%llu\n\tpointer:%p\n",
|
||||
(void *)fpgasrc, (long long unsigned int)fsize, (void*)filefp));
|
||||
|
||||
if(fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp )!= fsize){
|
||||
FILE_LOG(logERROR, ("Could not write FPGA source to flash (size:%lu)\n", fsize));
|
||||
FILE_LOG(logERROR, ("Could not write FPGA source to flash (size:%llu)\n", (long long unsigned int)fsize));
|
||||
return 1;
|
||||
}
|
||||
FILE_LOG(logDEBUG1, ("program written to flash\n"));
|
152
slsDetectorServers/slsDetectorServer/src/programFpgaNios.c
Executable file
152
slsDetectorServers/slsDetectorServer/src/programFpgaNios.c
Executable file
@ -0,0 +1,152 @@
|
||||
#include "programFpgaNios.h"
|
||||
#include "ansi.h"
|
||||
#include "clogger.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include <unistd.h> // usleep
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* global variables */
|
||||
#define MTDSIZE 10
|
||||
char mtdvalue[MTDSIZE] = {0};
|
||||
#define NOTIFICATION_FILE "/tmp/block_shutdown"
|
||||
#define MICROCONTROLLER_FILE "/dev/ttyAL0"
|
||||
|
||||
void NotifyServerStartSuccess() {
|
||||
FILE_LOG(logINFOBLUE, ("Server started successfully\n"));
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"echo r > %s",MICROCONTROLLER_FILE);
|
||||
system(command);
|
||||
}
|
||||
|
||||
void CreateNotificationForCriticalTasks() {
|
||||
FILE* fd = fopen(NOTIFICATION_FILE, "r");
|
||||
if (fd == NULL) {
|
||||
fd = fopen(NOTIFICATION_FILE, "w");
|
||||
if (fd == NULL) {
|
||||
FILE_LOG(logERROR, ("Could not create notication file: %s\n", NOTIFICATION_FILE));
|
||||
return;
|
||||
}
|
||||
FILE_LOG(logINFOBLUE, ("Created notification file: %s\n", NOTIFICATION_FILE));
|
||||
}
|
||||
fclose(fd);
|
||||
NotifyCriticalTaskDone();
|
||||
}
|
||||
|
||||
void NotifyCriticalTask() {
|
||||
FILE_LOG(logINFO, ("\tNotifying Critical Task Ongoing\n"));
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"echo 1 > %s",NOTIFICATION_FILE);
|
||||
system(command);
|
||||
}
|
||||
|
||||
void NotifyCriticalTaskDone() {
|
||||
FILE_LOG(logINFO, ("\tNotifying Critical Task Done\n"));
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"echo 0 > %s",NOTIFICATION_FILE);
|
||||
system(command);
|
||||
}
|
||||
|
||||
void rebootControllerAndFPGA() {
|
||||
FILE_LOG(logDEBUG1, ("Reseting FPGA...\n"));
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"echo z > %s",MICROCONTROLLER_FILE);
|
||||
system(command);
|
||||
}
|
||||
|
||||
int findFlash(char* mess) {
|
||||
FILE_LOG(logDEBUG1, ("Finding flash drive...\n"));
|
||||
//getting the drive
|
||||
// # cat /proc/mtd
|
||||
// dev: size erasesize name
|
||||
// mtd0: 00580000 00010000 "qspi BootInfo + Factory Image"
|
||||
// mtd1: 00580000 00010000 "qspi Application Image"
|
||||
// mtd2: 00800000 00010000 "qspi Linux Kernel with initramfs"
|
||||
// mtd3: 00800000 00010000 "qspi Linux Kernel with initramfs Backup"
|
||||
// mtd4: 02500000 00010000 "qspi ubi filesystem"
|
||||
// mtd5: 04000000 00010000 "qspi Complete Flash"
|
||||
char output[255];
|
||||
memset(output, 0, 255);
|
||||
FILE* fp = popen("awk \'$5== \"Application\" {print $1}\' /proc/mtd", "r");
|
||||
if (fp == NULL) {
|
||||
strcpy(mess, "popen returned NULL. Need that to get mtd drive.\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
return RO_TRIGGER_IN_FALLING_EDGE;
|
||||
}
|
||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||
strcpy(mess, "fgets returned NULL. Need that to get mtd drive.\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
pclose(fp);
|
||||
memset(mtdvalue, 0, MTDSIZE);
|
||||
strcpy(mtdvalue, "/dev/");
|
||||
char* pch = strtok(output, ":");
|
||||
if (pch == NULL){
|
||||
strcpy (mess, "Could not get mtd value\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
strcat(mtdvalue, pch);
|
||||
FILE_LOG(logINFO, ("\tFlash drive found: %s\n", mtdvalue));
|
||||
return OK;
|
||||
}
|
||||
|
||||
void eraseFlash() {
|
||||
FILE_LOG(logDEBUG1, ("Erasing Flash...\n"));
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"flash_erase %s 0 0",mtdvalue);
|
||||
system(command);
|
||||
FILE_LOG(logINFO, ("\tFlash erased\n"));
|
||||
}
|
||||
|
||||
int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize) {
|
||||
if (findFlash(mess) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
NotifyCriticalTask();
|
||||
eraseFlash();
|
||||
|
||||
// open file pointer to flash
|
||||
FILE *filefp = fopen(mtdvalue, "w");
|
||||
if(filefp == NULL){
|
||||
NotifyCriticalTaskDone();
|
||||
sprintf (mess, "Unable to open %s in write mode\n", mtdvalue);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
FILE_LOG(logINFO, ("\tFlash ready for writing\n"));
|
||||
|
||||
// write to flash
|
||||
if (writeFPGAProgram(mess, fpgasrc, fsize, filefp) == FAIL) {
|
||||
NotifyCriticalTaskDone();
|
||||
fclose(filefp);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
fclose(filefp);
|
||||
NotifyCriticalTaskDone();
|
||||
return OK;
|
||||
}
|
||||
|
||||
int writeFPGAProgram(char* mess, char* fpgasrc, uint64_t fsize, FILE* filefp) {
|
||||
FILE_LOG(logDEBUG1, ("Writing to flash...\n"
|
||||
"\taddress of fpgasrc:%p\n"
|
||||
"\tfsize:%lu\n\tpointer:%p\n",
|
||||
(void *)fpgasrc, fsize, (void*)filefp));
|
||||
|
||||
uint64_t retval = fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp);
|
||||
if (retval != fsize) {
|
||||
sprintf (mess, "Could not write FPGA source to flash (size:%llu), write %llu\n", (long long unsigned int) fsize, (long long unsigned int)retval);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
FILE_LOG(logINFO, ("\tProgram written to flash\n"));
|
||||
return OK;
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
// Global variables from communication_funcs
|
||||
extern int isControlServer;
|
||||
@ -149,9 +149,13 @@ int main(int argc, char *argv[]){
|
||||
exitServer(sockfd);
|
||||
|
||||
if (retval == REBOOT) {
|
||||
FILE_LOG(logINFOBLUE,("Rebooting!\n"));
|
||||
FILE_LOG(logINFORED,("Rebooting!\n"));
|
||||
fflush(stdout);
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
rebootControllerAndFPGA();
|
||||
#else
|
||||
system("reboot");
|
||||
#endif
|
||||
}
|
||||
FILE_LOG(logINFO,("Goodbye!\n"));
|
||||
return 0;
|
||||
|
@ -2587,7 +2587,7 @@ int set_dynamic_range(int file_des) {
|
||||
#elif EIGERD
|
||||
case 4: case 8: case 16: case 32:
|
||||
#endif
|
||||
#if defined(GOTTHARD) || defined(JUNGFRAU) || defined(CHIPTESTBOARD) || defined(MOENCH) || defined(GOTTHARD2)
|
||||
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(GOTTHARD2D)
|
||||
case 16:
|
||||
#endif
|
||||
retval = setDynamicRange(dr);
|
||||
@ -3710,7 +3710,7 @@ int program_fpga(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
#if defined(EIGERD) || defined(GOTTHARDD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
#if defined(EIGERD) || defined(GOTTHARDD)
|
||||
//to receive any arguments
|
||||
int n = 1;
|
||||
while (n > 0)
|
||||
@ -3723,9 +3723,30 @@ int program_fpga(int file_des) {
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("Programming FPGA...\n"));
|
||||
|
||||
size_t filesize = 0;
|
||||
size_t totalsize = 0;
|
||||
size_t unitprogramsize = 0;
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
uint64_t filesize = 0;
|
||||
// filesize
|
||||
if (receiveData(file_des,&filesize,sizeof(filesize),INT64) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Total program size is: %lld\n", (long long unsigned int)filesize));
|
||||
|
||||
// receive program
|
||||
char* fpgasrc = (char*)malloc(filesize);
|
||||
if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0)
|
||||
return printSocketReadError();
|
||||
|
||||
ret = eraseAndWriteToFlash(mess, fpgasrc, filesize);
|
||||
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
||||
|
||||
//free resources
|
||||
if (fpgasrc != NULL)
|
||||
free(fpgasrc);
|
||||
|
||||
|
||||
#else // jungfrau, ctb, moench
|
||||
uint64_t filesize = 0;
|
||||
uint64_t totalsize = 0;
|
||||
uint64_t unitprogramsize = 0;
|
||||
char* fpgasrc = NULL;
|
||||
FILE* fp = NULL;
|
||||
|
||||
@ -3733,7 +3754,7 @@ int program_fpga(int file_des) {
|
||||
if (receiveData(file_des,&filesize,sizeof(filesize),INT32) < 0)
|
||||
return printSocketReadError();
|
||||
totalsize = filesize;
|
||||
FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize));
|
||||
FILE_LOG(logDEBUG1, ("Total program size is: %lld\n", (long long unsigned int)totalsize));
|
||||
|
||||
|
||||
// opening file pointer to flash and telling FPGA to not touch flash
|
||||
@ -3758,7 +3779,7 @@ int program_fpga(int file_des) {
|
||||
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
|
||||
if (unitprogramsize > filesize) //less than 2mb
|
||||
unitprogramsize = filesize;
|
||||
FILE_LOG(logDEBUG1, ("unit size to receive is:%d\nfilesize:%d\n", unitprogramsize, filesize));
|
||||
FILE_LOG(logDEBUG1, ("unit size to receive is:%lld\nfilesize:%lld\n", (long long unsigned int)unitprogramsize, (long long unsigned int)filesize));
|
||||
|
||||
//receive part of program
|
||||
if (receiveData(file_des,fpgasrc,unitprogramsize,OTHER) < 0)
|
||||
@ -3783,7 +3804,6 @@ int program_fpga(int file_des) {
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
if (ret == OK) {
|
||||
FILE_LOG(logINFO, ("Done copying program\n"));
|
||||
}
|
||||
@ -3797,8 +3817,13 @@ int program_fpga(int file_des) {
|
||||
if (fp != NULL)
|
||||
fclose(fp);
|
||||
|
||||
FILE_LOG(logINFO, ("Completed program fpga command with %s\n", (ret == OK ? "success" : "fail")));
|
||||
}
|
||||
#endif
|
||||
if (ret == FAIL) {
|
||||
FILE_LOG(logINFORED, ("Program FPGA fail!\n"));
|
||||
} else {
|
||||
FILE_LOG(logINFOGREEN, ("Programming FPGA completed successfully\n"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return ret;
|
||||
@ -4301,13 +4326,22 @@ int copy_detector_server(int file_des) {
|
||||
int reboot_controller(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
#ifdef EIGERD
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
if (getHardwareVersionNumber() == 0) {
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Old board version, reboot by yourself please!\n");
|
||||
FILE_LOG(logINFORED, (mess));
|
||||
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
||||
return GOODBYE;
|
||||
}
|
||||
ret = REBOOT;
|
||||
#elif EIGERD
|
||||
functionNotImplemented();
|
||||
return ret;
|
||||
#else
|
||||
FILE_LOG(logINFORED, ("Rebooting controller\n"));
|
||||
return REBOOT;
|
||||
ret = REBOOT;
|
||||
#endif
|
||||
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1216,7 +1216,9 @@ class Detector {
|
||||
* *
|
||||
* ************************************************/
|
||||
|
||||
/** [Jungfrau][CTB] */
|
||||
/** [Jungfrau][CTB] fname is a pof file
|
||||
* [Mythen3][Gotthard2] fname is an rbf file
|
||||
*/
|
||||
void programFPGA(const std::string &fname, Positions pos = {});
|
||||
|
||||
/** [Jungfrau][CTB] */
|
||||
@ -1229,7 +1231,7 @@ class Detector {
|
||||
void copyDetectorServer(const std::string &fname,
|
||||
const std::string &hostname, Positions pos = {});
|
||||
|
||||
/** [Jungfrau][Gotthard][CTB] */
|
||||
/** [Jungfrau][Gotthard][CTB][Mythen3][Gotthard2] */
|
||||
void rebootController(Positions pos = {});
|
||||
|
||||
/**
|
||||
|
@ -1807,7 +1807,8 @@ std::string CmdProxy::ProgramFpga(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[fname.pof]\n\t[Jungfrau][Ctb] Programs FPGA from pof file."
|
||||
os << "[fname.pof | fname.rbf]\n\t[Jungfrau][Ctb] Programs FPGA from pof file."
|
||||
<< "\n\t[Mythen3][Gotthard2] Programs FPGA from rbf file."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
throw sls::RuntimeError("Cannot get");
|
||||
@ -1815,9 +1816,6 @@ std::string CmdProxy::ProgramFpga(int action) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
if (args[0].find(".pof") == std::string::npos) {
|
||||
throw sls::RuntimeError("Programming file must be a pof file.");
|
||||
}
|
||||
det->programFPGA(args[0], {det_id});
|
||||
os << "successful\n";
|
||||
} else {
|
||||
|
@ -1696,7 +1696,7 @@ class CmdProxy {
|
||||
"\n\t[Jungfrau][Ctb] Reset FPGA.");
|
||||
|
||||
EXECUTE_SET_COMMAND(rebootcontroller, rebootController,
|
||||
"\n\t[Jungfrau][Ctb] Reboot controler (blackfin) of detector.");
|
||||
"\n\t[Jungfrau][Ctb][Gotthard][Mythen3][Gotthard2] Reboot controler (blackfin) of detector.");
|
||||
|
||||
EXECUTE_SET_COMMAND(firmwaretest, executeFirmwareTest,
|
||||
"\n\t[Jungfrau][Gotthard][Mythen3][Gotthard2][Ctb] Firmware test, ie. reads a read fixed pattern from a register.");
|
||||
|
@ -1652,9 +1652,7 @@ void Detector::setDetectorMode(defs::detectorModeType value, Positions pos) {
|
||||
// Advanced
|
||||
|
||||
void Detector::programFPGA(const std::string &fname, Positions pos) {
|
||||
FILE_LOG(logINFO)
|
||||
<< "Updating Firmware. This can take awhile. Please be patient...";
|
||||
std::vector<char> buffer = pimpl->readPofFile(fname);
|
||||
std::vector<char> buffer = pimpl->readProgrammingFile(fname);
|
||||
pimpl->Parallel(&slsDetector::programFPGA, pos, buffer);
|
||||
}
|
||||
|
||||
|
@ -1156,11 +1156,34 @@ int multiSlsDetector::kbhit() {
|
||||
return FD_ISSET(STDIN_FILENO, &fds);
|
||||
}
|
||||
|
||||
std::vector<char> multiSlsDetector::readPofFile(const std::string &fname) {
|
||||
std::vector<char> multiSlsDetector::readProgrammingFile(const std::string &fname) {
|
||||
// validate type of file
|
||||
bool isPof = false;
|
||||
switch (multi_shm()->multiDetectorType) {
|
||||
case JUNGFRAU:
|
||||
case CHIPTESTBOARD:
|
||||
if (fname.find(".pof") == std::string::npos) {
|
||||
throw RuntimeError("Programming file must be a pof file.");
|
||||
}
|
||||
isPof = true;
|
||||
break;
|
||||
case MYTHEN3:
|
||||
case GOTTHARD2:
|
||||
if (fname.find(".rbf") == std::string::npos) {
|
||||
throw RuntimeError("Programming file must be an rbf file.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw RuntimeError("Not implemented for this detector");
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO)
|
||||
<< "Updating Firmware. This can take awhile. Please be patient...";
|
||||
FILE_LOG(logDEBUG1) << "Programming FPGA with file name:" << fname;
|
||||
|
||||
|
||||
size_t filesize = 0;
|
||||
// check if it exists
|
||||
|
||||
struct stat st;
|
||||
if (stat(fname.c_str(), &st) != 0) {
|
||||
throw RuntimeError("Program FPGA: Programming file does not exist");
|
||||
@ -1188,35 +1211,50 @@ std::vector<char> multiSlsDetector::readPofFile(const std::string &fname) {
|
||||
// convert src to dst rawbin
|
||||
FILE_LOG(logDEBUG1) << "Converting " << fname << " to " << destfname;
|
||||
{
|
||||
int filepos, x, y, i;
|
||||
// Remove header (0...11C)
|
||||
for (filepos = 0; filepos < 0x11C; ++filepos) {
|
||||
fgetc(src);
|
||||
}
|
||||
// Write 0x80 times 0xFF (0...7F)
|
||||
{
|
||||
char c = 0xFF;
|
||||
for (filepos = 0; filepos < 0x80; ++filepos) {
|
||||
write(dst, &c, 1);
|
||||
const int pofNumHeaderBytes = 0x11C;
|
||||
const int pofNumPadding = 0x80;
|
||||
const int pofFooterOfst = 0x1000000;
|
||||
int dstFilePos = 0;
|
||||
if (isPof) {
|
||||
// Read header and discard
|
||||
for (int i = 0; i < pofNumHeaderBytes; ++i) {
|
||||
fgetc(src);
|
||||
}
|
||||
// Write 0xFF to destination 0x80 times (padding)
|
||||
{
|
||||
char c = 0xFF;
|
||||
while (dstFilePos < pofNumPadding) {
|
||||
write(dst, &c, 1);
|
||||
++dstFilePos;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Swap bits and write to file
|
||||
for (filepos = 0x80; filepos < 0x1000000; ++filepos) {
|
||||
x = fgetc(src);
|
||||
if (x < 0) {
|
||||
// Swap bits from source and write to dest
|
||||
while (!feof(src)) {
|
||||
// pof: exit early to discard footer
|
||||
if (isPof && dstFilePos >= pofFooterOfst) {
|
||||
break;
|
||||
}
|
||||
y = 0;
|
||||
for (i = 0; i < 8; ++i) {
|
||||
y = y |
|
||||
(((x & (1 << i)) >> i) << (7 - i)); // This swaps the bits
|
||||
// read source
|
||||
int s = fgetc(src);
|
||||
if (s < 0) {
|
||||
break;
|
||||
}
|
||||
// swap bits
|
||||
int d = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
d = d |
|
||||
(((s & (1 << i)) >> i) << (7 - i));
|
||||
}
|
||||
write(dst, &y, 1);
|
||||
write(dst, &d, 1);
|
||||
++dstFilePos;
|
||||
}
|
||||
if (filepos < 0x1000000) {
|
||||
// validate pof: read less than footer offset
|
||||
if (isPof && dstFilePos < pofFooterOfst) {
|
||||
throw RuntimeError(
|
||||
"Could not convert programming file. EOF before end of flash");
|
||||
}
|
||||
|
||||
}
|
||||
if (fclose(src) != 0) {
|
||||
throw RuntimeError("Program FPGA: Could not close source file");
|
||||
|
@ -323,11 +323,13 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
||||
|
||||
/**
|
||||
* Convert raw file
|
||||
* @param fname name of pof file
|
||||
* @param fpgasrc pointer in memory to read pof to
|
||||
* [Jungfrau][Ctb] from pof file
|
||||
* [Mythen3][Gotthard2] from rbf file
|
||||
* @param fname name of pof/rbf file
|
||||
* @param fpgasrc pointer in memory to read programming file to
|
||||
* @returns file size
|
||||
*/
|
||||
std::vector<char> readPofFile(const std::string &fname);
|
||||
std::vector<char> readProgrammingFile(const std::string &fname);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -2888,23 +2888,28 @@ int slsDetector::setStoragecellStart(int pos) {
|
||||
}
|
||||
|
||||
void slsDetector::programFPGA(std::vector<char> buffer) {
|
||||
// validate type
|
||||
switch (shm()->myDetectorType) {
|
||||
case JUNGFRAU:
|
||||
case CHIPTESTBOARD:
|
||||
case MOENCH:
|
||||
programFPGAviaBlackfin(buffer);
|
||||
break;
|
||||
case MYTHEN3:
|
||||
case GOTTHARD2:
|
||||
programFPGAviaNios(buffer);
|
||||
break;
|
||||
default:
|
||||
throw RuntimeError("Program FPGA is not implemented for this detector");
|
||||
}
|
||||
}
|
||||
|
||||
size_t filesize = buffer.size();
|
||||
void slsDetector::programFPGAviaBlackfin(std::vector<char> buffer) {
|
||||
uint64_t filesize = buffer.size();
|
||||
|
||||
// send program from memory to detector
|
||||
int fnum = F_PROGRAM_FPGA;
|
||||
int ret = FAIL;
|
||||
char mess[MAX_STR_LENGTH] = {0};
|
||||
FILE_LOG(logINFO) << "Sending programming binary to detector " << detId
|
||||
FILE_LOG(logINFO) << "Sending programming binary (from pof) to detector " << detId
|
||||
<< " (" << shm()->hostname << ")";
|
||||
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
@ -2921,35 +2926,34 @@ void slsDetector::programFPGA(std::vector<char> buffer) {
|
||||
}
|
||||
|
||||
// erasing flash
|
||||
if (ret != FAIL) {
|
||||
FILE_LOG(logINFO) << "Erasing Flash for detector " << detId << " ("
|
||||
<< shm()->hostname << ")";
|
||||
printf("%d%%\r", 0);
|
||||
std::cout << std::flush;
|
||||
// erasing takes 65 seconds, printing here (otherwise need threads
|
||||
// in server-unnecessary)
|
||||
const int ERASE_TIME = 65;
|
||||
int count = ERASE_TIME + 1;
|
||||
while (count > 0) {
|
||||
usleep(1 * 1000 * 1000);
|
||||
--count;
|
||||
printf("%d%%\r",
|
||||
static_cast<int>(
|
||||
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) *
|
||||
100));
|
||||
std::cout << std::flush;
|
||||
}
|
||||
printf("\n");
|
||||
FILE_LOG(logINFO) << "Writing to Flash to detector " << detId << " ("
|
||||
<< shm()->hostname << ")";
|
||||
printf("%d%%\r", 0);
|
||||
FILE_LOG(logINFO) << "Erasing Flash for detector " << detId << " ("
|
||||
<< shm()->hostname << ")";
|
||||
printf("%d%%\r", 0);
|
||||
std::cout << std::flush;
|
||||
// erasing takes 65 seconds, printing here (otherwise need threads
|
||||
// in server-unnecessary)
|
||||
const int ERASE_TIME = 65;
|
||||
int count = ERASE_TIME + 1;
|
||||
while (count > 0) {
|
||||
usleep(1 * 1000 * 1000);
|
||||
--count;
|
||||
printf("%d%%\r",
|
||||
static_cast<int>(
|
||||
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) *
|
||||
100));
|
||||
std::cout << std::flush;
|
||||
}
|
||||
printf("\n");
|
||||
FILE_LOG(logINFO) << "Writing to Flash to detector " << detId << " ("
|
||||
<< shm()->hostname << ")";
|
||||
printf("%d%%\r", 0);
|
||||
std::cout << std::flush;
|
||||
|
||||
// sending program in parts of 2mb each
|
||||
size_t unitprogramsize = 0;
|
||||
|
||||
// sending program in parts of 2mb each
|
||||
uint64_t unitprogramsize = 0;
|
||||
int currentPointer = 0;
|
||||
size_t totalsize = filesize;
|
||||
uint64_t totalsize = filesize;
|
||||
while (filesize > 0) {
|
||||
unitprogramsize = MAX_FPGAPROGRAMSIZE; // 2mb
|
||||
if (unitprogramsize > filesize) { // less than 2mb
|
||||
@ -2967,19 +2971,46 @@ void slsDetector::programFPGA(std::vector<char> buffer) {
|
||||
os << "Detector " << detId << " (" << shm()->hostname << ")"
|
||||
<< " returned error: " << mess;
|
||||
throw RuntimeError(os.str());
|
||||
} else {
|
||||
filesize -= unitprogramsize;
|
||||
currentPointer += unitprogramsize;
|
||||
|
||||
// print progress
|
||||
printf("%d%%\r",
|
||||
static_cast<int>(
|
||||
(static_cast<double>(totalsize - filesize) / totalsize) *
|
||||
100));
|
||||
std::cout << std::flush;
|
||||
}
|
||||
filesize -= unitprogramsize;
|
||||
currentPointer += unitprogramsize;
|
||||
|
||||
// print progress
|
||||
printf("%d%%\r",
|
||||
static_cast<int>(
|
||||
(static_cast<double>(totalsize - filesize) / totalsize) *
|
||||
100));
|
||||
std::cout << std::flush;
|
||||
}
|
||||
printf("\n");
|
||||
FILE_LOG(logINFO) << "FPGA programmed successfully";
|
||||
rebootController();
|
||||
}
|
||||
|
||||
void slsDetector::programFPGAviaNios(std::vector<char> buffer) {
|
||||
uint64_t filesize = buffer.size();
|
||||
|
||||
// send program from memory to detector
|
||||
int fnum = F_PROGRAM_FPGA;
|
||||
int ret = FAIL;
|
||||
char mess[MAX_STR_LENGTH] = {0};
|
||||
FILE_LOG(logINFO) << "Sending programming binary (from rbf) to detector " << detId
|
||||
<< " (" << shm()->hostname << ")";
|
||||
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Send(&filesize, sizeof(filesize));
|
||||
client.Send(&buffer[0], filesize);
|
||||
client.Receive(&ret, sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
printf("\n");
|
||||
client.Receive(mess, sizeof(mess));
|
||||
std::ostringstream os;
|
||||
os << "Detector " << detId << " (" << shm()->hostname << ")"
|
||||
<< " returned error: " << mess;
|
||||
throw RuntimeError(os.str());
|
||||
}
|
||||
FILE_LOG(logINFO) << "FPGA programmed successfully";
|
||||
rebootController();
|
||||
}
|
||||
|
||||
@ -2999,15 +3030,9 @@ void slsDetector::copyDetectorServer(const std::string &fname,
|
||||
}
|
||||
|
||||
void slsDetector::rebootController() {
|
||||
if (shm()->myDetectorType == EIGER) {
|
||||
throw RuntimeError(
|
||||
"Reboot controller not implemented for this detector");
|
||||
}
|
||||
int fnum = F_REBOOT_CONTROLLER;
|
||||
FILE_LOG(logINFO) << "Sending reboot controller to detector " << detId
|
||||
<< " (" << shm()->hostname << ")";
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
FILE_LOG(logDEBUG1) << "Rebooting Controller";
|
||||
sendToDetector(F_REBOOT_CONTROLLER, nullptr, nullptr);
|
||||
FILE_LOG(logINFO) << "Controller rebooted successfully!";
|
||||
}
|
||||
|
||||
int slsDetector::powerChip(int ival) {
|
||||
|
@ -1382,11 +1382,17 @@ class slsDetector : public virtual slsDetectorDefs {
|
||||
int setStoragecellStart(int pos = -1);
|
||||
|
||||
/**
|
||||
* Programs FPGA with pof file (Jungfrau, CTB, Moench)
|
||||
* [Jungfau][Ctb] Programs FPGA with raw file from pof file
|
||||
* [Mythen3][Gotthard2] Programs FPGA with raw file from rbf file
|
||||
* @param buffer programming file in memory
|
||||
*/
|
||||
void programFPGA(std::vector<char> buffer);
|
||||
|
||||
/** [Jungfau][Ctb] */
|
||||
void programFPGAviaBlackfin(std::vector<char> buffer);
|
||||
|
||||
/** [Mythen3][Gotthard2] */
|
||||
void programFPGAviaNios(std::vector<char> buffer);
|
||||
/**
|
||||
* Resets FPGA (Jungfrau)
|
||||
*/
|
||||
@ -1401,6 +1407,7 @@ class slsDetector : public virtual slsDetectorDefs {
|
||||
const std::string &hostname);
|
||||
|
||||
/**
|
||||
* [Jungfrau][Ctb][Gotthard][Mythen3][Gotthard2]
|
||||
* Reboot detector controller (blackfin/ powerpc)
|
||||
*/
|
||||
void rebootController();
|
||||
|
@ -4,9 +4,9 @@
|
||||
#define APIRECEIVER 0x190722
|
||||
#define APIGUI 0x190723
|
||||
#define APIMOENCH 0x190820
|
||||
#define APICTB 0x200122
|
||||
#define APIGOTTHARD 0x200122
|
||||
#define APIEIGER 0x200122
|
||||
#define APIMYTHEN3 0x200122
|
||||
#define APIGOTTHARD2 0x200123
|
||||
#define APIJUNGFRAU 0x200123
|
||||
#define APIJUNGFRAU 0x200130
|
||||
#define APICTB 0x200130
|
||||
#define APIGOTTHARD2 0x200130
|
||||
#define APIMYTHEN3 0x200130
|
||||
#define APIGOTTHARD 0x200130
|
||||
|
Loading…
x
Reference in New Issue
Block a user