Spin (programming language)
From Wikipedia, the free encyclopedia
Spin is a multitasking object-oriented high level computer programming language created by Parallax's Chip Gracey, (Who also designed the Propeller microcontroller it runs on) for their line of Propeller microcontrollers.
Spin code is written on "the propeller tool". A GUI oriented software development platform which is written for Windows XP. This compiler converts the Spin code into bytecodes that can be loaded, (with the same tool) into the main 32KB RAM, (and optionally into the serial boot FLASH EEPROM) of the Propeller chip. After booting the propeller a bytecode interpreter is copied from the built in ROM into the 2K RAM of the primary COG. And then this COG will start interpreting the bytecodes in the main 32KB RAM.
More than one copy of the bytecode interpreter can run in other COG's, so several Spin code threads can run simultaneously.
Within a the general Spin code program assembler code program(s) can be "inline" inserted. These assembler program(s) will then run on their own COG's.
Just like Python Spin uses indentation/whitespace, rather than curly braces or keywords, to delimit statement blocks.
Contents |
[edit] Syntax
The syntax of Spin can be broken down into blocks. The blocks are as following.
[edit] VAR
Holds global variables
[edit] CON
Holds program constants
[edit] PUB
Holds code for a sub-routine
[edit] OBJ
Contains code for objects
[edit] Example Keywords
reboot: causes the microcontroller to reboot
waitcnt: wait for an amount of clock cycles
waitvid: Waits for a video timing event before outputting video data to I/O pins.
COGINIT: starts a processor on a new task
[edit] Sample Code
An example program, (as it would appear in the "Propeller Tool" editor) which outputs the current system counter every 3000000 cycles, the cog running the program is then shut down by another cog after 40000000 cycles:

