Skip to content

Commit ab53154

Browse files
committed
nimble/porting: sync with core
Synchronization of state with core repository.
1 parent 7b5b5e5 commit ab53154

File tree

15 files changed

+911
-196
lines changed

15 files changed

+911
-196
lines changed

porting/nimble/include/mem/mem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ typedef struct os_mbuf *mem_frag_alloc_fn(uint16_t frag_size, void *arg);
6161
struct os_mbuf *mem_split_frag(struct os_mbuf **om, uint16_t max_frag_sz,
6262
mem_frag_alloc_fn *alloc_cb, void *cb_arg);
6363

64+
void *mem_pullup_obj(struct os_mbuf **om, uint16_t len);
65+
6466
#ifdef __cplusplus
6567
}
6668
#endif

porting/nimble/include/os/endian.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ extern "C" {
186186
#endif
187187

188188
#ifndef htobe64
189-
#define htobe64(x) os_bswap64(x)
189+
#define htobe64(x) os_bswap_64(x)
190190
#endif
191191

192192
#ifndef htole64
193193
#define htole64(x) ((uint64_t)(x))
194194
#endif
195195

196196
#ifndef be64toh
197-
#define be64toh(x) os_bswap64(x)
197+
#define be64toh(x) os_bswap_64(x)
198198
#endif
199199

200200
#ifndef le64toh

porting/nimble/include/os/os_cputime.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
* under the License.
1818
*/
1919

20-
/**
21-
* @addtogroup OSKernel
22-
* @{
23-
* @defgroup OSCPUTime High Resolution Timers
24-
* @{
25-
*/
20+
/**
21+
* @addtogroup OSKernel
22+
* @{
23+
* @defgroup OSCPUTime High Resolution Timers
24+
* @{
25+
*/
2626

2727
#ifndef H_OS_CPUTIME_
2828
#define H_OS_CPUTIME_
@@ -33,7 +33,6 @@ extern "C" {
3333

3434
#include "syscfg/syscfg.h"
3535
#include "hal/hal_timer.h"
36-
#include "os/os.h"
3736

3837
/*
3938
* NOTE: these definitions allow one to override the cputime frequency used.
@@ -88,9 +87,9 @@ extern struct os_cputime_data g_os_cputime;
8887
#define CPUTIME_LT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) < 0)
8988
/** evaluates to true if t1 is after t2 in time */
9089
#define CPUTIME_GT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) > 0)
91-
/** evaluates to true if t1 is after t2 in time */
92-
#define CPUTIME_GEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) >= 0)
9390
/** evaluates to true if t1 is on or after t2 in time */
91+
#define CPUTIME_GEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) >= 0)
92+
/** evaluates to true if t1 is on or before t2 in time */
9493
#define CPUTIME_LEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) <= 0)
9594

9695
/**
@@ -188,7 +187,7 @@ void os_cputime_delay_usecs(uint32_t usecs);
188187
* @param arg Pointer to data object to pass to timer.
189188
*/
190189
void os_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp,
191-
void *arg);
190+
void *arg);
192191

193192
/**
194193
* Start a cputimer that will expire at 'cputime'. If cputime has already

porting/nimble/include/os/os_error.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
#include "os/os.h"
2424

25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/* OS error enumerations */
2530
enum os_error {
2631
OS_OK = 0,
2732
OS_ENOMEM = 1,
@@ -40,4 +45,18 @@ enum os_error {
4045

4146
typedef enum os_error os_error_t;
4247

48+
/**
49+
* @brief Converts an OS error code (`OS_[...]`) to an equivalent system error
50+
* code (`SYS_E[...]`).
51+
*
52+
* @param os_error The OS error code to convert.
53+
*
54+
* @return The equivalent system error code.
55+
*/
56+
int os_error_to_sys(os_error_t os_error);
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
4362
#endif

porting/nimble/include/os/os_mbuf.h

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ _os_mbuf_leadingspace(struct os_mbuf *om)
189189
}
190190

191191
leadingspace = (uint16_t) (OS_MBUF_DATA(om, uint8_t *) -
192-
((uint8_t *) &om->om_databuf[0] + startoff));
192+
((uint8_t *) &om->om_databuf[0] + startoff));
193193

194194
return (leadingspace);
195195
}
@@ -220,7 +220,7 @@ _os_mbuf_trailingspace(struct os_mbuf *om)
220220
omp = om->om_omp;
221221

222222
return (&om->om_databuf[0] + omp->omp_databuf_len) -
223-
(om->om_data + om->om_len);
223+
(om->om_data + om->om_len);
224224
}
225225

226226
/** @endcond */
@@ -347,7 +347,7 @@ int os_msys_num_free(void);
347347
* @return 0 on success, error code on failure.
348348
*/
349349
int os_mbuf_pool_init(struct os_mbuf_pool *, struct os_mempool *mp,
350-
uint16_t, uint16_t);
350+
uint16_t, uint16_t);
351351

352352
/**
353353
* Get an mbuf from the mbuf pool. The mbuf is allocated, and initialized
@@ -370,7 +370,7 @@ struct os_mbuf *os_mbuf_get(struct os_mbuf_pool *omp, uint16_t);
370370
* @return A freshly allocated mbuf on success, NULL on failure.
371371
*/
372372
struct os_mbuf *os_mbuf_get_pkthdr(struct os_mbuf_pool *omp,
373-
uint8_t pkthdr_len);
373+
uint8_t pkthdr_len);
374374

375375
/**
376376
* Duplicate a chain of mbufs. Return the start of the duplicated chain.
@@ -413,6 +413,20 @@ struct os_mbuf *os_mbuf_off(const struct os_mbuf *om, int off,
413413
*/
414414
int os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst);
415415

416+
/**
417+
* @brief Calculates the length of an mbuf chain.
418+
*
419+
* Calculates the length of an mbuf chain. If the mbuf contains a packet
420+
* header, you should use `OS_MBUF_PKTLEN()` as a more efficient alternative to
421+
* this function.
422+
*
423+
* @param om The mbuf to measure.
424+
*
425+
* @return The length, in bytes, of the provided mbuf
426+
* chain.
427+
*/
428+
uint16_t os_mbuf_len(const struct os_mbuf *om);
429+
416430
/**
417431
* Append data onto a mbuf
418432
*
@@ -614,6 +628,22 @@ struct os_mbuf *os_mbuf_pullup(struct os_mbuf *om, uint16_t len);
614628
*/
615629
struct os_mbuf *os_mbuf_trim_front(struct os_mbuf *om);
616630

631+
/**
632+
* Increases the length of an mbuf chain by inserting a gap at the specified
633+
* offset. The contents of the gap are indeterminate. If the mbuf chain
634+
* contains a packet header, its total length is increased accordingly.
635+
*
636+
* This function never frees the provided mbuf chain.
637+
*
638+
* @param om The mbuf chain to widen.
639+
* @param off The offset at which to insert the gap.
640+
* @param len The size of the gap to insert.
641+
*
642+
* @return 0 on success; SYS_[...] error code on failure.
643+
*/
644+
int os_mbuf_widen(struct os_mbuf *om, uint16_t off, uint16_t len);
645+
646+
617647
/**
618648
* Creates a single chained mbuf from m1 and m2 utilizing all
619649
* the available buffer space in all mbufs in the resulting

porting/nimble/include/os/os_mempool.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct os_mempool {
6666
/** Bitmap of OS_MEMPOOL_F_[...] values. */
6767
uint8_t mp_flags;
6868
/** Address of memory buffer used by pool */
69-
uintptr_t mp_membuf_addr;
69+
uint32_t mp_membuf_addr;
7070
STAILQ_ENTRY(os_mempool) mp_list;
7171
SLIST_HEAD(,os_memblock);
7272
/** Name for memory block */
@@ -140,20 +140,31 @@ struct os_mempool_info {
140140
* when at the last memory pool.
141141
*/
142142
struct os_mempool *os_mempool_info_get_next(struct os_mempool *,
143-
struct os_mempool_info *);
143+
struct os_mempool_info *);
144144

145145
/*
146146
* To calculate size of the memory buffer needed for the pool. NOTE: This size
147147
* is NOT in bytes! The size is the number of os_membuf_t elements required for
148148
* the memory pool.
149149
*/
150-
#if (OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4)
151-
#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 3) / 4) * (n))
152-
typedef uint32_t os_membuf_t;
150+
#if MYNEWT_VAL(OS_MEMPOOL_GUARD)
151+
/*
152+
* Leave extra 4 bytes of guard area at the end.
153+
*/
154+
#define OS_MEMPOOL_BLOCK_SZ(sz) ((sz) + sizeof(os_membuf_t))
153155
#else
154-
#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 7) / 8) * (n))
155-
typedef uint64_t os_membuf_t;
156+
#define OS_MEMPOOL_BLOCK_SZ(sz) (sz)
156157
#endif
158+
#if (OS_ALIGNMENT == 4)
159+
typedef uint32_t os_membuf_t;
160+
#elif (OS_ALIGNMENT == 8)
161+
typedef uint64_t os_membuf_t;
162+
#elif (OS_ALIGNMENT == 16)
163+
typedef __uint128_t os_membuf_t;
164+
#else
165+
#error "Unhandled `OS_ALIGNMENT` for `os_membuf_t`"
166+
#endif /* OS_ALIGNMENT == * */
167+
#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + ((OS_ALIGNMENT)-1)) / (OS_ALIGNMENT)) * (n))
157168

158169
/** Calculates the number of bytes required to initialize a memory pool. */
159170
#define OS_MEMPOOL_BYTES(n,blksize) \
@@ -189,6 +200,17 @@ os_error_t os_mempool_init(struct os_mempool *mp, uint16_t blocks,
189200
os_error_t os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks,
190201
uint32_t block_size, void *membuf, char *name);
191202

203+
/**
204+
* Removes the specified mempool from the list of initialized mempools.
205+
*
206+
* @param mp The mempool to unregister.
207+
*
208+
* @return 0 on success;
209+
* OS_INVALID_PARM if the mempool is not
210+
* registered.
211+
*/
212+
os_error_t os_mempool_unregister(struct os_mempool *mp);
213+
192214
/**
193215
* Clears a memory pool.
194216
*

0 commit comments

Comments
 (0)