]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/include/kernel.h
788cd0ec05af1aaddc0fd0223e8843d97e477d33
[arc.git] / system / kernel / include / kernel.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 \r
17 #ifndef KERNEL_H_\r
18 #define KERNEL_H_\r
19 \r
20 #include <sys/queue.h>\r
21 #include "Os.h"\r
22 \r
23 extern uint32_t os_dbg_mask;\r
24 \r
25 \r
26 /*\r
27  * Configuration tree:\r
28  * USE_OS_DEBUG               - Turn on/off all Os_DbgPrintf()\r
29  * SELECT_OS_CONSOLE          - Select console\r
30  * USE_RAMLOG                 - Compile ramlog code...\r
31  *\r
32  *\r
33  * Default is to print to RAMLOG.\r
34  *\r
35  *\r
36  * Use cases:\r
37  * 1. We don't have a RAMLOG (low on RAM) so we want to print to serial console:\r
38  *     #define CFG_OS_DEBUG = STD_ON\r
39  *     #define USE_SERIAL_PORT\r
40  *     #define SELECT_OS_CONSOLE=TTY_SERIAL0\r
41  * 2. We have a RAMLOG but we have a debugger connected and want the OS debug\r
42  *    to go there instead:\r
43  *     #define CFG_OS_DEBUG = STD_ON\r
44  *     #define USE_RAMLOG\r
45  *     #define USE_TTY_T32\r
46  *     #define SELECT_OS_CONSOLE=TTY_T32\r
47  * 3. We have only the ramlog:\r
48  *     #define CFG_OS_DEBUG = STD_ON\r
49  *     #define USE_RAMLOG\r
50  *     #define SELECT_OS_CONSOLE=TTY_RAMLOG\r
51  * 4. We use no debug.\r
52  *    <empty>\r
53   *\r
54  */\r
55 \r
56 #if (CFG_OS_DEBUG == STD_ON)\r
57 # if (SELECT_OS_CONSOLE==RAMLOG)\r
58 #  ifndef USE_RAMLOG\r
59 #  error  USE_RAMLOG must be defined.\r
60 #  endif\r
61 \r
62 #  define OS_DEBUG(_mask,...) \\r
63         do { \\r
64                 if( os_dbg_mask & (_mask) ) { \\r
65                         ramlog_printf("[%08u] : ",(unsigned)GetOsTick()); \\r
66                         ramlog_printf(__VA_ARGS__ );    \\r
67                 }; \\r
68         } while(0);\r
69 # elif (SELECT_OS_CONSOLE==TTY_NONE)\r
70 #   define OS_DEBUG(_mask,...)\r
71 # else\r
72 #  define OS_DEBUG(_mask,...) \\r
73         do { \\r
74                 if( os_dbg_mask & (_mask) ) { \\r
75                         printf("[%08u] : %s %d ",(unsigned)GetOsTick(), __FUNCTION__, __LINE__ ); \\r
76                         printf(__VA_ARGS__ );   \\r
77                 }; \\r
78         } while(0);\r
79 # endif\r
80 #else\r
81 # define OS_DEBUG(_mask,...)\r
82 #endif\r
83 \r
84 \r
85 #if ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON )\r
86 typedef void ( * trusted_func_t)( TrustedFunctionIndexType , TrustedFunctionParameterRefType );\r
87 #endif\r
88 \r
89 \r
90 /* STD container : OsOs. OSEK properties\r
91  * Class: ALL\r
92  *\r
93  * OsScalabilityClass:                  0..1 SC1,SC2,SC3,SC4\r
94  * OsStackMonitoring:                   1    Stack monitoring of tasks/category 2\r
95  * OsStatus                     1    EXTENDED or STANDARD status\r
96  * OsUseGetServiceId                    1    We can use the  OSErrorGetServiceId() function\r
97  * OsUseParameterAccess                 1    We save the parameters in OSError_XX_YY()\r
98  * OsUseResScheduler                    1\r
99  * OsHooks[C]                   1\r
100  *\r
101  * From OSEK/VDX oil:\r
102  *\r
103  * OS ExampleOS {\r
104  *   STATUS = STANDARD;\r
105  *   STARTUPHOOK = TRUE;\r
106  *   ERRORHOOK = TRUE;\r
107  *   SHUTDOWNHOOK = TRUE;\r
108  *   PRETASKHOOK = FALSE;\r
109  *   POSTTASKHOOK = FALSE;\r
110  *   USEGETSERVICEID = FALSE;\r
111  *   USEPARAMETERACCESS = FALSE;\r
112  *   USERESSCHEDULER = TRUE;\r
113  * };\r
114  *\r
115  * OS_SC1 | OS_SC2 | OS_SC3 | OS_SC4\r
116  * OS_STACK_MONITORING\r
117  * OS_STATUS_EXTENDED  / OS_STATUS_STANDARD\r
118  * OS_USE_GET_SERVICE_ID\r
119  * OS_USE_PARAMETER_ACCESS\r
120  * OS_RES_SCHEDULER\r
121  * */\r
122 \r
123 /**\r
124  * STD container: OsResource\r
125  * OsResourceProperty:                          1    INTERNAL, LINKED, STANDARD\r
126  * OsResourceAccessingApplication:  0..*\r
127  * OsResourceLinkedResourceRef:     0..1\r
128  */\r
129 \r
130 typedef enum {\r
131         /* External resource */\r
132         RESOURCE_TYPE_STANDARD,//!< RESOURCE_TYPE_STANDARD\r
133         /* ?? */\r
134         RESOURCE_TYPE_LINKED,  //!< RESOURCE_TYPE_LINKED\r
135         /* Internal resource */\r
136         RESOURCE_TYPE_INTERNAL //!< RESOURCE_TYPE_INTERNAL\r
137 } OsResourcePropertyType;\r
138 \r
139 /*-----------------------------------------------------------------*/\r
140 typedef struct OsResource {\r
141         char id[16];\r
142         // The running number, starting at RES_SCHEDULER=0\r
143         int nr;\r
144         // The calculated ceiling prio\r
145         uint32 ceiling_priority;\r
146         // Stored prio of the owner oi the resource\r
147         uint32 old_task_prio;\r
148 \r
149         // What application may access this resource. A resource may only be\r
150         // accessed by one application\r
151 #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )\r
152         uint32 application_owner_id;\r
153 #endif\r
154         // What tasks may access this resource. A resource may be be shared\r
155         // several tasks.\r
156 //      uint32 task_mask;\r
157         // Owner of the resource...\r
158         TaskType owner;\r
159 \r
160         OsResourcePropertyType type;\r
161         // used only if type is RESOURCE_TYPE_LINKED\r
162         ResourceType    linked_resource;\r
163 \r
164         /* List of resources for each task. */\r
165         TAILQ_ENTRY(OsResource) listEntry;\r
166 \r
167 } OsResourceType;\r
168 \r
169 typedef enum {\r
170         LOCK_TYPE_RESOURCE,\r
171         LOCK_TYPE_INTERRUPT,\r
172 } OsLocktypeType;\r
173 \r
174 typedef struct OsLockingtime {\r
175         OsLocktypeType type;\r
176         union {\r
177                 struct {\r
178                         ResourceType id;\r
179                         uint64 time;\r
180                 } resource;\r
181 \r
182                 struct {\r
183                         uint64 all;\r
184                         uint64 os;\r
185                 } interrupt;\r
186         } u;\r
187 } OsLockingtimeType;\r
188 \r
189 typedef struct OsTimingProtection {\r
190         // ROM, worst case execution budget in ns\r
191         uint64  execution_budget;\r
192         // ROM, the frame in ns that timelimit may execute in.\r
193         uint64 timeframe;\r
194         // ROM, time in ns that the task/isr may with a timeframe.\r
195         uint64 timelimit;\r
196         // ROM, resource/interrupt locktimes\r
197         OsLockingtimeType *lockingtime;\r
198 } OsTimingProtectionType;\r
199 \r
200 \r
201 #include "counter_i.h"\r
202 #include "alarm_i.h"\r
203 #include "sched_table_i.h"\r
204 #include "application.h"\r
205 #include "pcb.h"\r
206 #include "sys.h"\r
207 \r
208 /*-----------------------------------------------------------------*/\r
209 \r
210 \r
211 /*-----------------------------------------------------------------*/\r
212 /*\r
213  * debug settings for os_debug_mask\r
214  *\r
215  */\r
216 \r
217 // print to STDOUT. If not set it prints to ramlog\r
218 #define D_STDOUT                                        0\r
219 #define D_RAMLOG                                        0\r
220 #define D_MASTER_PRINT                          0\r
221 #define D_ISR_MASTER_PRINT                      0\r
222 #define D_ISR_RAMLOG                            0\r
223 \r
224 #define D_TASK                                          (1<<0)\r
225 #define D_ALARM                                 (1<<1)\r
226 #define D_RESOURCE                                      (1<<2)\r
227 #define D_SCHTBL                                        (1<<3)\r
228 #define D_EVENT                                 (1<<4)\r
229 #define D_MESSAGE                                       (1<<5)\r
230 \r
231 \r
232 #endif /* KERNEL_H_ */\r