News Archive (1999-2012) | 2013-current at LinuxGizmos | Current Tech News Portal |    About   

Article: Building a Linux/RTAI based software radio

Apr 16, 2001 — by Rick Lehrbaum — from the LinuxDevices Archive — 2 views

You already knew you could use a Linux box to create your own “Internet radio” station that streams MP3s onto the 'net, right? But did you know you could turn your Linux system into a real radio transmitter, using nothing but the system's parallel port as the wireless media interface?

Well, don't get too excited . . . because this is really just a very clever way to demonstrate the real-time capabilities of a popular real-time Linux add-on, called RTAI (the Real-Time Application Interface).

How it works

First you need to know a bit about RTAI. Please bear with me, for I'm about to attempt a highly simplified two-paragraph explanation of RTAI. If you prefer all the gory details, read some of the whitepapers referenced here.

Basically, RTAI is a tiny kernel that assumes ultimate control of system resources and runs Linux as a low-priority task beneath itself. Thereafter, RTAI has dominion over system Interrupts, a situation which allows it to respond in a near-instantaneous manner to certain real-world events when they occur. The term “near-instantaneous” is, of course, relative. At the risk of setting myself up for an email deluge, I'll oversimplify it like this: Linux itself is capable of handling response times, depending on who you ask, in the range of a few milliseconds to a few dozen milliseconds. RTAI, according to Lineo's specs on Embedix RealTime, can respond to interrupts within approximately 15 microseconds — making it around a thousand times as responsive as the Linux kernel.

One further comment, before moving on, is that although RTAI can obviously greatly improve a system's responsiveness to real-world events in comparison to normal Linux, that improvement comes at a price — which is that the techniques needed to take advantage of RTAI fall outside the normal Linux programming model. You can't, for instance, simply install RTAI and instantly see improvements in applications such as streaming multimedia — unless they were designed to take advantage of RTAI.

In any case, it is this thousand-fold improvement in event responsiveness provided by RTAI that forms the essence of the software radio demo.

The demo software creates a radio carrier in the “long wave” radio spectrum, using a task running under RTAI to turn parallel port data lines on and off at a fast rate. The carrier is further modulated with a lower frequency, in the audio range, to produce music. Now for more detail.

More detail

The RTAI software radio demo was developed by Lineo's Pierre Coupard, to show off the capabilities of RTAI. To create an OS platform for the demo, Coupard built a small footprint embedded Linux kernel and filesystem which fits on a single floppy diskette and contains the RTAI real-time add-on and the RTAI-based radio demo program. The floppy boots on an x86 PC compatible system, loads Linux, loads RTAI, and displays a simple startup menu.

When you activate the software radio demo from the menu (option 1 or 2), a task is started which toggles the data lines on the printer port at a rate of 30,600 times per second, which creates a 15.3KHz square wave signal on the parallel port data lines. By the way . . .

Coupard's demo originally generated a carrier frequency of 153 KHz, based on running the real-time task on every system timer interrupt, or 306,000 times per second. Since at that rate it required a 500 MHz Pentium or faster, and my system only has a 400 MHz Celeron, I talked him into cutting back the CPU requirement so that nobody would have any trouble playing the demo. (Did I mention that the carrier frequency is one-half that of the rate at which the real-time task runs, since it turns the bits on and off every other time?)

In addition to simply toggling the data lines on and off, the RTAI task cycles through a decision tree which turns the carrier itself on and off at a rate corresponding to a series of musical notes. The result can be heard on an AM radio if you tune it to the right frequency, and if you provide a suitable antenna.

The antenna

Coupard recommends connecting an unshielded parallel cable to your PC's parallel port connector and forming it into a coil, which you then loop around your radio's receiving antenna. You can see what this looks like in this photo.


RTAI software radio transmission antenna and AM receiver

I cheated. I plugged a printer cable into my PC that had a female DB25 on its other end, and inserted the bare end of a thin copper wire into one of the data lines (pin 2 works) of the dangling end of the cable. Then, I wrapped the wire tightly around my AM radio's telescoping antenna. Anything along those lines ought to work, but you do need a good antenna or you won't hear anything.

Where should you tune your radio?

Unless your radio goes down to 15.3 KHz, which isn't likely, you will need to tune in one of the many harmonics of the transmitted carrier. Actually, you'll quickly discover that the signal appears in many locations. This is because the transmit carrier is a square wave. Not a good general practice for radio transmitters, because it results in an infinite number of harmonics, but handy for this demonstration since it provides thousands of places on your dial where you can receive the signal generated by the RTAI demo.

The step-by-step procedure

OK, so now that you know what to expect, here's what to do . . .

  • Download this Linux boot image and copy it to a formatted floppy. To install the file on the floppy, log in as root and do a “dd if=diskette.img of=/dev/fd0”

  • Reboot your system from the floppy you just prepared in the above step.

  • Assuming it boots successfully from the floppy, select option 1 from the menu that is displayed. Note: ignore the error message that says “can't access tty; job control turned off” — it is due to a programming error and is of no consequence.

  • Tune your AM radio to the lowest available frequency band. This might be at the bottom of the AM broadcast band, or if your radio has a “long wave” band, listen to the lowest frequency you can receive. Listen for computer generated music. You will be receiving harmonics of the 15.3 KHz carrier so you might find good signals at 520.2, 535.5, 550.8 KHz, and so on.

  • The system is really running Linux in addition to RTAI and the software radio (and music synthesis) program. As a result, you can type commands like “ls” and “cd” at the “#” shell prompt that is presented once the demo begins. You can type “exit” to end the software radio demo and return to the main menu.
The music you will hear is what Coupard calls “my approximation of the beginning of Bach's Toccata and Fugue.”

Cool, eh? In case you'd like to read the source code of Coupard's RTAI software radio demo, you can get it here. Enjoy!

 
This article was originally published on LinuxDevices.com and has been donated to the open source community by QuinStreet Inc. Please visit LinuxToday.com for up-to-date news and articles about Linux and open source.



Comments are closed.