- Welcome
- Getting Started With the NVIDIA DriveWorks SDK
- Modules
- Samples
- Tools
- Tutorials
- SDK Porting Guide
- DriveWorks API
- More
Initialization of the CAN bus sensor is achieved as follows:
The dwSensorParams.protocol
expects one of the following can interfaces:
can.socket
interface for system CAN bus.can.aurix
interface for CAN over Aurix.can.virtual
interface for reading CAN data from binary logs.The dwSensorParams.parameters
accepts the following parameters:
filter=id:mask[+id:mask]
:
filter
is a string of +
seperated filtersid
is a hex valuemask
is a hex valueExample: filter=123:FFF+60A:FFF
See the Setting message filters section to see how these values are used.
can.socket
:device=can0[,fifo-size=1024]
device
CAN device interface, usually canx, x starting from 0ifconfig
to list available CAN interfacespidin a | grep nvcan
to list available CAN interfacesfifo-size
size of internal buffer, in number of dwCANMessage
stored.discard-threshold
the timestamp of CAN data who is older than current timestamp by threshold will be discarded.read-number
data size to be read from driver buffer in one syscall, default number is 256do-not-send
disables send functionality when set to true
.can.aurix
in driveworks 3.5 and above (Aurix version 4.0 and above):ip=10.0.0.1,bus={a,b,c,d,e,f}[,aport=50000,bport=60395],[inIDMap=1:0x106+2:0x206][6,outIDMap=0x105:17+0x205:18][,fifo-size=1024]
ip
IP of Aurix (Drive AGX: 10.42.0.146
).aport
port on which CAN messages are sent to Aurix.bport
port on which CAN messages are received from Aurix.fifo-size
see above.inIDMap
a mapping of PDU ID to CAN ID in the format pduID:canID seperated by '+'. This should match the security model compiled onto the Aurix. ID values in decimal or hex format with leading 0x. Messages recieved from Aurix with pduID will be mapped to matched canID.outIDMap
a mapping of CAN ID to PDU ID in the format canID:pduUD seperated by '+'. This should match the security model compiled onto the Aurix. ID values in decimal or hex format with leading 0x. Messages with canID will be send to Aurix mapped to pduID.Note: Hardware timestamping is not available with Aurix version 4.0 and above.
can.aurix
in driveworks 3.0 and below (Aurix version 3.X and below)ip=10.42.0.146,bus={a,b,c,d,e,f}[,aport=50000,bport=60395],[config-file=/path/to/EasyCanConfigFile.conf][,fifo-size=1024]
ip
IP of Aurix (Drive AGX: 10.42.0.146
).aport
port on which CAN messages are sent to Aurix.bport
port on which CAN messages are received from Aurix.fifo-size
see above.bus
EasyCAN bus.config-file
path to EasyCanConfigFile.conf, when provided, configures Aurix EasyCAN message routing when starting sensor. An example is provided in the DriveWorks data folder, under /path/to/data/samples/sensors/can.can.simulator
:Identical parameters to can.socket
.
can.virtual
:file=/path/to/file.can[,create_seek,default_timeout_us,time-offset=0]
file
path to CAN bus recordingcreate_seek
create seek tabledefault_timeout_us
period after which sensor times outtime-offset
offset applied to CAN messages timestampsThe CAN buses are setup with CAN FD if supported. If not supported sending and receiving CAN FD messages will fail.
The CAN bus sensor can be started, stopped and released as follows:
CAN messages can be read from the bus as follows:
This will populate a dwCANMessage
structure with the next CAN message received on the bus, in this example waiting up to 10000us, or 10ms, for a message to arrive. Timeout can be set to DW_TIMEOUT_INFINITE
to indicate infinite waiting until new message arrives, or 0 to immediately return and only read messages already received. The dwCANMessage
structure can hold up to 64 bytes to accommodate CAN FD messages.
To only read messages available in the internal queue, without reading new messages on the CAN bus, the dwSensorCAN_popMessage()
method can be used. Together with dwSensorCAN_processRawData()
, raw binary CAN data can be read and parsed in dwCANMessage
format, see Reading CAN Messages from Raw Data (Binary).
CAN messages can be sent on the bus as follows:
This sends a message over the CAN bus within a specified timeout. A message is guaranteed to have been sent when this method returns DW_SUCCESS
. The method can block for up-to the specified amount of time if a bus is blocked or previous dwSensorCAN_readMessage()
operation has not yet finished.
If the msg.size
value is from 9 - 64, then the message will be sent as a CAN FD message.
CAN messages be filtered by ID as follows:
This function takes an array of IDs and an array of masks to setup filters. Once the filters are set, only messages with IDs matching the filters will be read. Each call to the above will reset previously set filters. To reset all filtering, call the above with 0 as number of filters.
Internally, only messages that meet the following condition for at least one filter are read:
Masks are optional; when passing NULL
, a default mask of 1FFFFFFF
is used.
The dwSensorCAN_setUseHwTimestamps()
function allows the user to enable or disable hardware timestamping of messages on compatible CAN Bus devices. By default, hardware timestamping is enabled if available, but can be turned off if the default behavior is not working properly with the current hardware stack.
The dwSensorCAN_readMessage()
function reads the next available CAN message with a given timeout. The function call is blocking, until a CAN message is available or the timeout is exceeded. Filters can be set with dwSensorCAN_setMessageFilter()
so that only specific messages are read from the bus. Messages can be sent with dwSensorCAN_sendMessage()
.
The dwCANMessage
structure holds a CAN message, consisting of a timestamp, an ID, message data (payload) and size. The CAN bus module supports the extended CAN frame format.
As of software version 3.01.3, the Aurix is configured to cyclically send CAN messages with IDs 0x10f to 0x114 on buses A through F. These message IDs should be considered as reserved as this behavior cannot be disabled at run-time. Please refer to the Elektrobit Aurix Software User Guide for more details.
As of software version 3.05.4, the Aurix can send CAN FD messages with BRS. Note that this is configured to use timing sample points of 0.8. Devices on the network must be setup using this timing or bus errors can occur. Please refer to Drive Developer Guide, Flashing Aurix documentation for more information.
A message routing configuration has to be sent to Aurix prior to running the application in order to receive, over Aurix, select CAN messages on the desired Xavier device(s). This can be done by providing an EasyCAN configuration file when creating the CAN bus sensor for can.aurix
protocol, by specifying the path to an Aurix EasyCAN configuration file with the config-file
argument. The configuration file is a text file containing the following structures, one per CAN message to be routed:
Where:
MsgId
is the message ID to be routed, in hexadecimalCtrlId
is the EasyCAN bus on which the message is received, in range EC_CAN_BUS_A
to EC_CAN_BUS_F
FrmTyp
is the CAN ID type selector, either CAN_ID_STANDARD
or CAN_ID_EXTENDED
DestId
is the destination device, either TEGRA_DEVICE_A
or TEGRA_DEVICE_B
DestSwc
is set to SWC_ID_CANDATA
for CAN dataEach structure, corresponding to one CAN message to be routed, is separated by an empty line from the next. An example file is provided in the DriveWorks data folder, under /path/to/data/samples/sensors/can.
Please refer to the Elektrobit Aurix Software User Guide provided as part of PDK documentation for more information on the EasyCAN message routing feature and on how to configure Aurix.
The following code shows the general structure of a program setting up CAN message filters and receiving/sending messages on the bus. Only messages with IDs 0x100
-0x1FF
and 0x6AB
will be read.
For more information, refer to CAN Message Logger Sample.