@@ -32,108 +32,101 @@ namespace vendor {
32
32
namespace odin_w2 {
33
33
34
34
class HCIDriver : public cordio ::CordioHCIDriver {
35
+ public:
36
+ HCIDriver (cordio::CordioHCITransportDriver &transport_driver, PinName shutdown_name, PinName hci_rts_name) :
37
+ cordio::CordioHCIDriver (transport_driver),
38
+ shutdown (shutdown_name, 0 ),
39
+ hci_rts (hci_rts_name, 0 ),
40
+ service_pack_index (0 ),
41
+ service_pack_transfered (false ) {
42
+ };
35
43
36
- public:
37
- HCIDriver (cordio::CordioHCITransportDriver& transport_driver, PinName shutdown_name, PinName hci_rts_name) :
38
- cordio::CordioHCIDriver (transport_driver),
39
- shutdown (shutdown_name, 0 ),
40
- hci_rts (hci_rts_name, 0 ),
41
- service_pack_index (0 ),
42
- service_pack_transfered (false ) {
43
- };
44
+ virtual void do_initialize ();
44
45
45
- virtual void do_initialize ();
46
+ virtual void do_terminate ();
46
47
47
- virtual void do_terminate ();
48
+ virtual void start_reset_sequence ();
48
49
49
- virtual void start_reset_sequence ( );
50
+ virtual void handle_reset_sequence ( uint8_t *pMsg );
50
51
51
- virtual void handle_reset_sequence (uint8_t *pMsg);
52
+ private:
53
+ void start_service_pack_transfert (void )
54
+ {
55
+ service_pack_index = 0 ;
56
+ service_pack_transfered = false ;
57
+ send_service_pack_command ();
58
+ }
52
59
53
- private:
54
- void start_service_pack_transfert (void ) {
55
- service_pack_index = 0 ;
56
- service_pack_transfered = false ;
57
- send_service_pack_command ();
60
+ void send_service_pack_command (void )
61
+ {
62
+ uint16_t cmd_len = odin_service_pack[service_pack_index + HCI_CMD_HDR_LEN];
63
+ cmd_opcode_ack_expected = (odin_service_pack[service_pack_index + 2 ] << 8 ) | odin_service_pack[service_pack_index + 1 ];
64
+ uint8_t *pBuf = hciCmdAlloc (cmd_opcode_ack_expected, cmd_len);
65
+ if (pBuf) {
66
+ memcpy (pBuf, odin_service_pack + service_pack_index + 1 , cmd_len + HCI_CMD_HDR_LEN);
67
+ hciCmdSend (pBuf);
68
+ } else {
69
+ printf (" Error cannot allocate memory for the buffer" );
58
70
}
71
+ }
59
72
60
- void send_service_pack_command (void ) {
61
- uint16_t cmd_len = OdinServicePack[service_pack_index + HCI_CMD_HDR_LEN];
62
- cmd_opcode_ack_expected = (OdinServicePack[service_pack_index + 2 ] << 8 ) | OdinServicePack[service_pack_index + 1 ];
63
- uint8_t *pBuf = hciCmdAlloc (cmd_opcode_ack_expected, cmd_len);
64
- if (pBuf) {
65
- memcpy (pBuf, OdinServicePack + service_pack_index + 1 , cmd_len + HCI_CMD_HDR_LEN);
66
- hciCmdSend (pBuf);
67
- }
68
- else {
69
- printf (" Error cannot allocate memory for the buffer" );
70
- }
71
- }
73
+ void ack_service_pack_command (uint16_t opcode, uint8_t *msg)
74
+ {
75
+ /* check if response opcode is same as expected command opcode */
76
+ MBED_ASSERT (cmd_opcode_ack_expected == opcode);
72
77
73
- void ack_service_pack_command (uint16_t opcode, uint8_t * msg) {
74
- /* check if response opcode is same as expected command opcode */
75
- MBED_ASSERT (cmd_opcode_ack_expected == opcode);
76
-
77
- // update service pack index
78
- service_pack_index += (1 + HCI_CMD_HDR_LEN + OdinServicePack[service_pack_index + HCI_CMD_HDR_LEN]);
79
-
80
- if (service_pack_index < service_pack_size) {
81
- send_service_pack_command ();
82
- }
83
- else if (opcode == HCID_VS_WRITE_BD_ADDR) {
84
- /* send an HCI Reset command to start the sequence */
85
- HciResetCmd ();
86
- service_pack_transfered = true ;
87
- }
88
- else {
89
- /* send BT device hardware address write command */
90
- send_hci_vs_cmd (HCID_VS_WRITE_BD_ADDR);
91
- cmd_opcode_ack_expected = HCID_VS_WRITE_BD_ADDR;
92
- }
93
- }
78
+ // update service pack index
79
+ service_pack_index += (1 + HCI_CMD_HDR_LEN + odin_service_pack[service_pack_index + HCI_CMD_HDR_LEN]);
94
80
95
- void hciCoreReadResolvingListSize ( void )
96
- {
97
- /* if LL Privacy is supported by Controller and included */
98
- if ((hciCoreCb. leSupFeat & HCI_LE_SUP_FEAT_PRIVACY) &&
99
- (hciLeSupFeatCfg & HCI_LE_SUP_FEAT_PRIVACY))
100
- {
101
- /* send next command in sequence */
102
- HciLeReadResolvingListSize ();
103
- }
104
- else
105
- {
106
- hciCoreCb. resListSize = 0 ;
81
+ if (service_pack_index < service_pack_size )
82
+ send_service_pack_command ();
83
+ else if (opcode == HCID_VS_WRITE_BD_ADDR) {
84
+ /* send an HCI Reset command to start the sequence */
85
+ HciResetCmd ();
86
+ service_pack_transfered = true ;
87
+ } else {
88
+ /* send BT device hardware address write command */
89
+ send_hci_vs_cmd (HCID_VS_WRITE_BD_ADDR);
90
+ cmd_opcode_ack_expected = HCID_VS_WRITE_BD_ADDR;
91
+ }
92
+ }
107
93
108
- /* send next command in sequence */
109
- hciCoreReadMaxDataLen ();
110
- }
94
+ void hci_read_resolving_list_size (void )
95
+ {
96
+ /* if LL Privacy is supported by Controller and included */
97
+ if ((hciCoreCb.leSupFeat & HCI_LE_SUP_FEAT_PRIVACY) &&
98
+ (hciLeSupFeatCfg & HCI_LE_SUP_FEAT_PRIVACY)) {
99
+ /* send next command in sequence */
100
+ HciLeReadResolvingListSize ();
101
+ } else {
102
+ hciCoreCb.resListSize = 0 ;
103
+
104
+ /* send next command in sequence */
105
+ hci_read_max_data_len ();
111
106
}
107
+ }
112
108
113
- void hciCoreReadMaxDataLen (void )
114
- {
115
- /* if LE Data Packet Length Extensions is supported by Controller and included */
116
- if ((hciCoreCb.leSupFeat & HCI_LE_SUP_FEAT_DATA_LEN_EXT) &&
117
- (hciLeSupFeatCfg & HCI_LE_SUP_FEAT_DATA_LEN_EXT))
118
- {
119
- /* send next command in sequence */
120
- HciLeReadMaxDataLen ();
121
- }
122
- else
123
- {
124
- /* send next command in sequence */
125
- HciLeRandCmd ();
126
- }
109
+ void hci_read_max_data_len (void )
110
+ {
111
+ /* if LE Data Packet Length Extensions is supported by Controller and included */
112
+ if ((hciCoreCb.leSupFeat & HCI_LE_SUP_FEAT_DATA_LEN_EXT) &&
113
+ (hciLeSupFeatCfg & HCI_LE_SUP_FEAT_DATA_LEN_EXT)) {
114
+ /* send next command in sequence */
115
+ HciLeReadMaxDataLen ();
116
+ } else {
117
+ /* send next command in sequence */
118
+ HciLeRandCmd ();
127
119
}
120
+ }
128
121
129
- DigitalOut shutdown; // power/shutdown pin for bt device
130
- DigitalOut hci_rts; // request to sent pin
131
- size_t service_pack_index; // Index of command to be recently sent over hci
132
- bool service_pack_transfered; // Flag to notify if service pack is completely transferred or not
133
- uint16_t cmd_opcode_ack_expected; // Command against which acknowledgment is expected
134
- uint32_t service_pack_size; // size of service pack
135
- char * OdinServicePack ;
136
- vs_cmd_send_t send_hci_vs_cmd ;
122
+ DigitalOut shutdown; // power/shutdown pin for bt device
123
+ DigitalOut hci_rts; // request to sent pin
124
+ size_t service_pack_index; // Index of command to be recently sent over hci
125
+ bool service_pack_transfered; // Flag to notify if service pack is completely transferred or not
126
+ uint16_t cmd_opcode_ack_expected; // Command against which acknowledgment is expected
127
+ uint32_t service_pack_size; // size of service pack
128
+ char *odin_service_pack ; // Service pack needs to be provided by driver
129
+ vs_cmd_send_t send_hci_vs_cmd ; // callback function to call vendor specific call handler
137
130
138
131
};
139
132
@@ -157,7 +150,7 @@ void ble::vendor::odin_w2::HCIDriver::do_initialize()
157
150
/* ODIN ble driver initialization function */
158
151
cbCordio_Btinit (&callback);
159
152
160
- OdinServicePack = callback.Service_pack ;
153
+ odin_service_pack = callback.Service_pack ;
161
154
send_hci_vs_cmd = callback.vs_command_callback ;
162
155
service_pack_size = callback.service_pack_size ;
163
156
}
@@ -180,16 +173,14 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
180
173
static uint8_t randCnt;
181
174
182
175
/* if event is a command complete event */
183
- if (*pMsg == HCI_CMD_CMPL_EVT)
184
- {
176
+ if (*pMsg == HCI_CMD_CMPL_EVT) {
185
177
/* parse parameters */
186
178
pMsg += HCI_EVT_HDR_LEN;
187
179
pMsg++; /* skip num packets */
188
180
BSTREAM_TO_UINT16 (opcode, pMsg);
189
181
pMsg++; /* skip status */
190
182
191
- if (opcode == HCID_VS_UPDATE_UART_BAUD_RATE)
192
- {
183
+ if (opcode == HCID_VS_UPDATE_UART_BAUD_RATE) {
193
184
update_uart_baud_rate ();
194
185
start_service_pack_transfert ();
195
186
return ;
@@ -282,19 +273,18 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
282
273
BSTREAM_TO_UINT16 (hciCoreCb.leSupFeat , pMsg);
283
274
284
275
/* send next command in sequence */
285
- hciCoreReadResolvingListSize ();
276
+ hci_read_resolving_list_size ();
286
277
break ;
287
278
288
279
case HCI_OPCODE_LE_READ_RES_LIST_SIZE:
289
280
/* parse and store event parameters */
290
281
BSTREAM_TO_UINT8 (hciCoreCb.resListSize , pMsg);
291
282
292
283
/* send next command in sequence */
293
- hciCoreReadMaxDataLen ();
284
+ hci_read_max_data_len ();
294
285
break ;
295
286
296
287
case HCI_OPCODE_LE_READ_MAX_DATA_LEN:
297
- {
298
288
uint16_t maxTxOctets;
299
289
uint16_t maxTxTime;
300
290
@@ -306,17 +296,13 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
306
296
* of payload octets and maximum packet transmission time for new connections.
307
297
*/
308
298
HciLeWriteDefDataLen (maxTxOctets, maxTxTime);
309
- }
310
- break ;
299
+ break ;
311
300
312
301
case HCI_OPCODE_LE_WRITE_DEF_DATA_LEN:
313
- if (hciCoreCb.extResetSeq )
314
- {
302
+ if (hciCoreCb.extResetSeq ) {
315
303
/* send first extended command */
316
304
(*hciCoreCb.extResetSeq )(pMsg, opcode);
317
- }
318
- else
319
- {
305
+ } else {
320
306
/* initialize extended parameters */
321
307
hciCoreCb.maxAdvDataLen = 0 ;
322
308
hciCoreCb.numSupAdvSets = 0 ;
@@ -330,22 +316,18 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
330
316
case HCI_OPCODE_LE_READ_MAX_ADV_DATA_LEN:
331
317
case HCI_OPCODE_LE_READ_NUM_SUP_ADV_SETS:
332
318
case HCI_OPCODE_LE_READ_PER_ADV_LIST_SIZE:
333
- if (hciCoreCb.extResetSeq )
334
- {
319
+ if (hciCoreCb.extResetSeq ) {
335
320
/* send next extended command in sequence */
336
321
(*hciCoreCb.extResetSeq )(pMsg, opcode);
337
322
}
338
323
break ;
339
324
340
325
case HCI_OPCODE_LE_RAND:
341
326
/* check if need to send second rand command */
342
- if (randCnt < (HCI_RESET_RAND_CNT - 1 ))
343
- {
327
+ if (randCnt < (HCI_RESET_RAND_CNT - 1 )) {
344
328
randCnt++;
345
329
HciLeRandCmd ();
346
- }
347
- else
348
- {
330
+ } else {
349
331
signal_reset_sequence_done ();
350
332
}
351
333
break ;
0 commit comments