1 /***********************************************************************************************//**
2 * \file cybsp_wifi.h
3 *
4 * \brief
5 * Basic abstraction layer for dealing with boards containing a Cypress MCU. This
6 * API provides convenience methods for initializing and manipulating different
7 * hardware found on the board.
8 *
9 ***************************************************************************************************
10 * \copyright
11 * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
12 * an affiliate of Cypress Semiconductor Corporation
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License");
17 * you may not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 **************************************************************************************************/
28
29 /**
30 * \addtogroup group_bsp_wifi WiFi Initialization
31 * \{
32 * Basic integration code for interfacing the WiFi Host Driver (WHD) with the Board
33 * Support Packages (BSPs).
34 */
35 #pragma once
36
37 #include "cy_result.h"
38 #include "whd_wifi_api.h"
39
40 #if defined(__cplusplus)
41 extern "C" {
42 #endif
43
44 /** Initialization of the WiFi driver failed. */
45 #define CYBSP_RSLT_WIFI_INIT_FAILED \
46 (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_WHD_INTEGRATION, 0))
47
48 /** SDIO enumeration failed. */
49 #define CYBSP_RSLT_WIFI_SDIO_ENUM_TIMEOUT \
50 (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_WHD_INTEGRATION, 1))
51
52 /** SD device does not support IO functionality */
53 #define CYBSP_RSLT_WIFI_SDIO_ENUM_IO_NOT_SUPPORTED \
54 (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_WHD_INTEGRATION, 2))
55
56 /** SDIO device is not ready */
57 #define CYBSP_RSLT_WIFI_SDIO_ENUM_NOT_READY \
58 (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_WHD_INTEGRATION, 3))
59
60 /** SDIO switch to High Speed mode failed. */
61 #define CYBSP_RSLT_WIFI_SDIO_HS_SWITCH_FAILED \
62 (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_WHD_INTEGRATION, 4))
63
64 /** Initializes the primary interface for the WiFi driver on the board. This sets up
65 * the WHD interface to use the \ref group_bsp_network_buffer APIs and to communicate
66 * over the SDIO interface on the board. This function does the following:<br>
67 * 1) Initializes the WiFi driver.<br>
68 * 2) Turns on the WiFi chip.
69 *
70 * @note This function cannot be called multiple times. If the interface needs to be
71 * reinitialized, \ref cybsp_wifi_deinit must be called before calling this function
72 * again.
73 *
74 * @param[out] interface Interface to be initialized
75 * @param[in] init_config Pointer to the configuration parameters to initialize the driver.
76 * Passing NULL will use default values.
77 * @param[in] resource_if Pointer to resource interface to provide resources to the driver
78 * initialization process. Passing NULL will use the default.
79 * @param[in] buffer_if Pointer to a buffer interface to provide buffer related services to the
80 * driver instance. Passing NULL will use the default.
81 * @param[in] netif_if Pointer to a whd_netif_funcs_t to provide network stack services to the
82 * driver instance. Passing NULL will use the default.
83 *
84 * @return CY_RSLT_SUCCESS for successful initialization or error if initialization failed.
85 */
86 cy_rslt_t cybsp_wifi_init_primary_extended(whd_interface_t* interface,
87 whd_init_config_t* init_config,
88 whd_resource_source_t* resource_if,
89 whd_buffer_funcs_t* buffer_if,
90 whd_netif_funcs_t* netif_if);
91
92 /**
93 * Initializes the primary interface for the WiFi driver on the board using the default
94 * configuration, resource, buffer, and network interfaces.
95 * See cybsp_wifi_init_primary_extended() for more details.
96 *
97 * @param[out] interface Interface to be initialized
98 *
99 * @return CY_RSLT_SUCCESS for successful initialization or error if initialization failed.
100 */
cybsp_wifi_init_primary(whd_interface_t * interface)101 static inline cy_rslt_t cybsp_wifi_init_primary(whd_interface_t* interface)
102 {
103 return cybsp_wifi_init_primary_extended(interface, NULL, NULL, NULL, NULL);
104 }
105
106
107 /** This function initializes and adds a secondary interface to the WiFi driver.
108 * @note This function does not initialize the WiFi driver or turn on the WiFi chip.
109 * That is required to be done by first calling \ref cybsp_wifi_init_primary.
110 *
111 * @param[out] interface Interface to be initialized
112 * @param[in] mac_address Mac address for secondary interface
113 *
114 * @return CY_RSLT_SUCCESS for successful initialization or error if initialization failed.
115 */
116 cy_rslt_t cybsp_wifi_init_secondary(whd_interface_t* interface, whd_mac_t* mac_address);
117
118 /** De-initializes all WiFi interfaces and the WiFi driver. This function does the
119 * following:<br>
120 * 1) Deinitializes all WiFi interfaces.<br>
121 * 2) Deinitializes the WiFi driver.<br>
122 * 3) Turns off the WiFi chip.
123 *
124 * @param[in] interface Either the Primary or Secondary interface.
125 *
126 * @return CY_RSLT_SUCCESS for successful de-initialization or error if de-initialization failed.
127 */
128 cy_rslt_t cybsp_wifi_deinit(whd_interface_t interface);
129
130 /** Gets the wifi driver instance initialized by the driver. This should only be called
131 * after being initialized by \ref cybsp_wifi_init_primary() and before being
132 * deinitialized by \ref cybsp_wifi_deinit(). This is also the only time where the
133 * driver reference is valid.
134 *
135 * @return Wifi driver instance pointer.
136 */
137 whd_driver_t cybsp_get_wifi_driver(void);
138
139 #ifdef __cplusplus
140 }
141 #endif // __cplusplus
142
143 /** \} group_bsp_wifi */
144