Skip to content

Commit 02e90ef

Browse files
author
Cruz Monrreal
authored
Merge pull request #7163 from pan-/cordio-driver-hook
Cordio driver hook
2 parents a782081 + 06d9aac commit 02e90ef

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ struct buf_pool_desc_t {
5858
* - Access to the write function of the underlying HCITransport driver.
5959
*/
6060
class CordioHCIDriver {
61+
62+
// hook for internal tests and passthrough driver
63+
friend class CordioHCIHook;
64+
6165
public:
6266
/**
6367
* Construct a new instance of an HCI driver.

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include <algorithm>
18+
#include <limits>
19+
1720
#include "CordioHCITransportDriver.h"
1821
#include "CordioHCIDriver.h"
1922

@@ -23,9 +26,22 @@ namespace ble {
2326
namespace vendor {
2427
namespace cordio {
2528

29+
CordioHCITransportDriver::data_received_handler_t
30+
CordioHCITransportDriver::data_received_handler = hciTrSerialRxIncoming;
31+
2632
void CordioHCITransportDriver::on_data_received(uint8_t* data, uint16_t len)
2733
{
28-
hciTrSerialRxIncoming(data, len);
34+
while (len) {
35+
uint8_t chunk_length = std::min(len, (uint16_t) std::numeric_limits<uint8_t>::max());
36+
data_received_handler(data, chunk_length);
37+
len = len - chunk_length;
38+
data = data + chunk_length;
39+
}
40+
}
41+
42+
void CordioHCITransportDriver::set_data_received_handler(data_received_handler_t handler)
43+
{
44+
data_received_handler = handler;
2945
}
3046

3147
} // namespace cordio

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace cordio {
2828
* It allow the stack to write data in the HCI channel.
2929
*/
3030
class CordioHCITransportDriver {
31+
32+
// hook for internal tests and passthrough driver
33+
friend class CordioHCIHook;
34+
3135
public:
3236
/**
3337
* Driver destructor.
@@ -64,6 +68,13 @@ class CordioHCITransportDriver {
6468
* @param len Number of bytes received.
6569
*/
6670
static void on_data_received(uint8_t* data, uint16_t len);
71+
72+
private:
73+
typedef void (*data_received_handler_t)(uint8_t* data, uint8_t len);
74+
75+
static data_received_handler_t data_received_handler;
76+
77+
static void set_data_received_handler(data_received_handler_t handler);
6778
};
6879

6980
} // namespace cordio

0 commit comments

Comments
 (0)