0 comments Sunday, February 28, 2010

Intro

Recently I've made progress on having an interpreted language running on the XMOS chip. I've found a small (but incomplete) lisp interpreter which fits in and runs with the limited memory of the chip. By using an interpreted language, programs can be run on the XMOS chip without the need for compilation. Unfortunately it doesn't contain a garbage collector (at this moment), meaning that an inevitable crash awaits a lot of the programs.

Examples

Primitives for ports and timers are added to allow various IO operations.
For example turning some leds on, on the development board:

(pout clockled0 15)

This function returns the value set (in this case 15), allowing to chain multiple outputs:

(pout clockled0 (pout clockled1 (pout clockled2 15)))

Input is also supported using the following methods:
  • simple read: (pin button)
  • pin equal: (peq button 12)
  • pin not equal: (pne button 15)
These methods obviously return the value read from the port allowing combinations like:

(pout clockled0 (pne button 15))

There is also support for timers. These evaluate to an integer value similar to the way they are used in XC. That way delays can easily be created by doing:

(after (+ (timer) 100000000) value)

Using these timers the following demo was made. It is a function which is called recursively generating a small animation using the LEDs on the development board. The initial value (being 1) is multiplied by two on every function call, effectively shifting to the next led. The "mod 15", keeps everything in range.

((lambda x (apply (car x) x))
 (lambda (f n)
  (f f
   (after (+ (timer) 20000000)
    (% (* 2 (pout clockled0 (pout clockled1 (pout clockled2 n)))) 15)
 )))
 1
)

Due to the lack of a garbage collector and the use of recursion, it will run out of memory after about 10-15 seconds.





Parallellism

At this moment there is no way to use the multithreading in the XMOS chip using the lisp interpreter.