Moving UART init from construtor to init method; altering init method to reset BT device via regulator control; modifications to terminate method

pull/14009/head^2
Wheeler Keith (CY CSS ICW Integration) 2020-11-12 15:41:06 -08:00
parent bf7adcf0d2
commit 47aab97d16
2 changed files with 36 additions and 16 deletions

View File

@ -33,6 +33,7 @@ using namespace std::chrono_literals;
CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name, uint8_t host_wake_irq, uint8_t dev_wake_irq) :
cts(cts), rts(rts),
tx(tx), rx(rx),
bt_host_wake_name(bt_host_wake_name),
bt_device_wake_name(bt_device_wake_name),
bt_host_wake(bt_host_wake_name, PIN_INPUT, PullNone, 0),
@ -40,7 +41,6 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
host_wake_irq_event(host_wake_irq),
dev_wake_irq_event(dev_wake_irq)
{
cyhal_uart_init(&uart, tx, rx, NULL, NULL);
enabled_powersave = true;
bt_host_wake_active = false;
}
@ -48,15 +48,16 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud) :
cts(cts),
rts(rts),
tx(tx), rx(rx),
bt_host_wake_name(NC),
bt_device_wake_name(NC),
bt_host_wake(bt_host_wake_name),
bt_device_wake(bt_device_wake_name)
{
cyhal_uart_init(&uart, tx, rx, NULL, NULL);
enabled_powersave = false;
bt_host_wake_active = false;
sleep_manager_lock_deep_sleep();
sleep_manager_lock_deep_sleep(); // locking deep sleep because this option
// does not include a host wake pin
holding_deep_sleep_lock = true;
}
@ -124,12 +125,21 @@ void CyH4TransportDriver::initialize()
sleep_manager_lock_deep_sleep();
cyhal_gpio_write(CYBSP_BT_POWER, 0);
rtos::ThisThread::sleep_for(20ms);
cyhal_uart_init(&uart, tx, rx, NULL, NULL);
const cyhal_uart_cfg_t uart_cfg = { .data_bits = 8, .stop_bits = 1, .parity = CYHAL_UART_PARITY_NONE, .rx_buffer = NULL, .rx_buffer_size = 0 };
cyhal_uart_configure(&uart, &uart_cfg);
cyhal_uart_set_flow_control(&uart, cts, rts);
cyhal_uart_clear(&uart);
cyhal_uart_register_callback(&uart, &on_controller_irq, &uart);
cyhal_uart_enable_event(&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true);
cyhal_gpio_write(CYBSP_BT_POWER, 1);
rtos::ThisThread::sleep_for(10ms);
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
if (bt_host_wake_name != NC) {
//Register IRQ for Host WAKE
@ -161,14 +171,22 @@ void CyH4TransportDriver::terminate()
CYHAL_ISR_PRIORITY_DEFAULT,
false
);
cyhal_uart_register_callback(&uart,
NULL,
NULL
);
cyhal_uart_register_callback(&uart, NULL, NULL);
cyhal_uart_free(&uart);
if(CYBSP_BT_DEVICE_WAKE != NC) cyhal_gpio_free(CYBSP_BT_DEVICE_WAKE);
cyhal_gpio_free(CYBSP_BT_DEVICE_WAKE);
cyhal_gpio_free(CYBSP_BT_HOST_WAKE);
if(CYBSP_BT_HOST_WAKE != NC) cyhal_gpio_write(CYBSP_BT_DEVICE_WAKE, false);
if(CYBSP_BT_POWER != NC)
{
cyhal_gpio_write(CYBSP_BT_POWER, false);
cyhal_gpio_free(CYBSP_BT_POWER);
}
cyhal_uart_free(&uart);
}
uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)

View File

@ -92,6 +92,8 @@ private:
cyhal_uart_t uart;
PinName cts;
PinName rts;
PinName tx;
PinName rx;
PinName bt_host_wake_name;
PinName bt_device_wake_name;