Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSoC6 serial driver: Setup RTS and TX lines on deepsleep entry/exit #10268

Merged
merged 1 commit into from Apr 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c
Expand Up @@ -34,6 +34,7 @@
#include "cy_scb_uart.h"
#include "cy_sysint.h"
#include "cycfg_pins.h"
#include "cycfg_peripherals.h"

#define UART_OVERSAMPLE 12
#define UART_DEFAULT_BAUDRATE 115200
Expand Down Expand Up @@ -127,6 +128,10 @@ static irq_info_t irq_info[NUM_SERIAL_PORTS] = {
{NULL, NULL, 0, unconnected_IRQn}
};

static uint32_t Cy_SCB_UART_GetRtsAcitvePolarity(CySCB_Type const *base)
{
return _FLD2VAL(SCB_UART_FLOW_CTRL_RTS_POLARITY, SCB_UART_FLOW_CTRL(base));
}

/** Routes interrupt to proper SCB block.
*
Expand Down Expand Up @@ -398,6 +403,8 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
{
serial_obj_t *obj = (serial_obj_t *) callbackParams->context;
cy_en_syspm_status_t status = CY_SYSPM_FAIL;
GPIO_PRT_Type *port_tx = Cy_GPIO_PortToAddr(CY_PORT(obj->pin_tx));
GPIO_PRT_Type *port_rts = Cy_GPIO_PortToAddr(CY_PORT(obj->pin_rts));

switch (mode) {
case CY_SYSPM_CHECK_READY:
Expand All @@ -407,6 +414,17 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
*/
if (Cy_SCB_UART_IsTxComplete(obj->base)) {
if (0 == Cy_SCB_UART_GetNumInRxFifo(obj->base)) {
/* Configure RTS and TX GPIO DR register to drive output (high) */
if(obj->pin_rts != NC) {
uint32_t rts_polarity = Cy_SCB_UART_GetRtsAcitvePolarity(obj->base);
uint32_t rts_value = ((rts_polarity == CY_SCB_UART_ACTIVE_LOW) ? CY_SCB_UART_ACTIVE_HIGH : CY_SCB_UART_ACTIVE_LOW);
Cy_GPIO_Write (port_rts, CY_PIN(obj->pin_rts), rts_value);
Cy_GPIO_SetHSIOM(port_rts, CY_PIN(obj->pin_rts), HSIOM_SEL_GPIO);
}

Cy_GPIO_Write (port_tx, CY_PIN(obj->pin_tx), 1);
Cy_GPIO_SetHSIOM(port_tx, CY_PIN(obj->pin_tx), HSIOM_SEL_GPIO);

/* Disable the UART. The transmitter stops driving the
* lines and the receiver stops receiving data until
* the UART is enabled.
Expand All @@ -422,6 +440,13 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
case CY_SYSPM_CHECK_FAIL:
/* Enable the UART to operate */
Cy_SCB_UART_Enable(obj->base);
/* Return SCB control on TX and RTS output pins */
if(obj->pin_rts != NC) {
Cy_GPIO_SetHSIOM(port_rts, CY_PIN(obj->pin_rts), CY_PIN_HSIOM(pinmap_function(obj->pin_rts, PinMap_UART_RTS)));
}

Cy_GPIO_SetHSIOM(port_tx, CY_PIN(obj->pin_tx), CY_PIN_HSIOM(pinmap_function(obj->pin_tx, PinMap_UART_TX)));

status = CY_SYSPM_SUCCESS;
break;

Expand All @@ -432,6 +457,13 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
case CY_SYSPM_AFTER_TRANSITION:
/* Enable the UART to operate */
Cy_SCB_UART_Enable(obj->base);
/* Return SCB control on TX and RTS output pins */
if(obj->pin_rts != NC) {
Cy_GPIO_SetHSIOM(port_rts, CY_PIN(obj->pin_rts), CY_PIN_HSIOM(pinmap_function(obj->pin_rts, PinMap_UART_RTS)));
}

Cy_GPIO_SetHSIOM(port_tx, CY_PIN(obj->pin_tx), CY_PIN_HSIOM(pinmap_function(obj->pin_tx, PinMap_UART_TX)));

status = CY_SYSPM_SUCCESS;
break;

Expand Down