Hello all,
we are doing some CANopen stuff with SocketCAN again and I have
some questions / feature requests here.
First the background to our use case:
We have CANopen Client SDO (CSDO) functionality, which, from
the CAN Layer 2 point of view, is nothing more than sending
some CAN message (request) over CAN and waiting on the response.
So normally we send one message and wait for reception of the
message. The response shall arrive in specified time. If no
response message is received, the timeout condition shall be
signaled.
So the question now is: when is the right moment to start CSDO
timeout timer? Here we have few approaches:
1) Start the timeout timer at the moment we write request message
to the socket.
This simple approach have huge disadvantage - the moment of writing
CAN message to the socket is far from being the moment the recipient
will get it. So if doing like that, we start our timeout timer
before request message has achieve to the CAN bus. On heavy loaded
systems, with bigger CAN interface Tx queue length on sender side
and short timeout times, this can lead to CSDO signaling timeout
condition before the request CAN message even arrived the CAN bus!
The SocketCAN framework has mechanism to improve the situation -
this is the self-reception mechanism.
2) So the better scenario may be to configure option
CAN_RAW_RECV_OWN_MSGS for the socket, which is used for sending the
CSDO request. The timeout countdown is than started on the self-
reception of the CSDO request. We can even use the timestamp of the
message for adjusting the timeout to be more precise (let call this
solution 2b).
The problem with self-reception however is that we cannot distinguish
on reception between messages "truly" received from other CAN nodes
and messages, which are sent by ourselves. Here will be nice to have
some per-message-self-reception-flag, which will immediately signal if
the received message is self-reception message.
Another additional nice feature helping on this issue may be marking
the CAN message with some value similar to "--set-mark" used in
iptables to mark packets.
Can you still follow me? Because I have to commit, the solution based
On currently implemented and available self-reception is still not
perfect. The self-reception message is put to the Rx queue at the
moment we put Tx message to the CAN Tx buffer (passive interfaces)
or transmit queue of the active CAN interface (that is what I see for
SJA1000). This is still not the moment, when the CAN message is going
on the bus! Here is the figure to illustrate that (at least how I
understand the current implementation):
socket
write
|
(1)
|
TxQueue --********-----------------
|
(2a)
|
CAN buff ---------********----------
| |
| (3)
| |
CANbus --------------***-----------
|
RxQueue ----------*************-----
|
(2)
|
socket
read
(1) - moment we write CAN message to socket
(2) - moment we read written message over self-reception mechanism
(2a) - moment the self-reception message is looped back to Rx queue
(3) - Tx interrupt of the CAN controller, the moment when CAN message
is actually sent. Correct start point for CSDO timeout countdown.
So, for getting the really correct Tx time stamp, the self reception
message shall be written back to Rx queue and "labeled" with
timestamp at the moment it really sent on the CAN, means in Tx
interrupt:
socket
write
|
(1)
|
TxQueue --********--------------------
|
(2a)
|
CAN buff ---------********-------------
| |
| (3)
| |
CANbus --------------***--------------
|
RxQueue -----------------*********-----
|
(2)
|
socket
read
If the self reception message is looped back to Rx queue in Tx
interrupt (3) end becomes time stamp exactly at this moment - when we
are getting the correct starting point for our timeout countdown. And
important issue - if we are using active CAN interface (the one with
own microcontroller), the timestamp shall be generated by
microcontroller and passed to SocketCAN driver.
<-------------------------------------------------------------------->
So, to sum that much stuff up:
A) The proposal to extend CAN message with self reception flag. The
self-received messages will have that flag set. One of the 4 unused
bits of the can_frame.can_dlc may be e.g. used for that.
B) Is it possible to label CAN packets in the similar way as done by
"--set-mark" in iptables?
C) The looping back of self reception messages shall be done in CAN
Tx interrupt and not in the ".ndo_start_xmit" .
D) Do we still need extra ioctl call to get the Rx message timestamp?
I remember the discussion about the possibility to pass timestamp
with the message itself about two years ago.
Regards and RFC,
Vladislav
Mit freundlichen Grüßen / Kind regards,
Dipl.-Ing. Vladislav Gribov MSc
Development
--------------------------------------------
IXXAT Automation GmbH
Leibnizstr. 15, 88250 Weingarten, Germany
Phone +49-751-56146-0
Direct +49-751-56146-162
Fax +49-751-56146-29
mailto:[email protected]
http://www.ixxat.de
--------------------------------------------
PRIVILEGED AND CONFIDENTIAL.
Any unauthorized use or disclosure
is strictly prohibited.
--------------------------------------------
Sitz der Gesellschaft: Weingarten
Handelsregister Ulm HRB 551905
Geschäftsführer:
Dipl.-Ing. Christian Schlegel,
Dipl.-Ing. Werner Sauter
--------------------------------------------
_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core