In the last post, I explained how I had slimmed down the kernel of SIMPL - at the same time removing much of the Arduino specific code so that it would fit into 2Kbytes of Flash plus a lower RAM requirement. This also makes it highly portable to other microcontrollers.
My intention was to be able to put an image of SIMPL onto any microcontroller target system that I happened to be working on at the time - and give myself a friendly, predictable environment with which to exercise the hardware. In some cases, SIMPL could even be loaded into the bootloader space of a processor - so that it was always accessible.
SIMPL fundamentally allows interaction with the microcontroller, because of it's interpreted nature. The interpreter is flexible enough to form the basis of a series of simple tools, such as cross assemblers, debuggers and simulators. It is, whatever you want it to be - you have absolute control over what action the cpu performs in response to your key strokes.
SIMPL communicates with a PC using a serial UART interface. It can be driven from any terminal application.
It really only needs getchar() and putchar() routines that interface with the on-chip UART.
These together with a printnum() function which prints out a 16 bit unsigned number are all that is needed to communicate with the PC in a meaningful manner. It's old-school, but it works - and easy to set up, on almost any microcontroller or SoC device.
SIMPL is a low overhead program - a kind of interactive tiny OS, that only takes a few Kbytes, yet provides all the means of accessing and controlling the micro.
A brief list of functionality.
The digital I/O is limited to the writing to or reading from a single I/O pin. In most cases this will be one that supports a LED. The I/O functions can be extended to whatever is needed by the application - for example in one application - an LED chaser display I needed to write a 13 bit number to an array of LEDs each connected to an output pin of the Arduino.
Analogue Input (ADC) and output PWM functions may be ennabled if required - but these will add approximately a further 600 bytes to the kernel code.
The kernel uses the delay() and delayMicroseconds() functions to allow accurate timing of I/O operations. With these the microcontroller can generate pulse sequences (up to 100kHz on Arduino), generate musical tones, sound effects or animate LED displays.
As well as the functions that interact with the hardware peripherals, SIMPL also has a range of arithmetic and bitwise logic operators to allow simple integer maths and logical decision making.
There is a simple looping function which permits a block of code to be repeated - up to 32K times.
Recently added functions allow the printing of strings and the manipulation of ascii characters.
On top of the 2K kernel core is some further code which allows the user to define their own functions and store them in RAM. Up to 26 user functions can be defined under the current system. It's not exactly Forth - but borrows a whole lot of ideas from that remarkable language.
The system could be extended to include SPI or I2C functions to exercise specific peripheral chips or access a microSD card for program storage.
One of my designs "WiNode" is an Arduino compatible target board but with 433MHz wireless module, external SRAM, RTC, motor driver/ speaker driver, and microSD card. SMPL may be used to exercise and interact with all of these peripherals.
32bit Math Extensions
This was remarkably easy to implement. By re-type-ing the x and y variables to long - it forced all of the arithmetic routines to 32 bit. Whilst this pushed the code size up by about 900 bytes - some of this was offset by rewriting the printnum() function as a 32 bit printong() and deleting the original printnum(). The code now stands at 4826 bytes and can be found on this GitHub Gist
This means that SIMPL can do 32 bit integer maths - straight form the can.
SIMPL has been an ongoing project for over 2 years, and as it has developed - so have my C coding skills. As the code becomes larger, things become easier - as the switch from 16 bit to 32 bit integer maths has proven - it was literally a 10 minute hack.
I am very aware that SIMPL is not yet a fully fledged language - it can flap its wings and tweet a bit - but is not ready to leap out of the nest and fly. Perhaps I am a bad mother bird - too eager to experiment with new ideas rather than concentrate on the basics. Time will tell.
I have ported SIMPL to STM32Fxxx ARM microcontrollers and seen a 25X increase in speed. Now their are ARMs that run at 240 and 300MHz (Atmel SAM E7) that will give even more of a performance boost.
The final intention is to create a SIMPL virtual machine (SVM) that can be hosted on nearly any micro - including FPGA soft core stack proessors - such a James Bowman's J1b. With these we hope to see a large leap in performance.
In the meanwhile, I still have an Arduino plugged into my laptop - as my preferred development platform - if it will run on Arduino - it will run on everything else a whole lot better!
Next Time - more uses for the SIMPL Interpreter.