]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_id.c
Do not enter unnecessary subdirectories
[frescor/fna.git] / src_frescan / frescan_id.c
1 /*!
2  * @file frescan_id.c
3  *
4  * @brief functions to manage the fields of the FRESCAN Identifier
5  *
6  * @version 0.01
7  *
8  * @date 27-Feb-2008
9  *
10  * @author
11  *      Daniel Sangorrin
12  *
13  * @comments
14  *
15  * This file contains the functions needed to manage the fields of a
16  * FRESCAN identifier. That is, how the 29 CAN ID bits of each frame are
17  * allocated in the FRESCAN protocol. If this configuration was to
18  * be changed (for example, the bits per field or the position  of the
19  * fields inside the ID), then only these functions need to be modified
20  *
21  * @license
22  *
23 //----------------------------------------------------------------------
24 //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
25 //
26 //    Universidad de Cantabria,              SPAIN
27 //    University of York,                    UK
28 //    Scuola Superiore Sant'Anna,            ITALY
29 //    Kaiserslautern University,             GERMANY
30 //    Univ. Politecnica  Valencia,           SPAIN
31 //    Czech Technical University in Prague,  CZECH REPUBLIC
32 //    ENEA                                   SWEDEN
33 //    Thales Communication S.A.              FRANCE
34 //    Visual Tools S.A.                      SPAIN
35 //    Rapita Systems Ltd                     UK
36 //    Evidence                               ITALY
37 //
38 //    See http://www.frescor.org
39 //
40 //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
41 //        in part by the European Union Sixth Framework Programme
42 //        The European Union is not liable of any use that may be
43 //        made of this code.
44 //
45 //
46 //  based on previous work (FSF) done in the FIRST project
47 //
48 //   Copyright (C) 2005  Mälardalen University, SWEDEN
49 //                       Scuola Superiore S.Anna, ITALY
50 //                       Universidad de Cantabria, SPAIN
51 //                       University of York, UK
52 //
53 // This file is part of FNA (Frescor Network Adaptation)
54 //
55 // FNA is free software; you can redistribute it and/or modify it
56 // under terms of the GNU General Public License as published by the
57 // Free Software Foundation; either version 2, or (at your option) any
58 // later version.  FNA is distributed in the hope that it will be
59 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
60 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
61 // General Public License for more details. You should have received a
62 // copy of the GNU General Public License along with FNA; see file
63 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
64 // Cambridge, MA 02139, USA.
65 //
66 // As a special exception, including FNA header files in a file,
67 // instantiating FNA generics or templates, or linking other files
68 // with FNA objects to produce an executable application, does not
69 // by itself cause the resulting executable application to be covered
70 // by the GNU General Public License. This exception does not
71 // however invalidate any other reasons why the executable file might be
72 // covered by the GNU Public License.
73 // -----------------------------------------------------------------------
74  *
75  */
76
77 #include "frescan_id.h"
78
79 typedef struct {
80         uint32_t bit_offset; // offset of the field in the CAN id
81         uint32_t bit_mask;   // the number of bits of the field in a mask
82 } frescan_field_t;
83
84 static frescan_field_t the_fields[] = {
85         {.bit_offset = 21, .bit_mask = 0xFF},
86         {.bit_offset = 17, .bit_mask = 0x0F},
87         {.bit_offset = 13, .bit_mask = 0x0F},
88         {.bit_offset =  9, .bit_mask = 0x0F},
89         {.bit_offset =  1, .bit_mask = 0xFF},
90         {.bit_offset =  0, .bit_mask = 0x01},
91 };
92
93 void frescan_id_set_field(uint32_t *id, uint32_t field, uint32_t value)
94 {
95         frescan_field_t *f = &the_fields[field];
96
97         *id = *id & ~(f->bit_mask << f->bit_offset);
98         *id = *id | ((value & f->bit_mask) << f->bit_offset);
99 }
100
101 uint32_t frescan_id_get_field(uint32_t id, uint32_t field)
102 {
103         frescan_field_t *f = &the_fields[field];
104         return ((id >> f->bit_offset) & f->bit_mask);
105 }