XMOS LED demo using lisp

XCore Project reviews, ideas, videos and proposals.
Post Reply
User avatar
jason
XCore Expert
Posts: 577
Joined: Tue Sep 08, 2009 5:15 pm
Contact:

XMOS LED demo using lisp

Post by jason »

FIAekX7bI5g

An XMOS challenge user has managed to successfully port a simple LISP interpreter to XMOS:

(For more details please visit his website here)
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 and runs in with the limited memory of the chip. By using and 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
)


User avatar
shawn
XCore Addict
Posts: 238
Joined: Thu Dec 17, 2009 5:15 am

Post by shawn »

It shall be interesting to see were this go's.
I'm wondering what XC codes are used inside.
Anyways, thanks for pointing to this, its cool...
User avatar
Ruben
Member
Posts: 15
Joined: Sun Mar 07, 2010 9:58 pm
Contact:

Post by Ruben »

I've uploaded the code to xcore:
http://xcore.com/projects/xmoslisp
(I first had to clear out some licensing & copyright issues)

@shawn:
Inside I use as much XC as possible.
The "pne" function in lisp for example really does
p when pinsneq (v) :> w ;
The w is then returned back into the interpreter.

Since my last blogpost (the above one) I've added a basic form of garbage collection. But at this moment it doesn't collect during execution of functions. So crashing it is still very easy ;)

There is still a problem with the integers being unsigned in XC, but being signed in the interpreter, so be prepared for time becoming negative ;) However it doesn't really give problems for most applications.

enjoy... :)
User avatar
johanar
Active Member
Posts: 60
Joined: Tue Feb 16, 2010 8:21 am
Location: Sweden
Contact:

Post by johanar »

Any plans of writing a Haskell interpreter/compiler for XMOS? :D I've written an interpreter for a small functional language, but it's in Haskell so it's kind of useless..
User avatar
Ruben
Member
Posts: 15
Joined: Sun Mar 07, 2010 9:58 pm
Contact:

Post by Ruben »

No plans to write anything else than this ;)

But also, it's very tricky to find something small enough to fit inside the 64K (and have some space left for code ;) ). I've been looking for quite some time, just to find some interpreter for some language (but preferably lisp/scheme like) that fits. With the current one, I will try to keep it smaller than 32K leaving some reasonable space for "useful" programs :)
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

I remember seeing a small Python interpreter that can run on tiny memory footprints.
User avatar
trousers
Active Member
Posts: 44
Joined: Fri Dec 11, 2009 10:20 am
Contact:

Post by trousers »

Andy wrote:I remember seeing a small Python interpreter that can run on tiny memory footprints.
Python on a chip gets kicked up by Google. Here: http://code.google.com/p/python-on-a-chip/.
Requires roughly 40 KB program memory and initializes in under 3 KB of RAM
So it most probably would fit on an xcore but you wouldn't have much space left for programs.
Best friends with the code fairy.
User avatar
Ruben
Member
Posts: 15
Joined: Sun Mar 07, 2010 9:58 pm
Contact:

Post by Ruben »

That's indeed a nice project.
trousers wrote:
Requires roughly 40 KB program memory and initializes in under 3 KB of RAM
So it most probably would fit on an xcore but you wouldn't have much space left for programs.
True, also remember that it doesn't contain any XC specific stuff yet, so the size will obviously still increase. In the faq I read, that they recommend 8K of RAM, so in theory there is about 10-16K to get the symbols in.

Well, I'll stick with the lisp thing now :)
User avatar
shawn
XCore Addict
Posts: 238
Joined: Thu Dec 17, 2009 5:15 am

Post by shawn »

LISP on XMOS is most excellent choice, its interpreter is very mailable.
Also LISP steps outside of the embeded market. LISP origins are
deep and go back to the IBM704 and well proven in tight enviorments.
A MLISP or *LISP would sure help MACLISP, all possible on Xmos. Not
something very possible with any embedded possessor. I like LISP and
look forward to using LISP for highlevel programing on Xmos. I hope to
contribute something of worth to the LISP project.
User avatar
shawn
XCore Addict
Posts: 238
Joined: Thu Dec 17, 2009 5:15 am

Post by shawn »

Post Reply