1 /*
2  * Copyright 2022, 2024 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef FSL_XBAR_H_
9 #define FSL_XBAR_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup xbar
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 #define FSL_XBAR_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
23 
24 #if defined(FSL_FEATURE_XBAR_REG_WIDTH) && (FSL_FEATURE_XBAR_REG_WIDTH == 32)
25 typedef uint32_t xbar_reg_t;
26 #else
27 typedef uint16_t xbar_reg_t;
28 #endif
29 
30 /*!
31  * @brief Find the instance index from base address and register offset mappings.
32  */
33 typedef struct
34 {
35     volatile xbar_reg_t *baseAddr; /* Peripheral base address. */
36     uint16_t regSelOffset;       /* SEL register offset in peripheral. */
37     uint16_t regSelNum;          /* SEL register number in peripheral. */
38     uint16_t regCtrlOffset;      /* CTRL register offset in peripheral. */
39     uint16_t regCtrlNum;         /* CTRL register number in peripheral. */
40 } xbar_info_t;
41 
42 /*!
43  * @brief XBAR active edge for detection
44  */
45 typedef enum _xbar_active_edge
46 {
47     kXBAR_EdgeNone             = 0U, /*!< Edge detection status bit never asserts. */
48     kXBAR_EdgeRising           = 1U, /*!< Edge detection status bit asserts on rising edges. */
49     kXBAR_EdgeFalling          = 2U, /*!< Edge detection status bit asserts on falling edges. */
50     kXBAR_EdgeRisingAndFalling = 3U  /*!< Edge detection status bit asserts on rising and falling edges. */
51 } xbar_active_edge_t;
52 
53 /*!
54  * @brief Defines the XBAR DMA and interrupt configurations.
55  */
56 typedef enum _xbar_request
57 {
58     kXBAR_RequestDisable         = 0U, /*!< Interrupt and DMA are disabled. */
59     kXBAR_RequestDMAEnable       = 1U, /*!< DMA enabled, interrupt disabled. */
60     kXBAR_RequestInterruptEnable = 2U  /*!< Interrupt enabled, DMA disabled. */
61 } xbar_request_t;
62 
63 /*!
64  * @brief Defines the configuration structure of the XBAR control register.
65  *
66  * This structure keeps the configuration of XBAR control register for one output.
67  * Control registers are available only for a few outputs. Not every XBAR module has
68  * control registers.
69  */
70 typedef struct _xbar_control_config
71 {
72     xbar_active_edge_t activeEdge; /*!< Active edge to be detected. */
73     xbar_request_t requestType;    /*!< Selects DMA/Interrupt request. */
74 } xbar_control_config_t;
75 
76 /*******************************************************************************
77  * API
78  ******************************************************************************/
79 
80 #if defined(__cplusplus)
81 extern "C" {
82 #endif /* __cplusplus */
83 
84 /*!
85  * @name XBAR functional Operation
86  * @{
87  */
88 
89 /*!
90  * @brief Initializes the XBAR modules.
91  *
92  * This function un-gates the XBAR clock.
93  *
94  * @param xbarInstance XBAR peripheral address.
95  */
96 void XBAR_Init(xbar_instance_t xbarInstance);
97 
98 /*!
99  * @brief Shutdown the XBAR modules.
100  *
101  * This function disables XBAR clock.
102  *
103  * @param xbarInstance XBAR peripheral address.
104  */
105 void XBAR_Deinit(xbar_instance_t xbarInstance);
106 
107 /*!
108  * @brief Set connection between the selected XBAR_IN[*] input and the XBAR_OUT[*] output signal.
109  *
110  * This function connects the XBAR input to the selected XBAR output.
111  * If more than one XBAR module is available, only the inputs and outputs from the same module
112  * can be connected.
113  *
114  * Example:
115    @code
116    XBAR_SetSignalsConnection(kXBAR_DSC1_InputLogicLow, kXBAR_DSC1_OutputTriggerSyncIn0);
117    @endcode
118  *
119  * @param input XBAR input signal.
120  * @param output XBAR output signal.
121  * @retval kStatus_Success Signal connection set successfully.
122  * @retval kStatus_InvalidArgument Failed because of invalid argument.
123  */
124 status_t XBAR_SetSignalsConnection(xbar_input_signal_t input, xbar_output_signal_t output);
125 
126 /*!
127  * @brief Clears the edge detection status flags.
128  *
129  * @param output XBAR output signal.
130  * @retval kStatus_Success Signal connection set successfully.
131  * @retval kStatus_InvalidArgument Failed because of invalid argument.
132  */
133 status_t XBAR_ClearOutputStatusFlag(xbar_output_signal_t output);
134 
135 /*!
136  * @brief Gets the active edge detection status.
137  *
138  * This function gets the active edge detect status of all XBAR_OUTs. If the
139  * active edge occurs, the return value is asserted. When the interrupt or the DMA
140  * functionality is enabled for the XBAR_OUTx, this field is 1 when the interrupt
141  * or DMA request is asserted and 0 when the interrupt or DMA request has been
142  * cleared.
143  *
144  * @param output XBAR output signal.
145  * @param flag get XBAR output status flag.
146  * @retval kStatus_Success Signal connection set successfully.
147  * @retval kStatus_InvalidArgument Failed because of invalid argument.
148  */
149 status_t XBAR_GetOutputStatusFlag(xbar_output_signal_t output, bool *flag);
150 
151 /*!
152  * @brief Configures the XBAR control register.
153  *
154  * This function configures an XBAR control register. The active edge detection
155  * and the DMA/IRQ function on the corresponding XBAR output can be set.
156  *
157  * Example:
158    @code
159    xbar_control_config_t userConfig;
160    userConfig.activeEdge = kXBAR_EdgeRising;
161    userConfig.requestType = kXBAR_RequestInterruptEnable;
162    XBAR_SetOutputSignalConfig(kXBARA_OutputDMAMUX18, &userConfig);
163    @endcode
164  *
165  * @param output XBAR output signal.
166  * @param controlConfig Pointer to structure that keeps configuration of control register.
167  * @retval kStatus_Success Signal connection set successfully.
168  * @retval kStatus_InvalidArgument Failed because of invalid argument.
169  */
170 status_t XBAR_SetOutputSignalConfig(xbar_output_signal_t output, const xbar_control_config_t *controlConfig);
171 
172 #if defined(__cplusplus)
173 }
174 #endif /* __cplusplus */
175 
176 /*! @}*/
177 
178 /*! @}*/
179 
180 #endif /* FSL_XBAR_H_ */
181