Skip to content

Commit

Permalink
Applied preempt-rt patch set
Browse files Browse the repository at this point in the history
Used 2012-05-04 patch set from John Morris, which includes work from
(at least) Michael Abel, Michael Busch, and Jeff Epler.

Currently fails to link HAL modules (on Debian Wheezy), apparently
due to some recent changes in the LinuxCNC code base.
  • Loading branch information
cdsteinkuehler committed Oct 9, 2012
1 parent c261a72 commit 9d1a46d
Show file tree
Hide file tree
Showing 31 changed files with 2,743 additions and 186 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build-stamp
*.mod.c
*.cmd
.tmp*
*~
# Ignore generated html files,
*.html
# Except Gcode quick-ref cards (en,de,sp,fr) which are maintained by hand
Expand Down
8 changes: 4 additions & 4 deletions scripts/realtime.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CheckConfig(){
MODULES_LOAD=
MODULES_UNLOAD=
case $RTPREFIX in
sim) SHM_DEV=/dev/zero;;
sim|linux) SHM_DEV=/dev/zero;;
*)
for MOD in $MODULES ; do
eval MOD=\${MODPATH_$MOD}
Expand Down Expand Up @@ -103,7 +103,7 @@ CheckConfig(){

CheckStatus(){
case $RTPREFIX in
sim)
sim|linux)
if [ -z "$($PIDOF rtapi_app)" ]; then
exit 1
else
Expand Down Expand Up @@ -152,7 +152,7 @@ CheckMem(){
Load(){
CheckKernel
case $RTPREFIX in
sim)
sim|linux)
;;
*)
for MOD in $MODULES_LOAD ; do
Expand Down Expand Up @@ -181,7 +181,7 @@ CheckLoaded(){
Unload(){
CheckKernel
case $RTPREFIX in
sim)
sim|linux)
rtapi_app exit
ipcrm -M 0x48414c32 2>/dev/null ;# HAL_KEY
ipcrm -M 0x90280A48 2>/dev/null ;# RTAPI_KEY
Expand Down
54 changes: 37 additions & 17 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ default: configs userspace modules
ifeq ($(RUN_IN_PLACE),yes)
ifneq ($(BUILD_SYS),sim)
@if [ -f ../bin/linuxcnc_module_helper ]; then if ! [ `stat -c %u ../bin/linuxcnc_module_helper` -eq 0 -a -u ../bin/linuxcnc_module_helper ]; then $(VECHO) "You now need to run 'sudo make setuid' in order to run in place."; fi; fi
@if [ -f ../bin/rtapi_app ]; then if ! [ `stat -c %u ../bin/rtapi_app` -eq 0 -a -u ../bin/rtapi_app ]; then $(VECHO) "You now need to run 'sudo make setuid' in order to run in place."; fi; fi
endif
endif

Expand Down Expand Up @@ -405,12 +406,22 @@ setuid:
@echo "'make setuid' is not needed for the simulator"
else
setuid:
chown root ../bin/linuxcnc_module_helper
chmod 4750 ../bin/linuxcnc_module_helper
chown root ../bin/pci_write
chmod 4750 ../bin/pci_write
chown root ../bin/pci_read
chmod 4750 ../bin/pci_read
if test -f ../bin/rtapi_app; then\
chown root ../bin/rtapi_app;\
chmod 4750 ../bin/rtapi_app;\
fi
if test -f ../bin/linuxcnc_module_helper; then\
chown root ../bin/linuxcnc_module_helper;\
chmod 4750 ../bin/linuxcnc_module_helper;\
fi
if test -f ../bin/pci_write; then\
chown root ../bin/pci_write;\
chmod 4750 ../bin/pci_write;\
fi
if test -f ../bin/pci_read; then\
chown root ../bin/pci_read;\
chmod 4750 ../bin/pci_read;\
fi
endif

