original documentation and design document (pdf) - BESSY II

26
BESSY MultiCAN – EPICS goes CAN with Multiple Protocol Support 1 MultiCAN – EPICS goes CAN with Multiple Protocol Support Jens Bergl, Ralph Lange, Götz Pfeiffer BESSY GmbH Lentzeallee 100 14195 Berlin Germany

Transcript of original documentation and design document (pdf) - BESSY II

Page 1: original documentation and design document (pdf) - BESSY II

BESSY MultiCAN – EPICS goes CAN with Multiple Protocol Support 1

MultiCAN –EPICS goes CAN withMultiple Protocol Support

Jens Ber gl, Ralph Lang e, Götz Pf eiff erBESSY GmbHLentzeallee 10014195 BerlinGermany

Page 2: original documentation and design document (pdf) - BESSY II

2 MultiCAN – EPICS goes CAN with Multiple Protocol Support Document Revision: Draft

Page 3: original documentation and design document (pdf) - BESSY II

BESSY 3

Table of Contents

Chapter 1: MultiCAN Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5SCI — A Hardware Independent Data Link. . . . . . . . . . . . . . . . . . . . . . . . . . . . .5Design Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6Multiple Protocols. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7Informations for using MultiCAN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8

Chapter 2: Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9Common Lower (GPS) Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9LowCAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11HighCANal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19LowCANal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21

Chapter 3: GPS – Generic Protocol Support . . . . . . . . . . . . . . . . .23Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23Initialization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26

Chapter 4: EPICS Device Support. . . . . . . . . . . . . . . . . . . . . . . . . .27Usage of MultiCAN with EPICS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27Special Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30

Page 4: original documentation and design document (pdf) - BESSY II

4 Document Revision: Draft

Page 5: original documentation and design document (pdf) - BESSY II

BESSY 5

Chapter 1: MultiCAN Design

The basic design of a modular multi-protocol CAN integration into EPICS was firstpresented at the ICALEPCS’95 in Chicago[3].

Within the BESSY II control system the CAN field bus will serve a variety of tasks: Inaddition to the 'normal' device control it will interface underlying intelligentsubsystems (like measurement PCs, PLCs), can be used for downloadingconfiguration data and possibly object code to the embedded controllers, carries theID compensation data and can be used for synchronization of IOC tasks. Thesedifferent communication tasks require different protocols to be used in parallel on oneCAN segment.

The CAN interface has to be implemented on three platforms: The IOC (MotorolaMVME with VxWorks/EPICS and commercial 68000-based CAN cards), theembedded controller (i80386EX without OS with a single on-board CAN chip) and aPC used for measurement and debugging (80x86 using DOS and an AT bus CANcard).

SCI — A Hardware Independent Data Link

SCI, theSimple CAN Interface, is the specification of a library that embodies astandard for accessing CAN interface cards independent of the actual hardware[6].Programs that use this library to access the CAN field bus will be portable betweendifferent CAN cards and even different operating systems. SCI is intentionally keptsimple and it largely represents the data-link layer of the OSI model.

SCI is prepared to handle several CAN ports which are distinguished by port numbers.The ports may be realized on one or more interface cards, not necessarily from thesame vendor. Different interface cards may have to be accessed through differentdrivers, but these differences are hidden by SCI.

SCI is capable of multithreading. In order to facilitate this function, each thread thatopens the library is provided with a unique pointer. This pointer, which is a parameterfor all SCI functions, is used to distinguish different threads. The properties of a

Page 6: original documentation and design document (pdf) - BESSY II

6 Document Revision: Draft

COB1 — identifier, data length, timeout and type, where type can be one of read,write, remote-read and remote-write — are defined when it is initialized. SCI thenreturns a pointer to an internal structure that is allocated and initialized per object. Allother functions use this sci_object pointer as a handle to a certain object. Read andwrite functions exist in order to transfer data to and from CAN objects.

Reading can be done in three basically different ways:Immediate read gets whateverdata is stored on the CAN hardware for a certain object.Read with timeout gets newdata or — if there is no new data — waits for the COB to arrive. Install a callbackfunction that is called when new data arrives for an object is the asynchronous mode toretrieve data. On multitasking operating systems this callback is called from within asignal handler.

1. Communication Object, message with a unique tag.

Design Overview

The requirements of portability and reusability are fulfilled best by a layered interfacestructure. This allows the parallel use of different protocols through well-definedinterfaces into the protocol layer and collects the platform dependencies in anotherlayer. Thus the support for a protocol can be implemented fully independent fromhardware and OS properties. Figure1 on page7 shows the task level structure of theCAN interface in front of its layer structure.

Above the low level CAN library SCI is the GPS layer (Generic Protocol Support)hiding the Operating System and hardware dependencies. The tasks and functions inthis layer set up the data transfer between the CAN segments (through SCI) and aCOB oriented cache structure which is an interface to the next layer handling thedifferent protocols. This layer consists of a small set of functions for each protocol tobe run over the CAN bus. These functions include initialization, reading and writingdata in protocol specific format (the upper interface) as well as reading and writingdata in SCI conformal format (the lower interface).

EPICS device support writes and reads data to/from the cache using the upperinterface functions of the appropriate Protocol Function Set. For output records thewrite request is fed into a queue. The mCANWriter dequeues it, fetches the data usingthe lower interface of the protocol layer and calls SCI to send the message. If SCIrejects the message (there might be minimal delays between messages to be kept), theWriter puts it back into the protocol, where it gets buffered and is resent after the SCI-requested delay. For asynchronous record processing an EPICS callback may berequested. On an incoming message SCI calls the mCANReader task. ThemCANReader gets the COB, stores it through the appropriate protocol function andeventually requests an EPICS callback, which gets the data out of the protocol layerand moves it to the EPICS record. To minimize any mutual influences betweenprotocols there is a mCANReader task for every protocol in use (not shown in figure).A third task, mCANTimer, periodically checks the protocol’s status to detect timeoutscaused by failures of the CAN hardware or the peer CAN node.

Page 7: original documentation and design document (pdf) - BESSY II

BESSY 7

Multiple Pr otocols

It is intended to implement the following protocols (i.e., their Protocol Function Sets):

• LowCAL is a subset of the CAL (CAN Application Layer)[1] protocol defined byCiA1. CAL is a huge protocol suite defining an open CAN environment,including services for message transfer, network management, on-line addressdistribution as well as remote configuration of certain layer parameters. Ourlightweight LowCAL subset defines only the message specification as well asthe encoding rules for the variable types used in BESSYII device control. Thiswill be the protocol used for communication with the embedded controllers.

• CANal (CAN arbitrary length) specifies two protocol variants for sending dataof arbitrary length such as tables, configuration data or object code: A multicasttransfer which is not confirmed (LowCANal) and a point-to-point transferwhich is confirmed and allows partial re-transfer of data (HighCANal).

1. CAN in Automation International Users and Manufacturers Group e.V.

Figure 1: Overview of the MultiCAN Concept

...T3

Entity 1

...

BufferMessage

Dev

ice

Sup

port

Driv

er S

uppo

rtD

river

SCI (Simple CAN Interface)

<P1>_Put<P1>_Get<P1>_Reject

<P1>_Read<P1>_Write

sends

Record Processingwrites data

andenqueueshandle tomessage

cache entry

messages aredelayed to limit

the accessfrequency

rejected

Callback Processingreads data

Send

mCANReader

Queue

Entity n

checks for timeouts

mCANTimer

callbackEPICS

eventuallyrequest

stores dataand eventuallyrequests EPICS callback

Entity 3Entity 2

...321

dequeues,gets data

ProtocolFunctionSet 1

DelayListT1

T2

SC

IG

PS

Lay

erP

roto

col L

ayer

EPICS Record

gets data

mCANWriter

Page 8: original documentation and design document (pdf) - BESSY II

8 Document Revision: Draft

Since the Protocol Function Sets are almost symmetrical and platform independent,the implementation of a new protocol is cut down to implementing its set of functions,which should be running on all target systems (i.e., the IOC as well as the embeddedcontroller or PC).

Inf ormations for using MultiCAN

Initialization

The use of the several protocols united in MultiCAN requires

• a configuration fileconfig.<machine-name>

• the initialization of MultiCAN with� � � � � � � � � � � � � � � � � � � � �• the initialization of GPS described in “Initialization” on page26

• the initialization of the protocols1 as described in “Interface” on page15

The configuration fileconfig.<machine-name>has the following format:� � � � � � � � � � � � � !� " � � � ! � # $ � � % � � !These supported bitrates are :

• 1000 kbit

• 500 kbit

• 250 kbit

• 66 kbit

1. At the moment only LowCAL is implemented

The use of MultiCAN by applications beside EPICS

If MultiCAN is used by EPICS, the whole initialization process is closely connectedwith EPICS. The way for other applications to use MultiCAN is the function

� � % � � % � � % � & � � � ' � � � � � � � � � � � � � � � � � % � � ( � � � � � � � � � � � � � � � � � � � � ( � � � � � � ) * � + � � � $ � � � � � � � � � � � � � $ � � � ,It allows an application to announce a number of entities on one of the supportedprotocols. The application has to provide a function, which is called in a later pass ofthe initialization by the device support of the corresponding protocol. The pointer ofthat function is the last parameter of� � � ' � � � � � � . That function must contain thecalls for the initialization of all entities of that protocoll used by the application.

The detailed explaination where to call� � � ' � � � � � � can be found in “How to build it”on page27.

Page 9: original documentation and design document (pdf) - BESSY II

BESSY 9

Chapter 2: Protocols

Common Lower (GPS) Interface

The interface between the different protocols and the GPS layer consists of thefollowing functions:

� � � � � � � � � ! � � � � - � * � ' . / � 0 � � � � � � � � � � � ! ' 1 / � � � � � ' 2 3 4 ' 5 � � + 6 / � � 7 � & % � 8 � � � � ( 3 9 � / 8 % � % � � � :Get raw data from� � � � � � � � .� � 7 � & % � 8 � � � � Returns the object handle for which data is to be sent8 % � % � � Returns the raw data (max. 8 bytes) to send

Return value Flag set may consist of; . 2 < ' = . . Error occurred; . 2 < ' = > ; < ? No message to be sent; . 2 < ' @ 2 ' ; ; If set, GPS is requested to arrange post-processing after successful write; . 2 < ' . @ ' ; ; If

; . 2 < ' @ 2 ' ; ; is set, this flag specifies the typeof post-processing: if set, read post-proc is to beexecuted, otherwise write post-proc; . 2 < ' � � 5 � A Non-zero inhibit time; requests the use ofB � ' C � � � / ' � � � 3 � � instead of

B � ' C � � � /; . 2 < ' 2 D No errors; i.e., valid object handle and data, nopost-processing, no inhibit time

This function is called by the writing task of the GPS layer to get the object handleand the raw data of a message to be sent over the CAN bus.

� � � � � � � � � ! � � � 7 � � � ) * � + � � � � � � � � � ! ' � / 4 / � � � � � ' 2 3 4 ' 5 � � + 6 / � � 7 � & % � 8 � � ( 0 � B � 1 � / + 6 * � 1 8 � � % E � ,Return message to be delayed back to� � � � � � � � F� � 7 � & % � 8 � � Object handle of message to be delayed8 � � % E Demanded delay [inµs]

Page 10: original documentation and design document (pdf) - BESSY II

10 Document Revision: Draft

GPS uses this function to return those messages back to�G�H�I� �J�K�I� that were rejected byB K� 'ICL�M� �N/O'G� �IJ� 3I� � because of their inhibit time not having expired. The protocol takes themessage back and organizes re-notification of the GPS writer task after8J�I� %PEmicroseconds.

