@@ -177,10 +177,12 @@ static inline void unicoap_options_clear(unicoap_options_t* options)
177
177
* @{
178
178
*/
179
179
#ifndef DOXYGEN
180
- # define _UNICOAP_OPTIONS_ALLOC (_buf , _name , capacity ) \
181
- uint8_t _buf[capacity]; \
182
- unicoap_options_t _name; \
183
- unicoap_options_init(&_name, _buf, capacity);
180
+ # define _UNICOAP_OPTIONS_ALLOC (_buf , _name , capacity , _static ) \
181
+ _static uint8_t _buf[capacity]; \
182
+ _static unicoap_options_t _name = { \
183
+ .entries = { { .data = _buf } }, \
184
+ .storage_capacity = capacity, \
185
+ };
184
186
#endif
185
187
186
188
/**
@@ -190,22 +192,56 @@ static inline void unicoap_options_clear(unicoap_options_t* options)
190
192
* @param capacity Storage buffer capacity in bytes
191
193
*
192
194
* Allocates a new @ref unicoap_options_t container and a storage buffer with
193
- * the given capacity, then calls @ref unicoap_options_t::unicoap_options_init.
195
+ * the given capacity, and initializes it. No need to call
196
+ * @ref unicoap_options_t::unicoap_options_init afterwards.
197
+ *
198
+ * See @ref UNICOAP_OPTIONS_ALLOC_STATIC for static allocation
194
199
*/
195
200
#define UNICOAP_OPTIONS_ALLOC (name , capacity ) \
196
- _UNICOAP_OPTIONS_ALLOC(_CONCAT3(name, _storage, __LINE__), name, capacity)
201
+ _UNICOAP_OPTIONS_ALLOC(_CONCAT3(name, _storage, __LINE__), name, capacity,)
202
+
203
+ /**
204
+ * @brief Statically allocates options with buffer capacity
205
+ *
206
+ * @param name Name of the variable storing the options structure
207
+ * @param capacity Static storage buffer capacity in bytes
208
+ *
209
+ * Statically allocates a new @ref unicoap_options_t container and a storage
210
+ * buffer with the given capacity, and initializes it. No need to call
211
+ * @ref unicoap_options_t::unicoap_options_init afterwards.
212
+ *
213
+ * See @ref UNICOAP_OPTIONS_ALLOC for non-static allocation
214
+ */
215
+ #define UNICOAP_OPTIONS_ALLOC_STATIC (name , capacity ) \
216
+ _UNICOAP_OPTIONS_ALLOC(_CONCAT3(name, _storage, __LINE__), name, capacity, static)
197
217
198
218
/**
199
219
* @brief Allocates options with default capacity
200
220
*
201
221
* @param name Name of the variable storing the options structure
202
222
*
203
223
* Allocates a new @ref unicoap_options_t container and a storage buffer with
204
- * @ref CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY,
205
- * then calls @ref unicoap_options_t::unicoap_options_init.
224
+ * @ref CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY, and initializes it.
225
+ * No need to call @ref unicoap_options_t::unicoap_options_init afterwards.
226
+ *
227
+ * See @ref UNICOAP_OPTIONS_ALLOC_STATIC_DEFAULT for static allocation
206
228
*/
207
229
#define UNICOAP_OPTIONS_ALLOC_DEFAULT (name ) \
208
230
UNICOAP_OPTIONS_ALLOC(name, CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY)
231
+
232
+ /**
233
+ * @brief Statically allocates options with default capacity
234
+ *
235
+ * @param name Name of the variable storing the options structure
236
+ *
237
+ * Statically allocates a new @ref unicoap_options_t container and a storage buffer
238
+ * with @ref CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY, and initializes it.
239
+ * No need to call @ref unicoap_options_t::unicoap_options_init afterwards.
240
+ *
241
+ * See @ref UNICOAP_OPTIONS_ALLOC_DEFAULT for non-static allocation
242
+ */
243
+ #define UNICOAP_OPTIONS_ALLOC_STATIC_DEFAULT (name ) \
244
+ UNICOAP_OPTIONS_ALLOC_STATIC(name, CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY)
209
245
/** @} */
210
246
211
247
/* MARK: - Option characteristics */
0 commit comments