]> rtime.felk.cvut.cz Git - arc.git/blob - include/os_config_macros.h
Added kernel_extra example. Added CW support again.
[arc.git] / include / os_config_macros.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 /* Configure "rules"\r
17  * - Don't pollute the namespace with the generator tools. The tools should\r
18  *   ONLY know the GEN_xxx macros.\r
19  * - If something is a container with multiplicity 1 and above, make it a pointer.\r
20  * - ...\r
21  */\r
22 \r
23 #ifndef _OS_CONFIG_MACROS_H\r
24 #define _OS_CONFIG_MACROS_H\r
25 \r
26 #include "Std_Types.h"\r
27 \r
28 #define false           0\r
29 #define true            1\r
30 \r
31 #ifndef ARRAY_SIZE\r
32 #define ARRAY_SIZE(_x)          (sizeof(_x)/sizeof((_x)[0]))\r
33 #endif\r
34 \r
35 \r
36 // +1 here.. easy to have a reference..\r
37 #define GEN_TRUSTEDFUNCTIONS_LIST trusted_func_t os_cfg_trusted_list[OS_SERVICE_CNT];\r
38 \r
39 #define GEN_APPLICATION_HEAD const OsAppConstType Os_AppConst[OS_APPLICATION_CNT]\r
40 \r
41 #define GEN_APPLICATION(        _id,_name, _trusted, _core, _startuphook,_shutdownhook, _errorhook, \\r
42                                                         _restart_task  ) \\r
43 {                                                                                               \\r
44         .appId = _id,                                           \\r
45         .name = _name,                                                          \\r
46         .core = _core,                              \\r
47         .trusted = _trusted,                                            \\r
48         .StartupHook = _startuphook,                            \\r
49         .ShutdownHook = _shutdownhook,                          \\r
50         .ErrorHook = _errorhook,                                        \\r
51         .restartTaskId = _restart_task                          \\r
52 }\r
53 \r
54 #define GEN_TASK_HEAD const OsTaskConstType  Os_TaskConstList[OS_TASK_CNT]\r
55 \r
56 \r
57 \r
58 /**\r
59  * _id\r
60  * _priority            The task priority\r
61  * _autostart           true/false\r
62  * _resource_int_p  Pointer to internal resource.\r
63  *                  NULL - if no internal resource or scheduling==NON\r
64  *                  Pointer to\r
65  * _scheduling      FULL or NON\r
66  * _resource_mask   Mask of the resources used. Applies to STANDARD and LINKED (NOT INTERNAL)\r
67  *                  For example if this task would use resource with id 2 and 4 the mask would\r
68  *                  become (1<<2)|(1<<4) = 0x14 (limits resources to 32).\r
69  *                  Currently used for calculating the ceiling priority.\r
70  */\r
71 #define GEN_ETASK(      _id, _name, _priority, _scheduling, \\r
72                                         _autostart, _resource_int_p,  _resource_mask, \\r
73                                         _appl_owner, _accessing_appl_mask ) \\r
74 {                                                                       \\r
75         .pid = TASK_ID_ ## _id,                                 \\r
76         .name = _name,                                  \\r
77         .entry = _id,                           \\r
78         .prio = _priority,                              \\r
79         .proc_type = PROC_EXTENDED,             \\r
80         .stack.size = sizeof stack_##_id,       \\r
81         .stack.top = stack_##_id,               \\r
82         .autostart = _autostart,                \\r
83         .resourceIntPtr = _resource_int_p, \\r
84         .scheduling = _scheduling, \\r
85         .resourceAccess = _resource_mask, \\r
86         .activationLimit = 1, \\r
87         .applOwnerId = _appl_owner, \\r
88         .accessingApplMask = _accessing_appl_mask, \\r
89 }\r
90 \r
91 #define GEN_BTASK(      _id, _name, _priority, _scheduling, \\r
92                                         _autostart, _resource_int_p,  _resource_mask, \\r
93                                         _activation_limit, _appl_owner, _accessing_appl_mask ) \\r
94 {                                                                       \\r
95         .pid = TASK_ID_ ## _id,                                 \\r
96         .name = _name,                                  \\r
97         .entry = _id,                           \\r
98         .prio = _priority,                              \\r
99         .proc_type = PROC_BASIC,                \\r
100         .stack.size = sizeof stack_##_id,       \\r
101         .stack.top = stack_##_id,               \\r
102         .autostart = _autostart,                \\r
103         .resourceIntPtr = _resource_int_p, \\r
104         .scheduling = _scheduling, \\r
105         .resourceAccess = _resource_mask, \\r
106         .activationLimit = _activation_limit, \\r
107         .applOwnerId = _appl_owner, \\r
108         .accessingApplMask = _accessing_appl_mask, \\r
109 }\r
110 \r
111 #define GEN_ISR_HEAD const OsIsrConstType Os_IsrConstList[OS_ISR_CNT]\r
112 \r
113 #define GEN_ISR1( _name, _vector, _priority, _entry, _appOwner ) \\r
114 {                                      \\r
115                 .vector = _vector,             \\r
116                 .type = ISR_TYPE_1,            \\r
117                 .priority = _priority,         \\r
118                 .entry = _entry,               \\r
119                 .name = _name,                 \\r
120                 .resourceMask = 0,             \\r
121                 .appOwner = _appOwner,         \\r
122 }\r
123 \r
124 #define GEN_ISR2( _name, _vector, _priority, _entry, _appOwner, _resourceMask ) \\r
125 {                                      \\r
126                 .vector = _vector,             \\r
127                 .type = ISR_TYPE_1,            \\r
128                 .priority = _priority,         \\r
129                 .entry = _entry,               \\r
130                 .name = _name,                 \\r
131                 .resourceMask = _resourceMask, \\r
132                 .appOwner = _appOwner,         \\r
133 }\r
134 \r
135 \r
136 #define GEN_ISR_MAP const uint8_t Os_VectorToIsr[NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS]\r
137 \r
138 \r
139 #define GEN_RESOURCE_HEAD OsResourceType resource_list[OS_RESOURCE_CNT]\r
140 \r
141 \r
142 /**\r
143  * _id\r
144  * _type              RESOURCE_TYPE_STANDARD, RESOURCE_TYPE_LINKED or RESOURCE_TYPE_INTERNAL\r
145  * _ceiling_priority  The calculated ceiling priority\r
146  */\r
147 #define GEN_RESOURCE( _id, _type, _ceiling_priority, _appl_owner, _accessing_appl_mask ) \\r
148 {                                                                                               \\r
149         .nr= _id,                                                                       \\r
150         .type= _type,                                                           \\r
151         .ceiling_priority = _ceiling_priority,          \\r
152         .owner = (-1),                                                          \\r
153         .applOwnerId = _appl_owner,                             \\r
154         .accessingApplMask = _accessing_appl_mask       \\r
155 }\r
156 \r
157 /**\r
158  * _id\r
159  *      NOT_USED\r
160  * _name\r
161  *    Name of the alarm, string\r
162  *\r
163  * _type\r
164  *   COUNTER_TYPE_HARD or COUNTER_TYPE_SOFT\r
165  *\r
166  * _unit\r
167  *   COUNTER_UNIT_TICKS or COUNTER_UNIT_NANO\r
168  *\r
169  * _maxallowedvalue\r
170  *    0xffffffffUL\r
171  *\r
172  * _ticksperbase\r
173  *    1\r
174  *\r
175  * _mincycle\r
176  *    Say 10000\r
177 \r
178  * _gpt_ch\r
179  *    NOT USED. Set to 0\r
180  */\r
181 \r
182 #define GEN_COUNTER_HEAD OsCounterType counter_list[OS_COUNTER_CNT]\r
183 #define GEN_COUNTER( _id, _name, _type, _unit,  \\r
184                                         _maxallowedvalue,                       \\r
185                                         _ticksperbase,                          \\r
186                                         _mincycle,          \\r
187                                         _gpt_ch,                                \\r
188                                         _appl_owner, \\r
189                                         _accessing_appl_mask )  \\r
190 {                                                                                               \\r
191         .type = _type,                                                          \\r
192         .unit = _unit,                                                          \\r
193         .alarm_base.maxallowedvalue = _maxallowedvalue, \\r
194         .alarm_base.tickperbase = _ticksperbase,                \\r
195         .alarm_base.mincycle = _mincycle,                               \\r
196         .applOwnerId = _appl_owner, \\r
197         .accessingApplMask = _accessing_appl_mask, \\r
198 }\r
199 \r
200 #define GEN_ALARM_AUTOSTART_NAME(_id)    &(Os_AlarmAutoStart_ ## _id)\r
201 \r
202 /**\r
203  * _id\r
204  * _type\r
205  * _alarms_time\r
206  * _cycle_time\r
207  * _app_mode       Mask of the application modes.\r
208  */\r
209 #define GEN_ALARM_AUTOSTART(_id, _type, _alarm_time, _cycle_time, _app_mode ) \\r
210                 const OsAlarmAutostartType Os_AlarmAutoStart_ ## _id = \\r
211                 { \\r
212                         .autostartType = _type, \\r
213                         .alarmTime = _alarm_time, \\r
214                         .cycleTime = _cycle_time, \\r
215                         .appModeRef = _app_mode \\r
216                 }\r
217 \r
218 #define GEN_ALARM_HEAD OsAlarmType alarm_list[OS_ALARM_CNT]\r
219 \r
220 /**\r
221  * _id\r
222  *    NOT USED\r
223  *\r
224  * _name\r
225  *    Name of the alarm, string\r
226  *\r
227  * _counter_id\r
228  *    The id of the counter to drive the alarm\r
229  *\r
230  * _autostart_ref\r
231  *\r
232  * _X_type       - Any of:\r
233  *                                      ALARM_ACTION_ACTIVATETASK\r
234  *                                      ALARM_ACTION_SETEVENT\r
235  *                                      ALARM_ACTION_ALARMCALLBACK\r
236  *                                      ALARM_ACTION_INCREMENTCOUNTER\r
237  *\r
238  * _X_task_id    - The task ID to activate if _X_type is:\r
239  *                                      ALARM_ACTION_ACTIVATETASK or\r
240  *                                      ALARM_ACTION_SETEVENT\r
241  *\r
242  * _X_event_id   - The event ID if type is ALARM_ACTION_SETEVENT\r
243  *\r
244  * _X_counter_id - The counter ID if type is ALARM_ACTION_INCREMENTCOUNTER\r
245  *\r
246  */\r
247 #define GEN_ALARM( _id, _name, _counter_id,             \\r
248                     _autostart_ref,                     \\r
249                         _action_type,                                           \\r
250                         _action_task_id,                                        \\r
251                         _action_event_id,                                       \\r
252                         _action_counter_id,                                     \\r
253                         _appl_owner,                                            \\r
254                         _accessing_appl_mask )                          \\r
255 {                                                                                       \\r
256         .name = _name,                                                  \\r
257         .counter = &counter_list[_counter_id],  \\r
258         .counter_id = _counter_id,                              \\r
259         .autostartPtr = _autostart_ref,         \\r
260         .action = {                                                             \\r
261                 .type = _action_type,                           \\r
262                 .task_id = _action_task_id,                     \\r
263                 .event_id = _action_event_id,           \\r
264                 .counter_id = _action_counter_id        \\r
265         },                                                                              \\r
266         .applOwnerId = _appl_owner, \\r
267         .accessingApplMask = _accessing_appl_mask, \\r
268 }\r
269 \r
270 /*\r
271  *---------------------- SCHEDULE TABLES -----------------------------------\r
272  */\r
273 \r
274 #define GEN_SCHTBL_EXPIRY_POINT_HEAD(_id ) \\r
275                 OsScheduleTableExpiryPointType Os_SchTblExpPointList_##_id[] =\r
276 \r
277 #define GEN_SCHTBL_EXPIRY_POINT_W_TASK_EVENT(_id, _offset )                                                                             \\r
278         {                                                                                                                                                       \\r
279                 .offset      = _offset,                                                                                                 \\r
280                 .taskList    = Os_SchTblTaskList_ ## _id ## _ ## _offset,                               \\r
281                 .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset),   \\r
282                 .eventList   = Os_SchTblEventList_ ## _id ## _ ## _offset,                              \\r
283                 .eventListCnt    = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset)       \\r
284         }\r
285 \r
286 #define GEN_SCHTBL_EXPIRY_POINT_W_TASK(_id, _offset )                                                   \\r
287         {                                                                                                                                                       \\r
288                 .offset      = _offset,                                                                                                 \\r
289                 .taskList    = Os_SchTblTaskList_ ## _id ## _ ## _offset,                               \\r
290                 .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset),   \\r
291         }\r
292 \r
293 #define GEN_SCHTBL_EXPIRY_POINT_W_EVENT(_id, _offset )                                                  \\r
294         {                                                                                                                                                       \\r
295                 .offset      = _offset,                                                                                                 \\r
296                 .eventList   = Os_SchTblEventList_ ## _id ## _ ## _offset,                              \\r
297                 .eventListCnt    = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset)       \\r
298         }\r
299 \r
300 #define GEN_SCHTBL_TASK_LIST_HEAD( _id, _offset ) \\r
301                 const TaskType Os_SchTblTaskList_ ## _id ## _ ## _offset[] =\r
302 \r
303 #define GEN_SCHTBL_EVENT_LIST_HEAD( _id, _offset ) \\r
304                 const OsScheduleTableEventSettingType Os_SchTblEventList_ ## _id ## _ ## _offset[] =\r
305 \r
306 #define GEN_SCHTBL_AUTOSTART(_id, _type, _offset, _app_mode ) \\r
307                 const struct OsSchTblAutostart Os_SchTblAutoStart_ ## _id = \\r
308                 { \\r
309                         .type = _type, \\r
310                         .offset = _offset, \\r
311                         .appMode = _app_mode, \\r
312                 }\r
313 \r
314 #define GEN_SCHTBL_AUTOSTART_NAME(_id)  &(Os_SchTblAutoStart_ ## _id)\r
315 \r
316 #define GEN_SCHTBL_HEAD OsSchTblType sched_list[] =\r
317 \r
318 /**\r
319  * _id\r
320  *    NOT USED\r
321  *\r
322  * _name\r
323  *    Name of the alarm, string\r
324  *\r
325  * _counter_ref\r
326  *    Pointer to the counter that drives the table\r
327  *\r
328  * _repeating\r
329  *   SINGLE_SHOT or REPEATING\r
330  *\r
331  * _duration\r
332  *   The duration of the schedule table\r
333  *\r
334  * _autostart_ref\r
335  *   Pointer to autostart configuration.\r
336  *   If autostart is desired set name to GEN_SCHTBL_AUTOSTART_NAME(<id>). It also\r
337  *   requires that GEN_SCHTBL_AUTOSTART(...) is set.\r
338  *   Set to NULL if not autostart configuration is desired.\r
339  *\r
340  * The usage of the macro requires that GEN_SCHTBL_EXPIRY_POINT_HEAD(<id>) is also\r
341  * set.\r
342  */\r
343 \r
344 #define GEN_SCHEDULETABLE(  _id, _name, _counter_id, _repeating, \\r
345                                                         _duration,       \\r
346                                                         _autostart_ref ) \\r
347 {                                                                                        \\r
348         .name = _name,                                               \\r
349         .counter = &counter_list[_counter_id],       \\r
350         .repeating = _repeating,                             \\r
351         .duration = _duration,                                   \\r
352         .expirePointList = {                     \\r
353           .data = (void *)( Os_SchTblExpPointList_ ## _id ), \\r
354           .cnt = ARRAY_SIZE(Os_SchTblExpPointList_ ## _id), \\r
355          }, \\r
356         .autostartPtr = _autostart_ref,                          \\r
357 }\r
358 \r
359 \r
360 #define GEN_HOOKS( _startup, _protection, _shutdown, _error, _pretask, _posttask ) \\r
361 struct OsHooks os_conf_global_hooks = { \\r
362                 .StartupHook = _startup,                \\r
363                 .ProtectionHook = _protection,  \\r
364                 .ShutdownHook = _shutdown,              \\r
365                 .ErrorHook = _error,                    \\r
366                 .PreTaskHook = _pretask,                \\r
367                 .PostTaskHook = _posttask               \\r
368 }\r
369 \r
370 #define ALIGN_16(x) (((x)>>4)<<4)\r
371 \r
372 #define DECLARE_STACK(_name,_size) \\r
373         uint8_t stack_##_name[_size]\r
374 \r
375 #define SECTION_BSS_SUPER       __attribute__ ((aligned (16),section(".bss")))\r
376 #define SECTION_BSS_USER        __attribute__ ((aligned (16),section(".bss")))\r
377 \r
378 #endif\r
379 \r
380 \r
381 \r
382 \r
383 \r
384 \r
385 \r