1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_XBAR_H_ 10 #define _FSL_XBAR_H_ 11 12 #include "fsl_common.h" 13 14 /*! 15 * @addtogroup xbar 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 #define FSL_XBAR_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) 24 25 /* Macros for entire XBAR_SELx register. */ 26 #define XBAR_SELx(base, output) (((volatile uint16_t *)(&((base)->SEL0)))[(uint32_t)(output) / 2UL]) 27 28 /* Set the XBAR_SELx_SELx field to a new value. */ 29 #define XBAR_WR_SELx_SELx(base, input, output) XBAR_SetSignalsConnection((base), (input), (output)) 30 31 /*! 32 * @brief XBAR active edge for detection 33 */ 34 typedef enum _xbar_active_edge 35 { 36 kXBAR_EdgeNone = 0U, /*!< Edge detection status bit never asserts. */ 37 kXBAR_EdgeRising = 1U, /*!< Edge detection status bit asserts on rising edges. */ 38 kXBAR_EdgeFalling = 2U, /*!< Edge detection status bit asserts on falling edges. */ 39 kXBAR_EdgeRisingAndFalling = 3U /*!< Edge detection status bit asserts on rising and falling edges. */ 40 41 } xbar_active_edge_t; 42 43 /*! 44 * @brief Defines the XBAR DMA and interrupt configurations. 45 */ 46 typedef enum _xbar_request 47 { 48 kXBAR_RequestDisable = 0U, /*!< Interrupt and DMA are disabled. */ 49 kXBAR_RequestDMAEnable = 1U, /*!< DMA enabled, interrupt disabled. */ 50 kXBAR_RequestInterruptEnalbe = 2U /*!< Interrupt enabled, DMA disabled. */ 51 } xbar_request_t; 52 53 /*! 54 * @brief XBAR status flags. 55 * 56 * This provides constants for the XBAR status flags for use in the XBAR 57 * functions. 58 */ 59 typedef enum _xbar_status_flag_t 60 { 61 kXBAR_EdgeDetectionOut0 = 62 (XBAR_CTRL0_STS0_MASK), /*!< XBAR_OUT0 active edge interrupt flag, sets when active edge detected. */ 63 #if FSL_FEATURE_XBAR_INTERRUPT_COUNT > 1 64 kXBAR_EdgeDetectionOut1 = 65 (XBAR_CTRL0_STS1_MASK), /*!< XBAR_OUT1 active edge interrupt flag, sets when active edge detected. */ 66 #endif 67 #if FSL_FEATURE_XBAR_INTERRUPT_COUNT > 2 68 kXBAR_EdgeDetectionOut2 = 69 (XBAR_CTRL1_STS2_MASK << 16U), /*!< XBAR_OUT2 active edge interrupt flag, sets when active edge detected. */ 70 #endif 71 #if FSL_FEATURE_XBAR_INTERRUPT_COUNT > 3 72 kXBAR_EdgeDetectionOut3 = 73 (XBAR_CTRL1_STS3_MASK << 16U), /*!< XBAR_OUT3 active edge interrupt flag, sets when active edge detected. */ 74 #endif 75 } xbar_status_flag_t; 76 77 /*! 78 * @brief Defines the configuration structure of the XBAR control register. 79 * 80 * This structure keeps the configuration of XBAR control register for one output. 81 * Control registers are available only for a few outputs. Not every XBAR module has 82 * control registers. 83 */ 84 typedef struct _xbar_control_config 85 { 86 xbar_active_edge_t activeEdge; /*!< Active edge to be detected. */ 87 xbar_request_t requestType; /*!< Selects DMA/Interrupt request. */ 88 } xbar_control_config_t; 89 90 /******************************************************************************* 91 * API 92 ******************************************************************************/ 93 94 #if defined(__cplusplus) 95 extern "C" { 96 #endif /* __cplusplus */ 97 98 /*! 99 * @name XBAR functional Operation 100 * @{ 101 */ 102 103 /*! 104 * @brief Initializes the XBAR modules. 105 * 106 * This function un-gates the XBAR clock. 107 * 108 * @param base XBAR peripheral address. 109 */ 110 void XBAR_Init(XBAR_Type *base); 111 112 /*! 113 * @brief Shutdown the XBAR modules. 114 * 115 * This function disables XBAR clock. 116 * 117 * @param base XBAR peripheral address. 118 */ 119 void XBAR_Deinit(XBAR_Type *base); 120 121 /*! 122 * @brief Set connection between the selected XBAR_IN[*] input and the XBAR_OUT[*] output signal. 123 * 124 * This function connects the XBAR input to the selected XBAR output. 125 * If more than one XBAR module is available, only the inputs and outputs from the same module 126 * can be connected. 127 * 128 * Example: 129 @code 130 XBAR_SetSignalsConnection(XBAR, kXBAR_InputTMR_CH0_Output, kXBAR_OutputXB_DMA_INT2); 131 @endcode 132 * 133 * @param base XBAR peripheral address 134 * @param input XBAR input signal. 135 * @param output XBAR output signal. 136 */ 137 void XBAR_SetSignalsConnection(XBAR_Type *base, xbar_input_signal_t input, xbar_output_signal_t output); 138 139 /*! 140 * @brief Clears the edge detection status flags of relative mask. 141 * 142 * @param base XBAR peripheral address 143 * @param mask the status flags to clear. 144 */ 145 void XBAR_ClearStatusFlags(XBAR_Type *base, uint32_t mask); 146 147 /*! 148 * @brief Gets the active edge detection status. 149 * 150 * This function gets the active edge detect status of all XBAR_OUTs. If the 151 * active edge occurs, the return value is asserted. When the interrupt or the DMA 152 * functionality is enabled for the XBAR_OUTx, this field is 1 when the interrupt 153 * or DMA request is asserted and 0 when the interrupt or DMA request has been 154 * cleared. 155 * 156 * Example: 157 @code 158 uint32_t status; 159 160 status = XBAR_GetStatusFlags(XBAR); 161 @endcode 162 * 163 * @param base XBAR peripheral address. 164 * @return the mask of these status flag bits. 165 */ 166 uint32_t XBAR_GetStatusFlags(XBAR_Type *base); 167 168 /*! 169 * @brief Configures the XBAR control register. 170 * 171 * This function configures an XBAR control register. The active edge detection 172 * and the DMA/IRQ function on the corresponding XBAR output can be set. 173 * 174 * Example: 175 @code 176 xbar_control_config_t userConfig; 177 userConfig.activeEdge = kXBAR_EdgeRising; 178 userConfig.requestType = kXBAR_RequestInterruptEnalbe; 179 XBAR_SetOutputSignalConfig(XBAR, kXBAR_OutputXB_DMA_INT0, &userConfig); 180 @endcode 181 * 182 * @param base XBAR peripheral address 183 * @param output XBAR output number. 184 * @param controlConfig Pointer to structure that keeps configuration of control register. 185 */ 186 void XBAR_SetOutputSignalConfig(XBAR_Type *base, 187 xbar_output_signal_t output, 188 const xbar_control_config_t *controlConfig); 189 190 #if defined(__cplusplus) 191 } 192 #endif /* __cplusplus */ 193 194 /*! @}*/ 195 196 /*! @}*/ 197 198 #endif /* _FSL_XBAR_H_ */ 199