
| Source | Mainlined? |
|---|---|
| git | No |
This driver is not mainline - it can be found in the IEEE802.15.4/ZigBee Stack for Linux Project.
For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.
For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.
Unlike PCI or USB devices, SPI devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each SPI bus segment, and what slave selects these devices are using. For this reason, the kernel code must instantiate SPI devices explicitly. The most common method is to declare the SPI devices by bus number.
This method is appropriate when the SPI bus is a system bus, as in many embedded systems, wherein each SPI bus has a number which is known in advance. It is thus possible to pre-declare the SPI devices that inhabit this bus. This is done with an array of struct spi_board_info, which is registered by calling spi_register_board_info().
For more information see: Documentation/spi/spi-summary
#include <linux/spi/adf7242.h> static const struct adf7242_platform_data adf7242_pdata = { .mode = ADF_IEEE802154_AUTO_CSMA_CA | ADF_IEEE802154_HW_AACK, /* * Specifies number of attempts to * retransmit unacknowledged * frames while in automatic CSMA-CA * Tx mode. */ .max_frame_retries = 4, /* * Specifies number of attempts to * repeat CSMA-CA algorithm prior to * cancellation of RC_TX command. * Valid range is 0 to 5; * 7: CSMA-CA algorithm is off */ .max_cca_retries = 4, /* * Specifies the maximum back-off * exponent used in the CSMA-CA * algorithm; valid range is 4 to 8 * */ .max_csma_be = 6, /* * Specifies the minimum back-off * exponent used in the CSMA-CA * algorithm; valid range is 0 to * csma_max_be */ .min_csma_be = 1, };
static struct spi_board_info bfin_spi_board_info[] __initdata = { #if defined(CONFIG_IEEE802154_ADF7242) || defined(CONFIG_IEEE802154_ADF7242_MODULE) { .modalias = "adf7242", .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */ .irq = IRQ_PF6, .bus_num = 0, .chip_select = 0, /* GPIO controlled SSEL */ .controller_data = &adf7242_spi_chip_info, /* Blackfin only */ .platform_data = &adf7242_pdata, .mode = SPI_MODE_0, }, #endif };
Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)
The ADF7242 Driver depends on CONFIG_SPI and CONFIG_IEEE802154
------------------- Linux Kernel Configuration ----------------------
[*] Networking support --->
Networking options --->
<*> IEEE Std 802.15.4 Low-Rate Wireless Personal Area Networks support (EXPERIMENTAL)
<*> Generic IEEE 802.15.4 Soft Networking Stack (mac802154)
[*] Network device support --->
--- Network device support
< > Dummy net driver support
< > Bonding driver support
< > MAC-VLAN support (EXPERIMENTAL)
< > EQL (serial line load balancing) support
< > Universal TUN/TAP device driver support
< > Virtual ethernet pair device
-*- PHY Device support and infrastructure --->
[*] Ethernet (10 or 100Mbit) --->
[ ] Ethernet (1000 Mbit) --->
[ ] Ethernet (10000 Mbit) --->
[*] Wireless LAN --->
*** Enable WiMAX (Networking options) to see the WiMAX drivers ***
[ ] Wan interfaces support --->
<*> IEEE 802.15.4 drivers --->
--- IEEE 802.15.4 drivers
< > Fake LR-WPAN driver with several interconnected devices
< > Fake LR-WPAN driver with several interconnected devices
< > Simple LR-WPAN UART driver
< > AT86RF230 transceiver driver
<M> ADF7242 transceiver driver
< > PPP (point-to-point protocol) support
< > SLIP (serial line) support
< > Network console logging support (EXPERIMENTAL)
There is no dedicated Blackfin STAMP evaluation board for the ADF7242. During test and driver development we used the ADF7242 Evaluation Board.
On the EVAL-ADF724x-EBZ:
The EVAL-ADF724x-EBZ can be easily wired to the Blackfin STAMP SPI header.
| EVAL-ADF724x-EBZ Board (J6) | BF537-STAMP (P9) SPI header | ||
|---|---|---|---|
| PIN | Function | PIN | Function |
| 1 | CSN | 9 | SPI_SSEL1 |
| 2 | SI | 5 | SPI_MOSI |
| 3 | SCLK | 8 | SPI_SCK |
| 4 | SO | 6 | SPI_MISO |
| 5 | IRQ_GP4 | 14 | IRQ_PF6 |
| 6 | TRCLK_CKO_GP3 | ||
| 7 | TRFS_GP2 | ||
| 8 | DT_GP1 | ||
| 9 | DR_GPO | ||
| 10 | GND | 20 | GND |
| EVAL-ADF724x-EBZ Board (J4) | BF537-STAMP (P9) SPI header | ||
|---|---|---|---|
| PIN | Function | PIN | Function |
| 5 | VDD_RF_BAT | 2 | +3.3 Volt |
Usage: iz [options] [command]
Manage IEEE 802.15.4 network interfaces
Options:
-d, --debug[=N] print netlink messages and other debug information
-v, --version print version
-h, --help print help
Common commands:
help [command]
Print detailed help for a command.
event [iface]
Monitor events from the kernel (^C to stop).
PHY 802.15.4 commands:
listphy [phy]
List phys(s).
add phy [iface]
Add an interface attached to specified phy.
del [phy] iface
Delete the specified interface.
MAC 802.15.4 commands:
scan <iface> <ed|active|passive|orphan> <channels> <duration>
Perform network scanning on specified channels.
assoc <iface> <pan> <coord> <chan> ['short']
Associate with a given network via coordinator.
disassoc <iface> <addr> <reason>
Disassociate from a network.
list [iface]
List interface(s).
Report bugs to linux-zigbee-devel@lists.sourceforge.net
Userspace tools for Linux IEEE 802.15.4 stack homepage <http://linux-zigbee.sourceforge.net/>
root:/> izcoordinator
Usage: izcoordinator [OPTION]... -i IFACE
Provide a userspace part of IEEE 802.15.4 coordinator on specified IFACE.
-l lease_file Where we store lease file.
-d debug_level Set debug level of application.
Will not demonize on levels > 0.
-m range_min Minimal new 16-bit address allocated.
-n range_max Maximal new 16-bit address allocated.
-i iface Interface to work with.
-s addr 16-bit address of coordinator (hexadecimal).
-p addr 16-bit PAN ID (hexadecimal).
-c chan number of channel to use.
-h, --help This usage information.
-v, --version Print version information.
Report bugs to linux-zigbee-devel@lists.sourceforge.net
Userspace tools for Linux IEEE 802.15.4 stack homepage <http://linux-zigbee.sourceforge.net/>
On this demo network we will have 3 radios connected to different boards. On each of these radio interfaces, we will start 1 node which will have short addresses 0x1234, 0x8001 and 0x8002. Node with short address 0x1234 will act as a coordinator and shall run izcoordinator on it, which will handle network with PAN ID 0x10. Nodes 0x8001 and 0x8002 will associate with coordinator and will receive addresses after association. We will start izchat tool on these nodes.
root:/> iz add wpan-phy0
Registered new device ('wpan0') on phy wpan-phy0
root:/> ip link set wpan0 address 11:22:33:44:55:66:77:88
root:/> ifconfig wpan0 up
root:/> izcoordinator -i wpan0 -s 0x1234 -c 12 -p 10
In case the izcoordinator daemon is started successfully we see it in the process list
root:/> ps
PID USER VSZ STAT COMMAND
1 root 572 S /init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [watchdog/0]
5 root 0 SW [events/0]
6 root 0 SW [khelper]
9 root 0 SW [async/mgr]
41 root 0 SW [sync_supers]
43 root 0 SW [bdi-default]
45 root 0 SW [kblockd/0]
64 root 0 SW [khungtaskd]
65 root 0 SW [kswapd0]
104 root 0 SW [mtdblockd]
105 root 0 SW [bfin-spi.0]
118 root 0 SW [wpan-phy0]
144 root 798 S -/bin/sh
145 root 493 S /sbin/inetd
146 root 786 S /sbin/syslogd -n
147 root 782 S /sbin/klogd -n
148 root 483 S /bin/watchdogd -f -s
155 root 848 S izcoordinator -i wpan0 -s 0x1234 -c 12 -p 10
156 root 786 R ps
root:/>
Following output from ifconfig indicates that wpan phy0 was successfully added and is running. The ip command also assigned the 64-bit (IEEE) address to the device.
root:/> ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wpan0 Link encap:UNSPEC HWaddr 11-22-33-44-55-66-77-88-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING NOARP MTU:127 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
root:/>
Associate with a given network via coordinator
root:/> iz add wpan-phy0
Registered new device ('wpan0') on phy wpan-phy0
root:/> ip link set wpan0 address 11:22:33:44:55:66:77:11
root:/> ifconfig wpan0 up
root:/> iz assoc wpan0 10 0x1234 12 short
Received ASSOC-RESP status 0, addr 8001
Received short address 8001, status 00
root:/>
The network coordinator assigned short address 8001 to this node.
Associate with a given network via coordinator
root:/> iz add wpan-phy0
Registered new device ('wpan0') on phy wpan-phy0
root:/> ip link set wpan0 address 11:22:33:44:55:66:77:22
root:/> ifconfig wpan0 up
root:/> iz assoc wpan0 10 0x1234 12 short
Received ASSOC-RESP status 0, addr 8002
Received short address 8002, status 00
root:/>
The network coordinator assigned short address 8002 to this node.
Two nodes associated with the network. Now start simple chat program (0x8001 and 0x8002 are the short addresses are received during association):
Node 1:
root:/> izchat 10 8001 8002 Hello World! >Thanks
Node 2:
root:/> izchat 10 8002 8001 >Hello World! Thanks
This is a pretty simple two way communication. The ASCII strings are encapsulated in IEEE802.15.4 DATA frames
file: trunk/user/lowpan-tools/lowpan-tools-0.2-rc2/tests/test2.c
/* * Linux IEEE 802.15.4 userspace tools * * Copyright (C) 2008, 2009 Siemens AG * * Written-by: Dmitry Eremin-Solenikov * Written-by: Sergey Lapin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <linux/sockios.h> #include <net/if.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <stdio.h> #include <stdint.h> #include <string.h> #include <unistd.h> #include "ieee802154.h" int main(int argc, char **argv) { int ret; struct sockaddr_ieee802154 sa = {}; struct ifreq req = {}; char buf[] = {0x01, 0x80, 0xa5, 0x5a}; int sd = socket(PF_IEEE802154, SOCK_DGRAM, 0); if (sd < 0) { perror("socket"); return 1; } strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); ret = ioctl(sd, SIOCGIFHWADDR, &req); if (ret < 0) perror("ioctl: SIOCGIFHWADDR"); sa.family = AF_IEEE802154; sa.addr.addr_type = IEEE802154_ADDR_LONG; sa.addr.pan_id = 0xffff; memcpy(&sa.addr.hwaddr, req.ifr_hwaddr.sa_data, sizeof(sa.addr.hwaddr)); ret = bind(sd, (struct sockaddr*)&sa, sizeof(sa)); if (ret < 0) perror("bind"); ret = send(sd, buf, sizeof(buf), 0); if (ret < 0) perror("send"); ret = recv(sd, buf, sizeof(buf), 0); if (ret < 0) perror("recv"); ret = shutdown(sd, SHUT_RDWR); if (ret < 0) perror("shutdown"); ret = close(sd); if (ret < 0) perror("close"); return 0; }