]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/include/kernel.h
Initial commit.
[arc.git] / system / kernel / include / kernel.h
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16
17
18
19
20
21
22
23 /*\r
24  * kernel.h\r
25  *\r
26  *  Created on: 23 aug 2009\r
27  *      Author: mahi\r
28  */\r
29 \r
30 #ifndef KERNEL_H_\r
31 #define KERNEL_H_\r
32 \r
33 #include <sys/queue.h>\r
34 #include "Os.h"\r
35 #include "counter_i.h"\r
36 #include "alarm_i.h"\r
37 #include "sched_table_i.h"\r
38 \r
39 typedef void ( * trusted_func_t)( TrustedFunctionIndexType , TrustedFunctionParameterRefType );\r
40 \r
41 /*-----------------------------------------------------------------*/\r
42 /* Global Hooks( non-application specific ) */\r
43 \r
44 typedef struct os_conf_global_hooks_s {\r
45         ProtectionHookType ProtectionHook;\r
46         StartupHookType StartupHook;\r
47         ShutdownHookType ShutdownHook;\r
48         ErrorHookType ErrorHook;\r
49         PreTaskHookType PreTaskHook;\r
50         PostTaskHookType PostTaskHook;\r
51 } os_conf_global_hooks_t;\r
52 \r
53 \r
54 \r
55 /* Application hooks */\r
56 /*\r
57 typedef struct os_application_hooks_s {\r
58         void (*StartupHook)( void );\r
59         void (*ShutdownHook)( Std_ReturnType Error );\r
60         void (*ErrorHook)( Std_ReturnType Error );\r
61 } os_application_hooks_t;\r
62 */\r
63 \r
64 /*-----------------------------------------------------------------*/\r
65 \r
66 /*\r
67  * The only information about the COM that is valid is\r
68  * in the COM specification ..SWS_COM.pdf.\r
69  *\r
70  * The most important requirements are COM010 and COM013\r
71  *\r
72  * Com_Init()\r
73  * Com_DeInit()\r
74  *\r
75  * No error hooks..\r
76  * No. GetMessageStatus()\r
77  * No. SendZeroMessage()\r
78  * No. SendDynamicMessage(), RecieveDynamicMessage()\r
79  *\r
80  * See http://www.altium.com/files/AltiumDesigner6/LearningGuides/GU0102%20TSK51x%20TSK52x%20RTOS.pdf\r
81  *\r
82  * Yes. SendMessage()\r
83  *\r
84  * */\r
85 \r
86 typedef enum message_property_e {\r
87         // ???\r
88         SEND_STATIC_INTERNAL,\r
89         // messages are not consumed during read\r
90         RECEIVE_UNQUEUED_INTERNAL,\r
91         // We have an internal queue\r
92         RECEIVE_QUEUE_INTERNAL,\r
93 } message_property_t;\r
94 \r
95 \r
96 \r
97 typedef enum message_notification_action_e {\r
98         MESSAGE_NOTIFICATION_ACTION_NONE=0,\r
99         MESSAGE_NOTIFICATION_ACTION_ACTIVATETASK,\r
100         MESSAGE_NOTIFICATION_ACTION_SETEVENT,\r
101 } message_notification_action_t;\r
102 \r
103 typedef struct message_notification_s {\r
104         message_notification_action_t type;\r
105         TaskType                        task_id;\r
106         EventMaskType           event_id;\r
107 } message_notification_t;\r
108 \r
109 #if 0\r
110 // TODO: Do a untion of all types here ???\r
111 typedef struct {\r
112         void *cdata;\r
113 } message_tx_t;\r
114 #endif\r
115 \r
116 \r
117 typedef struct message_obj_s {\r
118         message_property_t              property;               // send/recieve...\r
119         int                                     q_size;                 // 0-Not queued\r
120         message_notification_t  notification;\r
121         // TODO: This is not a good solution but it will have to do for now\r
122         void *data;\r
123         int data_size;\r
124 } message_obj_t;\r
125 \r
126 \r
127 typedef enum scheduling_e {\r
128         SCHEDULING_FULL,\r
129         SCHEDULING_NONE\r
130 } scheduling_t;\r
131 \r
132 /*-----------------------------------------------------------------*/\r
133 \r
134 #if 0\r
135 typedef enum {\r
136 //      PROC_BG,\r
137 //      PROC_INT,\r
138         PROC_BASIC,\r
139         PROC_EXTENDED,\r
140         PROC_ISR1,\r
141         PROC_ISR2,\r
142 } proc_type_t;\r
143 #endif\r
144 \r
145 typedef uint8_t proc_type_t;\r
146 \r
147 #define PROC_PRIO               0x1\r
148 #define PROC_BASIC              0x1\r
149 #define PROC_EXTENDED   0x3\r
150 \r
151 #define PROC_ISR                0x4\r
152 #define PROC_ISR1               0x4\r
153 #define PROC_ISR2               0xc\r
154 \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 } stack_t;\r
161 \r
162 typedef struct rom_app_s {\r
163         uint32  application_id;\r
164         char    name[16];\r
165         uint8   trusted;\r
166 \r
167         /* hooks */\r
168         void (*StartupHook)( void );\r
169         void (*ShutdownHook)( Std_ReturnType Error );\r
170         void (*ErrorHook)( Std_ReturnType Error );\r
171 \r
172         uint32 isr_mask;\r
173         uint32 scheduletable_mask;\r
174         uint32 alarm_mask;\r
175         uint32 counter_mask;\r
176         uint32 resource_mask;\r
177         uint32 message_mask;\r
178 \r
179 } rom_app_t;\r
180 \r
181 /*-----------------------------------------------------------------*/\r
182 \r
183 typedef struct lockingtime_obj_s {\r
184         char id[16];\r
185         int resource;\r
186         int resource_clock_time;\r
187         int all_interrupt_clock_time;\r
188         int os_interrupt_clock_time;\r
189         int locking_type;\r
190 } lockingtime_obj_t;\r
191 \r
192 \r
193 typedef enum {\r
194         // the normal behaviour\r
195         RESOURCE_TYPE_STANDARD,\r
196         // ??\r
197         RESOURCE_TYPE_LINKED,\r
198         // Used for grouping tasks\r
199         RESOURCE_TYPE_INTERNAL\r
200 } resource_type_t;\r
201 \r
202 typedef struct  {\r
203         resource_type_t type;\r
204         // used only if type is RESOURCE_TYPE_LINKED\r
205         ResourceType    linked_resource;\r
206 } resource_property_t;\r
207 \r
208 /*-----------------------------------------------------------------*/\r
209 typedef struct resource_obj_s {\r
210         char id[16];\r
211         // The running number, starting at RES_SCHEDULER=0\r
212         int nr;\r
213         // The calculated ceiling prio\r
214         uint32 ceiling_priority;\r
215         // Stored prio of the owner oi the resource\r
216         uint32 old_task_prio;\r
217 \r
218         // What application may access this resource. A resource may only be\r
219         // accessed by one application\r
220         uint32 application_owner_id;\r
221         // What tasks may access this resource. A resource may be be shared\r
222         // several tasks.\r
223         uint32 task_mask;\r
224         // Owner of the resource...\r
225         TaskType owner;\r
226 \r
227         resource_type_t type;\r
228         // used only if type is RESOURCE_TYPE_LINKED\r
229         ResourceType    linked_resource;\r
230 \r
231 //      resource_property_t     resource_property;\r
232 \r
233 } resource_obj_t;\r
234 \r
235 typedef enum {\r
236         LOCK_TYPE_RESOURCE,\r
237         LOCK_TYPE_INTERRUPT,\r
238 } lock_type_t;\r
239 \r
240 /*\r
241 typedef struct {\r
242         ResourceType resource;\r
243         uint64 locktime;\r
244 } resource_locktime_t;\r
245 \r
246 typedef struct {\r
247         uint64 all;\r
248         uint64 os;\r
249 } interrupt_locktime_t;\r
250 */\r
251 \r
252 typedef struct lockingtime_s {\r
253 //      lock_type_t type;\r
254         lock_type_t type;\r
255         union {\r
256                 struct {\r
257                         ResourceType id;\r
258                         uint64 time;\r
259                 } resource;\r
260 \r
261                 struct {\r
262                         uint64 all;\r
263                         uint64 os;\r
264                 } interrupt;\r
265         } u;\r
266 //              resource_locktime_t resource;\r
267 //              interrupt_locktime_t interrupt;\r
268 //      } locktime;\r
269 } lockingtime_t;\r
270 \r
271 typedef struct timing_protection_s {\r
272         // ROM, worst case execution budget in ns\r
273         uint64  execution_budget;\r
274         // ROM, the frame in ns that timelimit may execute in.\r
275         uint64 timeframe;\r
276         // ROM, time in ns that the task/isr may with a timeframe.\r
277         uint64 timelimit;\r
278         // ROM, resource/interrupt locktimes\r
279         lockingtime_t *lockingtime;\r
280 \r
281 //      interrupt_locktime_t interrupt_locktime;\r
282         // ROM, resource lock times\r
283 //      const resource_locktime_t *resource_locktime_list;\r
284 //      lockingtime_t *lockingtime;\r
285 } timing_protection_t;\r
286 \r
287 \r
288 /*-----------------------------------------------------------------*/\r
289 \r
290 typedef struct rom_pcb_s {\r
291         TaskType                pid;\r
292         uint8                   prio;\r
293         uint32                  app_mask;\r
294         void                    (*entry)();\r
295         proc_type_t     proc_type;\r
296         uint8                   autostart;\r
297         stack_t                 stack;\r
298         int                             vector;                                 // ISR\r
299         ApplicationType application_id;\r
300         char                    name[16];\r
301         scheduling_t scheduling;\r
302 //      uint64                  execution_budget;\r
303 //      uint32                  count_limit;\r
304 //      uint64                  time_limit;\r
305         // pointer to internal resource\r
306         // NULL if none\r
307         resource_obj_t  *resource_int_p;\r
308         timing_protection_t     *timing_protection;\r
309 //      lockingtime_obj_t\r
310 } rom_pcb_t;\r
311 \r
312 \r
313 /*-----------------------------------------------------------------*/\r
314 \r
315 typedef struct sched_action_s {\r
316         int                     type;           // 0 - activate task, 1 - event\r
317         uint64                  offset;         // for debug only???\r
318         uint64                  delta;          // delta to next action\r
319         TaskType                task_id;\r
320         EventMaskType event_id;         // used only if event..\r
321 } sched_action_t;\r
322 \r
323 /*-----------------------------------------------------------------*/\r
324 \r
325 \r
326 /*\r
327 \r
328 typedef enum message_type_e {\r
329         // ???\r
330         SEND_STATIC_INTERNAL,\r
331         // messages are not consumed during read\r
332         RECEIVE_UNQUEUED_INTERNAL,\r
333         // We have an internal queue\r
334         RECEIVE_QUEUE_INTERNAL,\r
335 } message_type_t;\r
336 */\r
337 \r
338 #if 0\r
339 typedef struct message_obj_s {\r
340         char name[16];\r
341         message_type_t type;\r
342         void *\r
343         char name[16];\r
344         uint32  accessingapplications_mask;\r
345         // TODO:  Below types are NOT OK !!!!!!!\r
346         void*   cdatatype;\r
347         void*   initialvalue;\r
348         uint32  queuesize;\r
349         message_property_t messageproperty;\r
350         void *  callbackroutine;\r
351         uint32  callbackMessage;\r
352         void*   flagname;\r
353         uint32  notification;\r
354 \r
355 } message_obj_t;\r
356 #endif\r
357 \r
358 \r
359 \r
360 /*-----------------------------------------------------------------*/\r
361 \r
362 \r
363 typedef struct memory_s {\r
364         uint32_t flags;\r
365         /* ptr to start of memory region */\r
366         void    *start;\r
367         /* size in bytes */\r
368         uint32_t size;\r
369 } memory_t;\r
370 \r
371 /*-----------------------------------------------------------------*/\r
372 /*\r
373  * debug settings for os_debug_mask\r
374  *\r
375  */\r
376 \r
377 #define OS_DBG_MASTER_PRINT                     (1<<0)\r
378 #define OS_DBG_ISR_MASTER_PRINT         (1<<1)\r
379 #define OS_DBG_STDOUT                           (1<<2)\r
380 #define OS_DBG_ISR_STDOUT                       (1<<3)\r
381 \r
382 // Enable print dbg_XXXX (not dbg_isr_XXX though)\r
383 #define D_MASTER_PRINT                  (1<<0)\r
384 // Enable print for all dbg_isr_XXX\r
385 #define D_ISR_MASTER_PRINT              (1<<1)\r
386 // print to STDOUT. If not set it prints to ramlog\r
387 #define D_STDOUT                                (1<<2)\r
388 #define D_RAMLOG                                0\r
389 // print to STDOUT, If not set print to ramlog\r
390 #define D_ISR_STDOUT                    (1<<3)\r
391 #define D_ISR_RAMLOG                    0\r
392 \r
393 #define D_TASK                                          (1<<16)\r
394 #define D_ALARM                                         (1<<18)\r
395 \r
396 #define OS_DBG_TASK                                     (1<<16)\r
397 #define OS_DBG_ALARM                            (1<<18)\r
398 \r
399 \r
400 \r
401 #endif /* KERNEL_H_ */\r