ArduSat SD Card Prototyping

Since my last post on the ArduSat and the idea I had to use the Supervisor node, an ATmega2561, as the core of a centralised eXtended RAM system for the Client nodes, ATmega328p “Arduino” devices, I’ve been thinking and working on a solution for building a centralised non-volatile SD Card based storage solution.

With design, sometimes it is necessary to let an idea stew for a while before the right answer just sort of distils out of the soup. For the solution for this problem, this was the case. There was some thinking space required…

thinking space

The Question

There are 16 Client nodes in the ArduSat platform. Each and any of them may wish to use the central SD Card to store information at the same, or at different times. How would it be possible to allow more than 16 files to be open on the one SD Card (connected to the Supervisor node) whilst maintaining consistency in the file system? How would access to the file system be scheduled?

The Tools

I have been using the ChaN FatFs file system libraries now for some time. They are fully featured and have a very clean design, fully separating the file system layer from the underlying physical media access layer (the drivers). This means that the file system tools can be implemented on many different architectures, with only changes to the driver layer (DiskIO) needed for each platform.

The Thought Process

My initial thought was that the Supervisor node should maintain the file system, and that I should write packaging for the FatFs file system commands to allow them to be remotely implemented across the SPI bus, in a similar manner as described in the XRAMFS post.

The idea of writing these “remote controls” for the file system commands was scary, as I recognised that there are 33 commands in the interface, and each of them has their own characteristics. Also, maintaining these interfaces would likely be problematic, as I would have to test each command extensively to ensure that there were no “thick thumb” errors introduced into the stable and proven FatFs library.

Some weeks passed…

Then at about 3am, I realised that the right answer was to write a “shim” between the standard FatF file system commands and the standard physical media drivers, and to have this shim operate across the SPI bus in exactly the same manner as the XRAMFS solution.

So, I wrote it.

The Solution

The solution separates the ChaN libraries into two parts. The file system part is resident on the Client node. Each Client node maintains its own view of the file system on the Supervisor SD Card. As the ChaN FatFs library is written for low memory devices, the file directory tree is refreshed each time a change in the working file is done. The Supervisor node only does the DiskIO under the command of each of the Clients.

There are only 5 relevant driver layer DiskIO commands. These commands are used in the Supervisor node to execute requests sent over the SPI bus from the individual Clients. Since there are only a small number of commands, and they are static and dependent on the architecture of the machine they’re running on, their functionality is quite constant. The Supervisor has no knowledge of the file system at all. It simply implements DiskIO commands on sectors of the SD Card as requested, one a time, as requested by Clients.

The Supervisor implementation simply expands on the existing Task loop established for the XRAMFS system, by adding in the 5 additional DiskIO commands. The added complexity, that the SD Card is accessed over the SAME SPI bus as the communications between Client and Supervisor, means that I had to introduce an interim “Pending” state for commands to allow the Client to wait for confirmation that a task has been completed or, in the case of disk_read or disk_ioctl, to recover the waiting data from the Supervisor.

The Client implementation inserts different shim DiskIO commands for the FatF system to call. These commands use the SPI bus to call the Supervisor, and enter a request. Some commands return immediately, allowing the Supervisor to continue with the command, once the command and any required data has been transferred. Other commands wait until they can retrieve information from the Supervisor, before returning to the FatF file system layer of the library.

In this solution, the XRAMFS was instrumental in simplifying the transfer of information. The exclusive availability of 16kB of RAM for each Client meant that disk_write or disk_read commands could cache their data in XRAMFS whilst it was actually written to or read from the SDCard. Because the RAM is available exclusively, there is no consideration that another Client may overwrite the results of a command, or that memory exhaustion may corrupt data.

The code is available at Sourceforge in the usual location.

How does it work?

When a Client program calls one of the FatFs library commands, it in turn calls one of the special ArduSat SPI DiskIO shim routines. These routines signal the Supervisor in the normal manner, and transfer any data associated with the command into the Page of XRAMFS assigned to the Client.

The Supervisor will then undertake the standard DiskIO command, retaining the result of the command and any data resulting from the command in XRAMFS.

Both Client DiskIO routines, and the Task running in the Supervisor are aware of the “Pending” state, which is where a DiskIO command has been completed on the Supervisor and there is data waiting in the XRAMFS for the Client to recover.

Once the Client DiskIO command completes, it returns the normal interface information to the calling FatFs command.

Here a monitor program on a Client is initialising the SD Card. If the Supervisor notices that the SD Card is not initialised, it will return Error, and then undertake to initialise the card. The second call for initialisation will then be successful. This decoupling method ensures that Clients cannot reinitialise the card, whilst other Clients may be using the Card.

The file system (on the Client) is then initialised Then, the SD Card status is read. Finally, the current working directory is read and printed.

Initialisation

In this screenshot, a file is opened for reading, and the file pointer set to the start of the file. A dump of the first 64 Bytes of the file is read and printed. Then the file is closed.

readfile

Here, the same file as above is opened for writing, and 45 bytes of 0x10 (16) are being written. The result is checked by opening the file for reading, and dumping the relevant bytes to the screen. Success!

