]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_id.c
add a lock for the queue structures when dequeued, for th moment is hardwired to...
[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  * See MaRTE OS license
24  *
25  */
26
27 #include "frescan_id.h"
28
29 typedef struct {
30         uint32_t bit_offset; // offset of the field in the CAN id
31         uint32_t bit_mask;   // the number of bits of the field in a mask
32 } frescan_field_t;
33
34 static frescan_field_t the_fields[] = {
35         {.bit_offset = 21, .bit_mask = 0xFF},
36         {.bit_offset = 17, .bit_mask = 0x0F},
37         {.bit_offset = 13, .bit_mask = 0x0F},
38         {.bit_offset =  9, .bit_mask = 0x0F},
39         {.bit_offset =  1, .bit_mask = 0xFF},
40         {.bit_offset =  0, .bit_mask = 0x01},
41 };
42
43 void frescan_id_set_field(uint32_t *id, uint32_t field, uint32_t value)
44 {
45         frescan_field_t *f = &the_fields[field];
46
47         *id = *id & ~(f->bit_mask << f->bit_offset);
48         *id = *id | ((value & f->bit_mask) << f->bit_offset);
49 }
50
51 uint32_t frescan_id_get_field(uint32_t id, uint32_t field)
52 {
53         frescan_field_t *f = &the_fields[field];
54         return ((id >> f->bit_offset) & f->bit_mask);
55 }