drivers: can: mcp2515: move filter_match function
Move filter match function to can_utils.h, so that it can be reused for Renesas driver. Preserve copyright from Karsten Koenig. Signed-off-by: Julien Massot <julien.massot@iot.bzh>
This commit is contained in:
parent
02b788cd62
commit
d79044cd2b
2 changed files with 35 additions and 20 deletions
|
@ -16,6 +16,7 @@
|
|||
LOG_MODULE_REGISTER(mcp2515_can);
|
||||
|
||||
#include "can_mcp2515.h"
|
||||
#include "can_utils.h"
|
||||
|
||||
#define SP_IS_SET(inst) DT_INST_NODE_HAS_PROP(inst, sample_point) ||
|
||||
|
||||
|
@ -565,24 +566,6 @@ static void mcp2515_register_state_change_isr(const struct device *dev,
|
|||
dev_data->state_change_isr = isr;
|
||||
}
|
||||
|
||||
static uint8_t mcp2515_filter_match(struct zcan_frame *msg,
|
||||
struct zcan_filter *filter)
|
||||
{
|
||||
if (msg->id_type != filter->id_type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((msg->rtr ^ filter->rtr) & filter->rtr_mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((msg->id ^ filter->id) & filter->id_mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void mcp2515_rx_filter(const struct device *dev,
|
||||
struct zcan_frame *msg)
|
||||
{
|
||||
|
@ -598,8 +581,8 @@ static void mcp2515_rx_filter(const struct device *dev,
|
|||
continue; /* filter slot empty */
|
||||
}
|
||||
|
||||
if (!mcp2515_filter_match(msg,
|
||||
&dev_data->filter[filter_idx])) {
|
||||
if (!can_utils_filter_match(msg,
|
||||
&dev_data->filter[filter_idx])) {
|
||||
continue; /* filter did not match */
|
||||
}
|
||||
|
||||
|
|
32
drivers/can/can_utils.h
Normal file
32
drivers/can/can_utils.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Karsten Koenig
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file Header where utility code can be found for CAN drivers
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_DRIVERS_CAN_CAN_UTILS_H_
|
||||
#define ZEPHYR_DRIVERS_CAN_CAN_UTILS_H_
|
||||
|
||||
static inline uint8_t can_utils_filter_match(const struct zcan_frame *msg,
|
||||
struct zcan_filter *filter)
|
||||
{
|
||||
if (msg->id_type != filter->id_type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((msg->rtr ^ filter->rtr) & filter->rtr_mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((msg->id ^ filter->id) & filter->id_mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_CAN_CAN_UTILS_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue