Skip to content

Commit b4040f2

Browse files
authored
Merge pull request #15026 from OpenNuvoton/nvt_can_mask_5.15
[mbed-os-5.15] Nuvoton M480/M451 CAN API support mask feature
2 parents 4866c79 + 75dd2c2 commit b4040f2

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

targets/TARGET_NUVOTON/TARGET_M451/can_api.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,18 @@ int can_mode(can_t *obj, CanMode mode)
285285

286286
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
287287
{
288-
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle , (uint32_t)format, id);
288+
uint32_t numask = mask;
289+
290+
if (numask == 0x0000) {
291+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
292+
}
293+
294+
if (format == CANStandard) {
295+
numask = (mask << 18);
296+
}
297+
298+
numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk);
299+
return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask);
289300
}
290301

291302

targets/TARGET_NUVOTON/TARGET_M480/can_api.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,19 @@ int can_mode(can_t *obj, CanMode mode)
329329

330330
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
331331
{
332-
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
333-
}
332+
uint32_t numask = mask;
333+
334+
if (numask == 0x0000) {
335+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
336+
}
334337

338+
if (format == CANStandard) {
339+
numask = (mask << 18);
340+
}
341+
342+
numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk);
343+
return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask);
344+
}
335345

336346
void can_reset(can_t *obj)
337347
{

0 commit comments

Comments
 (0)