patch #7885: modification of api modules to support FreeRTOS-MPU (don't pass stack-pointers to other threads) (based on patch by Artem Pisarenko)

This commit is contained in:
Simon Goldschmidt
2014-02-20 19:50:17 +01:00
parent cffe54d094
commit e2c2afbbe0
14 changed files with 444 additions and 202 deletions

View File

@@ -48,6 +48,12 @@
extern "C" {
#endif
#if LWIP_MPU_COMPATIBLE
#define API_MSG_M_DEF(m) m
#else /* LWIP_MPU_COMPATIBLE */
#define API_MSG_M_DEF(m) *m
#endif /* LWIP_MPU_COMPATIBLE */
/* For the netconn API, these values are use as a bitmask! */
#define NETCONN_SHUT_RD 1
#define NETCONN_SHUT_WR 2
@@ -75,13 +81,13 @@ struct api_msg_msg {
} n;
/** used for lwip_netconn_do_bind and lwip_netconn_do_connect */
struct {
ip_addr_t *ipaddr;
ip_addr_t API_MSG_M_DEF(ipaddr);
u16_t port;
} bc;
/** used for lwip_netconn_do_getaddr */
struct {
ipX_addr_t *ipaddr;
u16_t *port;
ipX_addr_t API_MSG_M_DEF(ipaddr);
u16_t API_MSG_M_DEF(port);
u8_t local;
} ad;
/** used for lwip_netconn_do_write */
@@ -104,8 +110,8 @@ struct api_msg_msg {
#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
/** used for lwip_netconn_do_join_leave_group */
struct {
ipX_addr_t *multiaddr;
ipX_addr_t *netif_addr;
ipX_addr_t API_MSG_M_DEF(multiaddr);
ipX_addr_t API_MSG_M_DEF(netif_addr);
enum netconn_igmp join_or_leave;
} jl;
#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
@@ -136,12 +142,12 @@ struct dns_api_msg {
/** Hostname to query or dotted IP address string */
const char *name;
/** Rhe resolved address is stored here */
ip_addr_t *addr;
ip_addr_t API_MSG_M_DEF(addr);
/** This semaphore is posted when the name is resolved, the application thread
should wait on it. */
sys_sem_t *sem;
sys_sem_t API_MSG_M_DEF(sem);
/** Errors are given back here */
err_t *err;
err_t API_MSG_M_DEF(err);
};
#endif /* LWIP_DNS */

View File

@@ -58,6 +58,18 @@ LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn),
#if NO_SYS==0
LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API")
#if LWIP_MPU_COMPATIBLE
LWIP_MEMPOOL(API_MSG, MEMP_NUM_API_MSG, sizeof(struct api_msg), "API_MSG")
#if LWIP_DNS
LWIP_MEMPOOL(DNS_API_MSG, MEMP_NUM_DNS_API_MSG, sizeof(struct dns_api_msg), "DNS_API_MSG")
#endif
#if LWIP_SOCKET
LWIP_MEMPOOL(SOCKET_SETGETSOCKOPT_DATA, MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA, sizeof(struct lwip_setgetsockopt_data), "SOCKET_SETGETSOCKOPT_DATA")
#endif
#if LWIP_NETIF_API
LWIP_MEMPOOL(NETIFAPI_MSG, MEMP_NUM_NETIFAPI_MSG, sizeof(struct netifapi_msg), "NETIFAPI_MSG")
#endif
#endif /* LWIP_MPU_COMPATIBLE */
#if !LWIP_TCPIP_CORE_LOCKING_INPUT
LWIP_MEMPOOL(TCPIP_MSG_INPKT,MEMP_NUM_TCPIP_MSG_INPKT, sizeof(struct tcpip_msg), "TCPIP_MSG_INPKT")
#endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */

View File

@@ -41,6 +41,12 @@
extern "C" {
#endif
#if LWIP_MPU_COMPATIBLE
#define NETIFAPI_IPADDR_DEF(m) m
#else /* LWIP_MPU_COMPATIBLE */
#define NETIFAPI_IPADDR_DEF(m) *m
#endif /* LWIP_MPU_COMPATIBLE */
typedef void (*netifapi_void_fn)(struct netif *netif);
typedef err_t (*netifapi_errt_fn)(struct netif *netif);
@@ -52,9 +58,9 @@ struct netifapi_msg_msg {
struct netif *netif;
union {
struct {
ip_addr_t *ipaddr;
ip_addr_t *netmask;
ip_addr_t *gw;
ip_addr_t NETIFAPI_IPADDR_DEF(ipaddr);
ip_addr_t NETIFAPI_IPADDR_DEF(netmask);
ip_addr_t NETIFAPI_IPADDR_DEF(gw);
void *state;
netif_init_fn init;
netif_input_fn input;

View File

@@ -92,6 +92,16 @@
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
#endif
/**
* LWIP_MPU_COMPATIBLE: enables special memory management mechanism
* which makes lwip able to work on MPU (Memory Protection Unit) system
* by not passing stack-pointers to other threads
* (this decreases performance)
*/
#ifndef LWIP_MPU_COMPATIBLE
#define LWIP_MPU_COMPATIBLE 0
#endif
/*
------------------------------------
---------- Memory options ----------
@@ -414,6 +424,33 @@
#define PBUF_POOL_SIZE 16
#endif
/** MEMP_NUM_API_MSG: the number of concurrently active calls to various
* socket, netconn, and tcpip functions
*/
#ifndef MEMP_NUM_API_MSG
#define MEMP_NUM_API_MSG MEMP_NUM_TCPIP_MSG_API
#endif
/** MEMP_NUM_DNS_API_MSG: the number of concurrently active calls to netconn_gethostbyname
*/
#ifndef MEMP_NUM_DNS_API_MSG
#define MEMP_NUM_DNS_API_MSG MEMP_NUM_TCPIP_MSG_API
#endif
/** MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA: the number of concurrently active calls
* to getsockopt/setsockopt
*/
#ifndef MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA
#define MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA MEMP_NUM_TCPIP_MSG_API
#endif
/** MEMP_NUM_NETIFAPI_MSG: the number of concurrently active calls to the
* netifapi functions
*/
#ifndef MEMP_NUM_NETIFAPI_MSG
#define MEMP_NUM_NETIFAPI_MSG MEMP_NUM_TCPIP_MSG_API
#endif
/*
---------------------------------
---------- ARP options ----------

View File

@@ -41,6 +41,7 @@
#include <stddef.h> /* for size_t */
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/inet6.h"
@@ -105,6 +106,30 @@ struct sockaddr_storage {
typedef u32_t socklen_t;
#endif
struct lwip_sock;
/** This struct is used to pass data to the set/getsockopt_internal
* functions running in tcpip_thread context (only a void* is allowed) */
struct lwip_setgetsockopt_data {
/** socket struct for which to change options */
struct lwip_sock *sock;
#ifdef LWIP_DEBUG
/** socket index for which to change options */
int s;
#endif /* LWIP_DEBUG */
/** level of the option to process */
int level;
/** name of the option to process */
int optname;
/** set: value to set the option to
* get: value of the option is stored here */
void *optval;
/** size of *optval */
socklen_t *optlen;
/** if an error occures, it is temporarily stored here */
err_t err;
};
/* Socket protocol types (TCP/UDP/RAW) */
#define SOCK_STREAM 1
#define SOCK_DGRAM 2

View File

@@ -87,6 +87,35 @@ extern sys_mutex_t lock_tcpip_core;
#define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem)
#endif /* LWIP_TCPIP_CORE_LOCKING */
#if LWIP_MPU_COMPATIBLE
#define API_VAR_REF(name) (*(name))
#define API_VAR_DECLARE(type, name) type * name
#define API_VAR_ALLOC(type, pool, name) do { \
name = (type *)memp_malloc(pool); \
if (name == NULL) { \
return ERR_MEM; \
} \
} while(0)
#define API_VAR_ALLOC_DONTFAIL(type, pool, name) do { \
name = (type *)memp_malloc(pool); \
LWIP_ASSERT("pool empty", name != NULL); \
} while(0)
#define API_VAR_FREE(pool, name) memp_free(pool, name)
#define API_EXPR_REF(expr) &(expr)
#define API_EXPR_DEREF(expr) expr
#else /* LWIP_MPU_COMPATIBLE */
#define API_VAR_REF(name) name
#define API_VAR_DECLARE(type, name) type name
#define API_VAR_ALLOC(type, pool, name)
#define API_VAR_ALLOC_DONTFAIL(type, pool, name)
#define API_VAR_FREE(pool, name)
#define API_EXPR_REF(expr) expr
#define API_EXPR_DEREF(expr) *(expr)
#endif /* LWIP_MPU_COMPATIBLE */
/** Function prototype for the init_done function passed to tcpip_init */
typedef void (*tcpip_init_done_fn)(void *arg);
/** Function prototype for functions passed to tcpip_callback() */