SocketCAN, The Official CAN API of The Linux Kernel
SocketCAN, The Official CAN API of The Linux Kernel
CAN in Automation
05-17
iCC 2012
CAN in Automation
iCC 2012
CAN in Automation
05-19
iCC 2012
CAN in Automation
05-20
struct
sk_buff
The generic data type in the Linux
kernel to describe a socket buffer in
the networking stack. It includes meta
data and the payload.
struct
can_frame
The SocketCAN abstraction of a CAN
frame, consists of the CAN id, the
data length code (dlc) and the eight
data bytes.
First, the driver allocates a generic buffer
with the alloc_can_skb() function, which
marks the buffer as a CAN frame and lets
cf point to the struct can_frame within the
buffer's payload. In this example a hardware
dependent
helper
function
flexcan_read_fifo() is called to read the
CAN frame from the controller's FIFO and
store it in the can_frame and thus into the
generic buffer. In a NAPI capable driver like
this the netif_receive_skb() function is used
to push the CAN frame into the packet
scheduler. From an IRQ handler the buffer is
passed via the netif_rx() function instead.
CAN frame transmission
The transmission of a CAN frame is
originated in the local system, usually in the
userspace. For example: an application
wants to send raw CAN frames (abstracted
by the struct can_frame), a CAN_RAW
socket is opened and a write() or send()
system call is issued. The CAN_RAW
protocol copies the CAN frame into the
kernel space and passes it to the packet
scheduler. During the run of the packet
scheduler in a soft IRQ context the driver's
start_xmit() function will be called to
activate the transmission of the CAN frame.
The above outlined sequence is missing the
flow control. An application might generate
CAN frames faster than the CAN hardware is
able to send. The CAN networking
subsystem implements flow control in the
layers above the packet scheduler. The
iCC 2012
CAN in Automation
}
return IRQ_HANDLED;
}
netif_stop_queue(dev);
can_put_echo_skb(skb, dev, 0);
flexcan_write_frame(dev, cfe);
return NETDEV_TX_OK;
}
[...]
};
iCC 2012
CAN in Automation
Marc Kleine-Budde
Pengutronix e.K.
Peiner Strae 6-8
31137 Hildesheim
Phone: +49 51 21 / 20 69 17 - 0
Fax: +49 51 21 / 20 69 17 - 55 55
[email protected]
www.pengutronix.de/
return 0;
05-22