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