Skip to content

Commit

Permalink
ROCK Pi 4 (RK3399) support (mysensors#1499)
Browse files Browse the repository at this point in the history
* ROCK Pi 4 (RK3399) support

* Code style
  • Loading branch information
docbender authored Apr 18, 2022
1 parent 4afa7a6 commit 423b9d7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
29 changes: 26 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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. []
Expand Down Expand Up @@ -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}"
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions hal/architecture/Linux/drivers/core/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -190,15 +202,15 @@ 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);
}
}

// 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));
}
Expand Down

0 comments on commit 423b9d7

Please sign in to comment.