-
Notifications
You must be signed in to change notification settings - Fork 0
Generating clock interrupts from Mesanet cards
these are notes on how to generate clock interrupts for Mesanet PCI cards, with the intent to make them work with external thread clocking feature.
this is based on a extended exchange with Peter Wallace of Mesanet - thanks, Peter!
hostmot2 drivers do not as of now supports interrupts in any flavor (kernel or userland threads). However, (at least) PC cards are able to do so. Looking at the HostMot2 Register map we find:
0x0A00 IRQStatus Bit 2..4 Select which timer is used as IRQ source: 000 = Timer Reference 001 = Timer1 010 = Timer2 011 = Timer3 100 = Timer4 Bit 1 = Irq mask: 0 = masked Bit 0 = IRQ status (R/W) 0x0B00 ClearIRQ: Writes here clear IRQ
so to generate interrupts we need to unmask the low level interrupt by setting the mask bit ( bit 1 @ 0x0A00 ) true
Also, we need a PCI driver which registers the card, registers and enables an interrupt, and eventually does the right thing (once it is wrapped into an RTDM driver along the lines of the GPIO RTDM driver to clock Xenomai RT threads.
-
firmware for Mesanet cards which support the DPLL feature. I used a 5i25 card and freeby.mesanet.com/7i76x2d.bit[this firmware as provided by Peter]
-
flash that firmware onto the 5i25, for this you need to build mesaflash - BIG FAT WARNING: mesaflash is currently broken for amd64, but works fine for x86, so I had to move the test to a x86 box for now
-
to verify interrupts are properly generated, a PCI driver which does interrupts. I used the uio_pci_generic driver which can forward interrupts to a plain userland program. It should come stock with recent linux kernels.
-
machinekit installed on the x86 platform
-
make sure card is recognized:
# lspci -v .... 04:00.0 DPIO module: Device 2718:5125 (rev 01) Subsystem: Device 2718:5125 Flags: medium devsel, IRQ 18 Memory at d0600000 (32-bit, non-prefetchable) [size=64K] Kernel driver in use: uio_pci_generic
(2718 is the Mesanet PCI vendor ID)
-
get current firmware which supports DPLL
-
install mesaflash as per README
-
save and compile the UIO IRQ test program
-
verify it works with your card, for instance: sudo mesaflash --device 5i25 --readhmid
-
flash it like so:
root@dumpster:/home/mah/external-clocking# mesaflash --device 5i25 --verbose --write 7i76x2d.bit Checking file... OK File type: BIT file Design name: TopPCIHostMot2.ncd;UserID=0xFFFFFFFF Part name: 6slx9tqg144 Design date: 2015/06/16 Design time: 17:20:45 Config Length: 340604 Boot sector OK EEPROM sectors to write: 6, max sectors in area: 8 Erasing EEPROM sectors starting from 0x80000... |EEEEEE Erasing time: 3.43 seconds Programming EEPROM sectors starting from 0x80000... |WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW Programming time: 1.616 seconds Board configuration updated successfully. You must power cycle board or use --reload command to load updated firmware.
-
power cycle the box to activate the new firmware
-
load the UIO driver and verify it did:
# modprobe uio_pci_generic # lsmod Module Size Used by uio_pci_generic 12432 1
-
bind the UIO driver to the mesanet card:
echo "2718 5125" > /sys/bus/pci/drivers/uio_pci_generic/new_id
-
verify the UIO driver has registered the interrupt for the Mesanet card:
# grep uio /proc/interrupts 18: 1 0 290700 0 IO-APIC-fasteoi uio_pci_generic
-
now start a machinekit config which uses the Mesanet card, I used configs/hm2-stepper
-
run the UIO test program from above as root:
# ./uio Started uio test driver.
-
from a separate root window, enable the low-level interrupt by
mesaflash --device 5i25 --wpo 0x0a00=0x02
-
the uio program should generate lots of output showing it received the interrupts:
... Interrupts: 884164 Interrupts: 884165 Interrupts: 884166 Interrupts: 884167 Interrupts: 884168
-
disable interrupts by:
mesaflash --device 5i25 --wpo 0x0a00=0x0
-
the output from the uio program should stop