1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2019, 2022 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_XBARA_H_ 10 #define _FSL_XBARA_H_ 11 12 #include "fsl_common.h" 13 14 /*! 15 * @addtogroup xbara 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 #define FSL_XBARA_DRIVER_VERSION (MAKE_VERSION(2, 0, 5)) 24 25 /* Macros for entire XBARA_SELx register. */ 26 #define XBARA_SELx(base, output) (((volatile uint16_t *)(&((base)->SEL0)))[(uint32_t)(output) / 2UL]) 27 28 /* Set the XBARA_SELx_SELx field to a new value. */ 29 #define XBARA_WR_SELx_SELx(base, input, output) XBARA_SetSignalsConnection((base), (input), (output)) 30 31 /* For driver backward compatibility. */ 32 #define kXBARA_RequestInterruptEnalbe kXBARA_RequestInterruptEnable 33 34 /*! 35 * @brief XBARA active edge for detection 36 */ 37 typedef enum _xbara_active_edge 38 { 39 kXBARA_EdgeNone = 0U, /*!< Edge detection status bit never asserts. */ 40 kXBARA_EdgeRising = 1U, /*!< Edge detection status bit asserts on rising edges. */ 41 kXBARA_EdgeFalling = 2U, /*!< Edge detection status bit asserts on falling edges. */ 42 kXBARA_EdgeRisingAndFalling = 3U /*!< Edge detection status bit asserts on rising and falling edges. */ 43 } xbara_active_edge_t; 44 45 /*! 46 * @brief Defines the XBARA DMA and interrupt configurations. 47 */ 48 typedef enum _xbar_request 49 { 50 kXBARA_RequestDisable = 0U, /*!< Interrupt and DMA are disabled. */ 51 kXBARA_RequestDMAEnable = 1U, /*!< DMA enabled, interrupt disabled. */ 52 kXBARA_RequestInterruptEnable = 2U /*!< Interrupt enabled, DMA disabled. */ 53 } xbara_request_t; 54 55 /*! 56 * @brief XBARA status flags. 57 * 58 * This provides constants for the XBARA status flags for use in the XBARA functions. 59 */ 60 typedef enum _xbara_status_flag_t 61 { 62 kXBARA_EdgeDetectionOut0 = 63 (XBARA_CTRL0_STS0_MASK), /*!< XBAR_OUT0 active edge interrupt flag, sets when active edge detected. */ 64 kXBARA_EdgeDetectionOut1 = 65 (XBARA_CTRL0_STS1_MASK), /*!< XBAR_OUT1 active edge interrupt flag, sets when active edge detected. */ 66 kXBARA_EdgeDetectionOut2 = 67 (XBARA_CTRL1_STS2_MASK << 16U), /*!< XBAR_OUT2 active edge interrupt flag, sets when active edge detected. */ 68 kXBARA_EdgeDetectionOut3 = 69 (XBARA_CTRL1_STS3_MASK << 16U), /*!< XBAR_OUT3 active edge interrupt flag, sets when active edge detected. */ 70 } xbara_status_flag_t; 71 72 /*! 73 * @brief Defines the configuration structure of the XBARA control register. 74 * 75 * This structure keeps the configuration of XBARA control register for one output. 76 * Control registers are available only for a few outputs. Not every XBARA module has 77 * control registers. 78 */ 79 typedef struct XBARAControlConfig 80 { 81 xbara_active_edge_t activeEdge; /*!< Active edge to be detected. */ 82 xbara_request_t requestType; /*!< Selects DMA/Interrupt request. */ 83 } xbara_control_config_t; 84 85 /******************************************************************************* 86 * API 87 ******************************************************************************/ 88 89 #if defined(__cplusplus) 90 extern "C" { 91 #endif /* __cplusplus */ 92 93 /*! 94 * @name XBARA functional Operation. 95 * @{ 96 */ 97 98 /*! 99 * @brief Initializes the XBARA module. 100 * 101 * This function un-gates the XBARA clock. 102 * 103 * @param base XBARA peripheral address. 104 */ 105 void XBARA_Init(XBARA_Type *base); 106 107 /*! 108 * @brief Shuts down the XBARA module. 109 * 110 * This function disables XBARA clock. 111 * 112 * @param base XBARA peripheral address. 113 */ 114 void XBARA_Deinit(XBARA_Type *base); 115 116 /*! 117 * @brief Sets a connection between the selected XBARA_IN[*] input and the XBARA_OUT[*] output signal. 118 * 119 * This function connects the XBARA input to the selected XBARA output. 120 * If more than one XBARA module is available, only the inputs and outputs from the same module 121 * can be connected. 122 * 123 * Example: 124 @code 125 XBARA_SetSignalsConnection(XBARA, kXBARA_InputPIT_TRG0, kXBARA_OutputDMAMUX18); 126 @endcode 127 * 128 * @param base XBARA peripheral address. 129 * @param input XBARA input signal. 130 * @param output XBARA output signal. 131 */ 132 void XBARA_SetSignalsConnection(XBARA_Type *base, xbar_input_signal_t input, xbar_output_signal_t output); 133 134 /*! 135 * @brief Gets the active edge detection status. 136 * 137 * This function gets the active edge detect status of all XBARA_OUTs. If the 138 * active edge occurs, the return value is asserted. When the interrupt or the DMA 139 * functionality is enabled for the XBARA_OUTx, this field is 1 when the interrupt 140 * or DMA request is asserted and 0 when the interrupt or DMA request has been 141 * cleared. 142 * 143 * @param base XBARA peripheral address. 144 * @return the mask of these status flag bits. 145 */ 146 uint32_t XBARA_GetStatusFlags(XBARA_Type *base); 147 148 /*! 149 * @brief Clears the edge detection status flags of relative mask. 150 * 151 * @param base XBARA peripheral address. 152 * @param mask the status flags to clear. 153 */ 154 void XBARA_ClearStatusFlags(XBARA_Type *base, uint32_t mask); 155 156 /*! 157 * @brief Configures the XBARA control register. 158 * 159 * This function configures an XBARA control register. The active edge detection 160 * and the DMA/IRQ function on the corresponding XBARA output can be set. 161 * 162 * Example: 163 @code 164 xbara_control_config_t userConfig; 165 userConfig.activeEdge = kXBARA_EdgeRising; 166 userConfig.requestType = kXBARA_RequestInterruptEnalbe; 167 XBARA_SetOutputSignalConfig(XBARA, kXBARA_OutputDMAMUX18, &userConfig); 168 @endcode 169 * 170 * @param base XBARA peripheral address. 171 * @param output XBARA output number. 172 * @param controlConfig Pointer to structure that keeps configuration of control register. 173 */ 174 void XBARA_SetOutputSignalConfig(XBARA_Type *base, 175 xbar_output_signal_t output, 176 const xbara_control_config_t *controlConfig); 177 178 #if defined(__cplusplus) 179 } 180 #endif /* __cplusplus */ 181 182 /*! @}*/ 183 184 /*!* @} */ 185 186 #endif /* _FSL_XBARA_H_ */ 187