]> rtime.felk.cvut.cz Git - arc.git/blob - include/os_config_macros.h
905c4a965df3dd0ed0f0701a367828c8787e8d8d
[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 #if 0\r
140 #define GEN_ISR_2( _id, _name, _entry, _priority,  _vector ) \\r
141 {                                                                       \\r
142         .pid = _id,                                             \\r
143         .name = _name,                                  \\r
144         .entry = _entry,                                \\r
145         .prio = _priority,                              \\r
146         .proc_type = PROC_ISR2,             \\r
147         .vector = _vector,              \\r
148 }\r
149 \r
150 \r
151 #define GEN_ISR_1( _id, _name, _entry, _priority , _vector ) \\r
152 {                                                                       \\r
153         .pid = _id,                                             \\r
154         .name = _name,                                  \\r
155         .entry = _entry,                                \\r
156         .prio = _priority,                              \\r
157         .proc_type = PROC_ISR1,         \\r
158         .vector = _vector,              \\r
159 }\r
160 #endif\r
161 \r
162 \r
163 //#define GEN_PCB_LIST()        uint8_t Os_TaskVarList[PCB_T_SIZE*ARRAY_SIZE( Os_TaskConstList)];\r
164 #define GEN_PCB_LIST()  OsTaskVarType Os_TaskVarList[ARRAY_SIZE( Os_TaskConstList)];\r
165 \r
166 #define GEN_RESOURCE_HEAD OsResourceType resource_list[OS_RESOURCE_CNT]\r
167 \r
168 \r
169 /**\r
170  * _id\r
171  * _type              RESOURCE_TYPE_STANDARD, RESOURCE_TYPE_LINKED or RESOURCE_TYPE_INTERNAL\r
172  * _ceiling_priority  The calculated ceiling priority\r
173  */\r
174 #define GEN_RESOURCE( _id, _type, _ceiling_priority, _appl_owner, _accessing_appl_mask ) \\r
175 {                                                                                               \\r
176         .nr= _id,                                                                       \\r
177         .type= _type,                                                           \\r
178         .ceiling_priority = _ceiling_priority,          \\r
179         .owner = (-1),                                                          \\r
180         .applOwnerId = _appl_owner,                             \\r
181         .accessingApplMask = _accessing_appl_mask       \\r
182 }\r
183 \r
184 /**\r
185  * _id\r
186  *      NOT_USED\r
187  * _name\r
188  *    Name of the alarm, string\r
189  *\r
190  * _type\r
191  *   COUNTER_TYPE_HARD or COUNTER_TYPE_SOFT\r
192  *\r
193  * _unit\r
194  *   COUNTER_UNIT_TICKS or COUNTER_UNIT_NANO\r
195  *\r
196  * _maxallowedvalue\r
197  *    0xffffffffUL\r
198  *\r
199  * _ticksperbase\r
200  *    1\r
201  *\r
202  * _mincycle\r
203  *    Say 10000\r
204 \r
205  * _gpt_ch\r
206  *    NOT USED. Set to 0\r
207  */\r
208 \r
209 #define GEN_COUNTER_HEAD OsCounterType counter_list[OS_COUNTER_CNT]\r
210 #define GEN_COUNTER( _id, _name, _type, _unit,  \\r
211                                         _maxallowedvalue,                       \\r
212                                         _ticksperbase,                          \\r
213                                         _mincycle,          \\r
214                                         _gpt_ch,                                \\r
215                                         _appl_owner, \\r
216                                         _accessing_appl_mask )  \\r
217 {                                                                                               \\r
218         .type = _type,                                                          \\r
219         .unit = _unit,                                                          \\r
220         .alarm_base.maxallowedvalue = _maxallowedvalue, \\r
221         .alarm_base.tickperbase = _ticksperbase,                \\r
222         .alarm_base.mincycle = _mincycle,                               \\r
223         .applOwnerId = _appl_owner, \\r
224         .accessingApplMask = _accessing_appl_mask, \\r
225 }\r
226 \r
227 #define GEN_ALARM_AUTOSTART_NAME(_id)    &(Os_AlarmAutoStart_ ## _id)\r
228 \r
229 /**\r
230  * _id\r
231  * _type\r
232  * _alarms_time\r
233  * _cycle_time\r
234  * _app_mode       Mask of the application modes.\r
235  */\r
236 #define GEN_ALARM_AUTOSTART(_id, _type, _alarm_time, _cycle_time, _app_mode ) \\r
237                 const OsAlarmAutostartType Os_AlarmAutoStart_ ## _id = \\r
238                 { \\r
239                         .autostartType = _type, \\r
240                         .alarmTime = _alarm_time, \\r
241                         .cycleTime = _cycle_time, \\r
242                         .appModeRef = _app_mode \\r
243                 }\r
244 \r
245 #define GEN_ALARM_HEAD OsAlarmType alarm_list[OS_ALARM_CNT]\r
246 \r
247 /**\r
248  * _id\r
249  *    NOT USED\r
250  *\r
251  * _name\r
252  *    Name of the alarm, string\r
253  *\r
254  * _counter_id\r
255  *    The id of the counter to drive the alarm\r
256  *\r
257  * _autostart_ref\r
258  *\r
259  * _X_type       - Any of:\r
260  *                                      ALARM_ACTION_ACTIVATETASK\r
261  *                                      ALARM_ACTION_SETEVENT\r
262  *                                      ALARM_ACTION_ALARMCALLBACK\r
263  *                                      ALARM_ACTION_INCREMENTCOUNTER\r
264  *\r
265  * _X_task_id    - The task ID to activate if _X_type is:\r
266  *                                      ALARM_ACTION_ACTIVATETASK or\r
267  *                                      ALARM_ACTION_SETEVENT\r
268  *\r
269  * _X_event_id   - The event ID if type is ALARM_ACTION_SETEVENT\r
270  *\r
271  * _X_counter_id - The counter ID if type is ALARM_ACTION_INCREMENTCOUNTER\r
272  *\r
273  */\r
274 #define GEN_ALARM( _id, _name, _counter_id,             \\r
275                     _autostart_ref,                     \\r
276                         _action_type,                                           \\r
277                         _action_task_id,                                        \\r
278                         _action_event_id,                                       \\r
279                         _action_counter_id,                                     \\r
280                         _appl_owner,                                            \\r
281                         _accessing_appl_mask )                          \\r
282 {                                                                                       \\r
283         .name = _name,                                                  \\r
284         .counter = &counter_list[_counter_id],  \\r
285         .counter_id = _counter_id,                              \\r
286         .autostartPtr = _autostart_ref,         \\r
287         .action = {                                                             \\r
288                 .type = _action_type,                           \\r
289                 .task_id = _action_task_id,                     \\r
290                 .event_id = _action_event_id,           \\r
291                 .counter_id = _action_counter_id        \\r
292         },                                                                              \\r
293         .applOwnerId = _appl_owner, \\r
294         .accessingApplMask = _accessing_appl_mask, \\r
295 }\r
296 \r
297 /*\r
298  *---------------------- SCHEDULE TABLES -----------------------------------\r
299  */\r
300 \r
301 #define GEN_SCHTBL_EXPIRY_POINT_HEAD(_id ) \\r
302                 OsScheduleTableExpiryPointType Os_SchTblExpPointList_##_id[] =\r
303 \r
304 #define GEN_SCHTBL_EXPIRY_POINT_W_TASK_EVENT(_id, _offset )                                                                             \\r
305         {                                                                                                                                                       \\r
306                 .offset      = _offset,                                                                                                 \\r
307                 .taskList    = Os_SchTblTaskList_ ## _id ## _ ## _offset,                               \\r
308                 .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset),   \\r
309                 .eventList   = Os_SchTblEventList_ ## _id ## _ ## _offset,                              \\r
310                 .eventListCnt    = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset)       \\r
311         }\r
312 \r
313 #define GEN_SCHTBL_EXPIRY_POINT_W_TASK(_id, _offset )                                                   \\r
314         {                                                                                                                                                       \\r
315                 .offset      = _offset,                                                                                                 \\r
316                 .taskList    = Os_SchTblTaskList_ ## _id ## _ ## _offset,                               \\r
317                 .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset),   \\r
318         }\r
319 \r
320 #define GEN_SCHTBL_EXPIRY_POINT_W_EVENT(_id, _offset )                                                  \\r
321         {                                                                                                                                                       \\r
322                 .offset      = _offset,                                                                                                 \\r
323                 .eventList   = Os_SchTblEventList_ ## _id ## _ ## _offset,                              \\r
324                 .eventListCnt    = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset)       \\r
325         }\r
326 \r
327 #define GEN_SCHTBL_TASK_LIST_HEAD( _id, _offset ) \\r
328                 const TaskType Os_SchTblTaskList_ ## _id ## _ ## _offset[] =\r
329 \r
330 #define GEN_SCHTBL_EVENT_LIST_HEAD( _id, _offset ) \\r
331                 const OsScheduleTableEventSettingType Os_SchTblEventList_ ## _id ## _ ## _offset[] =\r
332 \r
333 #define GEN_SCHTBL_AUTOSTART(_id, _type, _offset, _app_mode ) \\r
334                 const struct OsSchTblAutostart Os_SchTblAutoStart_ ## _id = \\r
335                 { \\r
336                         .type = _type, \\r
337                         .offset = _offset, \\r
338                         .appMode = _app_mode, \\r
339                 }\r
340 \r
341 #define GEN_SCHTBL_AUTOSTART_NAME(_id)  &(Os_SchTblAutoStart_ ## _id)\r
342 \r
343 #define GEN_SCHTBL_HEAD OsSchTblType sched_list[] =\r
344 \r
345 /**\r
346  * _id\r
347  *    NOT USED\r
348  *\r
349  * _name\r
350  *    Name of the alarm, string\r
351  *\r
352  * _counter_ref\r
353  *    Pointer to the counter that drives the table\r
354  *\r
355  * _repeating\r
356  *   SINGLE_SHOT or REPEATING\r
357  *\r
358  * _duration\r
359  *   The duration of the schedule table\r
360  *\r
361  * _autostart_ref\r
362  *   Pointer to autostart configuration.\r
363  *   If autostart is desired set name to GEN_SCHTBL_AUTOSTART_NAME(<id>). It also\r
364  *   requires that GEN_SCHTBL_AUTOSTART(...) is set.\r
365  *   Set to NULL if not autostart configuration is desired.\r
366  *\r
367  * The usage of the macro requires that GEN_SCHTBL_EXPIRY_POINT_HEAD(<id>) is also\r
368  * set.\r
369  */\r
370 \r
371 #define GEN_SCHEDULETABLE(  _id, _name, _counter_id, _repeating, \\r
372                                                         _duration,       \\r
373                                                         _autostart_ref ) \\r
374 {                                                                                        \\r
375         .name = _name,                                               \\r
376         .counter = &counter_list[_counter_id],       \\r
377         .repeating = _repeating,                             \\r
378         .duration = _duration,                                   \\r
379         .expirePointList = {                     \\r
380           .data = (void *)( Os_SchTblExpPointList_ ## _id ), \\r
381           .cnt = ARRAY_SIZE(Os_SchTblExpPointList_ ## _id), \\r
382          }, \\r
383         .autostartPtr = _autostart_ref,                          \\r
384 }\r
385 \r
386 \r
387 #define GEN_HOOKS( _startup, _protection, _shutdown, _error, _pretask, _posttask ) \\r
388 struct OsHooks os_conf_global_hooks = { \\r
389                 .StartupHook = _startup,                \\r
390                 .ProtectionHook = _protection,  \\r
391                 .ShutdownHook = _shutdown,              \\r
392                 .ErrorHook = _error,                    \\r
393                 .PreTaskHook = _pretask,                \\r
394                 .PostTaskHook = _posttask               \\r
395 }\r
396 \r
397 #define ALIGN_16(x) (((x)>>4)<<4)\r
398 \r
399 #define DECLARE_STACK(_name,_size) \\r
400         uint8_t stack_##_name[_size]\r
401 \r
402 #define SECTION_BSS_SUPER       __attribute__ ((aligned (16),section(".bss")))\r
403 #define SECTION_BSS_USER        __attribute__ ((aligned (16),section(".bss")))\r
404 \r
405 #endif\r
406 \r
407 \r
408 \r
409 \r
410 \r
411 \r
412 \r