Skip to content
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

Async repl #106

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/micropython/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1)
#define MICROPY_EPOCH_IS_1970 (1)
#define MICROPY_PY_SYS_STDFILES (1)
#define MICROPY_KBD_EXCEPTION (1)

#ifdef ENABLE_SERIAL_STDIO
#define MICROPY_PY_SYS_STDFILES (1)
Expand Down
27 changes: 27 additions & 0 deletions examples/webserver/board/odroidc4/webserver.system
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@
<memory_region name="serial_tx_data_driver" size="0x4_000" />
<memory_region name="serial_tx_data_micropython" size="0x2_000" />
<memory_region name="serial_tx_data_nfs" size="0x2_000" />
<memory_region name="serial_rx_data_driver" size="0x2_000" />
<memory_region name="serial_rx_data_micropython" size="0x2_000" />

<!-- shared memory for serial driver/serial virt queue mechanism -->
<memory_region name="serial_tx_queue_driver" size="0x1_000" />
<memory_region name="serial_rx_queue_driver" size="0x1_000" />

<!-- shared memory for serial virt/client queue mechanism -->
<memory_region name="serial_tx_queue_micropython" size="0x1_000" />
<memory_region name="serial_rx_queue_micropython" size="0x1_000" />
<memory_region name="serial_tx_queue_nfs" size="0x1_000" />

<!-- shared memory for micropython/nfs queue -->
Expand Down Expand Up @@ -135,7 +139,9 @@
<map mr="uart" vaddr="0x5_000_000" perms="rw" cached="false" setvar_vaddr="uart_base" />

<map mr="serial_tx_queue_driver" vaddr="0x4_001_000" perms="rw" cached="true" setvar_vaddr="tx_queue" />
<map mr="serial_rx_queue_driver" vaddr="0x4_000_000" perms="rw" cached="true" setvar_vaddr="rx_queue" />
<map mr="serial_tx_data_driver" vaddr="0x4_004_000" perms="rw" cached="true" setvar_vaddr="tx_data" />
<map mr="serial_rx_data_driver" vaddr="0x4_002_000" perms="rw" cached="true" setvar_vaddr="rx_data" />

<irq irq="225" id="0" trigger="edge" /> <!-- UART interrupt -->
</protection_domain>
Expand All @@ -151,6 +157,15 @@
<map mr="serial_tx_data_nfs" vaddr="0x4_009_000" perms="r" cached="true"/>
</protection_domain>

<protection_domain name="serial_virt_rx" priority="98">
<program_image path="serial_virt_rx.elf" />
<map mr="serial_rx_queue_driver" vaddr="0x4_000_000" perms="rw" cached="true" setvar_vaddr="rx_queue_drv" />
<map mr="serial_rx_queue_micropython" vaddr="0x4_001_000" perms="rw" cached="true" setvar_vaddr="rx_queue_cli0" />

<map mr="serial_rx_data_driver" vaddr="0x4_002_000" perms="r" cached="true" setvar_vaddr="rx_data_drv" />
<map mr="serial_rx_data_micropython" vaddr="0x4_004_000" perms="rw" cached="true" setvar_vaddr="rx_data_cli0" />
</protection_domain>

<protection_domain name="nfs" priority="98" stack_size="0x10000">
<program_image path="nfs.elf" />
<map mr="eth_rx_free_nfs" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
Expand All @@ -176,7 +191,9 @@
<map mr="shared_nfs_micropython" vaddr="0x8_000_000" perms="rw" cached="true" setvar_vaddr="nfs_share" />

<map mr="serial_tx_queue_micropython" vaddr="0x60_000_000" perms="rw" cached="true" setvar_vaddr="serial_tx_queue" />
<map mr="serial_rx_queue_micropython" vaddr="0x60_001_000" perms="rw" cached="true" setvar_vaddr="serial_rx_queue" />
<map mr="serial_tx_data_micropython" vaddr="0x60_002_000" perms="rw" cached="true" setvar_vaddr="serial_tx_data" />
<map mr="serial_rx_data_micropython" vaddr="0x60_004_000" perms="rw" cached="true" setvar_vaddr="serial_rx_data" />

<map mr="eth_rx_free_micropython" vaddr="0x4_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="eth_rx_active_micropython" vaddr="0x4_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand Down Expand Up @@ -232,6 +249,11 @@
<end pd="serial_virt_tx" id="0"/>
</channel>

<channel>
<end pd="serial_virt_rx" id="1"/>
<end pd="micropython" id="8"/>
</channel>

<channel>
<end pd="serial_virt_tx" id="1"/>
<end pd="micropython" id="9"/>
Expand All @@ -242,6 +264,11 @@
<end pd="nfs" id="0"/>
</channel>

