Cifx Netx Application Programmers Guide XX EN
Cifx Netx Application Programmers Guide XX EN
V0.0
Table of Contents
1 Introduction.............................................................................................................................................4
1.1 About this Document......................................................................................................................4
1.2 List of Revisions .............................................................................................................................5
1.3 Terms, Abbreviations and Definitions ............................................................................................6
2 Programming Resources.......................................................................................................................7
2.1 Manuals and Documents ...............................................................................................................7
2.2 Product CDs/DVDs and Content....................................................................................................8
2.3 Choose a Programming Level........................................................................................................9
2.3.1 Hardware Level ............................................................................................................................... 11
2.3.2 Low Level ........................................................................................................................................ 11
2.3.3 Intermediate Level........................................................................................................................... 12
2.3.4 Driver Level ..................................................................................................................................... 12
3 Fundamentals - DPM Layout and Content .........................................................................................13
3.1 The DPM Layout ..........................................................................................................................14
3.1.1 DPM Area Definition ........................................................................................................................ 14
3.1.2 DPM Definitions, Structures and Header Files ................................................................................ 15
3.2 System Channel Structure ...........................................................................................................16
3.2.1 System Information.......................................................................................................................... 17
3.2.2 System Status ................................................................................................................................. 17
3.3 Handshake Channel.....................................................................................................................18
3.3.1 Handshake Register Functionality................................................................................................... 19
3.4 Communication Channel Structure ..............................................................................................20
3.4.1 Channel Information ........................................................................................................................ 21
3.4.2 Channel State.................................................................................................................................. 21
3.5 Data Transfer Methods and Areas ...............................................................................................22
3.5.1 Packet Definition and Transfer via a Mailbox System...................................................................... 22
3.5.2 I/O Data Transfer............................................................................................................................. 25
3.6 Communication Mechanism and Synchronization .......................................................................26
3.6.1 System Channel Handshake Register............................................................................................. 26
3.6.2 Communication Channel Handshake Register................................................................................ 27
3.6.3 Working with Handshake Registers and Flags ................................................................................ 28
3.6.3.1 Simple State and Command Handshake Flags ............................................................... 28
3.6.3.2 Synchronization Handshake Flags .................................................................................. 28
3.6.3.3 Packet Data Transfer - Handshake Flag Synchronisation ............................................... 29
3.6.3.4 I/O Data Transfer - Handshake Flag Synchronisation ..................................................... 32
3.6.3.5 Change of State Mechanism (COS) ................................................................................ 36
3.7 Programming Interface - CIFX-API ..............................................................................................40
4 Examples...............................................................................................................................................41
4.1 System Identification and Start-Up Handling ...............................................................................41
4.2 Channel Identification and Start-Up Handling..............................................................................42
4.3 Packet Transfer ............................................................................................................................43
4.3.1 Send a Packet to the Device ........................................................................................................... 43
4.3.2 Read a Packet form the Device....................................................................................................... 44
4.4 I/O Data Transfer .........................................................................................................................45
4.4.1 Write Output data to the Device ...................................................................................................... 45
4.4.2 Read Input data from Device........................................................................................................... 46
4.5 Change of State (COS) Information and Handling.......................................................................47
4.5.1 Host COS Handling ......................................................................................................................... 47
4.5.2 Communication COS Handling........................................................................................................ 48
4.6 Hardware and Protocol Stack Identification .................................................................................49
4.7 Additional Functions .....................................................................................................................49
4.8 Hardware and Driver Installation Guides .....................................................................................50
4.9 Load a Firmware to a CIFX Card .................................................................................................50
4.10 Start with an Example Program ...................................................................................................50
4.11 Protocol Stack handling via CIFX API..........................................................................................51
5 Additional Resources ..........................................................................................................................51
5.1 Protocol API Manuals...................................................................................................................51
6 Appendix ...............................................................................................................................................52
1 Introduction
1.1 About this Document
This guide is an introduction to the programming of Hilscher netX based device. It explains the fundamentals
necessary to understand the functions and the handling of Hilscher netX hardware and will show the
programming principals needed for correct device handling.
It should also help to choose the level where to start with developments, describes where to find the
necessary information.
Furthermore it explains the available information in regards to the programming level, describes necessary
synchronisation mechanism for the data transfer between a host and the netX firmware and covers all
aspects from a simple memory connection to a netX (dual-port-memory access), the use of pre-created low
level hardware functions, the netX C toolkit, the implementation of own drivers based the toolkit until the use
of Hilscher device drivers for different operating systems.
2 Programming Resources
Hilscher offers several resources for the programming. The following list contains the most
important manuals necessary.
Usage: One or more netX Chip(s), COMX modules or CIFX cards connected to
microcontrollers
- DPM or ISA connection to the netX hardware
- with or without an operating system
- limited system resources (RAM/FLASH)
Programming Resources:
Manuals: netX Dual-Port Memory Interface DPM xx EN.pdf
(Dual Port Memory layout, structures and functionalities)
CIFX netX Toolkit DPM TK xx EN.pdf
CD /DVD NXDRV-TKIT or Communication Solution DVD
Source Files: Toolkit .\Examples\cifXTKitHWFunctions directory
cifXUser.h
cifXErrors.h
netX_RegDefs.h
cifXHWFunctions.h.c / cifXHWFunctions.h
cifXEndianess.c / cifXEndianess.h
cifXInterrupt.c / cifXInterrupt.h
Usage: One or more netX chip(s), COMX modules, CIFX cards connected to a host
PC system
- Support for standard Hilscher devices (complete function support)
- C / C++ development environment
- With or without an operating system
- Writing own drivers
Programming Resources:
Manuals: CIFX netX Toolkit DPM TK xx EN.pdf
CIFX API PR xx EN.pdf
CD /DVD NXDRV-TKIT or Communication Solution DVD
Source Files: Toolkit .\cifXToolkit directory
Usage: Host PC system with an operating system or real time extension supported
by Hilscher
- COMX modules, CIFX cards connected to a host PC
- ISA / PC104 / PCI or PCIexpress bus system
- Support for standard Hilscher devices (complete function support)
- Creation own high level user applications
Programming Resources:
Manuals: CIFX API PR xx EN.pdf
CD /DVD NXDRV-xxx or Communication Solution DVD
Source Files: Comming with the driver
cifXUser.h
cifXErrors.h
All Hilscher netX based devices processing a Hilscher standard firmware performing in the same
way.
Handshake Channel:
- Special hardware registers containing synchronization flags and channel states
- Independent registers pairs for each channel
- Register pairs consists of a host dedicated and netX dedicated register
- Registers are able to create interrupts on the corresponding (host register on netX, netX register
on host side)
Application Channel:
- Dedicated channel to access a customer application running on netX
- Optional and not defined yet
rcx_User.h
Definition of the DPM structure, data blocks and all global definitions offered by the DPM.
The C-header file contains all parts necessary to work with the DPM by using symbolic
names.
rcx_Public.h
Definition of "rcX Public Packet" functions.
Packets are asynchronous commands which can be sent to the hardware. A packet is the
combination of a "Packet-Header", containing global command, routing and handling
information for the packet, and a following "User-Data Area" containing command specific
data.
NOTE: All structures and definition used in the following chapters can be found in these two
header files
/*****************************************************************************/
/*! System status block (Size = 64 Byte) */
/*****************************************************************************/
typedef __RCX_PACKED_PRE struct NETX_SYSTEM_STATUS_BLOCKtag
{
uint32_t ulSystemCOS; /*!< 0x00 System channel change of state
acknowledge */
uint32_t ulSystemStatus; /*!< 0x04 Actual system state */
uint32_t ulSystemError; /*!< 0x08 Actual system error */
uint32_t ulBootError; /*!< 0x0C Bootup error (only set by 2nd Stage
Bootloader) */
uint32_t ulTimeSinceStart; /*!< 0x10 time since start in seconds */
uint16_t usCpuLoad; /*!< 0x14 cpu load in 0,01% units (10000 => 100%)
*/
uint16_t usReserved; /*!< 0x16 Reserved */
uint32_t ulHWFeatures; /*!< 0x18 Hardware features */
uint8_t abReserved[36]; /*!< 0x1C:3F Reserved */
} __RCX_PACKED_POST NETX_SYSTEM_STATUS_BLOCK;
Handshake Channel
Bit 7 Host Flags Bit 0 Bit 7 netX Flags Bit 0 empty empty
__RCX_PACKED_PRE struct
{
volatile uint16_t usNetxFlags; /*!< Device status flags (16Bit Mode) */
volatile uint16_t usHostFlags; /*!< Device command flags (16Bit Mode)*/
} __RCX_PACKED_POST t16Bit;
volatile uint32_t ulValue; /*!< Handshake cell value */
} __RCX_PACKED_POST NETX_HANDSHAKE_CELL;
/*****************************************************************************/
/*! Default RCX packet structure, including user data */
/*****************************************************************************/
typedef __RCX_PACKED_PRE struct RCX_PACKETtag
{
RCX_PACKET_HEADER tHeader; /*!< Packet header */
uint8_t abData[RCX_MAX_DATA_SIZE]; /*!< Packet data */
} __RCX_PACKED_POST RCX_PACKET;
Mailbox System:
Mailbox System
Host Application
netX Firmware
/*****************************************************************************/
/*! System receive packet mailbox (Size 128 Byte) */
/*****************************************************************************/
typedef __RCX_PACKED_PRE struct NETX_SYSTEM_RECV_MAILBOXtag
{
uint16_t usWaitingPackages; /*!< Number of packages waiting to be processed */
uint16_t usReserved; /*!< Reserved */
uint8_t abRecvMbx[NETX_SYSTEM_MAILBOX_MIN_SIZE]; /*!< Receive mailbox packet buffer */
} __RCX_PACKED_POST NETX_SYSTEM_RECV_MAILBOX;
netX Firmware
1 1 EMPTY
HCF_SEND_MBX_CMD NCF_SEND_MBX_ACK
1 0 FULL
0 1 FULL
0 0 EMPTY
1 1 EMPTY
NCF_RECV_MBX_CMD HCF_RECV_MBX_ACK
1 0 FULL
0 1 FULL
Evaluation of the actual mailbox state can be done by an easy XOR relation between the involved
flags:
if (0 == ((usHostFlags ^ usNetxFlags) & HCF_SEND_MAILBOX))
/* Mailbox empty */
else
/* Mailbox full */
1 1
0 0
1 0
Back to step 1
Example: netX device sending a packet to the host (NCF_RECV / receive mailbox)
Stap Flags Mailbox State Description
1 1
0 0
1 0
Back to step 1
The I/O data transfer uses an additional definition (Handshake Mode) which defines the initiator of
a data transfer.
Handshake Mode Definition:
Buffered Host Controlled Mode Host initiates the INPUT/OUTPUT data update
Buffered Device Controlled Mode Device initiates the INPUT/OUTPUT data update
The combination of the flag state and the handshake mode is used to handle the I/O data transfer.
Example: Read INPUT data by the host in "Buffered Host Controlled Mode"
Step Flags INPUT State Description
1 1
0 0
3 Device updates the INPUT data area with local buffer holding the latest data received by the
fieldbus connection.
- Device getting an interrupt signalling changes in the host flags
- Checks the state of HCF_PDO_IN_CMD and NCF_PDO_IN_ACK
- Copies the actual local input data into the input process data area in the DPM
- Toggle NCF_PDO_IN_CMD (1->0 or 0->1)
Host polls flags or waits on an I/O read event and processes following functions
- Copy the data from the DPM to a local buffer
- Processes the input data
Back to step 1
Example: Write OUTPUT data by the host in "Buffered Host Controlled Mode"
Step Flags OUTPUT Description
State
1 1
0 0
3 Device takes the OUTPUT data and copies the data to a local output buffer and sending the data
with the next bus cycle.
- Device getting an interrupt signalling changes in the host flags
- Checks the state of HCF_PDO_OUT_CMD and NCF_PDO_OUT_ACK
- Copies the actual OUTPUT data from the DPM to a local output buffer
- Toggle NCF_PDO_OUT_ACK (1->0 or 0->1)
Back to step 1
ATTENTION: In "Device Controlled Mode" the initiator of the transfer changes from HOST to
netX and therefore also the flag meanings are changing (_CMD flags becoming
_ACK flags and _ACK flags becoming _CMD flags).
Example: Read INPUT data by the host in "Buffered Device Controlled Mode"
Step Flags OUTPUT Description
State
1 1
0 0
2 Device gets new INPUT data from the field bus connection and signals them to the host
"Buffered Device Controlled Mode"
- Checking for state 1
- Copy local INPUT data to the input process data area in the DPM
- Signal host to take the INPUT data
- Toggle NCF_PDO_IN_ACK (1->0 or 0->1)
Back to step 1
Example: Write OUTPUT data by the host in "Buffered Device Controlled Mode"
Step Flags OUTPUT Description
State
1 1
0 0
2 Device gets new OUTPUT data from the DPM and copies them to the local output data buffer
"Buffered Device Controlled Mode"
- Checking for state 1
- Copy OUTPUT data from the DPM to the local output process data
- Signal host, data taken from the OUTPUT process data area
- Toggle NCF_PDO_OUT_ACK (1->0 or 0->1)
Back to step 1
This mechanism is direction oriented and distinguishes between state changes from the host
application and form the device:
Device state changes are named "Communication COS Handling"
Application state changes are named "Application COS Handling"
3 4
Communication Channel
Communication Channel 5
NCF_HOST_COS_CMD HCF_HOST_COS_ACK
2 1
netX Firmware
The netX device "COS" flags are located in the "Common Status Block" structure
NETX_COMMON_STATUS_BLOCK of a communication channel.
0 0
Back to step 1
5 1
2 Communication Channel
Communication Channel
Control Block structure
Handshake Register NETX_CONTROL_BLOCK
netXFlags Host Flags Offset 0x0008 = ulApplicationCOS
3
NCF_APP_COS_ACK HCF_APP_COS_CMD
netX Firmware
The application "COS" flags are located in the "Control Block" structure NETX_CONTROL_BLOCK
of a communication channel.
0 0
Back to step 1
The API offers general handling functions and functions corresponding to the DPM components
described above.
Example API functions:
Asynchronous Services (Packets)
API Function Description
xChannelGetMBXState Retrieve the channels mailbox state
xChannelGetPacket Read a packet from the channel receive mailbox
xChannelPutPacket Send a packet via the channel send mailbox
...........
The complete API is described can be found in the "cifX API PR xx EN.pdf" manual.
4 Examples
4.1 System Identification and Start-Up Handling
This flow chart describes the necessary start-up handling to identify a running netX boot loader or
firmware.
no
Channel Type ==
RCX_CHANNEL_TYPE_COMMUNICATION?
yes
no
no
RCX_COMM_COS_READY bit set? Timeout expired?
yes
yes
no
data length < = output area size?
yes
no
no
HCF_PD0_OUT_CMD == NCF_PD0_OUT_ACK? Timeout expired?
yes
yes
Toggle HCF_PD0_OUT_CMD
no
no
HCF_NETX_COS_ACK != NCF_NETX_COS_CMD? Timeout expired?
yes
yes
Toggle HCF_NETX_COS_ACK
Hardware Identification
This information can be found in the "System Information Block"
Device Class => DPM Offset 0x0028 usDeviceClass
Hardware Assembly Option
Defines which communication hardware is offered by the device
This information can be found in the "System Information Block"
Hardware Option => DPM Offset 0x0010 ausHwOptions
This information can be found in the "netX Dual Port Memory Interface DPM...pdf" manual.
A description on how to install and pre-configure the hardware you will found under:
.\documentation\Installation - "cifX Device Driver Installation for Windows"
Such devices must be pre-loaded with a firmware to be usable by a configuration tool or by any application
which want a field bus protocol firmware.
Actual firmware can be taken from the "Communication Solution DVD" (either shipped with the device or
downloadable Hilscher web site the following link:
http://de.hilscher.com/hcde/files_software/Communication_Solutions_DVD_20xx-xx-1..............
Go to the "Firmware" sub-directory and choose the appropriate firmware for your hardware (like described in
the "cifX Device Driver Installation for Windows" manual.
On COMX module the firmware is stored on the hardware and a firmware download during start-up is not
necessary.
This example contains most of the CIFX API functions in separate source modules an mostly contains a
corresponding project file (e.g. Microsoft Visual Studio project under Windows) which can be used to compile
and run the example.
The main function of the example can be found in the source module cifXTest_console.cpp which than calls
the function RunCifXConsoleTest() in the source module cifXConsole_Main.cpp for further processing.
5 Additional Resources
5.1 Protocol API Manuals
Each fieldbus protocol stack has it own documentation, describing the protocol specific functions
and commands.
Protocol API manuals can be found on the "Communication Solution DVD" in the
.\Documentation\Programming Manuals\ directory and the manual file names are containing the
protocol stack name, e.g. "PROFIBUS Master Protocol API....pdf"
6 Appendix
6.1 List of Tables
Table 1: List of Revisions .................................................................................................................................................... 5
Table 2: Terms, Abbreviations and Definitions.................................................................................................................... 6
Table 3: General Packet Structure .................................................................................................................................... 22
Table 4: Host System Flags / netX System Flags ............................................................................................................. 26
Table 5: Host Communication Flags / netX Communication Channel Flags ..................................................................... 27
6.3 Contacts
Headquarters
Germany
Hilscher Gesellschaft für
Systemautomation mbH
Rheinstrasse 15
65795 Hattersheim
Phone: +49 (0) 6190 9907-0
Fax: +49 (0) 6190 9907-50
E-Mail: info@hilscher.com
Support
Phone: +49 (0) 6190 9907-99
E-Mail: de.support@hilscher.com
Subsidiaries
China Japan
Hilscher Systemautomation (Shanghai) Co. Ltd. Hilscher Japan KK
200010 Shanghai Tokyo, 160-0022
Phone: +86 (0) 21-6355-5161 Phone: +81 (0) 3-5362-0521
E-Mail: info@hilscher.cn E-Mail: info@hilscher.jp
Support Support
Phone: +86 (0) 21-6355-5161 Phone: +81 (0) 3-5362-0521
E-Mail: cn.support@hilscher.com E-Mail: jp.support@hilscher.com
France Korea
Hilscher France S.a.r.l. Hilscher Korea Inc.
69500 Bron Suwon, Gyeonggi, 443-734
Phone: +33 (0) 4 72 37 98 40 Phone: +82 (0) 31-695-5515
E-Mail: info@hilscher.fr E-Mail: info@hilscher.kr
Support
Phone: +33 (0) 4 72 37 98 40 Switzerland
E-Mail: fr.support@hilscher.com Hilscher Swiss GmbH
4500 Solothurn
India Phone: +41 (0) 32 623 6633
Hilscher India Pvt. Ltd. E-Mail: info@hilscher.ch
New Delhi - 110 065 Support
Phone: +91 11 43055431 Phone: +49 (0) 6190 9907-99
E-Mail: info@hilscher.in E-Mail: ch.support@hilscher.com
Italy USA
Hilscher Italia S.r.l. Hilscher North America, Inc.
20090 Vimodrone (MI) Lisle, IL 60532
Phone: +39 02 25007068 Phone: +1 630-505-5301
E-Mail: info@hilscher.it E-Mail: info@hilscher.us
Support Support
Phone: +39 02 25007068 Phone: +1 630-505-5301
E-Mail: it.support@hilscher.com E-Mail: us.support@hilscher.com