CMSIS2000  0.0.7
 Указатель Структуры данных Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Макросы Группы Страницы
interrupt.h
См. документацию.
1 /*
2  * CMSIS2000
3  * CMSIS-like sources for LPC2xxx series MCUs
4  *
5  * (C) Copyright 2011-2012, Dmitriy Cherepanov, All Rights Reserved
6  *
7  * Version: 0.0.7
8  * Date of the Last Update: 2013-03-04
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to
12  * deal in the Software without restriction, including without limitation the
13  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14  * sell copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  *
28  * Do not be lasy! For the latest version see http://irtos.sourceforge.net .
29  *
30  *
31 #*/
32 /** \file
33  *\if russian_lng
34  * Файл определяющий макросы прерываний и исключений
35  *\else
36  * This file is used to define exeptions and interrupt subroutines macroses for selected arch
37 
38  * \note need to insert iConfig.h or FreeRTOSConfig.h
39  *\endif
40  */
41 #ifndef _iARCH_ARM_INTERRUPT_H_
42 #define _iARCH_ARM_INTERRUPT_H_ 1
43 
44 #if defined ( __CC_ARM ) /*------------------ RealView Compiler ------------*/
45 /* ARM armcc specific functions */
46 __irq
47 /* neeed to do separate ISR asm file for inserting OS save/restore context code*/
48 /* :-(*/
49 #elif (defined (__ICCARM__)) /*---------------- ICC Compiler -----------------*/
50 /* IAR iccarm specific functions */
51 
52 /* neeed to do separate ISR asm file for inserting OS save/restore context code*/
53 /* :-(*/
54 #define ISR_HANDLER_PROTO(name) \
55  void name (void) __irq
56 
57 #elif (defined (__GNUC__)) /*------------------ GNU Compiler -----------------*/
58 /* GNU gcc specific functions */
59 /** \brief Enable IRQ Interrupts
60 
61  This function enables IRQ interrupts by clearing the I-bit in the CPSR.
62  \note Can only be executed in Privileged modes.
63  */
64 __attribute__( ( always_inline ) ) static inline void __enable_irq(void)
65 {
66 // __asm volatile ("cpsie i" : : : "memory"); TODO check for memory
67 __asm volatile ("mrs r0, cpsr; bic r0, r0, #0x80; msr cpsr, r0" : : : "r0");
68 }
69 
70 /** \brief Disable IRQ Interrupts
71 
72  This function disables IRQ interrupts by setting the I-bit in the CPSR.
73  \note Can only be executed in Privileged modes.
74  */
75 __attribute__( ( always_inline ) ) static inline void __disable_irq(void)
76 {// TODO : : : "memory"); ???? check for memory
77  __asm volatile ("mrs r0, cpsr; orr r0, r0, #0x80; msr cpsr, r0" : : : "r0");
78 }
79 /** \brief Enable FIQ
80 
81  This function enables FIQ interrupts by clearing the F-bit in the CPSR.
82  Can only be executed in Privileged modes.
83  */
84 __attribute__( ( always_inline ) ) static inline void __enable_fault_irq(void)
85 {
86 // __asm volatile ("cpsie i" : : : "memory"); TODO check for memory
87 __asm volatile ("mrs r0, cpsr; bic r0, r0, #0x40; msr cpsr, r0" : : : "r0");
88 }
89 
90 
91 /** \brief Disable FIQ
92 
93  This function disables FIQ interrupts by setting the F-bit in the CPSR.
94  Can only be executed in Privileged modes.
95  */
96 __attribute__( ( always_inline ) ) static inline void __disable_fault_irq(void)
97 {// TODO : : : "memory"); ???? check for memory
98  __asm volatile ("mrs r0, cpsr; orr r0, r0, #0x40; msr cpsr, r0" : : : "r0");
99 }
100 
101 
102 #define ISR_HANDLER_PROTO(name) \
103  void name (void) __attribute__ ((interrupt("IRQ"),section (".text.keep.vector")))
104 
105 #define FIQ_HANDLER_PROTO(name) \
106  void name (void) __attribute__ ((interrupt("FIQ"),section (".text.keep.vector")))
107 
108 #define FIQ_HANDLER(name) void name (void)
109 
110 #define UNDEF_HANDLER_PROTO(name) \
111  void name (void) __attribute__ ((interrupt("UNDEF"),section (".text.keep.vector")))
112 
113 #define UNDEF_HANDLER(name) void name (void)
114 
115 
116 #define SWI_HANDLER_PROTO(name) \
117  void name (void) __attribute__ ((interrupt("SWI"),section (".text.keep.vector")))
118 
119 #define SWI_HANDLER(name) void name (void)
120 
121 #ifdef iSCHEDULER_TYPE /* --------------using iRTOS----------------*/
122 
123  #if (iSCHEDULER_TYPE == iPREEMPETIVE_SCHEDULER)
124 
125 
126  #endif
127 #endif
128 #ifdef configUSE_PREEMPTION /* --------------using freeRTOS----------------*/
129  #if (configUSE_PREEMPTION == 1)
130 
131  #define dri_make_asm_call_here(STRING) \
132  __asm volatile ("bl " #STRING)
133 
134  /* accoding to CMSIS function name is function_name##_IRQHandler*/
135  #define ISR_IRQ_OS_PROTO(function_name) \
136  void function_name##_IRQHandler ( void ) \
137  __attribute__ ((naked,section (".text.keep.vector")));\
138  void function_name##_IRQHandler_internal( void ) \
139  __attribute__ ((noinline)) \
140 
141  /* - Save the context of the interrupted task.
142  - Call the handler.
143  - Restore the context of whichever task is going to run next. */
144  #define ISR_IRQ_OS(function_name) \
145  void function_name##_IRQHandler ( void ) \
146  { \
147  portSAVE_CONTEXT(); \
148  dri_make_asm_call_here (function_name##_IRQHandler_internal) ; \
149  portRESTORE_CONTEXT(); \
150  } \
151  \
152  void function_name##_IRQHandler_internal( void )
153 
154 
155  #endif /* (configUSE_PREEMPTION == 1)*/
156 #endif /* (configUSE_PREEMPTION*/
157 
158 #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
159 /* TASKING carm specific functions */
160 #endif /* defined ( __CC_ARM ) */
161 
162 
163 
164 
165 
166 /*-------------------------------------------------------------------------*/
167 #if ((i_MCU_MODEL >= 2000) && (i_MCU_MODEL < 2300))
168  #define VICVectAddr_ISR_HOOK() (*(unsigned int*)(0xFFFFF030)) = 0;
169 #else
170  #define VICVectAddr_ISR_HOOK() (*(unsigned int*)(0xFFFFFF00)) = 0
171 #endif
172 
173 /*- THE DEFAULT PROTOTYPING OF THIS HANDLERS WITHOUT ANY RTOS-----------------*/
174 #ifndef ISR_EXCEPTION_PROTO
175  #define ISR_EXCEPTION_PROTO(name) ISR_HANDLER_PROTO(name##_Handler)
176 #endif
177 #ifndef ISR_EXCEPTION
178  #define ISR_EXCEPTION(name) ISR_IRQhook(name##_Handler)
179 #endif
180 
181 #ifndef ISR_IRQ_PROTOint
182  #define ISR_IRQ_PROTOint(name) ISR_HANDLER_PROTO(name##_IRQHandler)
183 #endif
184 
185 #ifndef ISR_IRQ_PROTO
186  #define ISR_IRQ_PROTO(name) ISR_IRQ_PROTOint(name)
187 #endif
188 #ifndef ISR_IRQhook
189  #define ISR_IRQhook(function_name) \
190 inline static void function_name##_internal( void ); \
191  ISR_HANDLER(function_name) \
192  { \
193  function_name##_internal() ; \
194  VIC->VectAddress = 0; \
195  }; \
196  inline static void function_name##_internal( void )
197 #endif
198 
199 #ifndef ISR_IRQint
200  #define ISR_IRQint(name) ISR_IRQhook(name##_IRQHandler)
201 #endif
202 #ifndef ISR_IRQ
203  #define ISR_IRQ(name) ISR_IRQint(name)
204 #endif
205 
206 /*if thumb then
207  sub lr, lr, #4
208  push {r0, r1, r2, r3, r4, fp, ip, lr}
209  add fp, sp, #28
210  bl 40003b40 <Handler_internal>
211  mov r3, #-2147483648 ; 0x80000000
212  asr r3, r3, #19
213  mov r2, #0
214  str r2, [r3, #3840] ; 0xf00
215  sub sp, fp, #28
216  ldm sp!, {r0, r1, r2, r3, r4, fp, ip, pc}^
217 
218 */
219 /* push {r2, r3}
220  mov r2, #0
221  mvn r3, #3840 ; 0xf00
222  str r2, [r3, #3585] ; 0xe01
223  pop {r2, r3}
224  subs pc, lr, #4
225 */
226 /*
227  sub lr, lr, #4
228  push {r0, r1, r2, r3, ip, lr}
229  ldr r3, [pc, #24] ; <----adress link here --->>>
230  ldr ip, [r3]
231  mov lr, pc
232  bx ip
233  mov r2, #0
234  mvn r3, #3840 ; 0xf00
235  str r2, [r3, #3585] ; 0xe01
236  ldm sp!, {r0, r1, r2, r3, ip, pc}^
237  <--------- here adress ->>>>>>>>>>
238 */
239 /*---here is the copy of upper level -----------------------------------------*/
240 
241 
242 
243 
244 #endif /* _iARCH_ARM_INTERRUPT_H_ */