feat(ble): added ble support for esp32h4 eco1

This commit is contained in:
ShenWeilong
2026-04-02 14:59:40 +08:00
parent 099d7ee8ce
commit 6e359ad99e
151 changed files with 12582 additions and 846 deletions
@@ -0,0 +1,721 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef _BLE_MBUF_H
#define _BLE_MBUF_H
#include "btdm_mempool.h"
#include "queue.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* A mbuf pool from which to allocate mbufs. This contains a pointer to the os
* mempool to allocate mbufs out of, the total number of elements in the pool,
* and the amount of "user" data in a non-packet header mbuf. The total pool
* size, in bytes, should be:
* ble_mbuf_count * (omp_databuf_len + sizeof(struct ble_mbuf))
*/
struct ble_mbuf_pool {
/**
* Total length of the databuf in each mbuf. This is the size of the
* mempool block, minus the mbuf header
*/
uint16_t omp_databuf_len;
/**
* The memory pool which to allocate mbufs out of
*/
struct btdm_mempool *omp_pool;
STAILQ_ENTRY(ble_mbuf_pool) omp_next;
};
/**
* A packet header structure that precedes the mbuf packet headers.
*/
struct ble_mbuf_pkthdr {
/**
* Overall length of the packet.
*/
uint16_t omp_len;
/**
* Flags
*/
uint16_t omp_flags;
STAILQ_ENTRY(ble_mbuf_pkthdr) omp_next;
};
/**
* Chained memory buffer.
*/
struct ble_mbuf {
/**
* Current pointer to data in the structure
*/
uint8_t *om_data;
/**
* Flags associated with this buffer, see BLE_MBUF_F_* definitions
*/
uint8_t om_flags;
/**
* Length of packet header
*/
uint8_t om_pkthdr_len;
/**
* Length of data in this buffer
*/
uint16_t om_len;
/**
* The mbuf pool this mbuf was allocated out of
*/
struct ble_mbuf_pool *om_omp;
SLIST_ENTRY(ble_mbuf) om_next;
/**
* Pointer to the beginning of the data, after this buffer
*/
uint8_t om_databuf[0];
};
/*
* Checks whether a given mbuf is a packet header mbuf
*
* @param __om The mbuf to check
*/
#define BLE_MBUF_IS_PKTHDR(__om) ((__om)->om_pkthdr_len >= sizeof(struct ble_mbuf_pkthdr))
/** Get a packet header pointer given an mbuf pointer */
#define BLE_MBUF_PKTHDR(__om) \
((struct ble_mbuf_pkthdr *)(uintptr_t)(void *)((uint8_t *)&(__om)->om_data + \
sizeof(struct ble_mbuf)))
/** Given a mbuf packet header pointer, return a pointer to the mbuf */
#define BLE_MBUF_PKTHDR_TO_MBUF(__hdr) \
(struct ble_mbuf *)(uintptr_t)((uint8_t *)(__hdr) - sizeof(struct ble_mbuf))
/**
* Gets the length of an entire mbuf chain. The specified mbuf must have a
* packet header.
*/
#define BLE_MBUF_PKTLEN(__om) (BLE_MBUF_PKTHDR(__om)->omp_len)
/**
* Access the data of a mbuf, and cast it to type
*
* @param __om The mbuf to access, and cast
* @param __type The type to cast it to
*/
#define BLE_MBUF_DATA(__om, __type) (__type)((__om)->om_data)
/**
* Access the "user header" in the head of an mbuf chain.
*
* @param om Pointer to the head of an mbuf chain.
*/
#define BLE_MBUF_USRHDR(om) \
(void *)((uint8_t *)om + sizeof(struct ble_mbuf) + sizeof(struct ble_mbuf_pkthdr))
/**
* Retrieves the length of the user header in an mbuf.
*
* @param om Pointer to the mbuf to query.
*/
#define BLE_MBUF_USRHDR_LEN(om) ((om)->om_pkthdr_len - sizeof(struct ble_mbuf_pkthdr))
/*
* Called by BLE_MBUF_LEADINGSPACE() macro
*/
static inline uint16_t
_ble_mbuf_leadingspace(struct ble_mbuf *om)
{
extern uint16_t r_os_mbuf_leadingspace(struct ble_mbuf * om);
return r_os_mbuf_leadingspace(om);
}
/**
* Returns the leading space (space at the beginning) of the mbuf.
* Works on both packet header, and regular mbufs, as it accounts
* for the additional space allocated to the packet header.
*
* @param __omp Is the mbuf pool (which contains packet header length.)
* @param __om Is the mbuf in that pool to get the leadingspace for
*
* @return Amount of leading space available in the mbuf
*/
#define BLE_MBUF_LEADINGSPACE(__om) _ble_mbuf_leadingspace(__om)
/** @cond INTERNAL_HIDDEN */
/* Called by BLE_MBUF_TRAILINGSPACE() macro. */
static inline uint16_t
_ble_mbuf_trailingspace(struct ble_mbuf *om)
{
extern uint16_t r_os_mbuf_trailingspace(struct ble_mbuf * om);
return r_os_mbuf_trailingspace(om);
}
/** @endcond */
/**
* Returns the trailing space (space at the end) of the mbuf.
* Works on both packet header and regular mbufs.
*
* @param __omp The mbuf pool for this mbuf
* @param __om Is the mbuf in that pool to get trailing space for
*
* @return The amount of trailing space available in the mbuf
*/
#define BLE_MBUF_TRAILINGSPACE(__om) _ble_mbuf_trailingspace(__om)
/**
* MSYS is a system level mbuf registry. Allows the system to share
* packet buffers amongst the various networking stacks that can be running
* simultaeneously.
*
* Mbuf pools are created in the system initialization code, and then when
* a mbuf is allocated out of msys, it will try and find the best fit based
* upon estimated mbuf size.
*
* os_msys_register() registers a mbuf pool with MSYS, and allows MSYS to
* allocate mbufs out of it.
*
* @param new_pool The pool to register with MSYS
*
* @return 0 on success, non-zero on failure
*/
static inline int
ble_msys_register(struct ble_mbuf_pool *mp)
{
extern int r_os_msys_register(struct ble_mbuf_pool * mp);
return r_os_msys_register(mp);
}
/**
* Allocate a mbuf from msys. Based upon the data size requested,
* os_msys_get() will choose the mbuf pool that has the best fit.
*
* @param dsize The estimated size of the data being stored in the mbuf
* @param leadingspace The amount of leadingspace to allocate in the mbuf
*
* @return A freshly allocated mbuf on success, NULL on failure.
*/
static inline struct ble_mbuf *
ble_msys_get(uint16_t dsize, uint16_t leadingspace)
{
extern struct ble_mbuf *r_os_msys_get(uint16_t dsize, uint16_t leadingspace);
return r_os_msys_get(dsize, leadingspace);
}
/**
* De-registers all mbuf pools from msys.
*/
static inline void
ble_msys_reset(void)
{
extern void r_os_msys_reset(void);
r_os_msys_reset();
}
/**
* Allocate a packet header structure from the MSYS pool. See
* os_msys_register() for a description of MSYS.
*
* @param dsize The estimated size of the data being stored in the mbuf
* @param user_hdr_len The length to allocate for the packet header structure
*
* @return A freshly allocated mbuf on success, NULL on failure.
*/
static inline struct ble_mbuf *
ble_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len)
{
extern struct ble_mbuf *r_os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len);
return r_os_msys_get_pkthdr(dsize, user_hdr_len);
}
/**
* Count the number of blocks in all the mbuf pools that are allocated.
*
* @return total number of blocks allocated in Msys
*/
static inline int
ble_msys_count(void)
{
extern int r_os_msys_count(void);
return r_os_msys_count();
}
/**
* Return the number of free blocks in Msys
*
* @return Number of free blocks available in Msys
*/
static inline int
ble_msys_num_free(void)
{
extern int r_os_msys_num_free(void);
return r_os_msys_num_free();
}
/**
* Initialize a pool of mbufs.
*
* @param omp The mbuf pool to initialize
* @param mp The memory pool that will hold this mbuf pool
* @param buf_len The length of the buffer itself.
* @param nbufs The number of buffers in the pool
*
* @return 0 on success, error code on failure.
*/
static inline int
ble_mbuf_pool_init(struct ble_mbuf_pool *omp, struct btdm_mempool *mp, uint16_t buf_len,
uint16_t nbufs)
{
extern int r_os_mbuf_pool_init(struct ble_mbuf_pool *, struct btdm_mempool * mp, uint16_t,
uint16_t);
return r_os_mbuf_pool_init(omp, mp, buf_len, nbufs);
}
/**
* Get an mbuf from the mbuf pool. The mbuf is allocated, and initialized
* prior to being returned.
*
* @param omp The mbuf pool to return the packet from
* @param leadingspace The amount of leadingspace to put before the data
* section by default.
*
* @return An initialized mbuf on success, and NULL on failure.
*/
static inline struct ble_mbuf *
ble_mbuf_get(struct ble_mbuf_pool *omp, uint16_t leadingspace)
{
extern struct ble_mbuf *r_os_mbuf_get(struct ble_mbuf_pool * omp, uint16_t leadingspace);
return r_os_mbuf_get(omp, leadingspace);
}
/**
* Allocate a new packet header mbuf out of the os_mbuf_pool.
*
* @param omp The mbuf pool to allocate out of
* @param user_pkthdr_len The packet header length to reserve for the caller.
*
* @return A freshly allocated mbuf on success, NULL on failure.
*/
static inline struct ble_mbuf *
ble_mbuf_get_pkthdr(struct ble_mbuf_pool *omp, uint8_t user_pkthdr_len)
{
extern struct ble_mbuf *r_os_mbuf_get_pkthdr(struct ble_mbuf_pool * omp,
uint8_t user_pkthdr_len);
return r_os_mbuf_get_pkthdr(omp, user_pkthdr_len);
}
/**
* Duplicate a chain of mbufs. Return the start of the duplicated chain.
*
* @param omp The mbuf pool to duplicate out of
* @param om The mbuf chain to duplicate
*
* @return A pointer to the new chain of mbufs
*/
static inline struct ble_mbuf *
ble_mbuf_dup(struct ble_mbuf *m)
{
extern struct ble_mbuf *r_os_mbuf_dup(struct ble_mbuf * m);
return r_os_mbuf_dup(m);
}
/**
* Locates the specified absolute offset within an mbuf chain. The offset
* can be one past than the total length of the chain, but no greater.
*
* @param om The start of the mbuf chain to seek within.
* @param off The absolute address to find.
* @param out_off On success, this points to the relative offset
* within the returned mbuf.
*
* @return The mbuf containing the specified offset on
* success.
* NULL if the specified offset is out of bounds.
*/
static inline struct ble_mbuf *
ble_mbuf_off(const struct ble_mbuf *om, int off, uint16_t *out_off)
{
extern struct ble_mbuf *r_os_mbuf_off(const struct ble_mbuf *om, int off, uint16_t *out_off);
return r_os_mbuf_off(om, off, out_off);
}
/*
* Copy data from an mbuf chain starting "off" bytes from the beginning,
* continuing for "len" bytes, into the indicated buffer.
*
* @param m The mbuf chain to copy from
* @param off The offset into the mbuf chain to begin copying from
* @param len The length of the data to copy
* @param dst The destination buffer to copy into
*
* @return 0 on success;
* -1 if the mbuf does not contain enough data.
*/
static inline int
ble_mbuf_copydata(const struct ble_mbuf *m, int off, int len, void *dst)
{
extern int r_os_mbuf_copydata(const struct ble_mbuf *m, int off, int len, void *dst);
return r_os_mbuf_copydata(m, off, len, dst);
}
/**
* @brief Calculates the length of an mbuf chain.
*
* Calculates the length of an mbuf chain. If the mbuf contains a packet
* header, you should use `OS_MBUF_PKTLEN()` as a more efficient alternative to
* this function.
*
* @param om The mbuf to measure.
*
* @return The length, in bytes, of the provided mbuf
* chain.
*/
static inline uint16_t
ble_mbuf_len(const struct ble_mbuf *om)
{
extern uint16_t r_os_mbuf_len(const struct ble_mbuf *om);
return r_os_mbuf_len(om);
}
/**
* Append data onto a mbuf
*
* @param om The mbuf to append the data onto
* @param data The data to append onto the mbuf
* @param len The length of the data to append
*
* @return 0 on success, and an error code on failure
*/
static inline int
ble_mbuf_append(struct ble_mbuf *m, const void *data, uint16_t len)
{
extern int r_os_mbuf_append(struct ble_mbuf * m, const void *, uint16_t);
return r_os_mbuf_append(m, data, len);
}
/**
* Reads data from one mbuf and appends it to another. On error, the specified
* data range may be partially appended. Neither mbuf is required to contain
* an mbuf packet header.
*
* @param dst The mbuf to append to.
* @param src The mbuf to copy data from.
* @param src_off The absolute offset within the source mbuf
* chain to read from.
* @param len The number of bytes to append.
*
* @return 0 on success;
* OS_EINVAL if the specified range extends beyond
* the end of the source mbuf chain.
*/
static inline int
ble_mbuf_appendfrom(struct ble_mbuf *dst, const struct ble_mbuf *src, uint16_t src_off,
uint16_t len)
{
extern int r_os_mbuf_appendfrom(struct ble_mbuf * dst, const struct ble_mbuf *src,
uint16_t src_off, uint16_t len);
return r_os_mbuf_appendfrom(dst, src, src_off, len);
}
/**
* Release a mbuf back to the pool
*
* @param mb The Mbuf to release back to the pool
*
* @return 0 on success, -1 on failure
*/
static inline int
ble_mbuf_free(struct ble_mbuf *mb)
{
extern int r_os_mbuf_free(struct ble_mbuf * mb);
return r_os_mbuf_free(mb);
}
/**
* Free a chain of mbufs
*
* @param om The starting mbuf of the chain to free back into the pool
*
* @return 0 on success, -1 on failure
*/
static inline int
ble_mbuf_free_chain(struct ble_mbuf *om)
{
extern int r_os_mbuf_free_chain(struct ble_mbuf * om);
return r_os_mbuf_free_chain(om);
}
/**
* Adjust the length of a mbuf, trimming either from the head or the tail
* of the mbuf.
*
* @param mp The mbuf chain to adjust
* @param req_len The length to trim from the mbuf. If positive, trims
* from the head of the mbuf, if negative, trims from the
* tail of the mbuf.
*/
static inline void
ble_mbuf_adj(struct ble_mbuf *mp, int req_len)
{
extern void r_os_mbuf_adj(struct ble_mbuf * mp, int req_len);
r_os_mbuf_adj(mp, req_len);
}
/**
* Performs a memory compare of the specified region of an mbuf chain against a
* flat buffer.
*
* @param om The start of the mbuf chain to compare.
* @param off The offset within the mbuf chain to start the
* comparison.
* @param data The flat buffer to compare.
* @param len The length of the flat buffer.
*
* @return 0 if both memory regions are identical;
* A memcmp return code if there is a mismatch;
* INT_MAX if the mbuf is too short.
*/
static inline int
ble_mbuf_cmpf(const struct ble_mbuf *om, int off, const void *data, int len)
{
extern int r_os_mbuf_cmpf(const struct ble_mbuf *om, int off, const void *data, int len);
return r_os_mbuf_cmpf(om, off, data, len);
}
/**
* Compares the contents of two mbuf chains. The ranges of the two chains to
* be compared are specified via the two offset parameters and the len
* parameter. Neither mbuf chain is required to contain a packet header.
*
* @param om1 The first mbuf chain to compare.
* @param offset1 The absolute offset within om1 at which to
* start the comparison.
* @param om2 The second mbuf chain to compare.
* @param offset2 The absolute offset within om2 at which to
* start the comparison.
* @param len The number of bytes to compare.
*
* @return 0 if both mbuf segments are identical;
* A memcmp() return code if the segment contents
* differ;
* INT_MAX if a specified range extends beyond the
* end of its corresponding mbuf chain.
*/
static inline int
ble_mbuf_cmpm(const struct ble_mbuf *om1, uint16_t offset1, const struct ble_mbuf *om2,
uint16_t offset2, uint16_t len)
{
extern int r_os_mbuf_cmpm(const struct ble_mbuf *om1, uint16_t offset1,
const struct ble_mbuf *om2, uint16_t offset2, uint16_t len);
return r_os_mbuf_cmpm(om1, offset1, om2, offset2, len);
}
/**
* Increases the length of an mbuf chain by adding data to the front. If there
* is insufficient room in the leading mbuf, additional mbufs are allocated and
* prepended as necessary. If this function fails to allocate an mbuf, the
* entire chain is freed.
*
* The specified mbuf chain does not need to contain a packet header.
*
* @param omp The mbuf pool to allocate from.
* @param om The head of the mbuf chain.
* @param len The number of bytes to prepend.
*
* @return The new head of the chain on success;
* NULL on failure.
*/
static inline struct ble_mbuf *
ble_mbuf_prepend(struct ble_mbuf *om, int len)
{
extern struct ble_mbuf *r_os_mbuf_prepend(struct ble_mbuf * om, int len);
return r_os_mbuf_prepend(om, len);
}
/**
* Prepends a chunk of empty data to the specified mbuf chain and ensures the
* chunk is contiguous. If either operation fails, the specified mbuf chain is
* freed and NULL is returned.
*
* @param om The mbuf chain to prepend to.
* @param len The number of bytes to prepend and pullup.
*
* @return The modified mbuf on success;
* NULL on failure (and the mbuf chain is freed).
*/
static inline struct ble_mbuf *
ble_mbuf_prepend_pullup(struct ble_mbuf *om, uint16_t len)
{
extern struct ble_mbuf *r_os_mbuf_prepend_pullup(struct ble_mbuf * om, uint16_t len);
return r_os_mbuf_prepend_pullup(om, len);
}
/**
* Copies the contents of a flat buffer into an mbuf chain, starting at the
* specified destination offset. If the mbuf is too small for the source data,
* it is extended as necessary. If the destination mbuf contains a packet
* header, the header length is updated.
*
* @param om The mbuf chain to copy into.
* @param off The offset within the chain to copy to.
* @param src The source buffer to copy from.
* @param len The number of bytes to copy.
*
* @return 0 on success; nonzero on failure.
*/
static inline int
ble_mbuf_copyinto(struct ble_mbuf *om, int off, const void *src, int len)
{
extern int r_os_mbuf_copyinto(struct ble_mbuf * om, int off, const void *src, int len);
return r_os_mbuf_copyinto(om, off, src, len);
}
/**
* Attaches a second mbuf chain onto the end of the first. If the first chain
* contains a packet header, the header's length is updated. If the second
* chain has a packet header, its header is cleared.
*
* @param first The mbuf chain being attached to.
* @param second The mbuf chain that gets attached.
*/
static inline void
ble_mbuf_concat(struct ble_mbuf *first, struct ble_mbuf *second)
{
extern void r_os_mbuf_concat(struct ble_mbuf * first, struct ble_mbuf * second);
r_os_mbuf_concat(first, second);
}
/**
* Increases the length of an mbuf chain by the specified amount. If there is
* not sufficient room in the last buffer, a new buffer is allocated and
* appended to the chain. It is an error to request more data than can fit in
* a single buffer.
*
* @param om The head of the chain to extend.
* @param len The number of bytes to extend by.
*
* @return A pointer to the new data on success;
* NULL on failure.
*/
static inline void *
ble_mbuf_extend(struct ble_mbuf *om, uint16_t len)
{
extern void *r_os_mbuf_extend(struct ble_mbuf * om, uint16_t len);
return r_os_mbuf_extend(om, len);
}
/**
* Rearrange a mbuf chain so that len bytes are contiguous,
* and in the data area of an mbuf (so that OS_MBUF_DATA() will
* work on a structure of size len.) Returns the resulting
* mbuf chain on success, free's it and returns NULL on failure.
*
* If there is room, it will add up to "max_protohdr - len"
* extra bytes to the contiguous region, in an attempt to avoid being
* called next time.
*
* @param om The mbuf chain to make contiguous
* @param len The number of bytes in the chain to make contiguous
*
* @return The contiguous mbuf chain on success, NULL on failure.
*/
static inline struct ble_mbuf *
ble_mbuf_pullup(struct ble_mbuf *om, uint16_t len)
{
extern struct ble_mbuf *r_os_mbuf_pullup(struct ble_mbuf * om, uint16_t len);
return r_os_mbuf_pullup(om, len);
}
/**
* Removes and frees empty mbufs from the front of a chain. If the chain
* contains a packet header, it is preserved.
*
* @param om The mbuf chain to trim.
*
* @return The head of the trimmed mbuf chain.
*/
static inline struct ble_mbuf *
ble_mbuf_trim_front(struct ble_mbuf *om)
{
extern struct ble_mbuf *r_os_mbuf_trim_front(struct ble_mbuf * om);
return r_os_mbuf_trim_front(om);
}
/**
* Increases the length of an mbuf chain by inserting a gap at the specified
* offset. The contents of the gap are indeterminate. If the mbuf chain
* contains a packet header, its total length is increased accordingly.
*
* This function never frees the provided mbuf chain.
*
* @param om The mbuf chain to widen.
* @param off The offset at which to insert the gap.
* @param len The size of the gap to insert.
*
* @return 0 on success; SYS_[...] error code on failure.
*/
static inline int
ble_mbuf_widen(struct ble_mbuf *om, uint16_t off, uint16_t len)
{
extern int r_os_mbuf_widen(struct ble_mbuf * om, uint16_t off, uint16_t len);
return r_os_mbuf_widen(om, off, len);
}
/**
* Creates a single chained mbuf from m1 and m2 utilizing all
* the available buffer space in all mbufs in the resulting
* chain. In other words, ensures there is no leading space in
* any mbuf in the resulting chain and trailing space only in
* the last mbuf in the chain. Mbufs from either chain may be
* freed if not needed. No mbufs are allocated. Note that mbufs
* from m2 are added to the end of m1. If m1 has a packet
* header, it is retained and length updated. If m2 has a packet
* header it is discarded. If m1 is NULL, NULL is returned and
* m2 is left untouched.
*
* @param m1 Pointer to first mbuf chain to pack
* @param m2 Pointer to second mbuf chain to pack
*
* @return struct os_mbuf* Pointer to resulting mbuf chain
*/
static inline struct ble_mbuf *
ble_mbuf_pack_chains(struct ble_mbuf *m1, struct ble_mbuf *m2)
{
extern struct ble_mbuf *r_os_mbuf_pack_chains(struct ble_mbuf * m1, struct ble_mbuf * m2);
return r_os_mbuf_pack_chains(m1, m2);
}
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MBUF_H */
@@ -0,0 +1,23 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MSYS_H_
#define _BLE_MSYS_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int ble_msys_init(void);
void ble_msys_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MSYS_H_ */
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_PRIV_H_
#define _ESP_BLE_PRIV_H_
#include "btdm_osal.h"
int ble_stack_init(esp_bt_controller_config_t *cfg);
void ble_stack_deinit(void);
int ble_stack_enable(void);
void ble_stack_disable(void);
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
esp_err_t sleep_modem_ble_mac_modem_state_init(void);
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
void ble_osal_elem_calc(esp_bt_controller_config_t *cfg, btdm_osal_elem_num_t *elem);
#endif // _ESP_BLE_PRIV_H_
@@ -0,0 +1,178 @@
/*
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __BLE_USER_CFG_H__
#define __BLE_USER_CFG_H__
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#if CONFIG_BT_NIMBLE_ENABLED
#include "syscfg/syscfg.h"
#endif
#if CONFIG_BT_NIMBLE_ENABLED
#if CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY
#define BLE_LL_SCAN_PHY_NUMBER_N (2)
#else
#define BLE_LL_SCAN_PHY_NUMBER_N (1)
#endif
#define DEFAULT_BT_LE_MAX_PERIODIC_ADVERTISER_LIST MYNEWT_VAL(BLE_MAX_PERIODIC_ADVERTISER_LIST)
#define DEFAULT_BT_LE_MAX_PERIODIC_SYNCS MYNEWT_VAL(BLE_MAX_PERIODIC_SYNCS)
#define DEFAULT_BT_LE_MAX_CONNECTIONS MYNEWT_VAL(BLE_MAX_CONNECTIONS)
#define DEFAULT_BT_LE_ACL_BUF_SIZE MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE)
#define DEFAULT_BT_LE_ACL_BUF_COUNT MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT)
#define DEFAULT_BT_LE_HCI_EVT_BUF_SIZE MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE)
#define DEFAULT_BT_LE_EXT_ADV_MAX_SIZE MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)
#define DEFAULT_BT_LE_MAX_EXT_ADV_INSTANCES MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES)
#define DEFAULT_BT_NIMBLE_WHITELIST_SIZE MYNEWT_VAL(BLE_LL_WHITELIST_SIZE)
#define DEFAULT_BT_LE_HCI_EVT_HI_BUF_COUNT MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT)
#define DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT)
#define DEFAULT_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF CONFIG_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF
#define DEFAULT_BT_LE_POWER_CONTROL_ENABLED MYNEWT_VAL(BLE_POWER_CONTROL)
#else
#if CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY
#define BLE_LL_SCAN_PHY_NUMBER_N (2)
#else
#define BLE_LL_SCAN_PHY_NUMBER_N (1)
#endif
#if defined(CONFIG_BT_LE_MAX_PERIODIC_ADVERTISER_LIST)
#define DEFAULT_BT_LE_MAX_PERIODIC_ADVERTISER_LIST (CONFIG_BT_LE_MAX_PERIODIC_ADVERTISER_LIST)
#else
#define DEFAULT_BT_LE_MAX_PERIODIC_ADVERTISER_LIST (5)
#endif
#if defined(CONFIG_BT_LE_MAX_PERIODIC_SYNCS)
#define DEFAULT_BT_LE_MAX_PERIODIC_SYNCS (CONFIG_BT_LE_MAX_PERIODIC_SYNCS)
#else
#define DEFAULT_BT_LE_MAX_PERIODIC_SYNCS (1)
#endif
#if defined(CONFIG_BT_LE_MAX_CONNECTIONS)
#define DEFAULT_BT_LE_MAX_CONNECTIONS (CONFIG_BT_LE_MAX_CONNECTIONS)
#else
#define DEFAULT_BT_LE_MAX_CONNECTIONS (2)
#endif
#if defined(CONFIG_BT_LE_ACL_BUF_SIZE)
#define DEFAULT_BT_LE_ACL_BUF_SIZE (CONFIG_BT_LE_ACL_BUF_SIZE)
#else
#define DEFAULT_BT_LE_ACL_BUF_SIZE (255)
#endif
#if defined(CONFIG_BT_LE_ACL_BUF_COUNT)
#define DEFAULT_BT_LE_ACL_BUF_COUNT (CONFIG_BT_LE_ACL_BUF_COUNT)
#else
#define DEFAULT_BT_LE_ACL_BUF_COUNT (24)
#endif
#if defined(CONFIG_BT_LE_HCI_EVT_BUF_SIZE)
#define DEFAULT_BT_LE_HCI_EVT_BUF_SIZE (CONFIG_BT_LE_HCI_EVT_BUF_SIZE)
#else
#define DEFAULT_BT_LE_HCI_EVT_BUF_SIZE (70)
#endif
#if defined(CONFIG_BT_LE_EXT_ADV_MAX_SIZE)
#define DEFAULT_BT_LE_EXT_ADV_MAX_SIZE (CONFIG_BT_LE_EXT_ADV_MAX_SIZE)
#else
#define DEFAULT_BT_LE_EXT_ADV_MAX_SIZE (31)
#endif
#if defined(CONFIG_BT_LE_MAX_EXT_ADV_INSTANCES)
#define DEFAULT_BT_LE_MAX_EXT_ADV_INSTANCES (CONFIG_BT_LE_MAX_EXT_ADV_INSTANCES)
#else
#define DEFAULT_BT_LE_MAX_EXT_ADV_INSTANCES (1)
#endif
#if defined(CONFIG_BT_LE_WHITELIST_SIZE)
#define DEFAULT_BT_NIMBLE_WHITELIST_SIZE (CONFIG_BT_LE_WHITELIST_SIZE)
#else
#define DEFAULT_BT_NIMBLE_WHITELIST_SIZE (12)
#endif
#if defined(CONFIG_BT_LE_HCI_EVT_HI_BUF_COUNT)
#define DEFAULT_BT_LE_HCI_EVT_HI_BUF_COUNT (CONFIG_BT_LE_HCI_EVT_HI_BUF_COUNT)
#else
#define DEFAULT_BT_LE_HCI_EVT_HI_BUF_COUNT (30)
#endif
#if defined(CONFIG_BT_LE_HCI_EVT_LO_BUF_COUNT)
#define DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT (CONFIG_BT_LE_HCI_EVT_LO_BUF_COUNT)
#else
#define DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT (8)
#endif
#define DEFAULT_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF CONFIG_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF
#if defined(CONFIG_BT_LE_POWER_CONTROL_ENABLED)
#define DEFAULT_BT_LE_POWER_CONTROL_ENABLED (CONFIG_BT_LE_POWER_CONTROL_ENABLED)
#else
#define DEFAULT_BT_LE_POWER_CONTROL_ENABLED (0)
#endif
#endif
#ifdef CONFIG_BT_LE_TX_CCA_ENABLED
#define DEFAULT_BT_LE_TX_CCA_ENABLED (CONFIG_BT_LE_TX_CCA_ENABLED)
#else
#define DEFAULT_BT_LE_TX_CCA_ENABLED (0)
#endif
#ifdef CONFIG_BT_LE_CCA_RSSI_THRESH
#define DEFAULT_BT_LE_CCA_RSSI_THRESH (CONFIG_BT_LE_CCA_RSSI_THRESH)
#else
#define DEFAULT_BT_LE_CCA_RSSI_THRESH (50)
#endif
#define DEFAULT_BT_LE_SCAN_RSP_DATA_MAX_LEN_N DEFAULT_BT_LE_EXT_ADV_MAX_SIZE
/* Unchanged configuration */
#define BLE_LL_CTRL_PROC_TIMEOUT_MS_N (40000) /* ms */
#define BLE_LL_CFG_NUM_HCI_CMD_PKTS_N (1)
#define BLE_LL_SCHED_ADV_MAX_USECS_N (852)
#define BLE_LL_SCHED_DIRECT_ADV_MAX_USECS_N (502)
#define BLE_LL_SCHED_MAX_ADV_PDU_USECS_N (376)
#define BLE_LL_SUB_VERS_NR_N (0x0000)
#define BLE_LL_JITTER_USECS_N (16)
#define BLE_PHY_MAX_PWR_DBM_N (10)
#define BLE_LL_CONN_DEF_AUTH_PYLD_TMO_N (3000)
#define RTC_FREQ_N (32768) /* in Hz */
#define BLE_LL_TX_PWR_DBM_N (9)
#ifdef CONFIG_BT_LE_BQB_TEST_EN
#define RUN_BQB_TEST (CONFIG_BT_LE_BQB_TEST_EN)
#else
#define RUN_BQB_TEST (0)
#endif // CONFIG_BT_LE_BQB_TEST_EN
#define RUN_QA_TEST (0)
#define NIMBLE_DISABLE_SCAN_BACKOFF (0)
#ifdef __cplusplus
}
#endif
#endif /* __BLE_USER_CFG_H__ */
@@ -0,0 +1,425 @@
/*
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @addtogroup OSKernel
* @{
* @defgroup OSMempool Memory Pools
* @{
*/
#ifndef _OS_MEMPOOL_H_
#define _OS_MEMPOOL_H_
#include <stdbool.h>
#include "os/os.h"
#include "os/queue.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* A memory block structure. This simply contains a pointer to the free list
* chain and is only used when the block is on the free list. When the block
* has been removed from the free list the entire memory block is usable by the
* caller.
*/
struct os_memblock {
SLIST_ENTRY(os_memblock) mb_next;
};
/* XXX: Change this structure so that we keep the first address in the pool? */
/* XXX: add memory debug structure and associated code */
/* XXX: Change how I coded the SLIST_HEAD here. It should be named:
SLIST_HEAD(,os_memblock) mp_head; */
/**
* Memory pool
*/
struct os_mempool {
/** Size of the memory blocks, in bytes. */
uint32_t mp_block_size;
/** The number of memory blocks. */
uint16_t mp_num_blocks;
/** The number of free blocks left */
uint16_t mp_num_free;
/** The lowest number of free blocks seen */
uint16_t mp_min_free;
/** Bitmap of OS_MEMPOOL_F_[...] values. */
uint8_t mp_flags;
/** Address of memory buffer used by pool */
uint32_t mp_membuf_addr;
STAILQ_ENTRY(os_mempool) mp_list;
SLIST_HEAD(,os_memblock);
/** Name for memory block */
const char *name;
/** The number of allocated blocks. */
uint32_t mp_alloc_blocks;
};
/**
* Indicates an extended mempool. Address can be safely cast to
* (struct os_mempool_ext *).
*/
#define OS_MEMPOOL_F_EXT 0x01
/* Flag to indicate runtime allocation mode */
#define OS_MEMPOOL_F_RUNTIME 0x02
/* Flag to indicate reuse block for runtime allocation mode */
#define OS_MEMPOOL_F_REUSED 0x04
struct os_mempool_ext;
/**
* Block put callback function. If configured, this callback gets executed
* whenever a block is freed to the corresponding extended mempool. Note: The
* os_memblock_put() function calls this callback instead of freeing the block
* itself. Therefore, it is the callback's responsibility to free the block
* via a call to os_memblock_put_from_cb().
*
* @param ome The extended mempool that a block is being
* freed back to.
* @param data The block being freed.
* @param arg Optional argument configured along with the
* callback.
*
* @return Indicates whether the block was successfully
* freed. A non-zero value should only be
* returned if the block was not successfully
* released back to its pool.
*/
typedef os_error_t os_mempool_put_fn(struct os_mempool_ext *ome, void *data,
void *arg);
struct os_mempool_ext {
struct os_mempool mpe_mp;
/* Callback that is executed immediately when a block is freed. */
os_mempool_put_fn *mpe_put_cb;
void *mpe_put_arg;
};
#define OS_MEMPOOL_INFO_NAME_LEN (32)
/**
* Information describing a memory pool, used to return OS information
* to the management layer.
*/
struct os_mempool_info {
/** Size of the memory blocks in the pool */
int omi_block_size;
/** Number of memory blocks in the pool */
int omi_num_blocks;
/** Number of free memory blocks */
int omi_num_free;
/** Minimum number of free memory blocks ever */
int omi_min_free;
/** Name of the memory pool */
char omi_name[OS_MEMPOOL_INFO_NAME_LEN];
};
/**
* Get information about the next system memory pool.
*
* @param mempool The current memory pool, or NULL if starting iteration.
* @param info A pointer to the structure to return memory pool information
* into.
*
* @return The next memory pool in the list to get information about, or NULL
* when at the last memory pool.
*/
struct os_mempool *os_mempool_info_get_next(struct os_mempool *,
struct os_mempool_info *);
/*
* To calculate size of the memory buffer needed for the pool. NOTE: This size
* is NOT in bytes! The size is the number of os_membuf_t elements required for
* the memory pool.
*/
#if MYNEWT_VAL(OS_MEMPOOL_GUARD)
/*
* Leave extra 4 bytes of guard area at the end.
*/
#define OS_MEMPOOL_BLOCK_SZ(sz) ((sz) + sizeof(os_membuf_t))
#else
#define OS_MEMPOOL_BLOCK_SZ(sz) (sz)
#endif
#if (OS_ALIGNMENT == 4)
typedef uint32_t os_membuf_t;
#elif (OS_ALIGNMENT == 8)
typedef uint64_t os_membuf_t;
#elif (OS_ALIGNMENT == 16)
typedef __uint128_t os_membuf_t;
#else
#error "Unhandled `OS_ALIGNMENT` for `os_membuf_t`"
#endif /* OS_ALIGNMENT == * */
#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + ((OS_ALIGNMENT)-1)) / (OS_ALIGNMENT)) * (n))
/** Calculates the number of bytes required to initialize a memory pool. */
#define OS_MEMPOOL_BYTES(n,blksize) \
(sizeof (os_membuf_t) * OS_MEMPOOL_SIZE((n), (blksize)))
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
/**
* Initialize a memory pool.
*
* @param mp Pointer to a pointer to a mempool
* @param blocks The number of blocks in the pool
* @param blocks_size The size of the block, in bytes.
* @param membuf Pointer to memory to contain blocks.
* @param name Name of the pool.
*
* @return os_error_t
*/
os_error_t r_os_mempool_init(struct os_mempool *mp, uint16_t blocks,
uint32_t block_size, void *membuf, const char *name);
#define os_mempool_init r_os_mempool_init
/**
* Initializes an extended memory pool. Extended attributes (e.g., callbacks)
* are not specified when this function is called; they are assigned manually
* after initialization.
*
* @param mpe The extended memory pool to initialize.
* @param blocks The number of blocks in the pool.
* @param block_size The size of each block, in bytes.
* @param membuf Pointer to memory to contain blocks.
* @param name Name of the pool.
*
* @return os_error_t
*/
os_error_t r_os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks,
uint32_t block_size, void *membuf, const char *name);
#define os_mempool_ext_init r_os_mempool_ext_init
/**
* Removes the specified mempool from the list of initialized mempools.
*
* @param mp The mempool to unregister.
*
* @return 0 on success;
* OS_INVALID_PARM if the mempool is not
* registered.
*/
// os_error_t r_os_mempool_unregister(struct os_mempool *mp);
#define os_mempool_unregister(mp)
/**
* Clears a memory pool.
*
* @param mp The mempool to clear.
*
* @return os_error_t
*/
os_error_t r_os_mempool_clear(struct os_mempool *mp);
#define os_mempool_clear r_os_mempool_clear
/**
* Performs an integrity check of the specified mempool. This function
* attempts to detect memory corruption in the specified memory pool.
*
* @param mp The mempool to check.
*
* @return true if the memory pool passes the integrity
* check;
* false if the memory pool is corrupt.
*/
bool r_os_mempool_is_sane(const struct os_mempool *mp);
#define os_mempool_is_sane r_os_mempool_is_sane
/**
* Checks if a memory block was allocated from the specified mempool.
*
* @param mp The mempool to check as parent.
* @param block_addr The memory block to check as child.
*
* @return 0 if the block does not belong to the mempool;
* 1 if the block does belong to the mempool.
*/
int r_os_memblock_from(const struct os_mempool *mp, const void *block_addr);
#define os_memblock_from r_os_memblock_from
/**
* Get a memory block from a memory pool
*
* @param mp Pointer to the memory pool
*
* @return void* Pointer to block if available; NULL otherwise
*/
void *r_os_memblock_get(struct os_mempool *mp);
#define os_memblock_get r_os_memblock_get
/**
* Puts the memory block back into the pool, ignoring the put callback, if any.
* This function should only be called from a put callback to free a block
* without causing infinite recursion.
*
* @param mp Pointer to memory pool
* @param block_addr Pointer to memory block
*
* @return os_error_t
*/
os_error_t r_os_memblock_put_from_cb(struct os_mempool *mp, void *block_addr);
#define os_memblock_put_from_cb r_os_memblock_put_from_cb
/**
* Puts the memory block back into the pool
*
* @param mp Pointer to memory pool
* @param block_addr Pointer to memory block
*
* @return os_error_t
*/
os_error_t r_os_memblock_put(struct os_mempool *mp, void *block_addr);
#define os_memblock_put r_os_memblock_put
#else
/**
* Initialize a memory pool.
*
* @param mp Pointer to a pointer to a mempool
* @param blocks The number of blocks in the pool
* @param blocks_size The size of the block, in bytes.
* @param membuf Pointer to memory to contain blocks.
* @param name Name of the pool.
*
* @return os_error_t
*/
os_error_t os_mempool_init(struct os_mempool *mp, uint16_t blocks,
uint32_t block_size, void *membuf, const char *name);
/**
* Initializes an extended memory pool. Extended attributes (e.g., callbacks)
* are not specified when this function is called; they are assigned manually
* after initialization.
*
* @param mpe The extended memory pool to initialize.
* @param blocks The number of blocks in the pool.
* @param block_size The size of each block, in bytes.
* @param membuf Pointer to memory to contain blocks.
* @param name Name of the pool.
*
* @return os_error_t
*/
os_error_t os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks,
uint32_t block_size, void *membuf, const char *name);
/**
* Removes the specified mempool from the list of initialized mempools.
*
* @param mp The mempool to unregister.
*
* @return 0 on success;
* OS_INVALID_PARM if the mempool is not
* registered.
*/
os_error_t os_mempool_unregister(struct os_mempool *mp);
/**
* Clears a memory pool.
*
* @param mp The mempool to clear.
*
* @return os_error_t
*/
os_error_t os_mempool_clear(struct os_mempool *mp);
/**
* Clears an extended memory pool.
*
* @param mpe The extended memory pool to clear.
*
* @return os_error_t
*/
os_error_t os_mempool_ext_clear(struct os_mempool_ext *mpe);
/**
* Performs an integrity check of the specified mempool. This function
* attempts to detect memory corruption in the specified memory pool.
*
* @param mp The mempool to check.
*
* @return true if the memory pool passes the integrity
* check;
* false if the memory pool is corrupt.
*/
bool os_mempool_is_sane(const struct os_mempool *mp);
/**
* Checks if a memory block was allocated from the specified mempool.
*
* @param mp The mempool to check as parent.
* @param block_addr The memory block to check as child.
*
* @return 0 if the block does not belong to the mempool;
* 1 if the block does belong to the mempool.
*/
int os_memblock_from(const struct os_mempool *mp, const void *block_addr);
/**
* Get a memory block from a memory pool
*
* @param mp Pointer to the memory pool
*
* @return void* Pointer to block if available; NULL otherwise
*/
void *os_memblock_get(struct os_mempool *mp);
/**
* Puts the memory block back into the pool, ignoring the put callback, if any.
* This function should only be called from a put callback to free a block
* without causing infinite recursion.
*
* @param mp Pointer to memory pool
* @param block_addr Pointer to memory block
*
* @return os_error_t
*/
os_error_t os_memblock_put_from_cb(struct os_mempool *mp, void *block_addr);
/**
* Puts the memory block back into the pool
*
* @param mp Pointer to memory pool
* @param block_addr Pointer to memory block
*
* @return os_error_t
*/
os_error_t os_memblock_put(struct os_mempool *mp, void *block_addr);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _OS_MEMPOOL_H_ */
/**
* @} OSMempool
* @} OSKernel
*/
@@ -0,0 +1,78 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_err.h"
#include "queue.h"
#include "sdkconfig.h"
#if CONFIG_BT_NIMBLE_ENABLED
#include "syscfg/syscfg.h"
#endif
/*
***************************************************************************************************
* Local Defined Macros
***************************************************************************************************
*/
#define BLE_MSYS_ALIGN(__n, __a) \
((((__n) & ((__a) - 1)) == 0) ? (__n) : ((__n) + ((__a) - ((__n) & ((__a) - 1)))))
#if CONFIG_BT_NIMBLE_ENABLED
#define BLE_MSYS_1_BLOCK_COUNT MYNEWT_VAL(MSYS_1_BLOCK_COUNT)
#define BLE_MSYS_1_BLOCK_SIZE MYNEWT_VAL(MSYS_1_BLOCK_SIZE)
#define BLE_MSYS_2_BLOCK_COUNT MYNEWT_VAL(MSYS_2_BLOCK_COUNT)
#define BLE_MSYS_2_BLOCK_SIZE MYNEWT_VAL(MSYS_2_BLOCK_SIZE)
#define BLE_MSYS_BLOCK_FROM_HEAP CONFIG_BT_NIMBLE_MSYS_BUF_FROM_HEAP
#else
#define BLE_MSYS_1_BLOCK_COUNT CONFIG_BT_LE_MSYS_1_BLOCK_COUNT
#define BLE_MSYS_1_BLOCK_SIZE CONFIG_BT_LE_MSYS_1_BLOCK_SIZE
#define BLE_MSYS_2_BLOCK_COUNT CONFIG_BT_LE_MSYS_2_BLOCK_COUNT
#define BLE_MSYS_2_BLOCK_SIZE CONFIG_BT_LE_MSYS_2_BLOCK_SIZE
#define BLE_MSYS_BLOCK_FROM_HEAP CONFIG_BT_LE_MSYS_BUF_FROM_HEAP
#endif /* CONFIG_BT_NIMBLE_ENABLED */
#if BLE_MSYS_1_BLOCK_COUNT > 0
#define SYSINIT_MSYS_1_MEMBLOCK_SIZE BLE_MSYS_ALIGN(BLE_MSYS_1_BLOCK_SIZE, 4)
#define SYSINIT_MSYS_1_MEMPOOL_SIZE \
OS_MEMPOOL_SIZE(BLE_MSYS_1_BLOCK_COUNT, SYSINIT_MSYS_1_MEMBLOCK_SIZE)
#else
#error "BLE_MSYS_1_BLOCK_COUNT should be larger than 0!"
#endif /* BLE_MSYS_1_BLOCK_COUNT > 0 */
#if BLE_MSYS_2_BLOCK_COUNT > 0
#define SYSINIT_MSYS_2_MEMBLOCK_SIZE BLE_MSYS_ALIGN(BLE_MSYS_2_BLOCK_SIZE, 4)
#define SYSINIT_MSYS_2_MEMPOOL_SIZE \
OS_MEMPOOL_SIZE(BLE_MSYS_2_BLOCK_COUNT, SYSINIT_MSYS_2_MEMBLOCK_SIZE)
#else
#error #error "BLE_MSYS_2_BLOCK_COUNT should be larger than 0!"
#endif /* BLE_MSYS_2_BLOCK_COUNT > 0 */
/*
***************************************************************************************************
* External Functions
***************************************************************************************************
*/
extern int r_esp_ble_msys_init(uint16_t msys_size1, uint16_t msys_size2, uint16_t msys_cnt1,
uint16_t msys_cnt2, uint8_t from_heap);
extern void r_esp_ble_msys_deinit(void);
/*
***************************************************************************************************
* BLE MSYS Initialization
***************************************************************************************************
*/
int
ble_msys_init(void)
{
return r_esp_ble_msys_init(SYSINIT_MSYS_1_MEMBLOCK_SIZE, SYSINIT_MSYS_2_MEMBLOCK_SIZE,
BLE_MSYS_1_BLOCK_COUNT, BLE_MSYS_2_BLOCK_COUNT,
BLE_MSYS_BLOCK_FROM_HEAP);
}
void
ble_msys_deinit(void)
{
r_esp_ble_msys_deinit();
}