lwip: Rename esp32 port layer to esp32xx

As it reflects all chips from esp32-xx family, not only esp32
This commit is contained in:
David Cermak
2023-01-31 08:15:33 +01:00
parent fa97004faf
commit 332e4902b4
8 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,103 @@
/*
* SPDX-FileCopyrightText: 2001 Swedish Institute of Computer Science
*
* SPDX-License-Identifier: BSD-3-Clause
*
* SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
*/
#ifndef __ARCH_CC_H__
#define __ARCH_CC_H__
#include <stdint.h>
#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "arch/sys_arch.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif // BYTE_ORDER
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#define htons(x) __builtin_bswap16(x)
#define ntohs(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohl(x) __builtin_bswap32(x)
#ifndef CONFIG_LWIP_ESP_LWIP_ASSERT
#define LWIP_NOASSERT 1
#endif
typedef uint8_t u8_t;
typedef int8_t s8_t;
typedef uint16_t u16_t;
typedef int16_t s16_t;
typedef uint32_t u32_t;
typedef int32_t s32_t;
typedef int sys_prot_t;
#define S16_F "d"
#define U16_F "d"
#define X16_F "x"
#define S32_F "d"
#define U32_F "u"
#define X32_F "x"
#define PACK_STRUCT_FIELD(x) x
#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
#include <stdio.h>
#ifdef CONFIG_LWIP_DEBUG_ESP_LOG
// lwip debugs routed to ESP_LOGD
#include "esp_log.h"
#define LWIP_ESP_LOG_FUNC(format, ...) ESP_LOG_LEVEL(ESP_LOG_DEBUG, "lwip", format, ##__VA_ARGS__)
#define LWIP_PLATFORM_DIAG(x) LWIP_ESP_LOG_FUNC x
#else
// lwip debugs routed to printf
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
#endif
#ifdef NDEBUG
#define LWIP_NOASSERT 1
#else // Assertions enabled
#if CONFIG_OPTIMIZATION_ASSERTIONS_SILENT
#define LWIP_PLATFORM_ASSERT(message) abort()
#else
// __assert_func is the assertion failure handler from newlib, defined in assert.h
#define LWIP_PLATFORM_ASSERT(message) __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, message)
#endif
// If assertions are on, the default LWIP_ERROR handler behaviour is to
// abort w/ an assertion failure. Don't do this, instead just print the error (if LWIP_DEBUG is set)
// and run the handler (same as the LWIP_ERROR behaviour if LWIP_NOASSERT is set).
#ifdef LWIP_DEBUG
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
puts(message); handler;}} while(0)
#else
// If LWIP_DEBUG is not set, return the error silently (default LWIP behaviour, also.)
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
handler;}} while(0)
#endif // LWIP_DEBUG
#endif /* NDEBUG */
#ifdef __cplusplus
}
#endif
#endif /* __ARCH_CC_H__ */

View File

@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2001 Swedish Institute of Computer Science
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

View File

@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void esp_vfs_lwip_sockets_register(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,22 @@
/**
* @file
* This file is a posix wrapper for lwip/sockets.h.
*/
/*
* SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science
*
* SPDX-License-Identifier: BSD-3-Clause
*
* SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
*/
#ifndef LWIP_HDR_SYS_SOCKETS_H
#define LWIP_HDR_SYS_SOCKETS_H
#include "lwip/sockets.h"
/*
SOMAXCONN is expected to be found in this header too,
while for ESP32 port is defined in net/if.h
*/
#include <net/if.h>
#endif /* LWIP_HDR_SYS_SOCKETS_H */

View File

@@ -0,0 +1,73 @@
/*
* SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "nvs.h"
#include "lwip/dhcp.h"
#include "lwip/netif.h"
#include "netif/dhcp_state.h"
#define DHCP_NAMESPACE "dhcp_state"
#define IF_KEY_SIZE 3
/*
* As a NVS key, use string representation of the interface index number
*/
static inline char *gen_if_key(struct netif *netif, char *name)
{
lwip_itoa(name, IF_KEY_SIZE, netif->num);
return name;
}
bool dhcp_ip_addr_restore(struct netif *netif)
{
nvs_handle_t nvs;
char if_key[IF_KEY_SIZE];
bool err = false;
if (netif == NULL) {
return false;
}
struct dhcp *dhcp = netif_dhcp_data(netif);
uint32_t *ip_addr = &dhcp->offered_ip_addr.addr;
if (nvs_open(DHCP_NAMESPACE, NVS_READONLY, &nvs) == ESP_OK) {
if (nvs_get_u32(nvs, gen_if_key(netif, if_key), ip_addr) == ESP_OK) {
err = true;
}
nvs_close(nvs);
}
return err;
}
void dhcp_ip_addr_store(struct netif *netif)
{
nvs_handle_t nvs;
char if_key[IF_KEY_SIZE];
if (netif == NULL) {
return;
}
struct dhcp *dhcp = netif_dhcp_data(netif);
uint32_t ip_addr = dhcp->offered_ip_addr.addr;
if (nvs_open(DHCP_NAMESPACE, NVS_READWRITE, &nvs) == ESP_OK) {
nvs_set_u32(nvs, gen_if_key(netif, if_key), ip_addr);
nvs_commit(nvs);
nvs_close(nvs);
}
}
void dhcp_ip_addr_erase(struct netif *netif)
{
nvs_handle_t nvs;
char if_key[IF_KEY_SIZE];
if (netif == NULL) {
return;
}
if (nvs_open(DHCP_NAMESPACE, NVS_READWRITE, &nvs) == ESP_OK) {
nvs_erase_key(nvs, gen_if_key(netif, if_key));
nvs_commit(nvs);
nvs_close(nvs);
}
}

View File

@@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include <sys/errno.h>
#include <sys/lock.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include "sdkconfig.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#ifdef CONFIG_VFS_SUPPORT_IO
#error This file should only be built when CONFIG_VFS_SUPPORT_IO=n
#endif
/* Default implementations of read/write provided in newlib component,
* used as a fallback for console I/O.
*/
extern ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t size);
extern ssize_t _read_r_console(struct _reent *r, int fd, const void * data, size_t size);
ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size)
{
if (fd < LWIP_SOCKET_OFFSET) {
return _write_r_console(r, fd, data, size);
}
return lwip_write(fd, data, size);
}
ssize_t _read_r(struct _reent *r, int fd, void * dst, size_t size)
{
if (fd < LWIP_SOCKET_OFFSET) {
return _read_r_console(r, fd, dst, size);
}
return lwip_read(fd, dst, size);
}
int _close_r(struct _reent *r, int fd)
{
if (fd < LWIP_SOCKET_OFFSET) {
errno = ENOSYS;
return -1;
}
return lwip_close(fd);
}
int _fcntl_r(struct _reent *r, int fd, int cmd, int arg)
{
return lwip_fcntl(fd, cmd, arg);
}
int ioctl(int fd, int cmd, ...)
{
va_list args;
va_start(args, cmd);
int res = lwip_ioctl(fd, cmd, va_arg(args, void*));
va_end(args);
return res;
}
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
{
return lwip_select(nfds, readfds, writefds, errorfds, timeout);
}
void esp_vfs_lwip_sockets_register(void)
{
/* Doesn't register anything, just a hook to force linking this file */
}

View File

@@ -0,0 +1,110 @@
/*
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include <sys/errno.h>
#include <sys/lock.h>
#include <sys/fcntl.h>
#include "esp_attr.h"
#include "esp_vfs.h"
#include "sdkconfig.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#ifndef CONFIG_VFS_SUPPORT_IO
#error This file should only be built when CONFIG_VFS_SUPPORT_IO=y
#endif
_Static_assert(MAX_FDS >= CONFIG_LWIP_MAX_SOCKETS, "MAX_FDS < CONFIG_LWIP_MAX_SOCKETS");
#ifdef CONFIG_VFS_SUPPORT_SELECT
/**
* @brief This function is implemented only in FreeRTOS port (ingroup sys_sem)
* and has no official API counterpart in lwip's sys.h declarations
* Signals a semaphore from ISR
* @param sem the semaphore to signal
* @return 1 if the signal has caused a high-prio task to unblock (pxHigherPriorityTaskWoken)
*/
int sys_sem_signal_isr(sys_sem_t *sem);
static void lwip_stop_socket_select(void *sem)
{
sys_sem_signal(sem); //socket_select will return
}
static void lwip_stop_socket_select_isr(void *sem, BaseType_t *woken)
{
if (sys_sem_signal_isr(sem) && woken) {
*woken = pdTRUE;
}
}
static void *lwip_get_socket_select_semaphore(void)
{
/* Calling this from the same process as select() will ensure that the semaphore won't be allocated from
* ISR (lwip_stop_socket_select_isr).
*/
return (void *) sys_thread_sem_get();
}
#else // CONFIG_VFS_SUPPORT_SELECT
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
{
return lwip_select(nfds, readfds, writefds, errorfds, timeout);
}
#endif // CONFIG_VFS_SUPPORT_SELECT
static int lwip_fcntl_r_wrapper(int fd, int cmd, int arg)
{
return lwip_fcntl(fd, cmd, arg);
}
static int lwip_ioctl_r_wrapper(int fd, int cmd, va_list args)
{
return lwip_ioctl(fd, cmd, va_arg(args, void *));
}
static int lwip_fstat(int fd, struct stat * st)
{
if (st == NULL || fd < LWIP_SOCKET_OFFSET || fd > (MAX_FDS - 1)) {
errno = EBADF;
return -1;
}
memset(st, 0, sizeof(*st));
/* set the stat mode to socket type */
st->st_mode = S_IFSOCK;
return 0;
}
void esp_vfs_lwip_sockets_register(void)
{
esp_vfs_t vfs = {
.flags = ESP_VFS_FLAG_DEFAULT,
.write = &lwip_write,
.open = NULL,
.fstat = &lwip_fstat,
.close = &lwip_close,
.read = &lwip_read,
.fcntl = &lwip_fcntl_r_wrapper,
.ioctl = &lwip_ioctl_r_wrapper,
#ifdef CONFIG_VFS_SUPPORT_SELECT
.socket_select = &lwip_select,
.get_socket_select_semaphore = &lwip_get_socket_select_semaphore,
.stop_socket_select = &lwip_stop_socket_select,
.stop_socket_select_isr = &lwip_stop_socket_select_isr,
#endif // CONFIG_VFS_SUPPORT_SELECT
};
/* Non-LWIP file descriptors are from 0 to (LWIP_SOCKET_OFFSET-1). LWIP
* file descriptors are registered from LWIP_SOCKET_OFFSET to
* MAX_FDS-1.
*/
ESP_ERROR_CHECK(esp_vfs_register_fd_range(&vfs, NULL, LWIP_SOCKET_OFFSET, MAX_FDS));
}