mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 13:01:10 +02:00
Compare commits
5 Commits
628d53d23c
...
c72a3e528d
Author | SHA1 | Date | |
---|---|---|---|
|
c72a3e528d | ||
|
554f114f18 | ||
|
0b698b8241 | ||
|
cf490ed346 | ||
|
8504391766 |
@@ -23,7 +23,7 @@ PIO_RX_PIN = Pin(3, Pin.IN, Pin.PULL_UP)
|
||||
@asm_pio(
|
||||
autopush=True,
|
||||
push_thresh=8,
|
||||
in_shiftdir=rp2.PIO.SHIFT_RIGHT,
|
||||
in_shiftdir=PIO.SHIFT_RIGHT,
|
||||
fifo_join=PIO.JOIN_RX,
|
||||
)
|
||||
def uart_rx_mini():
|
||||
@@ -42,7 +42,7 @@ def uart_rx_mini():
|
||||
|
||||
|
||||
@asm_pio(
|
||||
in_shiftdir=rp2.PIO.SHIFT_RIGHT,
|
||||
in_shiftdir=PIO.SHIFT_RIGHT,
|
||||
)
|
||||
def uart_rx():
|
||||
# fmt: off
|
||||
|
@@ -28,6 +28,9 @@
|
||||
|
||||
#include "py/mpconfig.h"
|
||||
|
||||
// This is needed to access `next_timeout` via `sys_timeouts_get_next_timeout()`.
|
||||
#define LWIP_TESTMODE 1
|
||||
|
||||
// This sys-arch protection is not needed.
|
||||
// Ports either protect lwIP code with flags, or run it at PendSV priority.
|
||||
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
|
||||
|
@@ -82,6 +82,9 @@ extern const struct _mp_obj_type_t mp_network_ppp_lwip_type;
|
||||
#endif
|
||||
|
||||
struct netif;
|
||||
|
||||
void sys_untimeout_all_with_arg(void *arg);
|
||||
|
||||
void mod_network_lwip_init(void);
|
||||
void mod_network_lwip_poll_wrapper(uint32_t ticks_ms);
|
||||
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args);
|
||||
|
@@ -52,6 +52,19 @@ int mp_mod_network_prefer_dns_use_ip_version = 4;
|
||||
|
||||
// Implementations of network methods that can be used by any interface.
|
||||
|
||||
// This follows sys_untimeout but removes all timeouts with the given argument.
|
||||
void sys_untimeout_all_with_arg(void *arg) {
|
||||
for (struct sys_timeo **t = sys_timeouts_get_next_timeout(); *t != NULL;) {
|
||||
if ((*t)->arg == arg) {
|
||||
struct sys_timeo *next = (*t)->next;
|
||||
memp_free(MEMP_SYS_TIMEOUT, *t);
|
||||
*t = next;
|
||||
} else {
|
||||
t = &(*t)->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function provides the implementation of nic.ifconfig, is deprecated and will be removed.
|
||||
// Use network.ipconfig and nic.ipconfig instead.
|
||||
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args) {
|
||||
|
@@ -1,49 +1,13 @@
|
||||
#ifndef MICROPY_INCLUDED_ALIF_LWIP_LWIPOPTS_H
|
||||
#define MICROPY_INCLUDED_ALIF_LWIP_LWIPOPTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// This protection is not needed, instead we execute all lwIP code at PendSV priority
|
||||
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
|
||||
#define SYS_ARCH_PROTECT(lev) do { } while (0)
|
||||
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
|
||||
|
||||
#define NO_SYS 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
#define LWIP_CHKSUM_ALGORITHM 3
|
||||
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
|
||||
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_RAW 1
|
||||
#define LWIP_NETCONN 0
|
||||
#define LWIP_SOCKET 0
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NETIF_HOSTNAME 1
|
||||
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
|
||||
|
||||
#define LWIP_LOOPIF_MULTICAST 1
|
||||
#define LWIP_LOOPBACK_MAX_PBUFS 8
|
||||
|
||||
#define LWIP_IPV6 0
|
||||
#define LWIP_DHCP 1
|
||||
#define LWIP_DHCP_CHECK_LINK_UP 1
|
||||
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
|
||||
#define LWIP_DNS 1
|
||||
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
|
||||
#define LWIP_MDNS_RESPONDER 1
|
||||
#define LWIP_IGMP 1
|
||||
|
||||
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
|
||||
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
|
||||
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
|
||||
|
||||
#define SO_REUSE 1
|
||||
#define TCP_LISTEN_BACKLOG 1
|
||||
|
||||
extern uint64_t se_services_rand64(void);
|
||||
#define LWIP_RAND() se_services_rand64()
|
||||
|
||||
#define MEM_SIZE (16 * 1024)
|
||||
@@ -55,6 +19,9 @@ extern uint64_t se_services_rand64(void);
|
||||
#define TCP_QUEUE_OOSEQ (1)
|
||||
#define MEMP_NUM_TCP_SEG (2 * TCP_SND_QUEUELEN)
|
||||
|
||||
typedef uint32_t sys_prot_t;
|
||||
// Include common lwIP configuration.
|
||||
#include "extmod/lwip-include/lwipopts_common.h"
|
||||
|
||||
uint64_t se_services_rand64(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ALIF_LWIP_LWIPOPTS_H
|
||||
|
@@ -30,6 +30,7 @@
|
||||
|
||||
#if MICROPY_PY_LWIP
|
||||
|
||||
#include "extmod/modnetwork.h"
|
||||
#include "shared/runtime/softtimer.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/timeouts.h"
|
||||
@@ -183,6 +184,10 @@ static void mp_network_netif_status_cb(struct netif *netif, netif_nsc_reason_t r
|
||||
mp_network_soft_timer.mode = SOFT_TIMER_MODE_PERIODIC;
|
||||
soft_timer_reinsert(&mp_network_soft_timer, LWIP_TICK_RATE_MS);
|
||||
}
|
||||
|
||||
if (reason == LWIP_NSC_NETIF_REMOVED) {
|
||||
sys_untimeout_all_with_arg(netif);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICROPY_PY_LWIP
|
||||
|
@@ -165,34 +165,35 @@ const py_proxy_handler = {
|
||||
if (prop === "_ref") {
|
||||
return target._ref;
|
||||
}
|
||||
if (prop === "then") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (prop === Symbol.iterator) {
|
||||
// Get the Python object iterator, and return a JavaScript generator.
|
||||
const iter_ref = Module.ccall(
|
||||
"proxy_c_to_js_get_iter",
|
||||
"number",
|
||||
["number"],
|
||||
[target._ref],
|
||||
);
|
||||
return function* () {
|
||||
const value = Module._malloc(3 * 4);
|
||||
while (true) {
|
||||
const valid = Module.ccall(
|
||||
"proxy_c_to_js_iternext",
|
||||
"number",
|
||||
["number", "pointer"],
|
||||
[iter_ref, value],
|
||||
);
|
||||
if (!valid) {
|
||||
break;
|
||||
// ignore both then and all symbols but Symbol.iterator
|
||||
if (prop === "then" || typeof prop !== "string") {
|
||||
if (prop === Symbol.iterator) {
|
||||
// Get the Python object iterator, and return a JavaScript generator.
|
||||
const iter_ref = Module.ccall(
|
||||
"proxy_c_to_js_get_iter",
|
||||
"number",
|
||||
["number"],
|
||||
[target._ref],
|
||||
);
|
||||
return function* () {
|
||||
const value = Module._malloc(3 * 4);
|
||||
while (true) {
|
||||
const valid = Module.ccall(
|
||||
"proxy_c_to_js_iternext",
|
||||
"number",
|
||||
["number", "pointer"],
|
||||
[iter_ref, value],
|
||||
);
|
||||
if (!valid) {
|
||||
break;
|
||||
}
|
||||
yield proxy_convert_mp_to_js_obj_jsside(value);
|
||||
}
|
||||
yield proxy_convert_mp_to_js_obj_jsside(value);
|
||||
}
|
||||
Module._free(value);
|
||||
};
|
||||
Module._free(value);
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const value = Module._malloc(3 * 4);
|
||||
|
14
tests/ports/webassembly/py_proxy_get.mjs
Normal file
14
tests/ports/webassembly/py_proxy_get.mjs
Normal file
@@ -0,0 +1,14 @@
|
||||
// Test `<py-obj> get <attr>` on the JavaScript side, which tests PyProxy.get.
|
||||
|
||||
const mp = await (await import(process.argv[2])).loadMicroPython();
|
||||
|
||||
mp.runPython(`
|
||||
x = {"a": 1}
|
||||
`);
|
||||
|
||||
const x = mp.globals.get("x");
|
||||
console.log(x.a === 1);
|
||||
console.log(x.b === undefined);
|
||||
console.log(typeof x[Symbol.iterator] === "function");
|
||||
console.log(x[Symbol.toStringTag] === undefined);
|
||||
console.log(x.then === undefined);
|
5
tests/ports/webassembly/py_proxy_get.mjs.exp
Normal file
5
tests/ports/webassembly/py_proxy_get.mjs.exp
Normal file
@@ -0,0 +1,5 @@
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
Reference in New Issue
Block a user