mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
gotthard2 and mythen3: programming fpga, reboot; jungfrau, ctb: modified programming (#74)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user