From 3198bab7c6a2d00a268c1238089f7ebf8ab8a9a3 Mon Sep 17 00:00:00 2001 From: cyliangtw Date: Tue, 24 Aug 2021 17:21:01 +0800 Subject: [PATCH] NuMaker M480 & M451 support CAN mask --- targets/TARGET_NUVOTON/TARGET_M451/can_api.c | 12 +++++++++++- targets/TARGET_NUVOTON/TARGET_M480/can_api.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M451/can_api.c b/targets/TARGET_NUVOTON/TARGET_M451/can_api.c index f836768e48..775f98f8b0 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/can_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/can_api.c @@ -285,7 +285,17 @@ int can_mode(can_t *obj, CanMode mode) int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { - return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle , (uint32_t)format, id); + uint32_t numask = mask; + if( numask == 0x0000 ) + { + return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id); + } + if( format == CANStandard ) + { + numask = (mask << 18); + } + numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk); + return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask); } diff --git a/targets/TARGET_NUVOTON/TARGET_M480/can_api.c b/targets/TARGET_NUVOTON/TARGET_M480/can_api.c index 0d3e27a45d..e82ad24911 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/can_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/can_api.c @@ -329,10 +329,19 @@ int can_mode(can_t *obj, CanMode mode) int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { - return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id); + uint32_t numask = mask; + if( numask == 0x0000 ) + { + return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id); + } + if( format == CANStandard ) + { + numask = (mask << 18); + } + numask = (numask | CAN_IF_MASK2_MDIR_Msk | CAN_IF_MASK2_MXTD_Msk); + return CAN_SetRxMsgAndMsk((CAN_T *)NU_MODBASE(obj->can), handle, (uint32_t)format, id, numask); } - void can_reset(can_t *obj) { const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab);