forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrew Leech <[email protected]>
- Loading branch information
1 parent
7d9cc69
commit 15fea3a
Showing
9 changed files
with
271 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef MICROPY_INCLUDED_RP2_LWIP_ARCH_CC_H | ||
#define MICROPY_INCLUDED_RP2_LWIP_ARCH_CC_H | ||
|
||
#include <assert.h> | ||
#define LWIP_PLATFORM_DIAG(x) | ||
#define LWIP_PLATFORM_ASSERT(x) { assert(1); } | ||
|
||
#define LWIP_NO_CTYPE_H 1 | ||
|
||
#endif // MICROPY_INCLUDED_RP2_LWIP_ARCH_CC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef MICROPY_INCLUDED_RP2_LWIP_LWIPOPTS_H | ||
#define MICROPY_INCLUDED_RP2_LWIP_LWIPOPTS_H | ||
|
||
#include <stdint.h> | ||
|
||
// This protection is not needed, instead protect lwIP code with flags | ||
#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 | ||
// The checksum flags are set in eth.c | ||
#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_IPV6 0 | ||
#define LWIP_DHCP 1 | ||
#define LWIP_DHCP_CHECK_LINK_UP 1 | ||
#define DHCP_DOES_ARP_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 uint32_t rosc_random_u32(void); | ||
#define LWIP_RAND() rosc_random_u32() | ||
|
||
// lwip takes 26700 bytes | ||
#define MEM_SIZE (8000) | ||
#define TCP_MSS (800) | ||
#define TCP_WND (8 * TCP_MSS) | ||
#define TCP_SND_BUF (8 * TCP_MSS) | ||
#define MEMP_NUM_TCP_SEG (32) | ||
|
||
typedef uint32_t sys_prot_t; | ||
|
||
#endif // MICROPY_INCLUDED_RP2_LWIP_LWIPOPTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This file is part of the MicroPython project, http://micropython.org/ | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014 Damien P. George | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#include "py/runtime.h" | ||
#include "py/mphal.h" | ||
|
||
#if MICROPY_PY_LWIP | ||
|
||
#include "lwip/timeouts.h" | ||
#include "pico/time.h" | ||
|
||
// Poll lwIP every 64ms by default | ||
#define LWIP_TICK_RATE_MS 64 | ||
|
||
static alarm_id_t lwip_alarm_id = -1; | ||
static bool lwip_can_poll = true; | ||
static bool lwip_poll_pending = false; | ||
|
||
u32_t sys_now(void) { | ||
// Used by LwIP | ||
return mp_hal_ticks_ms(); | ||
} | ||
|
||
STATIC uint32_t lwip_poll(void) { | ||
// Run the lwIP internal updates | ||
sys_check_timeouts(); | ||
|
||
return MAX(5, MIN(sys_timeouts_sleeptime(), LWIP_TICK_RATE_MS)); | ||
} | ||
|
||
void lwip_lock_acquire(void) { | ||
lwip_can_poll = false; | ||
} | ||
|
||
void lwip_lock_release(void) { | ||
lwip_can_poll = false; | ||
if (lwip_poll_pending) { | ||
lwip_poll(); | ||
lwip_poll_pending = false; | ||
} | ||
lwip_can_poll = true; | ||
} | ||
|
||
uint32_t lwip_try_poll(void) { | ||
uint32_t ret = LWIP_TICK_RATE_MS; | ||
if (lwip_can_poll) { | ||
lwip_can_poll = false; | ||
ret = lwip_poll(); | ||
lwip_can_poll = true; | ||
} else { | ||
lwip_poll_pending = true; | ||
} | ||
return ret; | ||
} | ||
|
||
STATIC int64_t alarm_callback(alarm_id_t id, void *user_data) { | ||
return lwip_try_poll(); | ||
} | ||
|
||
void mod_network_lwip_init(void) { | ||
if (lwip_alarm_id != -1) { | ||
cancel_alarm(lwip_alarm_id); | ||
} | ||
lwip_alarm_id = add_alarm_in_ms(LWIP_TICK_RATE_MS, alarm_callback, mp_const_true, true); | ||
} | ||
|
||
#endif // MICROPY_PY_LWIP |