Skip to content

Commit 0cce5d5

Browse files
cy-vivekpcy-opm
authored andcommitted
PSOC6 deep-sleep changes
- Enable add MBED_TICKLESS in targets/targets.json - BLE : deep-sleep aware HCI transport driver - WIFI: deep-sleep aware driver - Rebuild WICED libraries with Low Power changes
1 parent 69c5404 commit 0cce5d5

File tree

21 files changed

+257
-41
lines changed

21 files changed

+257
-41
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
#if DEVICE_SERIAL && DEVICE_SERIAL_FC
19+
20+
#include "CyH4TransportDriver.h"
21+
#include "cycfg_pins.h"
22+
23+
namespace ble {
24+
namespace vendor {
25+
namespace cypress_ble {
26+
27+
CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name) :
28+
uart(tx, rx, baud), cts(cts), rts(rts),
29+
bt_host_wake_name(bt_host_wake_name),
30+
bt_device_wake_name(bt_device_wake_name),
31+
bt_host_wake(bt_host_wake_name, PIN_INPUT, PullNone, 0),
32+
bt_device_wake(bt_device_wake_name, PIN_OUTPUT, PullDefault, 1)
33+
{
34+
}
35+
36+
void CyH4TransportDriver::bt_host_wake_irq_handler(void)
37+
{
38+
sleep_manager_lock_deep_sleep();
39+
CyH4TransportDriver::on_controller_irq();
40+
sleep_manager_unlock_deep_sleep();
41+
}
42+
43+
void CyH4TransportDriver::initialize()
44+
{
45+
InterruptIn *host_wake_pin;
46+
47+
uart.format(
48+
/* bits */ 8,
49+
/* parity */ SerialBase::None,
50+
/* stop bit */ 1
51+
);
52+
53+
uart.set_flow_control(
54+
/* flow */ SerialBase::RTSCTS,
55+
/* rts */ rts,
56+
/* cts */ cts
57+
);
58+
59+
uart.attach(
60+
callback(this, &CyH4TransportDriver::on_controller_irq),
61+
SerialBase::RxIrq
62+
);
63+
64+
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
65+
//Register IRQ for Host WAKE
66+
host_wake_pin = new InterruptIn(bt_host_wake_name);
67+
host_wake_pin->fall(callback(this, &CyH4TransportDriver::bt_host_wake_irq_handler));
68+
69+
#endif
70+
bt_device_wake = 0;
71+
wait_ms(500);
72+
}
73+
74+
void CyH4TransportDriver::terminate() { }
75+
76+
uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
77+
{
78+
uint16_t i = 0;
79+
80+
assert_bt_dev_wake();
81+
82+
while (i < len + 1) {
83+
uint8_t to_write = i == 0 ? type : pData[i - 1];
84+
while (uart.writeable() == 0);
85+
uart.putc(to_write);
86+
++i;
87+
}
88+
89+
deassert_bt_dev_wake();
90+
return len;
91+
}
92+
93+
void CyH4TransportDriver::on_controller_irq()
94+
{
95+
assert_bt_dev_wake();
96+
97+
while (uart.readable()) {
98+
uint8_t char_received = uart.getc();
99+
on_data_received(&char_received, 1);
100+
}
101+
102+
deassert_bt_dev_wake();
103+
}
104+
105+
void CyH4TransportDriver::assert_bt_dev_wake()
106+
{
107+
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
108+
bt_device_wake = 0;
109+
#endif
110+
}
111+
112+
void CyH4TransportDriver::deassert_bt_dev_wake()
113+
{
114+
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
115+
//De-assert bt_device_wake
116+
bt_device_wake = 1;
117+
#endif
118+
}
119+
120+
} // namespace cypress_ble
121+
} // namespace vendor
122+
} // namespace ble
123+
124+
#endif
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 "mbed.h"
25+
#include "CordioHCITransportDriver.h"
26+
#include "drivers/DigitalInOut.h"
27+
28+
29+
namespace ble {
30+
namespace vendor {
31+
namespace cypress_ble {
32+
33+
using namespace ble::vendor;
34+
35+
/**
36+
* Implementation of the H4 driver over Cypress based chips.
37+
*/
38+
class CyH4TransportDriver : public cordio::CordioHCITransportDriver {
39+
public:
40+
/**
41+
* Initialize the transport driver.
42+
*
43+
*/
44+
CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name);
45+
46+
/**
47+
* Destructor
48+
*/
49+
virtual ~CyH4TransportDriver() { }
50+
51+
/**
52+
* @see CordioHCITransportDriver::initialize
53+
*/
54+
virtual void initialize();
55+
56+
/**
57+
* @see CordioHCITransportDriver::terminate
58+
*/
59+
virtual void terminate();
60+
61+
/**
62+
* @see CordioHCITransportDriver::write
63+
*/
64+
virtual uint16_t write(uint8_t type, uint16_t len, uint8_t *pData);
65+
66+
void bt_host_wake_irq_handler();
67+
68+
private:
69+
private:
70+
void on_controller_irq();
71+
void assert_bt_dev_wake();
72+
void deassert_bt_dev_wake();
73+
74+
// Use RawSerial as opposed to Serial as we don't require the locking primitives
75+
// provided by the Serial class (access to the UART should be exclusive to this driver)
76+
// Furthermore, we access the peripheral in interrupt context which would clash
77+
// with Serial's locking facilities
78+
RawSerial uart;
79+
PinName cts;
80+
PinName rts;
81+
PinName bt_host_wake_name;
82+
PinName bt_device_wake_name;
83+
DigitalInOut bt_host_wake;
84+
DigitalInOut bt_device_wake;
85+
};
86+
87+
} // namespace cypress
88+
} // namespace vendor
89+
} // namespace ble
90+
91+
#endif
92+
#endif /* CY_H4TRANSPORT_DRIVER_H_ */

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/HCIDriver.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "bstream.h"
2525
#include <stdbool.h>
2626
#include "hci_mbed_os_adaptation.h"
27-
#include "H4TransportDriver.h"
27+
#include "CyH4TransportDriver.h"
2828
#include "cycfg_pins.h"
2929