Caution: This function is defined only if inhibit time handling is enabled (i.e., if>Q�R�S�T'GUWVX=Y'Z� �W5W� AX� < is defined).� �G�H�J� �I�K�J� ![�J� � � -I�H*\� 'G.W/\�N0J�]� � �Z�^�J� �I�K�J� !_'G-I0O�G�H�QK�I�\'Z2`3\4 'Z5a�J�I+J6 /J X� �O7 �G&I%J�I8J� �O�I�T(J3b9K�N/I G8I%I� %\�I�c(I� �\�Z d�G�H�I� �H,

Put incoming CAN message into�Z�^�J� �I�K�J� .� �O7 �G&I%J�I8J� �O�I� Points to where GPS keeps the object handle (may be changed bythe protocol)8I%J� %\�J� Pointer to raw data d�G�H�I� SCI flags returned on receiving this message

Return value Flag set may consist of; .e2R<c'G=G.a. Error occurred; .e2R<c'G@W2f' ;X; If set, GPS is requested to arrange post-processing after successful write; .e2R<c'G.W@T' ;G; If

; .e2R<c'G@W2f' ;X; is set, this flag specifies the typeof post-processing: if set, read post-proc is to beexecuted, otherwise write post-proc; .e2R<c'G2`D No errors; i.e., valid object handle and data, nopost-processing, no inhibit time

This function is called by the reading task of the GPS layer to put the object handleand the raw data of a received message into the protocol layer. The object handle maybe changed by the protocol, if post-processing is desired for a different object. Thismay be needed for different variables in a LowCAL variable set, where one objectreceives the data for all variables of a variable set.

� �G�H�J� �I�K�J� ![�Z� $ � � -I�H*\� 'G.W/\�N0J�]� � �Z�^�J� �I�K�J� !_'I�N� �Q/g�H�QK�I�\'Z2`3\4 'Z5a�J�I+J6 /J X� �\7 �G&J%I�I8J� �\�I�Z�^,Check for timeouts.� �O7 �G&I%J�I8J� �O�I� Returns the object handle for which timeout post-processing is

demanded

Return value Flag set may consist of; .e2R<c' ; =X�W@ More timeouts may be pending —� �Z�^�J� �I�K�J� !['I�N� �Q/has to be called again; .e2R<c'G@W2f' ;X; If set, GPS is requested to arrange post-processing; .e2R<c'G.W@T' ;G; If

; .e2R<c'G@W2f' ;X; is set, this flag specifies the typeof post-processing: if set, read post-proc is to beexecuted, otherwise write post-proc; .e2R<c'G2`D No errors; i.e., valid object handle and data, nopost-processing, no inhibit time

This function is called by the GPS timeout watchdog task in regular intervals (of<e� >Q=X2`UT<c'G.W=XVG2`hIUT<e� 2`� , defined inmultican.h).

Page 11: original documentation and design document (pdf) - BESSY II

BESSY 11

LowCAL

Definition

The CAN Application Layer (CAL) provides four application layer service elements:

1. CAN based Message Specification (CMS)CMS offers an open, object oriented environment to design user applications. Itspecifies Variable, Event and Domain objects, their data types, the CAN accessprotocol and the encoding rules.

2. Network Management (NMT)NMT offers an environment to let one module (the NMT Master) deal with theinitialization and possible failures of the other modules (NMT Slaves).

3. Distributor (DBT)The DBT offers a dynamic distribution of CAN message identifiers (COB-IDs)by one module (the DBT Master) to the other modules (DBT Slaves).

4. Layer Management (LMT)LMT offers the possibility to let one module (the LMT Master) control thesettings of certain layer parameters at another module (LMT Slave).

The architecture of CAL allows to implement and use these services independently.Since only small parts of the CAL definition are relevant for use in the BESSYIIcontrols, this feature was used to minimize the implementation effort.

LowCAL is a minimal subset of the CAL specification’s CMS service. It providesasynchronous transmission of variables.

Data Types

The following basic data types for variables are defined:

INTEGER (valid lengths are 8, 16, 32 bits)

UNSIGNED (valid lengths are 8, 16, 32 bits)

Additionally arrays of variables of these basic types can be defined, as long as theCMS Encoding Rules are obeyed.1

1. Usually the total length of the array must not exceed 7bytes for Multiplexed, 8bytes for Basicvariables (exept Read/Write access types).

Attributes

The following attributes for variables are defined:

user_type: One of [CLIENT, SERVER].

data_type: See “Data Types” on page11.

class: One of the values [BASIC, MULTIPLEXED].

access_type: One of the values [READ_ONLY, WRITE_ONLY,READ_WRITE].

inhibit_time: n ∗ 100µsec, n ³ 0

Page 12: original documentation and design document (pdf) - BESSY II

12 Document Revision: Draft

Usage

The server of a variable is the CAN node where the variable originally resides.Accesses on the server side do a local update/read of the variable’s value, accessesfrom the client side lead to request and response messages being sent over the CANbus.

Variable sets can be used to “multiplex” several variables. All these multiplexedvariables will then be mapped onto the COBs that are used by that variable set. Thisindirect addressing scheme reduces the number of used COBs. Within a variable setthe variables are identified by a unique 7bit “multiplexor”, so the number of variablesin a set is limited to 128. Since the multiplexor is transmitted in the data part of theCAN message, the maximum data size for a multiplexed variable is reduced to7 bytes.

The access type of a variable is seen from the point of view of the client. Read-onlyvariables can be used by a client only to collect data. The collected data will be thedata that was set by the server in its last write access — previous updates are lost.Write-only variables can be used by a client to request one or more servers to executea command. This access is not confirmed (multicast). Read-write variables can beused by a client to collect the ‘current data’ from the server (read access) or to requestthe server to take a value and/or execute a command (write access). Both read andwrite accesses are confirmed.

The inhibit time enforces a minimal time delay between accesses on the same variableresp. variable set. This can be used to slow down a client not to exceed the capabilitiesof the variable’s server.

CAN Protocol

Order and type of the messages sent over the CAN bus during a LowCAL variableaccess strongly depend on the attributes of that variable. There are unconfirmed andconfirmed services (‘service’ being a read or write variable access). The unconfirmedservices use one COB that may have more than one recipient, confirmed servicesusually use two COBs (one for each direction) and connect exactly one server/clientpair.

Basic Variables, Read Only Access

One confirmed service (Read Variable) is defined. The client sends aRemote TransmitRequest (RTR) frame over the CAN, the server responds with a message containingthe requested data. One COB is needed for the connection. There has to be exactly oneserver and an arbitrary number of clients.

Application Data:up to 8bytes of data representing a value of the data type attributeof the basic variable.

Figure 2: CAN Protocol for Basic Variables, Read Only Access

8 Byte Application Data

Protocol Protocol

EnqueueingRequests

CAN Bus

Buffering andCaching

Data

Buffering andCaching

Data

Request

Data Flow

write()read()Remote Frame C

AN

Chip

-

Page 13: original documentation and design document (pdf) - BESSY II

BESSY 13

Multiplexed Variables, Read Only Access

One confirmed service (Read Variable) is defined. The client sends a request framewhich contains the multiplexor of the variable to be read. The server returns the dataand a flag indicating the result of the operation. Two COBs are needed for theconnection (one for each direction). There has to be at most one server and one clientper connection.

mux: Multiplexor, a value between 0 and 127 (inclusive)

X: not used, always 0

r: result

0: Success

1: Failure

Application Data:up to 7bytes of data. If r= 0, it represents a value of the data typeattribute of the multiplexed variable identified by mux. If r= 1, itrepresents a value of the error type attribute of this variable.

Basic Variables, Write Only Access

One unconfirmed service (Write Variable) is defined. The client sends a data frame tothe server(s). One COB is needed for the connection. There may be one or moreserver(s) and at most one client.

Application Data:up to 8bytes of data representing a value of the data type attributeof the basic variable.

Figure 3: CAN Protocol for Multiplexed Variables, Read Only Access

Requests

Buffering andCaching

Data

EnqueueingRequests

Buffering andCaching

Data

Request

Data Flow

muxXEnqueueing

r

Protocol Protocol

mux 7 Byte Application Data

CAN Bus

read() write()

Figure 4: CAN Protocol for Basic Variables, Write Only Access

8 Byte Application Data

Protocol CAN Bus Protocol

EnqueueingRequests

Buffering andCaching

Data

Buffering andCaching

Data

read()write()

Request

Data Flow

Page 14: original documentation and design document (pdf) - BESSY II

14 Document Revision: Draft

Multiplexed Variable, Write Only Access

One unconfirmed service (Write Variable) is defined. The client sends a data frame tothe server(s). One COB is needed for the connection. There may be one or moreserver(s) and at most one client.most one client.most one client.

X: not used, always 0

Application Data:up to 7bytes of data representing a value of the data type attributeof the multiplexed variable identified by mux.

Basic and Multiplexed Variables, Read/Write Access

Two confirmed services (Read Variable and Write Variable) are defined. The clientsends a request frame which contains the multiplexor of the variable to be accessedand a flag indicating the operation type. The server returns the data and a flagindicating the result of the operation. Two COBs are needed for the connection (onefor each direction). There has to be at most one server and one client per connection.

mux: Multiplexor, only valid for multiplexed variables. If valid, a valuebetween 0 and 127 (inclusive), otherwise 0

c: command specifier

0: Write

1: Read

Req. Appl. Data:only valid when c= 0, contains up to 7bytes of data, representing avalue of the data type attribute of the basic variable resp. themultiplexed variable identified by mux.

r: result

Figure 5: CAN Protocol for Multiplexed Variables, Write Only Access

Requests

Buffering andCaching

Data

mux 7 Byte Application DataXwrite()

Enqueueing

CAN Bus

read()Buffering andCaching

Data

Data Flow

Request

Protocol Protocol

Figure 6: CAN Protocol for Basic and Multiplexed Variables, Read/Write Access

Data Flow

Request

EnqueueingRequests

Buffering andCaching

Data

write()

7 Byte Resp. Appl. Data

Protocol Protocol

read()

mux

muxEnqueueingRequests

Buffering andCaching

Data r

CAN Bus

c 7 Byte Req. Appl. Data

Page 15: original documentation and design document (pdf) - BESSY II

BESSY 15

0: Success

1: Failure

Resp. Appl. Data:up to 7bytes of data. In case of a write response and r= 0, itrepresents the same value as passed with the write request. In caseof a read response and r= 0, it represents a value of the data typeattribute of the multiplexed variable identified by mux. In case ofr = 1, it represents a value of the error type attribute of the basicvariable resp. the multiplexed variable identified by mux.

Encoding Rules

The CAN message encoding rules are conformant with the CMS (CAL) encodingrules[1]. Since LowCAL defines a subset of the CMS data types (only 8bit alignedtypes), the encoding rules can be simplified as follows:

The transfer encoding syntax equals the representation syntax for little endian two’scomplement computers.

Figure7 shows the encoding for an array of two signed short integer variables.

Implementation

Interface

LowCAL’s interface (application side) consists of the following functions:� � i � % � � $ � $ � � � % � � - � * � ' . / � 0 � � 6 * C � 6 ' � � � � ' B � � � � � 0 � B � 1 � / + B * � � � � � ,First pass initialization routine.� � Number of LowCAL entities (variables) that will be used

Return value Flag set may consist of; . 2 < ' = . . 2 . Error occurred; . 2 < ' 2 D No errors

This first pass of initialization allocates buffers, semaphores and queues. The SCI andGPS layers are initialized.

In a multi application environment, this function may be called only by the mainapplication that starts up MultiCAN. Other applications have to use� � � ' � � � � toannounce their use of LowCAL.

Figure 7: Encoding Rules (Example)

1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 00

u15 u14 u13 u12 u11 u10 u9 u7 u6 u5 u3 u2 u1u8 u4 u0 v15 v14 v13 v12 v11 v10 v9 v7 v6 v5 v3 v2 v1v8 v4 v0

byte 0 byte 1 byte 2 byte 3

bit transmission order

i(1) = 42 = 0x002A =

msbsign lsb

1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0

u15 u14 u13 u12 u11 u10 u9 u7 u6 u5 u3 u2 u1u8 u4 u0

msbsign lsb

v15 v14 v13 v12 v11 v10 v9 v7 v6 v5 v3 v2 v1v8 v4 v0

0 0 0 0 0 0 0 0 0 1 0 1 0 1 00

i(0) = -42 = 0xFFD6 =

Page 16: original documentation and design document (pdf) - BESSY II

16 Document Revision: Draft

� �RiR�K%J� � $ � $ � �Z�I�I� $ � E -I�H*\� 'G.W/\�N0J�]�6 *OCLK�I6 'Z� �J� � 'G/J�\�N� � 9j�Z0J� B � 1I�J/I+ B I*J� �I�Z�I�N� (0J� B � 1I�J/I+ B I*J� �G� � � � $ 8I(0J� B � 1I�J/I+ B I*J� � $ �O� $ 8I(3b9K�]/ � %\kK�Z� �J�I�J� &I(�QK�J�\'G2l3\4 'G5W�I�J+I6 /I G� �\7 �Z&I%I�J8I� �\�J�T(6 K�J6 'J�X� �]�M� 3nm]%I� �G%J� � � $ � (6 K�J6 'Z@W�\�N�O'I<[9o-I/pmN%J� �Z� EK�G�q(0J� B � 1I�J/I+Q6 *I�I1Q� $ � �I� � � �H,Second pass initialization routine.�G�J�r� Number of the CAN segment to be used� � � � $ 8 COB ID for outgoing data$ �\� $ 8 COB ID for incoming data� %\kK�G� �J�I�I� & Maximum length of this variable’s data

For multiplexed variables: maximum length of this variable set’sdata (including multiplexor byte)� �O7 �G&I%J�I8J� �O�I� Returns an MultiCAN object handle to use in subsequent callsmN%J� �G%I� � � $ � LowCAL attribute setof the variable to be initializedmN%J� �G� EK�Z� LowCAL data type of the variable to be initialized� $ � �I� � � Timeout value [ms] for confirmed services

Return value Flag set may consist of; .e2R<c'G=G.a. Error occurred; .e2R<c'G� �W� < Variable was already initialized. The returnedobject handle is a duplicate.; .e2R<c'G2`D No errors

The second pass of initialization initializes a variable’s buffer entry, creates a newvariable set (if needed) and initializes the SCI in and out objects used for this variable.Arguments might be ignored, if not applicable (e.g.,$ �O�G� �\7 resp.� � � �G� �\7 and � $ � �I� � � forunconfirmed services). The returned object handle is used to identify the variable insubsequent LowCAL calls.� �RiR�K%J� � $ � $ � �Z�I�I8 -I�H*\� 'G.W/\�N0J�]�Q6 *OCLK�J6 'Z� �I� � 'G/J�I+Q� )Y*J� +I�H,Third pass initialization routine.

Return value Flag set is always; .e2R<c'G2`D No errors

This routine marks the end of LowCAL initialization — subsequent calls to6 *OCLK�I6 'Z� �J� � 'G/J�\�N� � 9 are erroneous.� �RiR�K%J� �SiT� $ � � -I�H*\� 'G.W/\�N0J�]�Q6 *OCLK�J6 'JCL�M� �N/Q�^�QK�I�O'G2`3O4 'G5W�I�J+I6 /g� �\7 �G&J%I�J8I� �J(O)Y*I� +I G8I%I� %\�I�Z�H,Write data to the protocol buffer and set up sending.� �O7 �G&I%J�I8J� � Object handle of the variable to use (as returned on6 *OCLK�I6 'Z� �J� � 'G/J�\�N� � 9

call)8I%J� %\�J� Pointer to data to be written (of the type declared in its6 *OCLK�I6 'Z� �J� � 'G/J�\�N� � 9 call)

Return value Flag set may consist of; .e2R<c'G=G.a. Error occurred; .e2R<c'I<e� >Q2 Only returned on a client’s second call to6 *OCLK�I6 'JCQ�^� �N/ : A timeout occurred (i.e., post-processing was initiated by the timeout watchdogtask, not the confirmation of the write access)

Page 17: original documentation and design document (pdf) - BESSY II

BESSY 17

; .e2R<c'GsP�l� h Only returned on a client’s second call to6 *OCLK�I6 'JCQ�^� �N/ : A failure occurred (i.e., theconfirmation of the last write access had itsfailure bit set); .e2R<c'G2`D No errors

On the client side, this routine copies the data into the protocol’s cache buffer. If thereis no request pending, it issues the sending of the appropriate write request by puttingthe request into the send queue and notifying the writer task.

On the server side, this call copies the data into the protocol’s cache buffer and sets thevariable’s buffer entry valid.� �RiR�K%J� �G�H�I%J8 -I�H*\� 'G.W/\�N0J�]�Q6 *OCLK�J6 'Z�^/J�I+Q�H�gK�J�\'G2l3\4 'G5W�I�J+I6 /Q� �\7 �Z&I%I�J8I� �q(\)Y*I� +J X8I%J� %\�J�G�H,Read data from the protocol buffer, eventually set up sending of a read request (clientside only).� �O7 �G&I%J�I8J� � Object handle of the variable to use (as returned on6 *OCLK�I6 'Z� �J� � 'G/J�\�N� � 9

call)8I%J� %\�J� Pointer to data to be read (of the type declared in its6 *bCLK�I6 'G� �I� � 'Z/I�O�N� � 9call)

Return value Flag set may consist of; .e2R<c'G=G.a. Error occurred; .e2R<c'I<e� >Q2 Only returned by a client’s second call to6 *OCLK�I6 'Z�^/J�I+ : A timeout occurred (i.e., post-processing was initiated by the timeout watchdogtask, not the confirmation of the read access); .e2R<c'GsP�l� h Only returned by a client’s second call to6 *OCLK�I6 'Z�^/J�I+ : A failure occurred (i.e., theconfirmation of the last read access had its failurebit set); .e2R<c'G2`hJ@t�J< Only returned on a client’s call to6 *OCLK�I6 'Z�^/J�I+ : Thedata copied to data_p is old (i.e., it has been readalready); .e2R<c'G2`D No errors

On the client side, this routine copies the cache buffer’s contents to the variable8I%J� %\�J�points to. If there is no request pending, it issues the sending of the appropriate readrequest by putting the request into the send queue and notifying the writer task.

On the server side, this call copies the cache buffer’s contents to the variable 8I%J� %\�J�points to.� �RiR�K%J� �I�I�J�G�K� � �Z� �I� � )Y*I� +Q6 *OCLK�I6 'G-J-\'ZK*I�Q-I6 /\�]/g�H�QK�I�\'Z2`3\4 'Z5a�J�I+J6 /Q� �O7 �G&I%J�I8J� �J�^,Signal the completion of post-processing.� �O7 �G&I%J�I8J� � Object handle of the variable to use (as returned on6 *OCLK�I6 'Z� �J� � 'G/J�\�N� � 9

call)

Calling this function signals the completion of post processing to the protocol. Thebuffer entry’s flags are set accordingly. On the client side, if a read or write access hasbeen postponed because of post-processing being busy, it is issued by putting therequest into the send queue and notifying the writer task.� �RiR�K%J� �G�I�J� � $ �J� �\7 B K� 'G2`3O4u/Id�N X6 *bCLK�I6 'G1J/\� 'Z� �J*I3O4o�^�QK�I�O'G2`3O4 'G5W�I�J+I6 /g� �\7 �G&J%I�J8I� �I�H,Get pointer to SCI object for incoming data.� �O7 �G&I%J�I8J� � MultiCAN object handle (variable) to use

Return value Pointer to the SCI object used for a variable’s incoming data

Page 18: original documentation and design document (pdf) - BESSY II

18 Document Revision: Draft

Caution: This function is defined only if MultiCAN runs on one processor (i.e., if>Q�R�S�T'G@W� VY<e.W� AGUT<e=X@ is not defined).� �RiR�K%J� �G�I�J� �G� � � � �\7 B K� 'G2`3O4u/Id�N X6 *bCLK�I6 'G1J/\� 'Z*I0\�]*I3\4o�H�QK�I�O'G2`3O4 'Z5W�I�I+J6 /g� �\7 �G&J%I�I8J� �I�H,Get pointer to SCI object for outgoing data.� �O7 �G&I%J�I8J� � MultiCAN object handle (variable) to use

Return value Pointer to the SCI object used for a variable’s outgoing data

Caution: This function is defined only if MultiCAN runs on one processor (i.e., if>Q�R�S�T'G@W� VY<e.W� AGUT<e=X@ is not defined).

Page 19: original documentation and design document (pdf) - BESSY II

BESSY 27

Chapter 4: EPICS Device Support

Using MultiCAN for transmitting data from an EPICS database to a variety of devicesover the CAN field bus needs appropriate device support. The runtime interface of thatlayered architecture is provided by the set of protocols. Every implemented protocolneeds an own device support. At the moment the protocol LowCAL is supported forthe following record types:

• String Input and String Output record

• Analog In and Analog Out record

• MultiBit Binary In Direct and MultiBit Binary Out Direct record

The several steps of the initialization of MultiCAN are closely connected with theinitialization of EPICS.

The properties of the communication channel and the peer entity of the EPICS recordare specified in the hardware link.

Usage of MultiCAN with EPICS

How to build it

The first step is the building of the MultiCAN coremCANCore. Now the environmentvariableMCANhas to be set to the absolute path of the subdirectory of MultiCAN.

The following modules have to be rebuilt1 for supporting MultiCAN:

• drvSupin .../epics/base/src/drv

• devSupin .../epics/base/src/dev

• initHooks.o

The new building of the moduledrvSupwith set variableMCAN causes a compilingof drvmCAN.c and the linking ofdrvmCAN.oandmCANCore to drvSup.

1. Rebuild means to do agmake in the corresponding directory.

Page 20: original documentation and design document (pdf) - BESSY II

28 Document Revision: Draft

The new devSupresults from the compilation of the device support functions of theseveral protocols of MultiCAN and the linking of it to devSup.

For initialization reasons the file initHooks.c has to be compiled after the setting ofMCAN. If it is intended to use MultiCAN with other applications beside EPICS, theenvironment variable ATTACH must be set. Besides the file .../epics/base/src/db/initHooks.chas to be modified in the here shown way:

1. Insert in theUSERAREA-2 the call of�QK�I�\'Z�\� �]�IKI�HKJ�I�H v-J�^*O�N*IK*J6 'G�I�J�Q/J(w� �\�x�J0I�Q3I/J� 'G*\y 'G/I6 /J�g/J�\� B (w� �\�x�H r�z� )Y*I� +I�-I*J� �\�N/J� 'J�N*\'JyN0I�Jd�N� *I�I�H,Example:{ r|I|J|IAX=G}`� �~2`s�UWVX=G.R�S.W=Y�l�H�I|J|I|I {�QK�J�\'G�O� �N�JKI�H�M6 *bCLK�I6 �M( �I( �N/ B � 'Z� �I� �N�\'Z�\� �]�IKI�{ r|I|J|I=X�W@~2`s�UWVX=G.T�l.W=Y�l�H�I|J|I|J {

2. Insert the declaration of the extern user function, which has to do theinitialization of the entities of the corresponding protocol used by thatapplication beside EPICS.Example:{ r|I|J|IAX=G}`� �~2`s�UWVX=G.R�S.W=Y�l�H�I|J|I|I {/b�K�]/I�M�g� �\�J�N/ B � 'G� �I� �N�O'G�\� �N�IKJ� )Y*J� +I�H,{ r|I|J|I=X�W@~2`s�UWVX=G.T�l.W=Y�l�H�I|J|I|J {

3. New compilation ofinitHooks.c

More detailed information about attaching applications to the MultiCAN initializationdone by EPICS can be found in “The use of MultiCAN by applications beside EPICS”on page8.

How to use it

The use of the CAN fieldbus with MultiCAN by EPICS requires the correct setting oftwo fields of the corresponding records.

The appliance of the protocol LowCAL claims the setting of the field� � � � to � � � � � � �The other is field is the� � � field or the � � � field. It has to contain a string with themaximum length of 35 characters� That sequence of characters describes theconnection to another entity using MultiCAN.

For LowCAL that string has the following syntax. Like for all strings in these fieldsthe first character is� � � . It is followed by the first character describing attributes of theLowCAL variable. These are the meanings of the several permissible characters:

� & % � % � � � � � � � � E � � � � % � � � � � E � �� Client Basic Read-only�

Client Basic Write-only

� Client Basic Read-Write�Client Multiplexed Read-only

� Client Multiplexed Write-only�Client Multiplexed Read-Write

� Server Basic Read-only�Server Basic Write-only�Server Basic Read-Write

Page 21: original documentation and design document (pdf) - BESSY II

BESSY 29

The next character, separated with�t d¡G¢J£K¤I¥ from the first, specify the data type of theLowCAL variable as shown in the next table

The different arrays of¦ §I¨J© can only be used with basic variables because 8 is themaximum number of bytes you can transmit with one CAN data frame.The succeeding 10 hexadecimal integers are separated withªt«I¬c­I® �I¯ and have themeaning as shown in that table:

1. °Q­\± � ²j³c²µ´ �J¶c�¸· � of data in byte to transmit with that object id (COB) on theCAN bus. If you use multiplexed variables, one byte for the multiplexor is to be

a.Encoding or decoding means the replacement of ’\0’ in incoming strings before writing it tothe record respectively regenerating of replaced ’\0’ in outgoing strings. More information aboutthe use of it can be found in “Special Features” on page30.

¹Server Multiplexed Read-onlyºServer Multiplexed Write-only´Server Multiplexed Read-Write

Character LowCAL Data Type

a String

b String being encoded or decoded by the device supporta

s Signed Short

S Unsigned Short

t Array of Signed Short

T Array of Unsigned Short

u Raw Signed Short

U Raw Unsigned Short

v Array of Raw Signed Short

V Array of Raw Unsigned Short

l Signed Long

L Unsigned Long

m Array of Signed Long

M Array of Unsigned Long

n Raw Signed Long

N Raw Unsigned Long

o Array of Raw Signed Long

O Array of Raw Unsigned Long

c Signed Character

C Unsigned Character

d Array of Signed Character

D Array of Unsigned Character

Page 22: original documentation and design document (pdf) - BESSY II

30 Document Revision: Draft

added to the size of the chosen data type. All multiplexed variables using thesame CAN object id (COB) must have the same maximum length.

2. The ¬c»c¼ · numberon the CAN card depending on the jumper settings of thatcard

3. CAN »c½ ¹ � ® · � ¾ (COB) of the» ³ ·b� » � ¶c� object

4. CAN »c½ ¹ � ® · � ¾ (COB) of the� ¶ ®I» ²�� ¶c� object

5. The²¿³c´ · � ¬ ´ � ±G»c¼

6. The� ¶ � � ½ � ·W· � ² � is the minimum time to elapse between the sending of CAN

objects with the same CAN object id. The time t results from the input valuemultiplied with a constant of 100µs.

7. The · � ² � » ³ ·RÀ ­ ´ ³ � refers to confirmed or remote LowCAL services1 and can beadjusted in a resolution of 1ms.

8. The meaning of that integer depends on the record type and the LowCAL datatype. For mbbiDirect and mbboDirect record it represents a shift value which isexplained in[2]. If the LowCAL data type is an array it represents the size of thearray.

Not for all LowCAL variable types all parameters are necessary but the device supportfor LowCAL expects all above mentioned entries in the string. Not needed parametersshould be set to ’0’.

Here is an example of an hardware link to LowCAL with the following attributes:

• Client / Multiplexed/ Read-Write

• Multiplexor 10

• Unsigned Short

• Maximum length of 3

• Port 2/ Out-id 257/ In-id 193

• Inhibit time of 500µs

• Timeout value of 500msÁYÂ �eÃnÄgÅQÆIÇJÆ ® Æ ­QÈ Æ\�PÉgÇÁ

1. All LowCAL clients of the access types Read-only and Read-Write.

Special Features

At the moment there are no array records, for instance array of short, available inEPICS. For reading and writing such arrays to or from a set of single records over theCAN bus it needs a workaround. With the help of a string record and a sequencer it isnow possible to substitute the missing record types. The in[4] described sequencerrealizes the connection between the single records and the string record. The stringrecord is connected over its hardlink via MultiCAN to a peer entity using LowCALtoo. For avoiding an occurrence of ’\0’ in the string, what would lead to an arbitrarycut off, encoding and decoding functions are used in the sequencer and in the devicesupport. The setting of the data type in the hardware link to’b’ activate that feature.Every simulation of an array record requires one separate state set in the stateprogram.

Page 23: original documentation and design document (pdf) - BESSY II

BESSY 31

References

[1] CAN Application Layer. CiA/DS201 ... CiA/DS205, CiA/DS207. May 1995. CiA e.V., Simon-Schöffel-Str 21, D-90427Nürnberg.

[2] J. Anderson, M. Kraimer:EPICS Input / Output Controller (IOC)Record Reference Manual.Argonne National Laboratory –Advanced Photon Source. November 1994.

[3] J. Bergl, B. Kuner, R. Lange, I. Müller, R. Müller, G.Pfeiffer,J.Rahn, H. Rüdiger:Controller Area Network (CAN) — a FieldBus Gives Access to the Bulk of BESSYII Devices.Presented atthe ICALEPCS’95, Chicago, 1995.

[4] A. Kozubal:State Notation Language and Run-time SequencerUsers Guide. Argonne National Laboratory – Advanced PhotonSource. September 1993.

[5] M. Kraimer:EPICS Input / Output Controller (IOC) ApplicationDeveloper’s Guide. Argonne National Laboratory – AdvancedPhoton Source. November 1994.

[6] B. Kuner, R. Lange, I. Müller, G.Pfeiffer, J.Rahn:SCI — SimpleCAN Interface. BESSY, Berlin, 1996.

Page 24: original documentation and design document (pdf) - BESSY II

32 Document Revision: Draft

Page 25: original documentation and design document (pdf) - BESSY II

BESSY 33

Index

A

Access_Type. . . . . . . . . . . . . . . . . . .11Attributes. . . . . . . . . . . . . . . . . . . . . .11

C

CAL. . . . . . . . . . . . . . . . . . . . . . . .7, 11CAN based Message Specification

(CMS). . . . . . . . . . . . . . . . . .11Distributor (DBT). . . . . . . . . . . . .11Layer Management (LMT). . . . . .11Network Management (NMT) . . .11

CAN Application Layer . . . . . . . .7, 11CANal . . . . . . . . . . . . . . . . . . . . . . . . .7

HighCANal. . . . . . . . . . . . . . . .7, 19LowCANal . . . . . . . . . . . . . . . .7, 21

Class . . . . . . . . . . . . . . . . . . . . . . . . .11Client. . . . . . . . . . . . . . . . . . . . . . . . .12CMS . . . . . . . . . . . . . . . . . . . . . . . . .11COB . . . . . . . . . . . . . . . . . . . . . . . . . .6Communication Object. . . . . . . . . . . .6Concept Overview. . . . . . . . . . . . . . . .7

D

Data Types . . . . . . . . . . . . . . . . . . . .11Data_Type. . . . . . . . . . . . . . . . . . . . .11DBT. . . . . . . . . . . . . . . . . . . . . . . . . .11Device Support . . . . . . . . . . . . . . . . . .6

E

Encoding RulesLowCAL . . . . . . . . . . . . . . . . . . . .15

EPICSAsynchronous Record Processing. 23Callback . . . . . . . . . . . . . . . . . . . .23Device Support . . . . . . . . . . . . . . . .6

G

Generic Protocol Support. . . . . . . . . .6Generic Protocol Support (GPS) . . . 23GPS. . . . . . . . . . . . . . . . . . . . . .6, 9, 23gps_table. . . . . . . . . . . . . . . . . . . . . .23

H

HighCANal. . . . . . . . . . . . . . . . . .7, 19

I

Inhibit Time . . . . . . . . . . . . . . . . .9, 11

L

LMT . . . . . . . . . . . . . . . . . . . . . . . . .11LowCAL . . . . . . . . . . . . . . . . . . . .7, 11

Attributes . . . . . . . . . . . . . . . .11, 16CAN Protocol. . . . . . . . . . . . . . . .12Client. . . . . . . . . . . . . . . . . . . . . . .12Data Types . . . . . . . . . . . . . . .11, 16Encoding Rules. . . . . . . . . . . . . . .15Inhibit Time . . . . . . . . . . . . . . . . .11Multiplexed Variables. . . . . . . . . .12Server . . . . . . . . . . . . . . . . . . . . . .12Variable Set. . . . . . . . . . . . . . .10, 12Ê Ë Ì Í Î Ê Ï Ð Ñ Ò Ï Ó Ô Ë Õ Ö

. . . . . . . . . . . . . . . . .17Ê Ë Ì Í Î Ê Ï Ð Ñ Ò Ï Ë × Ò Ë Õ Ö . . . . . . . . . . . . . . . .18Ê Ë Ì Í Î Ê Ï Ó Ô Ó Ò Ï Ñ Ô Ø

. . . . . . . . . . . . . . . . . .16Ê Ë Ì Í Î Ê Ï Ó Ô Ó Ò Ï Ñ Ô Ò Ó Ò Ù . . . . . . . . . . . . . . . . .16Ê Ë Ì Í Î Ê Ï Ó Ô Ó Ò Ï Ú Ò Î Û Ò. . . . . . . . . . . . . . . . . .15Ê Ë Ì Í Î Ê Ï Ü Ü Ï Í Ë Ý Ü Ê Ñ Ò Ñ

. . . . . . . . . . . . . . .17Ê Ë Ì Í Î Ê Ï Û Ñ Î Ø. . . . . . . . . . . . . . . . . . . . .17Ê Ë Ì Í Î Ê Ï Ì Û Ó Ò Ñ . . . . . . . . . . . . . . . . . . . .16

LowCANal . . . . . . . . . . . . . . . . . .7, 21

MÝ Í Î Ô Ï Î Ò Ò Î Í Þ. . . . . . . . . . . . . . . . . . . . .8ß à á â Ï ã ä å æ ç ä è é æ ê ã

. . . . . . . . . . . . .18mCANReader. . . . . . . . . . . . . . . . . . .6mCANTimer. . . . . . . . . . . . . . . . .6, 16mCANWriter . . . . . . . . . . . . . .6, 9, 17Multicast Message . . . . . . . . . . . . . .12Multiplexed Variables. . . . . . . . . . . .12Multiplexor. . . . . . . . . . . . . . . . .12, 16

N

NMT . . . . . . . . . . . . . . . . . . . . . . . . .11

O

Object Handle. . . . . . . . . . . . . . . . . .16

P

Post-Processing. . . . . . . . . . . . . . . . . .9Protocol Function Set. . . . . . . . . . .6, 8ë Ü Û Ë Ò Ë Í Ë Ê ì Ï Ð Ñ Ò . . . . . . . . . . . . . . . . . . .9ë Ü Û Ë Ò Ë Í Ë Ê ì Ï Ü × Ò . . . . . . . . . . . . . . . . . .10ë Ü Û Ë Ò Ë Í Ë Ê ì Ï Û Ñ Ö Ñ Í Ò . . . . . . . . . . . . . . . . . .9ë Ü Û Ë Ò Ë Í Ë Ê ì Ï Ò Ó Ý Ñ . . . . . . . . . . . . . . . . . .10

R

Remote Transmit Request (RTR) . . . 12RTR. . . . . . . . . . . . . . . . . . . . . . . . . .12

S

SCI . . . . . . . . . . . . . . . . . . . . . . . . . . .5Server . . . . . . . . . . . . . . . . . . . . . . . .12

Page 26: original documentation and design document (pdf) - BESSY II

34 Document Revision: Draft

Simple CAN Interface. . . . . . . . . . . . .5

T

TaskmCANReader . . . . . . . . . . . . . . . . .6mCANTimer. . . . . . . . . . . . . . .6, 16mCANWriter. . . . . . . . . . . . .6, 9, 17

U

User_Type. . . . . . . . . . . . . . . . . . . . .11

V

VariableAttributes. . . . . . . . . . . . . . . . . . . .11Data Types . . . . . . . . . . . . . . . . . .11Multiplexed. . . . . . . . . . . . . . . . . .12

Variable Set. . . . . . . . . . . . . . . . . . . .12