測試can需要ip,can-utils和libsocketcan庫.
通過ip工具配置can,如速率,啟用和禁用can等.不能用buildroot編譯出來的ip,需要重新編譯.
1. 編譯ip:
ip原始碼
1>. 修改makefile
destdir=/home/tom/myd-xc7z010/usr/ 修改安裝目錄
#dbm_include:=$(rootdir)/usr/include 遮蔽屏這行
cc = arm-xilinx-linux-gnueabi-gcc 使用交叉編譯器編譯
2>. 執行ip原始碼目錄下的build.sh編譯, build.sh內容:
#!/bin/sh
# create by myir tom 2015-01-28
# put this file under the ip source root dir
cp misc/makefile
sed '/^targets/s@arpd@@g' misc/makefile.orig > misc/makefile
export gnueabi=arm-xilinx-linux-gnueabi
export cc=$gnueabi-gcc
export ld=$gnueabi-ld
export nm=$gnueabi-nm
export ar=$gnueabi-ar
export ranlib=$gnueabi-ranlib
export cxx=$gnueabi-c++
export prefix=$filesys_path/usr
export cross_compile_prefix=$prefix
export path=$tool_chain_path/bin:$path
export dbm_include=/usr/include
export includes=/usr/include
export destdir=$prefix/
./configure --host=arm-xilinx-linux-gnueabi --prefix=$prefix --enable-debug
make
sudo make install
3>. 將ip工具copy到檔案系統下
將/home/tom/myd-xc7z010/usr/sbin/ip copy到嵌入式檔案系統目錄/usr/sbin下,還需要把buildroot自帶的ip(在/sbin目錄下)重新命名為ip_buildroot.
檢視ip版本和用法:
$ ./ip -v
ip utility, iproute2-ss110629
$ ./ip link help
usage: ip link add link dev [ name ] name
[ txqueuelen packets ]
[ address lladdr ]
[ broadcast lladdr ]
[ mtu mtu ]
type type [ args ]
ip link delete dev type type [ args ]
ip link set [ ]
[ arp ]
[ dynamic ]
[ multicast ]
[ allmulticast ]
[ promisc ]
[ trailers ]
[ txqueuelen packets ]
[ name newname ]
[ address lladdr ]
[ broadcast lladdr ]
[ mtu mtu ]
[ netns pid ]
[ alias name ]
[ vf num [ mac lladdr ]
[ vlan vlanid [ qos vlan-qos ] ]
[ rate txrate ] ]
[ master device ]
[ nomaster ]
ip link show [ device | group group ]
type :=
2. can-utils和libsocketcan可以使用buildroot編譯
target packages > libraries > networking選上
[*] libsocketcan
[*] can-utils
3. 測試
can介面需要在down狀態下才能設定
1>. 檢視can介面狀態
down下的狀態
# ip link set can0 down
# ip -details link show can0
2: can0: mtu 16 qdisc pfifo_fast state down qlen 10
link/can
can state stopped (berr-counter tx 0 rx 0) restart-ms 0
bitrate 49999 sample-point 0.875
tq 2500 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
xilinx_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1
clock 99999999
loopback狀態
# ip link set can0 type can bitrate 50000 loopback on
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip -details link show can0
2: can0: mtu 16 qdisc pfifo_fast state down qlen 10
link/can
can state stopped (berr-counter tx 0 rx 0) restart-ms 0
bitrate 49999 sample-point 0.875
tq 2500 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
xilinx_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1
clock 99999999
up下的狀態
# ip link set can0 down
# ip link set can0 type can bitrate 50000 loopback off
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip link set can0 up
# ip -details link show can0
2: can0: mtu 16 qdisc pfifo_fast state unknown qlen 10
link/can
can state error-active (berr-counter tx 0 rx 0) restart-ms 0
bitrate 49999 sample-point 0.875
tq 2500 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
xilinx_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1
clock 99999999
2>. 使用loopback模式測試:
使用loopback模式可測試本機的can驅動是否正常工作.
# ip link set can0 down
# ip link set can0 type can bitrate 50000 loopback on
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip link set can0 up
# candump can0 &
# cansend can0 123#11223344556677
# can0 123 [7] 11 22 33 44 55 66 77
can0 123 [7] 11 22 33 44 55 66 77
3>. 將兩塊板的can介面接起來,canh對canh, canl對canl,一邊傳送,另一邊接收,測試之前速率要設定好,且can介面已經up.
#candump can0 開發板1執行接收命令
#cansend can0 123#11223344556677 開發板2傳送資料
4> 關於can工具的使用(cansend等),參考can原始碼目錄下的lib.h檔案, 裡邊講得很清楚
Linux驅動 LED驅動測試
環境 主機 fedora12 目標板 mini6410 目標板linux核心版本 2.6.38 實現功能 驅動目標板4個led.說明 led與6410引腳對應連線 led1 gpk4 led2 gpk5 led3 gpk6 led4 gpk7 驅動源 led driver.c cpp view pl...
Linux下 sys class gpio驅動除錯
在核心初始化階段,將自動呼叫gpioilib sysfs init 在 sys class中建立gpio類,用於統一管理除錯gpio。export unexport屬性為gpio class成員,在註冊gpio類時,將會在 sys class gpio 目錄下建立export和unexport屬性檔...
Linux驅動 核心延時測試
linux驅動 核心延時測試 環境 主機 fedora12 目標板 mini6410 目標板linux核心版本 2.6.38 實現功能 延遲2s 方法1 利用系統全域性變數jiffies jiffies記錄系統節拍,每一次節拍,核心時鐘中斷函式會將jiffies加1.hz在arm中為100,表示1s...