Skip to content

Commit 77f1ebd

Browse files
committed
Add new libs that reduce heap and binary allocation
1 parent 2fb2ef5 commit 77f1ebd

File tree

698 files changed

+49083
-4283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

698 files changed

+49083
-4283
lines changed

Diff for: libraries/WiFi/library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=WiFi
2-
version=2.0.0
2+
version=2.0.1
33
author=Hristo Gochkov
44
maintainer=Hristo Gochkov <hristo@espressif.com>
55
sentence=Enables network connection (local and Internet) using the ESP32 built-in WiFi.

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,18 @@ bool wifiLowLevelInit(bool persistent){
557557
}
558558

559559
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
560+
561+
#if 1
562+
// TWEAK to force Dynamic Buffer instead of Static ones
563+
// This uses less heap space in Arduino and makes it similar to 1.0.6 configuration
564+
cfg.static_tx_buf_num = 0;
565+
cfg.dynamic_tx_buf_num = 32;
566+
cfg.tx_buf_type = 1;
567+
cfg.cache_tx_buf_num = 0;
568+
cfg.static_rx_buf_num = 4;
569+
cfg.dynamic_rx_buf_num = 32;
570+
#endif
571+
560572
esp_err_t err = esp_wifi_init(&cfg);
561573
if(err){
562574
log_e("esp_wifi_init %d", err);

Diff for: platform.txt

+9-9
Large diffs are not rendered by default.

Diff for: tools/sdk/esp32/include/asio/port/include/esp_asio_config.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
# define ASIO_NO_TYPEID
1919
# endif // CONFIG_COMPILER_RTTI
2020

21+
//
22+
// Supress OpenSSL deprecation warning, when building ASIO
23+
//
24+
#define ESP_OPENSSL_SUPPRESS_LEGACY_WARNING
25+
2126
//
2227
// LWIP compatibility inet and address macros/functions
2328
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* address.h -- representation of network addresses
3+
*
4+
* Copyright (C) 2010-2011,2015-2016 Olaf Bergmann <bergmann@tzi.org>
5+
*
6+
* This file is part of the CoAP library libcoap. Please see README for terms
7+
* of use.
8+
*/
9+
10+
/**
11+
* @file address.h
12+
* @brief Representation of network addresses
13+
*/
14+
15+
#ifndef COAP_ADDRESS_H_
16+
#define COAP_ADDRESS_H_
17+
18+
#include <assert.h>
19+
#include <stdint.h>
20+
#include <string.h>
21+
#include <sys/types.h>
22+
#include "libcoap.h"
23+
24+
#if defined(WITH_LWIP)
25+
26+
#include <lwip/ip_addr.h>
27+
28+
typedef struct coap_address_t {
29+
uint16_t port;
30+
ip_addr_t addr;
31+
} coap_address_t;
32+
33+
#define _coap_address_equals_impl(A, B) \
34+
((A)->port == (B)->port \
35+
&& (!!ip_addr_cmp(&(A)->addr,&(B)->addr)))
36+
37+
#define _coap_address_isany_impl(A) ip_addr_isany(&(A)->addr)
38+
39+
#define _coap_is_mcast_impl(Address) ip_addr_ismulticast(&(Address)->addr)
40+
41+
#elif defined(WITH_CONTIKI)
42+
43+
#include "uip.h"
44+
45+
typedef struct coap_address_t {
46+
uip_ipaddr_t addr;
47+
uint16_t port;
48+
} coap_address_t;
49+
50+
#define _coap_address_equals_impl(A,B) \
51+
((A)->port == (B)->port \
52+
&& uip_ipaddr_cmp(&((A)->addr),&((B)->addr)))
53+
54+
/** @todo implementation of _coap_address_isany_impl() for Contiki */
55+
#define _coap_address_isany_impl(A) 0
56+
57+
#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
58+
59+
#else /* WITH_LWIP || WITH_CONTIKI */
60+
61+
/** multi-purpose address abstraction */
62+
typedef struct coap_address_t {
63+
socklen_t size; /**< size of addr */
64+
union {
65+
struct sockaddr sa;
66+
struct sockaddr_in sin;
67+
struct sockaddr_in6 sin6;
68+
} addr;
69+
} coap_address_t;
70+
71+
/**
72+
* Compares given address objects @p a and @p b. This function returns @c 1 if
73+
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
74+
* @c NULL;
75+
*/
76+
int coap_address_equals(const coap_address_t *a, const coap_address_t *b);
77+
78+
COAP_STATIC_INLINE int
79+
_coap_address_isany_impl(const coap_address_t *a) {
80+
/* need to compare only relevant parts of sockaddr_in6 */
81+
switch (a->addr.sa.sa_family) {
82+
case AF_INET:
83+
return a->addr.sin.sin_addr.s_addr == INADDR_ANY;
84+
case AF_INET6:
85+
return memcmp(&in6addr_any,
86+
&a->addr.sin6.sin6_addr,
87+
sizeof(in6addr_any)) == 0;
88+
default:
89+
;
90+
}
91+
92+
return 0;
93+
}
94+
#endif /* WITH_LWIP || WITH_CONTIKI */
95+
96+
/**
97+
* Resets the given coap_address_t object @p addr to its default values. In
98+
* particular, the member size must be initialized to the available size for
99+
* storing addresses.
100+
*
101+
* @param addr The coap_address_t object to initialize.
102+
*/
103+
COAP_STATIC_INLINE void
104+
coap_address_init(coap_address_t *addr) {
105+
assert(addr);
106+
memset(addr, 0, sizeof(coap_address_t));
107+
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
108+
/* lwip and Contiki have constant address sizes and doesn't need the .size part */
109+
addr->size = sizeof(addr->addr);
110+
#endif
111+
}
112+
113+
/* Convenience function to copy IPv6 addresses without garbage. */
114+
115+
COAP_STATIC_INLINE void
116+
coap_address_copy( coap_address_t *dst, const coap_address_t *src ) {
117+
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
118+
memcpy( dst, src, sizeof( coap_address_t ) );
119+
#else
120+
memset( dst, 0, sizeof( coap_address_t ) );
121+
dst->size = src->size;
122+
if ( src->addr.sa.sa_family == AF_INET6 ) {
123+
dst->addr.sin6.sin6_family = src->addr.sin6.sin6_family;
124+
dst->addr.sin6.sin6_addr = src->addr.sin6.sin6_addr;
125+
dst->addr.sin6.sin6_port = src->addr.sin6.sin6_port;
126+
dst->addr.sin6.sin6_scope_id = src->addr.sin6.sin6_scope_id;
127+
} else if ( src->addr.sa.sa_family == AF_INET ) {
128+
dst->addr.sin = src->addr.sin;
129+
} else {
130+
memcpy( &dst->addr, &src->addr, src->size );
131+
}
132+
#endif
133+
}
134+
135+
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
136+
/**
137+
* Compares given address objects @p a and @p b. This function returns @c 1 if
138+
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
139+
* @c NULL;
140+
*/
141+
COAP_STATIC_INLINE int
142+
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
143+
assert(a); assert(b);
144+
return _coap_address_equals_impl(a, b);
145+
}
146+
#endif
147+
148+
/**
149+
* Checks if given address object @p a denotes the wildcard address. This
150+
* function returns @c 1 if this is the case, @c 0 otherwise. The parameters @p
151+
* a must not be @c NULL;
152+
*/
153+
COAP_STATIC_INLINE int
154+
coap_address_isany(const coap_address_t *a) {
155+
assert(a);
156+
return _coap_address_isany_impl(a);
157+
}
158+
159+
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
160+
161+
/**
162+
* Checks if given address @p a denotes a multicast address. This function
163+
* returns @c 1 if @p a is multicast, @c 0 otherwise.
164+
*/
165+
int coap_is_mcast(const coap_address_t *a);
166+
#else /* !WITH_LWIP && !WITH_CONTIKI */
167+
/**
168+
* Checks if given address @p a denotes a multicast address. This function
169+
* returns @c 1 if @p a is multicast, @c 0 otherwise.
170+
*/
171+
COAP_STATIC_INLINE int
172+
coap_is_mcast(const coap_address_t *a) {
173+
return a && _coap_is_mcast_impl(a);
174+
}
175+
#endif /* !WITH_LWIP && !WITH_CONTIKI */
176+
177+
#endif /* COAP_ADDRESS_H_ */
+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* async.h -- state management for asynchronous messages
3+
*
4+
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5+
*
6+
* This file is part of the CoAP library libcoap. Please see README for terms
7+
* of use.
8+
*/
9+
10+
/**
11+
* @file async.h
12+
* @brief State management for asynchronous messages
13+
*/
14+
15+
#ifndef COAP_ASYNC_H_
16+
#define COAP_ASYNC_H_
17+
18+
#include "net.h"
19+
20+
#ifndef WITHOUT_ASYNC
21+
22+
/**
23+
* @defgroup coap_async Asynchronous Messaging
24+
* @{
25+
* Structure for managing asynchronous state of CoAP resources. A
26+
* coap_resource_t object holds a list of coap_async_state_t objects that can be
27+
* used to generate a separate response in case a result of an operation cannot
28+
* be delivered in time, or the resource has been explicitly subscribed to with
29+
* the option @c observe.
30+
*/
31+
typedef struct coap_async_state_t {
32+
unsigned char flags; /**< holds the flags to control behaviour */
33+
34+
/**
35+
* Holds the internal time when the object was registered with a
36+
* resource. This field will be updated whenever
37+
* coap_register_async() is called for a specific resource.
38+
*/
39+
coap_tick_t created;
40+
41+
/**
42+
* This field can be used to register opaque application data with the
43+
* asynchronous state object.
44+
*/
45+
void *appdata;
46+
coap_session_t *session; /**< transaction session */
47+
coap_tid_t id; /**< transaction id */
48+
struct coap_async_state_t *next; /**< internally used for linking */
49+
size_t tokenlen; /**< length of the token */
50+
uint8_t token[8]; /**< the token to use in a response */
51+
} coap_async_state_t;
52+
53+
/* Definitions for Async Status Flags These flags can be used to control the
54+
* behaviour of asynchronous response generation.
55+
*/
56+
#define COAP_ASYNC_CONFIRM 0x01 /**< send confirmable response */
57+
#define COAP_ASYNC_SEPARATE 0x02 /**< send separate response */
58+
#define COAP_ASYNC_OBSERVED 0x04 /**< the resource is being observed */
59+
60+
/** release application data on destruction */
61+
#define COAP_ASYNC_RELEASE_DATA 0x08
62+
63+
/**
64+
* Allocates a new coap_async_state_t object and fills its fields according to
65+
* the given @p request. The @p flags are used to control generation of empty
66+
* ACK responses to stop retransmissions and to release registered @p data when
67+
* the resource is deleted by coap_free_async(). This function returns a pointer
68+
* to the registered coap_async_t object or @c NULL on error. Note that this
69+
* function will return @c NULL in case that an object with the same identifier
70+
* is already registered.
71+
*
72+
* @param context The context to use.
73+
* @param session The session that is used for asynchronous transmissions.
74+
* @param request The request that is handled asynchronously.
75+
* @param flags Flags to control state management.
76+
* @param data Opaque application data to register. Note that the
77+
* storage occupied by @p data is released on destruction
78+
* only if flag COAP_ASYNC_RELEASE_DATA is set.
79+
*
80+
* @return A pointer to the registered coap_async_state_t object or @c
81+
* NULL in case of an error.
82+
*/
83+
coap_async_state_t *
84+
coap_register_async(coap_context_t *context,
85+
coap_session_t *session,
86+
coap_pdu_t *request,
87+
unsigned char flags,
88+
void *data);
89+
90+
/**
91+
* Removes the state object identified by @p id from @p context. The removed
92+
* object is returned in @p s, if found. Otherwise, @p s is undefined. This
93+
* function returns @c 1 if the object was removed, @c 0 otherwise. Note that
94+
* the storage allocated for the stored object is not released by this
95+
* functions. You will have to call coap_free_async() to do so.
96+
*
97+
* @param context The context where the async object is registered.
98+
* @param session The session that is used for asynchronous transmissions.
99+
* @param id The identifier of the asynchronous transaction.
100+
* @param s Will be set to the object identified by @p id after removal.
101+
*
102+
* @return @c 1 if object was removed and @p s updated, or @c 0 if no
103+
* object was found with the given id. @p s is valid only if the
104+
* return value is @c 1.
105+
*/
106+
int coap_remove_async(coap_context_t *context,
107+
coap_session_t *session,
108+
coap_tid_t id,
109+
coap_async_state_t **s);
110+
111+
/**
112+
* Releases the memory that was allocated by coap_async_state_init() for the
113+
* object @p s. The registered application data will be released automatically
114+
* if COAP_ASYNC_RELEASE_DATA is set.
115+
*
116+
* @param state The object to delete.
117+
*/
118+
void
119+
coap_free_async(coap_async_state_t *state);
120+
121+
/**
122+
* Retrieves the object identified by @p id from the list of asynchronous
123+
* transactions that are registered with @p context. This function returns a
124+
* pointer to that object or @c NULL if not found.
125+
*
126+
* @param context The context where the asynchronous objects are registered
127+
* with.
128+
* @param session The session that is used for asynchronous transmissions.
129+
* @param id The id of the object to retrieve.
130+
*
131+
* @return A pointer to the object identified by @p id or @c NULL if
132+
* not found.
133+
*/
134+
coap_async_state_t *coap_find_async(coap_context_t *context, coap_session_t *session, coap_tid_t id);
135+
136+
/**
137+
* Updates the time stamp of @p s.
138+
*
139+
* @param s The state object to update.
140+
*/
141+
COAP_STATIC_INLINE void
142+
coap_touch_async(coap_async_state_t *s) { coap_ticks(&s->created); }
143+
144+
/** @} */
145+
146+
#endif /* WITHOUT_ASYNC */
147+
148+
#endif /* COAP_ASYNC_H_ */

0 commit comments

Comments
 (0)