mirror of https://github.com/ARMmbed/mbed-os.git
Added BLE support based on CORDIO stack.
parent
d37026d063
commit
f906aac096
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2017-2017 ARM Limited
|
||||
* Copyright (c) 2017-2018 Future Electronics
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hci_api.h"
|
||||
#include "bstream.h"
|
||||
#include "driver/CordioHCIDriver.h"
|
||||
#include "drivers/IPCPipeTransportDriver.h"
|
||||
#include "psoc6_utils.h"
|
||||
|
||||
using namespace ble::vendor::cordio;
|
||||
using namespace ble::vendor::cypress;
|
||||
|
||||
const uint16_t HCI_VEND_SET_BD_ADDR = 0xfda0;
|
||||
const uint8_t HCI_VEND_SET_BD_ADDR_LEN = 7; /* MAC address + address type */
|
||||
|
||||
class Psoc6HCIDriver : public CordioHCIDriver
|
||||
{
|
||||
public:
|
||||
Psoc6HCIDriver(IPCPipeTransportDriver& transport_driver) :
|
||||
CordioHCIDriver(transport_driver)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
struct BdAddress {
|
||||
uint8_t mac_address[6];
|
||||
uint8_t addr_type;
|
||||
|
||||
BdAddress() : addr_type(0) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the chip.
|
||||
* The transport is up at that time.
|
||||
*/
|
||||
virtual void do_initialize();
|
||||
|
||||
/**
|
||||
* Terminate the driver
|
||||
*/
|
||||
virtual void do_terminate() {}
|
||||
|
||||
virtual void handle_reset_sequence(uint8_t *pMsg);
|
||||
|
||||
private:
|
||||
BdAddress bd_address;
|
||||
};
|
||||
|
||||
|
||||
void Psoc6HCIDriver::do_initialize()
|
||||
{
|
||||
cy_get_bd_mac_address(bd_address.mac_address);
|
||||
}
|
||||
|
||||
|
||||
void Psoc6HCIDriver::handle_reset_sequence(uint8_t *pMsg) {
|
||||
|
||||
uint16_t opcode;
|
||||
|
||||
/* if event is a command complete event */
|
||||
if (*pMsg == HCI_CMD_CMPL_EVT) {
|
||||
/* parse parameters */
|
||||
uint8_t *pMsg2 = pMsg + HCI_EVT_HDR_LEN;
|
||||
pMsg2++; /* skip num packets */
|
||||
BSTREAM_TO_UINT16(opcode, pMsg2);
|
||||
pMsg2 -= 2;
|
||||
/* decode opcode */
|
||||
switch (opcode) {
|
||||
case HCI_OPCODE_RESET:
|
||||
/* send next command in sequence */
|
||||
HciVendorSpecificCmd(HCI_VEND_SET_BD_ADDR,
|
||||
HCI_VEND_SET_BD_ADDR_LEN,
|
||||
reinterpret_cast<uint8_t*>(&bd_address));
|
||||
break;
|
||||
|
||||
case HCI_VEND_SET_BD_ADDR:
|
||||
/* pretend we have just completed reset */
|
||||
UINT16_TO_BSTREAM(pMsg2, HCI_OPCODE_RESET);
|
||||
CordioHCIDriver::handle_reset_sequence(pMsg);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* pass to parent */
|
||||
CordioHCIDriver::handle_reset_sequence(pMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CordioHCIDriver& ble_cordio_get_hci_driver() {
|
||||
static IPCPipeTransportDriver transport_driver;
|
||||
|
||||
static Psoc6HCIDriver hci_driver(
|
||||
transport_driver /* other hci driver parameters */
|
||||
);
|
||||
|
||||
return hci_driver;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2017-2017 ARM Limited
|
||||
* Copyright (c) 2017-2018 Future Electronics
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "IPCPipeTransportDriver.h"
|
||||
#include "ipcpipe_transport.h"
|
||||
#include "mbed_assert.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
namespace ble {
|
||||
namespace vendor {
|
||||
namespace cypress {
|
||||
|
||||
|
||||
void dump_buffer(uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
|
||||
while (len > 0) {
|
||||
printf(" %02x", *buffer++);
|
||||
--len;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void ipc_h4_receive(uint32_t *ptr)
|
||||
{
|
||||
IpcPipeMessage *message = (IpcPipeMessage *)ptr;
|
||||
|
||||
// We don't expect header to be received from M0+ core.
|
||||
MBED_ASSERT(message->header_length == 0);
|
||||
|
||||
// printf("BLE received: ");
|
||||
// h4_dump_buffer(buffer->message.data, buffer->message.length);
|
||||
cordio::CordioHCITransportDriver::on_data_received(message->data, message->data_length);
|
||||
}
|
||||
|
||||
IPCPipeTransportDriver::IPCPipeTransportDriver()
|
||||
{ }
|
||||
|
||||
void IPCPipeTransportDriver::initialize()
|
||||
{
|
||||
// printf("H4 Transport driver initialization.\n");
|
||||
ipcpipe_transport_start(IPCPIPE_CLIENT_H4, ipc_h4_receive, NULL);
|
||||
}
|
||||
|
||||
void IPCPipeTransportDriver::terminate()
|
||||
{
|
||||
ipcpipe_transport_stop(IPCPIPE_CLIENT_H4);
|
||||
}
|
||||
|
||||
uint16_t IPCPipeTransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
|
||||
{
|
||||
// printf("BLE sending T<%02x>:", type);
|
||||
// dump_buffer(pData, len);
|
||||
ipcpipe_write_data(IPCPIPE_CLIENT_H4, &type, 1, pData, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
} // namespace cypress
|
||||
} // namespace vendor
|
||||
} // namespace ble
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2017-2017 ARM Limited
|
||||
* Copyright (c) 2017-2018 Future Electronics
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PSOC6_IPCPIPE_TRANSPORT_DRIVER_H_
|
||||
#define PSOC6_IPCPIPE_TRANSPORT_DRIVER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mbed.h"
|
||||
#include "CordioHCITransportDriver.h"
|
||||
|
||||
|
||||
namespace ble {
|
||||
namespace vendor {
|
||||
namespace cypress {
|
||||
|
||||
using namespace ble::vendor;
|
||||
|
||||
/**
|
||||
* Implementation of the H4 driver over PSoC6 IPC pipe.
|
||||
*/
|
||||
class IPCPipeTransportDriver : public cordio::CordioHCITransportDriver {
|
||||
public:
|
||||
/**
|
||||
* Initialize the transport driver.
|
||||
*
|
||||
*/
|
||||
IPCPipeTransportDriver();
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~IPCPipeTransportDriver() { }
|
||||
|
||||
/**
|
||||
* @see CordioHCITransportDriver::initialize
|
||||
*/
|
||||
virtual void initialize();
|
||||
|
||||
/**
|
||||
* @see CordioHCITransportDriver::terminate
|
||||
*/
|
||||
virtual void terminate();
|
||||
|
||||
/**
|
||||
* @see CordioHCITransportDriver::write
|
||||
*/
|
||||
virtual uint16_t write(uint8_t type, uint16_t len, uint8_t *pData);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace cypress
|
||||
} // namespace vendor
|
||||
} // namespace ble
|
||||
|
||||
#endif /* PSOC6_IPCPIPE_TRANSPORT_DRIVER_H_ */
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue