1 /*******************************************************************************
2 * \file cybt_platform_config.h
3 *
4 * \brief
5 * Provides interface to configurate platform settings, including HCI, sleep mode
6 * and OS task memory pool.
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 
26 #ifndef CYBT_PLATFORM_CONFIG_H
27 #define CYBT_PLATFORM_CONFIG_H
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include "cyhal_gpio.h"
32 #include "cyhal_uart.h"
33 
34 #ifdef ENABLE_BT_SPY_LOG
35 #define ENABLE_DEBUG_UART
36 #endif
37 
38 /**
39  *  @addtogroup    platform_cfg   Bluetooth Platform Configuration
40  *
41  * The Bluetooth platform-specific configurations,
42  * including hardware pin assignment, HCI (Host Controller Interface) format,
43  * sleep mode settings and memory pool size for OS tasks.
44  *
45  *  @{
46  */
47 
48 /******************************************************************************
49  *                                Constants
50  ******************************************************************************/
51 #define CYBT_SLEEP_MODE_DISABLED      (0)
52 #define CYBT_SLEEP_MODE_ENABLED       (1)
53 
54 #define CYBT_WAKE_ACTIVE_LOW          (0)
55 #define CYBT_WAKE_ACTIVE_HIGH         (1)
56 
57 /*****************************************************************************
58  *                           Type Definitions
59  *****************************************************************************/
60 /**
61  *  The BT HCI transport type
62  */
63 typedef enum
64 {
65     CYBT_HCI_UNKNOWN = 0x00,
66     CYBT_HCI_UART    = 0x01,
67     CYBT_HCI_IPC     = 0x02,
68 } cybt_hci_transport_t;
69 
70 /**
71  *  The Porting layer exception list which is causing by low level
72  */
73 typedef enum
74 {
75     CYBT_NO_EXCEPTION          = 0x00,
76     CYBT_HCI_IPC_REL_BUFFER    = 0x01,
77     CYBT_CONTROLLER_CORE_DUMP  = 0x02,
78     CYBT_CONTROLLER_RESTARTED  = 0x03,
79     CYBT_MAX_EXCEPTION         = 0xFF,
80 } cybt_exception_t;
81 
82 /**
83  *  The HCI UART configuration, including:
84  *  * hardware pin assignment
85  *  * baud rate
86  *  * data format
87  *  * flow control support
88  */
89 typedef struct
90 {
91     cyhal_gpio_t         uart_tx_pin;  /**< Uart TXD pin */
92     cyhal_gpio_t         uart_rx_pin;  /**< Uart RXD pin */
93     cyhal_gpio_t         uart_rts_pin;  /**< Uart RTS pin */
94     cyhal_gpio_t         uart_cts_pin;  /**< Uart CTS pin */
95 
96     uint32_t             baud_rate_for_fw_download; /**< Uart baud rate for firmware downloading */
97     uint32_t             baud_rate_for_feature; /**< Uart baud rate for feature */
98 
99     uint32_t             data_bits;  /**< the size of data bits */
100     uint32_t             stop_bits;  /**< the size of stop bits */
101     cyhal_uart_parity_t  parity;     /**< parity check control */
102     bool                 flow_control;  /**< flow control status */
103 } cybt_hci_uart_config_t;
104 
105 /**
106  * Typedef for exception callback function pointer.
107  * which may occur due to low level API failures and if controller triggers coredump
108  *
109  * @param[in]       cybt_exception_t : Reason for the exception cause
110  * @param[in]       info             : Exception data buffer
111  * @param[in]       length           : Exception data buffer length
112  *
113  * @returns         bool : [true] If app handled this error and wants to continue from porting layer,
114  *                         [false] porting layer will issue assert.
115  */
116 typedef bool (* cybt_exception_callback_t)(cybt_exception_t error, uint8_t *info, uint32_t length);
117 
118 /**
119  *  The configuration of BT HCI transport, to specify which interface
120  *  is used and its format.
121  *
122  *  Currently only UART is supported.
123  */
124 typedef struct
125 {
126     cybt_hci_transport_t  hci_transport;  /**< HCI transport selection */
127 
128     union
129     {
130         cybt_hci_uart_config_t  hci_uart; /**< HCI UART configuration */
131     } hci;
132 } cybt_hci_transport_config_t;
133 
134 /**
135   * Cypress Bluetooth chip sleep mode configuration parameters,
136   * including enable status, wakeup pins assignment and
137   * their trigger polarity.
138   */
139 typedef struct
140 {
141     uint8_t         sleep_mode_enabled;    /**< Enable or disable the sleep mode of BT chip.
142                                            *  Either assign the value
143                                            *      CYBT_SLEEP_MODE_DISABLED, or
144                                            *      CYBT_SLEEP_MODE_ENABLED
145                                            *
146                                            *  or CYCFG_BT_LP_ENABLED for ModusToolBox
147                                            *  LPA configuration
148                                            *
149                                            *  Notice that sleep mode will be enabled
150                                            *  only if both device and host wakeup pins
151                                            *  are assigned.
152                                            */
153     cyhal_gpio_t    device_wakeup_pin;     /**< The gpio definition for BT device wakeup pin.
154                                            *  It can be assigned by the value with the type
155                                            *  cyhal_gpio_t directly. For ModusToolBox,
156                                            *  CYCFG_BT_DEV_WAKE_GPIO can be used.
157                                            *
158                                            *  NC is used as this pin is NOT connected.
159                                            */
160     cyhal_gpio_t    host_wakeup_pin;       /**< The gpio definition for BT host wakeup pin.
161                                            *  It can be assigned by the value with the type
162                                            *  cyhal_gpio_t directly. For ModusToolBox,
163                                            *  CYCFG_BT_HOST_WAKE_GPIO can be used.
164                                            *
165                                            *  NC is used as this pin is NOT connected.
166                                            */
167     uint8_t         device_wake_polarity;  /**< The trigger level of device wakeup pin.
168                                             * Either assign the value
169                                             *      CYBT_WAKE_ACTIVE_LOW, or<BR>
170                                             *      CYBT_WAKE_ACTIVE_HIGH.
171                                             *
172                                             *  Or CYCFG_BT_DEV_WAKE_POLARITY
173                                             *  for ModusToolBox LPA configuration.
174                                             *
175                                             *  The default value will be active low.
176                                             */
177     uint8_t         host_wake_polarity;    /**< The trigger level of host wakeup pin.
178                                             * Either assign the value
179                                             *      CYBT_WAKE_ACTIVE_LOW, or <BR>
180                                             *      CYBT_WAKE_ACTIVE_HIGH,
181                                             *
182                                             *  Or CYCFG_BT_DEV_WAKE_POLARITY
183                                             *  for ModusToolBox LPA configuration.
184                                             *
185                                             *  The default value will be active low.
186                                             */
187 } cybt_controller_sleep_config_t;
188 
189 /**
190  *  The BT chip control configuration
191  */
192 typedef struct
193 {
194     cyhal_gpio_t                    bt_power_pin;    /**< BT controller power pin */
195     cybt_controller_sleep_config_t  sleep_mode;      /**< sleep mode setting */
196 } cybt_controller_config_t;
197 
198 /**
199  *  The overall configuration for Cypress WICED BT/BLE stack and BT chip
200  */
201 typedef struct
202 {
203     cybt_hci_transport_config_t    hci_config;         /**< Bluetooth HCI transport configuration */
204     cybt_controller_config_t       controller_config;  /**< Cypress Bluetooth chip configuration*/
205     uint32_t                       task_mem_pool_size; /**< memory pool size for Bluetotoh task communication.
206                                                         * The default size is 2048 bytes if it wasn't specified.
207                                                         */
208 
209 } cybt_platform_config_t;
210 
211 
212 #ifdef __cplusplus
213 extern "C"
214 {
215 #endif
216 
217 /*****************************************************************************
218  *                           Function Declarations
219  ****************************************************************************/
220 
221 /**
222  * Configurate the Bluetotoh platform specific settings.
223  *
224  * @param[in]       p_bt_platform_cfg : point to the configuration structure
225  *
226  * @returns         void
227  */
228 void cybt_platform_config_init(const cybt_platform_config_t *p_bt_platform_cfg);
229 
230 
231 #ifdef __cplusplus
232 } /* extern "C" */
233 #endif
234 
235 /**@} */
236 
237 #endif
238 
239