<channel>
<end pd="uart_driver" id="2"/>
<end pd="serial_virt_rx" id="0"/>
</channel>

<channel>
<end pd="timer_driver" id="1" />
<end pd="micropython" id="1" />
Expand Down
27 changes: 27 additions & 0 deletions examples/webserver/board/qemu_virt_aarch64/webserver.system
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@
<memory_region name="serial_tx_data_driver" size="0x4_000" />
<memory_region name="serial_tx_data_micropython" size="0x2_000" />
<memory_region name="serial_tx_data_nfs" size="0x2_000" />
<memory_region name="serial_rx_data_driver" size="0x2_000" />
<memory_region name="serial_rx_data_micropython" size="0x2_000" />

<!-- shared memory for serial driver/serial virt queue mechanism -->
<memory_region name="serial_tx_queue_driver" size="0x1_000" />
<memory_region name="serial_rx_queue_driver" size="0x1_000" />

<!-- shared memory for serial virt/client queue mechanism -->
<memory_region name="serial_tx_queue_micropython" size="0x1_000" />
<memory_region name="serial_rx_queue_micropython" size="0x1_000"/>
<memory_region name="serial_tx_queue_nfs" size="0x1_000" />

<!-- shared memory for micropython/nfs queue -->
Expand Down Expand Up @@ -133,6 +137,8 @@
<map mr="uart" vaddr="0x5_000_000" perms="rw" cached="false" setvar_vaddr="uart_base" />

<map mr="serial_tx_queue_driver" vaddr="0x4_001_000" perms="rw" cached="true" setvar_vaddr="tx_queue" />
<map mr="serial_rx_queue_driver" vaddr="0x4_000_000" perms="rw" cached="true" setvar_vaddr="rx_queue" />
<map mr="serial_rx_data_driver" vaddr="0x4_002_000" perms="rw" cached="true" setvar_vaddr="rx_data" />
<map mr="serial_tx_data_driver" vaddr="0x4_004_000" perms="rw" cached="true" setvar_vaddr="tx_data" />

<irq irq="33" id="0" /> <!-- UART interrupt -->
Expand All @@ -149,6 +155,15 @@
<map mr="serial_tx_data_nfs" vaddr="0x4_009_000" perms="r" cached="true"/>
</protection_domain>

<protection_domain name="serial_virt_rx" priority="98">
<program_image path="serial_virt_rx.elf" />
<map mr="serial_rx_queue_driver" vaddr="0x4_000_000" perms="rw" cached="true" setvar_vaddr="rx_queue_drv" />
<map mr="serial_rx_queue_micropython" vaddr="0x4_001_000" perms="rw" cached="true" setvar_vaddr="rx_queue_cli0" />

<map mr="serial_rx_data_driver" vaddr="0x4_002_000" perms="r" cached="true" setvar_vaddr="rx_data_drv" />
<map mr="serial_rx_data_micropython" vaddr="0x4_004_000" perms="rw" cached="true" setvar_vaddr="rx_data_cli0" />
</protection_domain>

<protection_domain name="nfs" priority="98" stack_size="0x10000">
<program_image path="nfs.elf" />
<map mr="eth_rx_free_nfs" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
Expand All @@ -174,7 +189,9 @@
<map mr="shared_nfs_micropython" vaddr="0x7_900_000" perms="rw" cached="true" setvar_vaddr="nfs_share" />

<map mr="serial_tx_queue_micropython" vaddr="0x60_000_000" perms="rw" cached="true" setvar_vaddr="serial_tx_queue" />
<map mr="serial_rx_queue_micropython" vaddr="0x60_001_000" perms="rw" cached="true" setvar_vaddr="serial_rx_queue" />
<map mr="serial_tx_data_micropython" vaddr="0x60_002_000" perms="rw" cached="true" setvar_vaddr="serial_tx_data" />
<map mr="serial_rx_data_micropython" vaddr="0x60_004_000" perms="rw" cached="true" setvar_vaddr="serial_rx_data" />

<map mr="eth_rx_free_micropython" vaddr="0x4_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="eth_rx_active_micropython" vaddr="0x4_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand Down Expand Up @@ -240,6 +257,16 @@
<end pd="nfs" id="0"/>
</channel>

<channel>
<end pd="uart_driver" id="2"/>
<end pd="serial_virt_rx" id="0"/>
</channel>

<channel>
<end pd="serial_virt_rx" id="1"/>
<end pd="micropython" id="8"/>
</channel>

<channel>
<end pd="timer_driver" id="1" />
<end pd="micropython" id="1" />
Expand Down
17 changes: 14 additions & 3 deletions examples/webserver/config/serial_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
/* Number of clients of the serial subsystem. */
#define SERIAL_NUM_CLIENTS 2

