Skip to content

Commit c539656

Browse files
committed
update with ARM coding standard
1 parent 2ac6cff commit c539656

File tree

2 files changed

+91
-110
lines changed

2 files changed

+91
-110
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp

Lines changed: 91 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -32,108 +32,101 @@ namespace vendor {
3232
namespace odin_w2 {
3333

3434
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+
};
3543

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();
4445

45-
virtual void do_initialize();
46+
virtual void do_terminate();
4647

47-
virtual void do_terminate();
48+
virtual void start_reset_sequence();
4849

49-
virtual void start_reset_sequence();
50+
virtual void handle_reset_sequence(uint8_t *pMsg);
5051

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+
}
5259

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");
5870
}
71+
}
5972

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);
7277

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]);
9480

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+
}
10793

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();
111106
}
107+
}
112108

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();
127119
}
120+
}
128121

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
137130

138131
};
139132

@@ -157,7 +150,7 @@ void ble::vendor::odin_w2::HCIDriver::do_initialize()
157150
/* ODIN ble driver initialization function */
158151
cbCordio_Btinit(&callback);
159152

160-
OdinServicePack = callback.Service_pack;
153+
odin_service_pack = callback.Service_pack;
161154
send_hci_vs_cmd = callback.vs_command_callback;
162155
service_pack_size = callback.service_pack_size;
163156
}
@@ -180,16 +173,14 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
180173
static uint8_t randCnt;
181174

182175
/* if event is a command complete event */
183-
if (*pMsg == HCI_CMD_CMPL_EVT)
184-
{
176+
if (*pMsg == HCI_CMD_CMPL_EVT) {
185177
/* parse parameters */
186178
pMsg += HCI_EVT_HDR_LEN;
187179
pMsg++; /* skip num packets */
188180
BSTREAM_TO_UINT16(opcode, pMsg);
189181
pMsg++; /* skip status */
190182

191-
if (opcode == HCID_VS_UPDATE_UART_BAUD_RATE)
192-
{
183+
if (opcode == HCID_VS_UPDATE_UART_BAUD_RATE) {
193184
update_uart_baud_rate();
194185
start_service_pack_transfert();
195186
return;
@@ -282,19 +273,18 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
282273
BSTREAM_TO_UINT16(hciCoreCb.leSupFeat, pMsg);
283274

284275
/* send next command in sequence */
285-
hciCoreReadResolvingListSize();
276+
hci_read_resolving_list_size();
286277
break;
287278

288279
case HCI_OPCODE_LE_READ_RES_LIST_SIZE:
289280
/* parse and store event parameters */
290281
BSTREAM_TO_UINT8(hciCoreCb.resListSize, pMsg);
291282

292283
/* send next command in sequence */
293-
hciCoreReadMaxDataLen();
284+
hci_read_max_data_len();
294285
break;
295286

296287
case HCI_OPCODE_LE_READ_MAX_DATA_LEN:
297-
{
298288
uint16_t maxTxOctets;
299289
uint16_t maxTxTime;
300290

@@ -306,17 +296,13 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
306296
* of payload octets and maximum packet transmission time for new connections.
307297
*/
308298
HciLeWriteDefDataLen(maxTxOctets, maxTxTime);
309-
}
310-
break;
299+
break;
311300

312301
case HCI_OPCODE_LE_WRITE_DEF_DATA_LEN:
313-
if (hciCoreCb.extResetSeq)
314-
{
302+
if (hciCoreCb.extResetSeq) {
315303
/* send first extended command */
316304
(*hciCoreCb.extResetSeq)(pMsg, opcode);
317-
}
318-
else
319-
{
305+
} else {
320306
/* initialize extended parameters */
321307
hciCoreCb.maxAdvDataLen = 0;
322308
hciCoreCb.numSupAdvSets = 0;
@@ -330,22 +316,18 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
330316
case HCI_OPCODE_LE_READ_MAX_ADV_DATA_LEN:
331317
case HCI_OPCODE_LE_READ_NUM_SUP_ADV_SETS:
332318
case HCI_OPCODE_LE_READ_PER_ADV_LIST_SIZE:
333-
if (hciCoreCb.extResetSeq)
334-
{
319+
if (hciCoreCb.extResetSeq) {
335320
/* send next extended command in sequence */
336321
(*hciCoreCb.extResetSeq)(pMsg, opcode);
337322
}
338323
break;
339324

340325
case HCI_OPCODE_LE_RAND:
341326
/* 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)) {
344328
randCnt++;
345329
HciLeRandCmd();
346-
}
347-
else
348-
{
330+
} else {
349331
signal_reset_sequence_done();
350332
}
351333
break;

features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/OdinCordioInterface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define ODIN_CORDIO_INTF_H
1919

2020
#include <stdio.h>
21-
#include "mbed.h"
2221
#include "cb_main.h"
2322

2423
/*------------------------------------------------------------------------------

0 commit comments

Comments
 (0)