Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:58

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 #include "fsl_aoi.h"
0009 
0010 /* Component ID definition, used by tools. */
0011 #ifndef FSL_COMPONENT_ID
0012 #define FSL_COMPONENT_ID "platform.drivers.aoi"
0013 #endif
0014 
0015 /*******************************************************************************
0016  * Variables
0017  ******************************************************************************/
0018 /*! @brief Pointers to aoi bases for each instance. */
0019 static AOI_Type *const s_aoiBases[] = AOI_BASE_PTRS;
0020 
0021 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0022 /*! @brief Pointers to aoi clocks for each instance. */
0023 static const clock_ip_name_t s_aoiClocks[] = AOI_CLOCKS;
0024 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0025        /*******************************************************************************
0026         * Prototypes
0027         ******************************************************************************/
0028 /*!
0029  * @brief Get instance number for AOI module.
0030  *
0031  * @param base AOI peripheral base address
0032  *
0033  * @return The AOI instance
0034  */
0035 static uint32_t AOI_GetInstance(AOI_Type *base);
0036 /*******************************************************************************
0037  * Code
0038  ******************************************************************************/
0039 
0040 static uint32_t AOI_GetInstance(AOI_Type *base)
0041 {
0042     uint32_t instance;
0043 
0044     /* Find the instance index from base address mappings. */
0045     for (instance = 0; instance < ARRAY_SIZE(s_aoiBases); instance++)
0046     {
0047         if (s_aoiBases[instance] == base)
0048         {
0049             break;
0050         }
0051     }
0052 
0053     assert(instance < ARRAY_SIZE(s_aoiBases));
0054 
0055     return instance;
0056 }
0057 
0058 /*!
0059  * brief Initializes an AOI instance for operation.
0060  *
0061  * This function un-gates the AOI clock.
0062  *
0063  * param base AOI peripheral address.
0064  */
0065 void AOI_Init(AOI_Type *base)
0066 {
0067 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0068     /* Enable the clock gate from clock manager. */
0069     CLOCK_EnableClock(s_aoiClocks[AOI_GetInstance(base)]);
0070 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0071 }
0072 
0073 /*!
0074  * brief Deinitializes an AOI instance for operation.
0075  *
0076  * This function shutdowns AOI module.
0077  *
0078  * param  base AOI peripheral address.
0079  */
0080 void AOI_Deinit(AOI_Type *base)
0081 {
0082 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0083     /* Disable the clock gate from clock manager */
0084     CLOCK_DisableClock(s_aoiClocks[AOI_GetInstance(base)]);
0085 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0086 }
0087 
0088 /*!
0089  * brief Gets the Boolean evaluation associated.
0090  *
0091  * This function returns the Boolean evaluation associated.
0092  *
0093  * Example:
0094   code
0095     aoi_event_config_t demoEventLogicStruct;
0096 
0097     AOI_GetEventLogicConfig(AOI, kAOI_Event0, &demoEventLogicStruct);
0098   endcode
0099  *
0100  * param  base AOI peripheral address.
0101  * param  event Index of the event which will be set of type aoi_event_t.
0102  * param  config Selected input configuration .
0103  */
0104 void AOI_GetEventLogicConfig(AOI_Type *base, aoi_event_t event, aoi_event_config_t *config)
0105 {
0106     assert((uint32_t)event < (uint32_t)FSL_FEATURE_AOI_EVENT_COUNT);
0107     assert(config != NULL);
0108 
0109     uint16_t value;
0110     uint16_t temp;
0111     /* Read BFCRT01 register at event index. */
0112     value = base->BFCRT[event].BFCRT01;
0113 
0114     temp          = (value & AOI_BFCRT01_PT0_AC_MASK) >> AOI_BFCRT01_PT0_AC_SHIFT;
0115     config->PT0AC = (aoi_input_config_t)temp;
0116     temp          = (value & AOI_BFCRT01_PT0_BC_MASK) >> AOI_BFCRT01_PT0_BC_SHIFT;
0117     config->PT0BC = (aoi_input_config_t)temp;
0118     temp          = (value & AOI_BFCRT01_PT0_CC_MASK) >> AOI_BFCRT01_PT0_CC_SHIFT;
0119     config->PT0CC = (aoi_input_config_t)temp;
0120     temp          = (value & AOI_BFCRT01_PT0_DC_MASK) >> AOI_BFCRT01_PT0_DC_SHIFT;
0121     config->PT0DC = (aoi_input_config_t)temp;
0122 
0123     temp          = (value & AOI_BFCRT01_PT1_AC_MASK) >> AOI_BFCRT01_PT1_AC_SHIFT;
0124     config->PT1AC = (aoi_input_config_t)temp;
0125     temp          = (value & AOI_BFCRT01_PT1_BC_MASK) >> AOI_BFCRT01_PT1_BC_SHIFT;
0126     config->PT1BC = (aoi_input_config_t)temp;
0127     temp          = (value & AOI_BFCRT01_PT1_CC_MASK) >> AOI_BFCRT01_PT1_CC_SHIFT;
0128     config->PT1CC = (aoi_input_config_t)temp;
0129     temp          = (value & AOI_BFCRT01_PT1_DC_MASK) >> AOI_BFCRT01_PT1_DC_SHIFT;
0130     config->PT1DC = (aoi_input_config_t)temp;
0131 
0132     /* Read BFCRT23 register at event index. */
0133     value = base->BFCRT[event].BFCRT23;
0134 
0135     temp          = (value & AOI_BFCRT23_PT2_AC_MASK) >> AOI_BFCRT23_PT2_AC_SHIFT;
0136     config->PT2AC = (aoi_input_config_t)temp;
0137     temp          = (value & AOI_BFCRT23_PT2_BC_MASK) >> AOI_BFCRT23_PT2_BC_SHIFT;
0138     config->PT2BC = (aoi_input_config_t)temp;
0139     temp          = (value & AOI_BFCRT23_PT2_CC_MASK) >> AOI_BFCRT23_PT2_CC_SHIFT;
0140     config->PT2CC = (aoi_input_config_t)temp;
0141     temp          = (value & AOI_BFCRT23_PT2_DC_MASK) >> AOI_BFCRT23_PT2_DC_SHIFT;
0142     config->PT2DC = (aoi_input_config_t)temp;
0143 
0144     temp          = (value & AOI_BFCRT23_PT3_AC_MASK) >> AOI_BFCRT23_PT3_AC_SHIFT;
0145     config->PT3AC = (aoi_input_config_t)temp;
0146     temp          = (value & AOI_BFCRT23_PT3_BC_MASK) >> AOI_BFCRT23_PT3_BC_SHIFT;
0147     config->PT3BC = (aoi_input_config_t)temp;
0148     temp          = (value & AOI_BFCRT23_PT3_CC_MASK) >> AOI_BFCRT23_PT3_CC_SHIFT;
0149     config->PT3CC = (aoi_input_config_t)temp;
0150     temp          = (value & AOI_BFCRT23_PT3_DC_MASK) >> AOI_BFCRT23_PT3_DC_SHIFT;
0151     config->PT3DC = (aoi_input_config_t)temp;
0152 }
0153 
0154 /*!
0155  * brief Configures an AOI event.
0156  *
0157  * This function configures an AOI event according
0158  * to the aoiEventConfig structure. This function configures all  inputs (A, B, C, and D)
0159  * of all  product terms (0, 1, 2, and 3) of a desired event.
0160  *
0161  * Example:
0162   code
0163     aoi_event_config_t demoEventLogicStruct;
0164 
0165     demoEventLogicStruct.PT0AC = kAOI_InvInputSignal;
0166     demoEventLogicStruct.PT0BC = kAOI_InputSignal;
0167     demoEventLogicStruct.PT0CC = kAOI_LogicOne;
0168     demoEventLogicStruct.PT0DC = kAOI_LogicOne;
0169 
0170     demoEventLogicStruct.PT1AC = kAOI_LogicZero;
0171     demoEventLogicStruct.PT1BC = kAOI_LogicOne;
0172     demoEventLogicStruct.PT1CC = kAOI_LogicOne;
0173     demoEventLogicStruct.PT1DC = kAOI_LogicOne;
0174 
0175     demoEventLogicStruct.PT2AC = kAOI_LogicZero;
0176     demoEventLogicStruct.PT2BC = kAOI_LogicOne;
0177     demoEventLogicStruct.PT2CC = kAOI_LogicOne;
0178     demoEventLogicStruct.PT2DC = kAOI_LogicOne;
0179 
0180     demoEventLogicStruct.PT3AC = kAOI_LogicZero;
0181     demoEventLogicStruct.PT3BC = kAOI_LogicOne;
0182     demoEventLogicStruct.PT3CC = kAOI_LogicOne;
0183     demoEventLogicStruct.PT3DC = kAOI_LogicOne;
0184 
0185     AOI_SetEventLogicConfig(AOI, kAOI_Event0, demoEventLogicStruct);
0186   endcode
0187  *
0188  * param  base AOI peripheral address.
0189  * param  event Event which will be configured of type aoi_event_t.
0190  * param  eventConfig Pointer to type aoi_event_config_t structure. The user is responsible for
0191  * filling out the members of this structure and passing the pointer to this function.
0192  */
0193 void AOI_SetEventLogicConfig(AOI_Type *base, aoi_event_t event, const aoi_event_config_t *eventConfig)
0194 {
0195     assert(eventConfig != NULL);
0196     assert((uint32_t)event < (uint32_t)FSL_FEATURE_AOI_EVENT_COUNT);
0197 
0198     uint16_t value;
0199     /* Calculate value to configure product term 0, 1 */
0200     value = AOI_BFCRT01_PT0_AC(eventConfig->PT0AC) | AOI_BFCRT01_PT0_BC(eventConfig->PT0BC) |
0201             AOI_BFCRT01_PT0_CC(eventConfig->PT0CC) | AOI_BFCRT01_PT0_DC(eventConfig->PT0DC) |
0202             AOI_BFCRT01_PT1_AC(eventConfig->PT1AC) | AOI_BFCRT01_PT1_BC(eventConfig->PT1BC) |
0203             AOI_BFCRT01_PT1_CC(eventConfig->PT1CC) | AOI_BFCRT01_PT1_DC(eventConfig->PT1DC);
0204     /* Write value to register */
0205     base->BFCRT[event].BFCRT01 = value;
0206 
0207     /* Reset and calculate value to configure product term 2, 3 */
0208     value = AOI_BFCRT23_PT2_AC(eventConfig->PT2AC) | AOI_BFCRT23_PT2_BC(eventConfig->PT2BC) |
0209             AOI_BFCRT23_PT2_CC(eventConfig->PT2CC) | AOI_BFCRT23_PT2_DC(eventConfig->PT2DC) |
0210             AOI_BFCRT23_PT3_AC(eventConfig->PT3AC) | AOI_BFCRT23_PT3_BC(eventConfig->PT3BC) |
0211             AOI_BFCRT23_PT3_CC(eventConfig->PT3CC) | AOI_BFCRT23_PT3_DC(eventConfig->PT3DC);
0212     /* Write value to register */
0213     base->BFCRT[event].BFCRT23 = value;
0214 }