3030
extern const int brcm_patch_ram_length;
@@ -57,15 +57,9 @@ class HCIDriver : public cordio::CordioHCIDriver {
5757
public:
5858
HCIDriver(
5959
cordio::CordioHCITransportDriver& transport_driver,
60-
PinName bt_host_wake_name,
61-
PinName bt_device_wake_name,
6260
PinName bt_power_name
6361
) : cordio::CordioHCIDriver(transport_driver),
64-
bt_host_wake_name(bt_host_wake_name),
65-
bt_device_wake_name(bt_device_wake_name),
6662
bt_power_name(bt_power_name),
67-
bt_host_wake(bt_host_wake_name, PIN_INPUT, PullNone, 0),
68-
bt_device_wake(bt_device_wake_name, PIN_OUTPUT, PullDefault, 1),
6963
bt_power(bt_power_name, PIN_OUTPUT, PullUp, 0),
7064
service_pack_index(0),
7165
service_pack_ptr(0),
@@ -82,9 +76,6 @@ class HCIDriver : public cordio::CordioHCIDriver {
8276

8377
virtual void do_initialize()
8478
{
85-
bt_device_wake = 0;
86-
wait_ms(500);
87-
8879
bt_power = 1;
8980
wait_ms(500);
9081
}
@@ -352,7 +343,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
352343
uint8_t *pBuf;
353344
if ((pBuf = hciCmdAlloc(HCI_VS_CMD_SET_SLEEP_MODE, 12)) != NULL)
354345
{
355-
pBuf[HCI_CMD_HDR_LEN] = 0x00; // no sleep moode
346+
pBuf[HCI_CMD_HDR_LEN] = 0x00; // no sleep
356347
pBuf[HCI_CMD_HDR_LEN + 1] = 0x00; // no idle threshold host (N/A)
357348
pBuf[HCI_CMD_HDR_LEN + 2] = 0x00; // no idle threshold HC (N/A)
358349
pBuf[HCI_CMD_HDR_LEN + 3] = 0x00; // BT WAKE
@@ -415,11 +406,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
415406
}
416407
}
417408

418-
PinName bt_host_wake_name;
419-
PinName bt_device_wake_name;
420409
PinName bt_power_name;
421-
DigitalInOut bt_host_wake;
422-
DigitalInOut bt_device_wake;
423410
DigitalInOut bt_power;
424411
size_t service_pack_index;
425412
const uint8_t* service_pack_ptr;
@@ -434,13 +421,14 @@ class HCIDriver : public cordio::CordioHCIDriver {
434421
} // namespace ble
435422

436423
ble::vendor::cordio::CordioHCIDriver& ble_cordio_get_hci_driver() {
437-
static ble::vendor::cordio::H4TransportDriver transport_driver(
424+
static ble::vendor::cypress_ble::CyH4TransportDriver transport_driver(
438425
/* TX */ CY_BT_UART_TX, /* RX */ CY_BT_UART_RX,
439-
/* cts */ CY_BT_UART_CTS, /* rts */ CY_BT_UART_RTS, 115200
426+
/* cts */ CY_BT_UART_CTS, /* rts */ CY_BT_UART_RTS, 115200,
427+
CY_BT_PIN_HOST_WAKE, CY_BT_PIN_DEVICE_WAKE
440428
);
441429
static ble::vendor::cypress::HCIDriver hci_driver(
442-
transport_driver, /* host wake */ CY_BT_PIN_HOST_WAKE,
443-
/* device wake */ CY_BT_PIN_DEVICE_WAKE, /* bt_power */ CY_BT_PIN_POWER
430+
transport_driver,
431+
/* bt_power */ CY_BT_PIN_POWER
444432
);
445433
return hci_driver;
446434
}

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_4343W/PinNames.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ typedef enum {
250250

251251
USBTX = UART_TX,
252252
USBRX = UART_RX,
253-
253+
254+
CY_WIFI_HOST_WAKE = P2_7,
255+
254256
// Not connected
255257
AOUT = (int)0xFFFFFFFF
256258
} PinName;

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_WIFI_BT/PinNames.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ typedef enum {
250250

251251
USBTX = UART_TX,
252252
USBRX = UART_RX,
253-
253+
254+
CY_WIFI_HOST_WAKE = P2_7,
255+
254256
AOUT = P9_6
255257
} PinName;
256258

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CMOD_062_4343W/TARGET_CY8CPROTO_062_4343W/PinNames.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ typedef enum {
233233
USBTX = UART_TX,
234234
USBRX = UART_RX,
235235

236+
CY_WIFI_HOST_WAKE = P2_7,
237+
236238
// Not connected
237239
AOUT = (int)0xFFFFFFFF
238240
} PinName;

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/GeneratedSource/cycfg_pins.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,26 +379,26 @@ extern "C" {
379379
#endif
380380
#define BT_POWER_HSIOM ioss_0_port_3_pin_4_HSIOM
381381
#define BT_POWER_IRQ ioss_interrupts_gpio_3_IRQn
382-
#define BT_HOST_WAKE_PORT GPIO_PRT3
383-
#define BT_HOST_WAKE_PIN 5U
384-
#define BT_HOST_WAKE_NUM 5U
382+
#define BT_HOST_WAKE_PORT GPIO_PRT4
383+
#define BT_HOST_WAKE_PIN 0U
384+
#define BT_HOST_WAKE_NUM 0U
385385
#define BT_HOST_WAKE_DRIVEMODE CY_GPIO_DM_ANALOG
386386
#define BT_HOST_WAKE_INIT_DRIVESTATE 0
387-
#ifndef ioss_0_port_3_pin_5_HSIOM
388-
#define ioss_0_port_3_pin_5_HSIOM HSIOM_SEL_GPIO
387+
#ifndef ioss_0_port_4_pin_0_HSIOM
388+
#define ioss_0_port_4_pin_0_HSIOM HSIOM_SEL_GPIO
389389
#endif
390-
#define BT_HOST_WAKE_HSIOM ioss_0_port_3_pin_5_HSIOM
391-
#define BT_HOST_WAKE_IRQ ioss_interrupts_gpio_3_IRQn
392-
#define BT_DEVICE_WAKE_PORT GPIO_PRT4
393-
#define BT_DEVICE_WAKE_PIN 0U
394-
#define BT_DEVICE_WAKE_NUM 0U
390+
#define BT_HOST_WAKE_HSIOM ioss_0_port_4_pin_0_HSIOM
391+
#define BT_HOST_WAKE_IRQ ioss_interrupts_gpio_4_IRQn
392+
#define BT_DEVICE_WAKE_PORT GPIO_PRT3
393+
#define BT_DEVICE_WAKE_PIN 5U
394+
#define BT_DEVICE_WAKE_NUM 5U
395395
#define BT_DEVICE_WAKE_DRIVEMODE CY_GPIO_DM_STRONG_IN_OFF
396396
#define BT_DEVICE_WAKE_INIT_DRIVESTATE 0
397-
#ifndef ioss_0_port_4_pin_0_HSIOM
398-
#define ioss_0_port_4_pin_0_HSIOM HSIOM_SEL_GPIO
397+
#ifndef ioss_0_port_3_pin_5_HSIOM
398+
#define ioss_0_port_3_pin_5_HSIOM HSIOM_SEL_GPIO
399399
#endif
400-
#define BT_DEVICE_WAKE_HSIOM ioss_0_port_4_pin_0_HSIOM
401-
#define BT_DEVICE_WAKE_IRQ ioss_interrupts_gpio_4_IRQn
400+
#define BT_DEVICE_WAKE_HSIOM ioss_0_port_3_pin_5_HSIOM
401+
#define BT_DEVICE_WAKE_IRQ ioss_interrupts_gpio_3_IRQn
402402
#define EZI2C_SCL_PORT GPIO_PRT6
403403
#define EZI2C_SCL_PIN 0U
404404
#define EZI2C_SCL_NUM 0U

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/PinNames.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ typedef enum {
176176
BT_UART_RTS = P3_2,
177177

178178
BT_PIN_POWER = P3_4,
179-
BT_PIN_HOST_WAKE = P3_5,
180-
BT_PIN_DEVICE_WAKE = P4_0,
179+
BT_PIN_HOST_WAKE = P4_0,
180+
BT_PIN_DEVICE_WAKE = P3_5,
181181
BT_PIN_DEVICE_RESET = P4_1,
182182

183183
SWITCH2 = P0_4,
@@ -221,7 +221,9 @@ typedef enum {
221221

222222
USBTX = UART_TX,
223223
USBRX = UART_RX,
224-
224+
225+
CY_WIFI_HOST_WAKE = P2_7,
226+
225227
// Not connected
226228
AOUT = (int)0xFFFFFFFF
227229
} PinName;

0 commit comments

Comments
 (0)