Add Pico W and lwIP support
This commit is contained in:
278
src/rp2_common/pico_lwip/CMakeLists.txt
Normal file
278
src/rp2_common/pico_lwip/CMakeLists.txt
Normal file
@ -0,0 +1,278 @@
|
||||
if (DEFINED ENV{PICO_LWIP_PATH} AND (NOT PICO_LWIP_PATH))
|
||||
set(PICO_LWIP_PATH $ENV{PICO_LWIP_PATH})
|
||||
message("Using PICO_LWIP_PATH from environment ('${PICO_LWIP_PATH}')")
|
||||
endif ()
|
||||
|
||||
set(LWIP_TEST_PATH "src/Filelists.cmake")
|
||||
if (NOT PICO_LWIP_PATH)
|
||||
set(PICO_LWIP_PATH ${PROJECT_SOURCE_DIR}/lib/lwip)
|
||||
# if (NOT EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH})
|
||||
# message(WARNING "LWIP submodule has not been initialized; Pico W wireless support will be unavailable
|
||||
#hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).")
|
||||
# endif()
|
||||
elseif (NOT EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH})
|
||||
message(WARNING "PICO_LWIP_PATH specified but content not present.")
|
||||
endif()
|
||||
|
||||
if (EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH})
|
||||
message("lwIP available at ${PICO_LWIP_PATH}")
|
||||
|
||||
# argh... wanted to use this, but they dump stuff into the source tree, which breaks parallel builds
|
||||
#set(LWIP_DIR ${PICO_LWIP_PATH})
|
||||
#include(${PICO_LWIP_PATH}/src/Filelists.cmake)
|
||||
|
||||
pico_register_common_scope_var(PICO_LWIP_PATH)
|
||||
|
||||
# The minimum set of files needed for lwIP.
|
||||
add_library(pico_lwip_core INTERFACE)
|
||||
target_sources(pico_lwip_core INTERFACE
|
||||
${PICO_LWIP_PATH}/src/core/init.c
|
||||
${PICO_LWIP_PATH}/src/core/def.c
|
||||
${PICO_LWIP_PATH}/src/core/dns.c
|
||||
${PICO_LWIP_PATH}/src/core/inet_chksum.c
|
||||
${PICO_LWIP_PATH}/src/core/ip.c
|
||||
${PICO_LWIP_PATH}/src/core/mem.c
|
||||
${PICO_LWIP_PATH}/src/core/memp.c
|
||||
${PICO_LWIP_PATH}/src/core/netif.c
|
||||
${PICO_LWIP_PATH}/src/core/pbuf.c
|
||||
${PICO_LWIP_PATH}/src/core/raw.c
|
||||
${PICO_LWIP_PATH}/src/core/stats.c
|
||||
${PICO_LWIP_PATH}/src/core/sys.c
|
||||
${PICO_LWIP_PATH}/src/core/altcp.c
|
||||
${PICO_LWIP_PATH}/src/core/altcp_alloc.c
|
||||
${PICO_LWIP_PATH}/src/core/altcp_tcp.c
|
||||
${PICO_LWIP_PATH}/src/core/tcp.c
|
||||
${PICO_LWIP_PATH}/src/core/tcp_in.c
|
||||
${PICO_LWIP_PATH}/src/core/tcp_out.c
|
||||
${PICO_LWIP_PATH}/src/core/timeouts.c
|
||||
${PICO_LWIP_PATH}/src/core/udp.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/random.c
|
||||
)
|
||||
target_include_directories(pico_lwip_core INTERFACE
|
||||
${PICO_LWIP_PATH}/src/include)
|
||||
|
||||
add_library(pico_lwip_core4 INTERFACE)
|
||||
target_sources(pico_lwip_core4 INTERFACE
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/acd.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/autoip.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/dhcp.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/etharp.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/icmp.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/igmp.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/ip4_frag.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/ip4.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv4/ip4_addr.c
|
||||
)
|
||||
|
||||
add_library(pico_lwip_core6 INTERFACE)
|
||||
target_sources(pico_lwip_core6 INTERFACE
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/dhcp6.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/ethip6.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/icmp6.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/inet6.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/ip6.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/ip6_addr.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/ip6_frag.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/mld6.c
|
||||
${PICO_LWIP_PATH}/src/core/ipv6/nd6.c
|
||||
)
|
||||
|
||||
# APIFILES: The files which implement the sequential and socket APIs.
|
||||
add_library(pico_lwip_api INTERFACE)
|
||||
target_sources(pico_lwip_api INTERFACE
|
||||
${PICO_LWIP_PATH}/src/api/api_lib.c
|
||||
${PICO_LWIP_PATH}/src/api/api_msg.c
|
||||
${PICO_LWIP_PATH}/src/api/err.c
|
||||
${PICO_LWIP_PATH}/src/api/if_api.c
|
||||
${PICO_LWIP_PATH}/src/api/netbuf.c
|
||||
${PICO_LWIP_PATH}/src/api/netdb.c
|
||||
${PICO_LWIP_PATH}/src/api/netifapi.c
|
||||
${PICO_LWIP_PATH}/src/api/sockets.c
|
||||
${PICO_LWIP_PATH}/src/api/tcpip.c
|
||||
)
|
||||
|
||||
# Files implementing various generic network interface functions
|
||||
add_library(pico_lwip_netif INTERFACE)
|
||||
target_sources(pico_lwip_netif INTERFACE
|
||||
${PICO_LWIP_PATH}/src/netif/ethernet.c
|
||||
${PICO_LWIP_PATH}/src/netif/bridgeif.c
|
||||
${PICO_LWIP_PATH}/src/netif/bridgeif_fdb.c
|
||||
${PICO_LWIP_PATH}/src/netif/slipif.c
|
||||
)
|
||||
|
||||
# 6LoWPAN
|
||||
add_library(pico_lwip_sixlowpan INTERFACE)
|
||||
target_sources(pico_lwip_sixlowpan INTERFACE
|
||||
${PICO_LWIP_PATH}/src/netif/lowpan6_common.c
|
||||
${PICO_LWIP_PATH}/src/netif/lowpan6.c
|
||||
${PICO_LWIP_PATH}/src/netif/lowpan6_ble.c
|
||||
${PICO_LWIP_PATH}/src/netif/zepif.c
|
||||
)
|
||||
|
||||
# PPP
|
||||
add_library(pico_lwip_ppp INTERFACE)
|
||||
target_sources(pico_lwip_ppp INTERFACE
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/auth.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/ccp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/chap-md5.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/chap_ms.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/chap-new.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/demand.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/eap.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/ecp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/eui64.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/fsm.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/ipcp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/ipv6cp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/lcp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/magic.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/mppe.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/multilink.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/ppp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/pppapi.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/pppcrypt.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/pppoe.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/pppol2tp.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/pppos.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/upap.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/utils.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/vj.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/polarssl/arc4.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/polarssl/des.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/polarssl/md4.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/polarssl/md5.c
|
||||
${PICO_LWIP_PATH}/src/netif/ppp/polarssl/sha1.c
|
||||
)
|
||||
|
||||
# SNMPv3 agent
|
||||
add_library(pico_lwip_snmp INTERFACE)
|
||||
target_sources(pico_lwip_snmp INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_asn1.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_core.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_icmp.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_interfaces.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_ip.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_snmp.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_system.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_tcp.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_mib2_udp.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_snmpv2_framework.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_snmpv2_usm.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_msg.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmpv3.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_netconn.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_pbuf_stream.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_raw.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_scalar.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_table.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_threadsync.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmp_traps.c
|
||||
)
|
||||
|
||||
# HTTP server + client
|
||||
add_library(pico_lwip_http INTERFACE)
|
||||
target_sources(pico_lwip_http INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/http/altcp_proxyconnect.c
|
||||
${PICO_LWIP_PATH}/src/apps/http/fs.c
|
||||
${PICO_LWIP_PATH}/src/apps/http/http_client.c
|
||||
${PICO_LWIP_PATH}/src/apps/http/httpd.c
|
||||
)
|
||||
|
||||
# MAKEFSDATA HTTP server host utility
|
||||
add_library(pico_lwip_makefsdata INTERFACE)
|
||||
target_sources(pico_lwip_makefsdata INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/http/makefsdata/makefsdata.c
|
||||
)
|
||||
|
||||
# iperf
|
||||
add_library(pico_lwip_iperf INTERFACE)
|
||||
target_sources(pico_lwip_iperf INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/lwiperf/lwiperf.c
|
||||
)
|
||||
|
||||
# SMTP client
|
||||
add_library(pico_lwip_smtp INTERFACE)
|
||||
target_sources(pico_lwip_smtp INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/smtp/smtp.c
|
||||
)
|
||||
|
||||
# SNTP client
|
||||
add_library(pico_lwip_sntp INTERFACE)
|
||||
target_sources(pico_lwip_sntp INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/sntp/sntp.c
|
||||
)
|
||||
|
||||
# MDNS responder
|
||||
add_library(pico_lwip_mdns INTERFACE)
|
||||
target_sources(pico_lwip_mdns INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/mdns/mdns.c
|
||||
${PICO_LWIP_PATH}/src/apps/mdns/mdns_out.c
|
||||
${PICO_LWIP_PATH}/src/apps/mdns/mdns_domain.c
|
||||
)
|
||||
|
||||
# NetBIOS name server
|
||||
add_library(pico_lwip_netbios INTERFACE)
|
||||
target_sources(pico_lwip_netbios INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/netbiosns/netbiosns.c
|
||||
)
|
||||
|
||||
# TFTP server files
|
||||
add_library(pico_lwip_tftp INTERFACE)
|
||||
target_sources(pico_lwip_tftp INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/tftp/tftp.c
|
||||
)
|
||||
|
||||
# MQTT client files
|
||||
add_library(pico_lwip_mbedtls INTERFACE)
|
||||
target_sources(pico_lwip_mbedtls INTERFACE
|
||||
${PICO_LWIP_PATH}/src/apps/altcp_tls/altcp_tls_mbedtls.c
|
||||
${PICO_LWIP_PATH}/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c
|
||||
${PICO_LWIP_PATH}/src/apps/snmp/snmpv3_mbedtls.c
|
||||
)
|
||||
|
||||
|
||||
# All LWIP files without apps
|
||||
add_library(pico_lwip INTERFACE)
|
||||
target_link_libraries(pico_lwip INTERFACE
|
||||
pico_lwip_core
|
||||
pico_lwip_core4
|
||||
pico_lwip_core6
|
||||
pico_lwip_api
|
||||
pico_lwip_netif
|
||||
pico_lwip_sixlowpan
|
||||
pico_lwip_ppp
|
||||
)
|
||||
|
||||
# our arch/cc.h
|
||||
add_library(pico_lwip_arch INTERFACE)
|
||||
target_include_directories(pico_lwip_arch INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
|
||||
# our nosys impl
|
||||
add_library(pico_lwip_nosys INTERFACE)
|
||||
target_sources(pico_lwip_nosys INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/nosys.c
|
||||
)
|
||||
target_link_libraries(pico_lwip_nosys INTERFACE
|
||||
pico_lwip_arch)
|
||||
|
||||
|
||||
if (NOT PICO_LWIP_CONTRIB_PATH)
|
||||
set(PICO_LWIP_CONTRIB_PATH ${PICO_LWIP_PATH}/contrib)
|
||||
endif()
|
||||
pico_register_common_scope_var(PICO_LWIP_CONTRIB_PATH)
|
||||
|
||||
# Make lwip_contrib_freertos library, with the FreeRTOS/lwIP code from lwip-contrib
|
||||
add_library(pico_lwip_contrib_freertos INTERFACE)
|
||||
target_sources(pico_lwip_contrib_freertos INTERFACE
|
||||
${PICO_LWIP_CONTRIB_PATH}/ports/freertos/sys_arch.c
|
||||
)
|
||||
target_include_directories(pico_lwip_contrib_freertos INTERFACE
|
||||
${PICO_LWIP_CONTRIB_PATH}/ports/freertos/include
|
||||
)
|
||||
target_link_libraries(pico_lwip_contrib_freertos INTERFACE
|
||||
pico_lwip_arch)
|
||||
|
||||
pico_promote_common_scope_vars()
|
||||
endif()
|
44
src/rp2_common/pico_lwip/doc.h
Normal file
44
src/rp2_common/pico_lwip/doc.h
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* \defgroup pico_lwip pico_lwip
|
||||
* \brief Wrapper libraries for <a href="https://savannah.nongnu.org/projects/lwip/lwIP">lwIP</a>
|
||||
*
|
||||
* The following libraries are provided that contain the equivalent lwIP functionality groups:
|
||||
*
|
||||
* * \c \b pico_lwip_core -
|
||||
* * \c \b pico_lwip_core4 -
|
||||
* * \c \b pico_lwip_core6 -
|
||||
* * \c \b pico_lwip_netif -
|
||||
* * \c \b pico_lwip_sixlowpan -
|
||||
* * \c \b pico_lwip_ppp -
|
||||
* * \c \b pico_lwip_api -
|
||||
*
|
||||
* The following libraries are provided that contain the equivalent lwIP application support:
|
||||
*
|
||||
* * \c \b pico_lwip_snmp -
|
||||
* * \c \b pico_lwip_http -
|
||||
* * \c \b pico_lwip_makefsdata -
|
||||
* * \c \b pico_lwip_iperf -
|
||||
* * \c \b pico_lwip_smtp -
|
||||
* * \c \b pico_lwip_sntp -
|
||||
* * \c \b pico_lwip_mdns -
|
||||
* * \c \b pico_lwip_netbios -
|
||||
* * \c \b pico_lwip_tftp -
|
||||
* * \c \b pico_lwip_mbedtls -
|
||||
*
|
||||
* The SDK Provides a common set of functionality in \c \p pico_lwip which aggregates:
|
||||
*
|
||||
* * \c \b pico_lwip_core -
|
||||
* * \c \b pico_lwip_core4 -
|
||||
* * \c \b pico_lwip_core6 -
|
||||
* * \c \b pico_lwip_netif -
|
||||
* * \c \b pico_lwip_sixlowpan -
|
||||
* * \c \b pico_lwip_ppp -
|
||||
*
|
||||
* The following additional libraries are provided:
|
||||
*
|
||||
* * \c \b pico_lwip - Aggregates the lwIP RAW API: \c \b pico_lwip_core, \c \b pico_lwip_core4, \c \b pico_lwip_core6, \c \b pico_lwip_api, \c \b pico_lwip_netif, \c \b pico_lwip_sixlowpan and \c \b pico_lwip_ppp. It does
|
||||
* not include \c \b pico_lwip_api, which requires NO_SYS=0. You should include the latter separately if you want it.
|
||||
*
|
||||
* * \c \b pico_lwip_arch - lwIP required compiler adapters. This is not included in \c \b pico_lwip in case you wish to replace them.
|
||||
* * \c \b pico_lwip_nosys - basic stub functions for NO_SYS mode.
|
||||
*/
|
79
src/rp2_common/pico_lwip/include/arch/cc.h
Normal file
79
src/rp2_common/pico_lwip/include/arch/cc.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __CC_H__
|
||||
#define __CC_H__
|
||||
|
||||
#if NO_SYS
|
||||
// todo really we should just not allow SYS_LIGHTWEIGHT_PROT for nosys mode (it doesn't do anything anyway)
|
||||
typedef int sys_prot_t;
|
||||
#endif
|
||||
|
||||
/* define compiler specific symbols */
|
||||
#if defined (__ICCARM__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_USE_INCLUDES
|
||||
|
||||
#elif defined (__CC_ARM)
|
||||
|
||||
#define PACK_STRUCT_BEGIN __packed
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#elif defined (__GNUC__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#elif defined (__TASKING__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#endif
|
||||
|
||||
#define LWIP_PLATFORM_ASSERT(x) do { if(!(x)) while(1); } while(0)
|
||||
|
||||
unsigned int pico_lwip_rand(void);
|
||||
#ifndef LWIP_RAND
|
||||
// Use ROSC based random number generation, more for the fact that rand() may not be seeded, than anything else
|
||||
#define LWIP_RAND pico_lwip_rand
|
||||
#endif
|
||||
#endif /* __CC_H__ */
|
26
src/rp2_common/pico_lwip/nosys.c
Normal file
26
src/rp2_common/pico_lwip/nosys.c
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "lwip/init.h"
|
||||
#include "pico/time.h"
|
||||
|
||||
#if NO_SYS
|
||||
/* lwip has provision for using a mutex, when applicable */
|
||||
sys_prot_t sys_arch_protect(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sys_arch_unprotect(sys_prot_t pval) {
|
||||
(void) pval;
|
||||
}
|
||||
|
||||
/* lwip needs a millisecond time source, and the TinyUSB board support code has one available */
|
||||
uint32_t sys_now(void) {
|
||||
return to_ms_since_boot(get_absolute_time());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
29
src/rp2_common/pico_lwip/random.c
Normal file
29
src/rp2_common/pico_lwip/random.c
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "pico.h"
|
||||
#include "hardware/structs/rosc.h"
|
||||
|
||||
static uint8_t pico_lwip_random_byte(int cycles) {
|
||||
static uint8_t byte;
|
||||
assert(cycles >= 8);
|
||||
assert(rosc_hw->status & ROSC_STATUS_ENABLED_BITS);
|
||||
for(int i=0;i<cycles;i++) {
|
||||
// picked a fairly arbitrary polynomial of 0x35u - this doesn't have to be crazily uniform.
|
||||
byte = ((byte << 1) | rosc_hw->randombit) ^ (byte & 0x80u ? 0x35u : 0);
|
||||
// delay a little because the random bit is a little slow
|
||||
busy_wait_at_least_cycles(30);
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
||||
unsigned int pico_lwip_rand(void) {
|
||||
uint32_t value = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
value = (value << 8u) | pico_lwip_random_byte(32);
|
||||
}
|
||||
return value;
|
||||
}
|
Reference in New Issue
Block a user