mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-05-16 11:16:49 +02:00
0837de2a5a
* round CTB clocks to next closest possible value, added freq measurement * added time for firmware to measrue actual value after frequency change * add check for backwards compatibility * change CTB and XCTB clock values to MHz, TODO: units and validation errors * changed runclk command to use units and float, TODO: dbit, adcclk, why is everything called StringTo ? * do the same for dbit and adcclk * added tolerance to exptime, fixed test * update default values in server defs * added virtual check in Altera_PLL, update testcases * change python and pyctbgui to accept and return floating point MHz * update help and comments * Dev/ctb clocks fix (#1434) * introduced new type Hz, typetraits, String conversions, command generation (not yet generated) * incorrect unit typo * cmd generation and compiles * default to MHz, removed space between units for consistency with timers, min and max checks for clks * in python, but need to change the default to Hz again for clean code and intuition * allow ints, doubles, implicit conversions * dont allow raw ints, doubles and implicit conversions * fixed tests * added operators for Hz in python * fix test for min clk for xilinx ctb * fix test * fix python tests * fixed xilinx period and default clks * test fix * removed the 3 clock cycle check for ctb and implemented properly the max adc clk frq for altera ctb * removing 3 clock cycle code from xilinx as well * formatting * loadpattern before 3 clk cycles code * actualtime and measurement time to be implemented in 100ns already in fw * fix tests * pyzmq dependency forthe tests * fixed pyctbgui for freq * insert tolerance check again * also added tolerance check for patwaittime * formatting * minor: rounding test * removed Rep redundant in ToString for freq * intro frequency unit enums, removed unnecessary template behavior for ToString with freq unit, switching from parsing string unit argument to the enum argument for ToString, adding parsing string to unit at CLI boundary * minor, and binaries * minor, default clk vals are 0 but set up at detector setup * get frequency only for that unit * tolerance process * missed in previous commit * some more changes to exptime and validations * ctb is probably done * periodleft and delayleft * fixed xilinx freq conv as well * fixed m3 bug, binaries * xilinx: setup also done in stop server so that the clk is not 0 * missed a test marker * binaries in * review fixes, simpler validation of timers in ctb and xilinx ctb * typo fix * format * fix tests --------- Co-authored-by: Martin Mueller <martin.mueller@psi.ch> Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
91 lines
3.3 KiB
C
91 lines
3.3 KiB
C
// SPDX-License-Identifier: LGPL-3.0-or-other
|
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
|
#pragma once
|
|
|
|
#include "clogger.h"
|
|
#include "sls/md5.h"
|
|
#include <stdint.h> // int64_t
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <time.h>
|
|
|
|
#define UPDATE_FILE "update.txt"
|
|
#ifdef VIRTUAL
|
|
#define TEMP_PROG_FOLDER_NAME "/tmp/"
|
|
#else
|
|
#define TEMP_PROG_FOLDER_NAME "/var/tmp/"
|
|
#define TEMP_PROG_FOLDER_NAME_ALL_FILES "/var/tmp/*"
|
|
#endif
|
|
|
|
#define TEMP_PROG_FILE_NAME TEMP_PROG_FOLDER_NAME "tmp.rawbin"
|
|
|
|
enum numberMode { DEC, HEX };
|
|
enum PROGRAM_INDEX { PROGRAM_FPGA, PROGRAM_KERNEL, PROGRAM_SERVER };
|
|
|
|
#define NS_PER_SEC 1000000000ULL
|
|
#define HALF_NS_PER_SEC (NS_PER_SEC / 2)
|
|
static inline uint64_t ns_to_clocks(uint64_t t, uint32_t freq_hz) {
|
|
return (t * (uint64_t)freq_hz + HALF_NS_PER_SEC) / NS_PER_SEC;
|
|
}
|
|
static inline uint64_t clocks_to_ns(uint64_t clocks, uint32_t freq_hz) {
|
|
if (freq_hz == 0) {
|
|
LOG(logERROR, ("Frequency is 0, cannot convert clocks to ns\n"));
|
|
return (uint64_t)-1;
|
|
}
|
|
return (clocks * (uint64_t)NS_PER_SEC + freq_hz / 2) / freq_hz;
|
|
}
|
|
|
|
/**
|
|
* Convert a value from a range to a different range (eg voltage to dac or vice
|
|
* versa)
|
|
* @param inputMin input minimum
|
|
* @param inputMax input maximum
|
|
* @param outputMin output minimum
|
|
* @param outputMax output maximum
|
|
* @param inputValue input value
|
|
* @param outputValue pointer to output value
|
|
* @returns FAIL if input value is out of bounds, else OK
|
|
*/
|
|
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
|
int outputMax, int inputValue, int *outputValue);
|
|
|
|
int getAbsPath(char *buf, size_t bufSize, char *fname);
|
|
|
|
int getTimeFromString(char *buf, time_t *result);
|
|
|
|
int getKernelVersion(char *retvals);
|
|
|
|
int validateKernelVersion(char *expectedVersion);
|
|
|
|
void validate(int *ret, char *mess, int arg, int retval, char *modename,
|
|
enum numberMode nummode);
|
|
void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
|
|
char *modename, enum numberMode nummode);
|
|
|
|
int getModuleIdInFile(int *ret, char *mess, char *fileName);
|
|
int verifyChecksumFromBuffer(char *mess, char *functionType,
|
|
char *clientChecksum, char *buffer, ssize_t bytes);
|
|
int verifyChecksumFromFile(char *mess, char *functionType, char *clientChecksum,
|
|
char *fname);
|
|
int verifyChecksumFromFlash(char *mess, char *functionType,
|
|
char *clientChecksum, char *fname, ssize_t fsize);
|
|
int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
|
|
MD5_CTX *c, char *msg);
|
|
int setupDetectorServer(char *mess, char *sname);
|
|
|
|
int writeBinaryFile(char *mess, char *fname, char *buffer,
|
|
const uint64_t filesize, char *errorPrefix);
|
|
|
|
int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix);
|
|
|
|
int createEmptyFile(char *mess, char *fname, char *errorPrefix);
|
|
int deleteFile(char *mess, char *fname, char *errorPrefix);
|
|
|
|
int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix);
|
|
|
|
int readParameterFromFile(char *fname, char *parameterName, int *value);
|
|
|
|
int createAbsoluteDirectory(char *mess, const char *absPath, char *errorPrefix);
|
|
int deleteAbsoluteDirectory(char *mess, const char *absPath, char *errorPrefix);
|
|
|
|
int deleteItem(char *mess, int isFile, const char *absPath, char *errorPrefix); |