1 /*
2 * Copyright 2023, Cypress Semiconductor Corporation (an Infineon company)
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /** @file
19 *
20 */
21
22 #include "whd_utils.h"
23 #include "whd_bus.h"
24 #include "whd_int.h"
25
26
27 whd_driver_t g_bt_whd_driver;
28
whd_bus_write_reg_value(whd_driver_t whd_driver,uint32_t address,uint8_t value_length,uint32_t value)29 whd_result_t whd_bus_write_reg_value(whd_driver_t whd_driver, uint32_t address,
30 uint8_t value_length, uint32_t value)
31 {
32 CHECK_RETURN(whd_ensure_wlan_bus_is_up(whd_driver) );
33 return whd_bus_write_backplane_value(whd_driver, address, value_length, value);
34
35 }
36
whd_bus_read_reg_value(whd_driver_t whd_driver,uint32_t address,uint8_t value_length,uint8_t * value)37 whd_result_t whd_bus_read_reg_value(whd_driver_t whd_driver, uint32_t address,
38 uint8_t value_length, uint8_t *value)
39 {
40 CHECK_RETURN(whd_ensure_wlan_bus_is_up(whd_driver) );
41 return whd_bus_read_backplane_value(whd_driver, address, value_length, value);
42
43 }
44
whd_bus_share_bt_init(whd_driver_t whd_driver)45 whd_result_t whd_bus_share_bt_init(whd_driver_t whd_driver)
46 {
47 if (!whd_driver)
48 return WHD_WLAN_ERROR;
49 g_bt_whd_driver = whd_driver;
50 return WHD_SUCCESS;
51 }
52
whd_bt_get_whd_driver(void)53 whd_driver_t whd_bt_get_whd_driver(void)
54 {
55 if (g_bt_whd_driver)
56 return g_bt_whd_driver;
57 else
58 return NULL;
59 }
60
whd_bus_bt_attach(whd_driver_t whd_driver,void * btdata,void (* bt_int_fun)(void * data))61 whd_result_t whd_bus_bt_attach(whd_driver_t whd_driver, void *btdata,
62 void (*bt_int_fun)(void *data) )
63 {
64 whd_bt_dev_t btdev;
65 if (whd_driver->bt_dev)
66 {
67 return WHD_SUCCESS;
68 }
69 /* Allocate bt dev */
70 btdev = (whd_bt_dev_t)whd_mem_malloc(sizeof(struct whd_bt_dev) );
71 if (btdev == NULL)
72 {
73 WPRINT_WHD_ERROR( ("Memory allocation failed for whd_bt_dev_t in %s\n", __FUNCTION__) );
74 return WHD_BUFFER_UNAVAILABLE_PERMANENT;
75 }
76 btdev->bt_data = btdata;
77 btdev->intr = WHD_TRUE;
78 whd_driver->bt_dev = btdev;
79 whd_bus_init_stats(whd_driver);
80 btdev->bt_int_cb = bt_int_fun;
81 if (!btdev->bt_int_cb)
82 {
83 btdev->intr = WHD_FALSE;
84 }
85 return WHD_SUCCESS;
86 }
87
whd_bus_bt_detach(whd_driver_t whd_driver)88 void whd_bus_bt_detach(whd_driver_t whd_driver)
89 {
90 whd_bt_dev_t btdev = whd_driver->bt_dev;
91 if (btdev)
92 {
93 if (btdev->bt_data)
94 btdev->bt_data = NULL;
95 if (btdev->bt_int_cb)
96 btdev->bt_int_cb = NULL;
97 if (whd_driver->bt_dev)
98 {
99 whd_driver->bt_dev = NULL;
100 whd_mem_free(btdev);
101 }
102 }
103 }
104
whd_bus_init(whd_driver_t whd_driver)105 whd_result_t whd_bus_init(whd_driver_t whd_driver)
106 {
107 return whd_driver->bus_if->whd_bus_init_fptr(whd_driver);
108 }
109
whd_bus_deinit(whd_driver_t whd_driver)110 whd_result_t whd_bus_deinit(whd_driver_t whd_driver)
111 {
112 return whd_driver->bus_if->whd_bus_deinit_fptr(whd_driver);
113 }
114
whd_bus_wake_interrupt_present(whd_driver_t whd_driver)115 whd_bool_t whd_bus_wake_interrupt_present(whd_driver_t whd_driver)
116 {
117 return whd_driver->bus_if->whd_bus_wake_interrupt_present_fptr(whd_driver);
118 }
119
whd_bus_send_buffer(whd_driver_t whd_driver,whd_buffer_t buffer)120 whd_result_t whd_bus_send_buffer(whd_driver_t whd_driver, whd_buffer_t buffer)
121 {
122 return whd_driver->bus_if->whd_bus_send_buffer_fptr(whd_driver, buffer);
123 }
124
whd_bus_packet_available_to_read(whd_driver_t whd_driver)125 uint32_t whd_bus_packet_available_to_read(whd_driver_t whd_driver)
126 {
127 return whd_driver->bus_if->whd_bus_packet_available_to_read_fptr(whd_driver);
128 }
129
whd_bus_read_frame(whd_driver_t whd_driver,whd_buffer_t * buffer)130 whd_result_t whd_bus_read_frame(whd_driver_t whd_driver, whd_buffer_t *buffer)
131 {
132 return whd_driver->bus_if->whd_bus_read_frame_fptr(whd_driver, buffer);
133 }
134
whd_bus_write_backplane_value(whd_driver_t whd_driver,uint32_t address,uint8_t register_length,uint32_t value)135 whd_result_t whd_bus_write_backplane_value(whd_driver_t whd_driver, uint32_t address, uint8_t register_length,
136 uint32_t value)
137 {
138 return whd_driver->bus_if->whd_bus_write_backplane_value_fptr(whd_driver, address, register_length, value);
139 }
140
whd_bus_read_backplane_value(whd_driver_t whd_driver,uint32_t address,uint8_t register_length,uint8_t * value)141 whd_result_t whd_bus_read_backplane_value(whd_driver_t whd_driver, uint32_t address, uint8_t register_length,
142 uint8_t *value)
143 {
144 return whd_driver->bus_if->whd_bus_read_backplane_value_fptr(whd_driver, address, register_length, value);
145 }
146
whd_bus_read_register_value(whd_driver_t whd_driver,whd_bus_function_t function,uint32_t address,uint8_t value_length,uint8_t * value)147 whd_result_t whd_bus_read_register_value(whd_driver_t whd_driver, whd_bus_function_t function, uint32_t address,
148 uint8_t value_length, uint8_t *value)
149 {
150 return whd_driver->bus_if->whd_bus_read_register_value_fptr(whd_driver, function, address, value_length, value);
151 }
152
whd_bus_write_register_value(whd_driver_t whd_driver,whd_bus_function_t function,uint32_t address,uint8_t value_length,uint32_t value)153 whd_result_t whd_bus_write_register_value(whd_driver_t whd_driver, whd_bus_function_t function, uint32_t address,
154 uint8_t value_length, uint32_t value)
155 {
156 return whd_driver->bus_if->whd_bus_write_register_value_fptr(whd_driver, function, address, value_length, value);
157 }
158
whd_bus_transfer_bytes(whd_driver_t whd_driver,whd_bus_transfer_direction_t direction,whd_bus_function_t function,uint32_t address,uint16_t size,whd_transfer_bytes_packet_t * data)159 whd_result_t whd_bus_transfer_bytes(whd_driver_t whd_driver, whd_bus_transfer_direction_t direction,
160 whd_bus_function_t function, uint32_t address, uint16_t size,
161 whd_transfer_bytes_packet_t *data)
162 {
163 return whd_driver->bus_if->whd_bus_transfer_bytes_fptr(whd_driver, direction, function, address, size, data);
164 }
165
whd_bus_poke_wlan(whd_driver_t whd_driver)166 whd_result_t whd_bus_poke_wlan(whd_driver_t whd_driver)
167 {
168 return whd_driver->bus_if->whd_bus_poke_wlan_fptr(whd_driver);
169 }
170
whd_bus_wakeup(whd_driver_t whd_driver)171 whd_result_t whd_bus_wakeup(whd_driver_t whd_driver)
172 {
173 return whd_driver->bus_if->whd_bus_wakeup_fptr(whd_driver);
174 }
175
whd_bus_sleep(whd_driver_t whd_driver)176 whd_result_t whd_bus_sleep(whd_driver_t whd_driver)
177 {
178 return whd_driver->bus_if->whd_bus_sleep_fptr(whd_driver);
179 }
180
whd_bus_wait_for_wlan_event(whd_driver_t whd_driver,cy_semaphore_t * transceive_semaphore)181 whd_result_t whd_bus_wait_for_wlan_event(whd_driver_t whd_driver, cy_semaphore_t *transceive_semaphore)
182 {
183 return whd_driver->bus_if->whd_bus_wait_for_wlan_event_fptr(whd_driver, transceive_semaphore);
184 }
185
whd_bus_use_status_report_scheme(whd_driver_t whd_driver)186 whd_bool_t whd_bus_use_status_report_scheme(whd_driver_t whd_driver)
187 {
188 return whd_driver->bus_if->whd_bus_use_status_report_scheme_fptr(whd_driver);
189 }
190
whd_bus_backplane_read_padd_size(whd_driver_t whd_driver)191 uint8_t whd_bus_backplane_read_padd_size(whd_driver_t whd_driver)
192 {
193 return whd_driver->bus_if->whd_bus_backplane_read_padd_size_fptr(whd_driver);
194 }
195
whd_bus_get_max_transfer_size(whd_driver_t whd_driver)196 uint32_t whd_bus_get_max_transfer_size(whd_driver_t whd_driver)
197 {
198 return whd_driver->bus_if->whd_bus_get_max_transfer_size_fptr(whd_driver);
199 }
200
whd_bus_init_stats(whd_driver_t whd_driver)201 void whd_bus_init_stats(whd_driver_t whd_driver)
202 {
203 whd_driver->bus_if->whd_bus_init_stats_fptr(whd_driver);
204 }
205
whd_bus_print_stats(whd_driver_t whd_driver,whd_bool_t reset_after_print)206 whd_result_t whd_bus_print_stats(whd_driver_t whd_driver, whd_bool_t reset_after_print)
207 {
208 return whd_driver->bus_if->whd_bus_print_stats_fptr(whd_driver, reset_after_print);
209 }
210
whd_bus_reinit_stats(whd_driver_t whd_driver,whd_bool_t wake_from_firmware)211 whd_result_t whd_bus_reinit_stats(whd_driver_t whd_driver, whd_bool_t wake_from_firmware)
212 {
213 return whd_driver->bus_if->whd_bus_reinit_stats_fptr(whd_driver, wake_from_firmware);
214 }
215
whd_bus_irq_register(whd_driver_t whd_driver)216 whd_result_t whd_bus_irq_register(whd_driver_t whd_driver)
217 {
218 return whd_driver->bus_if->whd_bus_irq_register_fptr(whd_driver);
219 }
220
whd_bus_irq_enable(whd_driver_t whd_driver,whd_bool_t enable)221 whd_result_t whd_bus_irq_enable(whd_driver_t whd_driver, whd_bool_t enable)
222 {
223 return whd_driver->bus_if->whd_bus_irq_enable_fptr(whd_driver, enable);
224 }
225
whd_bus_download_resource(whd_driver_t whd_driver,whd_resource_type_t resource,whd_bool_t direct_resource,uint32_t address,uint32_t image_size)226 whd_result_t whd_bus_download_resource(whd_driver_t whd_driver, whd_resource_type_t resource,
227 whd_bool_t direct_resource, uint32_t address, uint32_t image_size)
228 {
229 return whd_driver->bus_if->whd_bus_download_resource_fptr(whd_driver, resource, direct_resource, address, image_size);
230 }
231