Skip to content

Commit

Permalink
hal_pi_gpio: Add a HAL driver for Raspberry Pi GPIO
Browse files Browse the repository at this point in the history
Based on the hal_gpio driver from Machinekit, modified for the LinuxCNC
build environment and with support for the Raspberry Pi Version 4.


Signed-off-by: andypugh <andy@bodgesoc.org>
  • Loading branch information
andypugh committed Oct 27, 2019
1 parent 4599a35 commit e0dc3a0
Show file tree
Hide file tree
Showing 7 changed files with 1,410 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Makefile 100644 → 100755
Expand Up @@ -863,9 +863,22 @@ hal_gm-objs := hal/drivers/hal_gm.o $(MATHSTUB)
obj-$(CONFIG_HAL_PPMC) += hal_ppmc.o
hal_ppmc-objs := hal/drivers/hal_ppmc.o $(MATHSTUB)

#Don't attempt to build Pi / Beaglebone GPIO for RTAI
ifeq ($(BUILD_SYS),uspace)
obj-$(CONFIG_HAL_BB_GPIO) += hal_bb_gpio.o
hal_bb_gpio-objs := \
hal/drivers/hal_bb_gpio.o \
$(MATHSTUB)
obj-$(CONFIG_HAL_PI_GPIO) += hal_pi_gpio.o
hal_pi_gpio-objs := \
hal/drivers/hal_pi_gpio.o \
hal/drivers/cpuinfo.o \
$(MATHSTUB)
endif

obj-$(CONFIG_HOSTMOT2) += hostmot2.o hm2_test.o hm2_pci.o hm2_7i43.o hm2_7i90.o setsserial.o
ifeq ($(BUILD_SYS),uspace)
obj-$(CONFIG_HOSTMOT2) += hm2_eth.o hm2_spi.o hm2_rpspi.o hal_bb_gpio.o
obj-$(CONFIG_HOSTMOT2) += hm2_eth.o hm2_spi.o hm2_rpspi.o
endif
hostmot2-objs := \
hal/drivers/mesa-hostmot2/hostmot2.o \
Expand Down Expand Up @@ -910,9 +923,6 @@ hm2_spi-objs := \
hm2_rpspi-objs := \
hal/drivers/mesa-hostmot2/hm2_rpspi.o \
$(MATHSTUB)
hal_bb_gpio-objs := \
hal/drivers/hal_bb_gpio.o \
$(MATHSTUB)
hm2_test-objs := \
hal/drivers/mesa-hostmot2/hm2_test.o \
hal/drivers/mesa-hostmot2/bitfile.o \
Expand Down Expand Up @@ -1130,6 +1140,7 @@ endif
../rtlib/hm2_spi$(MODULE_EXT): $(addprefix objects/rt,$(hm2_spi-objs))
../rtlib/hm2_rpspi$(MODULE_EXT): $(addprefix objects/rt,$(hm2_rpspi-objs))
../rtlib/hal_bb_gpio$(MODULE_EXT): $(addprefix objects/rt,$(hal_bb_gpio-objs))
../rtlib/hal_pi_gpio$(MODULE_EXT): $(addprefix objects/rt,$(hal_pi_gpio-objs))

ifeq ($(TRIVIAL_BUILD),no)
READ_RTDEPS = $(wildcard $(RTDEPS))
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.inc.in 100644 → 100755
Expand Up @@ -215,6 +215,8 @@ CONFIG_PCI_8255=m
CONFIG_HOSTMOT2=m
CONFIG_OPTO_AC5=m
CONFIG_HAL_GM=m
CONFIG_HAL_BB_GPIO=m
CONFIG_HAL_PI_GPIO=m

RTAPI_APP_CFLAGS=@RTAPI_APP_CFLAGS@
CONFIG_USPACE_RTAI=@CONFIG_USPACE_RTAI@
Expand Down
824 changes: 824 additions & 0 deletions src/hal/drivers/bcm2835.h

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions src/hal/drivers/cpuinfo.c
@@ -0,0 +1,89 @@
/*
Copyright (c) 2012 Ben Croston
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <stdio.h>
#include <string.h>
#include "cpuinfo.h"

char *get_cpuinfo_revision(char *revision)
{
FILE *fp;
char buffer[1024];
char hardware[1024];
int rpi_found = 0;

if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
return 0;

while(!feof(fp)) {
fgets(buffer, sizeof(buffer) , fp);
sscanf(buffer, "Hardware : %s", hardware);
if (strcmp(hardware, "BCM2708") == 0)
rpi_found = 1;
else if (strcmp(hardware, "BCM2709") == 0)
rpi_found = 1;
else if (strcmp(hardware, "BCM2835") == 0)
rpi_found = 1;
sscanf(buffer, "Revision : %s", revision);
}
fclose(fp);

if (!rpi_found)
revision = NULL;
return revision;
}

int get_rpi_revision(void)
{
char revision[1024] = {'\0'};

if (get_cpuinfo_revision(revision) == NULL)
return -1;

if ((strcmp(revision, "0002") == 0) ||
(strcmp(revision, "1000002") == 0 ) ||
(strcmp(revision, "0003") == 0) ||
(strcmp(revision, "1000003") == 0 ))
return 1;
else if ((strcmp(revision, "0004") == 0) ||
(strcmp(revision, "1000004") == 0 ) ||
(strcmp(revision, "0005") == 0) ||
(strcmp(revision, "1000005") == 0 ) ||
(strcmp(revision, "0006") == 0) ||
(strcmp(revision, "1000006") == 0 ))
return 2;
else if ((strcmp(revision, "a01041") == 0) ||
(strcmp(revision, "a21041") == 0) ||
(strcmp(revision, "a22042") == 0))
return 3;
else if ((strcmp(revision, "a22082") == 0) ||
(strcmp(revision, "a02082") == 0) ||
(strcmp(revision, "a32082") == 0) ||
(strcmp(revision, "a020d3") == 0))
return 4;
else if ((strcmp(revision, "a03111") == 0) ||
(strcmp(revision, "b03111") == 0) ||
(strcmp(revision, "c03111") == 0))
return 5;
else // assume rev 5
return 6;
}
23 changes: 23 additions & 0 deletions src/hal/drivers/cpuinfo.h
@@ -0,0 +1,23 @@
/*
Copyright (c) 2012 Ben Croston
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

int get_rpi_revision(void);

0 comments on commit e0dc3a0

Please sign in to comment.