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 #include "cyabs_rtos.h"
19 
20 #include "whd.h"
21 #include "whd_network_types.h"
22 #include "whd_types_int.h"
23 #include "whd_resource_api.h"
24 
25 #ifndef INCLUDED_WHD_BUS_PROTOCOL_INTERFACE_H_
26 #define INCLUDED_WHD_BUS_PROTOCOL_INTERFACE_H_
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 /******************************************************
34 *             Constants
35 ******************************************************/
36 
37 typedef enum
38 {
39     BUS_FUNCTION       = 0,
40     BACKPLANE_FUNCTION = 1,
41     WLAN_FUNCTION      = 2
42 } whd_bus_function_t;
43 
44 #define BUS_FUNCTION_MASK (0x3) /* Update this if adding functions */
45 #define WHD_BUS_FAIL                             (0xFFFFFFFF)
46 
47 /******************************************************
48 *             Macros
49 ******************************************************/
50 #define PLATFORM_WLAN_ALLOW_BUS_TO_SLEEP_DELAY_MS 10
51 
52 #define DELAYED_BUS_RELEASE_SCHEDULE(whd_driver, schedule) do {  whd_delayed_bus_release_schedule_update(whd_driver, \
53                                                                                                          schedule); \
54 } while (0)
55 
56 /******************************************************
57 *             Structures
58 ******************************************************/
59 
60 #pragma pack(1)
61 
62 typedef struct
63 {
64     uint8_t bus_header[MAX_BUS_HEADER_SIZE];
65     uint32_t data[1];
66 } whd_transfer_bytes_packet_t;
67 
68 #pragma pack()
69 
70 typedef void (*whd_bus_irq_callback_t)(void *handler_arg, uint32_t event);
71 
72 /******************************************************
73 *             Function declarations
74 ******************************************************/
75 
76 /* Share bus to BT */
77 extern whd_result_t whd_bus_write_reg_value(whd_driver_t whd_driver, uint32_t address,
78                                             uint8_t value_length, uint32_t value);
79 extern whd_result_t whd_bus_read_reg_value(whd_driver_t whd_driver, uint32_t address,
80                                            uint8_t value_length, uint8_t *value);
81 extern whd_result_t whd_bus_mem_bytes(whd_driver_t whd_driver, uint8_t direct,
82                                       uint32_t address, uint32_t size, uint8_t *data);
83 extern whd_driver_t whd_bt_get_whd_driver(void);
84 extern whd_result_t whd_bus_share_bt_init(whd_driver_t whd_driver);
85 extern whd_result_t whd_bus_bt_attach(whd_driver_t whd_driver, void *btdata,
86                                       void (*bt_int_fun)(void *data) );
87 extern void whd_bus_bt_detach(whd_driver_t whd_driver);
88 extern uint32_t whd_get_bt_info(whd_driver_t whd_drv, whd_bt_info_t bt_info);
89 /* Initialisation functions */
90 extern whd_result_t whd_bus_init(whd_driver_t whd_driver);
91 extern whd_result_t whd_bus_deinit(whd_driver_t whd_driver);
92 
93 /* Device register access functions */
94 extern whd_result_t whd_bus_set_backplane_window(whd_driver_t whd_driver, uint32_t addr);
95 extern whd_result_t whd_bus_write_backplane_value(whd_driver_t whd_driver, uint32_t address, uint8_t register_length,
96                                                   uint32_t value);
97 extern whd_result_t whd_bus_read_backplane_value(whd_driver_t whd_driver, uint32_t address, uint8_t register_length,
98                                                  uint8_t *value);
99 extern whd_result_t whd_bus_write_register_value(whd_driver_t whd_driver, whd_bus_function_t function, uint32_t address,
100                                                  uint8_t value_length, uint32_t value);
101 extern whd_result_t whd_bus_read_register_value(whd_driver_t whd_driver, whd_bus_function_t function, uint32_t address,
102                                                 uint8_t value_length, uint8_t *value);
103 
104 /* Device data transfer functions */
105 extern whd_result_t whd_bus_send_buffer(whd_driver_t whd_driver, whd_buffer_t buffer);
106 extern whd_result_t whd_bus_transfer_bytes(whd_driver_t whd_driver, whd_bus_transfer_direction_t direction,
107                                            whd_bus_function_t function, uint32_t address, uint16_t size,
108                                            whd_transfer_bytes_packet_t *data);
109 
110 /* Frame transfer function */
111 extern whd_result_t whd_bus_read_frame(whd_driver_t whd_driver, whd_buffer_t *buffer);
112 
113 extern uint32_t     whd_bus_packet_available_to_read(whd_driver_t whd_driver);
114 extern whd_result_t whd_bus_poke_wlan(whd_driver_t whd_driver);
115 extern whd_result_t   whd_bus_wait_for_wlan_event(whd_driver_t whd_driver,  cy_semaphore_t *transceive_semaphore);
116 
117 extern whd_result_t whd_bus_ack_interrupt(whd_driver_t whd_driver, uint32_t intstatus);
118 extern whd_bool_t whd_bus_wake_interrupt_present(whd_driver_t whd_driver);
119 
120 extern whd_result_t whd_bus_set_flow_control(whd_driver_t whd_driver, uint8_t value);
121 extern whd_bool_t whd_bus_is_flow_controlled(whd_driver_t whd_driver);
122 
123 extern whd_result_t whd_bus_wakeup(whd_driver_t whd_driver);
124 extern whd_result_t whd_bus_sleep(whd_driver_t whd_driver);
125 
126 extern uint8_t whd_bus_backplane_read_padd_size(whd_driver_t whd_driver);
127 extern whd_bool_t whd_bus_use_status_report_scheme(whd_driver_t whd_driver);
128 extern uint32_t whd_bus_get_max_transfer_size(whd_driver_t whd_driver);
129 
130 extern void         whd_bus_init_stats(whd_driver_t whd_driver);
131 extern whd_result_t whd_bus_print_stats(whd_driver_t whd_driver, whd_bool_t reset_after_print);
132 extern whd_result_t whd_bus_reinit_stats(whd_driver_t whd_driver, whd_bool_t wake_from_firmware);
133 extern whd_result_t whd_bus_irq_enable(whd_driver_t whd_driver, whd_bool_t enable);
134 extern whd_result_t whd_bus_irq_register(whd_driver_t whd_driver);
135 extern whd_result_t whd_bus_download_resource(whd_driver_t whd_driver, whd_resource_type_t resource,
136 											  whd_bool_t direct_resource, uint32_t address, uint32_t image_size);
137 /******************************************************
138 *             Global variables
139 ******************************************************/
140 
141 #ifdef __cplusplus
142 } /* extern "C" */
143 #endif
144 
145 #endif /* ifndef INCLUDED_WHD_BUS_PROTOCOL_INTERFACE_H_ */
146 
147