Skip to content

Commit 3198bab

Browse files
committed
NuMaker M480 & M451 support CAN mask
1 parent 4866c79 commit 3198bab

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +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);
332+
uint32_t numask = mask;
333+
if( numask == 0x0000 )
334+
{
335+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id);
336+
}
337+
if( format == CANStandard )
338+
{
339+
numask = (mask << 18);
340+
}
341+
numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk);
342+
return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask);
333343
}
334344

335-
336345
void can_reset(can_t *obj)
337346
{
338347
const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab);

0 commit comments

Comments
 (0)