/* Support only output. */
#define SERIAL_TX_ONLY 1
/* Support full duplex. */
#define SERIAL_TX_ONLY 0

/* Associate a colour with each client's output. */
#define SERIAL_WITH_COLOUR 1
Expand All @@ -23,6 +23,7 @@
/* One read/write client, one write only client */
#define SERIAL_CLI0_NAME "micropython"
#define SERIAL_CLI1_NAME "nfs"
#define SERIAL_VIRT_RX_NAME "serial_virt_rx"
#define SERIAL_VIRT_TX_NAME "serial_virt_tx"

#define SERIAL_QUEUE_SIZE 0x1000
Expand All @@ -32,9 +33,14 @@
#define SERIAL_TX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE
#define SERIAL_TX_DATA_REGION_SIZE_CLI1 SERIAL_DATA_REGION_SIZE

#define SERIAL_RX_DATA_REGION_SIZE_DRIV SERIAL_DATA_REGION_SIZE
#define SERIAL_RX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE

#define SERIAL_MAX_TX_DATA_SIZE MAX(SERIAL_TX_DATA_REGION_SIZE_DRIV, \
MAX(SERIAL_TX_DATA_REGION_SIZE_CLI0, \
SERIAL_TX_DATA_REGION_SIZE_CLI1))
#define SERIAL_MAX_RX_DATA_SIZE MAX(SERIAL_RX_DATA_REGION_SIZE_DRIV, \
SERIAL_RX_DATA_REGION_SIZE_CLI0)

/* String to be printed to start console input */
#define SERIAL_CONSOLE_BEGIN_STRING ""
Expand All @@ -55,6 +61,8 @@ static inline void serial_cli_queue_init_sys(const char *pd_name,
char *tx_data)
{
if (!sddf_strcmp(pd_name, SERIAL_CLI0_NAME)) {
serial_queue_init(rx_queue_handle, rx_queue,
SERIAL_RX_DATA_REGION_SIZE_CLI0, rx_data);
serial_queue_init(tx_queue_handle, tx_queue,
SERIAL_TX_DATA_REGION_SIZE_CLI0, tx_data);
} else if (!sddf_strcmp(pd_name, SERIAL_CLI1_NAME)) {
Expand All @@ -68,7 +76,10 @@ static inline void serial_virt_queue_init_sys(char *pd_name,
serial_queue_t *cli_queue,
char *cli_data)
{
if (!sddf_strcmp(pd_name, SERIAL_VIRT_TX_NAME)) {
if (!sddf_strcmp(pd_name, SERIAL_VIRT_RX_NAME)) {
serial_queue_init(cli_queue_handle, cli_queue,
SERIAL_RX_DATA_REGION_SIZE_CLI0, cli_data);
} else if (!sddf_strcmp(pd_name, SERIAL_VIRT_TX_NAME)) {
serial_queue_init(cli_queue_handle, cli_queue,
SERIAL_TX_DATA_REGION_SIZE_CLI0, cli_data);
serial_queue_init(&cli_queue_handle[1],
Expand Down
1 change: 1 addition & 0 deletions examples/webserver/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("$(MPY_DIR)/extmod/asyncio/manifest.py")
include("$(MPY_DIR)/lib/micropython-lib/micropython/aiorepl/manifest.py")
package("microdot", base_path="$(PORT_DIR)/../../dep/microdot/src/")
module("fs_async.py", base_path="$(PORT_DIR)")
module("webserver.py")
Expand Down
2 changes: 1 addition & 1 deletion examples/webserver/webserver.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MICRODOT := ${LIONSOS}/dep/microdot/src

IMAGES := timer_driver.elf eth_driver.elf micropython.elf nfs.elf \
copy.elf network_virt_rx.elf network_virt_tx.elf \
uart_driver.elf serial_virt_tx.elf
uart_driver.elf serial_virt_tx.elf serial_virt_rx.elf

SYSTEM_FILE := $(WEBSERVER_SRC_DIR)/board/$(MICROKIT_BOARD)/webserver.system

Expand Down
16 changes: 15 additions & 1 deletion examples/webserver/webserver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import asyncio
import aiorepl
import fs_async
import time
from microdot import Microdot, Response
Expand Down Expand Up @@ -130,4 +131,17 @@ async def index(request):
async def static(request, path):
return await send_file(path, request.headers)

app.run(debug=True, port=80)
async def start_httpd(app, port, debug):
app.run(port=port, debug=debug)


#app.run(debug=True, port=80)


async def main():
httpd = asyncio.create_task(start_httpd(app, port=80, debug=True))
repl = asyncio.create_task(aiorepl.task())
while True:
await asyncio.sleep(100)

asyncio.run(main())