Skip to content

Use emscripten to run a fully working MicroPython in the browser. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from

Conversation

GeorgeWort
Copy link
Collaborator

@GeorgeWort GeorgeWort commented May 31, 2019

This PR includes the previous simulator PRs (#1, #2, #3) along with a few additional commits to give the latest fully working simulator.

Files are removed separately to the initial simulator commit in
order to make it clearer what has been changed.
The simulator uses emscripten to run in the browser, meaning that
the nRF hardware API can no longer be used. Though the mbed API
along with its HAL is reimplemented using emscripten and
javascript. Instead of plugging into hardware, EM_ASM is used at
points to call directly into javascript.
Persistent memory is also removed and replaced with local
javascript memory.
Inline assembly is no longer supported.
Due to javascript being single threaded, in order to yield to the
browser and "hardware" threads, mp_hal_delay_ms is used to call
emscripten_sleep in the VM and throughout.
The initial stack usage is simulated by initialising the stack top
using a dummy value at the start of main.
Javascript is used in order to import any MicroPython script from
the simulator web page that exists on soft reset.
The stack may ascend on the machine running the browser and so the
stack_usage now accounts for that.
The yielding within the VM uses a counter to periodically check
whether enough time has passed for it to yield yet, this time
checking prevents fast CPUs yielding to the browser more frequently
than necessary.
@GeorgeWort GeorgeWort force-pushed the simulator branch 2 times, most recently from 6fb54d3 to bd9fbdf Compare June 25, 2019 16:12
GeorgeWort added 25 commits July 2, 2019 18:07
The nRF API is partially implemented in order to support the ticker,
with most methods being stubbed out. The ticker is implemented using
a javascript timeout function that calls the handler. Due to the
unreliability of javascript's timing, the handler is called more
frequently than is necessary for the slow ticker, and the time that
has passed is checked.
The nrf_gpio API calls directly into mbed's gpio API.
Implementing the pin API allows the display to run, though the light
sensor is not yet implemented.
Asyncify seems to prevent ccalls such as the ticker during emscripten_sleep.
To get around this issue, only briefly call emscripten_sleep in mp_hal_delay_ms,
and check ticks passed to return at correct time.
Explicitly handle exceptions.
@GeorgeWort GeorgeWort closed this Sep 9, 2019
@GeorgeWort GeorgeWort deleted the simulator branch September 9, 2019 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant