Main

March 18, 2007

Modifying read-only file systems in an embedded system

It's often a good idea to make the root file system in a embedded system read-only. If you do this and only make changes to files in a ram disk (mounted under /tmp, for example) the device will always come back to a known state when powered up. This is a nice feature and often a requirement.

But sometimes you need to make changes which persist. Check out the "mini fan out" file system. It allows you to layer changes on top of a read-only file system.

I have not used this package directly, but I plan to shortly.

Firefox bookmarks

Just a quick note on bookmarks. I use several laptops, a common machine at home and a workstation at work. This can sometimes get confusing when I save web bookmarks in various different places.

I recently discovered "foxmarks". I only used Firefox, and foxmarks is an extension which syncs up my bookmarks everyplace I install it. It's very handy.

I also discovered "gmarks", which places the bookmarks in a window on the left makes them easy to use. I'm still on the fence with gmarks

Sometimes I wish there was a way to make cross platform "notebooks" with firefox, which would combine a directory tree under SVN control, bookmarks, pdf and an email folder all into one. And make it easy to archive.

December 2, 2006

RCU in the linux kernel; an alternative to reader-writer locks

I ran into something in the announcement of the 2.6.19 kernel called "sleepable rcu". I found this wikipedia entry for rcu. It gives some nice background on rcu's.

I don't normally place much credence in wikipedia pages but this one seems reasonably good. And it explains why RCU's are a better alternative to multiple-reader-single-writer locks.

You don't care about this unless you're doing low level work on multiple CPU systems, which I do from time to time. I'm working on several at them moment, each small.

I'm new to rcu's but they look like a very low cost way to manage updates to high(er) contention data items which are updated (note the work "generations" in the wiki). This concept looks a lot like various academic techniques I've read about over they years to create safe software locks.

November 12, 2006

HTML from lisp

(aside: this is a pretty funny intro to lisp casting spels in lisp)

Generating HTML from lisp is nothing new. Many people have done it and there are lots projects on the web using it. There's also a lot of interesting XML/HTML lisp code floating around. It turns out that XML and HTML lend themselves rather well to symbolic processing.

I've recently been frustrated writing and maintaining html web pages. So, I thought I'd try an experiment. I modified a simple scheme based http server, placed it behind a caching apache2 server. These are ideas I got while looking at Hunchentoot and TBNL. It seems you can make a pretty robust and quick web server with SBCL and these tools. I also like this package (htout).

My needs are more simplistic, and I'm lazy, so I used scheme (siod). I took my old html web pages and extracted out the boiler-plate from the content. The I wrote some translation code which would generate HTML from lisp s-expressions. This translation takes several steps as I implemented some simple macros to make my life easier (common things like anchors in side a list element for example).

It only took a few days and I had parity with my old pages and found the new "content only, lispy style" pages much easier to read and edit.

Here's an example of one of the pages from www.unlambda.com. This pages as a standard look and style sheet as well as standard navigation but all of that is hidden. I can use all of html, but I get to use nice s-expression which are much easier to navigate (for me) than the XML syntax.

;; $Id$
(project-page
 :title "Various Lisp Machine Keyboards"
 :start "Various Lisp Machine Keyboards"
 :body
 '(
   (p "These some pictures of various Lisp Machine keyboards.  I don't have
any documentation on the actually keys (yet).")

   (h2 "CADR")

   (ul
    (li-url "http://world.std.com/~jdostale/kbd/SpaceCadet.html"
	    "")
    (li-url "http://world.std.com/~jdostale/kbd/Knight.html"
	    ""))

   (h2 "Symbolics")

   (ul
    (li-url "/keyboards/symbolics.gif"
	    "")
    (li-url "/keyboards/DSC_2077-small.jpg"
	    "Symbolics 3600 keyboard")
    (li-url "/keyboards/keyboard_6074.jpg" 
	    "Symbolics keyboard (PN 365407 Rev C)"))

   (p)))

