Template:AkDcanDriverUsage

= Driver Usage =

Quick Steps
Utilities required for DCAN driver usage are ip, canconfig, cansend, candump and cansequence. Details of these utilities are elaborated in CAN Utilities section

Steps for transmitting/receiving CAN packets


 * Set bit-timing

Set the bit-rate to 50Kbits/sec with triple sampling using the following command

$ ip link set can0 type can bitrate 50000 triple-sampling on

or

$ canconfig can0 bitrate 50000 ctrlmode triple-sampling on


 * Device bring up

Bring up the device using the command:

$ ip link set can0 up

or

$ canconfig can0 start


 * Transfer packets

Packet transmission can be achieve by using cansend and cansequence utilities.

a. Transmit 8 bytes with standard packet id number as 0x10 $ cansend can0 -i 0x10 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88

b. Transmit 8 bytes with extended packet id number as 0x800 $ cansend can0 -i 0x800 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 -e

c. Transmit 20 packets of 8 bytes each with same extended packet id number as 0xFFFFF $ cansend can0 -i 0xFFFFF 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 -e --loop=20

d. Transmit a sequence of numbers from 0x00-0xFF, till the buffer availability $ cansequence can0

e. Transmit a sequence of numbers from 0x00-0xFF and roll-back in a continuous loop $ cansequence can0 -p


 * Receive packets

Packet reception can be achieve by using candump utility

$ candump can0

Network up/down
$ ip link set can0 up
 * Bring up the device

or

$ canconfig can0 start

$ ip link set can0 down
 * Bring down the device

or

$ canconfig can0 stop

Set different Bitrate
For setting up the different bitrate form what was set before then follow these steps. In this example bitrate is setting it to 1MBPS

$ ip link set can0 down
 * Bring down the device if it was up

or

$ canconfig can0 stop

$ ip link set can0 type can bitrate 1000000 triple-sampling on
 * Set bitrate

or

$ canconfig can0 bitrate 1000000 ctrlmode triple-sampling on

$ ip link set can0 up
 * Bring up the device

or

$ canconfig can0 start

Test mode
To test the DCAN module then follow these steps

Loopback mode
For testing the module in loopback mode then use below steps

$ ip link set can0 down
 * Bring down the device if it was up

or

$ canconfig can0 stop

$ canconfig can0 bitrate 100000 ctrlmode triple-sampling on loopback on
 * Configure the loopback mode with triple sampling on and 100KBPS bitrate

$ ip link set can0 up
 * Bring up the device

or

$ canconfig can0 start

Silent mode
For testing the module in silent mode then use below steps

$ ip link set can0 down
 * Bring down the device if it was up

or

$ canconfig can0 stop

$ canconfig can0 bitrate 500000 ctrlmode triple-sampling on listen-only on
 * Configure the listen-only mode with triple sampling on and 500KBPS bitrate

$ ip link set can0 up
 * Bring up the device

or

$ canconfig can0 start

Statistics of CAN
Statistics of CAN device can be seen from these commands

$ ip -d -s link show can0

Below command also used to know the details $ cat /proc/net/can/stats

DCAN IP Error details
If the CAN bus is not properly connected or some hardware issues DCAN has the intelligence to generate an Error interrupt and corresponding error details on hardware registers.

In CAN terminology errors are divided into three categories


 * Error warning state, this state is reached if the error count of transmit or receive is more than 96.
 * Error passive state, this state is reached if the core still detecting more errors and error counter reaches 127 then bus will enter into
 * Bus off state, still seeing the problems then it will go to Bus off mode.

DCAN driver provides
For the above error state, driver will send the error frames to inform that there is error encountered. Frame details with respect to different states are listed here:

[8] 00 08 00 00 00 00 60 00 ID for error warning is 0x004 [8] represents 8 bytes have received 0x08 at 2nd byte represents type of error warning. 0x08 for transmission error warning, 0x04 for receive error warning frame 0x60 at 7th byte represent tx error count.
 * Error warning frame

[8] 00 10 00 00 00 00 00 64 ID for error passive frame is 0x004 [8] represents 8 bytes have received 0x10 at 2nd byte represents type of error passive. 0x10 for receive error passive, 0x20 for transmission error passive 0x64 at 8th byte represent rx error count.
 * Error passive frame

[8] 00 00 00 00 00 00 00 00 ID for bus-off state is 0x040
 * Buss off state

Error frames display with candump
candump has the capability to display the error frames along with data frames on the console. Some of the error frames details are mentioned in the previous section

$ candump can0 --error

Description
This template have DCAN driver usage details

Parameters
This template takes no parameters

Example
To use this template simply add the following line to your wiki page.

Here's how it will look in your wiki page: