drivers: can: catch up on API naming changes
Catch up on the CAN driver API argument naming changes: - Unify naming of callback function pointers as "callback". - Unify naming of user-specified callback function arguments as "user_data". - Instances and pointers to struct zcan_frame are named "frame", not "msg", to avoid confusion with the CAN message queue support. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
deb1b455b9
commit
b21a91e468
|
@ -120,7 +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);
|
||||
LOG_ERR("Workq buffer overflow. Frame ID: 0x%x", frame->id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ static void can_work_isr_put(struct zcan_frame *frame, void *arg)
|
|||
|
||||
int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
||||
struct zcan_work *work,
|
||||
can_rx_callback_t callback, void *callback_arg,
|
||||
can_rx_callback_t callback, void *user_data,
|
||||
const struct zcan_filter *filter)
|
||||
{
|
||||
const struct can_driver_api *api = dev->api;
|
||||
|
@ -137,7 +137,7 @@ int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
|||
k_work_init(&work->work_item, can_work_handler);
|
||||
work->work_queue = work_q;
|
||||
work->cb = callback;
|
||||
work->cb_arg = callback_arg;
|
||||
work->cb_arg = user_data;
|
||||
can_work_buffer_init(&work->buf);
|
||||
|
||||
return api->attach_isr(dev, can_work_isr_put, work, filter);
|
||||
|
|
|
@ -31,27 +31,27 @@ static inline int z_vrfy_can_get_core_clock(const struct device *dev,
|
|||
#include <syscalls/can_get_core_clock_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_can_send(const struct device *dev,
|
||||
const struct zcan_frame *msg,
|
||||
const struct zcan_frame *frame,
|
||||
k_timeout_t timeout,
|
||||
can_tx_callback_t callback_isr,
|
||||
void *callback_arg)
|
||||
can_tx_callback_t callback,
|
||||
void *user_data)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, send));
|
||||
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ((const struct zcan_frame *)msg,
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ((const struct zcan_frame *)frame,
|
||||
sizeof(struct zcan_frame)));
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ(((struct zcan_frame *)msg)->data,
|
||||
sizeof((struct zcan_frame *)msg)->data));
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(callback_isr == 0,
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ(((struct zcan_frame *)frame)->data,
|
||||
sizeof((struct zcan_frame *)frame)->data));
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(callback == 0,
|
||||
"callbacks may not be set from user mode"));
|
||||
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ((void *)callback_arg, sizeof(void *)));
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ((void *)user_data, sizeof(void *)));
|
||||
|
||||
return z_impl_can_send((const struct device *)dev,
|
||||
(const struct zcan_frame *)msg,
|
||||
(const struct zcan_frame *)frame,
|
||||
(k_timeout_t)timeout,
|
||||
(can_tx_callback_t) callback_isr,
|
||||
(void *)callback_arg);
|
||||
(can_tx_callback_t) callback,
|
||||
(void *)user_data);
|
||||
}
|
||||
#include <syscalls/can_send_mrsh.c>
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ void tx_thread(void *data_arg, void *arg2, void *arg3)
|
|||
int can_loopback_send(const struct device *dev,
|
||||
const struct zcan_frame *frame,
|
||||
k_timeout_t timeout, can_tx_callback_t callback,
|
||||
void *callback_arg)
|
||||
void *user_data)
|
||||
{
|
||||
struct can_loopback_data *data = DEV_DATA(dev);
|
||||
int ret;
|
||||
|
@ -105,7 +105,7 @@ int can_loopback_send(const struct device *dev,
|
|||
|
||||
loopback_frame.frame = *frame;
|
||||
loopback_frame.cb = callback;
|
||||
loopback_frame.cb_arg = callback_arg;
|
||||
loopback_frame.cb_arg = user_data;
|
||||
loopback_frame.tx_compl = &tx_sem;
|
||||
|
||||
if (!callback) {
|
||||
|
|
|
@ -626,7 +626,7 @@ int can_mcan_send(const struct can_mcan_config *cfg,
|
|||
struct can_mcan_msg_sram *msg_ram,
|
||||
const struct zcan_frame *frame,
|
||||
k_timeout_t timeout,
|
||||
can_tx_callback_t callback, void *callback_arg)
|
||||
can_tx_callback_t callback, void *user_data)
|
||||
{
|
||||
struct can_mcan_reg *can = cfg->can;
|
||||
size_t data_length = can_dlc_to_bytes(frame->dlc);
|
||||
|
@ -704,7 +704,7 @@ int can_mcan_send(const struct can_mcan_config *cfg,
|
|||
}
|
||||
|
||||
data->tx_fin_cb[put_idx] = callback;
|
||||
data->tx_fin_cb_arg[put_idx] = callback_arg;
|
||||
data->tx_fin_cb_arg[put_idx] = user_data;
|
||||
|
||||
can->txbar = (1U << put_idx);
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ int can_mcan_send(const struct can_mcan_config *cfg, struct can_mcan_data *data,
|
|||
struct can_mcan_msg_sram *msg_ram,
|
||||
const struct zcan_frame *frame,
|
||||
k_timeout_t timeout, can_tx_callback_t callback,
|
||||
void *callback_arg);
|
||||
void *user_data);
|
||||
|
||||
int can_mcan_attach_isr(struct can_mcan_data *data,
|
||||
struct can_mcan_msg_sram *msg_ram,
|
||||
|
|
|
@ -456,9 +456,9 @@ static int mcp2515_set_mode(const struct device *dev, enum can_mode mode)
|
|||
}
|
||||
|
||||
static int mcp2515_send(const struct device *dev,
|
||||
const struct zcan_frame *msg,
|
||||
const struct zcan_frame *frame,
|
||||
k_timeout_t timeout, can_tx_callback_t callback,
|
||||
void *callback_arg)
|
||||
void *user_data)
|
||||
{
|
||||
struct mcp2515_data *dev_data = DEV_DATA(dev);
|
||||
uint8_t tx_idx = 0U;
|
||||
|
@ -467,9 +467,9 @@ static int mcp2515_send(const struct device *dev,
|
|||
uint8_t len;
|
||||
uint8_t tx_frame[MCP2515_FRAME_LEN];
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
if (frame->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)",
|
||||
msg->dlc, CAN_MAX_DLC);
|
||||
frame->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -495,15 +495,15 @@ static int mcp2515_send(const struct device *dev,
|
|||
}
|
||||
|
||||
dev_data->tx_cb[tx_idx].cb = callback;
|
||||
dev_data->tx_cb[tx_idx].cb_arg = callback_arg;
|
||||
dev_data->tx_cb[tx_idx].cb_arg = user_data;
|
||||
|
||||
mcp2515_convert_zcanframe_to_mcp2515frame(msg, tx_frame);
|
||||
mcp2515_convert_zcanframe_to_mcp2515frame(frame, tx_frame);
|
||||
|
||||
/* Address Pointer selection */
|
||||
abc = 2 * tx_idx;
|
||||
|
||||
/* Calculate minimum length to transfer */
|
||||
len = sizeof(tx_frame) - CAN_MAX_DLC + msg->dlc;
|
||||
len = sizeof(tx_frame) - CAN_MAX_DLC + frame->dlc;
|
||||
|
||||
mcp2515_cmd_load_tx_buffer(dev, abc, tx_frame, len);
|
||||
|
||||
|
@ -571,12 +571,12 @@ static void mcp2515_register_state_change_isr(const struct device *dev,
|
|||
}
|
||||
|
||||
static void mcp2515_rx_filter(const struct device *dev,
|
||||
struct zcan_frame *msg)
|
||||
struct zcan_frame *frame)
|
||||
{
|
||||
struct mcp2515_data *dev_data = DEV_DATA(dev);
|
||||
uint8_t filter_idx = 0U;
|
||||
can_rx_callback_t callback;
|
||||
struct zcan_frame tmp_msg;
|
||||
struct zcan_frame tmp_frame;
|
||||
|
||||
k_mutex_lock(&dev_data->mutex, K_FOREVER);
|
||||
|
||||
|
@ -585,16 +585,16 @@ static void mcp2515_rx_filter(const struct device *dev,
|
|||
continue; /* filter slot empty */
|
||||
}
|
||||
|
||||
if (!can_utils_filter_match(msg,
|
||||
if (!can_utils_filter_match(frame,
|
||||
&dev_data->filter[filter_idx])) {
|
||||
continue; /* filter did not match */
|
||||
}
|
||||
|
||||
callback = dev_data->rx_cb[filter_idx];
|
||||
/*Make a temporary copy in case the user modifies the message*/
|
||||
tmp_msg = *msg;
|
||||
tmp_frame = *frame;
|
||||
|
||||
callback(&tmp_msg, dev_data->cb_arg[filter_idx]);
|
||||
callback(&tmp_frame, dev_data->cb_arg[filter_idx]);
|
||||
}
|
||||
|
||||
k_mutex_unlock(&dev_data->mutex);
|
||||
|
@ -604,7 +604,7 @@ static void mcp2515_rx(const struct device *dev, uint8_t rx_idx)
|
|||
{
|
||||
__ASSERT(rx_idx < MCP2515_RX_CNT, "rx_idx < MCP2515_RX_CNT");
|
||||
|
||||
struct zcan_frame msg;
|
||||
struct zcan_frame frame;
|
||||
uint8_t rx_frame[MCP2515_FRAME_LEN];
|
||||
uint8_t nm;
|
||||
|
||||
|
@ -613,8 +613,8 @@ static void mcp2515_rx(const struct device *dev, uint8_t rx_idx)
|
|||
|
||||
/* Fetch rx buffer */
|
||||
mcp2515_cmd_read_rx_buffer(dev, nm, rx_frame, sizeof(rx_frame));
|
||||
mcp2515_convert_mcp2515frame_to_zcanframe(rx_frame, &msg);
|
||||
mcp2515_rx_filter(dev, &msg);
|
||||
mcp2515_convert_mcp2515frame_to_zcanframe(rx_frame, &frame);
|
||||
mcp2515_rx_filter(dev, &frame);
|
||||
}
|
||||
|
||||
static void mcp2515_tx_done(const struct device *dev, uint8_t tx_idx)
|
||||
|
|
|
@ -316,9 +316,9 @@ static int mcux_get_tx_alloc(struct mcux_flexcan_data *data)
|
|||
}
|
||||
|
||||
static int mcux_flexcan_send(const struct device *dev,
|
||||
const struct zcan_frame *msg,
|
||||
const struct zcan_frame *frame,
|
||||
k_timeout_t timeout,
|
||||
can_tx_callback_t callback_isr, void *callback_arg)
|
||||
can_tx_callback_t callback, void *user_data)
|
||||
{
|
||||
const struct mcux_flexcan_config *config = dev->config;
|
||||
struct mcux_flexcan_data *data = dev->data;
|
||||
|
@ -326,8 +326,8 @@ static int mcux_flexcan_send(const struct device *dev,
|
|||
status_t status;
|
||||
int alloc;
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", msg->dlc, CAN_MAX_DLC);
|
||||
if (frame->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -346,9 +346,9 @@ static int mcux_flexcan_send(const struct device *dev,
|
|||
}
|
||||
}
|
||||
|
||||
mcux_flexcan_copy_zframe_to_frame(msg, &data->tx_cbs[alloc].frame);
|
||||
data->tx_cbs[alloc].function = callback_isr;
|
||||
data->tx_cbs[alloc].arg = callback_arg;
|
||||
mcux_flexcan_copy_zframe_to_frame(frame, &data->tx_cbs[alloc].frame);
|
||||
data->tx_cbs[alloc].function = callback;
|
||||
data->tx_cbs[alloc].arg = user_data;
|
||||
xfer.frame = &data->tx_cbs[alloc].frame;
|
||||
xfer.mbIdx = ALLOC_IDX_TO_TXMB_IDX(alloc);
|
||||
FLEXCAN_SetTxMbConfig(config->base, xfer.mbIdx, true);
|
||||
|
@ -358,7 +358,7 @@ static int mcux_flexcan_send(const struct device *dev,
|
|||
return CAN_TX_ERR;
|
||||
}
|
||||
|
||||
if (callback_isr == NULL) {
|
||||
if (callback == NULL) {
|
||||
k_sem_take(&data->tx_cbs[alloc].done, K_FOREVER);
|
||||
return data->tx_cbs[alloc].status;
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ static int mcux_flexcan_send(const struct device *dev,
|
|||
|
||||
static int mcux_flexcan_attach_isr(const struct device *dev,
|
||||
can_rx_callback_t isr,
|
||||
void *callback_arg,
|
||||
void *user_data,
|
||||
const struct zcan_filter *filter)
|
||||
{
|
||||
const struct mcux_flexcan_config *config = dev->config;
|
||||
|
@ -399,7 +399,7 @@ static int mcux_flexcan_attach_isr(const struct device *dev,
|
|||
&data->rx_cbs[alloc].mb_config,
|
||||
&mask);
|
||||
|
||||
data->rx_cbs[alloc].arg = callback_arg;
|
||||
data->rx_cbs[alloc].arg = user_data;
|
||||
data->rx_cbs[alloc].function = isr;
|
||||
|
||||
FLEXCAN_SetRxIndividualMask(config->base, ALLOC_IDX_TO_RXMB_IDX(alloc),
|
||||
|
|
|
@ -364,9 +364,9 @@ static void can_rcar_error(const struct device *dev)
|
|||
}
|
||||
|
||||
static void can_rcar_rx_filter_isr(struct can_rcar_data *data,
|
||||
const struct zcan_frame *msg)
|
||||
const struct zcan_frame *frame)
|
||||
{
|
||||
struct zcan_frame tmp_msg;
|
||||
struct zcan_frame tmp_frame;
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < CONFIG_CAN_RCAR_MAX_FILTER; i++) {
|
||||
|
@ -374,15 +374,15 @@ static void can_rcar_rx_filter_isr(struct can_rcar_data *data,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!can_utils_filter_match(msg,
|
||||
if (!can_utils_filter_match(frame,
|
||||
&data->filter[i])) {
|
||||
continue; /* filter did not match */
|
||||
}
|
||||
/* Make a temporary copy in case the user
|
||||
* modifies the message.
|
||||
*/
|
||||
tmp_msg = *msg;
|
||||
data->rx_callback[i](&tmp_msg, data->rx_callback_arg[i]);
|
||||
tmp_frame = *frame;
|
||||
data->rx_callback[i](&tmp_frame, data->rx_callback_arg[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,51 +390,51 @@ static void can_rcar_rx_isr(const struct device *dev)
|
|||
{
|
||||
struct can_rcar_data *data = DEV_CAN_DATA(dev);
|
||||
const struct can_rcar_cfg *config = DEV_CAN_CFG(dev);
|
||||
struct zcan_frame msg;
|
||||
struct zcan_frame frame;
|
||||
uint32_t val;
|
||||
int i;
|
||||
|
||||
val = sys_read32(config->reg_addr + RCAR_CAN_MB_60);
|
||||
if (val & RCAR_CAN_MB_IDE) {
|
||||
msg.id_type = CAN_EXTENDED_IDENTIFIER;
|
||||
msg.id = val & RCAR_CAN_MB_EID_MASK;
|
||||
frame.id_type = CAN_EXTENDED_IDENTIFIER;
|
||||
frame.id = val & RCAR_CAN_MB_EID_MASK;
|
||||
} else {
|
||||
msg.id_type = CAN_STANDARD_IDENTIFIER;
|
||||
msg.id = (val & RCAR_CAN_MB_SID_MASK) >> RCAR_CAN_MB_SID_SHIFT;
|
||||
frame.id_type = CAN_STANDARD_IDENTIFIER;
|
||||
frame.id = (val & RCAR_CAN_MB_SID_MASK) >> RCAR_CAN_MB_SID_SHIFT;
|
||||
}
|
||||
|
||||
if (val & RCAR_CAN_MB_RTR) {
|
||||
msg.rtr = CAN_REMOTEREQUEST;
|
||||
frame.rtr = CAN_REMOTEREQUEST;
|
||||
} else {
|
||||
msg.rtr = CAN_DATAFRAME;
|
||||
frame.rtr = CAN_DATAFRAME;
|
||||
}
|
||||
|
||||
msg.dlc = sys_read16(config->reg_addr
|
||||
+ RCAR_CAN_MB_60 + RCAR_CAN_MB_DLC_OFFSET) & 0xF;
|
||||
frame.dlc = sys_read16(config->reg_addr +
|
||||
RCAR_CAN_MB_60 + RCAR_CAN_MB_DLC_OFFSET) & 0xF;
|
||||
|
||||
/* Be paranoid doc states that any value greater than 8
|
||||
* should be considered as 8 bytes.
|
||||
*/
|
||||
if (msg.dlc > CAN_MAX_DLC) {
|
||||
msg.dlc = CAN_MAX_DLC;
|
||||
if (frame.dlc > CAN_MAX_DLC) {
|
||||
frame.dlc = CAN_MAX_DLC;
|
||||
}
|
||||
|
||||
for (i = 0; i < msg.dlc; i++) {
|
||||
msg.data[i] = sys_read8(config->reg_addr
|
||||
+ RCAR_CAN_MB_60 + RCAR_CAN_MB_DATA_OFFSET + i);
|
||||
for (i = 0; i < frame.dlc; i++) {
|
||||
frame.data[i] = sys_read8(config->reg_addr +
|
||||
RCAR_CAN_MB_60 + RCAR_CAN_MB_DATA_OFFSET + i);
|
||||
}
|
||||
#if defined(CONFIG_CAN_RX_TIMESTAMP)
|
||||
/* read upper byte */
|
||||
msg.timestamp = sys_read8(config->reg_addr +
|
||||
RCAR_CAN_MB_60 + RCAR_CAN_MB_TSH_OFFSET) << 8;
|
||||
frame.timestamp = sys_read8(config->reg_addr +
|
||||
RCAR_CAN_MB_60 + RCAR_CAN_MB_TSH_OFFSET) << 8;
|
||||
/* and then read lower byte */
|
||||
msg.timestamp |= sys_read8(config->reg_addr +
|
||||
RCAR_CAN_MB_60 + RCAR_CAN_MB_TSL_OFFSET);
|
||||
frame.timestamp |= sys_read8(config->reg_addr +
|
||||
RCAR_CAN_MB_60 + RCAR_CAN_MB_TSL_OFFSET);
|
||||
#endif
|
||||
/* Increment CPU side pointer */
|
||||
sys_write8(0xff, config->reg_addr + RCAR_CAN_RFPCR);
|
||||
|
||||
can_rcar_rx_filter_isr(data, &msg);
|
||||
can_rcar_rx_filter_isr(data, &frame);
|
||||
}
|
||||
|
||||
static void can_rcar_isr(const struct device *dev)
|
||||
|
@ -711,9 +711,9 @@ done:
|
|||
}
|
||||
#endif /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
|
||||
|
||||
int can_rcar_send(const struct device *dev, const struct zcan_frame *msg,
|
||||
int can_rcar_send(const struct device *dev, const struct zcan_frame *frame,
|
||||
k_timeout_t timeout, can_tx_callback_t callback,
|
||||
void *callback_arg)
|
||||
void *user_data)
|
||||
{
|
||||
const struct can_rcar_cfg *config = DEV_CAN_CFG(dev);
|
||||
struct can_rcar_data *data = DEV_CAN_DATA(dev);
|
||||
|
@ -725,17 +725,17 @@ int can_rcar_send(const struct device *dev, const struct zcan_frame *msg,
|
|||
"Id: 0x%x, "
|
||||
"ID type: %s, "
|
||||
"Remote Frame: %s"
|
||||
, msg->dlc, dev->name
|
||||
, msg->id
|
||||
, msg->id_type == CAN_STANDARD_IDENTIFIER ?
|
||||
, frame->dlc, dev->name
|
||||
, frame->id
|
||||
, frame->id_type == CAN_STANDARD_IDENTIFIER ?
|
||||
"standard" : "extended"
|
||||
, msg->rtr == CAN_DATAFRAME ? "no" : "yes");
|
||||
, frame->rtr == CAN_DATAFRAME ? "no" : "yes");
|
||||
|
||||
__ASSERT(msg->dlc == 0U || msg->data != NULL, "Dataptr is null");
|
||||
__ASSERT(frame->dlc == 0U || frame->data != NULL, "Dataptr is null");
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
if (frame->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)",
|
||||
msg->dlc, CAN_MAX_DLC);
|
||||
frame->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -747,7 +747,7 @@ int can_rcar_send(const struct device *dev, const struct zcan_frame *msg,
|
|||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||
tx_cb = &data->tx_cb[data->tx_head];
|
||||
tx_cb->cb = callback;
|
||||
tx_cb->cb_arg = callback_arg;
|
||||
tx_cb->cb_arg = user_data;
|
||||
|
||||
k_sem_reset(&tx_cb->sem);
|
||||
|
||||
|
@ -756,23 +756,23 @@ int can_rcar_send(const struct device *dev, const struct zcan_frame *msg,
|
|||
data->tx_head = 0;
|
||||
}
|
||||
|
||||
if (msg->id_type == CAN_STANDARD_IDENTIFIER) {
|
||||
identifier = msg->id << RCAR_CAN_MB_SID_SHIFT;
|
||||
if (frame->id_type == CAN_STANDARD_IDENTIFIER) {
|
||||
identifier = frame->id << RCAR_CAN_MB_SID_SHIFT;
|
||||
} else {
|
||||
identifier = msg->id | RCAR_CAN_MB_IDE;
|
||||
identifier = frame->id | RCAR_CAN_MB_IDE;
|
||||
}
|
||||
|
||||
if (msg->rtr == CAN_REMOTEREQUEST) {
|
||||
if (frame->rtr == CAN_REMOTEREQUEST) {
|
||||
identifier |= RCAR_CAN_MB_RTR;
|
||||
}
|
||||
|
||||
sys_write32(identifier, config->reg_addr + RCAR_CAN_MB_56);
|
||||
|
||||
sys_write16(msg->dlc, config->reg_addr
|
||||
sys_write16(frame->dlc, config->reg_addr
|
||||
+ RCAR_CAN_MB_56 + RCAR_CAN_MB_DLC_OFFSET);
|
||||
|
||||
for (i = 0; i < msg->dlc; i++) {
|
||||
sys_write8(msg->data[i], config->reg_addr
|
||||
for (i = 0; i < frame->dlc; i++) {
|
||||
sys_write8(frame->data[i], config->reg_addr
|
||||
+ RCAR_CAN_MB_56 + RCAR_CAN_MB_DATA_OFFSET + i);
|
||||
}
|
||||
|
||||
|
|
|
@ -63,22 +63,22 @@ static void can_stm32_signal_tx_complete(struct can_mailbox *mb)
|
|||
}
|
||||
|
||||
static void can_stm32_get_msg_fifo(CAN_FIFOMailBox_TypeDef *mbox,
|
||||
struct zcan_frame *msg)
|
||||
struct zcan_frame *frame)
|
||||
{
|
||||
if (mbox->RIR & CAN_RI0R_IDE) {
|
||||
msg->id = mbox->RIR >> CAN_RI0R_EXID_Pos;
|
||||
msg->id_type = CAN_EXTENDED_IDENTIFIER;
|
||||
frame->id = mbox->RIR >> CAN_RI0R_EXID_Pos;
|
||||
frame->id_type = CAN_EXTENDED_IDENTIFIER;
|
||||
} else {
|
||||
msg->id = mbox->RIR >> CAN_RI0R_STID_Pos;
|
||||
msg->id_type = CAN_STANDARD_IDENTIFIER;
|
||||
frame->id = mbox->RIR >> CAN_RI0R_STID_Pos;
|
||||
frame->id_type = CAN_STANDARD_IDENTIFIER;
|
||||
}
|
||||
|
||||
msg->rtr = mbox->RIR & CAN_RI0R_RTR ? CAN_REMOTEREQUEST : CAN_DATAFRAME;
|
||||
msg->dlc = mbox->RDTR & (CAN_RDT0R_DLC >> CAN_RDT0R_DLC_Pos);
|
||||
msg->data_32[0] = mbox->RDLR;
|
||||
msg->data_32[1] = mbox->RDHR;
|
||||
frame->rtr = mbox->RIR & CAN_RI0R_RTR ? CAN_REMOTEREQUEST : CAN_DATAFRAME;
|
||||
frame->dlc = mbox->RDTR & (CAN_RDT0R_DLC >> CAN_RDT0R_DLC_Pos);
|
||||
frame->data_32[0] = mbox->RDLR;
|
||||
frame->data_32[1] = mbox->RDHR;
|
||||
#ifdef CONFIG_CAN_RX_TIMESTAMP
|
||||
msg->timestamp = ((mbox->RDTR & CAN_RDT0R_TIME) >> CAN_RDT0R_TIME_Pos);
|
||||
frame->timestamp = ((mbox->RDTR & CAN_RDT0R_TIME) >> CAN_RDT0R_TIME_Pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ void can_stm32_rx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
|
|||
{
|
||||
CAN_FIFOMailBox_TypeDef *mbox;
|
||||
int filter_match_index;
|
||||
struct zcan_frame msg;
|
||||
struct zcan_frame frame;
|
||||
can_rx_callback_t callback;
|
||||
|
||||
while (can->RF0R & CAN_RF0R_FMP0) {
|
||||
|
@ -100,12 +100,12 @@ void can_stm32_rx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
|
|||
}
|
||||
|
||||
LOG_DBG("Message on filter index %d", filter_match_index);
|
||||
can_stm32_get_msg_fifo(mbox, &msg);
|
||||
can_stm32_get_msg_fifo(mbox, &frame);
|
||||
|
||||
callback = data->rx_cb[filter_match_index];
|
||||
|
||||
if (callback) {
|
||||
callback(&msg, data->cb_arg[filter_match_index]);
|
||||
callback(&frame, data->cb_arg[filter_match_index]);
|
||||
}
|
||||
|
||||
/* Release message */
|
||||
|
@ -606,9 +606,9 @@ done:
|
|||
#endif /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
|
||||
|
||||
|
||||
int can_stm32_send(const struct device *dev, const struct zcan_frame *msg,
|
||||
int can_stm32_send(const struct device *dev, const struct zcan_frame *frame,
|
||||
k_timeout_t timeout, can_tx_callback_t callback,
|
||||
void *callback_arg)
|
||||
void *user_data)
|
||||
{
|
||||
const struct can_stm32_config *cfg = DEV_CFG(dev);
|
||||
struct can_stm32_data *data = DEV_DATA(dev);
|
||||
|
@ -621,16 +621,16 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *msg,
|
|||
"Id: 0x%x, "
|
||||
"ID type: %s, "
|
||||
"Remote Frame: %s"
|
||||
, msg->dlc, dev->name
|
||||
, msg->id
|
||||
, msg->id_type == CAN_STANDARD_IDENTIFIER ?
|
||||
, frame->dlc, dev->name
|
||||
, frame->id
|
||||
, frame->id_type == CAN_STANDARD_IDENTIFIER ?
|
||||
"standard" : "extended"
|
||||
, msg->rtr == CAN_DATAFRAME ? "no" : "yes");
|
||||
, frame->rtr == CAN_DATAFRAME ? "no" : "yes");
|
||||
|
||||
__ASSERT(msg->dlc == 0U || msg->data != NULL, "Dataptr is null");
|
||||
__ASSERT(frame->dlc == 0U || frame->data != NULL, "Dataptr is null");
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", msg->dlc, CAN_MAX_DLC);
|
||||
if (frame->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -665,28 +665,28 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *msg,
|
|||
}
|
||||
|
||||
mb->tx_callback = callback;
|
||||
mb->callback_arg = callback_arg;
|
||||
mb->callback_arg = user_data;
|
||||
k_sem_reset(&mb->tx_int_sem);
|
||||
|
||||
/* mailbox identifier register setup */
|
||||
mailbox->TIR &= CAN_TI0R_TXRQ;
|
||||
|
||||
if (msg->id_type == CAN_STANDARD_IDENTIFIER) {
|
||||
mailbox->TIR |= (msg->id << CAN_TI0R_STID_Pos);
|
||||
if (frame->id_type == CAN_STANDARD_IDENTIFIER) {
|
||||
mailbox->TIR |= (frame->id << CAN_TI0R_STID_Pos);
|
||||
} else {
|
||||
mailbox->TIR |= (msg->id << CAN_TI0R_EXID_Pos)
|
||||
mailbox->TIR |= (frame->id << CAN_TI0R_EXID_Pos)
|
||||
| CAN_TI0R_IDE;
|
||||
}
|
||||
|
||||
if (msg->rtr == CAN_REMOTEREQUEST) {
|
||||
if (frame->rtr == CAN_REMOTEREQUEST) {
|
||||
mailbox->TIR |= CAN_TI1R_RTR;
|
||||
}
|
||||
|
||||
mailbox->TDTR = (mailbox->TDTR & ~CAN_TDT1R_DLC) |
|
||||
((msg->dlc & 0xF) << CAN_TDT1R_DLC_Pos);
|
||||
((frame->dlc & 0xF) << CAN_TDT1R_DLC_Pos);
|
||||
|
||||
mailbox->TDLR = msg->data_32[0];
|
||||
mailbox->TDHR = msg->data_32[1];
|
||||
mailbox->TDLR = frame->data_32[0];
|
||||
mailbox->TDHR = frame->data_32[1];
|
||||
|
||||
mailbox->TIR |= CAN_TI0R_TXRQ;
|
||||
k_mutex_unlock(&data->inst_mutex);
|
||||
|
|
|
@ -100,7 +100,7 @@ enum can_state can_stm32fd_get_state(const struct device *dev,
|
|||
|
||||
int can_stm32fd_send(const struct device *dev, const struct zcan_frame *frame,
|
||||
k_timeout_t timeout, can_tx_callback_t callback,
|
||||
void *callback_arg)
|
||||
void *user_data)
|
||||
{
|
||||
const struct can_stm32fd_config *cfg = DEV_CFG(dev);
|
||||
const struct can_mcan_config *mcan_cfg = &cfg->mcan_cfg;
|
||||
|
@ -108,7 +108,7 @@ int can_stm32fd_send(const struct device *dev, const struct zcan_frame *frame,
|
|||
struct can_mcan_msg_sram *msg_ram = cfg->msg_sram;
|
||||
|
||||
return can_mcan_send(mcan_cfg, mcan_data, msg_ram, frame, timeout,
|
||||
callback, callback_arg);
|
||||
callback, user_data);
|
||||
}
|
||||
|
||||
int can_stm32fd_attach_isr(const struct device *dev, can_rx_callback_t isr,
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
#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,
|
||||
static inline uint8_t can_utils_filter_match(const struct zcan_frame *frame,
|
||||
struct zcan_filter *filter)
|
||||
{
|
||||
if (msg->id_type != filter->id_type) {
|
||||
if (frame->id_type != filter->id_type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((msg->rtr ^ filter->rtr) & filter->rtr_mask) {
|
||||
if ((frame->rtr ^ filter->rtr) & filter->rtr_mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((msg->id ^ filter->id) & filter->id_mask) {
|
||||
if ((frame->id ^ filter->id) & filter->id_mask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -123,18 +123,18 @@ static inline void rx_thread(void *ctx, void *unused1, void *unused2)
|
|||
{
|
||||
struct socket_can_context *socket_context = ctx;
|
||||
struct net_pkt *pkt;
|
||||
struct zcan_frame msg;
|
||||
struct zcan_frame frame;
|
||||
int ret;
|
||||
|
||||
ARG_UNUSED(unused1);
|
||||
ARG_UNUSED(unused2);
|
||||
|
||||
while (1) {
|
||||
k_msgq_get((struct k_msgq *)socket_context->msgq, &msg,
|
||||
k_msgq_get((struct k_msgq *)socket_context->msgq, &frame,
|
||||
K_FOREVER);
|
||||
|
||||
pkt = net_pkt_rx_alloc_with_buffer(socket_context->iface,
|
||||
sizeof(msg),
|
||||
sizeof(frame),
|
||||
AF_CAN, 0,
|
||||
BUF_ALLOC_TIMEOUT);
|
||||
if (!pkt) {
|
||||
|
@ -142,7 +142,7 @@ static inline void rx_thread(void *ctx, void *unused1, void *unused2)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (net_pkt_write(pkt, (void *)&msg, sizeof(msg))) {
|
||||
if (net_pkt_write(pkt, (void *)&frame, sizeof(frame))) {
|
||||
LOG_ERR("Failed to append RX data");
|
||||
net_pkt_unref(pkt);
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue