1 /******************************************************************************* 2 * \file cybt_platform_hci.h 3 * 4 * \brief 5 * Provides API to access BT HCI transport. 6 * 7 ******************************************************************************** 8 * \copyright 9 * Copyright 2018-2019 Cypress Semiconductor Corporation 10 * SPDX-License-Identifier: Apache-2.0 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 *******************************************************************************/ 24 25 #ifndef CYBT_PLATFORM_HCI_H 26 #define CYBT_PLATFORM_HCI_H 27 28 #include "cybt_result.h" 29 30 /****************************************************************************** 31 * Constants 32 ******************************************************************************/ 33 /* NRBA-TODO: Remove below macro once patch download is up */ 34 #define HCI_UART_DEFAULT_BAUDRATE (115200) /**< HCI UART default controller 35 * baudrate 36 */ 37 38 /***************************************************************************** 39 * Type Definitions 40 *****************************************************************************/ 41 /** 42 * HCI packet type 43 */ 44 typedef enum 45 { 46 HCI_PACKET_TYPE_IGNORE = 0x00, 47 HCI_PACKET_TYPE_COMMAND = 0x01, 48 HCI_PACKET_TYPE_ACL = 0x02, 49 HCI_PACKET_TYPE_SCO = 0x03, 50 HCI_PACKET_TYPE_EVENT = 0x04, 51 HCI_PACKET_TYPE_ISO = 0x05, 52 HCI_PACKET_TYPE_DIAG = 0x07, 53 HCI_PACKET_TYPE_LOOPBACK = 0xFF 54 } hci_packet_type_t; 55 56 /** 57 * HCI Event packet header 58 */ 59 typedef struct 60 { 61 uint8_t event_code; 62 uint8_t content_length; 63 } hci_event_packet_header_t; 64 65 /** 66 * HCI ACL packet header 67 */ 68 typedef struct 69 { 70 uint16_t hci_handle; 71 uint16_t content_length; 72 } hci_acl_packet_header_t; 73 74 /** 75 * HCI SCO packet header 76 */ 77 typedef struct 78 { 79 uint16_t hci_handle; 80 uint8_t content_length; 81 } hci_sco_packet_header_t; 82 83 /** 84 * HCI Loopback packet header 85 */ 86 typedef struct 87 { 88 uint8_t content_length; 89 } hci_loopback_packet_header_t; 90 91 92 #ifdef __cplusplus 93 extern "C" 94 { 95 #endif 96 97 /***************************************************************************** 98 * Function Declarations 99 ****************************************************************************/ 100 101 /** 102 * Initialize and open HCI transport. 103 * @param[in] p_arg: Pointer to an argument if any 104 * @return the status of open operation 105 */ 106 cybt_result_t cybt_platform_hci_open(void *p_arg); 107 108 109 /** 110 * Get RX fifo count for HCI transport 111 * 112 * 113 * @returns Packet count available in RX fifo. 114 */ 115 uint16_t cybt_platfrom_hci_get_rx_fifo_count(void); 116 117 118 /** 119 * Write data to HCI transport. 120 * 121 * Note: This fuction shall be returned only when all data was written done. 122 * 123 * @param[in] pti : HCI packet type indicator 124 * @param[in] p_data: the pointer of the data to be written 125 * @param[in] lenght: the length of the data to be written 126 * 127 * @returns the status of write operation 128 */ 129 cybt_result_t cybt_platform_hci_write(hci_packet_type_t pti, 130 uint8_t *p_data, 131 uint32_t length 132 ); 133 134 135 /** 136 * Read data from HCI transpot. 137 * 138 * @param[in] pti : HCI packet type indicator 139 * @param[in] p_data: the pointer of received buffer 140 * @param[in/out] p_length: The pointer of requested/actual length. 141 * The request read length shall be specified 142 * through this parameter. The actual read length 143 * shall be provided in the same parameter, 144 * along with function return. 145 * 146 * @returns the status of read operation 147 */ 148 cybt_result_t cybt_platform_hci_read(void *event, hci_packet_type_t *pti, 149 uint8_t *p_data, 150 uint32_t *p_length 151 ); 152 153 154 /** 155 * Close HCI transport. 156 * 157 * @returns the status of close operation 158 */ 159 cybt_result_t cybt_platform_hci_close(void); 160 161 162 /** 163 * Set the new baudrate of HCI UART trasnport. 164 * 165 * @param[in] baudrate: the requested baudrate 166 * 167 * @returns the status of set baudrate operation 168 * @note : This function acts as dummy if HCI communication is using IPC instead UART 169 */ 170 cybt_result_t cybt_platform_hci_set_baudrate(uint32_t baudrate); 171 172 #ifdef __cplusplus 173 } /* extern "C" */ 174 #endif 175 176 #endif 177 178