can: Rename can_msg and can_msg_filter structs

In order to follow the naming from Linux, change the name of
can_msg to zcan_frame, and can_msg_filter to zcan_filter.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2019-02-21 13:23:44 +02:00 committed by Anas Nashif
parent 14d4023338
commit c478b5bb6e
7 changed files with 97 additions and 95 deletions

View file

@ -61,7 +61,7 @@ static inline int socket_can_send(struct device *dev, struct net_pkt *pkt)
}
ret = can_send(socket_context->can_dev,
(struct can_msg *)pkt->frags->data,
(struct zcan_frame *)pkt->frags->data,
SEND_TIMEOUT, tx_irq_callback);
if (ret) {
LOG_DBG("Cannot send socket CAN msg (%d)", ret);
@ -112,7 +112,7 @@ static inline void rx_thread(void *ctx, void *unused1, void *unused2)
{
struct socket_can_context *socket_context = ctx;
struct net_pkt *pkt;
struct can_msg msg;
struct zcan_frame msg;
int ret;
ARG_UNUSED(unused1);

View file

@ -37,7 +37,7 @@ static void can_stm32_signal_tx_complete(struct can_mailbox *mb)
}
static void can_stm32_get_msg_fifo(CAN_FIFOMailBox_TypeDef *mbox,
struct can_msg *msg)
struct zcan_frame *msg)
{
if (mbox->RIR & CAN_RI0R_IDE) {
msg->ext_id = mbox->RIR >> CAN_RI0R_EXID_Pos;
@ -58,7 +58,7 @@ void can_stm32_rx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
{
CAN_FIFOMailBox_TypeDef *mbox;
int filter_match_index;
struct can_msg msg;
struct zcan_frame msg;
while (can->RF0R & CAN_RF0R_FMP0) {
mbox = &can->sFIFOMailBox[0];
@ -319,7 +319,7 @@ static int can_stm32_init(struct device *dev)
return 0;
}
int can_stm32_send(struct device *dev, struct can_msg *msg, s32_t timeout,
int can_stm32_send(struct device *dev, struct zcan_frame *msg, s32_t timeout,
can_tx_callback_t callback)
{
const struct can_stm32_config *cfg = DEV_CFG(dev);
@ -578,21 +578,21 @@ static inline void can_stm32_set_mode_scale(enum can_filter_type filter_type,
*scale_reg |= scale_reg_bit;
}
static inline u32_t can_generate_std_mask(const struct can_msg_filter *filter)
static inline u32_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);
}
static inline u32_t can_generate_ext_mask(const struct can_msg_filter *filter)
static inline u32_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);
}
static inline u32_t can_generate_std_id(const struct can_msg_filter *filter)
static inline u32_t can_generate_std_id(const struct zcan_filter *filter)
{
return (filter->std_id << CAN_FIRX_STD_ID_POS) |
@ -600,14 +600,14 @@ static inline u32_t can_generate_std_id(const struct can_msg_filter *filter)
}
static inline u32_t can_generate_ext_id(const struct can_msg_filter *filter)
static inline u32_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);
}
static inline int can_stm32_set_filter(const struct can_msg_filter *filter,
static inline int can_stm32_set_filter(const struct zcan_filter *filter,
struct can_stm32_data *device_data,
CAN_TypeDef *can,
int *filter_index)
@ -739,7 +739,7 @@ done:
static inline int can_stm32_attach(struct device *dev, void *response_ptr,
const struct can_msg_filter *filter,
const struct zcan_filter *filter,
int *filter_index)
{
const struct can_stm32_config *cfg = DEV_CFG(dev);
@ -758,7 +758,7 @@ static inline int can_stm32_attach(struct device *dev, void *response_ptr,
}
int can_stm32_attach_msgq(struct device *dev, struct k_msgq *msgq,
const struct can_msg_filter *filter)
const struct zcan_filter *filter)
{
int filter_nr;
int filter_index;
@ -772,7 +772,7 @@ int can_stm32_attach_msgq(struct device *dev, struct k_msgq *msgq,
}
int can_stm32_attach_isr(struct device *dev, can_rx_callback_t isr,
const struct can_msg_filter *filter)
const struct zcan_filter *filter)
{
struct can_stm32_data *data = DEV_DATA(dev);
int filter_nr;

View file

@ -61,7 +61,8 @@ extern "C" {
* @param name Name of the message queue.
* @param size Number of can messages.
*/
#define CAN_DEFINE_MSGQ(name, size) K_MSGQ_DEFINE(name, sizeof(struct can_msg), size, 4)
#define CAN_DEFINE_MSGQ(name, size) \
K_MSGQ_DEFINE(name, sizeof(struct zcan_frame), size, 4)
/**
* @brief can_ide enum
@ -145,7 +146,7 @@ struct can_filter {
* from driver to userspace
*
*/
struct can_msg {
struct zcan_frame {
/** Indicates the identifier type (standard or extended)
* use can_ide enum for assignment
*/
@ -177,7 +178,7 @@ struct can_msg {
* field don't care for the filter matching.
*
*/
struct can_msg_filter {
struct zcan_filter {
/** Indicates the identifier type (standard or extended)
* use can_ide enum for assignment
*/
@ -213,7 +214,7 @@ typedef void (*can_tx_callback_t)(u32_t error_flags);
*
* @param received message
*/
typedef void (*can_rx_callback_t)(struct can_msg *msg);
typedef void (*can_rx_callback_t)(struct zcan_frame *msg);
/**
* @brief Configure operation of a host controller.
@ -244,7 +245,7 @@ typedef int (*can_configure_t)(struct device *dev, enum can_mode mode,
* @retval 0 If successful.
* @retval CAN_TX_* on failure.
*/
typedef int (*can_send_t)(struct device *dev, struct can_msg *msg,
typedef int (*can_send_t)(struct device *dev, struct zcan_frame *msg,
s32_t timeout, can_tx_callback_t callback_isr);
@ -260,14 +261,14 @@ typedef int (*can_send_t)(struct device *dev, struct can_msg *msg,
* *
* @param dev Pointer to the device structure for the driver instance.
* @param msgq Pointer to the already initialized message queue.
* @param filter Pointer to a can_msg_filter structure defining the id
* @param filter Pointer to a zcan_filter structure defining the id
* filtering.
*
* @retval filter id on success.
* @retval CAN_NO_FREE_FILTER if there is no filter left.
*/
typedef int (*can_attach_msgq_t)(struct device *dev, struct k_msgq *msg_q,
const struct can_msg_filter *filter);
const struct zcan_filter *filter);
/**
* @brief Attach an isr callback function to a single or group of identifiers.
@ -281,14 +282,14 @@ typedef int (*can_attach_msgq_t)(struct device *dev, struct k_msgq *msg_q,
* *
* @param dev Pointer to the device structure for the driver instance.
* @param isr Callback function pointer.
* @param filter Pointer to a can_msg_filter structure defining the id
* @param filter Pointer to a zcan_filter structure defining the id
* filtering.
*
* @retval filter id on success.
* @retval CAN_NO_FREE_FILTER if there is no filter left.
*/
typedef int (*can_attach_isr_t)(struct device *dev, can_rx_callback_t isr,
const struct can_msg_filter *filter);
const struct zcan_filter *filter);
/**
* @brief Detach an isr or message queue from the identifier filtering.
@ -312,10 +313,10 @@ struct can_driver_api {
};
__syscall int can_send(struct device *dev, struct can_msg *msg,
__syscall int can_send(struct device *dev, struct zcan_frame *msg,
s32_t timeout, can_tx_callback_t callback_isr);
static inline int _impl_can_send(struct device *dev, struct can_msg *msg,
static inline int _impl_can_send(struct device *dev, struct zcan_frame *msg,
s32_t timeout, can_tx_callback_t callback_isr)
{
const struct can_driver_api *api = dev->driver_api;
@ -346,7 +347,7 @@ static inline int _impl_can_send(struct device *dev, struct can_msg *msg,
static inline int can_write(struct device *dev, u8_t *data, u8_t length,
u32_t id, enum can_rtr rtr, s32_t timeout)
{
struct can_msg msg;
struct zcan_frame msg;
if (length > 8) {
return -EINVAL;
@ -369,11 +370,11 @@ static inline int can_write(struct device *dev, u8_t *data, u8_t length,
__syscall int can_attach_msgq(struct device *dev, struct k_msgq *msg_q,
const struct can_msg_filter *filter);
const struct zcan_filter *filter);
static inline int _impl_can_attach_msgq(struct device *dev,
struct k_msgq *msg_q,
const struct can_msg_filter *filter)
const struct zcan_filter *filter)
{
const struct can_driver_api *api = dev->driver_api;
@ -382,10 +383,10 @@ static inline int _impl_can_attach_msgq(struct device *dev,
__syscall int can_attach_isr(struct device *dev, can_rx_callback_t isr,
const struct can_msg_filter *filter);
const struct zcan_filter *filter);
static inline int _impl_can_attach_isr(struct device *dev,
can_rx_callback_t isr,
const struct can_msg_filter *filter)
const struct zcan_filter *filter)
{
const struct can_driver_api *api = dev->driver_api;
@ -415,68 +416,69 @@ static inline int _impl_can_configure(struct device *dev, enum can_mode mode,
}
/**
* @brief Converter that translates betwen can_frame and can_msg structs.
* @brief Converter that translates betwen can_frame and zcan_frame structs.
*
* @param frame Pointer to can_frame struct.
* @param msg Pointer to can_msg struct.
* @param zframe Pointer to zcan_frame struct.
*/
static inline void can_copy_frame_to_msg(struct can_frame *frame,
struct can_msg *msg)
static inline void can_copy_frame_to_zframe(struct can_frame *frame,
struct zcan_frame *zframe)
{
msg->id_type = (frame->can_id & BIT(31)) >> 31;
msg->rtr = (frame->can_id & BIT(30)) >> 30;
msg->ext_id = frame->can_id & BIT_MASK(29);
msg->dlc = frame->can_dlc;
memcpy(msg->data, frame->data, sizeof(msg->data));
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->dlc = frame->can_dlc;
memcpy(zframe->data, frame->data, sizeof(zframe->data));
}
/**
* @brief Converter that translates betwen can_msg and can_frame structs.
* @brief Converter that translates betwen zcan_frame and can_frame structs.
*
* @param msg Pointer to can_msg struct.
* @param zframe Pointer to zcan_frame struct.
* @param frame Pointer to can_frame struct.
*/
static inline void can_copy_msg_to_frame(struct can_msg *msg,
struct can_frame *frame)
static inline void can_copy_zframe_to_frame(struct zcan_frame *zframe,
struct can_frame *frame)
{
frame->can_id = (msg->id_type << 31) | (msg->rtr << 30) | msg->ext_id;
frame->can_dlc = msg->dlc;
memcpy(frame->data, msg->data, sizeof(frame->data));
frame->can_id = (zframe->id_type << 31) | (zframe->rtr << 30) |
zframe->ext_id;
frame->can_dlc = zframe->dlc;
memcpy(frame->data, zframe->data, sizeof(frame->data));
}
/**
* @brief Converter that translates betwen can_filter and can_msg_filter
* @brief Converter that translates betwen can_filter and zcan_frame_filter
* structs.
*
* @param filter Pointer to can_filter struct.
* @param msg_filter Pointer to can_msg_filter struct.
* @param zfilter Pointer to zcan_frame_filter struct.
*/
static inline
void can_copy_filter_to_msg_filter(struct can_filter *filter,
struct can_msg_filter *msg_filter)
void can_copy_filter_to_zfilter(struct can_filter *filter,
struct zcan_filter *zfilter)
{
msg_filter->id_type = (filter->can_id & BIT(31)) >> 31;
msg_filter->rtr = (filter->can_id & BIT(30)) >> 30;
msg_filter->ext_id = filter->can_id & BIT_MASK(29);
msg_filter->rtr_mask = (filter->can_mask & BIT(30)) >> 30;
msg_filter->ext_id_mask = filter->can_mask & BIT_MASK(29);
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->rtr_mask = (filter->can_mask & BIT(30)) >> 30;
zfilter->ext_id_mask = filter->can_mask & BIT_MASK(29);
}
/**
* @brief Converter that translates betwen can_msg_filter and can_filter
* @brief Converter that translates betwen zcan_filter and can_filter
* structs.
*
* @param msg_filter Pointer to can_msg_filter struct.
* @param zfilter Pointer to zcan_filter struct.
* @param filter Pointer to can_filter struct.
*/
static inline
void can_copy_msg_filter_to_filter(struct can_msg_filter *msg_filter,
struct can_filter *filter)
void can_copy_zfilter_to_filter(struct zcan_filter *zfilter,
struct can_filter *filter)
{
filter->can_id = (msg_filter->id_type << 31) |
(msg_filter->rtr << 30) | msg_filter->ext_id;
filter->can_mask = (msg_filter->rtr_mask << 30) |
(msg_filter->id_type << 31) | msg_filter->ext_id_mask;
filter->can_id = (zfilter->id_type << 31) |
(zfilter->rtr << 30) | zfilter->ext_id;
filter->can_mask = (zfilter->rtr_mask << 30) |
(zfilter->id_type << 31) | zfilter->ext_id_mask;
}
#ifdef __cplusplus

View file

@ -41,7 +41,7 @@ enum {
};
/* Socket CAN MTU size */
#define CAN_MTU (sizeof(struct can_msg))
#define CAN_MTU CAN_MAX_DLEN
/**
* struct sockaddr_can - The sockaddr structure for CAN sockets

View file

@ -51,7 +51,7 @@ void button_callback(struct device *port,
void send_string(char *string, struct device *can_dev)
{
struct can_msg msg;
struct zcan_frame msg;
int str_len;
msg.ext_id = STR_MSG_ID;
@ -72,8 +72,8 @@ void tx_thread(void *can_dev_param, void *unused2, void *unused3)
{
u8_t toggle = SET_LED;
u16_t button_press_cnt = 0U;
struct can_msg msg;
struct can_msg msg_button_cnt;
struct zcan_frame msg;
struct zcan_frame msg_button_cnt;
struct device *can_dev = can_dev_param;
msg.std_id = LED_MSG_ID;
@ -108,8 +108,8 @@ void tx_thread(void *can_dev_param, void *unused2, void *unused3)
void rx_str_thread(void *msgq, void *can_dev_param, void *unused)
{
struct can_msg msg;
const struct can_msg_filter filter = {
struct zcan_frame msg;
const struct zcan_filter filter = {
.id_type = CAN_EXTENDED_IDENTIFIER,
.rtr = CAN_DATAFRAME,
.ext_id = STR_MSG_ID,
@ -129,7 +129,7 @@ void rx_str_thread(void *msgq, void *can_dev_param, void *unused)
void led_thread(void *msgq, void *can_dev_param, void *gpio_dev_param)
{
const struct can_msg_filter filter = {
const struct zcan_filter filter = {
.id_type = CAN_STANDARD_IDENTIFIER,
.rtr = CAN_DATAFRAME,
.std_id = LED_MSG_ID,
@ -138,7 +138,7 @@ void led_thread(void *msgq, void *can_dev_param, void *gpio_dev_param)
};
struct device *can_dev = can_dev_param;
struct device *gpio_dev = gpio_dev_param;
struct can_msg msg;
struct zcan_frame msg;
int ret;
int filter_id;
@ -172,7 +172,7 @@ void led_thread(void *msgq, void *can_dev_param, void *gpio_dev_param)
}
}
void rx_button_isr(struct can_msg *msg)
void rx_button_isr(struct zcan_frame *msg)
{
u16_t cnt = msg->data[0] | (msg->data[1] << 8);
@ -181,7 +181,7 @@ void rx_button_isr(struct can_msg *msg)
void main(void)
{
const struct can_msg_filter filter = {
const struct zcan_filter filter = {
.id_type = CAN_STANDARD_IDENTIFIER,
.rtr = CAN_DATAFRAME,
.std_id = BUTTON_MSG_ID,

View file

@ -25,7 +25,7 @@ static void tx(int *can_fd)
static char data[] = { 0x11, 0x22, 0x33, 0x44,
0x55, 0x66, 0x77, 0x88 };
int fd = POINTER_TO_INT(can_fd);
struct can_msg msg;
struct zcan_frame msg;
int ret, i;
msg.dlc = sizeof(data);
@ -40,7 +40,7 @@ static void tx(int *can_fd)
LOG_DBG("Sending CAN data...");
while (1) {
ret = send(fd, &msg, sizeof(struct can_msg), K_FOREVER);
ret = send(fd, &msg, sizeof(struct zcan_frame), K_FOREVER);
if (ret < 0) {
LOG_ERR("Cannot send CAN message (%d)", -errno);
}
@ -53,7 +53,7 @@ static void rx(int fd)
{
struct sockaddr_can can_addr;
socklen_t addr_len;
struct can_msg msg;
struct zcan_frame msg;
int ret;
LOG_DBG("Waiting CAN data...");
@ -64,7 +64,7 @@ static void rx(int fd)
memset(&msg, 0, sizeof(msg));
addr_len = sizeof(can_addr);
ret = recvfrom(fd, &msg, sizeof(struct can_msg),
ret = recvfrom(fd, &msg, sizeof(struct zcan_frame),
0, (struct sockaddr *)&can_addr, &addr_len);
if (ret < 0) {
LOG_ERR("Cannot receive CAN message (%d)", ret);
@ -90,7 +90,7 @@ static void rx(int fd)
static int setup_socket(void)
{
const struct can_msg_filter filter = {
const struct zcan_filter filter = {
.id_type = CAN_STANDARD_IDENTIFIER,
.rtr = CAN_DATAFRAME,
.std_id = 0x1,

View file

@ -16,11 +16,11 @@ LOG_MODULE_REGISTER(can_test, LOG_LEVEL_ERR);
#include <ztest.h>
static void test_can_frame_to_msg(void)
static void test_can_frame_to_zcan_frame(void)
{
struct can_frame frame = { 0 };
struct can_msg expected = { 0 };
struct can_msg msg;
struct zcan_frame expected = { 0 };
struct zcan_frame msg;
const u8_t data[CAN_MAX_DLEN] = { 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08 };
@ -33,7 +33,7 @@ static void test_can_frame_to_msg(void)
expected.std_id = 1234;
expected.dlc = sizeof(data);
can_copy_frame_to_msg(&frame, &msg);
can_copy_frame_to_zframe(&frame, &msg);
LOG_HEXDUMP_DBG((const u8_t *)&frame, sizeof(frame), "frame");
LOG_HEXDUMP_DBG((const u8_t *)&msg, sizeof(msg), "msg");
@ -45,11 +45,11 @@ static void test_can_frame_to_msg(void)
zassert_equal(msg.dlc, expected.dlc, "Msg length invalid");
}
static void test_can_msg_to_frame(void)
static void test_zcan_frame_to_can_frame(void)
{
struct can_frame frame = { 0 };
struct can_frame expected = { 0 };
struct can_msg msg = { 0 };
struct zcan_frame msg = { 0 };
const u8_t data[CAN_MAX_DLEN] = { 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08 };
@ -63,7 +63,7 @@ static void test_can_msg_to_frame(void)
msg.dlc = sizeof(data);
memcpy(msg.data, data, sizeof(data));
can_copy_msg_to_frame(&msg, &frame);
can_copy_zframe_to_frame(&msg, &frame);
LOG_HEXDUMP_DBG((const u8_t *)&frame, sizeof(frame), "frame");
LOG_HEXDUMP_DBG((const u8_t *)&msg, sizeof(msg), "msg");
@ -77,11 +77,11 @@ static void test_can_msg_to_frame(void)
"CAN msg length not same");
}
static void test_can_filter_to_msg_filter(void)
static void test_can_filter_to_zcan_filter(void)
{
struct can_filter filter = { 0 };
struct can_msg_filter expected = { 0 };
struct can_msg_filter msg_filter = { 0 };
struct zcan_filter expected = { 0 };
struct zcan_filter msg_filter = { 0 };
filter.can_id = BIT(31) | BIT(30) | 1234;
filter.can_mask = BIT(31) | BIT(30) | 1234;
@ -92,7 +92,7 @@ static void test_can_filter_to_msg_filter(void)
expected.rtr_mask = 1;
expected.std_id_mask = 1234;
can_copy_filter_to_msg_filter(&filter, &msg_filter);
can_copy_filter_to_zfilter(&filter, &msg_filter);
LOG_HEXDUMP_DBG((const u8_t *)&msg_filter, sizeof(msg_filter),
"msg_filter");
@ -110,11 +110,11 @@ static void test_can_filter_to_msg_filter(void)
"Std id mask not set");
}
static void test_can_msg_filter_to_filter(void)
static void test_zcan_filter_to_can_filter(void)
{
struct can_filter filter = { 0 };
struct can_filter expected = { 0 };
struct can_msg_filter msg_filter = { 0 };
struct zcan_filter msg_filter = { 0 };
expected.can_id = BIT(31) | BIT(30) | 1234;
expected.can_mask = BIT(31) | BIT(30) | 1234;
@ -125,7 +125,7 @@ static void test_can_msg_filter_to_filter(void)
msg_filter.rtr_mask = 1;
msg_filter.std_id_mask = 1234;
can_copy_msg_filter_to_filter(&msg_filter, &filter);
can_copy_zfilter_to_filter(&msg_filter, &filter);
LOG_HEXDUMP_DBG((const u8_t *)&msg_filter, sizeof(msg_filter),
"msg_filter");
@ -141,10 +141,10 @@ static void test_can_msg_filter_to_filter(void)
void test_main(void)
{
ztest_test_suite(test_can_frame,
ztest_unit_test(test_can_frame_to_msg),
ztest_unit_test(test_can_msg_to_frame),
ztest_unit_test(test_can_filter_to_msg_filter),
ztest_unit_test(test_can_msg_filter_to_filter));
ztest_unit_test(test_can_frame_to_zcan_frame),
ztest_unit_test(test_zcan_frame_to_can_frame),
ztest_unit_test(test_can_filter_to_zcan_filter),
ztest_unit_test(test_zcan_filter_to_can_filter));
ztest_run_test_suite(test_can_frame);
}