]> rtime.felk.cvut.cz Git - arc.git/blob - include/isr.h
ISR1 installer was wrong
[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 #if 0\r
46 //#ifdef CFG_DRIVERS_USE_CONFIG_ISRS\r
47 #define ISR_INSTALL_ISR2( _name, _entry, _vector, _priority, _app )\r
48 #define ISR_INSTALL_ISR1(_name,_entry, _vector,_priority,_app)\r
49 #else\r
50 #define ISR_DECLARE_ISR2(_name, _entry, _unique, _vector,_priority,_app )        \\r
51           static const OsIsrConstType _entry ## _unique = { \\r
52                         .vector = _vector,   \\r
53                         .type = ISR_TYPE_2, \\r
54                         .priority = _priority,      \\r
55                         .entry = _entry,      \\r
56                         .name = _name,      \\r
57                         .resourceMask = 0,  \\r
58                         .timingProtPtr = NULL, \\r
59                         .appOwner = _app,      \\r
60                   };                    \\r
61 \r
62 \r
63 #define __ISR_INSTALL_ISR2(_name, _entry, _unique, _vector,_priority,_app )        \\r
64         do { \\r
65           static const OsIsrConstType _entry ## _unique = { \\r
66                         .vector = _vector,   \\r
67                         .type = ISR_TYPE_2, \\r
68                         .priority = _priority,      \\r
69                         .entry = _entry,      \\r
70                         .name = _name,      \\r
71                         .resourceMask = 0,  \\r
72                         .timingProtPtr = NULL, \\r
73                         .appOwner = _app,      \\r
74                   };                    \\r
75           Os_IsrAdd( & _entry ## _unique);   \\r
76         } while(0);\r
77 \r
78 \r
79 \r
80 #define _ISR_INSTALL_ISR2(_name,_entry, _unique, _vector,_priority,_app)        \\r
81                 __ISR_INSTALL_ISR2(_name,_entry, _unique, _vector,_priority,_app)\r
82 \r
83 #define ISR_INSTALL_ISR2(_name,_entry, _vector,_priority,_app)        \\r
84                 _ISR_INSTALL_ISR2(_name,_entry, __LINE__, _vector,_priority,_app)\r
85 \r
86 \r
87 #define ISR_DECLARE_ISR1(_name, _entry, _unique, _vector,_priority,_app )        \\r
88           static const OsIsrConstType _entry ## _unique = { \\r
89                         .vector = _vector,   \\r
90                         .type = ISR_TYPE_1, \\r
91                         .priority = _priority,      \\r
92                         .entry = _entry,      \\r
93                         .name = _name,      \\r
94                         .resourceMask = 0,  \\r
95                         .timingProtPtr = NULL, \\r
96                         .appOwner = _app,      \\r
97                   };                    \\r
98 \r
99 #define __ISR_INSTALL_ISR1(_name, _entry, _unique, _vector,_priority,_app )        \\r
100         do { \\r
101           static const OsIsrConstType _entry ## _unique = { \\r
102                         .vector = _vector,   \\r
103                         .type = ISR_TYPE_1, \\r
104                         .priority = _priority,      \\r
105                         .entry = _entry,      \\r
106                         .name = _name,      \\r
107                         .resourceMask = 0,  \\r
108                         .timingProtPtr = NULL, \\r
109                         .appOwner = _app,      \\r
110                   };                    \\r
111           Os_IsrAdd( & _entry ## _unique);   \\r
112         } while(0);\r
113 \r
114 #define _ISR_INSTALL_ISR1(_name,_entry, _unique, _vector,_priority,_app)        \\r
115                 __ISR_INSTALL_ISR1(_name,_entry, _unique, _vector,_priority,_app)\r
116 \r
117 #define ISR_INSTALL_ISR1(_name,_entry, _vector,_priority,_app)        \\r
118                 _ISR_INSTALL_ISR1(_name,_entry, __LINE__, _vector,_priority,_app)\r
119 \r
120 #endif\r
121 \r
122 /* ----------------------------[typedef]-------------------------------------*/\r
123 \r
124 \r
125 \r
126 /* STD container : OsIsrResourceLock\r
127  * Class: 2 and 4\r
128  *\r
129  * OsIsrResourceLockBudget      1    Float in seconds (MAXRESOURCELOCKINGTIME)\r
130  * OsIsrResourceLockResourceRef 1    Ref to OsResource\r
131  * */\r
132 \r
133 typedef struct OsIsrResourceLock {\r
134         uint32_t lockBudget;\r
135         uint32_t lockResourceRef;       /* Wrong type */\r
136 } OsIsrResourceLockType;\r
137 \r
138 \r
139 /* STD container : OsIsrTimingProtection\r
140  * Class: 2 and 4\r
141  *\r
142  * OsIsrAllInterruptLockBudget  0..1 float\r
143  * OsIsrExecutionBudget                 0..1 float\r
144  * OsIsrOsInterruptLockBudget   0..1 float\r
145  * OsIsrTimeFrame                               0..1 float\r
146  * OsIsrResourceLock[C]                 0..*\r
147  * */\r
148 \r
149 typedef struct OsIsrTimingProtection {\r
150         uint32_t allInterruptLockBudget;\r
151         uint32_t executionBudget;\r
152         uint32_t osInterruptLockBudget;\r
153         uint32_t timeFrame;\r
154         uint32_t resourceLock;          /* Wrong type */\r
155 } OsIsrTimingProtectionType;\r
156 \r
157 typedef struct {\r
158         void            *curr;  /* Current stack ptr( at swap time ) */\r
159         void            *top;   /* Top of the stack( low address )   */\r
160         uint32          size;   /* The size of the stack             */\r
161 } OsIsrStackType;\r
162 \r
163 \r
164 /* STD container : OsIsr\r
165  * Class: ALL\r
166  *\r
167  * OsIsrCategory:                               1    CATEGORY_1 or CATEGORY_2\r
168  * OsIsrResourceRef:                    0..* Reference to OsResources\r
169  * OsIsrTimingProtection[C]     0..1\r
170  * */\r
171 \r
172 typedef struct OsIsrConst {\r
173         const char              *name;\r
174         uint8_t                 core;\r
175         int16_t                 vector;\r
176         int16_t                 type;\r
177         int16_t                 priority;\r
178         void                    (*entry)();\r
179         uint32_t                appOwner;\r
180         /* Mapped against OsIsrResourceRef */\r
181         uint32_t                resourceMask;\r
182 #if (  OS_USE_ISR_TIMING_PROT == STD_ON )\r
183         /* Mapped against OsIsrTimingProtection[C] */\r
184         OsIsrTimingProtectionType *timingProtPtr;\r
185 #else\r
186         void *timingProtPtr;\r
187 #endif\r
188 } OsIsrConstType;\r
189 \r
190 /*\r
191  *\r
192  */\r
193 typedef struct OsIsrVar{\r
194         ISRType id;\r
195 //      OsIsrStackType          stack;\r
196         int                                     state;\r
197         const OsIsrConstType *constPtr;\r
198 #if defined(CFG_ARM_CR4)\r
199         int16_t activeVector;\r
200 #endif\r
201 \r
202         /* List of resource held by this ISR */\r
203         TAILQ_HEAD(,OsResource) resourceHead;\r
204 } OsIsrVarType;\r
205 \r
206 \r
207 /* ----------------------------[functions]-----------------------------------*/\r
208 \r
209 #if OS_ISR_MAX_CNT!=0\r
210 extern OsIsrVarType Os_IsrVarList[OS_ISR_MAX_CNT];\r
211 #endif\r
212 \r
213 void Os_IsrInit( void );\r
214 ISRType Os_IsrAdd( const OsIsrConstType * restrict isrPtr );\r
215 void Os_IsrGetStackInfo( OsIsrStackType *stack );\r
216 void *Os_Isr( void *stack, int16_t vector);\r
217 #if defined(CFG_ARM_CR4)\r
218 void *Os_Isr_cr4( void *stack, int16_t virtualVector, int16_t vector );\r
219 #endif\r
220 #if defined(CFG_ARM_CM3)\r
221 void Os_Isr_cm3( int16_t vector );\r
222 void TailChaining(void *stack);\r
223 #endif\r
224 \r
225 static inline const OsIsrVarType *Os_IsrGet( ISRType id ) {\r
226 #if OS_ISR_CNT != 0\r
227         return &Os_IsrVarList[id];\r
228 #else\r
229         (void)id;\r
230         return NULL;\r
231 #endif\r
232 }\r
233 \r
234 static inline ApplicationType Os_IsrGetApplicationOwner( ISRType id ) {\r
235         ApplicationType rv = INVALID_OSAPPLICATION;\r
236 \r
237 #if (OS_ISR_CNT!=0)\r
238         if( id < OS_ISR_CNT ) {\r
239                 rv = Os_IsrGet(id)->constPtr->appOwner;\r
240         }\r
241 #else\r
242         (void)id;\r
243 #endif\r
244         return rv;\r
245 }\r
246 \r
247 static inline void Os_IsrResourceAdd( OsResourceType *rPtr, OsIsrVarType *isrPtr) {\r
248         /* Save old task prio in resource and set new task prio */\r
249         rPtr->owner = isrPtr->id;\r
250 \r
251         assert( rPtr->type != RESOURCE_TYPE_INTERNAL );\r
252 }\r
253 \r
254 static inline  void Os_IsrResourceRemove( OsResourceType *rPtr , OsIsrVarType *isrPtr) {\r
255         assert( rPtr->owner == isrPtr->id );\r
256         rPtr->owner = NO_TASK_OWNER;\r
257 \r
258         if( rPtr->type != RESOURCE_TYPE_INTERNAL ) {\r
259                 /* The list can't be empty here */\r
260                 assert( !TAILQ_EMPTY(&isrPtr->resourceHead) );\r
261 \r
262                 /* The list should be popped in LIFO order */\r
263                 assert( TAILQ_LAST(&isrPtr->resourceHead, head) == rPtr );\r
264 \r
265                 /* Remove the entry */\r
266                 TAILQ_REMOVE(&isrPtr->resourceHead, rPtr, listEntry);\r
267         }\r
268 }\r
269 \r
270 static inline void Os_IsrResourceFreeAll( OsIsrVarType *isrPtr ) {\r
271         OsResourceType *rPtr;\r
272 \r
273         /* Pop the queue */\r
274         TAILQ_FOREACH(rPtr, &isrPtr->resourceHead, listEntry ) {\r
275                 Os_IsrResourceRemove(rPtr,isrPtr);\r
276         }\r
277 }\r
278 \r
279 static inline _Bool Os_IsrOccupiesResources(  OsIsrVarType *isrPtr ) {\r
280         return !(TAILQ_EMPTY(&isrPtr->resourceHead));\r
281 }\r
282 \r
283 \r
284 \r
285 \r
286 \r
287 #endif /*ISR_H_*/\r