writefile

Issues

The Client (Arduino) ATmega328p has so little Flash and RAM that implementing the FatFs consumes a significant proportion of the available resources. From the ChaN FatFs web site, at least 13 kByte of Flash (of 32 kByte on the Arduino), and 600 Bytes of RAM (of 2048 Bytes on the Arduino) are consumed by the library alone. This is excluding the working buffers necessary to prepare or process data for storage.

I was unable to fully test the FatFs solution, because of RAM and Flash limitations. I simply couldn’t turn on all the features. However, I have some confidence that the solution fully works, because the actual FatFs library is unchanged from the working solution that I’ve tested on the Arduino Mega platform. It is only the DiskIO routines that have been tampered with, and since they produce reliable results for some of the FatFs functions, there is every reason to believe they would work for all of the functions.

Thank you

Jon for providing a new Freetronics EtherMega, so that I could complete the prototyping work.

ArduSat and NanoSatisfi for running a great project, which inspired this thought process. Possibly, this work might be useful for one of the launches over the coming years.

Another NBN rant

There are a couple of things that the NBN fanbois generally fail to note about Liberal Party Broadband Policy.
(and I don’t vote, so this is just a technical & economic discussion)

It is not about FTTN at all. FTTN is only a cheap and fast “filler” for areas of Australia that aren’t being done some other way.

  • Satellite remains.
  • Fixed wireless remains.
  • Greenfield FTTH remains.
  • FTTH On-demand (i.e. anyone who wants to have it) remains.
  • HFC (and we know that EuroDOCSIS can do 1Gb/s services, as needed) will be recovered and provide service for 2.6 million homes, immediately.

All that is changing is that the difficult brownfields services are being given a fast and cheap alternative to get some kind of service upgrade in the short term (say 5 to 8 years).

Fanbois bitch about the FTTN cabinets in the street. Yes they’re ugly. Essentially, they’re providing centralised networked power to drive the copper tail for all FTTN subscribers. Cabinets are ugly, but they’re very maintainable, and upgradable at low cost and with low impact for consumers. The current FTTH solution is putting an unmaintainable ugly lead acid battery IN MY LOUNGEROOM! (And, forcing me to pay for the power for their service too. I’m used to getting my POTS power for free.)

And, if (when) the FTTH battery is dead my lifeline services are affected. It is part of every NBNCo service agreement that it is not their liability, if your battery is dead, you can’t make a call, and therefore you die!

I’d rather have someone professional maintaining my (mother’s / great aunt’s / disabled friend’s) lifeline services battery and have it somewhere where it can be properly maintained to deliver a known grade of service, without interfering with my life.

Oh, and the famous diagram with 1Gb/s FTTH services on it, with everything else miles below. Nice picture. He could have added HFC services up there at 1Gb/s too, but he didn’t. But paying for these 1Gb/s services is another story.

The NBNCo has gazetted their 100Mb/s prices in a SAU with the ACCC, and their prices will be INCREASED annually by CPI (-1.5%) for 27 YEARS. That means in 27 years we’ll be paying much more than today (compound it up, I dare you) for the same service. They need to lock in this price to pay for their network. Don’t imagine that Moore’s law is going to apply here. 27 years ago was 1986, and then 9600 baud was looking pretty good. How will 100Mb/s look in 2040? Now, how much is then 1Gb/s going to cost, if 100Mb/s has a fixed price for the next 27 years? Good question. You got any unwanted children you can sell?

UPDATE: So just a day after this rant was written, NBNCo announced pricing for 1Gb/s services, conveniently only available after the next election in December 2013. Pricing is $150 wholesale. This is exactly twice the 100Mb/s price. An interesting price point, given this will cut the fan-out on the GPON network infrastructure from 32:1 down to 2:1. Also RSPs will need to upgrade their POI backhaul packages by a factor of 10x if they want to provide this service. Using the ACCC transmission pricing calculator, this looks like a recipe for a VERY expensive retail service.

The Labour NBN plan is unbuildable. There are not the fibre splicers in the country we need to achieve the required daily rate build rate. NBN Co contractors (to get their contracts in the first place) are paying lowest rates in the market. Anyone with any skills is working on the mines in WA, fly in fly out. Not camping in the truck, schlepping around the country digging trenches. This was apparent back in 2010. Blind Freddy could have predicted the situation the NBNCo is in now, with missed delivery targets.

In 15 years, Conroy might be remembered for the man who thought of NBN. But Turnbull will be remembered as the one who saved it, and delivered it.
(Actually, Conroy should be remembered as the man who killed NBN, when he axed its predecessor OPEL http://en.wikipedia.org/wiki/OPEL_Networks, on April 2, 2008, when he entered office).

UPDATE: So on 12th July 2013, Mike Quigley resigned or retired from his role as CEO of NBN Co. Surely his efforts will not go unrewarded. My bet is that in the second half of 2014 or early 2015 Mr Quigley will be appointed to the Board of Alcatel Lucent. After all, getting your former employer an uncontested 1,500 million Dollar contract from the Australian Government for obsolete GPON equipment must be worth something, right?