cybsp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /***************************************************************************//**
  2. * \file cybsp.c
  3. *
  4. * Description:
  5. * Provides initialization code for starting up the hardware contained on the
  6. * Cypress board.
  7. *
  8. ********************************************************************************
  9. * \copyright
  10. * Copyright 2018-2019 Cypress Semiconductor Corporation
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *******************************************************************************/
  25. #include <stdlib.h>
  26. #include "cybsp.h"
  27. #if defined(CY_USING_HAL)
  28. #include "cyhal_hwmgr.h"
  29. #endif
  30. #if defined(__cplusplus)
  31. extern "C" {
  32. #endif
  33. /* The sysclk deep sleep callback is recommended to be the last callback that
  34. * is executed before entry into deep sleep mode and the first one upon
  35. * exit the deep sleep mode.
  36. * Doing so minimizes the time spent on low power mode entry and exit.
  37. */
  38. #ifndef CYBSP_SYSCLK_PM_CALLBACK_ORDER
  39. #define CYBSP_SYSCLK_PM_CALLBACK_ORDER (255u)
  40. #endif
  41. #if defined(CYBSP_WIFI_CAPABLE) && defined(CY_USING_HAL)
  42. static cyhal_sdio_t sdio_obj;
  43. cyhal_sdio_t* cybsp_get_wifi_sdio_obj(void)
  44. {
  45. return &sdio_obj;
  46. }
  47. #endif
  48. /**
  49. * Registers a power management callback that prepares the clock system
  50. * for entering deep sleep mode and restore the clocks upon wakeup from deep sleep.
  51. * NOTE: This is called automatically as part of \ref cybsp_init
  52. */
  53. static cy_rslt_t cybsp_register_sysclk_pm_callback(void)
  54. {
  55. cy_rslt_t result = CY_RSLT_SUCCESS;
  56. static cy_stc_syspm_callback_params_t cybsp_sysclk_pm_callback_param = {NULL, NULL};
  57. static cy_stc_syspm_callback_t cybsp_sysclk_pm_callback = {
  58. .callback = &Cy_SysClk_DeepSleepCallback,
  59. .type = CY_SYSPM_DEEPSLEEP,
  60. .callbackParams = &cybsp_sysclk_pm_callback_param,
  61. .order = CYBSP_SYSCLK_PM_CALLBACK_ORDER
  62. };
  63. if (!Cy_SysPm_RegisterCallback(&cybsp_sysclk_pm_callback))
  64. {
  65. result = CYBSP_RSLT_ERR_SYSCLK_PM_CALLBACK;
  66. }
  67. return result;
  68. }
  69. cy_rslt_t cybsp_init(void)
  70. {
  71. /* Setup hardware manager to track resource usage then initialize all system (clock/power) board configuration */
  72. #if defined(CY_USING_HAL)
  73. cy_rslt_t result = cyhal_hwmgr_init();
  74. #else
  75. cy_rslt_t result = CY_RSLT_SUCCESS;
  76. #endif
  77. init_cycfg_all();
  78. if (CY_RSLT_SUCCESS == result)
  79. {
  80. result = cybsp_register_sysclk_pm_callback();
  81. }
  82. #if defined(CYBSP_WIFI_CAPABLE) && defined(CY_USING_HAL)
  83. /* Initialize SDIO interface. This must be done before other HAL API calls as some SDIO implementations require
  84. * specific peripheral instances.
  85. * NOTE: The full WiFi interface still needs to be initialized via cybsp_wifi_init_primary(). This is typically
  86. * done when starting up WiFi.
  87. */
  88. if (CY_RSLT_SUCCESS == result)
  89. {
  90. /* Reserves: CYBSP_WIFI_SDIO, CYBSP_WIFI_SDIO_D0, CYBSP_WIFI_SDIO_D1, CYBSP_WIFI_SDIO_D2, CYBSP_WIFI_SDIO_D3
  91. * CYBSP_WIFI_SDIO_CMD and CYBSP_WIFI_SDIO_CLK.
  92. */
  93. result = cyhal_sdio_init(
  94. &sdio_obj,
  95. CYBSP_WIFI_SDIO_CMD,
  96. CYBSP_WIFI_SDIO_CLK,
  97. CYBSP_WIFI_SDIO_D0,
  98. CYBSP_WIFI_SDIO_D1,
  99. CYBSP_WIFI_SDIO_D2,
  100. CYBSP_WIFI_SDIO_D3);
  101. }
  102. #endif /* defined(CYBSP_WIFI_CAPABLE) */
  103. /* CYHAL_HWMGR_RSLT_ERR_INUSE error code could be returned if any needed for BSP resource was reserved by
  104. * user previously. Please review the Device Configurator (design.modus) and the BSP reservation list
  105. * (cyreservedresources.list) to make sure no resources are reserved by both.
  106. */
  107. return result;
  108. }
  109. #if defined(__cplusplus)
  110. }
  111. #endif