Lines Matching +full:timing +full:- +full:config +full:- +full:mask

4  * SPDX-License-Identifier: Apache-2.0
55 struct can_native_linux_data *data = dev->data; in dispatch_frame()
59 k_mutex_lock(&data->filter_mutex, K_FOREVER); in dispatch_frame()
61 for (int filter_id = 0; filter_id < ARRAY_SIZE(data->filters); filter_id++) { in dispatch_frame()
62 if (data->filters[filter_id].rx_cb == NULL) { in dispatch_frame()
66 if (!can_frame_matches_filter(frame, &data->filters[filter_id].filter)) { in dispatch_frame()
73 callback = data->filters[filter_id].rx_cb; in dispatch_frame()
74 callback(dev, &tmp_frame, data->filters[filter_id].cb_arg); in dispatch_frame()
77 k_mutex_unlock(&data->filter_mutex); in dispatch_frame()
83 struct can_native_linux_data *data = dev->data; in rx_thread()
95 while (linux_socketcan_poll_data(data->dev_fd) == 0) { in rx_thread()
96 count = linux_socketcan_read_data(data->dev_fd, (void *)(&sframe), in rx_thread()
99 data->tx_callback(dev, 0, data->tx_user_data); in rx_thread()
100 k_sem_give(&data->tx_idle); in rx_thread()
102 if ((data->common.mode & CAN_MODE_LOOPBACK) == 0U) { in rx_thread()
106 if ((count <= 0) || !data->common.started) { in rx_thread()
134 struct can_native_linux_data *data = dev->data; in can_native_linux_send()
138 int ret = -EIO; in can_native_linux_send()
141 frame->dlc, dev->name, frame->id, in can_native_linux_send()
142 (frame->flags & CAN_FRAME_IDE) != 0 ? "extended" : "standard", in can_native_linux_send()
143 (frame->flags & CAN_FRAME_RTR) != 0 ? ", RTR frame" : ""); in can_native_linux_send()
146 if ((frame->flags & ~(CAN_FRAME_IDE | CAN_FRAME_RTR | in can_native_linux_send()
148 LOG_ERR("unsupported CAN frame flags 0x%02x", frame->flags); in can_native_linux_send()
149 return -ENOTSUP; in can_native_linux_send()
152 if ((frame->flags & CAN_FRAME_FDF) != 0) { in can_native_linux_send()
153 if ((data->common.mode & CAN_MODE_FD) == 0U) { in can_native_linux_send()
154 return -ENOTSUP; in can_native_linux_send()
161 if ((frame->flags & ~(CAN_FRAME_IDE | CAN_FRAME_RTR)) != 0) { in can_native_linux_send()
162 LOG_ERR("unsupported CAN frame flags 0x%02x", frame->flags); in can_native_linux_send()
163 return -ENOTSUP; in can_native_linux_send()
167 if (frame->dlc > max_dlc) { in can_native_linux_send()
168 LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, max_dlc); in can_native_linux_send()
169 return -EINVAL; in can_native_linux_send()
172 if (data->dev_fd <= 0) { in can_native_linux_send()
173 LOG_ERR("No file descriptor: %d", data->dev_fd); in can_native_linux_send()
174 return -EIO; in can_native_linux_send()
177 if (!data->common.started) { in can_native_linux_send()
178 return -ENETDOWN; in can_native_linux_send()
183 if (k_sem_take(&data->tx_idle, timeout) != 0) { in can_native_linux_send()
184 return -EAGAIN; in can_native_linux_send()
187 data->tx_callback = callback; in can_native_linux_send()
188 data->tx_user_data = user_data; in can_native_linux_send()
190 ret = nsi_host_write(data->dev_fd, &sframe, mtu); in can_native_linux_send()
192 LOG_ERR("Cannot send CAN data len %d (%d)", sframe.len, -errno); in can_native_linux_send()
201 struct can_native_linux_data *data = dev->data; in can_native_linux_add_rx_filter()
203 int filter_id = -ENOSPC; in can_native_linux_add_rx_filter()
205 LOG_DBG("Setting filter ID: 0x%x, mask: 0x%x", filter->id, in can_native_linux_add_rx_filter()
206 filter->mask); in can_native_linux_add_rx_filter()
208 if ((filter->flags & ~(CAN_FILTER_IDE)) != 0) { in can_native_linux_add_rx_filter()
209 LOG_ERR("unsupported CAN filter flags 0x%02x", filter->flags); in can_native_linux_add_rx_filter()
210 return -ENOTSUP; in can_native_linux_add_rx_filter()
213 k_mutex_lock(&data->filter_mutex, K_FOREVER); in can_native_linux_add_rx_filter()
215 for (int i = 0; i < ARRAY_SIZE(data->filters); i++) { in can_native_linux_add_rx_filter()
216 if (data->filters[i].rx_cb == NULL) { in can_native_linux_add_rx_filter()
224 k_mutex_unlock(&data->filter_mutex); in can_native_linux_add_rx_filter()
228 filter_ctx = &data->filters[filter_id]; in can_native_linux_add_rx_filter()
229 filter_ctx->rx_cb = cb; in can_native_linux_add_rx_filter()
230 filter_ctx->cb_arg = cb_arg; in can_native_linux_add_rx_filter()
231 filter_ctx->filter = *filter; in can_native_linux_add_rx_filter()
233 k_mutex_unlock(&data->filter_mutex); in can_native_linux_add_rx_filter()
242 struct can_native_linux_data *data = dev->data; in can_native_linux_remove_rx_filter()
244 if (filter_id < 0 || filter_id >= ARRAY_SIZE(data->filters)) { in can_native_linux_remove_rx_filter()
249 k_mutex_lock(&data->filter_mutex, K_FOREVER); in can_native_linux_remove_rx_filter()
250 data->filters[filter_id].rx_cb = NULL; in can_native_linux_remove_rx_filter()
251 k_mutex_unlock(&data->filter_mutex); in can_native_linux_remove_rx_filter()
271 struct can_native_linux_data *data = dev->data; in can_native_linux_start()
273 if (data->common.started) { in can_native_linux_start()
274 return -EALREADY; in can_native_linux_start()
277 data->common.started = true; in can_native_linux_start()
284 struct can_native_linux_data *data = dev->data; in can_native_linux_stop()
286 if (!data->common.started) { in can_native_linux_stop()
287 return -EALREADY; in can_native_linux_stop()
290 data->common.started = false; in can_native_linux_stop()
297 struct can_native_linux_data *data = dev->data; in can_native_linux_set_mode()
303 return -ENOTSUP; in can_native_linux_set_mode()
308 return -ENOTSUP; in can_native_linux_set_mode()
312 if (data->common.started) { in can_native_linux_set_mode()
313 return -EBUSY; in can_native_linux_set_mode()
316 err = linux_socketcan_set_mode_fd(data->dev_fd, (mode & CAN_MODE_FD) != 0); in can_native_linux_set_mode()
319 return -EIO; in can_native_linux_set_mode()
322 data->common.mode = mode; in can_native_linux_set_mode()
327 static int can_native_linux_set_timing(const struct device *dev, const struct can_timing *timing) in can_native_linux_set_timing() argument
329 struct can_native_linux_data *data = dev->data; in can_native_linux_set_timing()
331 ARG_UNUSED(timing); in can_native_linux_set_timing()
333 if (data->common.started) { in can_native_linux_set_timing()
334 return -EBUSY; in can_native_linux_set_timing()
342 const struct can_timing *timing) in can_native_linux_set_timing_data() argument
344 struct can_native_linux_data *data = dev->data; in can_native_linux_set_timing_data()
346 ARG_UNUSED(timing); in can_native_linux_set_timing_data()
348 if (data->common.started) { in can_native_linux_set_timing_data()
349 return -EBUSY; in can_native_linux_set_timing_data()
359 struct can_native_linux_data *data = dev->data; in can_native_linux_get_state()
362 if (!data->common.started) { in can_native_linux_get_state()
371 err_cnt->tx_err_cnt = 0; in can_native_linux_get_state()
372 err_cnt->rx_err_cnt = 0; in can_native_linux_get_state()
450 const struct can_native_linux_config *cfg = dev->config; in can_native_linux_init()
451 struct can_native_linux_data *data = dev->data; in can_native_linux_init()
454 k_mutex_init(&data->filter_mutex); in can_native_linux_init()
455 k_sem_init(&data->tx_idle, 1, 1); in can_native_linux_init()
460 if_name = cfg->if_name; in can_native_linux_init()
464 data->dev_fd = linux_socketcan_iface_open(if_name); in can_native_linux_init()
465 if (data->dev_fd < 0) { in can_native_linux_init()
466 LOG_ERR("Cannot open %s (%d)", if_name, data->dev_fd); in can_native_linux_init()
467 return -ENODEV; in can_native_linux_init()
470 k_thread_create(&data->rx_thread, data->rx_thread_stack, in can_native_linux_init()
471 K_KERNEL_STACK_SIZEOF(data->rx_thread_stack), in can_native_linux_init()
476 LOG_DBG("Init of %s done", dev->name); in can_native_linux_init()
503 .option = "can-if", in DT_INST_FOREACH_STATUS_OKAY()