Skip to content

Commit 79ca430

Browse files
committed
Match: address -> id
1 parent 8b82c23 commit 79ca430

File tree

5 files changed

+60
-60
lines changed

5 files changed

+60
-60
lines changed

ports/atmel-samd/common-hal/canio/Listener.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ STATIC void static_assertions(void) {
5858
MP_STATIC_ASSERT(CAN_XIDFE_0_EFEC_STF0M_Val + 1 == CAN_XIDFE_0_EFEC_STF1M_Val);
5959
}
6060

61-
STATIC bool single_address_filter(canio_match_obj_t *match) {
62-
return match->mask == 0 || match->mask == match->address;
61+
STATIC bool single_id_filter(canio_match_obj_t *match) {
62+
return match->mask == 0 || match->mask == match->id;
6363
}
6464

6565
STATIC bool standard_filter_in_use(CanMramSidfe *filter) {
@@ -76,7 +76,7 @@ STATIC size_t num_filters_needed(size_t nmatch, canio_match_obj_t **matches, boo
7676
if (extended != matches[i]->extended) {
7777
continue;
7878
}
79-
if (single_address_filter(matches[i])) {
79+
if (single_id_filter(matches[i])) {
8080
num_half_filters_needed += 1;
8181
} else {
8282
num_half_filters_needed += 2;
@@ -191,7 +191,7 @@ STATIC void install_extended_filter(CanMramXidfe *extended, int id1, int id2, in
191191
}
192192

193193

194-
#define NO_ADDRESS (-1)
194+
#define NO_ID (-1)
195195
void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t **matches) {
196196
int fifo = self->fifo_idx;
197197

@@ -207,31 +207,31 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t **
207207
CanMramSidfe *standard = next_standard_filter(self, NULL);
208208
CanMramXidfe *extended = next_extended_filter(self, NULL);
209209

210-
int first_address = NO_ADDRESS;
210+
int first_id = NO_ID;
211211

212-
// step 1: single address standard matches
212+
// step 1: single id standard matches
213213
// we have to gather up pairs and stuff them in a single filter entry
214214
for(size_t i = 0; i<nmatch; i++) {
215215
canio_match_obj_t *match = matches[i];
216216
if (match->extended) {
217217
continue;
218218
}
219-
if (!single_address_filter(match)) {
219+
if (!single_id_filter(match)) {
220220
continue;
221221
}
222-
if (first_address != NO_ADDRESS) {
223-
install_standard_filter(standard, first_address, match->address, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_DUAL_Val);
224-
first_address = NO_ADDRESS;
222+
if (first_id != NO_ID) {
223+
install_standard_filter(standard, first_id, match->id, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_DUAL_Val);
224+
first_id = NO_ID;
225225
standard = next_standard_filter(self, standard);
226226
} else {
227-
first_address = match->address;
227+
first_id = match->id;
228228
}
229229
}
230-
// step 1.5. odd single address standard match
231-
if (first_address != NO_ADDRESS) {
232-
install_standard_filter(standard, first_address, first_address, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_DUAL_Val);
230+
// step 1.5. odd single id standard match
231+
if (first_id != NO_ID) {
232+
install_standard_filter(standard, first_id, first_id, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_DUAL_Val);
233233
standard = next_standard_filter(self, standard);
234-
first_address = NO_ADDRESS;
234+
first_id = NO_ID;
235235
}
236236

237237
// step 2: standard mask filter
@@ -240,36 +240,36 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t **
240240
if (match->extended) {
241241
continue;
242242
}
243-
if (single_address_filter(match)) {
243+
if (single_id_filter(match)) {
244244
continue;
245245
}
246-
install_standard_filter(standard, match->address, match->mask, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_CLASSIC_Val);
246+
install_standard_filter(standard, match->id, match->mask, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_CLASSIC_Val);
247247
standard = next_standard_filter(self, standard);
248248
}
249249

250-
// step 3: single address extended matches
250+
// step 3: single id extended matches
251251
// we have to gather up pairs and stuff them in a single filter entry
252252
for(size_t i = 0; i<nmatch; i++) {
253253
canio_match_obj_t *match = matches[i];
254254
if (!match->extended) {
255255
continue;
256256
}
257-
if (!single_address_filter(match)) {
257+
if (!single_id_filter(match)) {
258258
continue;
259259
}
260-
if (first_address != NO_ADDRESS) {
261-
install_extended_filter(extended, first_address, match->address, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_DUAL_Val);
262-
first_address = NO_ADDRESS;
260+
if (first_id != NO_ID) {
261+
install_extended_filter(extended, first_id, match->id, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_DUAL_Val);
262+
first_id = NO_ID;
263263
extended = next_extended_filter(self, extended);
264264
} else {
265-
first_address = match->address;
265+
first_id = match->id;
266266
}
267267
}
268-
// step 3.5. odd single address standard match
269-
if (first_address != NO_ADDRESS) {
270-
install_extended_filter(extended, first_address, first_address, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_DUAL_Val);
268+
// step 3.5. odd single id standard match
269+
if (first_id != NO_ID) {
270+
install_extended_filter(extended, first_id, first_id, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_DUAL_Val);
271271
extended = next_extended_filter(self, extended);
272-
first_address = NO_ADDRESS;
272+
first_id = NO_ID;
273273
}
274274

275275
// step 4: extended mask filters
@@ -278,10 +278,10 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t **
278278
if (!match->extended) {
279279
continue;
280280
}
281-
if (single_address_filter(match)) {
281+
if (single_id_filter(match)) {
282282
continue;
283283
}
284-
install_extended_filter(extended, match->address, match->mask, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_CLASSIC_Val);
284+
install_extended_filter(extended, match->id, match->mask, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_CLASSIC_Val);
285285
extended = next_extended_filter(self, extended);
286286
}
287287

@@ -363,7 +363,7 @@ bool common_hal_canio_listener_readinto(canio_listener_obj_t *self, canio_messag
363363
if (message->extended) {
364364
message->id = hw_message->rxf0.bit.ID;
365365
} else {
366-
message->id = hw_message->rxf0.bit.ID >> 18; // short addresses are left-justified
366+
message->id = hw_message->rxf0.bit.ID >> 18; // short ids are left-justified
367367
}
368368
message->rtr = hw_message->rxf0.bit.RTR;
369369
message->size = hw_message->rxf1.bit.DLC;

shared-bindings/canio/Match.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@
3333
//| """Describe CAN bus messages to match"""
3434
//|
3535
//|
36-
//| def __init__(self, address: int, *, mask: int = 0, extended: bool = False):
36+
//| def __init__(self, id: int, *, mask: int = 0, extended: bool = False):
3737
//| """Construct a Match with the given properties.
3838
//|
39-
//| If mask is nonzero, then the filter is for any sender which matches all
40-
//| the nonzero bits in mask. Otherwise, it matches exactly the given address.
41-
//| If extended is true then only extended addresses are matched, otherwise
42-
//| only standard addresses are matched."""
39+
//| If mask is nonzero, then the filter is for any id which matches all
40+
//| the nonzero bits in mask. Otherwise, it matches exactly the given id.
41+
//| If extended is true then only extended ids are matched, otherwise
42+
//| only standard ids are matched."""
4343
//|
4444

4545
STATIC mp_obj_t canio_match_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
46-
enum { ARG_address, ARG_mask, ARG_extended, NUM_ARGS };
46+
enum { ARG_id, ARG_mask, ARG_extended, NUM_ARGS };
4747
static const mp_arg_t allowed_args[] = {
48-
{ MP_QSTR_address, MP_ARG_INT | MP_ARG_REQUIRED },
48+
{ MP_QSTR_id, MP_ARG_INT | MP_ARG_REQUIRED },
4949
{ MP_QSTR_mask, MP_ARG_INT, {.u_int = 0} },
5050
{ MP_QSTR_extended, MP_ARG_BOOL, {.u_bool = false} },
5151
};
@@ -54,44 +54,44 @@ STATIC mp_obj_t canio_match_make_new(const mp_obj_type_t *type, size_t n_args, c
5454

5555
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
5656

57-
int address_bits = args[ARG_extended].u_bool ? 0x1fffffff : 0x7ff;
58-
int address = args[ARG_address].u_int;
57+
int id_bits = args[ARG_extended].u_bool ? 0x1fffffff : 0x7ff;
58+
int id = args[ARG_id].u_int;
5959
int mask = args[ARG_mask].u_int;
6060

61-
if (address & ~address_bits) {
62-
mp_raise_ValueError_varg(translate("%q out of range"), MP_QSTR_address);
61+
if (id & ~id_bits) {
62+
mp_raise_ValueError_varg(translate("%q out of range"), MP_QSTR_id);
6363
}
6464

65-
if (mask & ~address_bits) {
65+
if (mask & ~id_bits) {
6666
mp_raise_ValueError_varg(translate("%q out of range"), MP_QSTR_mask);
6767
}
6868

6969
canio_match_obj_t *self = m_new_obj(canio_match_obj_t);
7070
self->base.type = &canio_match_type;
71-
common_hal_canio_match_construct(self, args[ARG_address].u_int, args[ARG_mask].u_int, args[ARG_extended].u_bool);
71+
common_hal_canio_match_construct(self, args[ARG_id].u_int, args[ARG_mask].u_int, args[ARG_extended].u_bool);
7272
return self;
7373
}
7474

75-
//| address: int
76-
//| """The address to match"""
75+
//| id: int
76+
//| """The id to match"""
7777
//|
7878

79-
STATIC mp_obj_t canio_match_address_get(mp_obj_t self_in) {
79+
STATIC mp_obj_t canio_match_id_get(mp_obj_t self_in) {
8080
canio_match_obj_t *self = self_in;
81-
return MP_OBJ_NEW_SMALL_INT(common_hal_canio_match_get_address(self));
81+
return MP_OBJ_NEW_SMALL_INT(common_hal_canio_match_get_id(self));
8282
}
83-
MP_DEFINE_CONST_FUN_OBJ_1(canio_match_address_get_obj, canio_match_address_get);
83+
MP_DEFINE_CONST_FUN_OBJ_1(canio_match_id_get_obj, canio_match_id_get);
8484

85-
const mp_obj_property_t canio_match_address_obj = {
85+
const mp_obj_property_t canio_match_id_obj = {
8686
.base.type = &mp_type_property,
87-
.proxy = {(mp_obj_t)&canio_match_address_get_obj,
87+
.proxy = {(mp_obj_t)&canio_match_id_get_obj,
8888
(mp_obj_t)&mp_const_none_obj,
8989
(mp_obj_t)&mp_const_none_obj},
9090
};
9191

9292
//|
9393
//| mask: int
94-
//| """The optional mask of addresses to match"""
94+
//| """The optional mask of ids to match"""
9595
//|
9696

9797
STATIC mp_obj_t canio_match_mask_get(mp_obj_t self_in) {
@@ -108,7 +108,7 @@ const mp_obj_property_t canio_match_mask_obj = {
108108
};
109109

110110
//| extended: bool
111-
//| """True to match extended addresses, False to match standard addresses"""
111+
//| """True to match extended ids, False to match standard ides"""
112112
//|
113113

114114
STATIC mp_obj_t canio_match_extended_get(mp_obj_t self_in) {
@@ -125,7 +125,7 @@ const mp_obj_property_t canio_match_extended_obj = {
125125
};
126126

127127
STATIC const mp_rom_map_elem_t canio_match_locals_dict_table[] = {
128-
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&canio_match_address_obj) },
128+
{ MP_ROM_QSTR(MP_QSTR_id), MP_ROM_PTR(&canio_match_id_obj) },
129129
{ MP_ROM_QSTR(MP_QSTR_mask), MP_ROM_PTR(&canio_match_mask_obj) },
130130
{ MP_ROM_QSTR(MP_QSTR_extended), MP_ROM_PTR(&canio_match_extended_obj) },
131131
};

shared-bindings/canio/Match.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
extern const mp_obj_type_t canio_match_type;
3333

34-
void common_hal_canio_match_construct(canio_match_obj_t *self, int address, int mask, bool extended);
35-
int common_hal_canio_match_get_address(const canio_match_obj_t *self);
34+
void common_hal_canio_match_construct(canio_match_obj_t *self, int id, int mask, bool extended);
35+
int common_hal_canio_match_get_id(const canio_match_obj_t *self);
3636
int common_hal_canio_match_get_mask(const canio_match_obj_t *self);
3737
bool common_hal_canio_match_get_extended(const canio_match_obj_t *self);

shared-module/canio/Match.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
#include "shared-module/canio/Match.h"
2828

29-
void common_hal_canio_match_construct(canio_match_obj_t *self, int address, int mask, bool extended) {
30-
self->address = address;
29+
void common_hal_canio_match_construct(canio_match_obj_t *self, int id, int mask, bool extended) {
30+
self->id = id;
3131
self->mask = mask;
3232
self->extended = extended;
3333
}
3434

35-
int common_hal_canio_match_get_address(const canio_match_obj_t *self) {
36-
return self->address;
35+
int common_hal_canio_match_get_id(const canio_match_obj_t *self) {
36+
return self->id;
3737
}
3838
int common_hal_canio_match_get_mask(const canio_match_obj_t *self) {
3939
return self->mask;

shared-module/canio/Match.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
typedef struct {
3232
mp_obj_base_t base;
33-
int address;
33+
int id;
3434
int mask;
3535
bool extended;
3636
} canio_match_obj_t;

0 commit comments

Comments
 (0)