MRF24J40 Transeiver in Linux

I am working on porting an 802.15.4 tranceiver (Microchip MRF24j40) and protocol that I have working on an Arduino to the Beagleboard xm. How it works on the Arduino:

  1. The Arduino communicates with the transceiver using SPI and an interrupt pin
  2. On startup the Arduino initializes the transceiver
  3. The Arduino transmits a packet whenever I send a command from my PC (connected using serial)
  4. The transceiver signals the Arduino when action needs to be taken using an interrupt pin

My question is about the best way to implementing this type of operation in a linux environment. Right now I am thinking about righting a C program that initializes the transceiver and then runs in the background using the poll() function to pick up interrupts. Is this a good way to do it or is there a better way? Also, if I take this approach how do I signal to the running program that I want to transmit data? I am by no means married to this method of implementation, its just the best thing I have found so far.

Thanks,
Spencer

Hi Spencer,

I have developed a driver for this transceiver for Linux. I'm hoping to
have rev 0 posted to the linux-zigbee[1] mailing list later tonight
after I get some cleanup in.

What protocol are you using (raw 802.15.4, 6loWPAN, Zigbee, MiWi)?

While there's no Zigbee or MiWi support in the kernel, the linux-zigbee
project is aiming to get 802.15.4 and 6loWPAN support merged[2]. There
is some preliminary 802.15.4 support in mainline currently, but not
6loWPAN yet.

If you have to use Zigbee for interoperability with other devices, check
out the FreakZ project[3] which runs in userspace and has a BSD license.
I'm not sure the current state of this project. I've read hints that
support for it may come to an end.

Alan.

[1] http://sourceforge.net/apps/trac/linux-zigbee/

[2] linux-zigbee is a bit of a misnomer. It started as trying to get
zigbee support into Linux, but after GPL incompatibilities were
discovered with the Zigbee specification document's license (and with
repeated attempts for an open-source exclusion to their license having
failed), they have moved their attention to 6loWPAN, which is free and open.

[3] http://freaklabs.org/index.php/FreakZ-Open-Source-Zigbee-Stack.html

Alan,
I am using raw 802.15.4. Thanks for the resources this is exactly the
type of example I was looking for. I especially look forward to your
update with code specific to this transceiver. There was some
functionality such as some of the stronger encryption types that I
have not been able to get working on the Arduino and maybe your code
will help me shed some light on those problems also.

Spencer

I have finally gotten back around to working on this and I have a quick question about the interrupt in the driver[1]. I understand how the interrupt works inside the driver but I do not understand how it is setup in the kernel. I am guessing it is just a GPIO pin that you setup in your boards file but I am having trouble finding an example of this. Can you please explain and/or provide a snippet of code for your interrupt setup?

Thanks,
Spencer

[1] http://article.gmane.org/gmane.linux.network.zigbee.devel/1057/match=

Hi Spencer,

Yes, the driver is told what IRQ to use by the board file. In my case, I
used the convenience functions:
  gpio_to_irq(GPIO_TO_PIN(3, 19));

A quick diff of my board file is attached. Ignore that it says spidev. I
did this originally to set up the SPI port for spidev, but then just did
a quick change of modalias to make it work for my mrf24j40 driver.

Alan.

bone-mrf24j40-board.patch (1.81 KB)

How did you combine the changes in the linux-zigbee repo with the
beaglebone/beagleboard patchset? I mashed something together that
compiles, but it isn't pretty. I have tried to make a patchset from
the linux-zigbee repository[1] that I can apply to the mainline kernel
but I end up with 10000+ patches...

Thanks for all of your advice so far. I am very new to playing with
the linux kernel and you have helped me work through a lot of my
problems.

Spencer

[1] http://linux-zigbee.git.sourceforge.net/git/gitweb.cgi?p=linux-zigbee/kernel;a=shortlog;h=refs/heads/devel

Not knowing exactly what you did, that may not be what you want. Here's
what I did:

    1. Grab the BeagleBone kernel from OE
    2. Add a remote for the linux-zigbee project:
        git remote add linux-zigbee
git://linux-zigbee.git.sourceforge.net/gitroot/linux-zigbee/kernel
    3. Add a remote for mainline Linux:
        git remote add linux
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
    4. git fetch linux-zigbee
    5. git fetch linux
    6. Observe that the linux-zigbee tree [1] is based on version 3.3-rc5
    6. git diff v3.3-rc5..linux-zigbee/devel >
the_linux_zigbee_stuff_against_3.3-rc5.diff
    7. use git apply to apply the diff file you just created to the
BeagleBone tree (branch).

Basically this does a diff of the linux-zigbee tree against the upstream
kernel tree at the version on which the linux-zigbee tree is based.
Normally, you wouldn't do it this way, but the linux-zigbee people do
merging instead of rebasing on their tree, so in my experience it's
impossible to get a set of commits which are specific to the
linux-zigbee. Maybe some git-guru here can show me a better way.

Alan.

[1]
http://linux-zigbee.git.sourceforge.net/git/gitweb.cgi?p=linux-zigbee/kernel;a=shortlog;h=refs/heads/devel

I have the kernel up and running now and I have everything wired up
but I am not able to see packets using wireshark. The device driver
module is loaded and the device is listed in "iz listphy" but I think
I might be setting up the device wrong with iz. What commands do you
run after you boot to get your mrf24j40 working?

Thanks,
Spencer

Do the steps on this page[1], except adapt them for your hardware (ie:
don't use the fake driver).

Also, use the latest software from git for the userland tools, and apply
my patch[2] so that izcoordinator will work[3].

Alan.

[1] http://sourceforge.net/apps/trac/linux-zigbee/wiki/GettingStarted-0.2
[2]
http://www.mail-archive.com/linux-zigbee-devel@lists.sourceforge.net/msg01000.html
[3] You might be able to use version 0.2 of the userland tools but I
can't remember whether that works with the latest kernel stuff or not.

I am struggling to compile the newest version of the lowpan tools. I
am trying to the autogen.sh file which seems to work fine but when I
run make I get the following error:

make all-recursive
make[1]: Entering directory `/home/ubuntu/linux-zigbee'
Making all in lib
make[2]: Entering directory `/home/ubuntu/linux-zigbee/lib'
  CC libcommon_la-printbuf.lo
  CC libcommon_la-genl.lo
  CC libcommon_la-parse.lo
  CC libcommon_la-shash.lo
  CC libcommon_la-logging.lo
  CC libcommon_la-nl_policy.lo
  CCLD libcommon.la
make[2]: Leaving directory `/home/ubuntu/linux-zigbee/lib'
Making all in addrdb
make[2]: Entering directory `/home/ubuntu/linux-zigbee/addrdb'
make all-am
make[3]: Entering directory `/home/ubuntu/linux-zigbee/addrdb'
  CC coord-config-parse.lo
  LEX coord-config-lex.c
make[3]: *** [coord-config-lex.c] Error 1
make[3]: Leaving directory `/home/ubuntu/linux-zigbee/addrdb'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/ubuntu/linux-zigbee/addrdb'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ubuntu/linux-zigbee'
make: *** [all] Error 2

Did you run into this error and possibly have a solution? Or if
anyone can suggest a troubleshooting step, I am pretty lost on this
one.

Thanks,
Spencer

Well, I figured out that addrdb/coord-config-lex.c didn’t exist either in error or I don’t know how to generate it. I copied an old version from the lowpan-tools-0.2.2 tar ball and it compiled. Probably not optimal but it will do for now.

Spencer

All your issues look MMC related. This is a pretty old thread, and
things have now changed.

Your best bet for MRF24J40 in Linux is to get the mainline kernel for
BeagleBone, using the instructions here:
    https://github.com/beagleboard/kernel/tree/3.7

This is experimental, but is the basis for what I'm using. Depending on
how you attach your MRF24J40, you'll have to modify the device tree. I
recently gave a talk at ELC-Europe about this, and I'll have my material
(including scripts and DT mods) posted online soon. I'll post on this
mailing list when I do.

Alan.