# These rules allows a header file from this directory to be installed into
Expand Down Expand Up @@ -571,7 +582,7 @@ install-kernel-dep:
$(DESTDIR)$(bindir) \
$(DESTDIR)$(sysconfdir)/linuxcnc
$(FILE) ../rtlib/*$(MODULE_EXT) $(DESTDIR)$(EMC2_RTLIB_DIR)
ifneq "$(BUILD_SYS)" "sim"
ifeq "$(filter sim linux,$(BUILD_SYS))" ""
$(FILE) Module.symvers $(DESTDIR)$(EMC2_RTLIB_DIR)
$(SETUID) ../bin/linuxcnc_module_helper $(DESTDIR)$(bindir)
$(SETUID) ../bin/pci_write $(DESTDIR)$(bindir)
Expand Down Expand Up @@ -645,7 +656,7 @@ endif
# find a way around it.

# Subdirectory: rtapi
ifneq ($(BUILD_SYS),sim)
ifeq "$(filter sim linux,$(BUILD_SYS))" ""
obj-$(CONFIG_RTAPI) += rtapi.o
rtapi-objs := rtapi/$(RTPREFIX)_rtapi.o
endif
Expand Down Expand Up @@ -704,18 +715,23 @@ obj-$(CONFIG_HAL_STG) += hal_stg.o
hal_stg-objs := hal/drivers/hal_stg.o $(MATHSTUB)
obj-$(CONFIG_HAL_VTI) += hal_vti.o
hal_vti-objs := hal/drivers/hal_vti.o $(MATHSTUB)
obj-$(CONFIG_HAL_EVOREG) += hal_evoreg.o
hal_evoreg-objs := hal/drivers/hal_evoreg.o $(MATHSTUB)
#obj-$(CONFIG_HAL_EVOREG) += hal_evoreg.o
#hal_evoreg-objs := hal/drivers/hal_evoreg.o $(MATHSTUB)
obj-$(CONFIG_HAL_MOTENC) += hal_motenc.o
hal_motenc-objs := hal/drivers/hal_motenc.o $(MATHSTUB)
obj-$(CONFIG_HAL_AX521H) += hal_ax5214h.o
hal_ax5214h-objs := hal/drivers/hal_ax5214h.o $(MATHSTUB)
obj-$(CONFIG_HAL_PPMC) += hal_ppmc.o
hal_ppmc-objs := hal/drivers/hal_ppmc.o $(MATHSTUB)
obj-$(CONFIG_HAL_SPEAKER) += hal_speaker.o
hal_speaker-objs := hal/drivers/hal_speaker.o $(MATHSTUB)
obj-$(CONFIG_HAL_SKELETON) += hal_skeleton.o
hal_skeleton-objs := hal/drivers/hal_skeleton.o $(MATHSTUB)

# these won't compile as-is with realtime=linux
ifneq ($(BUILD_SYS),linux)
obj-$(CONFIG_HAL_M5I20) += hal_m5i20.o
hal_m5i20-objs := hal/drivers/hal_m5i20.o $(MATHSTUB)
obj-$(CONFIG_HAL_PPMC) += hal_ppmc.o
hal_ppmc-objs := hal/drivers/hal_ppmc.o $(MATHSTUB)
obj-$(CONFIG_OPTO_AC5) += opto_ac5.o
opto_ac5-objs := hal/drivers/opto_ac5.o $(MATHSTUB)

Expand Down Expand Up @@ -752,8 +768,9 @@ hm2_test-objs := \
hal/drivers/mesa-hostmot2/hm2_test.o \
hal/drivers/mesa-hostmot2/bitfile.o \
$(MATHSTUB)
endif

ifneq "$(filter 2.6.%, $(kernelvers))" ""
ifneq "$(filter linux,$(BUILD_SYS))$(filter 2.6.%, $(kernelvers))" ""
obj-$(CONFIG_PROBE_PARPORT) += probe_parport.o
probe_parport-objs := hal/drivers/probe_parport.o $(MATHSTUB)
endif
Expand Down Expand Up @@ -833,7 +850,7 @@ motmod-objs += libnml/posemath/_posemath.o
motmod-objs += libnml/posemath/sincos.o $(MATHSTUB)

TORTOBJS = $(foreach file,$($(patsubst %.o,%,$(1))-objs), objects/rt$(file))
ifeq ($(BUILD_SYS),sim)
ifneq "$(filter sim linux,$(BUILD_SYS))" ""
EXTRA_CFLAGS += -fPIC -Os
RTOBJS := $(sort $(foreach mod,$(obj-m),$(call TORTOBJS,$(mod))))

Expand Down Expand Up @@ -881,8 +898,8 @@ $(sort $(RTOBJS)) : objects/rt%.o : %.c
$(Q)ld -r -static -S -Os $(LDFLAGS) -o $@ $^ $(EXTRALINK) $(MATHLIB)
endif

ifneq "$(filter normal sim,$(BUILD_SYS))" ""
ifneq "$(BUILD_SYS)" "sim"
ifneq "$(filter normal sim linux,$(BUILD_SYS))" ""
ifeq "$(filter sim linux,$(BUILD_SYS))" ""
../rtlib/rtapi$(MODULE_EXT): $(addprefix objects/rt,$(rtapi-objs))
endif
../rtlib/classicladder_rt$(MODULE_EXT): $(addprefix objects/rt,$(classicladder_rt-objs))
Expand All @@ -906,11 +923,14 @@ endif
../rtlib/streamer$(MODULE_EXT): $(addprefix objects/rt,$(streamer-objs))
../rtlib/sampler$(MODULE_EXT): $(addprefix objects/rt,$(sampler-objs))
../rtlib/hal_parport$(MODULE_EXT): $(addprefix objects/rt,$(hal_parport-objs))
ifeq ($(BUILD_SYS),linux)
../rtlib/probe_parport$(MODULE_EXT): $(addprefix objects/rt,$(probe_parport-objs))
endif
../rtlib/pci_8255$(MODULE_EXT): $(addprefix objects/rt,$(pci_8255-objs))
../rtlib/hal_tiro$(MODULE_EXT): $(addprefix objects/rt,$(hal_tiro-objs))
../rtlib/hal_stg$(MODULE_EXT): $(addprefix objects/rt,$(hal_stg-objs))
../rtlib/hal_vti$(MODULE_EXT): $(addprefix objects/rt,$(hal_vti-objs))
../rtlib/hal_evoreg$(MODULE_EXT): $(addprefix objects/rt,$(hal_evoreg-objs))
#../rtlib/hal_evoreg$(MODULE_EXT): $(addprefix objects/rt,$(hal_evoreg-objs))
../rtlib/hal_motenc$(MODULE_EXT): $(addprefix objects/rt,$(hal_motenc-objs))
../rtlib/hal_ax5214h$(MODULE_EXT): $(addprefix objects/rt,$(hal_ax5214h-objs))
../rtlib/hal_ppmc$(MODULE_EXT): $(addprefix objects/rt,$(hal_ppmc-objs))
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.modinc.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ install:
cp $(patsubst %.o,%.ko,$(obj-m)) $(DESTDIR)$(RTLIBDIR)/
endif

ifeq ($(BUILDSYS),sim)
ifneq "$(filter sim linux,$(BUILDSYS))" ""
EXTRA_CFLAGS += -DSIM -fPIC
allmodules = $(patsubst %.o,%.so,$(obj-m))
modules: $(allmodules)
Expand Down
55 changes: 40 additions & 15 deletions src/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ RTLINUXPRO=""
RTPREFIX=""
KERNELDIR=""
RTFLAGS=""
LINUX_REALTIME=no

RTAI3_MOD=""
RTAI_MOD=""
Expand Down Expand Up @@ -116,17 +117,27 @@ AC_ARG_ENABLE(simulator,
AC_SUBST(SIMULATOR)

AC_ARG_WITH(realtime,
[ --with-realtime=<path to realtime> Path where RTAI or RTlinux is installed],
[ --with-realtime=<path to realtime> Path where RTAI or RTlinux is installed or 'linux' for linux-rt],
[ case "$withval" in
"" | y | ye | yes | n | no)
AC_MSG_ERROR([You must supply a path for --with-realtime.]) ;;
linux)
LINUX_REALTIME=yes
BUILD_SYS=linux
RTPREFIX=linux
MODEXT=.so
MODULE_DIR=${prefix}/lib/emc2/modules
AC_MSG_RESULT([configuring for Realtime-Linux])
;;
*)
case "$SIMULATOR" in
yes) AC_MSG_ERROR([--with-realtime and --enable-simulator are mutually exclusive]) ;;
*) RTDIR="$withval" ;;
esac
;;
RTDIR="$withval" ;;
esac])
if test x$RTDIR != x; then
case "$SIMULATOR" in
yes) AC_MSG_ERROR([--with-realtime and --enable-simulator are mutually exclusive]) ;;
esac
fi


##############################################################################
# Subsection 2.2 #
Expand All @@ -143,13 +154,8 @@ AC_ARG_WITH(realtime,
##############################################################################

#at this point if RTDIR is empty, we need to find RT ourselves
if test $SIMULATOR = yes; then
RTS=sim
AC_PATH_PROG(PTH_CONFIG,pth-config,"")
if test "$PTH_CONFIG" = ""; then
AC_MSG_ERROR([GNU PTH library is required: get it with apt-get install libpth-dev])
fi
else
if test $SIMULATOR != yes -a $LINUX_REALTIME != yes; then
# Using realtime hypervisor
if test -z "$RTDIR"; then
DIRS="/usr/realtime-`uname -r` /usr/realtime /usr/realtime* /usr /usr/src/rtai*"
else
Expand All @@ -175,6 +181,20 @@ to build without a realtime system.])
AC_MSG_RESULT([Using $RTS as the RT signature])
fi

if test $LINUX_REALTIME = yes; then
# Using realtime capable linux
RTS=linux
fi

if test $SIMULATOR = yes; then
# Using simulator
RTS=sim
AC_PATH_PROG(PTH_CONFIG,pth-config,"")
if test "$PTH_CONFIG" = ""; then
AC_MSG_ERROR([GNU PTH library is required: get it with apt-get install libpth-dev])
fi
fi


##############################################################################
# Subsection 2.3 #
Expand Down Expand Up @@ -246,7 +266,7 @@ sim)
RTFLAGS=-DSIMULATOR
esac

if test $RTS != sim; then
if test $RTS != sim -a $RTS != linux; then
AC_MSG_CHECKING([for location of kernel headers])
AC_ARG_WITH(kernel-headers,
[ --with-kernel-headers=<directory> Location for kernel headers],
Expand Down Expand Up @@ -274,6 +294,8 @@ elif test $RTPREFIX = rtai; then
AC_DEFINE(RTAPI_RTAI, [], [Realtime system is RTAI])
elif test $RTPREFIX = rtl; then
AC_DEFINE(RTAPI_RTL, [], [Realtime system is RTL])
elif test $RTPREFIX = linux; then
AC_DEFINE(RTAPI_LINUX, [], [Realtime capable Linux])
fi


Expand Down Expand Up @@ -366,7 +388,7 @@ AC_SUBST([HIDRAW_H_USABLE])
# compiled against. #
##############################################################################

if test $RTS '!=' sim; then
if test $RTS '!=' sim -a $RTS != linux; then
AC_CHECK_HEADERS([$KERNELDIR/include/linux/version.h],[],[AC_MSG_ERROR([version.h not found - Is the kernel headers package installed ?])])

# Unfortunately, many distributions (redhat, mandrake) have #defines
Expand Down Expand Up @@ -1508,6 +1530,9 @@ echo "# is possible. Drivers won't be built. #"
else
echo "# This means that RT is properly installed #"
fi
if test $LINUX_REALTIME = yes; then
echo "# Using realtime capable Linux. #"
fi
echo "# If things don't work check config.log for errors & warnings #"
echo "# #"

Expand Down
2 changes: 1 addition & 1 deletion src/hal/drivers/Submakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pluto_clean:

# The kernel's build system won't know how to rebuild generated files
# so modules must depend on them explicitly
ifneq ($(BUILD_SYS),sim)
ifeq "$(filter sim linux,$(BUILD_SYS))" ""
modules: \
hal/drivers/pluto_servo_rbf.h \
hal/drivers/pluto_step_rbf.h
Expand Down
2 changes: 1 addition & 1 deletion src/hal/drivers/hal_ax5214h.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
instead of rtapi_outb() and rtapi_inb() - the <asm.io> ones
are inlined, and save a microsecond or two (on my 233MHz box)
*/
#define FASTIO
#define NOFASTIO

