help with coding a loadable kernel module
Ian Lepore
ian at freebsd.org
Fri Apr 17 13:31:52 UTC 2015
On Fri, 2015-04-17 at 13:46 +0300, Daniel Braniss wrote:
> > On Apr 17, 2015, at 12:55 PM, Tom Jones <jones at sdf.org> wrote:
> >
> > On Fri, Apr 17, 2015 at 12:15:33PM +0300, Daniel Braniss wrote:
> >>
> >>> On Apr 17, 2015, at 11:08 AM, Kurt Jaeger <lists at opsec.eu> wrote:
> >>>
> >>> Hi!
> >>>
> >>>> I know I'm embarking on a dangerous trip, but I want to use a Raspberry Pi
> >>>> and or a BeagleBone to read (and write) RFID cards.
> >>>> Since a driver is needed to use the spibus, I have 2 options while
> >>>> developing:
> >>> [...]
> >>>> So before I give up on option 2, is there some examples/help?
> >>>
> >>> Are you aware of this book ?
> >>>
> >>> http://www.nostarch.com/bsddrivers.htm <http://www.nostarch.com/bsddrivers.htm>
> >>
> >> no, but before I spend more money (this is getting expensive :-),
> >> does it explain how to write a loadable module that needs to to talk
> >> to a spibus?
> >
> > I don't think it does.
> >
> > spibus is very simple, there is one interface call
> >
> > SPIBUS_TRANSFER(device_t, device_t, strcut spi_command);
> >
>
> chicken and egg issue :-), what device_t dev should I use?
> it must point to the spibus …
Your device will be a child of the spibus, and it is the bus that
implements the SPIBUS_TRANSFER() method, so it's the bus's device_t that
needs to be passed as the first parameter in the call (if it were C++ it
would be the "this" pointer -- this stuff is OO implemented in plain-C).
>From your driver, something like:
SPIBUS_TRANSFER(device_get_parent(sc->sc_dev), sc->sc_dev, cmdptr);
I haven't got time this morning to put together a complete example of
how to add a module to the build, but the process is basically along the
lines of...
Add a new directory to sys/dev for your driver just like you were
going to compile it into the kernel. Then in sys/modules find another
simple driver, copy it to a new directory, and change the names of
things in the makefile so that it refers to your new dir/files in
sys/dev. You can set MODULES_OVERRIDE=yournew_dirname on the make
command line or in your kernel config to make it compile.
-- Ian
More information about the freebsd-arm
mailing list