NIIETCM4 PD  v0.10.5
Драйвер периферии для микроконтроллеров на базе ядра ARM Cortex-M4
 Указатель Структуры данных Файлы Функции Переменные Перечисления Элементы перечислений Группы Страницы
niietcm4_irq.c
1 
33 /* Includes ------------------------------------------------------------------*/
34 #include "niietcm4_irq.h"
35 
57 #define IS_VECTORS_ALIGNED(VECTORS) (((uint32_t)VECTORS & 0x7f) == 0)
58 
67 #if defined (__ICCARM__)
68  #pragma data_alignment=128
69  static __no_init void (*Vectors[IRQ_TOTAL])(void) @ "VTABLE";
70 #elif defined (__GNUC__)
71  static __attribute__((section("vtable")))
72  void (*Vectors[IRQ_TOTAL])(void) __attribute__((aligned(128)));
73 #elif defined (__CC_ARM)
74  static __attribute__((section("vtable")))
75  void (*Vectors[IRQ_TOTAL])(void) __attribute__((aligned(128)));
76 #else
77  #error "Нет реализации под данный компилятор"
78 #endif
79 
80 /*
81  * This is the default interrupt handler for all interrupts. It simply loops
82  * forever so that the system state is preserved for observation by a
83  * debugger. Since interrupts should be disabled before unregistering the
84  * corresponding handler, this should never be called.
85  */
86 static void IntDefaultHandler(void)
87 {
88  while (1)
89  {
90  // Capture
91  }
92 }
93 
104 void IRQ_HandlerInit(IRQn_Type IRQn, void (*pfnHandler)(void))
105 {
106  assert_param(IS_IRQ_NUM(IRQn));
107  assert_param(IS_VECTORS_ALIGNED(Vectors));
108 
109  /*
110  * See if the RAM vector table has been initialized.
111  */
112  if (SCB->VTOR != (uint32_t)Vectors)
113  {
114  uint32_t *src = (uint32_t *)SCB->VTOR;
115  uint32_t *dst = (uint32_t *)Vectors;
116  uint32_t n = IRQ_TOTAL;
117 
118  /*
119  * Copy the vector table from the beginning of FLASH
120  * to the RAM vector table.
121  */
122  while (n--)
123  *dst++ = *src++;
124 
125  /*
126  * Point the NVIC at the RAM vector table.
127  */
128  SCB->VTOR = (uint32_t)Vectors;
129  }
130 
131  /*
132  * Save the interrupt handler.
133  */
134  Vectors[IRQ_NUM(IRQn)] = pfnHandler;
135 }
136 
145 void IRQ_HandlerDeInit(IRQn_Type IRQn)
146 {
147  assert_param(IS_IRQ_NUM(IRQn));
148 
149  /*
150  * Reset the interrupt handler.
151  */
152  Vectors[IRQ_NUM(IRQn)] = IntDefaultHandler;
153 }
154 
171 /******************* (C) COPYRIGHT 2016 NIIET *****END OF FILE****/
#define IRQ_NUM(IRQ)
Получение системного порядкового номера прерывания, с учетом исключений
Definition: niietcm4_irq.h:60
#define IS_VECTORS_ALIGNED(VECTORS)
Проверка выравнивания RAM таблицы векторов
Definition: niietcm4_irq.c:57
void IRQ_HandlerInit(IRQn_Type IRQn, void(*pfnHandler)(void))
Назначает функцию для обработки прерывания.
Definition: niietcm4_irq.c:104
Файл содержит все прототипы функций для назначения обработчиков прерываний во время выполнения програ...
#define IS_IRQ_NUM(IRQn)
Проверка значения номера прерывания в допустимый диапазон.
Definition: niietcm4_irq.h:78
void IRQ_HandlerDeInit(IRQn_Type IRQn)
Назначает функцию-заглушку (бесконечный цикл) для обработки прерывания.
Definition: niietcm4_irq.c:145