nvic.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral :
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. #include "Std_Types.h"
  25. #include "nvic.h"
  26. /*==================================================================================================
  27. * LOCAL MACROS
  28. ==================================================================================================*/
  29. /*==================================================================================================
  30. * FILE VERSION CHECKS
  31. ==================================================================================================*/
  32. /*==================================================================================================
  33. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  34. ==================================================================================================*/
  35. /*==================================================================================================
  36. * LOCAL CONSTANTS
  37. ==================================================================================================*/
  38. /*==================================================================================================
  39. * LOCAL VARIABLES
  40. ==================================================================================================*/
  41. /*==================================================================================================
  42. * LOCAL VARIABLES
  43. ==================================================================================================*/
  44. /*==================================================================================================
  45. * GLOBAL CONSTANTS
  46. ==================================================================================================*/
  47. /*==================================================================================================
  48. * GLOBAL VARIABLES
  49. ==================================================================================================*/
  50. /*==================================================================================================
  51. * LOCAL FUNCTION PROTOTYPES
  52. ==================================================================================================*/
  53. /*==================================================================================================
  54. * LOCAL FUNCTIONS
  55. ==================================================================================================*/
  56. #ifdef FEATURE_NVIC_PRIORITY_GROUPING
  57. /*================================================================================================*/
  58. /**
  59. * @brief Set Priority Grouping
  60. * @details The function sets the priority grouping field using the required unlock sequence.
  61. * The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
  62. * Only values from 0..7 are used.
  63. * In case of a conflict between priority grouping and available
  64. * priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set
  65. */
  66. /*================================================================================================*/
  67. void NVIC_SetPriorityGrouping(uint32 PriorityGroup)
  68. {
  69. /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  70. S32_SCB->AIRCR = (S32_SCB->AIRCR & (~0x700UL)) | PriorityGroup;
  71. }
  72. #endif
  73. /*================================================================================================*/
  74. /**
  75. * @brief Enable External Interrupt
  76. * @details The function enables a device-specific interrupt in the NVIC interrupt controller.
  77. */
  78. /*================================================================================================*/
  79. void NVIC_EnableIRQ(uint8 IRQn)
  80. {
  81. S32_NVIC->ISER[FEATURE_NVIC_REGISTER_INDEX(IRQn)] = (uint32)(1UL << ((uint32)(IRQn) & (uint32)0x1FU));
  82. }
  83. /*================================================================================================*/
  84. /**
  85. * @brief Disable External Interrupt
  86. * @details The function disables a device-specific interrupt in the NVIC interrupt controller
  87. */
  88. /*================================================================================================*/
  89. void NVIC_DisableIRQ(uint8 IRQn)
  90. {
  91. S32_NVIC->ICER[FEATURE_NVIC_REGISTER_INDEX(IRQn)] = (uint32)(1UL << ((uint32)(IRQn) & (uint32)0x1FU));
  92. }
  93. /*================================================================================================*/
  94. /**
  95. * @brief Set Interrupt Priority
  96. * @details The function sets the priority of an interrupt.
  97. */
  98. /*================================================================================================*/
  99. void NVIC_SetPriority(uint8 IRQn, uint8 priority)
  100. {
  101. uint8 shift = (uint8) (8U - FEATURE_NVIC_PRIO_BITS);
  102. #ifdef FEATURE_NVIC_CORTEX_M4
  103. S32_NVIC->IP[(uint32)(IRQn)] = (uint8)(((((uint32)priority) << shift)) & 0xFFUL);
  104. #else
  105. uint32 iprVectorId = (uint32)(IRQn) >> 2U;
  106. uint8 priByteShift = (uint8)((((uint8)IRQn) & 0x3U) << 3U);
  107. S32_NVIC->IP[iprVectorId] &= ~(3U << priByteShift);
  108. S32_NVIC->IP[iprVectorId] |= ((uint32)(((((uint32)priority) << shift)) & 0xFFUL)) << priByteShift;
  109. #endif
  110. }