1 /*
2 * Copyright (c) 2019 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <drivers/ipm.h>
8
9 #include <ipc/rpmsg_service.h>
10
11 #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
12 #define LOG_MODULE_NAME bt_hci_driver_nrf53
13 #include "common/log.h"
14
15 void bt_rpmsg_rx(uint8_t *data, size_t len);
16
17 static K_SEM_DEFINE(ready_sem, 0, 1);
18 static K_SEM_DEFINE(rx_sem, 0, 1);
19
20 BUILD_ASSERT(CONFIG_HEAP_MEM_POOL_SIZE >= 1024,
21 "Not enough heap memory for RPMsg queue allocation");
22
23 static int endpoint_id;
24
endpoint_cb(struct rpmsg_endpoint * ept,void * data,size_t len,uint32_t src,void * priv)25 static int endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len,
26 uint32_t src, void *priv)
27 {
28 BT_DBG("Received message of %u bytes.", len);
29 BT_HEXDUMP_DBG((uint8_t *)data, len, "Data:");
30
31 bt_rpmsg_rx(data, len);
32
33 return RPMSG_SUCCESS;
34 }
35
bt_rpmsg_platform_init(void)36 int bt_rpmsg_platform_init(void)
37 {
38 int err;
39
40 err = rpmsg_service_register_endpoint("nrf_bt_hci", endpoint_cb);
41
42 if (err < 0) {
43 LOG_ERR("Registering endpoint failed with %d", err);
44 return RPMSG_ERR_INIT;
45 }
46
47 endpoint_id = err;
48
49 return RPMSG_SUCCESS;
50 }
51
bt_rpmsg_platform_send(struct net_buf * buf)52 int bt_rpmsg_platform_send(struct net_buf *buf)
53 {
54 return rpmsg_service_send(endpoint_id, buf->data, buf->len);
55 }
56
bt_rpmsg_platform_endpoint_is_bound(void)57 int bt_rpmsg_platform_endpoint_is_bound(void)
58 {
59 return rpmsg_service_endpoint_is_bound(endpoint_id);
60 }
61