diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index 45d7af03e33..8712f6488b7 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -6,12 +6,12 @@ #include #include +#include #define LOG_LEVEL CONFIG_CAN_LOG_LEVEL #include LOG_MODULE_REGISTER(can_driver); -#define CAN_CLAMP(val, min, max) MIN(MAX(val, min), max) #define CAN_SYNC_SEG 1 #define WORK_BUF_COUNT_IS_POWER_OF_2 !(CONFIG_CAN_WORKQ_FRAMES_BUF_CNT & \ @@ -36,9 +36,7 @@ static void can_msgq_put(struct zcan_frame *frame, void *arg) ret = k_msgq_put(msgq, frame, K_NO_WAIT); if (ret) { - LOG_ERR("Msgq %p overflowed. Frame ID: 0x%x", arg, - frame->id_type == CAN_STANDARD_IDENTIFIER ? - frame->std_id : frame->ext_id); + LOG_ERR("Msgq %p overflowed. Frame ID: 0x%x", arg, frame->id); } } @@ -122,9 +120,7 @@ static void can_work_isr_put(struct zcan_frame *frame, void *arg) ret = can_work_buffer_put(frame, &work->buf); if (ret) { - LOG_ERR("Workq buffer overflow. Msg ID: 0x%x", - frame->id_type == CAN_STANDARD_IDENTIFIER ? - frame->std_id : frame->ext_id); + LOG_ERR("Workq buffer overflow. Msg ID: 0x%x", frame->id); return; } @@ -175,7 +171,7 @@ static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res, } } - res->prop_seg = CAN_CLAMP(ts1 / 2, min->prop_seg, max->prop_seg); + res->prop_seg = CLAMP(ts1 / 2, min->prop_seg, max->prop_seg); res->phase_seg1 = ts1 - res->prop_seg; res->phase_seg2 = ts2; diff --git a/drivers/can/can_loopback.c b/drivers/can/can_loopback.c index cb0b4ba7988..c8d0216a9a2 100644 --- a/drivers/can/can_loopback.c +++ b/drivers/can/can_loopback.c @@ -33,9 +33,7 @@ static void dispatch_frame(const struct zcan_frame *frame, struct zcan_frame frame_tmp = *frame; LOG_DBG("Receiving %d bytes. Id: 0x%x, ID type: %s %s", - frame->dlc, - frame->id_type == CAN_STANDARD_IDENTIFIER ? - frame->std_id : frame->ext_id, + frame->dlc, frame->id, frame->id_type == CAN_STANDARD_IDENTIFIER ? "standard" : "extended", frame->rtr == CAN_DATAFRAME ? "" : ", RTR frame"); @@ -46,16 +44,8 @@ static void dispatch_frame(const struct zcan_frame *frame, static inline int check_filter_match(const struct zcan_frame *frame, const struct zcan_filter *filter) { - uint32_t id, mask, frame_id; - - frame_id = frame->id_type == CAN_STANDARD_IDENTIFIER ? - frame->std_id : frame->ext_id; - id = filter->id_type == CAN_STANDARD_IDENTIFIER ? - filter->std_id : filter->ext_id; - mask = filter->id_type == CAN_STANDARD_IDENTIFIER ? - filter->std_id_mask : filter->ext_id_mask; - - return ((id & mask) == (frame_id & mask)); + return ((filter->id & filter->id_mask) == + (frame->id & filter->id_mask)); } void tx_thread(void *data_arg, void *arg2, void *arg3) @@ -99,9 +89,7 @@ int can_loopback_send(const struct device *dev, struct k_sem tx_sem; LOG_DBG("Sending %d bytes on %s. Id: 0x%x, ID type: %s %s", - frame->dlc, dev->name, - frame->id_type == CAN_STANDARD_IDENTIFIER ? - frame->std_id : frame->ext_id, + frame->dlc, dev->name, frame->id, frame->id_type == CAN_STANDARD_IDENTIFIER ? "standard" : "extended", frame->rtr == CAN_DATAFRAME ? "" : ", RTR frame"); @@ -153,14 +141,14 @@ int can_loopback_attach_isr(const struct device *dev, can_rx_callback_t isr, struct can_loopback_filter *loopback_filter; int filter_id; - LOG_DBG("Setting filter ID: 0x%x, mask: 0x%x", filter->ext_id, - filter->ext_id_mask); + LOG_DBG("Setting filter ID: 0x%x, mask: 0x%x", filter->id, + filter->id_mask); LOG_DBG("Filter type: %s ID %s mask", - filter->id_type == CAN_STANDARD_IDENTIFIER ? - "standard" : "extended", - ((filter->id_type && (filter->std_id_mask == CAN_STD_ID_MASK)) || - (!filter->id_type && (filter->ext_id_mask == CAN_EXT_ID_MASK))) ? - "with" : "without"); + filter->id_type == CAN_STANDARD_IDENTIFIER ? + "standard" : "extended", + ((filter->id_type && (filter->id_mask == CAN_STD_ID_MASK)) || + (!filter->id_type && (filter->id_mask == CAN_EXT_ID_MASK))) ? + "with" : "without"); k_mutex_lock(&data->mtx, K_FOREVER); filter_id = get_free_filter(data->filters); diff --git a/drivers/can/can_mcp2515.c b/drivers/can/can_mcp2515.c index ced73be7de6..1ee6a9cd113 100644 --- a/drivers/can/can_mcp2515.c +++ b/drivers/can/can_mcp2515.c @@ -202,16 +202,16 @@ static void mcp2515_convert_zcanframe_to_mcp2515frame(const struct zcan_frame uint8_t data_idx = 0U; if (source->id_type == CAN_STANDARD_IDENTIFIER) { - target[MCP2515_FRAME_OFFSET_SIDH] = source->std_id >> 3; + target[MCP2515_FRAME_OFFSET_SIDH] = source->id >> 3; target[MCP2515_FRAME_OFFSET_SIDL] = - (source->std_id & 0x07) << 5; + (source->id & 0x07) << 5; } else { - target[MCP2515_FRAME_OFFSET_SIDH] = source->ext_id >> 21; + target[MCP2515_FRAME_OFFSET_SIDH] = source->id >> 21; target[MCP2515_FRAME_OFFSET_SIDL] = - (((source->ext_id >> 18) & 0x07) << 5) | (BIT(3)) | - ((source->ext_id >> 16) & 0x03); - target[MCP2515_FRAME_OFFSET_EID8] = source->ext_id >> 8; - target[MCP2515_FRAME_OFFSET_EID0] = source->ext_id; + (((source->id >> 18) & 0x07) << 5) | (BIT(3)) | + ((source->id >> 16) & 0x03); + target[MCP2515_FRAME_OFFSET_EID8] = source->id >> 8; + target[MCP2515_FRAME_OFFSET_EID0] = source->id; } rtr = (source->rtr == CAN_REMOTEREQUEST) ? BIT(6) : 0; @@ -232,7 +232,7 @@ static void mcp2515_convert_mcp2515frame_to_zcanframe(const uint8_t *source, if (source[MCP2515_FRAME_OFFSET_SIDL] & BIT(3)) { target->id_type = CAN_EXTENDED_IDENTIFIER; - target->ext_id = + target->id = (source[MCP2515_FRAME_OFFSET_SIDH] << 21) | ((source[MCP2515_FRAME_OFFSET_SIDL] >> 5) << 18) | ((source[MCP2515_FRAME_OFFSET_SIDL] & 0x03) << 16) | @@ -240,7 +240,7 @@ static void mcp2515_convert_mcp2515frame_to_zcanframe(const uint8_t *source, source[MCP2515_FRAME_OFFSET_EID0]; } else { target->id_type = CAN_STANDARD_IDENTIFIER; - target->std_id = (source[MCP2515_FRAME_OFFSET_SIDH] << 3) | + target->id = (source[MCP2515_FRAME_OFFSET_SIDH] << 3) | (source[MCP2515_FRAME_OFFSET_SIDL] >> 5); } @@ -556,14 +556,8 @@ static uint8_t mcp2515_filter_match(struct zcan_frame *msg, return 0; } - if (msg->id_type == CAN_STANDARD_IDENTIFIER) { - if ((msg->std_id ^ filter->std_id) & filter->std_id_mask) { - return 0; - } - } else { - if ((msg->ext_id ^ filter->ext_id) & filter->ext_id_mask) { - return 0; - } + if ((msg->id ^ filter->id) & filter->id_mask) { + return 0; } return 1; diff --git a/drivers/can/can_mcux_flexcan.c b/drivers/can/can_mcux_flexcan.c index adea01704e2..9b0ddcf2040 100644 --- a/drivers/can/can_mcux_flexcan.c +++ b/drivers/can/can_mcux_flexcan.c @@ -177,10 +177,10 @@ static void mcux_flexcan_copy_zframe_to_frame(const struct zcan_frame *src, { if (src->id_type == CAN_STANDARD_IDENTIFIER) { dest->format = kFLEXCAN_FrameFormatStandard; - dest->id = FLEXCAN_ID_STD(src->std_id); + dest->id = FLEXCAN_ID_STD(src->id); } else { dest->format = kFLEXCAN_FrameFormatExtend; - dest->id = FLEXCAN_ID_EXT(src->ext_id); + dest->id = FLEXCAN_ID_EXT(src->id); } if (src->rtr == CAN_DATAFRAME) { @@ -199,10 +199,10 @@ static void mcux_flexcan_copy_frame_to_zframe(const flexcan_frame_t *src, { if (src->format == kFLEXCAN_FrameFormatStandard) { dest->id_type = CAN_STANDARD_IDENTIFIER; - dest->std_id = FLEXCAN_ID_TO_ZCAN_ID_STD(src->id); + dest->id = FLEXCAN_ID_TO_ZCAN_ID_STD(src->id); } else { dest->id_type = CAN_EXTENDED_IDENTIFIER; - dest->ext_id = FLEXCAN_ID_TO_ZCAN_ID_EXT(src->id); + dest->id = FLEXCAN_ID_TO_ZCAN_ID_EXT(src->id); } if (src->type == kFLEXCAN_FrameTypeData) { @@ -225,13 +225,13 @@ static void mcux_flexcan_copy_zfilter_to_mbconfig(const struct zcan_filter *src, { if (src->id_type == CAN_STANDARD_IDENTIFIER) { dest->format = kFLEXCAN_FrameFormatStandard; - dest->id = FLEXCAN_ID_STD(src->std_id); - *mask = FLEXCAN_RX_MB_STD_MASK(src->std_id_mask, + dest->id = FLEXCAN_ID_STD(src->id); + *mask = FLEXCAN_RX_MB_STD_MASK(src->id_mask, src->rtr & src->rtr_mask, 1); } else { dest->format = kFLEXCAN_FrameFormatExtend; - dest->id = FLEXCAN_ID_EXT(src->ext_id); - *mask = FLEXCAN_RX_MB_EXT_MASK(src->ext_id_mask, + dest->id = FLEXCAN_ID_EXT(src->id); + *mask = FLEXCAN_RX_MB_EXT_MASK(src->id_mask, src->rtr & src->rtr_mask, 1); } diff --git a/drivers/can/can_net.c b/drivers/can/can_net.c index 9c9c1ce72b0..b55f08189a4 100644 --- a/drivers/can/can_net.c +++ b/drivers/can/can_net.c @@ -50,16 +50,16 @@ static inline uint8_t can_get_frame_datalength(struct zcan_frame *frame) static inline uint16_t can_get_lladdr_src(struct zcan_frame *frame) { - return (frame->ext_id >> CAN_NET_IF_ADDR_SRC_POS) & + return (frame->id >> CAN_NET_IF_ADDR_SRC_POS) & CAN_NET_IF_ADDR_MASK; } static inline uint16_t can_get_lladdr_dest(struct zcan_frame *frame) { - uint16_t addr = (frame->ext_id >> CAN_NET_IF_ADDR_DEST_POS) & + uint16_t addr = (frame->id >> CAN_NET_IF_ADDR_DEST_POS) & CAN_NET_IF_ADDR_MASK; - if (frame->ext_id & CAN_NET_IF_ADDR_MCAST_MASK) { + if (frame->id & CAN_NET_IF_ADDR_MCAST_MASK) { addr |= CAN_NET_IF_IS_MCAST_BIT; } @@ -106,7 +106,7 @@ static void net_can_recv(struct zcan_frame *frame, void *arg) struct net_pkt *pkt; int ret; - NET_DBG("Frame with ID 0x%x received", frame->ext_id); + NET_DBG("Frame with ID 0x%x received", frame->id); pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_size, AF_UNSPEC, 0, K_NO_WAIT); if (!pkt) { @@ -147,14 +147,14 @@ static inline int attach_mcast_filter(struct net_can_context *ctx, .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, .rtr_mask = 1, - .ext_id_mask = CAN_NET_IF_ADDR_MCAST_MASK | + .id_mask = CAN_NET_IF_ADDR_MCAST_MASK | CAN_NET_IF_ADDR_DEST_MASK }; const uint16_t group = sys_be16_to_cpu(UNALIGNED_GET((&addr->s6_addr16[7]))); int filter_id; - filter.ext_id = CAN_NET_IF_ADDR_MCAST_MASK | + filter.id = CAN_NET_IF_ADDR_MCAST_MASK | ((group & CAN_NET_IF_ADDR_MASK) << CAN_NET_IF_ADDR_DEST_POS); @@ -242,13 +242,13 @@ static inline int can_attach_unicast_filter(struct net_can_context *ctx) .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, .rtr_mask = 1, - .ext_id_mask = CAN_NET_IF_ADDR_DEST_MASK + .id_mask = CAN_NET_IF_ADDR_DEST_MASK }; const uint8_t *link_addr = net_if_get_link_addr(ctx->iface)->addr; const uint16_t dest = sys_be16_to_cpu(UNALIGNED_GET((uint16_t *) link_addr)); int filter_id; - filter.ext_id = (dest << CAN_NET_IF_ADDR_DEST_POS); + filter.id = (dest << CAN_NET_IF_ADDR_DEST_POS); filter_id = can_attach_isr(ctx->can_dev, net_can_recv, ctx, &filter); @@ -269,8 +269,8 @@ static inline int can_attach_eth_bridge_filter(struct net_can_context *ctx) .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, .rtr_mask = 1, - .ext_id_mask = CAN_NET_IF_ADDR_DEST_MASK, - .ext_id = (NET_CAN_ETH_TRANSLATOR_ADDR << + .id_mask = CAN_NET_IF_ADDR_DEST_MASK, + .id = (NET_CAN_ETH_TRANSLATOR_ADDR << CAN_NET_IF_ADDR_DEST_POS) }; @@ -294,8 +294,8 @@ static inline int can_attach_all_mcast_filter(struct net_can_context *ctx) .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, .rtr_mask = 1, - .ext_id_mask = CAN_NET_IF_ADDR_MCAST_MASK, - .ext_id = CAN_NET_IF_ADDR_MCAST_MASK + .id_mask = CAN_NET_IF_ADDR_MCAST_MASK, + .id = CAN_NET_IF_ADDR_MCAST_MASK }; int filter_id; diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index 05f8799b9bc..3ff4ffd5940 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -190,8 +190,7 @@ static void print_frame(struct zcan_frame *frame, void *arg) const struct shell *shell = (const struct shell *)arg; shell_fprintf(shell, SHELL_NORMAL, "|0x%-8x|%s|%s|%d|", - frame->id_type == CAN_STANDARD_IDENTIFIER ? - frame->std_id : frame->ext_id, + frame->id, frame->id_type == CAN_STANDARD_IDENTIFIER ? "std" : "ext", frame->rtr ? "RTR" : " ", frame->dlc); @@ -293,7 +292,7 @@ static int cmd_send(const struct shell *shell, size_t argc, char **argv) return -EINVAL; } - frame.ext_id = id; + frame.id = id; pos = read_data(shell, pos, argv, argc, frame.data, &frame.dlc); if (pos < 0) { @@ -301,8 +300,7 @@ static int cmd_send(const struct shell *shell, size_t argc, char **argv) } shell_print(shell, "Send frame with ID 0x%x (%s id) and %d data bytes", - ext ? frame.ext_id : frame.std_id, - ext ? "extended" : "standard", frame.dlc); + frame.id, ext ? "extended" : "standard", frame.dlc); ret = can_send(can_dev, &frame, K_FOREVER, NULL, NULL); if (ret) { @@ -344,16 +342,16 @@ static int cmd_attach(const struct shell *shell, size_t argc, char **argv) return -EINVAL; } - filter.ext_id = id; + filter.id = id; if (pos != argc) { pos = read_mask(shell, pos, argv, ext, &mask); if (pos < 0) { return -EINVAL; } - filter.ext_id_mask = mask; + filter.id_mask = mask; } else { - filter.ext_id_mask = ext ? CAN_EXT_ID_MASK : CAN_STD_ID_MASK; + filter.id_mask = ext ? CAN_EXT_ID_MASK : CAN_STD_ID_MASK; } if (pos != argc) { @@ -367,9 +365,7 @@ static int cmd_attach(const struct shell *shell, size_t argc, char **argv) shell_print(shell, "Attach filter with ID 0x%x (%s id) and mask 0x%x " " RTR: %d", - ext ? filter.ext_id : filter.std_id, - ext ? "extended" : "standard", - ext ? filter.ext_id_mask : filter.std_id_mask, + filter.id, ext ? "extended" : "standard", filter.id_mask, filter.rtr_mask); ret = can_attach_workq(can_dev, &k_sys_work_q, &work, print_frame, diff --git a/drivers/can/can_stm32.c b/drivers/can/can_stm32.c index 4b31d7253e4..fa0c851fe83 100644 --- a/drivers/can/can_stm32.c +++ b/drivers/can/can_stm32.c @@ -47,10 +47,10 @@ static void can_stm32_get_msg_fifo(CAN_FIFOMailBox_TypeDef *mbox, struct zcan_frame *msg) { if (mbox->RIR & CAN_RI0R_IDE) { - msg->ext_id = mbox->RIR >> CAN_RI0R_EXID_Pos; + msg->id = mbox->RIR >> CAN_RI0R_EXID_Pos; msg->id_type = CAN_EXTENDED_IDENTIFIER; } else { - msg->std_id = mbox->RIR >> CAN_RI0R_STID_Pos; + msg->id = mbox->RIR >> CAN_RI0R_STID_Pos; msg->id_type = CAN_STANDARD_IDENTIFIER; } @@ -603,8 +603,7 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *msg, "ID type: %s, " "Remote Frame: %s" , msg->dlc, dev->name - , msg->id_type == CAN_STANDARD_IDENTIFIER ? - msg->std_id : msg->ext_id + , msg->id , msg->id_type == CAN_STANDARD_IDENTIFIER ? "standard" : "extended" , msg->rtr == CAN_DATAFRAME ? "no" : "yes"); @@ -654,9 +653,9 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *msg, mailbox->TIR &= CAN_TI0R_TXRQ; if (msg->id_type == CAN_STANDARD_IDENTIFIER) { - mailbox->TIR |= (msg->std_id << CAN_TI0R_STID_Pos); + mailbox->TIR |= (msg->id << CAN_TI0R_STID_Pos); } else { - mailbox->TIR |= (msg->ext_id << CAN_TI0R_EXID_Pos) + mailbox->TIR |= (msg->id << CAN_TI0R_EXID_Pos) | CAN_TI0R_IDE; } @@ -836,31 +835,31 @@ static inline void can_stm32_set_mode_scale(enum can_filter_type filter_type, static inline uint32_t can_generate_std_mask(const struct zcan_filter *filter) { - return (filter->std_id_mask << CAN_FIRX_STD_ID_POS) | - (filter->rtr_mask << CAN_FIRX_STD_RTR_POS) | - (1U << CAN_FIRX_STD_IDE_POS); + return (filter->id_mask << CAN_FIRX_STD_ID_POS) | + (filter->rtr_mask << CAN_FIRX_STD_RTR_POS) | + (1U << CAN_FIRX_STD_IDE_POS); } static inline uint32_t can_generate_ext_mask(const struct zcan_filter *filter) { - return (filter->ext_id_mask << CAN_FIRX_EXT_EXT_ID_POS) | - (filter->rtr_mask << CAN_FIRX_EXT_RTR_POS) | - (1U << CAN_FIRX_EXT_IDE_POS); + return (filter->id_mask << CAN_FIRX_EXT_EXT_ID_POS) | + (filter->rtr_mask << CAN_FIRX_EXT_RTR_POS) | + (1U << CAN_FIRX_EXT_IDE_POS); } static inline uint32_t can_generate_std_id(const struct zcan_filter *filter) { - return (filter->std_id << CAN_FIRX_STD_ID_POS) | + return (filter->id << CAN_FIRX_STD_ID_POS) | (filter->rtr << CAN_FIRX_STD_RTR_POS); } static inline uint32_t can_generate_ext_id(const struct zcan_filter *filter) { - return (filter->ext_id << CAN_FIRX_EXT_EXT_ID_POS) | - (filter->rtr << CAN_FIRX_EXT_RTR_POS) | - (1U << CAN_FIRX_EXT_IDE_POS); + return (filter->id << CAN_FIRX_EXT_EXT_ID_POS) | + (filter->rtr << CAN_FIRX_EXT_RTR_POS) | + (1U << CAN_FIRX_EXT_IDE_POS); } static inline int can_stm32_set_filter(const struct zcan_filter *filter, @@ -882,7 +881,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter, id = can_generate_std_id(filter); filter_type = CAN_FILTER_STANDARD; - if (filter->std_id_mask != CAN_STD_ID_MASK) { + if (filter->id_mask != CAN_STD_ID_MASK) { mask = can_generate_std_mask(filter); filter_type = CAN_FILTER_STANDARD_MASKED; } @@ -890,7 +889,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter, id = can_generate_ext_id(filter); filter_type = CAN_FILTER_EXTENDED; - if (filter->ext_id_mask != CAN_EXT_ID_MASK) { + if (filter->id_mask != CAN_EXT_ID_MASK) { mask = can_generate_ext_mask(filter); filter_type = CAN_FILTER_EXTENDED_MASKED; } @@ -898,8 +897,8 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter, register_demand = reg_demand[filter_type]; - LOG_DBG("Setting filter ID: 0x%x, mask: 0x%x", filter->ext_id, - filter->ext_id_mask); + LOG_DBG("Setting filter ID: 0x%x, mask: 0x%x", filter->id, + filter->id_mask); LOG_DBG("Filter type: %s ID %s mask (%d)", (filter_type == CAN_FILTER_STANDARD || filter_type == CAN_FILTER_STANDARD_MASKED) ? diff --git a/include/drivers/can.h b/include/drivers/can.h index b2047bff325..2863283315f 100644 --- a/include/drivers/can.h +++ b/include/drivers/can.h @@ -98,7 +98,7 @@ enum can_mode { /*Controller is in loopback mode (receive own messages)*/ CAN_LOOPBACK_MODE, /*Combination of loopback and silent*/ - CAN_SILENT_LOOPBACK_MODE, + CAN_SILENT_LOOPBACK_MODE }; /** @@ -167,34 +167,44 @@ struct can_filter { * */ struct zcan_frame { - /** Indicates the identifier type (standard or extended) - * use can_ide enum for assignment - */ - uint32_t id_type : 1; + /** Message identifier*/ + uint32_t id : 29; + /** Frame is in the CAN-FD frame format */ + uint32_t fd : 1; /** Set the message to a transmission request instead of data frame * use can_rtr enum for assignment */ uint32_t rtr : 1; - /** Message identifier*/ - union { - uint32_t std_id : 11; - uint32_t ext_id : 29; - }; + /** Indicates the identifier type (standard or extended) + * use can_ide enum for assignment + */ + uint32_t id_type : 1; /** The length of the message (max. 8) in byte */ uint8_t dlc; - /** The message data*/ - union { - uint8_t data[8]; - uint32_t data_32[2]; - }; + /** Baud Rate Switch. Frame transfer with different timing during + * the data phase. Only valid for CAN-FD + */ + uint8_t brs : 1; + /** Reserved for future flags */ + uint8_t res : 7; #if defined(CONFIG_CAN_RX_TIMESTAMP) - /** Timer value of the CAN free running timer. + /** Timer value of the CAN free-running timer. * The timer is incremented every bit time and captured at the start * of frame bit (SOF). */ uint16_t timestamp; +#else + /** @cond INTERNAL_HIDDEN */ + uint8_t res0; /* reserved / padding */ + uint8_t res1; /* reserved / padding */ + /** @endcond */ #endif -} __packed; + /** The frame payload data. */ + union { + uint8_t data[CAN_MAX_DLEN]; + uint32_t data_32[ceiling_fraction(CAN_MAX_DLEN, sizeof(uint32_t))]; + }; +}; /** * @brief CAN filter structure @@ -206,25 +216,22 @@ struct zcan_frame { * */ struct zcan_filter { + /** target state of the identifier */ + uint32_t id : 29; + uint32_t res0 : 1; + /** target state of the rtr bit */ + uint32_t rtr : 1; /** Indicates the identifier type (standard or extended) * use can_ide enum for assignment */ uint32_t id_type : 1; - /** target state of the rtr bit */ - uint32_t rtr : 1; - /** target state of the identifier */ - union { - uint32_t std_id : 11; - uint32_t ext_id : 29; - }; + /** identifier mask*/ + uint32_t id_mask : 29; + uint32_t res1 : 1; /** rtr bit mask */ uint32_t rtr_mask : 1; - /** identifier mask*/ - union { - uint32_t std_id_mask : 11; - uint32_t ext_id_mask : 29; - }; -} __packed; + uint32_t res2 : 1; +}; /** * @brief can bus error count structure @@ -445,12 +452,12 @@ static inline int can_write(const struct device *dev, const uint8_t *data, return -EINVAL; } + msg.id = id; + if (id > CAN_MAX_STD_ID) { msg.id_type = CAN_EXTENDED_IDENTIFIER; - msg.ext_id = id & CAN_EXT_ID_MASK; } else { msg.id_type = CAN_STANDARD_IDENTIFIER; - msg.std_id = id; } msg.dlc = length; @@ -691,8 +698,11 @@ static inline int z_impl_can_set_timing(const struct device *dev, } /** - * @brief Set the bitrate of the CAN-FD controller + * @brief Set the bitrate of the CAN controller * + * The second parameter bitrate_data is only relevant for CAN-FD. + * If the controller does not support CAN-FD or the FD mode is not enabled, + * this parameter is ignored. * The sample point is set to the CiA DS 301 reccommended value of 87.5% * * @param dev Pointer to the device structure for the driver instance. @@ -836,7 +846,7 @@ static inline void can_copy_frame_to_zframe(const struct can_frame *frame, { zframe->id_type = (frame->can_id & BIT(31)) >> 31; zframe->rtr = (frame->can_id & BIT(30)) >> 30; - zframe->ext_id = frame->can_id & BIT_MASK(29); + zframe->id = frame->can_id & BIT_MASK(29); zframe->dlc = frame->can_dlc; memcpy(zframe->data, frame->data, sizeof(zframe->data)); } @@ -851,8 +861,7 @@ static inline void can_copy_zframe_to_frame(const struct zcan_frame *zframe, struct can_frame *frame) { frame->can_id = (zframe->id_type << 31) | (zframe->rtr << 30) | - (zframe->id_type == CAN_STANDARD_IDENTIFIER ? zframe->std_id : - zframe->ext_id); + zframe->id; frame->can_dlc = zframe->dlc; memcpy(frame->data, zframe->data, sizeof(frame->data)); } @@ -870,9 +879,9 @@ void can_copy_filter_to_zfilter(const struct can_filter *filter, { zfilter->id_type = (filter->can_id & BIT(31)) >> 31; zfilter->rtr = (filter->can_id & BIT(30)) >> 30; - zfilter->ext_id = filter->can_id & BIT_MASK(29); + zfilter->id = filter->can_id & BIT_MASK(29); zfilter->rtr_mask = (filter->can_mask & BIT(30)) >> 30; - zfilter->ext_id_mask = filter->can_mask & BIT_MASK(29); + zfilter->id_mask = filter->can_mask & BIT_MASK(29); } /** @@ -887,9 +896,9 @@ void can_copy_zfilter_to_filter(const struct zcan_filter *zfilter, struct can_filter *filter) { filter->can_id = (zfilter->id_type << 31) | - (zfilter->rtr << 30) | zfilter->ext_id; + (zfilter->rtr << 30) | zfilter->id; filter->can_mask = (zfilter->rtr_mask << 30) | - (zfilter->id_type << 31) | zfilter->ext_id_mask; + (zfilter->id_type << 31) | zfilter->id_mask; } #ifdef __cplusplus diff --git a/samples/drivers/can/src/main.c b/samples/drivers/can/src/main.c index ebebad74b46..63aec185358 100644 --- a/samples/drivers/can/src/main.c +++ b/samples/drivers/can/src/main.c @@ -55,9 +55,9 @@ void rx_thread(void *arg1, void *arg2, void *arg3) const struct zcan_filter filter = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = COUNTER_MSG_ID, + .id = COUNTER_MSG_ID, .rtr_mask = 1, - .ext_id_mask = CAN_EXT_ID_MASK + .id_mask = CAN_EXT_ID_MASK }; struct zcan_frame msg; int filter_id; @@ -177,20 +177,20 @@ void main(void) const struct zcan_filter change_led_filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = LED_MSG_ID, + .id = LED_MSG_ID, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; struct zcan_frame change_led_frame = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = LED_MSG_ID, + .id = LED_MSG_ID, .dlc = 1 }; struct zcan_frame counter_frame = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = COUNTER_MSG_ID, + .id = COUNTER_MSG_ID, .dlc = 2 }; uint8_t toggle = 1; diff --git a/samples/net/sockets/can/src/main.c b/samples/net/sockets/can/src/main.c index 6debf86214c..fea81307eb4 100644 --- a/samples/net/sockets/can/src/main.c +++ b/samples/net/sockets/can/src/main.c @@ -32,9 +32,9 @@ static struct k_thread rx_data; static const struct zcan_filter zfilter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = 0x1, + .id = 0x1, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; static struct can_filter filter; @@ -48,7 +48,7 @@ static void tx(int *can_fd) msg.dlc = 8U; msg.id_type = CAN_STANDARD_IDENTIFIER; - msg.std_id = 0x1; + msg.id = 0x1; msg.rtr = CAN_DATAFRAME; for (i = 0; i < msg.dlc; i++) { @@ -127,7 +127,7 @@ static void rx(int *can_fd, int *do_close_period, can_copy_frame_to_zframe(&frame, &msg); LOG_INF("[%d] CAN msg: type 0x%x RTR 0x%x EID 0x%x DLC 0x%x", - fd, msg.id_type, msg.rtr, msg.std_id, msg.dlc); + fd, msg.id_type, msg.rtr, msg.id, msg.dlc); if (!msg.rtr) { if (msg.dlc > 8) { diff --git a/subsys/canbus/canopen/CO_driver.c b/subsys/canbus/canopen/CO_driver.c index 1921c9d84d3..17d67e20619 100644 --- a/subsys/canbus/canopen/CO_driver.c +++ b/subsys/canbus/canopen/CO_driver.c @@ -88,7 +88,7 @@ static void canopen_rx_isr_callback(struct zcan_frame *msg, void *arg) return; } - rxMsg.ident = msg->std_id; + rxMsg.ident = msg->id; rxMsg.DLC = msg->dlc; memcpy(rxMsg.data, msg->data, msg->dlc); buffer->pFunct(buffer->object, &rxMsg); @@ -126,7 +126,7 @@ static void canopen_tx_retry(struct k_work *item) buffer = &CANmodule->tx_array[i]; if (buffer->bufferFull) { msg.id_type = CAN_STANDARD_IDENTIFIER; - msg.std_id = buffer->ident; + msg.id = buffer->ident; msg.dlc = buffer->DLC; msg.rtr = (buffer->rtr ? 1 : 0); memcpy(msg.data, buffer->data, buffer->DLC); @@ -274,8 +274,8 @@ CO_ReturnError_t CO_CANrxBufferInit(CO_CANmodule_t *CANmodule, uint16_t index, buffer->pFunct = pFunct; filter.id_type = CAN_STANDARD_IDENTIFIER; - filter.std_id = ident; - filter.std_id_mask = mask; + filter.id = ident; + filter.id_mask = mask; filter.rtr = (rtr ? 1 : 0); filter.rtr_mask = 1; @@ -345,7 +345,7 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer) } msg.id_type = CAN_STANDARD_IDENTIFIER; - msg.std_id = buffer->ident; + msg.id = buffer->ident; msg.dlc = buffer->DLC; msg.rtr = (buffer->rtr ? 1 : 0); memcpy(msg.data, buffer->data, buffer->DLC); diff --git a/subsys/canbus/isotp/isotp.c b/subsys/canbus/isotp/isotp.c index 7515067714d..05f4e084bff 100644 --- a/subsys/canbus/isotp/isotp.c +++ b/subsys/canbus/isotp/isotp.c @@ -133,7 +133,7 @@ static void receive_send_fc(struct isotp_recv_ctx *ctx, uint8_t fs) struct zcan_frame frame = { .id_type = ctx->tx_addr.id_type, .rtr = CAN_DATAFRAME, - .ext_id = ctx->tx_addr.ext_id + .id = ctx->tx_addr.ext_id }; uint8_t *data = frame.data; int ret; @@ -532,9 +532,9 @@ static inline int attach_ff_filter(struct isotp_recv_ctx *ctx) struct zcan_filter filter = { .id_type = ctx->rx_addr.id_type, .rtr = CAN_DATAFRAME, - .ext_id = ctx->rx_addr.ext_id, + .id = ctx->rx_addr.ext_id, .rtr_mask = 1, - .ext_id_mask = CAN_EXT_ID_MASK + .id_mask = CAN_EXT_ID_MASK }; ctx->filter_id = can_attach_isr(ctx->can_dev, receive_can_rx_isr, ctx, @@ -834,7 +834,7 @@ static inline int send_sf(struct isotp_send_ctx *ctx) struct zcan_frame frame = { .id_type = ctx->tx_addr.id_type, .rtr = CAN_DATAFRAME, - .ext_id = ctx->tx_addr.ext_id + .id = ctx->tx_addr.ext_id }; size_t len = get_ctx_data_length(ctx); int index = 0; @@ -866,7 +866,7 @@ static inline int send_ff(struct isotp_send_ctx *ctx) struct zcan_frame frame = { .id_type = ctx->tx_addr.id_type, .rtr = CAN_DATAFRAME, - .ext_id = ctx->tx_addr.ext_id, + .id = ctx->tx_addr.ext_id, .dlc = ISOTP_CAN_DL }; int index = 0; @@ -908,7 +908,7 @@ static inline int send_cf(struct isotp_send_ctx *ctx) struct zcan_frame frame = { .id_type = ctx->tx_addr.id_type, .rtr = CAN_DATAFRAME, - .ext_id = ctx->tx_addr.ext_id, + .id = ctx->tx_addr.ext_id, }; int index = 0; int ret; @@ -1081,9 +1081,9 @@ static inline int attach_fc_filter(struct isotp_send_ctx *ctx) struct zcan_filter filter = { .id_type = ctx->rx_addr.id_type, .rtr = CAN_DATAFRAME, - .ext_id = ctx->rx_addr.ext_id, + .id = ctx->rx_addr.ext_id, .rtr_mask = 1, - .ext_id_mask = CAN_EXT_ID_MASK + .id_mask = CAN_EXT_ID_MASK }; ctx->filter_id = can_attach_isr(ctx->can_dev, send_can_rx_isr, ctx, diff --git a/subsys/net/l2/canbus/6locan.c b/subsys/net/l2/canbus/6locan.c index 07cebd67125..dc02503bbe6 100644 --- a/subsys/net/l2/canbus/6locan.c +++ b/subsys/net/l2/canbus/6locan.c @@ -395,10 +395,10 @@ static void canbus_set_frame_addr(struct zcan_frame *frame, frame->id_type = CAN_EXTENDED_IDENTIFIER; frame->rtr = CAN_DATAFRAME; - frame->ext_id = canbus_addr_to_id(dest->addr, src->addr); + frame->id = canbus_addr_to_id(dest->addr, src->addr); if (mcast) { - frame->ext_id |= CAN_NET_IF_ADDR_MCAST_MASK; + frame->id |= CAN_NET_IF_ADDR_MCAST_MASK; } } @@ -447,7 +447,7 @@ static int canbus_send_fc(const struct device *net_can_dev, frame.data[2] = NET_CAN_STMIN; canbus_set_frame_datalength(&frame, 3); - NET_DBG("Sending FC to ID: 0x%08x", frame.ext_id); + NET_DBG("Sending FC to ID: 0x%08x", frame.id); return api->send(net_can_dev, &frame, canbus_fc_send_cb, NULL, K_FOREVER); } @@ -885,11 +885,11 @@ static inline int canbus_send_ff(struct net_pkt *pkt, size_t len, bool mcast, if (mcast) { NET_DBG("Sending FF (multicast). ID: 0x%08x. PKT len: %zu" " CTX: %p", - frame.ext_id, len, pkt->canbus_tx_ctx); + frame.id, len, pkt->canbus_tx_ctx); } else { NET_DBG("Sending FF (unicast). ID: 0x%08x. PKT len: %zu" " CTX: %p", - frame.ext_id, len, pkt->canbus_tx_ctx); + frame.id, len, pkt->canbus_tx_ctx); } #if defined(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR) @@ -1506,7 +1506,7 @@ static inline int canbus_send_dad_request(const struct device *net_can_dev, canbus_set_frame_datalength(&frame, 0); frame.rtr = CAN_REMOTEREQUEST; frame.id_type = CAN_EXTENDED_IDENTIFIER; - frame.ext_id = canbus_addr_to_id(ll_addr->addr, + frame.id = canbus_addr_to_id(ll_addr->addr, sys_rand32_get() & CAN_NET_IF_ADDR_MASK); ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER); @@ -1550,7 +1550,7 @@ static inline void canbus_send_dad_response(struct k_work *item) canbus_set_frame_datalength(&frame, 0); frame.rtr = CAN_DATAFRAME; frame.id_type = CAN_EXTENDED_IDENTIFIER; - frame.ext_id = canbus_addr_to_id(NET_CAN_DAD_ADDR, + frame.id = canbus_addr_to_id(NET_CAN_DAD_ADDR, ntohs(UNALIGNED_GET((uint16_t *) ll_addr->addr))); ret = api->send(net_can_dev, &frame, canbus_send_dad_resp_cb, item, @@ -1587,11 +1587,11 @@ int canbus_attach_dad_resp_filter(const struct device *net_can_dev, .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, .rtr_mask = 1, - .ext_id_mask = CAN_EXT_ID_MASK + .id_mask = CAN_EXT_ID_MASK }; int filter_id; - filter.ext_id = canbus_addr_to_id(NET_CAN_DAD_ADDR, ll_addr->addr); + filter.id = canbus_addr_to_id(NET_CAN_DAD_ADDR, ll_addr->addr); filter_id = api->attach_filter(net_can_dev, canbus_dad_resp_cb, dad_sem, &filter); @@ -1618,11 +1618,11 @@ static inline int canbus_attach_dad_filter(const struct device *net_can_dev, .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_REMOTEREQUEST, .rtr_mask = 1, - .ext_id_mask = (CAN_NET_IF_ADDR_MASK << CAN_NET_IF_ADDR_DEST_POS) + .id_mask = (CAN_NET_IF_ADDR_MASK << CAN_NET_IF_ADDR_DEST_POS) }; int filter_id; - filter.ext_id = canbus_addr_to_id(ll_addr->addr, 0); + filter.id = canbus_addr_to_id(ll_addr->addr, 0); filter_id = api->attach_filter(net_can_dev, canbus_dad_request_cb, dad_work, &filter); diff --git a/tests/drivers/can/api/src/main.c b/tests/drivers/can/api/src/main.c index ba085c7a649..b198ded34f4 100644 --- a/tests/drivers/can/api/src/main.c +++ b/tests/drivers/can/api/src/main.c @@ -56,7 +56,7 @@ const struct device *can_dev; struct zcan_frame test_std_msg = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_STD_ID, + .id = TEST_CAN_STD_ID, .dlc = 8, .data = {1, 2, 3, 4, 5, 6, 7, 8} }; @@ -64,7 +64,7 @@ struct zcan_frame test_std_msg = { struct zcan_frame test_std_mask_msg = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_STD_MASK_ID, + .id = TEST_CAN_STD_MASK_ID, .dlc = 8, .data = {1, 2, 3, 4, 5, 6, 7, 8} }; @@ -72,7 +72,7 @@ struct zcan_frame test_std_mask_msg = { struct zcan_frame test_ext_msg = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = TEST_CAN_EXT_ID, + .id = TEST_CAN_EXT_ID, .dlc = 8, .data = {1, 2, 3, 4, 5, 6, 7, 8} }; @@ -80,7 +80,7 @@ struct zcan_frame test_ext_msg = { struct zcan_frame test_ext_mask_msg = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = TEST_CAN_EXT_MASK_ID, + .id = TEST_CAN_EXT_MASK_ID, .dlc = 8, .data = {1, 2, 3, 4, 5, 6, 7, 8} }; @@ -88,41 +88,41 @@ struct zcan_frame test_ext_mask_msg = { const struct zcan_filter test_std_filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_STD_ID, + .id = TEST_CAN_STD_ID, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; const struct zcan_filter test_std_masked_filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_STD_ID, + .id = TEST_CAN_STD_ID, .rtr_mask = 1, - .std_id_mask = TEST_CAN_STD_MASK + .id_mask = TEST_CAN_STD_MASK }; const struct zcan_filter test_ext_filter = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = TEST_CAN_EXT_ID, + .id = TEST_CAN_EXT_ID, .rtr_mask = 1, - .ext_id_mask = CAN_EXT_ID_MASK + .id_mask = CAN_EXT_ID_MASK }; const struct zcan_filter test_ext_masked_filter = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = TEST_CAN_EXT_ID, + .id = TEST_CAN_EXT_ID, .rtr_mask = 1, - .ext_id_mask = TEST_CAN_EXT_MASK + .id_mask = TEST_CAN_EXT_MASK }; const struct zcan_filter test_std_some_filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_SOME_STD_ID, + .id = TEST_CAN_SOME_STD_ID, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; struct zcan_work can_work; @@ -138,13 +138,8 @@ static inline void check_msg(struct zcan_frame *msg1, struct zcan_frame *msg2, zassert_equal(msg1->rtr, msg2->rtr, "RTR bit does not match"); - if (msg2->id_type == CAN_STANDARD_IDENTIFIER) { - zassert_equal(msg1->std_id | mask, msg2->std_id | mask, - "ID does not match"); - } else { - zassert_equal(msg1->ext_id | mask, msg2->ext_id | mask, - "ID does not match"); - } + zassert_equal(msg1->id | mask, msg2->id | mask, + "ID does not match"); zassert_equal(msg1->dlc, msg2->dlc, "DLC does not match"); @@ -159,7 +154,7 @@ static void tx_std_isr(uint32_t error_flags, void *arg) k_sem_give(&tx_cb_sem); - zassert_equal(msg->std_id, TEST_CAN_STD_ID, "Arg does not match"); + zassert_equal(msg->id, TEST_CAN_STD_ID, "Arg does not match"); } static void tx_std_masked_isr(uint32_t error_flags, void *arg) @@ -168,7 +163,7 @@ static void tx_std_masked_isr(uint32_t error_flags, void *arg) k_sem_give(&tx_cb_sem); - zassert_equal(msg->std_id, TEST_CAN_STD_MASK_ID, "Arg does not match"); + zassert_equal(msg->id, TEST_CAN_STD_MASK_ID, "Arg does not match"); } static void tx_ext_isr(uint32_t error_flags, void *arg) @@ -177,7 +172,7 @@ static void tx_ext_isr(uint32_t error_flags, void *arg) k_sem_give(&tx_cb_sem); - zassert_equal(msg->ext_id, TEST_CAN_EXT_ID, "Arg does not match"); + zassert_equal(msg->id, TEST_CAN_EXT_ID, "Arg does not match"); } static void tx_ext_masked_isr(uint32_t error_flags, void *arg) @@ -186,7 +181,7 @@ static void tx_ext_masked_isr(uint32_t error_flags, void *arg) k_sem_give(&tx_cb_sem); - zassert_equal(msg->ext_id, TEST_CAN_EXT_MASK_ID, "Arg does not match"); + zassert_equal(msg->id, TEST_CAN_EXT_MASK_ID, "Arg does not match"); } static void rx_std_isr(struct zcan_frame *msg, void *arg) @@ -262,7 +257,7 @@ static void send_test_msg_nowait(const struct device *can_dev, int ret; if (msg->id_type == CAN_STANDARD_IDENTIFIER) { - if (msg->std_id == TEST_CAN_STD_ID) { + if (msg->id == TEST_CAN_STD_ID) { ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, tx_std_isr, msg); } else { @@ -270,7 +265,7 @@ static void send_test_msg_nowait(const struct device *can_dev, tx_std_masked_isr, msg); } } else { - if (msg->ext_id == TEST_CAN_EXT_ID) { + if (msg->id == TEST_CAN_EXT_ID) { ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, tx_ext_isr, msg); } else { @@ -303,7 +298,7 @@ static inline int attach_workq(const struct device *can_dev, int filter_id; if (filter->id_type == CAN_STANDARD_IDENTIFIER) { - if (filter->std_id_mask == CAN_STD_ID_MASK) { + if (filter->id_mask == CAN_STD_ID_MASK) { filter_id = can_attach_workq(can_dev, &k_sys_work_q, &can_work, rx_std_cb, (void *)filter, filter); @@ -313,7 +308,7 @@ static inline int attach_workq(const struct device *can_dev, (void *)filter, filter); } } else { - if (filter->ext_id_mask == CAN_EXT_ID_MASK) { + if (filter->id_mask == CAN_EXT_ID_MASK) { filter_id = can_attach_workq(can_dev, &k_sys_work_q, &can_work, rx_ext_cb, (void *)filter, filter); @@ -339,7 +334,7 @@ static inline int attach_isr(const struct device *can_dev, k_sem_reset(&rx_isr_sem); if (filter->id_type == CAN_STANDARD_IDENTIFIER) { - if (filter->std_id_mask == CAN_STD_ID_MASK) { + if (filter->id_mask == CAN_STD_ID_MASK) { filter_id = can_attach_isr(can_dev, rx_std_isr, (void *)filter, filter); } else { @@ -347,7 +342,7 @@ static inline int attach_isr(const struct device *can_dev, (void *)filter, filter); } } else { - if (filter->ext_id_mask == CAN_EXT_ID_MASK) { + if (filter->id_mask == CAN_EXT_ID_MASK) { filter_id = can_attach_isr(can_dev, rx_ext_isr, (void *)filter, filter); } else { @@ -377,11 +372,11 @@ static void send_receive(const struct zcan_filter *filter, struct zcan_frame *ms zassert_equal(ret, 0, "Receiving timeout"); if (filter->id_type == CAN_STANDARD_IDENTIFIER) { - if (filter->std_id_mask != CAN_STD_ID_MASK) { + if (filter->id_mask != CAN_STD_ID_MASK) { mask = 0x0F; } } else { - if (filter->ext_id_mask != CAN_EXT_ID_MASK) { + if (filter->id_mask != CAN_EXT_ID_MASK) { mask = 0x0F; } } diff --git a/tests/drivers/can/stm32/src/main.c b/tests/drivers/can/stm32/src/main.c index a385d66099b..e7d2f2e9330 100644 --- a/tests/drivers/can/stm32/src/main.c +++ b/tests/drivers/can/stm32/src/main.c @@ -47,7 +47,7 @@ CAN_DEFINE_MSGQ(can_msgq, 5); struct zcan_frame test_std_msg = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_STD_ID, + .id = TEST_CAN_STD_ID, .dlc = 8, .data = {1, 2, 3, 4, 5, 6, 7, 8} }; @@ -55,33 +55,33 @@ struct zcan_frame test_std_msg = { const struct zcan_filter test_std_filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_STD_ID, + .id = TEST_CAN_STD_ID, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; const struct zcan_filter test_ext_filter = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = TEST_CAN_EXT_ID, + .id = TEST_CAN_EXT_ID, .rtr_mask = 1, - .ext_id_mask = CAN_EXT_ID_MASK + .id_mask = CAN_EXT_ID_MASK }; const struct zcan_filter test_ext_masked_filter = { .id_type = CAN_EXTENDED_IDENTIFIER, .rtr = CAN_DATAFRAME, - .ext_id = TEST_CAN_EXT_ID, + .id = TEST_CAN_EXT_ID, .rtr_mask = 1, - .ext_id_mask = TEST_CAN_EXT_MASK + .id_mask = TEST_CAN_EXT_MASK }; const struct zcan_filter test_std_some_filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = TEST_CAN_SOME_STD_ID, + .id = TEST_CAN_SOME_STD_ID, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; static inline void check_msg(struct zcan_frame *msg1, struct zcan_frame *msg2) @@ -94,13 +94,7 @@ static inline void check_msg(struct zcan_frame *msg1, struct zcan_frame *msg2) zassert_equal(msg1->rtr, msg2->rtr, "RTR bit does not match"); - if (msg2->id_type == CAN_STANDARD_IDENTIFIER) { - zassert_equal(msg1->std_id, msg2->std_id, - "ID does not match"); - } else { - zassert_equal(msg1->ext_id, msg2->ext_id, - "ID does not match"); - } + zassert_equal(msg1->id, msg2->id, "ID does not match"); zassert_equal(msg1->dlc, msg2->dlc, "DLC does not match"); diff --git a/tests/subsys/canbus/frame/src/main.c b/tests/subsys/canbus/frame/src/main.c index b525e6f178a..b015fd27413 100644 --- a/tests/subsys/canbus/frame/src/main.c +++ b/tests/subsys/canbus/frame/src/main.c @@ -30,7 +30,7 @@ static void test_can_frame_to_zcan_frame(void) expected.rtr = 1U; expected.id_type = 1U; - expected.std_id = 1234U; + expected.id = 1234U; expected.dlc = sizeof(data); can_copy_frame_to_zframe(&frame, &msg); @@ -41,7 +41,7 @@ static void test_can_frame_to_zcan_frame(void) zassert_equal(msg.rtr, expected.rtr, "RTR bit not set"); zassert_equal(msg.id_type, expected.id_type, "Id-type bit not set"); - zassert_equal(msg.std_id, expected.std_id, "Std CAN id invalid"); + zassert_equal(msg.id, expected.id, "Std CAN id invalid"); zassert_equal(msg.dlc, expected.dlc, "Msg length invalid"); } @@ -59,7 +59,7 @@ static void test_zcan_frame_to_can_frame(void) msg.rtr = 1U; msg.id_type = 1U; - msg.std_id = 1234U; + msg.id = 1234U; msg.dlc = sizeof(data); memcpy(msg.data, data, sizeof(data)); @@ -90,7 +90,7 @@ static void test_invalid_zcan_frame_to_can_frame(void) memcpy(expected.data, data, sizeof(expected.data)); msg.id_type = CAN_STANDARD_IDENTIFIER; - msg.ext_id = 0x12345678U; + msg.id = 0x12345678U; msg.dlc = sizeof(data); memcpy(msg.data, data, sizeof(data)); @@ -120,9 +120,9 @@ static void test_can_filter_to_zcan_filter(void) expected.rtr = 1U; expected.id_type = 1U; - expected.std_id = 1234U; + expected.id = 1234U; expected.rtr_mask = 1U; - expected.std_id_mask = 1234U; + expected.id_mask = 1234U; can_copy_filter_to_zfilter(&filter, &msg_filter); @@ -134,11 +134,11 @@ static void test_can_filter_to_zcan_filter(void) zassert_equal(msg_filter.rtr, expected.rtr, "RTR bit not set"); zassert_equal(msg_filter.id_type, expected.id_type, "Id-type bit not set"); - zassert_equal(msg_filter.std_id, expected.std_id, + zassert_equal(msg_filter.id, expected.id, "Std CAN id invalid"); zassert_equal(msg_filter.rtr_mask, expected.rtr_mask, "RTR mask bit not set"); - zassert_equal(msg_filter.std_id_mask, expected.std_id_mask, + zassert_equal(msg_filter.id_mask, expected.id_mask, "Std id mask not set"); } @@ -153,9 +153,9 @@ static void test_zcan_filter_to_can_filter(void) msg_filter.rtr = 1U; msg_filter.id_type = 1U; - msg_filter.std_id = 1234U; + msg_filter.id = 1234U; msg_filter.rtr_mask = 1U; - msg_filter.std_id_mask = 1234U; + msg_filter.id_mask = 1234U; can_copy_zfilter_to_filter(&msg_filter, &filter); diff --git a/tests/subsys/canbus/isotp/conformance/src/main.c b/tests/subsys/canbus/isotp/conformance/src/main.c index 1e695291bb3..09cdab5e8f1 100644 --- a/tests/subsys/canbus/isotp/conformance/src/main.c +++ b/tests/subsys/canbus/isotp/conformance/src/main.c @@ -221,7 +221,7 @@ static void send_frame_series(struct frame_desired *frames, size_t length, struct zcan_frame frame = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = id + .id = id }; struct frame_desired *desired = frames; @@ -263,9 +263,9 @@ static int attach_msgq(uint32_t id) struct zcan_filter filter = { .id_type = CAN_STANDARD_IDENTIFIER, .rtr = CAN_DATAFRAME, - .std_id = id, + .id = id, .rtr_mask = 1, - .std_id_mask = CAN_STD_ID_MASK + .id_mask = CAN_STD_ID_MASK }; filter_id = can_attach_msgq(can_dev, &frame_msgq, &filter);