You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two main steps to enable the Mbed BLE Cordio port for a given target:
3
+
There are two main steps to enable the Mbed BLE Cordio port:
4
4
5
-
1. Configure the target to include Cordio BLE port and Cordio libraries
6
-
during the build process.
5
+
1. Configure your target to include Cordio BLE port and Cordio libraries during the build process.
7
6
8
-
1. Implement `CordioHCIDriver` class targeting the Bluetooth controller.
9
-
10
-
[[[Do we want something like this at the beginning? Why not just give the steps, instead of summarizing them?]]]
7
+
1. Implement the `CordioHCIDriver` class targeting the Bluetooth controller.
11
8
12
9
## Configure the target
13
10
@@ -25,11 +22,9 @@ Define all Mbed OS targets in the `targets/target.json` file:
25
22
26
23
### Include Cordio BLE implementation
27
24
28
-
* Compile the BLE Cordio port sources:
29
-
30
-
[[[sources?]]]
25
+
Compile the BLE Cordio port sources:
31
26
32
-
* Add the string `CORDIO` to the `extra_labels` property of the JSON file.
27
+
* Add the string `CORDIO` to the `extra_labels` property of the JSON file.
33
28
34
29
```
35
30
"TARGET_NAME": {
@@ -40,37 +35,25 @@ Define all Mbed OS targets in the `targets/target.json` file:
40
35
41
36
## Implement CordioHCIDriver:
42
37
43
-
Include an HCI driver for the BLE module used by the target and a factory function which creates the BLE instance used by the user of the BLE API.
38
+
Include an HCI driver for the BLE module used by the target, and a factory function which creates the BLE instance you use.
44
39
45
40
### Create source folder
46
41
47
-
Create a `TARGET_<target name>` folder.
48
-
49
-
The port shall live in the folder of BLE API which host targets port :
50
-
`features/FEATURE_BLE/targets`.
51
-
52
-
You need to create a folder containing the port code to isolate it from other code. Name
42
+
1. Navigate to the folder of the BLE API that hosts target port `features/FEATURE_BLE/targets`.
53
43
54
-
To isolate the port code from other code, a folder containing the port code has
55
-
to be created. The name of this folder shall start with `TARGET_` and end with
56
-
the target name in capital.
44
+
1. Create a folder containing the port code to isolate it from other code. Begin this folder's name with `TARGET_` and the rest of the name in capital letters.
57
45
58
46
### Create the HCI driver
59
47
60
-
The HCI driver is split in two entities: one which handle HCI communication with
61
-
the Bluetooth module and the other handling the initialization, reset sequence
62
-
and memory dedicated for the Bluetooth controller.
48
+
The HCI driver is split in two entities: one which handle HCI communication with the Bluetooth module and the other handling the initialization, reset sequence and memory dedicated for the Bluetooth controller.
63
49
64
-
More information about the architecture can be found in the
More information about the architecture can be found in the [HCI abstraction architecture](HCIAbstraction.md) document.
66
51
67
52
#### HCITransport
68
53
69
-
<spanclass="notes">**Note:** If the Bluetooth controller uses an H4 communication interface and
70
-
the host exposes serial flow control in Mbed, then you can skip this step. Use the class `ble::vendor::cordio::H4TransportDriver` as the transport
71
-
driver.</span>
54
+
<spanclass="notes">**Note:** If the Bluetooth controller uses an H4 communication interface and the host exposes serial flow control in Mbed, then you can skip this step. Use the class `ble::vendor::cordio::H4TransportDriver` as the transport driver.</span>
72
55
73
-
You can code an empty transport driver as:
56
+
To code an empty transport driver:
74
57
75
58
```
76
59
#include "CordioHCITransportDriver.h"
@@ -102,28 +85,19 @@ private:
102
85
103
86
It inherits publicly from the base class `CordioHCITransportDriver`.
104
87
105
-
[[[still don't know what this means]]]
88
+
***Initialization/termination**: The functions `initialize` and `terminate` are responsible for initializing and terminating the transport driver. It is not necessary to initialize the transport in the constructor.
106
89
107
-
***Initialization/termination:** The functions `initialize` and `terminate` are
108
-
responsible for initializing and terminating the transport driver. It is not
109
-
necessary to initialize the transport in the constructor.
90
+
***Sending data**: The function `write` sends data in input to the Bluetooth controller and return the number of bytes in the `data` buffer sent. Depending on the type of transport you implement, you may need to send the packet `type` to the controller before the packet data.
110
91
111
-
***Sending data** The function `write` shall sends data in input to the
112
-
Bluetooth controller and return the number of bytes in the `data` buffer sent.
113
-
Depending on the type of transport being implemented, the packet `type` might
114
-
have to be sent to the controller before the packet data.
115
-
116
-
***Receiving data**: HCI data from the Bluetooth controller shall be injected
117
-
in the system by invoking the function `on_data_received` injects . This function is
118
-
a static one and is provided by the base class. Its prototype is:
92
+
***Receiving data**: Inject HCI data from the Bluetooth controller to the system by invoking the function `on_data_received`. This function is a static one and is provided by the base class:
The functions `do_initialize` and `do_terminate` handle initialization and termination processes. These functions manage the state of the Bluetooth controller.
165
139
166
-
<spanclass="notes">**Note:** It is unnecessary to initialize or terminate the HCI transport in those function because it is handled by the base class. The HCI transport is initialized right before the call to `do_initialize` and is terminated right
167
-
after the call to `do_terminate`.</span>
140
+
<spanclass="notes">**Note:** It is unnecessary to initialize or terminate the HCI transport in those function because it is handled by the base class. The HCI transport is initialized right before the call to `do_initialize` and is terminated right after the call to `do_terminate`.</span>
168
141
169
142
##### Memory pool
170
143
@@ -178,8 +151,7 @@ The function `get_buffer_pool_description` in the base class returns a buffer of
178
151
| 128 | 2 |
179
152
| 272 | 1 |
180
153
181
-
A port overrides this function if the memory provided by the base class
182
-
doesn't match what is required by the Bluetooth controller driver.
154
+
Porting overrides this function if the memory provided by the base class doesn't match what is required by the Bluetooth controller driver.
The reset sequence process is handled by three functions:
175
+
Three functions handle the reset sequence process:
204
176
205
-
*`start_reset_sequence`: This function start the process. The basic
206
-
implementation sends an HCI reset command to the Bluetooth controller. The
207
-
function shall be overridden in the driver if the bluetooth controller requires
208
-
more than just sending the standard reset command.
177
+
*`start_reset_sequence`: This function starts the process. It sends an HCI reset command to the Bluetooth controller. You can override this function *if* the Bluetooth controller requires more than just sending the standard reset command.
209
178
210
-
*`handle_reset_sequence`: Entry point to the state machine handling the reset
211
-
process. Every time an HCI packet is received during the reset sequence, this
212
-
function is called with the HCI packet received. Its purpose is to prepare the
213
-
Bluetooth controller and set the parameters the stack needs to operate properly.
214
-
This function can be overridden if necessary.
179
+
*`handle_reset_sequence`: Entry point to the state machine handling the reset process. Every time an HCI packet is received during the reset sequence, this function is called with the HCI packet received. Its purpose is to prepare the Bluetooth controller and set the parameters the stack needs to operate properly. You can override this function if necessary.
215
180
216
-
*`signal_reset_sequence_done`: This function shall be called once the reset
217
-
sequence is achieved. It cannot be overridden.
181
+
*`signal_reset_sequence_done`: Once the reset sequence is finished, you can call this function. You cannot override it.
218
182
219
183
###### Controller parameters to set
220
184
221
-
This instruct the controller which events are relevant for the stack.
185
+
This step tells the controller which events are relevant to the stack.
222
186
223
187
The following parameters should be set in the controller (if supported):
224
-
* event mask: The reset sequence should issue the call
225
-
`HciSetEventMaskCmd((uint8_t *) hciEventMask)`
226
-
* LE event mask: The call `HciLeSetEventMaskCmd((uint8_t *) hciLeEventMask)`
227
-
should be issued.
228
-
* 2nd page of events mask: Can be achieved by invoking
* LE event mask: Call `HciLeSetEventMaskCmd((uint8_t *) hciLeEventMask)`.
192
+
193
+
* 2nd page of events mask: Call `HciSetEventMaskPage2Cmd((uint8_t *) hciEventMaskPage2)`.
231
194
232
195
###### Stack runtime parameters
233
196
234
-
Some stack parameters shall be acquired at runtime from the controller:
235
-
236
-
* Bluetooth address: Can be queried with `HciReadBdAddrCmd`. Response shall be
237
-
copied into `hciCoreCb.bdAddr` with `BdaCpy`.
238
-
* Buffer size of the controller: Can be obtained by `HciLeReadBufSizeCmd`. The
239
-
return parameter *HC_ACL_Data_Packet_Length* shall be copied into
240
-
`hciCoreCb.bufSize` and the response parameter
241
-
`HC_Synchronous_Data_Packet_Length` shall be copied into `hciCoreCb.numBufs`.
242
-
The value of `hciCoreCb.availBufs` shall be initialized with `hciCoreCb.numBufs`.
243
-
* Supported state: Queried with `HciLeReadSupStatesCmd`, the response shall go
244
-
into `hciCoreCb.leStates`.
245
-
* Whitelist size: Queried with `HciLeReadWhiteListSizeCmd` the response shall go
246
-
into `hciCoreCb.whiteListSize`.
247
-
* LE features supported: Obtained with `HciLeReadLocalSupFeatCmd`. The response
248
-
shall be stored into `hciCoreCb.leSupFeat`.
249
-
* Resolving list size: Obtained with `hciCoreReadResolvingListSize`. The response
250
-
shall go into `hciCoreCb.resListSize`.
251
-
* Max data length: Acquired with `hciCoreReadMaxDataLen`. The response parameter
252
-
`supportedMaxTxOctets` and `supportedMaxTxTime` shall be pass to the function
253
-
`HciLeWriteDefDataLen`.
254
-
255
-
256
-
The default implementation is:
197
+
At runtime, you can get some stack parameters from the controller:
198
+
199
+
* Bluetooth address: Query this with `HciReadBdAddrCmd`. Copy the response into `hciCoreCb.bdAddr` with `BdaCpy`.
200
+
201
+
* Buffer size of the controller: Can be obtained by `HciLeReadBufSizeCmd`. The return parameter `HC_ACL_Data_Packet_Length` is copied to `hciCoreCb.bufSize`, and the response parameter `HC_Synchronous_Data_Packet_Length` shall be copied into `hciCoreCb.numBufs`. The value of `hciCoreCb.availBufs` shall be initialized with `hciCoreCb.numBufs`.
202
+
203
+
* Supported state: Query this with `HciLeReadSupStatesCmd`, and copy the response into `hciCoreCb.leStates`.
204
+
* Whitelist size: Query this with `HciLeReadWhiteListSizeCmd`, and copy the response into `hciCoreCb.whiteListSize`.
205
+
* LE features supported: Query this with `HciLeReadLocalSupFeatCmd`, and copy the response into `hciCoreCb.leSupFeat`.
206
+
* Resolving list size: Query this with `hciCoreReadResolvingListSize`, and copy the response into `hciCoreCb.resListSize`.
207
+
* Max data length: Query this with `hciCoreReadMaxDataLen`, and pass the response parameters `supportedMaxTxOctets` and `supportedMaxTxTime` to the function `HciLeWriteDefDataLen`:
The HCI driver is injected in the `CordioBLE` class at construction site.
466
-
Given that the CordioBLE class doesn't know what class shall be used to
467
-
construct the driver nor it knows how to construct it, the port shall provide a
468
-
function returning a reference to the HCI driver.
414
+
The HCI driver is injected to the `CordioBLE` class at manufacture.
415
+
416
+
Given that the CordioBLE class doesn't know what class constructs the driver nor how to construct it, the port provides a function returning a reference to the HCI driver.
469
417
470
-
This function lives in the global namespace and its signature is:
418
+
This function is in the global namespace, and you can call it with:
Greentea tests are bundled with the Cordio port of the BLE API so the transport driver works as expected as well as validate the Cordio stack initialization. You can run them with the following command:
442
+
We bundle Greentea tests with the Cordio port of the BLE API, so the transport driver works, as well as validation of Cordio stack initialization. You can run these tests with the following command:
495
443
496
444
```
497
445
mbed test -t <toolchain> -m <target> -n mbed-os-features-feature_ble-targets-target_cordio-tests-cordio_hci-driver,mbed-os-features-feature_ble-targets-target_cordio-tests-cordio_hci-transport
498
446
```
499
447
500
448
*`mbed-os-features-feature_ble-targets-target_cordio-tests-cordio_hci-transport`: Ensures that the transport is able to send an HCI reset command and receive the corresponding HCI status event.
501
-
*`mbed-os-features-feature_ble-targets-target_cordio-tests-cordio_hci-driver`: Runs the whole initialization process then ensure the Cordio stack has been properly initialized by the HCI driver.
449
+
*`mbed-os-features-feature_ble-targets-target_cordio-tests-cordio_hci-driver`: Runs the whole initialization process, then ensures the HCI driver has properly initialized the Cordio stack.
502
450
503
451
504
452
### Tools
505
453
506
-
The application [mbed-os-cordio-hci-passthrough](https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough)can be used to _proxify_ a Bluetooth controller connected to an Mbed board.
454
+
You can use the application [mbed-os-cordio-hci-passthrough](https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough) to proxify a Bluetooth controller connected to an Mbed board.
507
455
508
-
Bytes sent by the host over the board serial are forwarded to the controller with the help of the `HCITransportDriver` while bytes sent by the controller are sent back to the host through the board serial.
456
+
Bytes sent by the host over the board serial are forwarded to the controller with the help of the `HCITransportDriver`, while bytes sent by the controller are sent back to the host through the board serial.
509
457
510
458
This application can be used to validate the transport driver and debug the initialization process on a PC host.
0 commit comments