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

Fix SDIO communication issue on Cypress 1M boards and other minor fixes #12394

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ nsapi_error_t WhdSTAInterface::connect()

// initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
if(!_whd_emac.power_up()) {
return NSAPI_ERROR_DEVICE_ERROR;
}
}

res = whd_management_set_event_handler(_whd_emac.ifp, sta_link_change_events,
Expand Down Expand Up @@ -322,7 +324,9 @@ nsapi_error_t WhdSTAInterface::connect()
void WhdSTAInterface::wifi_on()
{
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
if(!_whd_emac.power_up()) {
CY_ASSERT(false);
}
}
}

Expand Down Expand Up @@ -384,11 +388,14 @@ int8_t WhdSTAInterface::get_rssi()

// initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
if(!_whd_emac.power_up()) {
CY_ASSERT(false);
}
}

res = (whd_result_t)whd_wifi_get_rssi(_whd_emac.ifp, &rssi);
if (res != 0) {
CY_ASSERT(false);
return 0;
}

Expand Down Expand Up @@ -463,7 +470,9 @@ int WhdSTAInterface::internal_scan(WiFiAccessPoint *aps, unsigned count, scan_re

// initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
if(!_whd_emac.power_up()) {
return NSAPI_ERROR_DEVICE_ERROR;
}
}

