Runtime expression evaluator & scripting for embedded processors

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in my application, my users generate a configuration file which is loaded into EEMEM and evaluated at run-time to configure inputs, outputs, actions, etc.

 

I would like to provide my users with a way to include expressions (return a value) and action statements (or better simple 'functions') that are evaluated at run-time using data and functions provided by my firmware environment.

 

I currently support expressions (compiled at run-time to pseudo-code which is saved and executed) and some actions (actually side-effects of referencing objects) but I would like to extend that functionality.

 

I am interested in anything from very basic to complete scripting ideally with the ability to select the options I want (and thus the ROM/RAM footprint).  I have heard of Lua but that might be a bit much ...

 

(using ATMega1284p and AVR Studio)

 

Regards,

 

Chuck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tiny basic?
https://hackaday.com/tag/tiny-basic/

The flash and ram footprint should suit. If your app can cope with the limitation of 26 sixteen bit variables, then you should be right. Just conjure up some new keywords for your requirements.

Takes me back to the 80’s with the ins8073 chip. If you want something fancier, then maybe look at running microsoft basic via a 6502/z80 emulator (not as silly as it first seems)- 8k for the binary and a 6502 emulator is a few k.

Last Edited: Mon. Nov 27, 2017 - 11:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you had a look at Bitlash?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Nov 28, 2017 - 12:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Off at about page 280 in "Best of Byte, Volume 1" (which is downloadable, these days), there are a set of articles on processing algebraic expressions and the "My Dear Aunt Sally" algorithm, that I found especially useful when I did something like this 40 years, for Fortran...

 

In general, the old magazines are a pretty good source for explanations of things that ... no one bothers to explain much anymore.  No one writes "how to make a UART out of TTL chips (and incidentally, how serial coms actually works) (because, you know, actual UART chips are SO expensive and hard to buy!)" any more :-(   Likewise, "parsing expressions" is hard to find outside of full interpreter or compiler-design efforts.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
"Best of Byte, Volume 1" (which is downloadable, these days)

Thanks for that hint!

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice idea ... but on an AVR ?

 

MicroPython Wiki wrote:

Platforms

Which all seem to be in the Cortex-M4 ballpark.

 

Then, again, turning the question around:  if this type of functionality is important, why choose an AVR ?

 

 

EDIT

 

Not that I have anything against MicroPython itself - it looks like a great idea, and the PyBoard looks a great tool ... 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Nov 28, 2017 - 10:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With lua, micropython and espruino you’re not going to get much change out of 100k flash and a few k of ram.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

Tiny basic?

 

Or Attobasic... http://www.cappels.org/dproj/Att...

 

Already working on the 1284P.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Nice idea ... but on an AVR ?

Python

Python Wiki

PyMite

https://wiki.python.org/moin/PyMite

What is PyMite

PyMite is a flyweight Python interpreter written from scratch to execute on 8-bit and larger microcontrollers with resources as limited as 64 KiB of program memory (flash) and 4 KiB of RAM. PyMite supports a subset of the Python 2.5 syntax and can execute a subset of the Python 2.5 bytecodes. ...

...

awneil wrote:
Which all seem to be in the Cortex-M4 ballpark.
PIC24/dsPIC is a side-port.

https://github.com/micropython/micropython/blob/master/ports/pic16bit/Makefile

...

XC16 = /opt/microchip/xc16/v1.24
CROSS_COMPILE = $(XC16)/bin/xc16-
 
PARTFAMILY = dsPIC33F

PART = 33FJ256GP506

http://www.microchip.com/wwwproducts/en/dsPIC33FJ256GP506A

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
Likewise, "parsing expressions" is hard to find outside of full interpreter or compiler-design efforts.

[CODE][C] Parsing strings flexibly/efficiently with Ragel

https://www.avrfreaks.net/forum/codec-parsing-strings-flexiblyefficiently-ragel

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

While it never seemed to get much momentum, I always thought that JavaCard had a lot of potential for load-and-go on AVR8-class processors.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

PyMite is a flyweight Python interpreter written from scratch to execute on 8-bit and larger microcontrollers with resources as limited as 64 KiB of program memory (flash) and 4 KiB of RAM. ...

Very interesting.

 

The ATMega1284p has 128KB flash and 16KB SRAM - so this would use half the flash and 25% of the RAM just for the interpreter.

 

Sounds like it could be workable ...

 

smiley

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can't examine [Bitlash] in-depth at the moment [driving from OKC to Tampa at the moment - wife actually driving :-) ] but it looks interesting.

 

Might look at porting it to my environment.  I obviously don't want users "printing", "delay"ing, etc. or accessing pins/ports directly but I assume I can strip all that stuff out and fence them into accessing only API functions I provide which should also make it significantly smaller.

 

Chuck

Last Edited: Tue. Nov 28, 2017 - 06:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did one that could execute a simple bytecode virtual machine, which was stack based. I wrote a compiler for it that used a BASIC-like syntax.

 

Another one was a bit higher level, basically let you call functions in the firmware with whatever parameters you wanted. You have to be careful with that to make it robust