mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-07 10:30:41 +02:00
check kernel version before enabling the gipo 3 chipenable pins
This commit is contained in:
parent
c3eff0246a
commit
2d2287e189
@ -105,3 +105,7 @@ uint32_t *Blackfin_getBaseAddress();
|
||||
* Map FPGA
|
||||
*/
|
||||
int mapCSP0(void);
|
||||
|
||||
/** check kernel version against expected version string (complain if too old)
|
||||
* @returns OK or FAIL */
|
||||
int blackfin_checkKernelVersion(char *expectedVersion);
|
@ -3,11 +3,14 @@
|
||||
#include "blackfin.h"
|
||||
#include "RegisterDefs.h"
|
||||
#include "clogger.h"
|
||||
#include "common.h"
|
||||
#include "sls/ansi.h"
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
#include <fcntl.h> // open
|
||||
#include <sys/mman.h> // mmap
|
||||
#include <fcntl.h> // open
|
||||
#include <string.h>
|
||||
#include <sys/mman.h> // mmap
|
||||
#include <sys/utsname.h> // uname
|
||||
|
||||
/* global variables */
|
||||
u_int32_t *csp0base = 0;
|
||||
@ -126,4 +129,50 @@ int mapCSP0(void) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t *Blackfin_getBaseAddress() { return csp0base; }
|
||||
uint32_t *Blackfin_getBaseAddress() { return csp0base; }
|
||||
|
||||
int blackfin_checkKernelVersion(char *expectedVersion) {
|
||||
// extract kernel date string
|
||||
struct utsname buf;
|
||||
if (uname(&buf) == -1) {
|
||||
LOG(logERROR, ("Could not get kernel version\n"));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// remove first word (#version number)
|
||||
const char *ptr = strchr(buf.version, ' ');
|
||||
if (ptr == NULL) {
|
||||
LOG(logERROR, ("Could not parse kernel version\n"));
|
||||
return FAIL;
|
||||
}
|
||||
char output[256];
|
||||
memset(output, 0, 256);
|
||||
strcpy(output, buf.version + (ptr - buf.version + 1));
|
||||
|
||||
// convert kernel date string into time
|
||||
time_t kernelDate;
|
||||
if (GetTimeFromString(output, &kernelDate) == FAIL) {
|
||||
LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// convert expected date into time
|
||||
time_t expDate;
|
||||
if (GetTimeFromString(expectedVersion, &expDate) == FAIL) {
|
||||
LOG(logERROR,
|
||||
("Could not parse expected kernel date, %s\n", expectedVersion));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// compare if kernel time is older than expected time
|
||||
if (kernelDate < expDate) {
|
||||
LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], "
|
||||
"Got [%s]\n",
|
||||
expectedVersion, output));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output,
|
||||
expectedVersion));
|
||||
return OK;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
#include "programFpgaBlackfin.h"
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
#include "common.h"
|
||||
#include "sls/ansi.h"
|
||||
@ -24,21 +25,33 @@ int gpioDefined = 0;
|
||||
|
||||
extern int executeCommand(char *command, char *result, enum TLogLevel level);
|
||||
|
||||
int latestKernelVerified = -1;
|
||||
#define KERNEL_DATE_VRSN "Fri Oct 29 13:58:38 CEST 2021"
|
||||
|
||||
void defineGPIOpins() {
|
||||
#ifdef VIRTUAL
|
||||
return;
|
||||
#endif
|
||||
if (latestKernelVerified == -1) {
|
||||
latestKernelVerified =
|
||||
((OK == blackfin_checkKernelVersion(KERNEL_DATE_VRSN)) ? 1 : 0);
|
||||
}
|
||||
if (!gpioDefined) {
|
||||
// define the gpio pins
|
||||
system("echo 7 > /sys/class/gpio/export");
|
||||
system("echo 9 > /sys/class/gpio/export");
|
||||
// gpio 3 = not chip enable
|
||||
system("echo 3 > /sys/class/gpio/export");
|
||||
|
||||
// define their direction
|
||||
system("echo in > /sys/class/gpio/gpio7/direction");
|
||||
system("echo out > /sys/class/gpio/gpio9/direction");
|
||||
system("echo out > /sys/class/gpio/gpio3/direction");
|
||||
LOG(logINFO, ("gpio pins defined\n"));
|
||||
|
||||
if (latestKernelVerified == 1) {
|
||||
// gpio 3 = not chip enable
|
||||
system("echo 3 > /sys/class/gpio/export");
|
||||
system("echo out > /sys/class/gpio/gpio3/direction");
|
||||
LOG(logINFO, ("gpio pin for !ChipEnable defined\n"));
|
||||
}
|
||||
gpioDefined = 1;
|
||||
} else
|
||||
LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user