I have been doing a fair bit of reading in the area of wireless sensor networks (WSNs) as a part of my work as a research associate on the DIAS project. It is interesting to note how few WSN papers actually deal with real problems. I should do a survey of my current literature holdings and determine how many of them are grounded in an actual problem that the authors were trying to solve.

For example, consider this snippet:

20070304-Wsn-Assumptions

The authors assume you have enough nodes in your network to form clusters. Most of the deployments I have to consider aren’t going to have a budget large enough to deploy so many nodes that we can form clusters. So, what do I do if I’m developing a four-node network? What use is this algorithm to me? Do I let four nodes duke it out for the role of “cluster head”, even though I already know the node with the GSM radio (read: mobile phone) is going to be in charge?

Assumptions are dangerous things.

This… this is a rant.

It is incredibly frustrating being a Mac and Linux user if you’re interested in embedded systems development. In particular, if you are working with the MSP430, one of the only viable parts if you’re really, really concerned about power consumption. There simply aren’t, at this time, any parts (that I know of) that come close in terms of power saving modes.

On the Mac and under Linux, it is possible to build the MSP430 GCC toolchain. That’s a big step, and it integrates nicely into build systems like make and Scons. However, that’s only part of the problem. Once you’ve built the executable for your embedded platform, you need to make the code go from the PC to the embedded device.

By far, the most common way for this to take place is via JTAG. This multi-wire protocol provides a mechanism by which the flash in these little processors can be rewritten from the host PC, as well as (if the tools are available) in-circuit emulation. Of course, both of these assume certain hardware and software connected to and on the host PC. The biggest problem I’m running into right now is that the JTAG programmer MUST be USB-based, or I can’t use it—because my Mac doesn’t have a parallel port, so even if I’m going to build a Linux virtual machine, it still needs to be a USB-based solution.

For example, both Rowley and Softbaugh produce USB-based MSP430 JTAG programmers; neither provide support for Linux. They have Windows XP and 2000 drivers, but they don’t support any open-source platforms; I guess embedded systems developers don’t use Linux. (As long as you’re paying £150 for a programmer, you might as well pay for your OS as well.) I’m not having much luck discovering which platforms the MSP-FET430UIF does or does not work with; are there Linux drivers? Aren’t there?

The problem, quite simply, is that we are an open-source project that builds under Windows, Mac, and Linux; somehow, I’d like to easily build the MSP430 version of the Transterpreter and install code on a development board. Currently, I’ve been working on the Tmote Sky simply because it has USB—but that’s not acceptable looking forward. And, more specifically, I travel a fair bit—I have to have a mobile solution that can work from my MacBook.

It seems to me that most embedded systems developers must not travel much, and have a big workbench where everything is set up just so for the work that they do. These developers all use Windows, and they pay a lot for their tools—because they are not trying to do embedded development under the auspices of an open-source research project. They are, instead, charging what their time is worth, and they can (therefore) afford the tools and bench space to do what they need to do.

I can run a Windows virtual machine on my Mac, and I’ll have to; it will run the lite tools provided by Softbaugh, and I’ll be able to program MSP430 boards using Tom’s (Windows only) programmer over the Texas Instrument flavor of JTAG. (Why, oh why, do embedded developers put up with the lack of standards on flash programmers? Every single chip should be programmable and inspectable over the same protocol.) I can mount my MacBook via Samba, and my development process will look like this:

  1. Edit source on Mac. (Using freely available, open-source tools.)
  2. Compile on Mac. (Using freely available, open-source tools.)
  3. Flip to Windows, and upload the code to the MSP430. (Using expensive, closed-source tools.)

Rinse and repeat.

If anyone has any thoughts on how we can improve this situation, please let me know. It seems to be we should build a device that has USB on one side, a 20-pin header on the other, and we build cables for each chip family we want to support. There is one protocol on the USB side, and the MPU in the middle of those two connectors handles the JTAG translation for each device family on the other side. Then, we demand that TI, AVR, and every other embedded chip developer provide the driver for that device that sits in the middle—and nothing else. If they don’t provide that software, we don’t use their product. This kills the JTAG programmer market (proprietary hardware that is often tied not only to a single OS, but also a single compiler), but that’s fine by me.

This is the end of this rant… for now.

