]> rtime.felk.cvut.cz Git - arc.git/blob - include/alist_i.h
Added example of CAN communication for the TMS570LS31x HDK
[arc.git] / include / alist_i.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 \r
17 \r
18 \r
19 \r
20 \r
21 \r
22 \r
23 #ifndef ALIST_I_H_\r
24 #define ALIST_I_H_\r
25 \r
26 /*\r
27  * Some macros to handle a static array and it's data.\r
28  *\r
29  *\r
30  * Usage:\r
31  * struct foo_s {\r
32  *   int foo_data;\r
33  * };\r
34  *\r
35  * struct foo_s my_data[5];\r
36  *\r
37  * // Create the head\r
38  * SA_LIST_HEAD(foo,foo_s) arr_list;\r
39  * // Init the head with data.\r
40  * arr_list = SA_LIST_HEAD_INITIALIZER(5,my_data);\r
41  *\r
42  */\r
43 \r
44 \r
45 /**\r
46  * @def ALIST_HEAD(name, type)\r
47  * Declare the head for the static list\r
48  *\r
49  * @param name - name of the struct\r
50  * @param type - struct type for the array\r
51  */\r
52 \r
53 \r
54 #define SA_LIST_HEAD(name, type)        \\r
55 struct name {                                           \\r
56         int cnt;                                                \\r
57         struct type *data;                              \\r
58 }\r
59 \r
60 #define SA_LIST_HEAD_INITIALIZER(elem_cnt, data_p ) \\r
61 {                                                                                                       \\r
62         .cnt = (elem_cnt),                                                              \\r
63         .data = (data_p)                                                                \\r
64 }\r
65 \r
66 #define SA_LIST_CNT(head)                                       (head)->cnt\r
67 #define SA_LIST_GET( head, index )                      (&(head)->data[(index)])\r
68 #define SA_LIST_FOREACH( head, ivar)            for( (ivar)=0;(ivar)<SA_LIST_CNT(head);(ivar)++)\r
69 \r
70 #endif /*ALIST_I_H_*/\r