about parameter type "cy_rslt_t"

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Level 5
Level 5
250 sign-ins 50 replies posted 50 questions asked

Dear Receiver,

In many sample codes, we can see parameters type " cy_rslt_t ".

For example, we can refer to the attached file.

In the attached file we can see there are 2 different types of GPIO initial process.

1. result = cyhal_gpio_init(...);

2. cyhal_gpio_init(...);

What's are their differences ?! I think above No.2 is enough to initial an IO.

Why we use "cy_rslt_t  result ;" and result = cyhal_gpio_init(...) ; to initial an I/O ?!

I know "result " may be a combined parameter but I can't see its function in the attached file.

Thank you so much. 

1 Reply
100 replies posted 10 likes received 50 sign-ins


1. If you want to check whether your GPIO initialization process is success or not, you need to use a variable to store the function return value.

2. Seriously, there is no difference whatever you use return value or not. The effect is the same.

3. The following code is the GPIO initialization of cyhal_gpio_init(...) ,  error or failure also will happen:

*       HAL Implementation

cy_rslt_t cyhal_gpio_init(cyhal_gpio_t pin, cyhal_gpio_direction_t direction, cyhal_gpio_drive_mode_t drvMode, bool initVal)
    /* Mbed creates GPIOs for pins that are dedicated to other peripherals in some cases. */
#ifndef __MBED__
    cyhal_resource_inst_t pinRsc = cyhal_utils_get_gpio_resource(pin);
    cy_rslt_t status = cyhal_hwmgr_reserve(&pinRsc);
    cy_rslt_t status = CY_RSLT_SUCCESS;

    if (status == CY_RSLT_SUCCESS)
        uint32_t pdlDrvMode = cyhal_gpio_convert_drive_mode(drvMode, direction);
        Cy_GPIO_Pin_FastInit(CYHAL_GET_PORTADDR(pin), CYHAL_GET_PIN(pin), pdlDrvMode, initVal, HSIOM_SEL_GPIO);

    return status;

cy_rslt_t cyhal_hwmgr_reserve(const cyhal_resource_inst_t* obj)
    bool isSet;
    uint32_t state = cyhal_system_critical_section_enter();
    cy_rslt_t rslt = cyhal_is_set(cyhal_used, obj->type, obj->block_num, obj->channel_num, &isSet);
    if (rslt == CY_RSLT_SUCCESS && isSet)

    if (rslt == CY_RSLT_SUCCESS)
        rslt = cyhal_set_bit(cyhal_used, obj->type, obj->block_num, obj->channel_num);

    return rslt;