Mistake on this page?
Report an issue in GitHub or email us
CyH4TransportDriver.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2017-2017 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef CY_H4TRANSPORT_DRIVER_H_
19 #define CY_H4TRANSPORT_DRIVER_H_
20 
21 #if (DEVICE_SERIAL && DEVICE_SERIAL_FC) || defined(DOXYGEN_ONLY)
22 
23 #include <stdint.h>
24 #include "ble/driver/CordioHCITransportDriver.h"
25 #include "drivers/DigitalInOut.h"
26 #include "drivers/InterruptIn.h"
27 
28 #if defined(CYW43XXX_UNBUFFERED_UART)
29 #include "drivers/UnbufferedSerial.h"
30 #else
31 #include "cyhal_uart.h"
32 #endif
33 
34 namespace ble {
35 namespace vendor {
36 namespace cypress_ble {
37 
38 using namespace ble::vendor;
39 
40 /**
41  * Implementation of the H4 driver over Cypress based chips.
42  */
44 public:
45  /**
46  * Initialize the transport driver.
47  *
48  */
49  CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, PinName bt_power_name, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name,
50  uint8_t host_wake_irq = 0, uint8_t dev_wake_irq = 0);
51  CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, PinName bt_power_name, int baud);
52 
53  /**
54  * Destructor
55  */
56  virtual ~CyH4TransportDriver();
57 
58  /**
59  * @see CordioHCITransportDriver::initialize
60  */
61  virtual void initialize();
62 
63  /**
64  * @see CordioHCITransportDriver::terminate
65  */
66  virtual void terminate();
67 
68  /**
69  * @see CordioHCITransportDriver::write
70  */
71  virtual uint16_t write(uint8_t type, uint16_t len, uint8_t *pData);
72 
73  void bt_host_wake_rise_irq_handler();
74  void bt_host_wake_fall_irq_handler();
75 
76 #if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
77  void on_host_stack_inactivity();
78 #endif
79 
80  void update_uart_baud_rate(int baud);
81 
82  bool get_enabled_powersave();
83  uint8_t get_host_wake_irq_event();
84  uint8_t get_dev_wake_irq_event();
85 
86 private:
87  void assert_bt_dev_wake();
88  void deassert_bt_dev_wake();
89 
90 #if defined(CYW43XXX_UNBUFFERED_UART)
91  void on_controller_irq();
92 #endif
93 
94  // Use HAL serial because Cypress UART is buffered.
95  // The PUTC function does not actually blocks until data is fully transmitted,
96  // it only blocks until data gets into HW buffer.
97  // The UART APIs prevents sleep while there are data in the HW buffer.
98  // However UART APIs does not prevent the BT radio from going to sleep.
99  // Use the HAL APIs to prevent the radio from going to sleep until UART transmition is complete.
100  // Mbed layer has no API that distinguish between data in HW buffer v.s. data already transmitted.
101 #if defined(CYW43XXX_UNBUFFERED_UART)
103 #else
104  cyhal_uart_t uart;
105  PinName tx;
106  PinName rx;
107 #endif
108  PinName cts;
109  PinName rts;
110  PinName bt_host_wake_name;
111  PinName bt_device_wake_name;
112 
113  mbed::DigitalInOut bt_power;
114  mbed::DigitalInOut bt_host_wake;
115  mbed::DigitalInOut bt_device_wake;
116 
117  bool bt_host_wake_active;
118 
119 #if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
120  mbed::InterruptIn *host_wake_pin;
121 #endif
122 
123  bool enabled_powersave;
124  uint8_t host_wake_irq_event;
125  uint8_t dev_wake_irq_event;
126 };
127 
128 } // namespace cypress
129 } // namespace vendor
130 } // namespace ble
131 
132 #define DEF_BT_BAUD_RATE (115200)
133 #define DEF_BT_3M_BAUD_RATE (3000000) /* Both Host and BT device have to be adapt to this */
134 
135 #define WAKE_EVENT_ACTIVE_HIGH ( 1 ) /* Interrupt Rising Edge */
136 #define WAKE_EVENT_ACTIVE_LOW ( 0 ) /* Interrupt Falling Edge */
137 
138 ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_default_h4_transport_driver();
139 ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_h4_transport_driver();
140 #endif
141 #endif /* CY_H4TRANSPORT_DRIVER_H_ */
Base class of the HCI transport driver.
Implementation of the H4 driver over Cypress based chips.
Class implementation for unbuffered I/O for an interrupt driven application or one that needs to have...
A digital input/output, used for setting or reading a bi-directional pin.
Definition: DigitalInOut.h:36
A digital interrupt input, used to call a function on a rising or falling edge.
Definition: InterruptIn.h:65
Entry namespace for all BLE API definitions.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.