1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 #ifndef LIBRARIES_PERIPHDRIVERS_SOURCE_SPIMSS_SPIMSS_REVA_H_
22 #define LIBRARIES_PERIPHDRIVERS_SOURCE_SPIMSS_SPIMSS_REVA_H_
23 
24 #include <stdio.h>
25 #include <stddef.h>
26 #include <stdint.h>
27 #include "mxc_errors.h"
28 #include "mxc_device.h"
29 #include "mxc_assert.h"
30 #include "mxc_lock.h"
31 #include "mxc_sys.h"
32 #include "mxc_delay.h"
33 #include "spimss_regs.h"
34 #include "spimss_reva_regs.h"
35 #include "spimss.h"
36 
37 /**
38  * @brief Enumeration type for setting the number data lines to use for communication.
39  */
40 typedef enum { // ONLY FOR COMPATIBILITY FOR CONSOLIDATION WITH SPY17, NOT USED OR NEEDED
41     DUMMY_1_RevA, /**< NOT USED                */
42     DUMMY_2_RevA, /**< NOT USED                */
43     DUMMY_3_RevA, /**< NOT USED                */
44 } spimss_reva_width_t;
45 
46 /**
47  * @brief Structure type representing a SPI Master Transaction request.
48  */
49 typedef struct spimss_reva_req spimss_reva_req_t;
50 
51 /**
52  * @brief Callback function type used in asynchronous SPI Master communication requests.
53  * @details The function declaration for the SPI Master callback is:
54  * @code
55  * void callback(spi_req_t * req, int error_code);
56  * @endcode
57  * |        |                                            |
58  * | -----: | :----------------------------------------- |
59  * | \p req |  Pointer to a #spi_req object representing the active SPI Master active transaction. |
60  * | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
61  * @note Callback will execute in interrupt context
62  * @addtogroup spi_async
63  */
64 typedef void (*spimss_reva_callback_fn)(spimss_reva_req_t *req, int error_code);
65 
66 /**
67  * @brief      Structure definition for an SPI Master Transaction request.
68  * @note       When using this structure for an asynchronous operation, the
69  *             structure must remain allocated until the callback is completed.
70  * @addtogroup spi_async
71  */
72 struct spimss_reva_req {
73     uint8_t ssel; /**< Not Used*/
74     uint8_t deass; /**< Not Used*/
75     void *tx_data; /**< Pointer to a buffer to transmit data from. NULL if undesired. */
76     void *rx_data; /**< Pointer to a buffer to store data received. NULL if undesired.*/
77     spimss_reva_width_t width; /**< Not Used */
78     unsigned len; /**< Number of transfer units to send from the \p tx_data buffer. */
79     unsigned bits; /**< Number of bits in transfer unit (e.g. 8 for byte, 16 for short) */
80     unsigned rx_num; /**< Number of bytes actually read into the \p rx_data buffer. */
81     unsigned tx_num; /**< Number of bytes actually sent from the \p tx_data buffer */
82     spimss_reva_callback_fn callback; /**< Callback function if desired, NULL otherwise */
83 };
84 
85 int MXC_SPIMSS_RevA_Init(mxc_spimss_reva_regs_t *spi, unsigned mode, unsigned freq);
86 int MXC_SPIMSS_RevA_Shutdown(mxc_spimss_reva_regs_t *spi);
87 void MXC_SPIMSS_RevA_Handler(mxc_spimss_reva_regs_t *spi);
88 int MXC_SPIMSS_RevA_MasterTrans(mxc_spimss_reva_regs_t *spi, spimss_reva_req_t *req);
89 int MXC_SPIMSS_RevA_MasterTransDMA(mxc_spimss_reva_regs_t *spi, spimss_reva_req_t *req);
90 int MXC_SPIMSS_RevA_SlaveTrans(mxc_spimss_reva_regs_t *spi, spimss_reva_req_t *req);
91 int MXC_SPIMSS_RevA_MasterTransAsync(mxc_spimss_reva_regs_t *spi, spimss_reva_req_t *req);
92 int MXC_SPIMSS_RevA_SlaveTransAsync(mxc_spimss_reva_regs_t *spi, spimss_reva_req_t *req);
93 int MXC_SPIMSS_RevA_AbortAsync(spimss_reva_req_t *req);
94 
95 int MXC_SPIMSS_RevA_SetAutoDMAHandlers(mxc_spimss_reva_regs_t *spi, bool enable);
96 int MXC_SPIMSS_RevA_SetTXDMAChannel(mxc_spimss_reva_regs_t *spi, unsigned int channel);
97 int MXC_SPIMSS_RevA_GetTXDMAChannel(mxc_spimss_reva_regs_t *spi);
98 int MXC_SPIMSS_RevA_SetRXDMAChannel(mxc_spimss_reva_regs_t *spi, unsigned int channel);
99 int MXC_SPIMSS_RevA_GetRXDMAChannel(mxc_spimss_reva_regs_t *spi);
100 
101 #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_SPIMSS_SPIMSS_REVA_H_
102