4 * @brief functions to manage the fields of the FRESCAN Identifier
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
23 * See MaRTE OS license
27 #include "frescan_id.h"
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
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},
43 void frescan_id_set_field(uint32_t *id, uint32_t field, uint32_t value)
45 frescan_field_t *f = &the_fields[field];
47 *id = *id & ~(f->bit_mask << f->bit_offset);
48 *id = *id | ((value & f->bit_mask) << f->bit_offset);
51 uint32_t frescan_id_get_field(uint32_t id, uint32_t field)
53 frescan_field_t *f = &the_fields[field];
54 return ((id >> f->bit_offset) & f->bit_mask);