ROCK Pi 4 (RK3399) support (#1499)

* ROCK Pi 4 (RK3399) support

* Code style
This commit is contained in:
Vita
2022-04-18 08:21:14 +02:00
committed by GitHub
parent 4afa7a6443
commit 423b9d790a
2 changed files with 43 additions and 8 deletions

29
configure vendored
View File

@@ -17,7 +17,7 @@ SPI driver options:
Device path. [/dev/spidev0.0]
Building options:
--soc=[BCM2711|BCM2835|BCM2836|BCM2837|AM33XX|A10|A13|A20|H3]
--soc=[BCM2711|BCM2835|BCM2836|BCM2837|AM33XX|A10|A13|A20|H3|RK3399]
SoC type to be used. [configure autodetected]
--cpu-flags=<CPUFLAGS> CPU defining/optimizing flags to be used. [configure autodetected]
--extra-cflags=<CFLAGS> Extra C flags passed to C compilation. []
@@ -248,7 +248,10 @@ function detect_machine {
soc="AM33XX"
;;
*)
soc="unknown"
if [[ $machine == *"ROCK Pi 4"* ]]; then
soc="RK3399"
tp="RockPi4"
fi
esac
echo "${soc} ${tp} ${cpu}"
}
@@ -283,12 +286,21 @@ function gcc_cpu_flags {
H3)
flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
;;
RK3399)
flags="-march=armv8-a+crc+crypto -mtune=cortex-a72.cortex-a53 -mfix-cortex-a53-835769 -mfix-cortex-a53-843419"
;;
*)
flags=""
esac
echo ${flags}
}
ROCKPI4_PIN_MAP=(
1 2 71 4 72 6 75 148 9 147
146 131 150 14 149 154 17 156 40 20
39 157 41 42 25 26 64 65 74 30
73 112 76 24 133 132 158 134 39 135 )
# Default values
debug=enable
gateway_type=ethernet
@@ -297,7 +309,7 @@ signing=none
signing_request_signatures=false
encryption=false
params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER"
params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER TYPE"
for opt do
if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
@@ -575,6 +587,17 @@ else
fi
fi
if [[ $TYPE == "RockPi4" ]]; then
FLTMP=$CPPFLAGS
pattern="(.+_PIN=)([0-9]+)(.*)"
while [[ $FLTMP =~ $pattern ]]; do
FLTMP=${BASH_REMATCH[3]}
CPPFLAGS=${BASH_REMATCH[1]}${ROCKPI4_PIN_MAP[${BASH_REMATCH[2]}-1]}
done
CPPFLAGS=$CPPFLAGS$FLTMP
CPPFLAGS="-DLINUX_ARCH_ROCKPI4 $CPPFLAGS"
fi
if [ -z "${SPI_DRIVER}" ]; then
printf "${SECTION} Detecting SPI driver.\n"
if [[ $SOC == "BCM2835" || $SOC == "BCM2836" || $SOC == "BCM2837" || $SOC == "BCM2711" ]]; then

View File

@@ -42,15 +42,27 @@ struct ThreadArgs {
volatile bool interruptsEnabled = true;
static pthread_mutex_t intMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t *threadIds[64] = {NULL};
static pthread_t *threadIds[256] = {NULL};
// sysFds:
// Map a file descriptor from the /sys/class/gpio/gpioX/value
static int sysFds[64] = {
static int sysFds[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
/*
@@ -130,7 +142,7 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
FILE *fd;
char fName[40];
char c;
int count, i;
int count;
if (threadIds[gpioPin] == NULL) {
threadIds[gpioPin] = new pthread_t;
@@ -190,7 +202,7 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
if (sysFds[gpioPin] == -1) {
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/value", gpioPin);
if ((sysFds[gpioPin] = open(fName, O_RDWR)) < 0) {
if ((sysFds[gpioPin] = open(fName, O_RDONLY)) < 0) {
logError("Error reading pin %d: %s\n", gpioPin, strerror(errno));
exit(1);
}
@@ -198,7 +210,7 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
// Clear any initial pending interrupt
ioctl(sysFds[gpioPin], FIONREAD, &count);
for (i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i) {
if (read(sysFds[gpioPin], &c, 1) == -1) {
logError("attachInterrupt: failed to read pin status: %s\n", strerror(errno));
}