Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
canbus.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
10
11#ifndef ZEPHYR_INCLUDE_NET_CANBUS_H_
12#define ZEPHYR_INCLUDE_NET_CANBUS_H_
13
14#include <zephyr/types.h>
15#include <zephyr/net/net_ip.h>
16#include <zephyr/net/net_if.h>
18#include <zephyr/drivers/can.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
27__subsystem struct canbus_driver_api {
32 struct net_if_driver_api iface_api;
33
35 int (*send)(const struct device *dev, struct net_pkt *pkt);
36
38 void (*close)(const struct device *dev, int filter_id);
39
41 int (*setsockopt)(const struct device *dev, void *obj, int level,
42 int optname,
43 const void *optval, net_socklen_t optlen);
44
46 int (*getsockopt)(const struct device *dev, void *obj, int level,
47 int optname,
48 const void *optval, net_socklen_t *optlen);
49};
50
52
53DEVICE_API_EXTENDS(canbus, net_if, iface_api);
54
55struct z_net_canbus_context {
56 struct net_if *iface;
57};
58
59struct z_net_canbus_config {
60 const struct device *can_dev;
61};
62
63int z_net_canbus_init(const struct device *dev);
64
65extern const struct canbus_driver_api z_net_canbus_api;
66
67/*
68 * Network interface of a CAN controller, defined by CAN_DEVICE_DT_DEFINE() next to the
69 * controller's device so that only controllers with a driver in the build get one.
70 */
71#define Z_NET_CANBUS_DEVICE_DT_DEFINE(node_id) \
72 static struct z_net_canbus_context z_net_canbus_ctx_##node_id; \
73 static const struct z_net_canbus_config z_net_canbus_cfg_##node_id = { \
74 .can_dev = DEVICE_DT_GET(node_id), \
75 }; \
76 NET_DEVICE_INIT(net_canbus_##node_id, DEVICE_DT_NAME(node_id), z_net_canbus_init, NULL, \
77 &z_net_canbus_ctx_##node_id, &z_net_canbus_cfg_##node_id, \
78 CONFIG_NET_CANBUS_INIT_PRIORITY, &z_net_canbus_api, CANBUS_RAW_L2, \
79 NET_L2_GET_CTX_TYPE(CANBUS_RAW_L2), CAN_MTU);
80
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif /* ZEPHYR_INCLUDE_NET_CANBUS_H_ */
#define DEVICE_API_EXTENDS(_child, _parent, _member)
Declare that API class _child is an extension of device API class _parent.
Definition device.h:1470
Header file for Controller Area Network (CAN) controller driver API.
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
Public API for network interface.
IPv6 and IPv4 definitions.
SocketCAN definitions.
CAN L2 network driver API.
Definition canbus.h:27
int(* setsockopt)(const struct device *dev, void *obj, int level, int optname, const void *optval, net_socklen_t optlen)
Set socket CAN option.
Definition canbus.h:41
struct net_if_driver_api iface_api
The net_if_driver_api must be placed in first position in this struct so that we are compatible with ...
Definition canbus.h:32
void(* close)(const struct device *dev, int filter_id)
Close the related CAN socket.
Definition canbus.h:38
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a CAN packet by socket.
Definition canbus.h:35
int(* getsockopt)(const struct device *dev, void *obj, int level, int optname, const void *optval, net_socklen_t *optlen)
Get socket CAN option.
Definition canbus.h:46
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
Network Interface structure.
Definition net_if.h:875
Network packet.
Definition net_pkt.h:119