lpc_nvic.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**********************************************************************
  2. * $Id$ lpc_nvic.c 2011-06-02
  3. *//**
  4. * @file lpc_nvic.c
  5. * @brief Contains all expansion functions support for Nesting
  6. * Vectored Interrupt Controller (NVIC) firmware library
  7. * on LPC. The main NVIC functions are defined
  8. * in core_cm3.h
  9. * @version 1.0
  10. * @date 02. June. 2011
  11. * @author NXP MCU SW Application Team
  12. *
  13. * Copyright(C) 2011, NXP Semiconductor
  14. * All rights reserved.
  15. *
  16. ***********************************************************************
  17. * Software that is described herein is for illustrative purposes only
  18. * which provides customers with programming information regarding the
  19. * products. This software is supplied "AS IS" without any warranties.
  20. * NXP Semiconductors assumes no responsibility or liability for the
  21. * use of the software, conveys no license or title under any patent,
  22. * copyright, or mask work right to the product. NXP Semiconductors
  23. * reserves the right to make changes in the software without
  24. * notification. NXP Semiconductors also make no representation or
  25. * warranty that such application will be suitable for the specified
  26. * use without further testing or modification.
  27. * Permission to use, copy, modify, and distribute this software and its
  28. * documentation is hereby granted, under NXP Semiconductors'
  29. * relevant copyright in the software, without fee, provided that it
  30. * is used in conjunction with NXP Semiconductors microcontrollers. This
  31. * copyright, permission, and disclaimer notice must appear in all copies of
  32. * this code.
  33. **********************************************************************/
  34. /* Peripheral group ----------------------------------------------------------- */
  35. /** @addtogroup NVIC
  36. * @{
  37. */
  38. #ifdef __BUILD_WITH_EXAMPLE__
  39. #include "lpc_libcfg.h"
  40. #else
  41. #include "lpc_libcfg_default.h"
  42. #endif /* __BUILD_WITH_EXAMPLE__ */
  43. #ifdef _NVIC
  44. /* Includes ------------------------------------------------------------------- */
  45. #include "lpc_nvic.h"
  46. /* Private Macros ------------------------------------------------------------- */
  47. /** @defgroup NVIC_Private_Macros NVIC Private Macros
  48. * @{
  49. */
  50. /* Vector table offset bit mask */
  51. #define NVIC_VTOR_MASK 0x3FFFFF80
  52. /**
  53. * @}
  54. */
  55. /* Public Functions ----------------------------------------------------------- */
  56. /** @addtogroup NVIC_Public_Functions
  57. * @{
  58. */
  59. /*****************************************************************************//**
  60. * @brief De-initializes the NVIC peripheral registers to their default
  61. * reset values.
  62. * @param None
  63. * @return None
  64. *
  65. * These following NVIC peripheral registers will be de-initialized:
  66. * - Disable Interrupt (32 IRQ interrupt sources that matched with LPC178X)
  67. * - Clear all Pending Interrupts (32 IRQ interrupt source that matched with LPC178X)
  68. * - Clear all Interrupt Priorities (32 IRQ interrupt source that matched with LPC178X)
  69. *******************************************************************************/
  70. void NVIC_DeInit(void)
  71. {
  72. uint8_t tmp;
  73. /* Disable all interrupts */
  74. NVIC->ICER[0] = 0xFFFFFFFF;
  75. NVIC->ICER[1] = 0x00000001;
  76. /* Clear all pending interrupts */
  77. NVIC->ICPR[0] = 0xFFFFFFFF;
  78. NVIC->ICPR[1] = 0x00000001;
  79. /* Clear all interrupt priority */
  80. for (tmp = 0; tmp < 32; tmp++) {
  81. NVIC->IP[tmp] = 0x00;
  82. }
  83. }
  84. /*****************************************************************************//**
  85. * @brief De-initializes the SCB peripheral registers to their default
  86. * reset values.
  87. * @param none
  88. * @return none
  89. *
  90. * These following SCB NVIC peripheral registers will be de-initialized:
  91. * - Interrupt Control State register
  92. * - Interrupt Vector Table Offset register
  93. * - Application Interrupt/Reset Control register
  94. * - System Control register
  95. * - Configuration Control register
  96. * - System Handlers Priority Registers
  97. * - System Handler Control and State Register
  98. * - Configurable Fault Status Register
  99. * - Hard Fault Status Register
  100. * - Debug Fault Status Register
  101. *******************************************************************************/
  102. void NVIC_SCBDeInit(void)
  103. {
  104. uint8_t tmp;
  105. SCB->ICSR = 0x0A000000;
  106. SCB->VTOR = 0x00000000;
  107. SCB->AIRCR = 0x05FA0000;
  108. SCB->SCR = 0x00000000;
  109. SCB->CCR = 0x00000000;
  110. for (tmp = 0; tmp < 32; tmp++) {
  111. SCB->SHP[tmp] = 0x00;
  112. }
  113. SCB->SHCSR = 0x00000000;
  114. SCB->CFSR = 0xFFFFFFFF;
  115. SCB->HFSR = 0xFFFFFFFF;
  116. SCB->DFSR = 0xFFFFFFFF;
  117. }
  118. /*****************************************************************************//**
  119. * @brief Set Vector Table Offset value
  120. * @param offset Offset value
  121. * @return None
  122. *******************************************************************************/
  123. void NVIC_SetVTOR(uint32_t offset)
  124. {
  125. // SCB->VTOR = (offset & NVIC_VTOR_MASK);
  126. SCB->VTOR = offset;
  127. }
  128. /**
  129. * @}
  130. */
  131. #endif /*_NVIC*/
  132. /**
  133. * @}
  134. */
  135. /* --------------------------------- End Of File ------------------------------ */