Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

215 строки
8.1 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2019 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include "fsl_aoi.h"
  9. /* Component ID definition, used by tools. */
  10. #ifndef FSL_COMPONENT_ID
  11. #define FSL_COMPONENT_ID "platform.drivers.aoi"
  12. #endif
  13. /*******************************************************************************
  14. * Variables
  15. ******************************************************************************/
  16. /*! @brief Pointers to aoi bases for each instance. */
  17. static AOI_Type *const s_aoiBases[] = AOI_BASE_PTRS;
  18. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  19. /*! @brief Pointers to aoi clocks for each instance. */
  20. static const clock_ip_name_t s_aoiClocks[] = AOI_CLOCKS;
  21. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  22. /*******************************************************************************
  23. * Prototypes
  24. ******************************************************************************/
  25. /*!
  26. * @brief Get instance number for AOI module.
  27. *
  28. * @param base AOI peripheral base address
  29. *
  30. * @return The AOI instance
  31. */
  32. static uint32_t AOI_GetInstance(AOI_Type *base);
  33. /*******************************************************************************
  34. * Code
  35. ******************************************************************************/
  36. static uint32_t AOI_GetInstance(AOI_Type *base)
  37. {
  38. uint32_t instance;
  39. /* Find the instance index from base address mappings. */
  40. for (instance = 0; instance < ARRAY_SIZE(s_aoiBases); instance++)
  41. {
  42. if (s_aoiBases[instance] == base)
  43. {
  44. break;
  45. }
  46. }
  47. assert(instance < ARRAY_SIZE(s_aoiBases));
  48. return instance;
  49. }
  50. /*!
  51. * brief Initializes an AOI instance for operation.
  52. *
  53. * This function un-gates the AOI clock.
  54. *
  55. * param base AOI peripheral address.
  56. */
  57. void AOI_Init(AOI_Type *base)
  58. {
  59. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  60. /* Enable the clock gate from clock manager. */
  61. CLOCK_EnableClock(s_aoiClocks[AOI_GetInstance(base)]);
  62. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  63. }
  64. /*!
  65. * brief Deinitializes an AOI instance for operation.
  66. *
  67. * This function shutdowns AOI module.
  68. *
  69. * param base AOI peripheral address.
  70. */
  71. void AOI_Deinit(AOI_Type *base)
  72. {
  73. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  74. /* Disable the clock gate from clock manager */
  75. CLOCK_DisableClock(s_aoiClocks[AOI_GetInstance(base)]);
  76. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  77. }
  78. /*!
  79. * brief Gets the Boolean evaluation associated.
  80. *
  81. * This function returns the Boolean evaluation associated.
  82. *
  83. * Example:
  84. code
  85. aoi_event_config_t demoEventLogicStruct;
  86. AOI_GetEventLogicConfig(AOI, kAOI_Event0, &demoEventLogicStruct);
  87. endcode
  88. *
  89. * param base AOI peripheral address.
  90. * param event Index of the event which will be set of type aoi_event_t.
  91. * param config Selected input configuration .
  92. */
  93. void AOI_GetEventLogicConfig(AOI_Type *base, aoi_event_t event, aoi_event_config_t *config)
  94. {
  95. assert((uint32_t)event < (uint32_t)FSL_FEATURE_AOI_EVENT_COUNT);
  96. assert(config != NULL);
  97. uint16_t value;
  98. uint16_t temp;
  99. /* Read BFCRT01 register at event index. */
  100. value = base->BFCRT[event].BFCRT01;
  101. temp = (value & AOI_BFCRT01_PT0_AC_MASK) >> AOI_BFCRT01_PT0_AC_SHIFT;
  102. config->PT0AC = (aoi_input_config_t)temp;
  103. temp = (value & AOI_BFCRT01_PT0_BC_MASK) >> AOI_BFCRT01_PT0_BC_SHIFT;
  104. config->PT0BC = (aoi_input_config_t)temp;
  105. temp = (value & AOI_BFCRT01_PT0_CC_MASK) >> AOI_BFCRT01_PT0_CC_SHIFT;
  106. config->PT0CC = (aoi_input_config_t)temp;
  107. temp = (value & AOI_BFCRT01_PT0_DC_MASK) >> AOI_BFCRT01_PT0_DC_SHIFT;
  108. config->PT0DC = (aoi_input_config_t)temp;
  109. temp = (value & AOI_BFCRT01_PT1_AC_MASK) >> AOI_BFCRT01_PT1_AC_SHIFT;
  110. config->PT1AC = (aoi_input_config_t)temp;
  111. temp = (value & AOI_BFCRT01_PT1_BC_MASK) >> AOI_BFCRT01_PT1_BC_SHIFT;
  112. config->PT1BC = (aoi_input_config_t)temp;
  113. temp = (value & AOI_BFCRT01_PT1_CC_MASK) >> AOI_BFCRT01_PT1_CC_SHIFT;
  114. config->PT1CC = (aoi_input_config_t)temp;
  115. temp = (value & AOI_BFCRT01_PT1_DC_MASK) >> AOI_BFCRT01_PT1_DC_SHIFT;
  116. config->PT1DC = (aoi_input_config_t)temp;
  117. /* Read BFCRT23 register at event index. */
  118. value = base->BFCRT[event].BFCRT23;
  119. temp = (value & AOI_BFCRT23_PT2_AC_MASK) >> AOI_BFCRT23_PT2_AC_SHIFT;
  120. config->PT2AC = (aoi_input_config_t)temp;
  121. temp = (value & AOI_BFCRT23_PT2_BC_MASK) >> AOI_BFCRT23_PT2_BC_SHIFT;
  122. config->PT2BC = (aoi_input_config_t)temp;
  123. temp = (value & AOI_BFCRT23_PT2_CC_MASK) >> AOI_BFCRT23_PT2_CC_SHIFT;
  124. config->PT2CC = (aoi_input_config_t)temp;
  125. temp = (value & AOI_BFCRT23_PT2_DC_MASK) >> AOI_BFCRT23_PT2_DC_SHIFT;
  126. config->PT2DC = (aoi_input_config_t)temp;
  127. temp = (value & AOI_BFCRT23_PT3_AC_MASK) >> AOI_BFCRT23_PT3_AC_SHIFT;
  128. config->PT3AC = (aoi_input_config_t)temp;
  129. temp = (value & AOI_BFCRT23_PT3_BC_MASK) >> AOI_BFCRT23_PT3_BC_SHIFT;
  130. config->PT3BC = (aoi_input_config_t)temp;
  131. temp = (value & AOI_BFCRT23_PT3_CC_MASK) >> AOI_BFCRT23_PT3_CC_SHIFT;
  132. config->PT3CC = (aoi_input_config_t)temp;
  133. temp = (value & AOI_BFCRT23_PT3_DC_MASK) >> AOI_BFCRT23_PT3_DC_SHIFT;
  134. config->PT3DC = (aoi_input_config_t)temp;
  135. }
  136. /*!
  137. * brief Configures an AOI event.
  138. *
  139. * This function configures an AOI event according
  140. * to the aoiEventConfig structure. This function configures all inputs (A, B, C, and D)
  141. * of all product terms (0, 1, 2, and 3) of a desired event.
  142. *
  143. * Example:
  144. code
  145. aoi_event_config_t demoEventLogicStruct;
  146. demoEventLogicStruct.PT0AC = kAOI_InvInputSignal;
  147. demoEventLogicStruct.PT0BC = kAOI_InputSignal;
  148. demoEventLogicStruct.PT0CC = kAOI_LogicOne;
  149. demoEventLogicStruct.PT0DC = kAOI_LogicOne;
  150. demoEventLogicStruct.PT1AC = kAOI_LogicZero;
  151. demoEventLogicStruct.PT1BC = kAOI_LogicOne;
  152. demoEventLogicStruct.PT1CC = kAOI_LogicOne;
  153. demoEventLogicStruct.PT1DC = kAOI_LogicOne;
  154. demoEventLogicStruct.PT2AC = kAOI_LogicZero;
  155. demoEventLogicStruct.PT2BC = kAOI_LogicOne;
  156. demoEventLogicStruct.PT2CC = kAOI_LogicOne;
  157. demoEventLogicStruct.PT2DC = kAOI_LogicOne;
  158. demoEventLogicStruct.PT3AC = kAOI_LogicZero;
  159. demoEventLogicStruct.PT3BC = kAOI_LogicOne;
  160. demoEventLogicStruct.PT3CC = kAOI_LogicOne;
  161. demoEventLogicStruct.PT3DC = kAOI_LogicOne;
  162. AOI_SetEventLogicConfig(AOI, kAOI_Event0, demoEventLogicStruct);
  163. endcode
  164. *
  165. * param base AOI peripheral address.
  166. * param event Event which will be configured of type aoi_event_t.
  167. * param eventConfig Pointer to type aoi_event_config_t structure. The user is responsible for
  168. * filling out the members of this structure and passing the pointer to this function.
  169. */
  170. void AOI_SetEventLogicConfig(AOI_Type *base, aoi_event_t event, const aoi_event_config_t *eventConfig)
  171. {
  172. assert(eventConfig != NULL);
  173. assert((uint32_t)event < (uint32_t)FSL_FEATURE_AOI_EVENT_COUNT);
  174. uint16_t value;
  175. /* Calculate value to configure product term 0, 1 */
  176. value = AOI_BFCRT01_PT0_AC(eventConfig->PT0AC) | AOI_BFCRT01_PT0_BC(eventConfig->PT0BC) |
  177. AOI_BFCRT01_PT0_CC(eventConfig->PT0CC) | AOI_BFCRT01_PT0_DC(eventConfig->PT0DC) |
  178. AOI_BFCRT01_PT1_AC(eventConfig->PT1AC) | AOI_BFCRT01_PT1_BC(eventConfig->PT1BC) |
  179. AOI_BFCRT01_PT1_CC(eventConfig->PT1CC) | AOI_BFCRT01_PT1_DC(eventConfig->PT1DC);
  180. /* Write value to register */
  181. base->BFCRT[event].BFCRT01 = value;
  182. /* Reset and calculate value to configure product term 2, 3 */
  183. value = AOI_BFCRT23_PT2_AC(eventConfig->PT2AC) | AOI_BFCRT23_PT2_BC(eventConfig->PT2BC) |
  184. AOI_BFCRT23_PT2_CC(eventConfig->PT2CC) | AOI_BFCRT23_PT2_DC(eventConfig->PT2DC) |
  185. AOI_BFCRT23_PT3_AC(eventConfig->PT3AC) | AOI_BFCRT23_PT3_BC(eventConfig->PT3BC) |
  186. AOI_BFCRT23_PT3_CC(eventConfig->PT3CC) | AOI_BFCRT23_PT3_DC(eventConfig->PT3DC);
  187. /* Write value to register */
  188. base->BFCRT[event].BFCRT23 = value;
  189. }