interal_scan_data.sema = new Semaphore();
Expand All @@ -476,7 +485,6 @@ int WhdSTAInterface::internal_scan(WiFiAccessPoint *aps, unsigned count, scan_re
whd_result_t whd_res;
int res;


whd_res = (whd_result_t)whd_wifi_scan(_whd_emac.ifp, WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY,
NULL, NULL, NULL, NULL, whd_scan_handler, &internal_scan_result, &interal_scan_data);
if (whd_res != WHD_SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -111,7 +111,7 @@ cy_en_syspm_status_t SDIO_DeepSleepCallback(cy_stc_syspm_callback_params_t *para
CY_UNUSED_PARAMETER(params);
cy_en_syspm_status_t status = CY_SYSPM_FAIL;

switch (mode)
switch (mode)
{
case CY_SYSPM_CHECK_READY:
case CY_SYSPM_CHECK_FAIL:
Expand Down Expand Up @@ -656,7 +656,7 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
cy_rslt_t result;

/* Initialize the semaphore. This is not done in init because init is called
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
* interrupt thread.
*/
if(!sema_initialized)
Expand Down Expand Up @@ -770,16 +770,16 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)

#ifdef CY_RTOS_AWARE
/* Wait for the transfer to finish.
* Acquire semaphore and wait until it will be released
* Acquire semaphore and wait until it will be released
* in SDIO_IRQ:
* 1. sdio_transfer_finished_semaphore count is equal to
* zero. cy_rtos_get_semaphore waits until semaphore
* count is increased by cy_rtos_set_semaphore() in
* 1. sdio_transfer_finished_semaphore count is equal to
* zero. cy_rtos_get_semaphore waits until semaphore
* count is increased by cy_rtos_set_semaphore() in
* SDIO_IRQ.
* 2. The cy_rtos_set_semaphore() increases
* 2. The cy_rtos_set_semaphore() increases
* sdio_transfer_finished_semaphore count.
* 3. The cy_rtos_get_semaphore() function decreases
* sdio_transfer_finished_semaphore back to zero
* 3. The cy_rtos_get_semaphore() function decreases
* sdio_transfer_finished_semaphore back to zero
* and exit. Or timeout occurs
*/
result = cy_rtos_get_semaphore( &sdio_transfer_finished_semaphore, 10, false );
Expand Down Expand Up @@ -1080,7 +1080,12 @@ void SDIO_DisableSdClk(void)
void SDIO_SetSdClkFrequency(uint32_t u32SdClkFreqHz)
{
uint16_t u16Div;
u16Div = Cy_SysClk_ClkPeriGetFrequency() / u32SdClkFreqHz;
/*
* The UDB SDIO implemenation has a extra divider internally that divides the input clock to the UDB
* by 2. The desired clock frequency is hence intentionally multiplied by 2 in order to get the required
* SDIO operating frequency.
*/
u16Div = Cy_SysClk_ClkPeriGetFrequency() / (2 * u32SdClkFreqHz);
Cy_SysClk_PeriphSetDivider(SDIO_HOST_Internal_Clock_DIV_TYPE, SDIO_HOST_Internal_Clock_DIV_NUM, (u16Div-1));
}

Expand Down Expand Up @@ -1247,10 +1252,10 @@ void SDIO_IRQ(void)
{
pfnCardInt_count++;
}

/* Execute card interrupt callback if neccesary */
if (0 != pfnCardInt_count)
{
{
if (NULL != gstcInternalData.pstcCallBacks.pfnCardIntCb)
{
gstcInternalData.pstcCallBacks.pfnCardIntCb();
Expand All @@ -1277,7 +1282,7 @@ void SDIO_IRQ(void)
/* CRC was bad, set the flag */
gstcInternalData.stcEvents.u8CRCError++;
}

/* Set the done flag */

#ifdef CY_RTOS_AWARE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -111,7 +111,7 @@ cy_en_syspm_status_t SDIO_DeepSleepCallback(cy_stc_syspm_callback_params_t *para
CY_UNUSED_PARAMETER(params);
cy_en_syspm_status_t status = CY_SYSPM_FAIL;

switch (mode)
switch (mode)
{
case CY_SYSPM_CHECK_READY:
case CY_SYSPM_CHECK_FAIL:
Expand Down Expand Up @@ -656,7 +656,7 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
cy_rslt_t result;

/* Initialize the semaphore. This is not done in init because init is called
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
* interrupt thread.
*/
if(!sema_initialized)
Expand Down Expand Up @@ -770,16 +770,16 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)

#ifdef CY_RTOS_AWARE
/* Wait for the transfer to finish.
* Acquire semaphore and wait until it will be released
* Acquire semaphore and wait until it will be released
* in SDIO_IRQ:
* 1. sdio_transfer_finished_semaphore count is equal to
* zero. cy_rtos_get_semaphore waits until semaphore
* count is increased by cy_rtos_set_semaphore() in
* 1. sdio_transfer_finished_semaphore count is equal to
* zero. cy_rtos_get_semaphore waits until semaphore
* count is increased by cy_rtos_set_semaphore() in
* SDIO_IRQ.
* 2. The cy_rtos_set_semaphore() increases
* 2. The cy_rtos_set_semaphore() increases
* sdio_transfer_finished_semaphore count.
* 3. The cy_rtos_get_semaphore() function decreases
* sdio_transfer_finished_semaphore back to zero
* 3. The cy_rtos_get_semaphore() function decreases
* sdio_transfer_finished_semaphore back to zero
* and exit. Or timeout occurs
*/
result = cy_rtos_get_semaphore( &sdio_transfer_finished_semaphore, 10, false );
Expand Down Expand Up @@ -1080,7 +1080,12 @@ void SDIO_DisableSdClk(void)
void SDIO_SetSdClkFrequency(uint32_t u32SdClkFreqHz)
{
uint16_t u16Div;
u16Div = Cy_SysClk_ClkPeriGetFrequency() / u32SdClkFreqHz;
/*
* The UDB SDIO implemenation has a extra divider internally that divides the input clock to the UDB
* by 2. The desired clock frequency is hence intentionally multiplied by 2 in order to get the required
* SDIO operating frequency.
*/
u16Div = Cy_SysClk_ClkPeriGetFrequency() / (2 * u32SdClkFreqHz);
Cy_SysClk_PeriphSetDivider(SDIO_HOST_Internal_Clock_DIV_TYPE, SDIO_HOST_Internal_Clock_DIV_NUM, (u16Div-1));
}

Expand Down Expand Up @@ -1247,10 +1252,10 @@ void SDIO_IRQ(void)
{
pfnCardInt_count++;
}

/* Execute card interrupt callback if neccesary */
if (0 != pfnCardInt_count)
{
{
if (NULL != gstcInternalData.pstcCallBacks.pfnCardIntCb)
{
gstcInternalData.pstcCallBacks.pfnCardIntCb();
Expand All @@ -1277,7 +1282,7 @@ void SDIO_IRQ(void)
/* CRC was bad, set the flag */
gstcInternalData.stcEvents.u8CRCError++;
}

/* Set the done flag */

#ifdef CY_RTOS_AWARE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -111,7 +111,7 @@ cy_en_syspm_status_t SDIO_DeepSleepCallback(cy_stc_syspm_callback_params_t *para
CY_UNUSED_PARAMETER(params);
cy_en_syspm_status_t status = CY_SYSPM_FAIL;

switch (mode)
switch (mode)
{
case CY_SYSPM_CHECK_READY:
case CY_SYSPM_CHECK_FAIL:
Expand Down Expand Up @@ -656,7 +656,7 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
cy_rslt_t result;

/* Initialize the semaphore. This is not done in init because init is called
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
* interrupt thread.
*/
if(!sema_initialized)
Expand Down Expand Up @@ -770,16 +770,16 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)

#ifdef CY_RTOS_AWARE
/* Wait for the transfer to finish.
* Acquire semaphore and wait until it will be released
* Acquire semaphore and wait until it will be released
* in SDIO_IRQ:
* 1. sdio_transfer_finished_semaphore count is equal to
* zero. cy_rtos_get_semaphore waits until semaphore
* count is increased by cy_rtos_set_semaphore() in
* 1. sdio_transfer_finished_semaphore count is equal to
* zero. cy_rtos_get_semaphore waits until semaphore
* count is increased by cy_rtos_set_semaphore() in
* SDIO_IRQ.
* 2. The cy_rtos_set_semaphore() increases
* 2. The cy_rtos_set_semaphore() increases
* sdio_transfer_finished_semaphore count.
* 3. The cy_rtos_get_semaphore() function decreases
* sdio_transfer_finished_semaphore back to zero
* 3. The cy_rtos_get_semaphore() function decreases
* sdio_transfer_finished_semaphore back to zero
* and exit. Or timeout occurs
*/
result = cy_rtos_get_semaphore( &sdio_transfer_finished_semaphore, 10, false );
Expand Down Expand Up @@ -1080,7 +1080,12 @@ void SDIO_DisableSdClk(void)
void SDIO_SetSdClkFrequency(uint32_t u32SdClkFreqHz)
{
uint16_t u16Div;
u16Div = Cy_SysClk_ClkPeriGetFrequency() / u32SdClkFreqHz;
/*
* The UDB SDIO implemenation has a extra divider internally that divides the input clock to the UDB
* by 2. The desired clock frequency is hence intentionally multiplied by 2 in order to get the required
* SDIO operating frequency.
*/
u16Div = Cy_SysClk_ClkPeriGetFrequency() / (2 * u32SdClkFreqHz);
Cy_SysClk_PeriphSetDivider(SDIO_HOST_Internal_Clock_DIV_TYPE, SDIO_HOST_Internal_Clock_DIV_NUM, (u16Div-1));
}

Expand Down Expand Up @@ -1247,10 +1252,10 @@ void SDIO_IRQ(void)
{
pfnCardInt_count++;
}

/* Execute card interrupt callback if neccesary */
if (0 != pfnCardInt_count)
{
{
if (NULL != gstcInternalData.pstcCallBacks.pfnCardIntCb)
{
gstcInternalData.pstcCallBacks.pfnCardIntCb();
Expand All @@ -1277,7 +1282,7 @@ void SDIO_IRQ(void)
/* CRC was bad, set the flag */
gstcInternalData.stcEvents.u8CRCError++;
}

/* Set the done flag */

#ifdef CY_RTOS_AWARE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
********************************************************************************
* \copyright
* Copyright 2016-2019 Cypress Semiconductor Corporation
* Copyright 2016-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading