HNHacker News
TopNewBestAskShowJobs

drozd

48 karma · joined January 16, 2016

submissionscomments
drozd··on A bare metal programming guide
The linker script specifies that .data section starts where 192k RAM region starts - in other words, addresses of all variables, etc, are in the RAM memory range.

But the firmware image (that resides on flash), which has .text and .data concatenated, has that .data section in Flash region, obviously. So we have .data section residing in Flash region, but all its addresses in the RAM memory range. That's why it is necessary to copy it over manually.

Hope this is clear... Let me know if not!

drozd··on Mongoose OS – An Open Source Operating System for the Internet of Things
Fast prototyping is the answer. If you or some others are skilled in C/C++, you don't need JS.

For others, having a simple way to prototype fast on the target hardware is a big benefit.

drozd··on Mongoose OS – An Open Source Operating System for the Internet of Things
mJS allows you to use C/C++ SDK functions directly without writing a glue code - basically, you can prototype things quite fast with the libraries/drivers that do not have any scripting support yet.
drozd··on Mongoose OS – An Open Source Operating System for the Internet of Things
That's right, cause Linux cannot run on the large class of microcontrollers - particularly, those with less than 4M of RAM. Mongoose OS is targeting that category.
drozd··on Mongoose OS – An Open Source Operating System for the Internet of Things
JS is for prototyping.
drozd··on Mongoose OS – An Open Source Operating System for the Internet of Things
Sure, try to run those on e.g. TI CC3200 microcontroller.
drozd··on Mongoose OS – An Open Source Operating System for the Internet of Things
I think Mongoose was called mongoose before mongo db plugin existed.

https://github.com/cesanta/mongoose - that's the project from which Mongoose OS stems.

drozd··on mJS – A new approach to embedded scripting
Ah, thanks, wrong about flash footprint. Neil has done a great job adopting Duktape on ESP32.
drozd··on mJS – A new approach to embedded scripting
Hi Gordon! Nice to meet you :) I am the author of the article, and I am quite fond of Espruino, it's a great project. Wasn't aware that Espruino has FFI API!
drozd··on mJS – A new approach to embedded scripting
Yes. Closures add quite a bit of complexity and footprint. Anticipated use case was a short script that orchestrates the device logic, calling existing SDK functions.
drozd··on mJS – A new approach to embedded scripting
Nice! I wasn't aware of lua ffi api, thank you!
drozd··on mJS – A new approach to embedded scripting
Nope. It's similar though, cause some of the concepts, and the code, were reused. mJS does not need an embedding API, really. The intent is that FFI is used.
drozd··on mJS – A new approach to embedded scripting
Embedded environment in this context means hardware low on resources, e.g. microcontrollers. Your perception of that word is "embedded into the C/C++ program". These are two different things. I agree that Lua (like some other languages) were designed to be embedded into C/C++ apps.
drozd··on mJS – A new approach to embedded scripting
Duktape is nice, and I've mentioned it in the article. However it's quite fat, and can't be used on some boards like ESP8266. It's flash footprint is Megabytes, whereas mJS flash footprint is ~25k.
drozd··on mJS – A new approach to embedded scripting
I recall that very much the same opinions were expressed about the JS and backend programming, until node.js appeared. Now the reality is different.

To be honest, we do not think that JS is a good language for embedded. Like any other existing popular scripting language. Perhaps scripted Go would be a better choice.

The point is that in many, many cases scripting brings a lot of benefits to the embedded environment. It all depends on a specific tasks - for some tasks, scripting will never be appropriate.

drozd··on mJS – A new approach to embedded scripting
There is no yacc code in either V7 or mJS.

V7 uses hand-written recursive-descent parser. Initially, it was using ordinary C functions, and that created a problem on systems with low stack size. E.g. each '(' starts statement parsing from the top, so 1 + (2 + (3 + (4 + 5))) consumed stack, and sometimes resulted in stack overflow in e.g. interrupt handlers or network callbacks.

Therefore we have rewritten recursive descent using C coroutines, and that is extremely sophisticated piece of work. See https://raw.githubusercontent.com/cesanta/v7/master/v7.c , search for #line 1 "v7/src/parser.c"

mJS on the other hand uses lemon parser generator - the one from sqlite project. It generates a LALR parser which is quite efficient in terms of memory.

drozd··on mJS – A new approach to embedded scripting
Currently we use mJS in our Mongoose OS firmware framework. There, a symbol resolver is generated automatically from the configuration file which tells which symbols you'd like to use.

https://github.com/cesanta/mongoose-os/blob/master/fw/exampl...

drozd··on mJS – A new approach to embedded scripting
The ability to script without the need of rebuilding/reflashing the whole firmware is often fairly useful. The most value is not in JS per se, but in the ability to script.
drozd··on mJS – A new approach to embedded scripting
Currently, mJS FFI is limited to functions only. And, to simple enough functions.

On how to access memory from mJS: write an accessor function!

    // C
    void setmem(uint8_t *ptr, int index, int value) {
      ptr[index] = value;
    }

    // mJS
    let setmem = ffi('void setmem(void *, int, int)');
    let malloc = ffi('void *malloc(int)');
    let mem = malloc(10);
    setmem(mem, 3, 5);