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