1 /*******************************************************************************
2 * \file cybt_debug_uart.h
3 
4 *
5 * \brief
6 * Provides API to access Debug transport.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2018-2019 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *     http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 #include "cybt_result.h"
26 #include "wiced_bt_dev.h"
27 /**
28  *  @addtogroup    debug_uart_cfg   Debug UART Configuration
29  *
30  * The BLESS UART-specific configurations, including hardware pin assignment.
31  * This debug UART is used for communication between the PSOC and host connected via USB cable.
32  *  @{
33  */
34 
35 
36 /**
37  * Received data handler callback type
38  *
39  * @param[in] p_data   : received data pointer
40  * @param[in] data_len : data length
41  *
42  */
43 typedef uint32_t (*cybt_debug_uart_data_handler_t)( uint8_t* p_data, uint32_t data_len );
44 
45 /** Debug Uart Configuration */
46 typedef struct
47 {
48     cyhal_gpio_t         uart_tx_pin;  /**< Uart TXD pin */
49     cyhal_gpio_t         uart_rx_pin;  /**< Uart RXD pin */
50     cyhal_gpio_t         uart_rts_pin;  /**< Uart RTS pin */
51     cyhal_gpio_t         uart_cts_pin;  /**< Uart CTS pin */
52 
53     uint32_t             baud_rate;     /**< Uart baud rate */
54 
55     bool                 flow_control;  /**< flow control status */
56 } cybt_debug_uart_config_t;
57 /**
58  * Initialize Debug UART.
59  * This debug UART is used for communication between the PSOC and host connected via USB cable.
60  *
61  * @param[in] config       : uart configuration
62  * @param[in] p_data_handler  : received data handler callback pointer
63  *
64  * @returns  CYBT_SUCCESS if success else error reason.
65  *
66  * @note : Debug UART Must be initialized to send traces over Debug UART.
67  */
68 cybt_result_t cybt_debug_uart_init(cybt_debug_uart_config_t* config, cybt_debug_uart_data_handler_t p_data_handler);
69 
70 /**
71  * De-initialize Debug UART.
72  *
73  * @note : Debug UART Must be initialized to send traces over Debug UART.
74  */
75 void cybt_debug_uart_deinit();
76 
77 /**
78  * Sends traces over Debug UART
79  *
80  * @param[in] length: Length of the data
81  * @param[in] p_data: data pointer
82  *
83  * @returns  CYBT_SUCCESS if success else error reason.
84  *
85  */
86 cybt_result_t cybt_debug_uart_send_trace (uint16_t length, uint8_t* p_data);
87 
88 /**
89  * Sends HCI traces over Debug UART
90  *
91  * @param[in] type  : Trace data type (refer wiced_bt_hci_trace_type_t in wiced_bt_dev.h)
92  * @param[in] length: Length of the data
93  * @param[in] p_data: data pointer
94  *
95  * @returns  CYBT_SUCCESS if success else error reason.
96  *
97  */
98 cybt_result_t cybt_debug_uart_send_hci_trace (uint8_t type, uint16_t length, uint8_t* p_data);
99 
100 /**
101  * Sends data over Debug UART
102  *
103  * @param[in] opcode  : Opcode
104  * @param[in] length: Length of the data
105  * @param[in] p_data: data pointer
106  *
107  * @returns  CYBT_SUCCESS if success else error reason.
108  *
109  * @note This can be used from register callback of wiced_bt_dev_register_hci_trace function.
110  */
111 cybt_result_t cybt_debug_uart_send_data (uint16_t opcode, uint16_t data_size, uint8_t *p_data);
112 
113 /**
114  * Sends coredump HCI traces over Debug UART
115  *
116  * @param[in] length: Length of the data
117  * @param[in] p_data: data pointer
118  *
119  * @returns  CYBT_SUCCESS if success else error reason.
120  */
121 cybt_result_t cybt_send_coredump_hci_trace (uint16_t data_size, uint8_t *p_data);
122 
123 /**
124 * Sends a WICED HCI packet in a WICED buffer over Debug UART
125 *
126 * @param[in] p_pkt: pointer to the WICED HCI packet in a wiced_bt_buffer
127 *
128 * @returns  CYBT_SUCCESS if the transmission is started, else error reason.
129 *
130 * @note the buffer should be obtained using wiced_bt_get_buffer(). If this
131 * function returns error, the buffer is not freed. After transmission, the
132 * the buffer is freed using a call to wiced_bt_free_buffer().
133 */
134 cybt_result_t cybt_debug_uart_send_wiced_hci_buf (void *p_buf);
135 
136 /**@} */
137 
138