Skip to content

Commit f13e966

Browse files
paul-szczepanek-arm0xc0170
authored andcommitted
translate hci types
1 parent ccddf32 commit f13e966

File tree

3 files changed

+67
-28
lines changed

3 files changed

+67
-28
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO_LL/stack_adaptation/fake_lhci_drv.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,61 @@
1717
#include "mbed.h"
1818
#include "fake_lhci_drv.h"
1919
#include "chci_tr.h"
20+
#include "chci_api.h"
21+
#include "hci_defs.h"
22+
#include "wsf_assert.h"
2023

2124
#ifdef __cplusplus
2225
extern "C" {
2326
#endif
2427

25-
uint16_t FakeChciTrRead(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData) {
26-
chciTrRecv(prot, type, pData);
28+
uint16_t FakeChciTrRead(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData)
29+
{
30+
uint8_t controller_type;
31+
switch (hci_type) {
32+
case HCI_CMD_TYPE:
33+
controller_type = CHCI_TR_TYPE_CMD;
34+
break;
35+
case HCI_ACL_TYPE:
36+
controller_type = CHCI_TR_TYPE_DATA;
37+
break;
38+
case HCI_ISO_TYPE:
39+
controller_type = CHCI_TR_TYPE_ISO;
40+
break;
41+
default:
42+
/* should never happen */
43+
WSF_ASSERT(false);
44+
return 0;
45+
break;
46+
}
47+
48+
chciTrRecv(prot, controller_type, pData);
2749
return len;
2850
}
2951

52+
uint16_t FakeChciTrWrite(uint8_t prot, uint8_t controller_type, uint16_t len, uint8_t *pData)
53+
{
54+
uint8_t hci_type;
55+
switch (controller_type) {
56+
case CHCI_TR_TYPE_EVT:
57+
hci_type = HCI_EVT_TYPE;
58+
break;
59+
case CHCI_TR_TYPE_DATA:
60+
hci_type = HCI_ACL_TYPE;
61+
break;
62+
case CHCI_TR_TYPE_ISO:
63+
hci_type = HCI_ISO_TYPE;
64+
break;
65+
default:
66+
/* should never happen */
67+
WSF_ASSERT(false);
68+
return 0;
69+
break;
70+
}
71+
72+
return controllerToHostWrite(prot, hci_type, len, pData);
73+
}
74+
3075
#ifdef __cplusplus
3176
};
3277
#endif
33-

features/FEATURE_BLE/targets/TARGET_CORDIO_LL/stack_adaptation/fake_lhci_drv.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,38 @@
2121
extern "C" {
2222
#endif
2323

24+
/**
25+
* Provide this callback in your HCI driver.
26+
*
27+
* @param prot Must be CHCI_TR_PROT_BLE.
28+
* @param hci_type HCI type, HCI_ACL_TYPE or HCI_CMD_TYPE.
29+
* @param len Buffer length.
30+
* @param pData Data to be sent.
31+
* @return Number of bytes processed.
32+
*/
33+
uint16_t controllerToHostWrite(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData);
34+
2435
/**
2536
* Send bytes from host to controller.
2637
*
2738
* @param prot Protocol, must be CHCI_TR_PROT_BLE.
28-
* @param type HCI_ACL_TYPE or HCI_CMD_TYPE.
39+
* @param type HCI type, HCI_ACL_TYPE or HCI_CMD_TYPE.
2940
* @param len Buffer length.
3041
* @param pData Data to be sent.
3142
* @return Number of bytes processed.
3243
*/
33-
uint16_t FakeChciTrRead(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData);
44+
uint16_t FakeChciTrRead(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData);
3445

3546
/**
3647
* Send bytes from controller to host.
3748
*
3849
* @param prot Protocol, must be CHCI_TR_PROT_BLE.
39-
* @param type HCI_ACL_TYPE or HCI_EVT_TYPE.
50+
* @param type Controller type, CHCI_TR_TYPE_DATA or CHCI_TR_TYPE_EVT.
4051
* @param len Buffer length.
4152
* @param pData Data to be sent.
4253
* @return Number of bytes processed.
4354
*/
44-
uint16_t FakeChciTrWrite(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData);
55+
uint16_t FakeChciTrWrite(uint8_t prot, uint8_t controller_type, uint16_t len, uint8_t *pData);
4556

4657
#ifdef __cplusplus
4758
};

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ void NRFCordioHCITransportDriver::terminate()
4444

4545
}
4646

47-
uint16_t NRFCordioHCITransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
47+
uint16_t NRFCordioHCITransportDriver::write(uint8_t hci_type, uint16_t len, uint8_t *pData)
4848
{
49-
return FakeChciTrRead(CHCI_TR_PROT_BLE, type, len, pData);
49+
return FakeChciTrRead(CHCI_TR_PROT_BLE, hci_type, len, pData);
5050
}
5151

5252
extern "C" void chciDrvInit(void)
@@ -55,27 +55,11 @@ extern "C" void chciDrvInit(void)
5555
}
5656

5757
// Callback from Cordio stack
58-
extern "C" uint16_t FakeChciTrWrite(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData)
58+
extern "C" uint16_t controllerToHostWrite(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData)
5959
{
60-
uint8_t ctype;
61-
switch (type) {
62-
case CHCI_TR_TYPE_EVT:
63-
ctype = HCI_EVT_TYPE;
64-
break;
65-
case CHCI_TR_TYPE_DATA:
66-
ctype = HCI_ACL_TYPE;
67-
break;
68-
case CHCI_TR_TYPE_ISO:
69-
ctype = HCI_ISO_TYPE;
70-
break;
71-
default:
72-
/* should never happen */
73-
WSF_ASSERT(false);
74-
return 0;
75-
break;
76-
}
60+
WSF_ASSERT(prot == CHCI_TR_PROT_BLE);
7761

78-
CordioHCITransportDriver::on_data_received(&ctype, 1);
62+
CordioHCITransportDriver::on_data_received(&hci_type, 1);
7963
CordioHCITransportDriver::on_data_received(pData, len);
8064

8165
return len;

0 commit comments

Comments
 (0)