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

164 строки
5.2 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017, 2019 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include "fsl_pdb.h"
  9. /* Component ID definition, used by tools. */
  10. #ifndef FSL_COMPONENT_ID
  11. #define FSL_COMPONENT_ID "platform.drivers.pdb"
  12. #endif
  13. /*******************************************************************************
  14. * Prototypes
  15. ******************************************************************************/
  16. /*!
  17. * @brief Get instance number for PDB module.
  18. *
  19. * @param base PDB peripheral base address
  20. */
  21. static uint32_t PDB_GetInstance(PDB_Type *base);
  22. /*******************************************************************************
  23. * Variables
  24. ******************************************************************************/
  25. /*! @brief Pointers to PDB bases for each instance. */
  26. static PDB_Type *const s_pdbBases[] = PDB_BASE_PTRS;
  27. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  28. /*! @brief Pointers to PDB clocks for each instance. */
  29. static const clock_ip_name_t s_pdbClocks[] = PDB_CLOCKS;
  30. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  31. /*******************************************************************************
  32. * Codes
  33. ******************************************************************************/
  34. static uint32_t PDB_GetInstance(PDB_Type *base)
  35. {
  36. uint32_t instance;
  37. /* Find the instance index from base address mappings. */
  38. for (instance = 0; instance < ARRAY_SIZE(s_pdbBases); instance++)
  39. {
  40. if (s_pdbBases[instance] == base)
  41. {
  42. break;
  43. }
  44. }
  45. assert(instance < ARRAY_SIZE(s_pdbBases));
  46. return instance;
  47. }
  48. /*!
  49. * brief Initializes the PDB module.
  50. *
  51. * This function initializes the PDB module. The operations included are as follows.
  52. * - Enable the clock for PDB instance.
  53. * - Configure the PDB module.
  54. * - Enable the PDB module.
  55. *
  56. * param base PDB peripheral base address.
  57. * param config Pointer to the configuration structure. See "pdb_config_t".
  58. */
  59. void PDB_Init(PDB_Type *base, const pdb_config_t *config)
  60. {
  61. assert(NULL != config);
  62. uint32_t tmp32;
  63. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  64. /* Enable the clock. */
  65. CLOCK_EnableClock(s_pdbClocks[PDB_GetInstance(base)]);
  66. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  67. /* Configure. */
  68. /* PDBx_SC. */
  69. tmp32 = base->SC &
  70. ~(PDB_SC_LDMOD_MASK | PDB_SC_PRESCALER_MASK | PDB_SC_TRGSEL_MASK | PDB_SC_MULT_MASK | PDB_SC_CONT_MASK);
  71. tmp32 |= PDB_SC_LDMOD(config->loadValueMode) | PDB_SC_PRESCALER(config->prescalerDivider) |
  72. PDB_SC_TRGSEL(config->triggerInputSource) | PDB_SC_MULT(config->dividerMultiplicationFactor);
  73. if (config->enableContinuousMode)
  74. {
  75. tmp32 |= PDB_SC_CONT_MASK;
  76. }
  77. base->SC = tmp32;
  78. PDB_Enable(base, true); /* Enable the PDB module. */
  79. }
  80. /*!
  81. * brief De-initializes the PDB module.
  82. *
  83. * param base PDB peripheral base address.
  84. */
  85. void PDB_Deinit(PDB_Type *base)
  86. {
  87. PDB_Enable(base, false); /* Disable the PDB module. */
  88. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  89. /* Disable the clock. */
  90. CLOCK_DisableClock(s_pdbClocks[PDB_GetInstance(base)]);
  91. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  92. }
  93. /*!
  94. * brief Initializes the PDB user configuration structure.
  95. *
  96. * This function initializes the user configuration structure to a default value. The default values are as follows.
  97. * code
  98. * config->loadValueMode = kPDB_LoadValueImmediately;
  99. * config->prescalerDivider = kPDB_PrescalerDivider1;
  100. * config->dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1;
  101. * config->triggerInputSource = kPDB_TriggerSoftware;
  102. * config->enableContinuousMode = false;
  103. * endcode
  104. * param config Pointer to configuration structure. See "pdb_config_t".
  105. */
  106. void PDB_GetDefaultConfig(pdb_config_t *config)
  107. {
  108. assert(NULL != config);
  109. /* Initializes the configure structure to zero. */
  110. (void)memset(config, 0, sizeof(*config));
  111. config->loadValueMode = kPDB_LoadValueImmediately;
  112. config->prescalerDivider = kPDB_PrescalerDivider1;
  113. config->dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1;
  114. config->triggerInputSource = kPDB_TriggerSoftware;
  115. config->enableContinuousMode = false;
  116. }
  117. #if defined(FSL_FEATURE_PDB_HAS_DAC) && FSL_FEATURE_PDB_HAS_DAC
  118. /*!
  119. * brief Configures the DAC trigger in the PDB module.
  120. *
  121. * param base PDB peripheral base address.
  122. * param channel Channel index for DAC instance.
  123. * param config Pointer to the configuration structure. See "pdb_dac_trigger_config_t".
  124. */
  125. void PDB_SetDACTriggerConfig(PDB_Type *base, pdb_dac_trigger_channel_t channel, pdb_dac_trigger_config_t *config)
  126. {
  127. assert((uint8_t)channel < (uint8_t)FSL_FEATURE_PDB_DAC_INTERVAL_TRIGGER_COUNT);
  128. assert(NULL != config);
  129. uint32_t tmp32 = 0U;
  130. /* PDBx_DACINTC. */
  131. if (config->enableExternalTriggerInput)
  132. {
  133. tmp32 |= PDB_INTC_EXT_MASK;
  134. }
  135. if (config->enableIntervalTrigger)
  136. {
  137. tmp32 |= PDB_INTC_TOE_MASK;
  138. }
  139. base->DAC[channel].INTC = tmp32;
  140. }
  141. #endif /* FSL_FEATURE_PDB_HAS_DAC */