#ifdef FASTIO
#define rtapi_inb inb
Expand Down
16 changes: 10 additions & 6 deletions src/hal/drivers/hal_motenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ typedef struct {

typedef struct {
// Private data.
struct rtapi_pcidev *pDev;
MotencRegMap *pCard;
int boardType;
char *pTypeName;
Expand Down Expand Up @@ -273,7 +274,7 @@ int
rtapi_app_main(void)
{
int i, j;
struct pci_dev *pDev = NULL;
struct rtapi_pcidev *pDev = NULL;
MotencRegMap *pCard = NULL;
Device *pDevice;

Expand All @@ -291,7 +292,7 @@ rtapi_app_main(void)

i = 0;
// Find a MOTENC card.
while((i < MAX_DEVICES) && ((pDev = pci_get_device(MOTENC_VENDOR_ID, MOTENC_DEVICE_ID, pDev)) != NULL)){
while((i < MAX_DEVICES) && ((pDev = rtapi_pci_get_device(MOTENC_VENDOR_ID, MOTENC_DEVICE_ID, pDev)) != NULL)){

// Allocate memory for device object.
pDevice = hal_malloc(sizeof(Device));
Expand All @@ -301,14 +302,15 @@ rtapi_app_main(void)
hal_exit(driver.componentId);
return(-ENOMEM);
}
pDevice->pDev = pDev;

// Save pointer to device object.
driver.deviceTable[i++] = pDevice;

// Map card into memory.
pCard = (MotencRegMap *)ioremap_nocache(pci_resource_start(pDev, 2), pci_resource_len(pDev, 2));
rtapi_print_msg(RTAPI_MSG_INFO, "MOTENC: Card detected in slot %2x\n", PCI_SLOT(pDev->devfn));
rtapi_print_msg(RTAPI_MSG_INFO, "MOTENC: Card address @ %p, Len = %d\n", pCard, (int)pci_resource_len(pDev, 2));
pCard = (MotencRegMap *)rtapi_pci_ioremap(pDev, 2, sizeof(MotencRegMap));
rtapi_print_msg(RTAPI_MSG_INFO, "MOTENC: Card detected\n");
rtapi_print_msg(RTAPI_MSG_INFO, "MOTENC: Card address @ %p, Len = %d\n", pCard, (int)sizeof(MotencRegMap));

// Initialize device.
Device_Init(pDevice, pCard);
Expand Down Expand Up @@ -376,7 +378,9 @@ rtapi_app_exit(void)
}

// Unmap card.
iounmap((void *)(pDevice->pCard));
rtapi_pci_iounmap(pDevice->pDev, (void *)(pDevice->pCard));
// Unregister the device
rtapi_pci_put_device(pDevice->pDev);

// TODO: Free device object when HAL supports free.
// hal_free(pDevice);
Expand Down
Loading

0 comments on commit 9d1a46d

Please sign in to comment.