Commit c478b5bb authored by Jukka Rissanen's avatar Jukka Rissanen Committed by Anas Nashif
Browse files

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: default avatarJukka Rissanen <jukka.rissanen@linux.intel.com>
parent 14d40233
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);
+11 −11
Original line number Diff line number Diff line
@@ -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;
+51 −49
Original line number Diff line number Diff line
@@ -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,
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,
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
+1 −1
Original line number Diff line number Diff line
@@ -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
+9 −9
Original line number Diff line number Diff line
@@ -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,
Loading