fsl_reset.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright (c) 2016, NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include "fsl_common.h"
  9. #include "fsl_reset.h"
  10. /*******************************************************************************
  11. * Definitions
  12. ******************************************************************************/
  13. /* Component ID definition, used by tools. */
  14. #ifndef FSL_COMPONENT_ID
  15. #define FSL_COMPONENT_ID "platform.drivers.reset"
  16. #endif
  17. /*******************************************************************************
  18. * Variables
  19. ******************************************************************************/
  20. /*******************************************************************************
  21. * Prototypes
  22. ******************************************************************************/
  23. /*******************************************************************************
  24. * Code
  25. ******************************************************************************/
  26. #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
  27. /*!
  28. * brief Assert reset to peripheral.
  29. *
  30. * Asserts reset signal to specified peripheral module.
  31. *
  32. * param peripheral Assert reset to this peripheral. The enum argument contains encoding of reset register
  33. * and reset bit position in the reset register.
  34. */
  35. void RESET_SetPeripheralReset(reset_ip_name_t peripheral)
  36. {
  37. const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
  38. const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
  39. const uint32_t bitMask = 1u << bitPos;
  40. assert(bitPos < 32u);
  41. /* reset register is in SYSCON */
  42. /* set bit */
  43. SYSCON->PRESETCTRLSET[regIndex] = bitMask;
  44. /* wait until it reads 0b1 */
  45. while (0u == (SYSCON->PRESETCTRLX[regIndex] & bitMask))
  46. {
  47. }
  48. }
  49. /*!
  50. * brief Clear reset to peripheral.
  51. *
  52. * Clears reset signal to specified peripheral module, allows it to operate.
  53. *
  54. * param peripheral Clear reset to this peripheral. The enum argument contains encoding of reset register
  55. * and reset bit position in the reset register.
  56. */
  57. void RESET_ClearPeripheralReset(reset_ip_name_t peripheral)
  58. {
  59. const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
  60. const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
  61. const uint32_t bitMask = 1u << bitPos;
  62. assert(bitPos < 32u);
  63. /* reset register is in SYSCON */
  64. /* clear bit */
  65. SYSCON->PRESETCTRLCLR[regIndex] = bitMask;
  66. /* wait until it reads 0b0 */
  67. while (bitMask == (SYSCON->PRESETCTRLX[regIndex] & bitMask))
  68. {
  69. }
  70. }
  71. /*!
  72. * brief Reset peripheral module.
  73. *
  74. * Reset peripheral module.
  75. *
  76. * param peripheral Peripheral to reset. The enum argument contains encoding of reset register
  77. * and reset bit position in the reset register.
  78. */
  79. void RESET_PeripheralReset(reset_ip_name_t peripheral)
  80. {
  81. RESET_SetPeripheralReset(peripheral);
  82. RESET_ClearPeripheralReset(peripheral);
  83. }
  84. #endif /* FSL_FEATURE_SOC_SYSCON_COUNT || FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT */