@@ -618,6 +618,7 @@ static void can_mcan_get_message(const struct device *dev,
618618 struct can_mcan_rx_fifo_hdr hdr ;
619619 bool rtr_filter_mask ;
620620 bool rtr_filter ;
621+ bool fd_frame_filter ;
621622
622623 while ((* fifo_status_reg & CAN_MCAN_RXF0S_F0FL )) {
623624 get_idx = (* fifo_status_reg & CAN_MCAN_RXF0S_F0GI ) >>
@@ -653,16 +654,22 @@ static void can_mcan_get_message(const struct device *dev,
653654 frame .flags |= CAN_FRAME_IDE ;
654655 rtr_filter_mask = (data -> ext_filt_rtr_mask & BIT (filt_idx )) != 0 ;
655656 rtr_filter = (data -> ext_filt_rtr & BIT (filt_idx )) != 0 ;
657+ fd_frame_filter = (data -> ext_filt_fd_frame & BIT (filt_idx )) != 0 ;
656658 } else {
657659 frame .id = hdr .std_id ;
658660 rtr_filter_mask = (data -> std_filt_rtr_mask & BIT (filt_idx )) != 0 ;
659661 rtr_filter = (data -> std_filt_rtr & BIT (filt_idx )) != 0 ;
662+ fd_frame_filter = (data -> std_filt_fd_frame & BIT (filt_idx )) != 0 ;
660663 }
661664
662665 if (rtr_filter_mask && (rtr_filter != ((frame .flags & CAN_FRAME_RTR ) != 0 ))) {
663666 /* RTR bit does not match filter RTR mask, drop frame */
664667 * fifo_ack_reg = get_idx ;
665668 continue ;
669+ } else if (fd_frame_filter != ((frame .flags & CAN_FRAME_FDF ) != 0 )) {
670+ /* FD bit does not match filter FD frame, drop frame */
671+ * fifo_ack_reg = get_idx ;
672+ continue ;
666673 }
667674
668675 data_length = can_dlc_to_bytes (frame .dlc );
@@ -949,11 +956,6 @@ int can_mcan_add_rx_filter_std(const struct device *dev,
949956 };
950957 int filter_id ;
951958
952- if ((filter -> flags & ~(CAN_FILTER_IDE | CAN_FILTER_DATA | CAN_FILTER_RTR )) != 0 ) {
953- LOG_ERR ("unsupported CAN filter flags 0x%02x" , filter -> flags );
954- return - ENOTSUP ;
955- }
956-
957959 k_mutex_lock (& data -> inst_mutex , K_FOREVER );
958960 filter_id = can_mcan_get_free_std (msg_ram -> std_filt );
959961
@@ -988,6 +990,12 @@ int can_mcan_add_rx_filter_std(const struct device *dev,
988990 data -> std_filt_rtr_mask &= ~(1U << filter_id );
989991 }
990992
993+ if ((filter -> flags & CAN_FILTER_FDF ) != 0 ) {
994+ data -> std_filt_fd_frame |= (1U << filter_id );
995+ } else {
996+ data -> std_filt_fd_frame &= ~(1U << filter_id );
997+ }
998+
991999 data -> rx_cb_std [filter_id ] = callback ;
9921000 data -> cb_arg_std [filter_id ] = user_data ;
9931001
@@ -1052,6 +1060,12 @@ static int can_mcan_add_rx_filter_ext(const struct device *dev,
10521060 data -> ext_filt_rtr_mask &= ~(1U << filter_id );
10531061 }
10541062
1063+ if ((filter -> flags & CAN_FILTER_FDF ) != 0 ) {
1064+ data -> ext_filt_fd_frame |= (1U << filter_id );
1065+ } else {
1066+ data -> ext_filt_fd_frame &= ~(1U << filter_id );
1067+ }
1068+
10551069 data -> rx_cb_ext [filter_id ] = callback ;
10561070 data -> cb_arg_ext [filter_id ] = user_data ;
10571071
@@ -1068,6 +1082,17 @@ int can_mcan_add_rx_filter(const struct device *dev,
10681082 return - EINVAL ;
10691083 }
10701084
1085+
1086+ #ifdef CONFIG_CAN_FD_MODE
1087+ if ((filter -> flags & ~(CAN_FILTER_IDE | CAN_FILTER_DATA |
1088+ CAN_FILTER_RTR | CAN_FILTER_FDF )) != 0 ) {
1089+ #else
1090+ if ((filter -> flags & ~(CAN_FILTER_IDE | CAN_FILTER_DATA | CAN_FILTER_RTR )) != 0 ) {
1091+ #endif
1092+ LOG_ERR ("unsupported CAN filter flags 0x%02x" , filter -> flags );
1093+ return - ENOTSUP ;
1094+ }
1095+
10711096 if ((filter -> flags & CAN_FILTER_IDE ) != 0 ) {
10721097 filter_id = can_mcan_add_rx_filter_ext (dev , callback , user_data , filter );
10731098 if (filter_id >= 0 ) {
0 commit comments