SocketCAN CAN Driver Interface under Linux



Similar documents
UART-based LIN-bus Support for Linux with SocketCAN Interface

Hopping On the CAN Bus

Introduction to NetGUI

2.1 CAN Bit Structure The Nominal Bit Rate of the network is uniform throughout the network and is given by:

Local Interconnect Network Training. Local Interconnect Network Training. Overview

1. Abstract Introduction Nomenclature CAN Basics The CAN Peripheral CAN Communication Levels...

Distributed Real-Time Systems (TI-DRTS) Track 2. CAN-BUS Introduction. Version Ref. VECTOR application note & Motorola note

Welcome to the Introduction to Controller Area Network web seminar My name is William Stuart, and I am a Applications Engineer for the Automotive

Network Diagnostic Tools. Jijesh Kalliyat Sr.Technical Account Manager, Red Hat 15th Nov 2014

Tutorial.

This howto is also a bit old now. But I thought of uploading it in the howtos section, as it still works.

Elettronica dei Sistemi Digitali Costantino Giaconia SERIAL I/O COMMON PROTOCOLS

Setting Up A High-Availability Load Balancer (With Failover and Session Support) With Perlbal/Heartbeat On Debian Etch

Understanding SAE J1939. by Simma Software, Inc.

CAN Specification 2.0, Part B page 1 PART B. CAN in Automation, Am Weichselgarten 26, D Erlangen

Bridgewalling - Using Netfilter in Bridge Mode

Comparison of FlexRay and CAN-bus for Real-Time Communication

CANnes PC CAN Interface Manual

Virtual Systems with qemu

Section 34. Controller Area Network (CAN)

Operating Systems Design 16. Networking: Sockets

The POSIX Socket API

TD-03011E. Identifier Usage in CANopen Networks

Virtual KNX/EIB devices in IP networks

VLAN for DekTec Network Adapters

LIN (Local Interconnect Network):

PCAN-USB CAN Interface for USB. User Manual. Document version ( )

Removing The Linux Routing Cache

3. The Domain Name Service

DeviceNet Communication Manual

! encor en etworks TM

How To Install Openstack On Ubuntu (Amd64)

Software User Guide UG-461

Implementing MOD bus and CAN bus Protocol Conversion Interface

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

Vorlesung Kommunikationsnetze Fieldbus Systems

netkit lab single-host Università degli Studi Roma Tre Dipartimento di Informatica e Automazione Computer Networks Research Group

ELEN 602: Computer Communications and Networking. Socket Programming Basics

Access Control: Firewalls (1)

Revision: 1.0 PROGRAMMER S GUIDE Date: Jul 1, 10. CrossCore XA. Programmer's guide.

PA-MC-T3 Multi-Channel T3 Synchronous Serial Port Adapter Enhancement

Networks. Inter-process Communication. Pipes. Inter-process Communication

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

CSCI 362 Computer and Network Security

Chapter 10 Case Study 1: LINUX

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

How Much Broadcast and Multicast Traffic Should I Allow in My Network?

Chapter 4. Medium Access Control. IN2P3 Octobre 2002 Jean-Pierre Thomesse

Workshop on Scientific Applications for the Internet of Things (IoT) March

Automotive Ethernet Prototype and test development with CANoe/CANalyzer.Ethernet

Written by Saif ur Rab Monday, 07 December :19 - Last Updated Monday, 27 December :19

EE984 Laboratory Experiment 2: Protocol Analysis

Verifying Detection of Asset Tags in WLAN Controllers

Network Administration and Monitoring

Internet Packets. Forwarding Datagrams

ISO11783 a Standardized Tractor Implement Interface

Change Log. 2 per vices corporation

Understanding OpenFlow

PCAN-ISA. CAN Interface for ISA. User Manual

PCAN-PC Card CAN Interface for the PC Card Slot. User Manual. Document version ( )

>>> SOLUTIONS <<< c) The OSI Reference Model has two additional layers. Where are these layers in the stack and what services do they provide?

Module 15: Network Structures

Mobile IP Network Layer Lesson 02 TCP/IP Suite and IP Protocol

Jena er Antriebstechnik. GmbH. 1. Introduction. 2. Properties. 3. Hardware. 4. Baud Rates. Brief Instructions - CANopen Interface

Data Center Bridging Attributes. John Fastabend LAN Access Division, Intel Corp.

The Elements of GigE Vision

Computer Networks Network architecture

IP Address: the per-network unique identifier used to find you on a network

Technical Support Information Belkin internal use only

The installation of pylon for Linux is described in the INSTALL text document.

Operating System Concepts. Operating System 資 訊 工 程 學 系 袁 賢 銘 老 師

16-PORT POWER OVER ETHERNET WEB SMART SWITCH

R70 Ethernet to CAN interface Software reference manual (1.3 EN)

Internet Architecture and Philosophy

VM-Series Firewall Deployment Tech Note PAN-OS 5.0

Communication Controller with IP services for leased lines and wireless links Radio Activity S.r.l.

DATA SHEET. SJA1000 Stand-alone CAN controller INTEGRATED CIRCUITS

8B/10B Coding 64B/66B Coding

Trinity Feature: T1/E1 Configuration

How To Monitor And Test An Ethernet Network On A Computer Or Network Card

A way towards Lower Latency and Jitter

The OSI Model and the TCP/IP Protocol Suite PROTOCOL LAYERS. Hierarchy. Services THE OSI MODEL

Based on Computer Networking, 4 th Edition by Kurose and Ross

AND8365/D. 125 kbps with AMIS-4168x APPLICATION NOTE

WAN Data Link Protocols

BASIC TCP/IP NETWORKING

Easy Setup Guide 1&1 CLOUD SERVER. Creating Backups. for Linux

Linux TCP/IP Network Management

Chapter 14: Distributed Operating Systems

MOST PCI Tool Kit. Overview. Ordering Information. Experience the Versatile MOST PC Interfaces.

A Design of Video Acquisition and Transmission Based on ARM. Ziqiang Hao a, Hongzuo Li b

MIMOTEC GigaLink AC. User Manual. Version 1.5 (8 January 2014) MIMOTEC, Norway & Sweden

PCAN-B10011S Bus Converter High-speed CAN to Truck Trailer CAN. User Manual. Document version ( )

Modicon Modbus Protocol Reference Guide. PI MBUS 300 Rev. J

Positioning Controller

This chapter discusses Synchronous Data Link Control (SDLC) protocols that you can configure on a BANDIT device s ports. See the following sections:

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

Performance and Recommended Use of AB545A 4-Port Gigabit Ethernet Cards

Transcription:

SocketCAN CAN Driver Interface under Linux Daniel Krüger daniel.krueger@systec-electronic.com SYS TEC electronic GmbH www.systec-electronic.com Version 3/19/2012

What is CAN? CAN = Controller Area Network Developed by Bosch (starting in 1983) Multi master network Short broadcast messages (up to 8 Byte) Bit rate: up to 1 MBit/s Network length up to 5 km (depending on the used bit rate) Powerful error detection mechanism minimum error rate of 4,7*10-11

CAN Standard Frame Format Dominant bit: logical 0 Recessive bit: logical 1 Lowest message identifier wins bus arbitration Message identifier: no unique node-id

SocketCAN SocketCAN is the framework for CAN under Linux Replaces plenty of vendor-specific CAN APIs CAN drivers are network drivers Applications receive and transmit CAN messages via BSD Socket API Configuration of CAN interfaces: via netlink protocol Mainline since Linux 2.6.25

SocketCAN linux/can.h struct can_frame { u32 can_id; /* 29 bit CAN_ID + flags */ u8 can_dlc; /* data length code: 0.. 8 */ u8 data[8]; }; #define CAN_EFF_FLAG 0x80000000U /* extended frame format */ #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ #define CAN_ERR_FLAG 0x20000000U /* error frame */ linux/can/...

Setup CAN channel Configure bit rate: $ ip link set can0 type can bitrate 125000 Set interface up and running: $ ifconfig can0 up Common pitfall: Standard distro kernels do not enable CONFIG_CAN_CALC_BITTIMING Bitrate setting $ ip link set can0 type can bitrate 125000

SocketCAN initialization int isock; struct sockaddr_can addr; isock = socket(pf_can, SOCK_RAW, CAN_RAW); addr.can_family = AF_CAN; addr.can_ifindex = if_nametoindex("can0"); bind(isock, (struct sockaddr *)&addr, sizeof(addr);

Send CAN message struct can_frame frame; frame.can_id = 0x123; frame.can_dlc = 1; frame.data[0] = 0xAB; nbytes = write(isock, &frame, sizeof(frame));

Receive CAN message struct can_frame frame; nbytes = read(isock, &frame, sizeof(frame)); if (nbytes > 0) { printf( ID=0x%X DLC=%d data[0]=0x%x\n, frame.can_id, frame.can_dlc, frame.data[0]); }

CAN error handling frame.can_id & CAN_ERR_FLAG frame.can_id & CAN_ERR_BUSOFF frame.can_id & CAN_ERR_ACK frame.can_id & CAN_ERR_RESTARTED frame.can_id & CAN_ERR_CRTL frame.data[1] & (CAN_ERR_CRTL_RX_WARNING CAN_ERR_CRTL_TX_WARNING) frame.data[1] & (CAN_ERR_CRTL_RX_PASSIVE CAN_ERR_CRTL_TX_PASSIVE) frame.data[1] & (CAN_ERR_CRTL_RX_OVERFLOW CAN_ERR_CRTL_TX_OVERFLOW) frame.can_id & CAN_ERR_PROT

CAN bus-off CAN controller enters bus-off state, when internal error counters reach a limit, e.g. in case of short-circuit between CAN_H, CAN_L Live demo, $ ip -det -stat link show can0 Recover from bus-off: $ ip link set can0 type can restart

Diagnostics $ ip -det -stat link show can0 9: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10 link/can 00:02:48:a2:03:00 brd 00:00:00:00:00:00 can state ERROR-ACTIVE restart-ms 0 bitrate 1000000 sample-point 0.750 tq 62 prop-seg 5 phase-seg1 6 phase-seg2 4 sjw 1 systec_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..255 brp-inc 1 clock 48000000 re-started bus-errors arbit-lost error-warn error-pass bus-off 0 0 0 0 0 0 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0

CAN utilities Source: https://gitorious.org/linux-can/can-utils $ git clone git://gitorious.org/linuxcan/can-utils.git $./candump can0 can0 4A2 [4] 27 96 C1 6C can0 151 [8] ED 85 FA 65 0D EB C2 4A can0 123 [2] AB CD $./cangen can0 $./cansend can0 123#abcd

Untouched subjects Higher layer protocols: CANopen, J1939, DeviceNet Extended frame format (29 bit CAN identifier) CAN message filtering Bit rate calculation Error handling: CAN error frames, bus-off recovery CAN driver structure

Conclusion SocketCAN Uniform and well-defined CAN framework for Linux CAN Flexible Powerful Cost-effective Future: CAN with Flexible Data-Rate (CAN FD) Higher bit rates Longer data fields (more than 8 Byte) Bus arbitration is identical to classic CAN First CAN FD controllers expected at end of 2012

References Specification: CAN 2.0 (by Bosch in 1991) Standards: ISO 11898-1:2003, ISO 11898-2:2003 SocketCAN: https://gitorious.org/linux-can/ CAN FD: http://www.boschsemiconductors.de/media/pdf/canliteratur/can_fd.pdf

Thank you for your attention