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 "whd.h"
19 #include "whd_bus_protocol_interface.h"
20 #include "cy_result.h"
21 #include "cyhal_spi.h"
22 
23 #ifndef INCLUDED_SPI_WHD_BUS_PROTOCOL_H
24 #define INCLUDED_SPI_WHD_BUS_PROTOCOL_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /******************************************************
31 *             Constants
32 ******************************************************/
33 
34 /******************************************************
35 *             Structures
36 ******************************************************/
37 
38 typedef uint32_t whd_bus_gspi_header_t;
39 
40 #pragma pack(1)
41 
42 typedef struct
43 {
44     whd_bus_gspi_header_t gspi_header;
45 } whd_bus_header_t;
46 
47 #pragma pack()
48 
49 #define WHD_BUS_SPI_HEADER_SIZE                     (sizeof(whd_bus_header_t) )
50 
51 #define WHD_BUS_SPI_USE_STATUS_REPORT_SCHEME        (1 == 1)
52 
53 #define WHD_BUS_SPI_MAX_BACKPLANE_TRANSFER_SIZE     (64)  /* Max packet size on F1 */
54 #define WHD_BUS_SPI_BACKPLANE_READ_PADD_SIZE        (4)
55 
56 /******************************************************
57 *             Function declarations
58 ******************************************************/
59 extern whd_result_t whd_bus_spi_send_buffer(whd_driver_t whd_driver, whd_buffer_t buffer);
60 extern whd_result_t whd_bus_spi_poke_wlan(whd_driver_t whd_driver);
61 extern whd_result_t whd_bus_spi_ack_interrupt(whd_driver_t whd_driver, uint32_t intstatus);
62 extern uint32_t whd_bus_spi_packet_available_to_read(whd_driver_t whd_driver);
63 extern whd_result_t whd_bus_spi_read_frame(whd_driver_t whd_driver, whd_buffer_t *buffer);
64 extern whd_result_t whd_bus_spi_init(whd_driver_t whd_driver);
65 extern whd_result_t whd_bus_spi_deinit(whd_driver_t whd_driver);
66 extern whd_bool_t whd_bus_spi_wake_interrupt_present(whd_driver_t whd_driver);
67 extern whd_result_t whd_bus_spi_wait_for_wlan_event(whd_driver_t whd_driver,
68                                                     cy_semaphore_t *transceive_semaphore);
69 extern whd_result_t whd_bus_spi_write_register_value(whd_driver_t whd_driver, whd_bus_function_t function,
70                                                      uint32_t address, uint8_t value_length, uint32_t value);
71 extern whd_result_t whd_bus_spi_read_register_value(whd_driver_t whd_driver, whd_bus_function_t function,
72                                                     uint32_t address, uint8_t value_length, uint8_t *value);
73 extern whd_result_t whd_bus_spi_write_backplane_value(whd_driver_t whd_driver, uint32_t address,
74                                                       uint8_t register_length, uint32_t value);
75 extern whd_result_t whd_bus_spi_read_backplane_value(whd_driver_t whd_driver, uint32_t address, uint8_t register_length,
76                                                      uint8_t *value);
77 extern whd_result_t whd_bus_spi_transfer_bytes(whd_driver_t whd_driver, whd_bus_transfer_direction_t direction,
78                                                whd_bus_function_t function, uint32_t address, uint16_t size,
79                                                whd_transfer_bytes_packet_t *packet);
80 extern whd_result_t whd_bus_spi_wakeup(whd_driver_t whd_driver);
81 extern whd_result_t whd_bus_spi_sleep(whd_driver_t whd_driver);
82 extern void whd_bus_spi_init_stats(whd_driver_t whd_driver);
83 extern whd_result_t whd_bus_spi_print_stats(whd_driver_t whd_driver, whd_bool_t reset_after_print);
84 extern whd_result_t whd_bus_spi_reinit_stats(whd_driver_t whd_driver, whd_bool_t wake_from_firmware);
85 extern uint8_t whd_bus_spi_backplane_read_padd_size(whd_driver_t whd_driver);
86 extern whd_bool_t whd_bus_spi_use_status_report_scheme(whd_driver_t whd_driver);
87 extern uint32_t whd_bus_spi_get_max_transfer_size(whd_driver_t whd_driver);
88 extern whd_result_t whd_bus_spi_irq_register(whd_driver_t whd_driver);
89 extern whd_result_t whd_bus_spi_irq_enable(whd_driver_t whd_driver, whd_bool_t enable);
90 #if (CYHAL_API_VERSION >= 2)
91 extern void whd_bus_spi_irq_handler(void *handler_arg, cyhal_spi_event_t event);
92 #else
93 extern void whd_bus_spi_irq_handler(void *handler_arg, cyhal_spi_irq_event_t event);
94 #endif
95 /******************************************************
96 *             Global variables
97 ******************************************************/
98 
99 #ifdef __cplusplus
100 } /*extern "C" */
101 #endif
102 
103 #endif /* ifndef INCLUDED_SPI_WHD_BUS_PROTOCOL_H */
104 
105