Skip to content

Commit

Permalink
Upload retarget-io [123]
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlab-runner committed Dec 2, 2022
1 parent a61cd7c commit 3072757
Show file tree
Hide file tree
Showing 41 changed files with 810 additions and 528 deletions.
5 changes: 4 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ A utility library to retarget the standard input/output (STDIO) messages to a UA
* Thread safe write for NewLib

### What Changed?
#### v1.4.0
* Add cy_retarget_io_init_fc function to initialize with flow control pins
* Mark mutex as no longer initialized after 'cy_retarget_io_deinit'
#### v1.3.0
* Added support for checking whether data is being transmitted and waiting until done before finishing the deinit process
* Added support for using with HAL v1 or v2
Expand Down Expand Up @@ -46,4 +49,4 @@ Minimum required ModusToolbox™ Software Environment: v2.0
* [PSoC™ 6 Resources - KBA223067](https://community.cypress.com/docs/DOC-14644)

---
© Cypress Semiconductor Corporation (an Infineon company) or an affiliate of Cypress Semiconductor Corporation, 2019-2021.
© Cypress Semiconductor Corporation (an Infineon company) or an affiliate of Cypress Semiconductor Corporation, 2019-2022.
34 changes: 20 additions & 14 deletions cy_retarget_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
********************************************************************************
* \copyright
* Copyright 2018-2021 Cypress Semiconductor Corporation (an Infineon company) or
* Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation
*
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -103,6 +103,7 @@ static void cy_retarget_io_mutex_deinit(void)
{
abort();
}
cy_retarget_io_mutex_initialized = false;
}


Expand Down Expand Up @@ -355,11 +356,11 @@ __attribute__((weak)) int _read(int fd, char* ptr, int len)
{
(void)fd;

cy_rslt_t rslt;
int nChars = 0;
if (ptr != NULL)
{
for (; nChars < len; ++ptr)
cy_rslt_t rslt;
do
{
rslt = cy_retarget_io_getchar(ptr);
if (rslt == CY_RSLT_SUCCESS)
Expand All @@ -369,13 +370,11 @@ __attribute__((weak)) int _read(int fd, char* ptr, int len)
{
break;
}
ptr++;
}
else
{
break;
}
}
} while ((rslt == CY_RSLT_SUCCESS) && (nChars < len));
}

return (nChars);
}

Expand Down Expand Up @@ -531,9 +530,12 @@ char __attribute__((weak)) *_sys_command_string(char* cmd, int len)
#endif // ARM-MDK

//--------------------------------------------------------------------------------------------------
// cy_retarget_io_init
// cy_retarget_io_init_fc
//
// Enables user to provide flow control pins during initialization
//--------------------------------------------------------------------------------------------------
cy_rslt_t cy_retarget_io_init(cyhal_gpio_t tx, cyhal_gpio_t rx, uint32_t baudrate)
cy_rslt_t cy_retarget_io_init_fc(cyhal_gpio_t tx, cyhal_gpio_t rx, cyhal_gpio_t cts,
cyhal_gpio_t rts, uint32_t baudrate)
{
const cyhal_uart_cfg_t uart_config =
{
Expand All @@ -545,10 +547,14 @@ cy_rslt_t cy_retarget_io_init(cyhal_gpio_t tx, cyhal_gpio_t rx, uint32_t baudrat
};

#if (CYHAL_API_VERSION >= 2)
cy_rslt_t result =
cyhal_uart_init(&cy_retarget_io_uart_obj, tx, rx, NC, NC, NULL, &uart_config);
#else // HAL API version 1
cy_rslt_t result = cyhal_uart_init(&cy_retarget_io_uart_obj, tx, rx, cts, rts, NULL,
&uart_config);
#else // HAL API before version 2
cy_rslt_t result = cyhal_uart_init(&cy_retarget_io_uart_obj, tx, rx, NULL, &uart_config);
if (result == CY_RSLT_SUCCESS)
{
result = cyhal_uart_set_flow_control(&cy_retarget_io_uart_obj, cts, rts);
}
#endif

if (result == CY_RSLT_SUCCESS)
Expand All @@ -568,7 +574,7 @@ cy_rslt_t cy_retarget_io_init(cyhal_gpio_t tx, cyhal_gpio_t rx, uint32_t baudrat
//--------------------------------------------------------------------------------------------------
// cy_retarget_io_is_tx_active
//--------------------------------------------------------------------------------------------------
bool cy_retarget_io_is_tx_active()
bool cy_retarget_io_is_tx_active(void)
{
return cyhal_uart_is_tx_active(&cy_retarget_io_uart_obj);
}
Expand Down
33 changes: 26 additions & 7 deletions cy_retarget_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
***************************************************************************************************
* \copyright
* Copyright 2018-2021 Cypress Semiconductor Corporation (an Infineon company) or
* Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation
*
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -53,6 +53,22 @@ extern cyhal_uart_t cy_retarget_io_uart_obj;
/** UART baud rate */
#define CY_RETARGET_IO_BAUDRATE (115200)

/**
* \brief Initialization function for redirecting low level IO commands to allow
* sending messages over a UART interface. This will setup the communication
* interface to allow using printf and related functions.
*
* In an RTOS environment, this function must be called after the RTOS has been
* initialized.
*
* \param tx UART TX pin, if no TX pin use NC
* \param rx UART RX pin, if no RX pin use NC
* \param baudrate UART baudrate
* \returns CY_RSLT_SUCCESS if successfully initialized, else an error about
* what went wrong
*/
#define cy_retarget_io_init(tx, rx, baudrate) cy_retarget_io_init_fc(tx, rx, NC, NC, baudrate)

#ifdef DOXYGEN

/** Defining this macro enables conversion of line feed (LF) into carriage
Expand All @@ -66,25 +82,28 @@ extern cyhal_uart_t cy_retarget_io_uart_obj;

/**
* \brief Initialization function for redirecting low level IO commands to allow
* sending messages over a UART interface. This will setup the communication
* interface to allow using printf and related functions.
* sending messages over a UART interface with flow control. This will setup the
* communication interface to allow using printf and related functions.
*
* In an RTOS environment, this function must be called after the RTOS has been
* initialized.
*
* \param tx UART TX pin
* \param rx UART RX pin
* \param tx UART TX pin, if no TX pin use NC
* \param rx UART RX pin, if no RX pin use NC
* \param cts UART CTS pin, if no CTS pin use NC
* \param rts UART RTS pin, if no RTS pin use NC
* \param baudrate UART baudrate
* \returns CY_RSLT_SUCCESS if successfully initialized, else an error about
* what went wrong
*/
cy_rslt_t cy_retarget_io_init(cyhal_gpio_t tx, cyhal_gpio_t rx, uint32_t baudrate);
cy_rslt_t cy_retarget_io_init_fc(cyhal_gpio_t tx, cyhal_gpio_t rx, cyhal_gpio_t cts,
cyhal_gpio_t rts, uint32_t baudrate);

/**
* \brief Checks whether there is data waiting to be written to the serial console.
* \returns true if there are pending TX transactions, otherwise false
*/
bool cy_retarget_io_is_tx_active();
bool cy_retarget_io_is_tx_active(void);

/**
* \brief Releases the UART interface allowing it to be used for other purposes.
Expand Down
Binary file removed docs/html/doxygen.png
Binary file not shown.
Loading

0 comments on commit 3072757

Please sign in to comment.