The Transterpreter project was born three years ago around this time; it started life as a Scheme implementation of a Transputer bytecode interpreter, and has grown quite a bit since then. Given that we’re starting into 2007, it seemed like a good time to give an update about what is going on in the group. In no particular order:

  • Jon Simpson (third-year undergraduate at Kent) has been working on revitalizing the LEGO Mindstorms RCX port of the Transterpreter. The old version was built on top of BrickOS; we were, effectively, running two operating systems on the LEGO, one on top of the other! Jon is at the point where he has the Transterpreter running natively on the LEGO Mindstorms RCX, can handle button input (including a nifty, non-blocking debouncer), and is continuing to slowly build up to more useful end-user interface code. By March he expects to have a complete and usable (native) port of the Transterpreter on the RCX. (/branches/new-lego)

    Looking forward, Jon (and the rest of us) are excited about getting the NXT port of the Transterpreter rolling. We have already had some interest expressed from others about taking part in this effort; we’ll be generating some mail on that shortly.

  • Damian ended the year cleaning up his Cell port of the Transterpreter (/branches/cell), with particular attention being paid to developing a native, big-endian port of the Transterpreter (/branches/big-endian). Currently, we pay a penalty on all big-endian hardware, and Damian (and other’s) efforts in this regard will give us full, native performance on big-endian platforms; this effects the PowerPC (Mac, Cell) and Mindstorms RCX, among others. Looking forward, he is coming back to 42 (our experimental compiler), and wants to work out the critical points in generating little/big endian code as well as “fat binaries”.

  • Adam Sampson picked up a few Arduino boards (http://www.arduino.cc/), which are driven by an Atmel ATmega8. This little chip has roughly 7KB of free flash and 1KB of RAM; it represents the smallest device the Transterpreter has been targeted at yet (/branches/arduino). While Adam’s intent was to develop an Arduino port of the Transterpreter, he says that “in the process I’ve done a load of cleanups which are probably more useful than the work I was intending to do.”

    The “cleanups” that Adam has made in the Arduino branch are (in his words):

    1. wrapper (currently untested) for the ATmega8

    2. instruction dispatching via switch, so all the instructions end up inlined, which cuts the code size considerably (and should make it a bit faster)

    3. some fixes to comments

    4. consistent ANSI C prototypes throughout

    5. add multiple-inclusion guards to all the headers

    6. make the word size code use inttypes.h and be configurable at compile
      time

    These are all nice cleanups that will ultimately be merged back into the trunk, and therefore benefit all of the Transterpreter ports.

    Adam’s explorations also involved cleaning up the “memory array” code (/branches/mem-array). When originally developing the TVM, we had a “virtual memory”, which made detecting a variety of faults easier; this was the original memory interface for the Transterpreter, but was dropped shortly after porting to C. Adam has cleaned this up as well, and (in his words, again):

    1. make the array memory backend actually work (mostly with the aim of being able to use a non-native word size, although I haven’t yet tested that)

    2. do bounds checking in mem_array so that the TVM stops (rather than
      segfaults) in the event of a bad memory access

    3. fix a number of bugs related to string handling and memory allocation which were revealed by Valgrind; we need to do a Valgrind run with some proper code (using dynamic memory) at some point to try and shake out more

    4. completely rework the code in stiw that builds the memory map, since it had a number of bugs and didn’t work with mem_array before

    5. fix a few bugs in interpreter revealed by the work above

    These are all excellent, and again will find their way back into the trunk. Indeed, as part of his explorations, Adam generated a number of tickets that I added to Trac (http://trac.transterpreter.org/), and we can begin addressing in the interpreter, which is good.

  • Matt Jadud (that’s me) has been focusing on the MSP430 port, living in the Tmote Sky branch (/trunk/wrappers/tmotesky). As a side effect of this work (along with Jon Simpson), we developed ‘tinyswig’ (/trunk/scripts/tinyswig.scm), a mini, SWIG-like script that lets us quickly and easily write C extensions to the VM, callable from occam-pi. After this, we worked out the details of interacting with hardware directly from occam-pi, which (in some cases) completely eliminates the need to call out to C from occam. For example, in ‘/trunk/wrappers/tmotesky/Native‘, you can find our initial explorations in this area, where we are bringing up the virtual machine with no connections to the hardware, and then configuring the MSP430 directly from occam-pi. We expect this to make implementing functionality for new embedded platforms much easier for the developer in some cases.

    Although it is unexciting infrastructure, I also began work on migration from Autotools to Scons (/branches/scons). Currently, it is possible to build the Transterpreter for Linux/Intel, MacOSX/Intel, and the MSP430 in this branch using Scons. The build scripts are, I believe, clearer, easier to extend, and will (I believe) give us a better cross-platform build experience (eg. Windows). Currently, we have to maintain a completely separate build system for Windows, which is untenable in the long run; with Scons, we have a chance of bringing things together nicely across all major development platforms. So, while unexciting, I consider this a rather important revision of tools and infrastructure. (Of course, I’m working on it, so you might expect I’d say that.)

    Along with the under-the-radar updates to the build system, I’ve nearly finished refactoring the linker; what had grown to 5000+ lines of Scheme has been reduced to roughly 1500. While the new slinker is not done yet, it is much simpler and much more modular. The new slinker was informed greatly by our explorations with 42—the underlying data structures are far more intelligent than they used to be, and allow us to do complex things very simply. It is, in a nutshell, a joy to work with (as source code), which I can no longer say about the original slinker.

    Looking forward, I’ll be working more with two new hardware development boards for the MSP430, exploring radio communications, analog-to-digital conversion, storage of data to external devices (SD, etc.), and most importantly, the integration of interrupts with the Transterpreter scheduler. The development boards are important, as they allow me to do in-system debugging via JTAG, which will be essential for the implementation of interrupt handling. This will, like many other things we do, impact all Transterpreter ports.

  • Christian Jacobsen has recently been sighted trying to set up a “build bot” for the Transterpreter project; this will automatically check out our code, build it, and run the test suite on a regular basis. However, he should not be doing this, but should be submitting the final version of his thesis. We expect that to go out the door ANY DAY NOW. I read it on my flight over to the USA, and believe-you-me, it was very, very exciting. Very.

If this sounds like we’re busy, it’s because we are. We’ve got a few other things up in the air related to our ongoing efforts, and will drop word of those as they see the light of day. If you have any questions about the project, or want to get involved, please feel free to drop me a note (matt at this domain).

In my last post, I talked about how we have some new documentation available for people interested in porting the Transterpreter. This documentation is, primarily, about how to use C and occam-pi together to configure hardware devices for working with the Transterpreter.

However, writing programs that involve two languages does not necessarily make life easier. Which is why I’m glad to say that it is possible to talk to hardware directly from occam-pi. In our porting documentation, we demonstrate the use of C and occam-pi to control the LEDs on a Texas Instruments MSP430-based device. What’s nice is that we don’t need C at all!

In occam-pi, we can declare a variable PLACED. Normally when you declare a variable the compiler decides on where, in memory, that variable will go. However, when working with memory-mapped I/O, you might want to place a variable there, and know that whenever you set that variable’s value, or read from it, you are reading from a particular location in memory. The PLACED keyword allows you to choose exactly where in memory that you want a particular variable to live.

You can do the same thing in C, of course… but you can’t guarantee the safety of that memory-mapped location in the context of many threads. occam-pi, on the other hand, guarantees at compile time that your program is free from race hazards.

Currently, you can see my explorations with this in the trunk of the source tree in the tmotesky wrapper. Things will move, eventually; for now, the Native subdirectory contains my explorations in configuring the Tmote Sky entirely from the interpreted language. Right now, I’m working on the SPI bus and radio configuration.

We’re not prepared to call things “version 1.0″ yet, but we are prepared to open the source. A read-only, anonymous Subversion repository is now available:

svn co http://svn.transterpreter.org/transterpreter/trunk/

If you’re just interested in using the Transterpreter on Mac OSX (PPC), Windows, or Debian GNU/Linux (Intel), you can just download a pre-built binary. However, if you want to use the Transterpreter on Mac OS X (Intel), or some other platform for which we do not have binaries, you will need to check out and build from source.

If you are really crazy (or are really curious, or know what you’re doing), you’re welcome to check everything out, including all our exploratory branches. Simply get rid of ‘trunk’ on that first URL. I’d like to point out that this is not, in the general case, necessary.

Lastly, if you’d just like to browse the source, you can take a look at

http://trac.transterpreter.org/browser/transterpreter/trunk

If you have any questions, I’d encourage you to join the tvm-discuss mailing list, or drop me a note.

Update 20060809: I’ve set up a new download page that provides more detail regarding the Subversion download.

I’m pleased. My ‘gtd’ script has evolved nicely over the last few days. By default, the output of the ‘gtd’ command line script looks like:

  20     3d @online  bills  Visa/MC/House bills
  10     3d @online  DIAS   PL email follow-up
  11     5d @online  CPA    CPA reg?
  19     6d @online  ICER   PhICER app deadline
  21  1w 1d @fun     life   6th anniv.
  12  2w 0d @PB      ACM    RoboDeb draft
   9  4w 0d @mtg     CPA    draft presentations
   1  4w 3d @mtg     DIAS   Manchester
   2  4w 4d @mtg     DIAS   Manchester
   3  4w 6d @online  ACM    SIGCSE paper due
   8  5w 0d @online  ACM    ACM SAC due
   4  6w 2d @mtg     CPA    CPA
   5  6w 3d @mtg     CPA    CPA
   6  6w 4d @mtg     CPA    CPA
   7  6w 5d @mtg     CPA    CPA
  13  8w 4d @online  AAAI   Symposium CFP
  17 070324 @fun     life   Sarah + Andy wedding
  14 070326 @mtg     AAAI   Symposium
  15 070327 @mtg     AAAI   Symposium
  16 070328 @mtg     AAAI   Symposium

There are a number of things I like about the tool as it has evolved. For one, I like the relative dates; they have more meaning to me, in the short term, than absolute dates. For example, it is more meaningful to me that I should handle my bills in three days time, rather than knowing I should do it on the 7th of August. I can also display this information by context (proceeded by an ‘@’) or by project. Of course, I can edit existing entries, flag items as being done, and if I want, remove entries from the ToDo list completely.

[Lyra] gtd > gtd -h
gtd [ <flag> ... ] [<todo>] ...
 where <flag> is one of
  -@ <context>, --context <context> : Add context to the ToDo in question.
  -! <project>, --project <project> : Assign this ToDo to a project.
  -# <date>, --date <date> : Assign this ToDo a completion date.
  -e <id>, --edit <id> : Edit an existing entry.
  -d <id>, --done <id> : Complete a ToDo.
  --remove <id> : Remove an entry.
  -s <regexp>, --search <regexp> : Search DB using a regular expression.
  --by-context : Show ToDos by context.
  --by-project : Show ToDos by project.
  --date-display <mode> : Date display mode; either 'relative' or
                             'absolute'. Default is 'relative'.
  --help, -h : Show this help

Because I’m using the MzScheme “cmdline.ss” library, I also get some nice help documentation “for free”. That’s quite handy.

The current default for the script is to render a .reminders file as well; this works with the UNIX utility ‘remind’ (useful links: 1, 2, and the home of remind). This is incredibly handy; I then render it to my desktop using Geektool:

remind-geektool-exe

As you can see, I render both a calendar and my ToDo list to my desktop; this way, it’s never more than a short keypress away. I like this, because it makes it very easy to figure out when I’m supposed to be doing what, where.

This may be one of the more immediately useful programs I’ve written lately. As in “this solves a problem I have, right now, and solves it the way I want.” That’s very groovy.

Porting to bare hardware is slightly more difficult than I thought it would be.

The Transterpreter recompiles to new targets with little or no effort; it’s just not a big deal. The VM is written in a subset of ANSI C that ports well from one machine to another. However, running on bare hardware means that you must first initialize the hardware.

This has been my biggest battle with the Tmote Sky. I’m not particularly well versed at reading datasheets (PDF) for hardware boards, nor does everything in the MSP430 processor specification (PDF) make sense to me the first (or second, or sometimes the third) time through. I’ve spent a fair amount of time in the last few days just reading the lowest-level sources for TinyOS, which has taught me a great deal about how they initialize the MSP430 (and therefore, the Tmote Sky).

For example, it took some time to discover the LED initialization sequence:

#define INIT_LEDS()  P5DIR = 0x70 ; P5OUT = 0x70;

And, I’m not even sure about my setting of the P5OUT register. Certainly, those register settings ignore everything else on port 5.

The serial communications took longer; I have to admit, there’s still some things going on that I don’t fully understand, as my initial explorations in this area were almost the same. Granted, one bit might make a difference in this case:

#define INIT_SERIAL()
  P3SEL |= 0xC0;
  U1CTL = SWRST; U1CTL |= CHAR; U1CTL = SWRST;
  U1CTL |= CHAR; U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
  U1TCTL |= SSEL_ACLK;  U1BR0 = 0x03; U1BR1 = 0x00;
  U1MCTL = 0x4A; ME2 &= ~USPIE1;
  ME2 |= (UTXE1 | URXE1); U1CTL &= ~SWRST;

That code is heavily based on some of the hardware initialization code in TinyOS.

This is an important start, and not bad for three days of work. It’s not as quick as I thought it would be… but it isn’t terribly slow, either. Once I have the hardware initialization sequence done (the biggest pieces left are the flash and the radio), “porting” the Transterpreter is a piece of cake. That is, binding external channels to these interfaces isn’t the hard part—it’s just getting the mote to come to life with everything ready to go that is the trick!

(Of course, learning how to turn these devices on and off is going to be another challenge…)