]> rtime.felk.cvut.cz Git - arc.git/blob - include/isr.h
Merge with tms570 core 2.9 branch.
[arc.git] / include / isr.h
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 #ifndef ISR_H_\r
17 #define ISR_H_\r
18 \r
19 #include "task_i.h"\r
20 #include "resource_i.h"\r
21 \r
22 /*\r
23  * INCLUDE "RULES"\r
24  *  Since the types and methods defined here are used by the drivers, they should\r
25  *  include it. E.g. #include "isr.h"\r
26  *\r
27  *  This file is also used internally by the kernel\r
28  *\r
29  *\r
30  *  irq_types.h ( Vector enums )\r
31  *  irq.h       ( Interface )\r
32  *\r
33  *  Problem:\r
34  *    Os_Cfg.h needs types from isr.h\r
35  *\r
36  */\r
37 \r
38 /* ----------------------------[includes]------------------------------------*/\r
39 /* ----------------------------[define]--------------------------------------*/\r
40 \r
41 #define ISR_TYPE_1                      0\r
42 #define ISR_TYPE_2                      1\r
43 \r
44 /* ----------------------------[macro]---------------------------------------*/\r
45 #ifdef CFG_DRIVERS_USE_CONFIG_ISRS\r
46 #define ISR_INSTALL_ISR2( _name, _entry, _vector, _priority, _app )\r
47 #define ISR_INSTALL_ISR1(_name,_entry, _vector,_priority,_app)\r
48 #else\r
49 #define ISR_DECLARE_ISR2(_name, _entry, _unique, _vector,_priority,_app )        \\r
50           static const OsIsrConstType _entry ## _unique = { \\r
51                         .vector = _vector,   \\r
52                         .type = ISR_TYPE_2, \\r
53                         .priority = _priority,      \\r
54                         .entry = _entry,      \\r
55                         .name = _name,      \\r
56                         .resourceMask = 0,  \\r
57                         .timingProtPtr = NULL, \\r
58                         .appOwner = _app,      \\r
59                   };                    \\r
60 \r
61 \r
62 #define __ISR_INSTALL_ISR2(_name, _entry, _unique, _vector,_priority,_app )        \\r
63         do { \\r
64           static const OsIsrConstType _entry ## _unique = { \\r
65                         .vector = _vector,   \\r
66                         .type = ISR_TYPE_2, \\r
67                         .priority = _priority,      \\r
68                         .entry = _entry,      \\r
69                         .name = _name,      \\r
70                         .resourceMask = 0,  \\r
71                         .timingProtPtr = NULL, \\r
72                         .appOwner = _app,      \\r
73                   };                    \\r
74           Os_IsrAdd( & _entry ## _unique);   \\r
75         } while(0);\r
76 \r
77 \r
78 \r
79 #define _ISR_INSTALL_ISR2(_name,_entry, _unique, _vector,_priority,_app)        \\r
80                 __ISR_INSTALL_ISR2(_name,_entry, _unique, _vector,_priority,_app)\r
81 \r
82 #define ISR_INSTALL_ISR2(_name,_entry, _vector,_priority,_app)        \\r
83                 _ISR_INSTALL_ISR2(_name,_entry, __LINE__, _vector,_priority,_app)\r
84 \r
85 \r
86 #define ISR_DECLARE_ISR1(_name, _entry, _unique, _vector,_priority,_app )        \\r
87           static const OsIsrConstType _entry ## _unique = { \\r
88                         .vector = _vector,   \\r
89                         .type = ISR_TYPE_1, \\r
90                         .priority = _priority,      \\r
91                         .entry = _entry,      \\r
92                         .name = _name,      \\r
93                         .resourceMask = 0,  \\r
94                         .timingProtPtr = NULL, \\r
95                         .appOwner = _app,      \\r
96                   };                    \\r
97 \r
98 #define __ISR_INSTALL_ISR1(_name, _entry, _unique, _vector,_priority,_app )        \\r
99         do { \\r
100           static const OsIsrConstType _entry ## _unique = { \\r
101                         .vector = _vector,   \\r
102                         .type = ISR_TYPE_2, \\r
103                         .priority = _priority,      \\r
104                         .entry = _entry,      \\r
105                         .name = _name,      \\r
106                         .resourceMask = 0,  \\r
107                         .timingProtPtr = NULL, \\r
108                         .appOwner = _app,      \\r
109                   };                    \\r
110           Os_IsrAdd( & _entry ## _unique);   \\r
111         } while(0);\r
112 \r
113 #define _ISR_INSTALL_ISR1(_name,_entry, _unique, _vector,_priority,_app)        \\r
114                 __ISR_INSTALL_ISR1(_name,_entry, _unique, _vector,_priority,_app)\r
115 \r
116 #define ISR_INSTALL_ISR1(_name,_entry, _vector,_priority,_app)        \\r
117                 _ISR_INSTALL_ISR1(_name,_entry, __LINE__, _vector,_priority,_app)\r
118 \r
119 #endif\r
120 \r
121 /* ----------------------------[typedef]-------------------------------------*/\r
122 \r
123 \r
124 \r
125 /* STD container : OsIsrResourceLock\r
126  * Class: 2 and 4\r
127  *\r
128  * OsIsrResourceLockBudget      1    Float in seconds (MAXRESOURCELOCKINGTIME)\r
129  * OsIsrResourceLockResourceRef 1    Ref to OsResource\r
130  * */\r
131 \r
132 typedef struct OsIsrResourceLock {\r
133         uint32_t lockBudget;\r
134         uint32_t lockResourceRef;       /* Wrong type */\r
135 } OsIsrResourceLockType;\r
136 \r
137 \r
138 /* STD container : OsIsrTimingProtection\r
139  * Class: 2 and 4\r
140  *\r
141  * OsIsrAllInterruptLockBudget  0..1 float\r
142  * OsIsrExecutionBudget                 0..1 float\r
143  * OsIsrOsInterruptLockBudget   0..1 float\r
144  * OsIsrTimeFrame                               0..1 float\r
145  * OsIsrResourceLock[C]                 0..*\r
146  * */\r
147 \r
148 typedef struct OsIsrTimingProtection {\r
149         uint32_t allInterruptLockBudget;\r
150         uint32_t executionBudget;\r
151         uint32_t osInterruptLockBudget;\r
152         uint32_t timeFrame;\r
153         uint32_t resourceLock;          /* Wrong type */\r
154 } OsIsrTimingProtectionType;\r
155 \r
156 typedef struct {\r
157         void            *curr;  /* Current stack ptr( at swap time ) */\r
158         void            *top;   /* Top of the stack( low address )   */\r
159         uint32          size;   /* The size of the stack             */\r
160 } OsIsrStackType;\r
161 \r
162 \r
163 /* STD container : OsIsr\r
164  * Class: ALL\r
165  *\r
166  * OsIsrCategory:                               1    CATEGORY_1 or CATEGORY_2\r
167  * OsIsrResourceRef:                    0..* Reference to OsResources\r
168  * OsIsrTimingProtection[C]     0..1\r
169  * */\r
170 \r
171 typedef struct OsIsrConst {\r
172         const char              *name;\r
173         uint8_t                 core;\r
174         int16_t                 vector;\r
175         int16_t                 type;\r
176         int16_t                 priority;\r
177         void                    (*entry)();\r
178         uint32_t                appOwner;\r
179         /* Mapped against OsIsrResourceRef */\r
180         uint32_t                resourceMask;\r
181 #if (  OS_USE_ISR_TIMING_PROT == STD_ON )\r
182         /* Mapped against OsIsrTimingProtection[C] */\r
183         OsIsrTimingProtectionType *timingProtPtr;\r
184 #else\r
185         void *timingProtPtr;\r
186 #endif\r
187 } OsIsrConstType;\r
188 \r
189 /*\r
190  *\r
191  */\r
192 typedef struct {\r
193         ISRType id;\r
194 //      OsIsrStackType          stack;\r
195         int                                     state;\r
196         const OsIsrConstType *constPtr;\r
197 #if defined(CFG_ARM_CR4)\r
198         int16_t activeVector;\r
199 #endif\r
200 \r
201         /* List of resource held by this ISR */\r
202         TAILQ_HEAD(,OsResource) resourceHead;\r
203 } OsIsrVarType;\r
204 \r
205 \r
206 /* ----------------------------[functions]-----------------------------------*/\r
207 \r
208 #if OS_ISR_MAX_CNT!=0\r
209 extern OsIsrVarType Os_IsrVarList[OS_ISR_MAX_CNT];\r
210 #endif\r
211 \r
212 void Os_IsrInit( void );\r
213 ISRType Os_IsrAdd( const OsIsrConstType * restrict isrPtr );\r
214 void Os_IsrGetStackInfo( OsIsrStackType *stack );\r
215 void *Os_Isr( void *stack, int16_t vector);\r
216 #if defined(CFG_ARM_CR4)\r
217 void *Os_Isr_cr4( void *stack, int16_t virtualVector, int16_t vector );\r
218 #endif\r
219 #if defined(CFG_ARM_CM3)\r
220 void Os_Isr_cm3( int16_t vector );\r
221 void TailChaining(void *stack);\r
222 #endif\r
223 \r
224 static inline const OsIsrVarType *Os_IsrGet( ISRType id ) {\r
225         return &Os_IsrVarList[id];\r
226 }\r
227 \r
228 static inline ApplicationType Os_IsrGetApplicationOwner( ISRType id ) {\r
229         ApplicationType rv = INVALID_OSAPPLICATION;\r
230 \r
231 #if (OS_ISR_CNT!=0)\r
232         if( id < OS_ISR_CNT ) {\r
233                 rv = Os_IsrGet(id)->constPtr->appOwner;\r
234         }\r
235 #else\r
236         (void)id;\r
237 #endif\r
238         return rv;\r
239 }\r
240 \r
241 static inline void Os_IsrResourceAdd( OsResourceType *rPtr, OsIsrVarType *isrPtr) {\r
242         /* Save old task prio in resource and set new task prio */\r
243         rPtr->owner = isrPtr->id;\r
244 \r
245         assert( rPtr->type != RESOURCE_TYPE_INTERNAL );\r
246 }\r
247 \r
248 static inline  void Os_IsrResourceRemove( OsResourceType *rPtr , OsIsrVarType *isrPtr) {\r
249         assert( rPtr->owner == isrPtr->id );\r
250         rPtr->owner = NO_TASK_OWNER;\r
251 \r
252         if( rPtr->type != RESOURCE_TYPE_INTERNAL ) {\r
253                 /* The list can't be empty here */\r
254                 assert( !TAILQ_EMPTY(&isrPtr->resourceHead) );\r
255 \r
256                 /* The list should be popped in LIFO order */\r
257                 assert( TAILQ_LAST(&isrPtr->resourceHead, head) == rPtr );\r
258 \r
259                 /* Remove the entry */\r
260                 TAILQ_REMOVE(&isrPtr->resourceHead, rPtr, listEntry);\r
261         }\r
262 }\r
263 \r
264 static inline void Os_IsrResourceFreeAll( OsIsrVarType *isrPtr ) {\r
265         OsResourceType *rPtr;\r
266 \r
267         /* Pop the queue */\r
268         TAILQ_FOREACH(rPtr, &isrPtr->resourceHead, listEntry ) {\r
269                 Os_IsrResourceRemove(rPtr,isrPtr);\r
270         }\r
271 }\r
272 \r
273 static inline _Bool Os_IsrOccupiesResources(  OsIsrVarType *isrPtr ) {\r
274         return !(TAILQ_EMPTY(&isrPtr->resourceHead));\r
275 }\r
276 \r
277 \r
278 \r
279 \r
280 \r
281 #endif /*ISR_H_*/\r