Skip to content

Commit 73db5da

Browse files
author
Cruz Monrreal
authored
Merge pull request #8981 from donatieng/cordio_nordic_memory_optimizations
Cordio Nordic memory optimizations
2 parents 243b9df + aa4b5a5 commit 73db5da

File tree

8 files changed

+70
-8
lines changed

8 files changed

+70
-8
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/doc/PortingGuide.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,26 @@ The functions `do_initialize` and `do_terminate` handle initialization and termi
149149

150150
##### Memory pool
151151

152-
The function `get_buffer_pool_description` in the base class returns a buffer of 1040 bytes divided into different memory pools:
152+
Porters must override the `get_buffer_pool_description` function, which should return a buffer pool for the Cordio stack to use.
153+
154+
The function `get_default_buffer_pool_description` in the base class returns a buffer of 2250 bytes divided into different memory pools, and most implementations can use it:
153155

154156
| Chunk size (bytes) | Number of chunks |
155157
|--------------------|------------------|
156-
| 16 | 8 |
157-
| 32 | 4 |
158-
| 64 | 2 |
159-
| 128 | 2 |
158+
| 16 | 16 |
159+
| 32 | 16 |
160+
| 64 | 8 |
161+
| 128 | 4 |
160162
| 272 | 1 |
161163

162-
Porting overrides this function if the memory provided by the base class doesn't match what is required by the Bluetooth controller driver.
164+
**Example:**
165+
```
166+
buf_pool_desc_t CordioHCIDriver::get_buffer_pool_description() {
167+
return get_default_buffer_pool_description();
168+
}
169+
```
170+
171+
If the memory the base class provides doesn't match what the Bluetooth controller driver requires, a custom pool can be returned.
163172

164173
**Example:**
165174

features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void CordioHCIDriver::terminate()
7878
_transport_driver.terminate();
7979
}
8080

81-
buf_pool_desc_t CordioHCIDriver::get_buffer_pool_description()
81+
buf_pool_desc_t CordioHCIDriver::get_default_buffer_pool_description()
8282
{
8383
static union {
8484
uint8_t buffer[2250];

features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CordioHCIDriver {
7777
/**
7878
* Return the set of memory pool which will be used by the Cordio stack
7979
*/
80-
virtual buf_pool_desc_t get_buffer_pool_description();
80+
virtual buf_pool_desc_t get_buffer_pool_description() = 0;
8181

8282
/**
8383
* Initialize the HCI driver.
@@ -126,6 +126,13 @@ class CordioHCIDriver {
126126
*/
127127
uint16_t write(uint8_t type, uint16_t len, uint8_t *pData);
128128

129+
protected:
130+
/**
131+
* Return a default set of memory pool that the Cordio stack can use.
132+
* This function can be used to implement get_buffer_pool_description().
133+
*/
134+
buf_pool_desc_t get_default_buffer_pool_description();
135+
129136
private:
130137
/**
131138
* Initialize the chip.

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,15 @@ void BLE::stack_setup()
330330
buf_pool_desc.pool_count, buf_pool_desc.pool_description
331331
);
332332

333+
// Raise assert if not enough memory was allocated
333334
MBED_ASSERT(bytes_used != 0);
334335

336+
// This warning will be raised if we've allocated too much memory
337+
if(bytes_used < buf_pool_desc.buffer_size)
338+
{
339+
MBED_WARNING1(MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_INVALID_SIZE), "Too much memory allocated for Cordio memory pool, reduce buf_pool_desc.buffer_size by value below.", buf_pool_desc.buffer_size - bytes_used);
340+
}
341+
335342
WsfTimerInit();
336343
SecInit();
337344

features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class HCIDriver : public cordio::CordioHCIDriver {
4141
service_pack_transfered(false) {
4242
};
4343

44+
virtual cordio::buf_pool_desc_t get_buffer_pool_description();
45+
4446
virtual void do_initialize();
4547

4648
virtual void do_terminate();
@@ -134,6 +136,13 @@ class HCIDriver : public cordio::CordioHCIDriver {
134136
} // namespace vendor
135137
} // namespace ble
136138

139+
140+
ble::vendor::cordio::buf_pool_desc_t ble::vendor::odin_w2::HCIDriver::get_buffer_pool_description()
141+
{
142+
// Use default buffer pool
143+
return ble::vendor::cordio::CordioHCIDriver::get_default_buffer_pool_description();
144+
}
145+
137146
void ble::vendor::odin_w2::HCIDriver::do_initialize()
138147
{
139148
cordio_callback_s callback;

features/FEATURE_BLE/targets/TARGET_CYW4343X/HCIDriver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ class HCIDriver : public cordio::CordioHCIDriver {
8484
service_pack_transfered(false) {
8585
}
8686

87+
virtual cordio::buf_pool_desc_t get_buffer_pool_description()
88+
{
89+
// Use default buffer pool
90+
return cordio::CordioHCIDriver::get_default_buffer_pool_description();
91+
}
92+
8793
virtual void do_initialize()
8894
{
8995
output_mode(bt_host_wake_name, 1);

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CY8C63XX/Psoc6BLE.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Psoc6HCIDriver : public CordioHCIDriver
4646
BdAddress() : addr_type(0) {}
4747
};
4848

49+
virtual cordio::buf_pool_desc_t get_buffer_pool_description();
50+
4951
/**
5052
* Initialize the chip.
5153
* The transport is up at that time.
@@ -63,6 +65,12 @@ class Psoc6HCIDriver : public CordioHCIDriver
6365
BdAddress bd_address;
6466
};
6567

68+
cordio::buf_pool_desc_t Psoc6HCIDriver::get_buffer_pool_description()
69+
{
70+
// Use default buffer pool
71+
return ble::vendor::cordio::CordioHCIDriver::get_default_buffer_pool_description();
72+
}
73+
6674

6775
void Psoc6HCIDriver::do_initialize()
6876
{

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_CORDIO/TARGET_NRF5x/NRFCordioHCIDriver.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ using namespace ble::vendor::nordic;
5656
using namespace ble::vendor::cordio;
5757

5858
/*! \brief Memory that should be reserved for the stack. */
59+
#if defined(NRF52840_XXAA)
5960
#define CORDIO_LL_MEMORY_FOOTPRINT 41906UL
61+
#else
62+
#define CORDIO_LL_MEMORY_FOOTPRINT 12768UL
63+
#endif
6064

6165
/*! \brief Typical implementation revision number (LlRtCfg_t::implRev). */
6266
#define LL_IMPL_REV 0x2303
@@ -107,7 +111,11 @@ const LlRtCfg_t NRFCordioHCIDriver::_ll_cfg = {
107111
/*maxScanReqRcvdEvt*/ 4,
108112
/*maxExtScanDataLen*/ advDataLen,
109113
/* Connection */
114+
#if defined(NRF52840_XXAA)
110115
/*maxConn*/ 4,
116+
#else
117+
/*maxConn*/ 2,
118+
#endif
111119
/*numTxBufs*/ numTxBufs,
112120
/*numRxBufs*/ numRxBufs,
113121
/*maxAclLen*/ connDataLen,
@@ -117,7 +125,11 @@ const LlRtCfg_t NRFCordioHCIDriver::_ll_cfg = {
117125
/*dtmRxSyncMs*/ 10000,
118126
/* PHY */
119127
/*phy2mSup*/ TRUE,
128+
#if defined(NRF52840_XXAA)
120129
/*phyCodedSup*/ TRUE,
130+
#else
131+
/*phyCodedSup*/ FALSE,
132+
#endif
121133
/*stableModIdxTxSup*/ TRUE,
122134
/*stableModIdxRxSup*/ TRUE
123135
};
@@ -184,7 +196,11 @@ NRFCordioHCIDriver::~NRFCordioHCIDriver()
184196
ble::vendor::cordio::buf_pool_desc_t NRFCordioHCIDriver::get_buffer_pool_description()
185197
{
186198
static union {
199+
#if defined(NRF52840_XXAA)
187200
uint8_t buffer[ 17304 ];
201+
#else
202+
uint8_t buffer[ 8920 ];
203+
#endif
188204
uint64_t align;
189205
};
190206
static const wsfBufPoolDesc_t pool_desc[] = {

0 commit comments

Comments
 (0)