]> rtime.felk.cvut.cz Git - arc.git/blob - include/os_config_macros.h
Merge branch 'mikulka' of git@rtime.felk.cvut.cz:arc into mikulka
[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, _event_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         .eventMask = _event_mask, \\r
87         .activationLimit = 1, \\r
88         .applOwnerId = _appl_owner, \\r
89         .accessingApplMask = _accessing_appl_mask, \\r
90 }\r
91 \r
92 #define GEN_BTASK(      _id, _name, _priority, _scheduling, \\r
93                                         _autostart, _resource_int_p,  _resource_mask, \\r
94                                         _activation_limit, _appl_owner, _accessing_appl_mask ) \\r
95 {                                                                       \\r
96         .pid = TASK_ID_ ## _id,                                 \\r
97         .name = _name,                                  \\r
98         .entry = _id,                           \\r
99         .prio = _priority,                              \\r
100         .proc_type = PROC_BASIC,                \\r
101         .stack.size = sizeof stack_##_id,       \\r
102         .stack.top = stack_##_id,               \\r
103         .autostart = _autostart,                \\r
104         .resourceIntPtr = _resource_int_p, \\r
105         .scheduling = _scheduling, \\r
106         .resourceAccess = _resource_mask, \\r
107         .activationLimit = _activation_limit, \\r
108         .applOwnerId = _appl_owner, \\r
109         .accessingApplMask = _accessing_appl_mask, \\r
110 }\r
111 \r
112 #define GEN_ISR_HEAD const OsIsrConstType Os_IsrConstList[OS_ISR_CNT]\r
113 \r
114 #define GEN_ISR1( _name, _vector, _priority, _entry, _appOwner ) \\r
115 {                                      \\r
116                 .vector = _vector,             \\r
117                 .type = ISR_TYPE_1,            \\r
118                 .priority = _priority,         \\r
119                 .entry = _entry,               \\r
120                 .name = _name,                 \\r
121                 .resourceMask = 0,             \\r
122                 .appOwner = _appOwner,         \\r
123 }\r
124 \r
125 #define GEN_ISR2( _name, _vector, _priority, _entry, _appOwner, _resourceMask ) \\r
126 {                                      \\r
127                 .vector = _vector,             \\r
128                 .type = ISR_TYPE_2,            \\r
129                 .priority = _priority,         \\r
130                 .entry = _entry,               \\r
131                 .name = _name,                 \\r
132                 .resourceMask = _resourceMask, \\r
133                 .appOwner = _appOwner,         \\r
134 }\r
135 \r
136 \r
137 #define GEN_ISR_MAP uint8_t Os_VectorToIsr[NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS]\r
138 \r
139 \r
140 #define GEN_RESOURCE_HEAD OsResourceType resource_list[OS_RESOURCE_CNT]\r
141 \r
142 \r
143 /**\r
144  * _id\r
145  * _type              RESOURCE_TYPE_STANDARD, RESOURCE_TYPE_LINKED or RESOURCE_TYPE_INTERNAL\r
146  * _ceiling_priority  The calculated ceiling priority\r
147  */\r
148 #define GEN_RESOURCE( _id, _type, _ceiling_priority, _appl_owner, _accessing_appl_mask ) \\r
149 {                                                                                               \\r
150         .nr= _id,                                                                       \\r
151         .type= _type,                                                           \\r
152         .ceiling_priority = _ceiling_priority,          \\r
153         .owner = (-1),                                                          \\r
154         .applOwnerId = _appl_owner,                             \\r
155         .accessingApplMask = _accessing_appl_mask       \\r
156 }\r
157 \r
158 /**\r
159  * _id\r
160  *      NOT_USED\r
161  * _name\r
162  *    Name of the alarm, string\r
163  *\r
164  * _type\r
165  *   COUNTER_TYPE_HARD or COUNTER_TYPE_SOFT\r
166  *\r
167  * _unit\r
168  *   COUNTER_UNIT_TICKS or COUNTER_UNIT_NANO\r
169  *\r
170  * _maxallowedvalue\r
171  *    0xffffffffUL\r
172  *\r
173  * _ticksperbase\r
174  *    1\r
175  *\r
176  * _mincycle\r
177  *    Say 10000\r
178 \r
179  * _gpt_ch\r
180  *    NOT USED. Set to 0\r
181  */\r
182 \r
183 #define GEN_COUNTER_HEAD OsCounterType counter_list[OS_COUNTER_CNT]\r
184 #define GEN_COUNTER( _id, _name, _type, _unit,  \\r
185                                         _maxallowedvalue,                       \\r
186                                         _ticksperbase,                          \\r
187                                         _mincycle,          \\r
188                                         _gpt_ch,                                \\r
189                                         _appl_owner, \\r
190                                         _accessing_appl_mask )  \\r
191 {                                                                                               \\r
192         .type = _type,                                                          \\r
193         .unit = _unit,                                                          \\r
194         .alarm_base.maxallowedvalue = _maxallowedvalue, \\r
195         .alarm_base.tickperbase = _ticksperbase,                \\r
196         .alarm_base.mincycle = _mincycle,                               \\r
197         .applOwnerId = _appl_owner, \\r
198         .accessingApplMask = _accessing_appl_mask, \\r
199 }\r
200 \r
201 #define GEN_ALARM_AUTOSTART_NAME(_id)    &(Os_AlarmAutoStart_ ## _id)\r
202 \r
203 /**\r
204  * _id\r
205  * _type\r
206  * _alarms_time\r
207  * _cycle_time\r
208  * _app_mode       Mask of the application modes.\r
209  */\r
210 #define GEN_ALARM_AUTOSTART(_id, _type, _alarm_time, _cycle_time, _app_mode ) \\r
211                 const OsAlarmAutostartType Os_AlarmAutoStart_ ## _id = \\r
212                 { \\r
213                         .autostartType = _type, \\r
214                         .alarmTime = _alarm_time, \\r
215                         .cycleTime = _cycle_time, \\r
216                         .appModeRef = _app_mode \\r
217                 }\r
218 \r
219 #define GEN_ALARM_HEAD OsAlarmType alarm_list[OS_ALARM_CNT]\r
220 \r
221 /**\r
222  * _id\r
223  *    NOT USED\r
224  *\r
225  * _name\r
226  *    Name of the alarm, string\r
227  *\r
228  * _counter_id\r
229  *    The id of the counter to drive the alarm\r
230  *\r
231  * _autostart_ref\r
232  *\r
233  * _X_type       - Any of:\r
234  *                                      ALARM_ACTION_ACTIVATETASK\r
235  *                                      ALARM_ACTION_SETEVENT\r
236  *                                      ALARM_ACTION_ALARMCALLBACK\r
237  *                                      ALARM_ACTION_INCREMENTCOUNTER\r
238  *\r
239  * _X_task_id    - The task ID to activate if _X_type is:\r
240  *                                      ALARM_ACTION_ACTIVATETASK or\r
241  *                                      ALARM_ACTION_SETEVENT\r
242  *\r
243  * _X_event_id   - The event ID if type is ALARM_ACTION_SETEVENT\r
244  *\r
245  * _X_counter_id - The counter ID if type is ALARM_ACTION_INCREMENTCOUNTER\r
246  *\r
247  */\r
248 #define GEN_ALARM( _id, _name, _counter_id,             \\r
249                     _autostart_ref,                     \\r
250                         _action_type,                                           \\r
251                         _action_task_id,                                        \\r
252                         _action_event_id,                                       \\r
253                         _action_counter_id,                                     \\r
254                         _appl_owner,                                            \\r
255                         _accessing_appl_mask )                          \\r
256 {                                                                                       \\r
257         .name = _name,                                                  \\r
258         .counter = &counter_list[_counter_id],  \\r
259         .counter_id = _counter_id,                              \\r
260         .autostartPtr = _autostart_ref,         \\r
261         .action = {                                                             \\r
262                 .type = _action_type,                           \\r
263                 .task_id = _action_task_id,                     \\r
264                 .event_id = _action_event_id,           \\r
265                 .counter_id = _action_counter_id        \\r
266         },                                                                              \\r
267         .applOwnerId = _appl_owner, \\r
268         .accessingApplMask = _accessing_appl_mask, \\r
269 }\r
270 \r
271 /*\r
272  *---------------------- SCHEDULE TABLES -----------------------------------\r
273  */\r
274 \r
275 #define GEN_SCHTBL_EXPIRY_POINT_HEAD(_id ) \\r
276                 OsScheduleTableExpiryPointType Os_SchTblExpPointList_##_id[] =\r
277 \r
278 #define GEN_SCHTBL_EXPIRY_POINT_W_TASK_EVENT(_id, _offset )                                                                             \\r
279         {                                                                                                                                                       \\r
280                 .offset      = _offset,                                                                                                 \\r
281                 .taskList    = Os_SchTblTaskList_ ## _id ## _ ## _offset,                               \\r
282                 .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset),   \\r
283                 .eventList   = Os_SchTblEventList_ ## _id ## _ ## _offset,                              \\r
284                 .eventListCnt    = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset)       \\r
285         }\r
286 \r
287 #define GEN_SCHTBL_EXPIRY_POINT_W_TASK(_id, _offset )                                                   \\r
288         {                                                                                                                                                       \\r
289                 .offset      = _offset,                                                                                                 \\r
290                 .taskList    = Os_SchTblTaskList_ ## _id ## _ ## _offset,                               \\r
291                 .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset),   \\r
292         }\r
293 \r
294 #define GEN_SCHTBL_EXPIRY_POINT_W_EVENT(_id, _offset )                                                  \\r
295         {                                                                                                                                                       \\r
296                 .offset      = _offset,                                                                                                 \\r
297                 .eventList   = Os_SchTblEventList_ ## _id ## _ ## _offset,                              \\r
298                 .eventListCnt    = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset)       \\r
299         }\r
300 \r
301 #define GEN_SCHTBL_TASK_LIST_HEAD( _id, _offset ) \\r
302                 const TaskType Os_SchTblTaskList_ ## _id ## _ ## _offset[] =\r
303 \r
304 #define GEN_SCHTBL_EVENT_LIST_HEAD( _id, _offset ) \\r
305                 const OsScheduleTableEventSettingType Os_SchTblEventList_ ## _id ## _ ## _offset[] =\r
306 \r
307 #define GEN_SCHTBL_AUTOSTART(_id, _type, _offset, _app_mode ) \\r
308                 const struct OsSchTblAutostart Os_SchTblAutoStart_ ## _id = \\r
309                 { \\r
310                         .type = _type, \\r
311                         .offset = _offset, \\r
312                         .appMode = _app_mode, \\r
313                 }\r
314 \r
315 #define GEN_SCHTBL_AUTOSTART_NAME(_id)  &(Os_SchTblAutoStart_ ## _id)\r
316 \r
317 #define GEN_SCHTBL_HEAD OsSchTblType sched_list[OS_SCHTBL_CNT]\r
318 \r
319 /**\r
320  * _id\r
321  *    NOT USED\r
322  *\r
323  * _name\r
324  *    Name of the alarm, string\r
325  *\r
326  * _counter_ref\r
327  *    Pointer to the counter that drives the table\r
328  *\r
329  * _repeating\r
330  *   SINGLE_SHOT or REPEATING\r
331  *\r
332  * _duration\r
333  *   The duration of the schedule table\r
334  *\r
335  * _autostart_ref\r
336  *   Pointer to autostart configuration.\r
337  *   If autostart is desired set name to GEN_SCHTBL_AUTOSTART_NAME(<id>). It also\r
338  *   requires that GEN_SCHTBL_AUTOSTART(...) is set.\r
339  *   Set to NULL if not autostart configuration is desired.\r
340  *\r
341  * The usage of the macro requires that GEN_SCHTBL_EXPIRY_POINT_HEAD(<id>) is also\r
342  * set.\r
343  */\r
344 \r
345 #define GEN_SCHEDULETABLE(  _id, _name, _counter_id, _repeating, \\r
346                                                         _duration,              \\r
347                                                         _autostart_ref,         \\r
348                                                         _appl_owner,            \\r
349                                                         _accessing_appl_mask )  \\r
350 {                                                                                        \\r
351         .name = _name,                                               \\r
352         .counter = &counter_list[_counter_id],       \\r
353         .repeating = _repeating,                             \\r
354         .duration = _duration,                                   \\r
355         .expirePointList = {                     \\r
356           .data = (void *)( Os_SchTblExpPointList_ ## _id ), \\r
357           .cnt = ARRAY_SIZE(Os_SchTblExpPointList_ ## _id), \\r
358          }, \\r
359          .autostartPtr = _autostart_ref,\\r
360         .applOwnerId = _appl_owner, \\r
361         .accessingApplMask = _accessing_appl_mask, \\r
362 }\r
363 \r
364 \r
365 #define GEN_HOOKS( _startup, _protection, _shutdown, _error, _pretask, _posttask ) \\r
366 struct OsHooks os_conf_global_hooks = { \\r
367                 .StartupHook = _startup,                \\r
368                 .ProtectionHook = _protection,  \\r
369                 .ShutdownHook = _shutdown,              \\r
370                 .ErrorHook = _error,                    \\r
371                 .PreTaskHook = _pretask,                \\r
372                 .PostTaskHook = _posttask               \\r
373 }\r
374 \r
375 #define ALIGN_16(x) (((x)>>4)<<4)\r
376 \r
377 #define DECLARE_STACK(_name,_size) \\r
378         uint8_t stack_##_name[_size]\r
379 \r
380 #define SECTION_BSS_SUPER       __attribute__ ((aligned (16),section(".bss")))\r
381 #define SECTION_BSS_USER        __attribute__ ((aligned (16),section(".bss")))\r
382 \r
383 #endif\r
384 \r
385 \r
386 \r
387 \r
388 \r
389 \r
390 \r