Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:02

0001 /*
0002  * Copyright (c) 2015, Freescale Semiconductor, Inc.
0003  * Copyright 2016-2019 NXP
0004  * All rights reserved.
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 
0009 #include "fsl_xbarb.h"
0010 
0011 /*******************************************************************************
0012  * Definitions
0013  ******************************************************************************/
0014 
0015 /* Component ID definition, used by tools. */
0016 #ifndef FSL_COMPONENT_ID
0017 #define FSL_COMPONENT_ID "platform.drivers.xbarb"
0018 #endif
0019 
0020 typedef union
0021 {
0022     uint8_t _u8[2];
0023     uint16_t _u16;
0024 } xbarb_u8_u16_t;
0025 
0026 /*******************************************************************************
0027  * Prototypes
0028  ******************************************************************************/
0029 
0030 /*!
0031  * @brief Get the XBARB instance from peripheral base address.
0032  *
0033  * @param base XBARB peripheral base address.
0034  * @return XBARB instance.
0035  */
0036 static uint32_t XBARB_GetInstance(XBARB_Type *base);
0037 
0038 /*******************************************************************************
0039  * Variables
0040  ******************************************************************************/
0041 
0042 /* Array of XBARB peripheral base address. */
0043 static XBARB_Type *const s_xbarbBases[] = XBARB_BASE_PTRS;
0044 
0045 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0046 /* Array of XBARB clock name. */
0047 static const clock_ip_name_t s_xbarbClock[] = XBARB_CLOCKS;
0048 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0049 
0050 /*******************************************************************************
0051  * Code
0052  ******************************************************************************/
0053 
0054 static uint32_t XBARB_GetInstance(XBARB_Type *base)
0055 {
0056     uint32_t instance;
0057 
0058     /* Find the instance index from base address mappings. */
0059     for (instance = 0; instance < ARRAY_SIZE(s_xbarbBases); instance++)
0060     {
0061         if (s_xbarbBases[instance] == base)
0062         {
0063             break;
0064         }
0065     }
0066 
0067     assert(instance < ARRAY_SIZE(s_xbarbBases));
0068 
0069     return instance;
0070 }
0071 
0072 /*!
0073  * brief Initializes the XBARB module.
0074  *
0075  * This function un-gates the XBARB clock.
0076  *
0077  * param base XBARB peripheral address.
0078  */
0079 void XBARB_Init(XBARB_Type *base)
0080 {
0081 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0082     /* Enable XBARB module clock. */
0083     CLOCK_EnableClock(s_xbarbClock[XBARB_GetInstance(base)]);
0084 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0085 }
0086 
0087 /*!
0088  * brief Shuts down the XBARB module.
0089  *
0090  * This function disables XBARB clock.
0091  *
0092  * param base XBARB peripheral address.
0093  */
0094 void XBARB_Deinit(XBARB_Type *base)
0095 {
0096 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0097     /* Disable XBARB module clock. */
0098     CLOCK_DisableClock(s_xbarbClock[XBARB_GetInstance(base)]);
0099 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0100 }
0101 
0102 /*!
0103  * brief Configures a connection between the selected XBARB_IN[*] input and the XBARB_OUT[*] output signal.
0104  *
0105  * This function configures which XBARB input is connected to the selected XBARB output.
0106  * If more than one XBARB module is available, only the inputs and outputs from the same module
0107  * can be connected.
0108  *
0109  * param base XBARB peripheral address.
0110  * param input XBARB input signal.
0111  * param output XBARB output signal.
0112  */
0113 void XBARB_SetSignalsConnection(XBARB_Type *base, xbar_input_signal_t input, xbar_output_signal_t output)
0114 {
0115     xbarb_u8_u16_t regVal;
0116     uint8_t byteInReg;
0117     uint8_t outputIndex = (uint8_t)output;
0118 
0119     byteInReg = outputIndex % 2U;
0120 
0121     regVal._u16 = XBARB_SELx(base, outputIndex);
0122 
0123     regVal._u8[byteInReg] = (uint8_t)input;
0124 
0125     XBARB_SELx(base, outputIndex) = regVal._u16;
0126 }