translate hci types

pull/10666/head
paul-szczepanek-arm 2019-03-08 15:15:31 +00:00 committed by Martin Kojtal
parent ccddf32f85
commit f13e966dc0
3 changed files with 69 additions and 30 deletions

View File

@ -17,17 +17,61 @@
#include "mbed.h" #include "mbed.h"
#include "fake_lhci_drv.h" #include "fake_lhci_drv.h"
#include "chci_tr.h" #include "chci_tr.h"
#include "chci_api.h"
#include "hci_defs.h"
#include "wsf_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
uint16_t FakeChciTrRead(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData) { uint16_t FakeChciTrRead(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData)
chciTrRecv(prot, type, pData); {
uint8_t controller_type;
switch (hci_type) {
case HCI_CMD_TYPE:
controller_type = CHCI_TR_TYPE_CMD;
break;
case HCI_ACL_TYPE:
controller_type = CHCI_TR_TYPE_DATA;
break;
case HCI_ISO_TYPE:
controller_type = CHCI_TR_TYPE_ISO;
break;
default:
/* should never happen */
WSF_ASSERT(false);
return 0;
break;
}
chciTrRecv(prot, controller_type, pData);
return len; return len;
} }
uint16_t FakeChciTrWrite(uint8_t prot, uint8_t controller_type, uint16_t len, uint8_t *pData)
{
uint8_t hci_type;
switch (controller_type) {
case CHCI_TR_TYPE_EVT:
hci_type = HCI_EVT_TYPE;
break;
case CHCI_TR_TYPE_DATA:
hci_type = HCI_ACL_TYPE;
break;
case CHCI_TR_TYPE_ISO:
hci_type = HCI_ISO_TYPE;
break;
default:
/* should never happen */
WSF_ASSERT(false);
return 0;
break;
}
return controllerToHostWrite(prot, hci_type, len, pData);
}
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif #endif

View File

@ -22,26 +22,37 @@ extern "C" {
#endif #endif
/** /**
* Send bytes from host to controller. * Provide this callback in your HCI driver.
* *
* @param prot Protocol, must be CHCI_TR_PROT_BLE. * @param prot Must be CHCI_TR_PROT_BLE.
* @param type HCI_ACL_TYPE or HCI_CMD_TYPE. * @param hci_type HCI type, HCI_ACL_TYPE or HCI_CMD_TYPE.
* @param len Buffer length. * @param len Buffer length.
* @param pData Data to be sent. * @param pData Data to be sent.
* @return Number of bytes processed. * @return Number of bytes processed.
*/ */
uint16_t FakeChciTrRead(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData); uint16_t controllerToHostWrite(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData);
/**
* Send bytes from host to controller.
*
* @param prot Protocol, must be CHCI_TR_PROT_BLE.
* @param type HCI type, HCI_ACL_TYPE or HCI_CMD_TYPE.
* @param len Buffer length.
* @param pData Data to be sent.
* @return Number of bytes processed.
*/
uint16_t FakeChciTrRead(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData);
/** /**
* Send bytes from controller to host. * Send bytes from controller to host.
* *
* @param prot Protocol, must be CHCI_TR_PROT_BLE. * @param prot Protocol, must be CHCI_TR_PROT_BLE.
* @param type HCI_ACL_TYPE or HCI_EVT_TYPE. * @param type Controller type, CHCI_TR_TYPE_DATA or CHCI_TR_TYPE_EVT.
* @param len Buffer length. * @param len Buffer length.
* @param pData Data to be sent. * @param pData Data to be sent.
* @return Number of bytes processed. * @return Number of bytes processed.
*/ */
uint16_t FakeChciTrWrite(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData); uint16_t FakeChciTrWrite(uint8_t prot, uint8_t controller_type, uint16_t len, uint8_t *pData);
#ifdef __cplusplus #ifdef __cplusplus
}; };

View File

@ -44,9 +44,9 @@ void NRFCordioHCITransportDriver::terminate()
} }
uint16_t NRFCordioHCITransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData) uint16_t NRFCordioHCITransportDriver::write(uint8_t hci_type, uint16_t len, uint8_t *pData)
{ {
return FakeChciTrRead(CHCI_TR_PROT_BLE, type, len, pData); return FakeChciTrRead(CHCI_TR_PROT_BLE, hci_type, len, pData);
} }
extern "C" void chciDrvInit(void) extern "C" void chciDrvInit(void)
@ -55,27 +55,11 @@ extern "C" void chciDrvInit(void)
} }
// Callback from Cordio stack // Callback from Cordio stack
extern "C" uint16_t FakeChciTrWrite(uint8_t prot, uint8_t type, uint16_t len, uint8_t *pData) extern "C" uint16_t controllerToHostWrite(uint8_t prot, uint8_t hci_type, uint16_t len, uint8_t *pData)
{ {
uint8_t ctype; WSF_ASSERT(prot == CHCI_TR_PROT_BLE);
switch (type) {
case CHCI_TR_TYPE_EVT:
ctype = HCI_EVT_TYPE;
break;
case CHCI_TR_TYPE_DATA:
ctype = HCI_ACL_TYPE;
break;
case CHCI_TR_TYPE_ISO:
ctype = HCI_ISO_TYPE;
break;
default:
/* should never happen */
WSF_ASSERT(false);
return 0;
break;
}
CordioHCITransportDriver::on_data_received(&ctype, 1); CordioHCITransportDriver::on_data_received(&hci_type, 1);
CordioHCITransportDriver::on_data_received(pData, len); CordioHCITransportDriver::on_data_received(pData, len);
return len; return len;