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