I'm pretty happy with this an plan to redo all my pages. Worst case I can always generate raw html and go back to the old way. Best case I can continue to leverage lisp and make better and more interesting (and active) pages.

November 1, 2006

A quick Scheme / embedded-system example

Usually when I find myself fighting to prove a point it's usually becuase it's a loosing battle and my ego just won't let go.

But let's assume you actually might be interesting seeing why a simple lisp like scripting language might be intesting.

I wanted to change the behavior of a display terminal. I wanted it to have a list of times (hours in the day) and different behaviors.

  • homework time = m-f, 3-5pm
  • blank display, all ways, 10pm - 6am

I cranked out some quick scheme code in 15 minutes to do this. Basically I made a list of times with functions to call to check if the time is now and a function to be called when the time starts and stops.

I don't think I could have done that as generally in C, C++ or /bin/sh in the same time. I could have done something pretty specific in /bin/sh but then it would be a pain and lots of duplicated text if I wanted to add another time, event. C or C++ would have required some debugging time and more pain dealing with lists, etc... (assuming no STL++, thank you very much)

going backwards (or starting at the top), I first defined the times:

   ;;
   (define (time-init)
     (add-sleep-time (config-get 'sleep-hours))
     (add-homework-time (config-get 'homework-hours))
   t)

Note that config-get returns a "dotted pair" of begin & end times, i.e. "(10 . 6)" or "(3 . 5)". In lisp a dotted pair is between an atom (like a number) and a list (often a list of atoms).

Then I define how to add times to the list:

    ;; add time, any day
    (define (add-sleep-time hour-pair)
      (add-special-time 'hour-check hour-pair 'its-sleep-time '*sleeping*))

    ;; add time, but weekday only
    (define (add-homework-time hour-pair)
      (add-special-time 'hour-check-weekday hour-pair
                         'its-homework-time '*homework*))

    ;; make list of special times with check & action functions
    (define (add-special-time check-function hour-pair action-function state-var)
      (set! *special-times*
	    (nconc *special-times*
		   (cons (list check-function hour-pair
			       action-function state-var)))))

Note that *sleeping* is a globle variable which gets set. It's quoted so it won't be evaluated to it's value (we just want it's name). hour-check is the function to call to check the time. its-sleep-time is the function to call when the time is entered.

Then I define the functions to check the time:

    ;;
    (define (weekday)
      (let* ((ltime (localtime))
	     (wday (cdr (assoc 'wday ltime))))
	;; 0=sunday, 6=saturday
	(and (> wday 0)
	     (< wday 6))))

    ;;
    (define (hour-check-weekday time-pair)
      (and (weekday)
	   (hour-check time-pair)))

I then spent 10 minutes debugging it (interactively) and then installed it in the larger body of code. Viola. New behavior.

And, or completeness, here the other functions:

;;
(define (check-time)
  (let ((st *special-times*))
    (while st
	   (let* ((item (car st))
		  (func (eval (first item)))
		  (data (second item))
		  (action (eval (third item)))
		  (state-var (fourth item))
		  (state (eval state-var)))
	     (printf "item % % data %\n" item state data)
	     ;; enter
	     (and (not state)
		  (func data)
		  (event-time t action item)
		  (set-symbol-value! state-var t))
	     ;; exit
	     (and state
		  (not (func data))
		  (event-time nil action item)
		  (set-symbol-value! state-var nil)))
	   (set! st (cdr st)))))
;;
(define (hour-check time-pair)
  (let* ((ltime (localtime))
	 (hour (cdr (assoc 'hour ltime)))
	 (mins (cdr (assoc 'min ltime)))
	 (min (car time-pair))
	 (max (cdr time-pair)))
    (printf "hour-check % % %\n" hour min max)
    ;; if span crosses midnight
    (if (> min max)
	(or (>= hour min)
	    (< hour max))
	;; normal span
	(and
	 (>= hour min)
	 (< hour max)))))

With any luck this is mildly interesting. And, maybe it shows how simple it is to add complex functionalty. Or maybe it doesn't. But it was fun to do and I didn't get all bolluxed up with bad pointers or overflowing arrays or gdb. To me this is a fairly compact representation of a simple behavior and very handy on a small embedded system.

October 27, 2006

Scheme + Bogl + SDL = simple, quick embedded UI

I have been struggling with a way to make a simple user userface for an embedded system with a 640x480 LCD but no keyboard or mouse. The machine only has 64mb of ram and wants to run largely out of ram. This eliminates things like X windows, TK, etc... And, I wanted to be able to hack up experiments quickly.

I originally tried Java, but it ate the machine and all it's ram. Then I recoded in C++. This worked well but required recompiling and was hard to debug. It was fun, however, but not fast to develope and not flexible.

Then I found a nice small scheme interpreter called "siod". It supports very simple extension via shared libraries. I also foubd "bogl" -- ben's own graphics library. This is a simple set of graphics primative (lines, blt, simple fonts) which runs directly on a frame buffer, i.e. "/dev/fb" in the unix world.

I wrote an extension library for bogl and was quickly writing scheme (lisp) code to draw on the screen. In order to make progress quickly I hacked bogl to also output using SDL. This way I could compile everything on my desktop X86 machine and SDL provides a 640x480 X window which looks like my target display.

Once the library was stable I had X86 and target (ARM) versions in place an I had to do wasmove updated scheme text files to the target after each debugging session.

Scheme is very nice and easy to learn. It's basically a simplified version of lisp. If you are scared of lisp Scheme is a great place to start. You write scheme code in a text file and siod interprets the text files. It's just like writing shell scripts only much more expressive.

for example, here are some simple scheme functions to blank, unblank and draw a little text on the screen

;;
(define (fb-blank)
  (ioctl *fb-fd* FBIOBLANK 3))

;;
(define (fb-unblank)
  (ioctl *fb-fd* FBIOBLANK 0))

;;
(define (fb-comment current last)
  (let* ((word1 (number->string current 10))
	 (word2 (number->string last 10))
	 (text (string-append word1 "/" word2))
	 (tx 0)
	 (ty 0))
    (bogl-drawtext tx ty text 0 12)))

In lisp/scheme the convension is to decorate global variables with "*"'s. (i.e. *fb-fd* is a global variable). And scheme is nice because is knows about strings.

Basically you can crank out a simple UI pretty fast, testing it all on an X86 box. I've added support for gif, jpeg, http get and unix low level file i/o (read/write/poll). So now I have crank out a sophisticated UI very quickly and easily make changes.

I like scheme because you end up writing verbs which describe the problem you want to solve, like

      ;;
      (define (idle-weather)
	(if (not (weather-still-valid-p))
	    (begin
	      (update-weather)
	      (show-weather)
	      (show-rss)))
	(weather-idle))

This function gets called when the program is idle and in "weather display mode". The weather page also shows various rss feeds, as well as getting the XML weather from weather.com and displaying it in a nice day by day format with an icon and text.

And it's all interpreted. Pretty fast too. I can fix bugs right on the target using vim on a text file.

October 17, 2005

Why is Software Development Still Magic?


I regularly talk to companies who have software development problems - late schedules, too many bugs, unhappy customers. I sometimes marvel when people act as if software development was some magic process which was impossible to understand or control.

My experience is that's not magic and is not that hard to control. I'd like to share some thoughts on ways to define and control the software development process in the "embedded space".

I'd also like to talk a little bit about how easy it is to keep engineers and software developers happy. And, conversly, how easy it is to get them off on the wrong foot.

And, it would be fun to share some techniques for bring groups of people together around a vision and product. One technique is call the "the delphi method".

There are also some fun methods using Post-it notes and something as simple as a round table discussion.

I'll write about all of these in some upcoming entries. I'd like to show some ways to get software out in a predictable manner and keep almost everyone happy.

July 28, 2005

Oh those crazy young people in Europe...


Apparently every four years young hackers in Europe get together and make
a sort of tent city. It's called "whathehack"

It looks like fun, at least if you like laptops and beer :-)