Skip to content

Commit 1ac928e

Browse files
authored
Merge pull request ARMmbed#15020 from OpenNuvoton/nvt_can_mask
Nuvoton: M480/M451 CAN API support mask feature
2 parents f6e165f + f28181c commit 1ac928e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

targets/TARGET_NUVOTON/TARGET_M451/can_api.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,17 @@ 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+
if( numask == 0x0000 )
290+
{
291+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
292+
}
293+
if( format == CANStandard )
294+
{
295+
numask = (mask << 18);
296+
}
297+
numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk);
298+
return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask);
289299
}
290300

291301

targets/TARGET_NUVOTON/TARGET_M480/can_api.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,17 @@ int can_mode(can_t *obj, CanMode mode)
332332

333333
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
334334
{
335-
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
335+
uint32_t numask = mask;
336+
if( numask == 0x0000 )
337+
{
338+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
339+
}
340+
if( format == CANStandard )
341+
{
342+
numask = (mask << 18);
343+
}
344+
numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk);
345+
return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask);
336346
}
337347

338348

0 commit comments

Comments
 (0)