Host Application Examples - Structure

Q

How to understand the structure of Hilschers host application examples?

A

Overview

Hilscher offers a number of example applications, published in the Knowledge Base →  LFW Host Examples

The examples are implemented in ANSI C.

Each example represents the implementation of a network (slave) device which produces and consumes IO-data. All examples are very similar and represent the same device from the application point of view.

In order to support and demonstrate different protocols and different host architectures, the example applications are structured in a modular way.

The projects are separated into 3 parts

  1. Application - YELLOW
  2. Protocol specific parts - GREEN
  3. Hardware specific parts - RED

Each part is modular and independent of any other part. E.g.the same application source code can be combined with any protocol specifc code and with any hardware specific code.

NrExampleApplicationProtocolHardware Platform
1PROFINET simple configApplication Module 1Protocol Module Variant 1Hardware Module netX 90 APP
2

PROFINET extended config

Application  Module 1Protocol Module Variant 2Hardware Module netX 90 APP
3EtherCAT simple configApplication  Module 1Protocol Module Variant 3Hardware Module netX 90 APP
4EtherCAT custom ODApplication  Module 1Protocol Module Variant 4Hardware Module netX 90 APP
5...


In the table above, 4 differnet example applications are listed. All applications use the same application source code (Application Module 1) and the same hardware specific source code (netX 90 APP). Only the protocol specific parts are different in each example.

In order to support an additional host architecture, like STM32 MCUs or a Windows PC, only the RED component must be replaced.

NrExampleApplicationProtocolHardware Platform
...



5PROFINET simple configApplication Module 1Protocol Module Variant 1Hardware Module STM32
6

PROFINET extended config

Application  Module 1Protocol Module Variant 2Hardware Module STM32
...



Once you are familiar with the project structure of one single example, it is easy to migrate to a different protocol or to a different hardware platform, since most software components are the same.

Block Diagram

Mapping to Project Components

Application Part - YELLOW

The application part, more concrete the function App_DemoApplication(), is the entry point of the example application. The function App_DemoApplication() is called in main.c

The application part is based on the cifX API (by using the cifX Toolkit or a driver from Hilscher, like the cifX Windows or Linux Driver) and a simple hardware abstraction layer, thus independent of any hardware. I.e. the same application parts can be used with any hardware platform like netX 90 APP, STM32 MCU, Windows PC, Linux, etc..

The effort for migration to a custom hardware platform, not supported by Hilscher yet, is not high. Only the RED parts of the example must be adapted to the specific host hardware.

Furthermore it contains only generic application parts without any protocol specific code. I.e. the same application parts can be used for any protocol example like PROFINET, EtherCAT, EthernetIP, PROFIBUS, etc.

The application example projects, provided by Hilscher, do not use an operating system. Though it is feasible to port the application example to a system including an RTOS using several OS tasks.

The YELLOW application part is splitted into several C-modules for clarity. These are represented by grey boxes in the block diagram above. In the published projects, the YELLOW application part and all its C-Modules are composited in the component "cifXApplicaionDemo".

The component provides basic, generic mailbox packet service routines to send and receive mailbox packets.

The body of the application has two main parts: 1) The main loop (while 1 loop) for "slow" less prior tasks like DPM mailbox packet handling, and 2) a cyclic timer interrupt service routine for "fast", higher prior IO data handling → App_IODataHandler() function.

Before entering the main loop and cyclic handling of the timer ISR, several configuration steps are executed: Opening the DPM channels (xChannelOpen()), retrieving information about the LFW on the netX communication side (xChannelInfo()) and configuration of the protocol stack (Protocol_StartConfiguration()).

The modeled IO device features 2 sensors (producing output data) and 2 actuators (consuming input data). Beside the actual sensor/actuator data, the IO data image contains state and mode information as well as a counter. The example applications do not fully implement the device functionality. I.e. the actual sensor/actuator data is not important and usually just dummy data. Depending on the available resources of the hardware platform, the data (or parts of it) might be output to LEDs, inputs might be DIP-switches or the netX 90 build in tempertaure sensor, etc. The data is provided/consumed by the hardware abstarction layer functions (HOSTAL - host abstraction layer)

List of C-files

Generic Application (cifX API based)

C-module
App_DemoApplication.cBody of the application
Contains the main loop (cyclic calls of PacketHandler and TerminalHandler) and the IODataHandler
App_DemoApplicationFunctions.cCollection of functions used in cifXApplicationDemo.c
App_PacketCommunication.hCollection of functions to send/receive packets via the mailbox
App_SystemPackets.c

Helper module to assembly and evaluate protocol stack independent packets.

No send/receive functions are called inside SystemPacket functions.

App_TerminalHandler.c

Console implementation (supported commands, see table below)
App_EventHandler.cEvaluation of system status and generation of alarms and errors


IO-Data

Output (PLC input)10 bytesprovider
Cyclic Counter2 bytesglobal counter variable, handled directly in IODataHandler
sensor 1 output2 bytesHOSTAL_Sensor_GetData()
sensor 1 state1 byteHOSTAL_Sensor_GetState()
sensor 2 output2 bytesHOSTAL_Sensor_GetData()
sensor 2 state1 byteHOSTAL_Sensor_GetState()
actuator 1 state1 byteHOSTAL_Actuator_GetState()
actuator 2 state1 byteHOSTAL_Actuator_GetState()
Input (PLC output)6 bytesconsumer
actuator 1 input2 bytesHOSTAL_Actuator_SetData()
actuator 2 input2 bytesHOSTAL_Actuator_SetData()
Cyclic counter direction1 byteHandling of global counter variable (Cyclic Counter in output data): up/down counter
0: Cyclic Counter counts up,
1: Cyclic Counter counts down
Cyclic counter speed1 byte

Handling of global counter variable (Cyclic Counter in output data): fast/slow increment/decrement

= 0: Cyclic Counter is not incremented/decremented at all
> 0: Number of cycles it takes to increment/decrement Cyclic Counter by one.



Protocol Part - GREEN

The protocol part is based on the cifX API (by using the cifX Toolkit or a driver from Hilscher, like the cifX Windows or Linux Driver) and a simple hardware abstraction layer, thus independent of any hardware. I.e. the same protocol component can be used with any hardware platform like netX 90 APP, STM32 MCU, Windows PC, Linux, etc..

The effort for migration to a custom hardware platform, not supported by Hilscher yet, is not high. Only the RED parts of the example must be adapted to the specific host hardware.

In contrast to the generic YELLOW application part, the GREEN protocol part is specifc for the different Hilscher Protocol LFWs like PROFINET, EtherCAT, ...

The GREEN protocol part is splitted into several C-modules for clarity. These are represented by grey boxes in the block diagram above. In the published projects, the GREEN protocol part and all its C-Modules are composited in the component "cifXApplicaionDemoXXX", where XXX is replaced by the respective protocol abbreviation (PNS - PROFINET slave, EIS, EthernetIP slave, ECS - EtherCAT slave, etc.).

The component provides 3 main functions, which are called from the YELLOW application part:

  1. Protocol_StartConfiguration()
  2. Protocol_PacketHandler() and subsequently AppXXX_Protocol_PacketHandler()
  3. Protocol_EventHandler()

1) is called only once during the initialization phase, 2) is called cyclically from the main loop in order to check and handle incoming mailbox packets. 3) may be used to demonstrate the implementation of protocol specific asyclic communication, like diagnosis or alarms, etc.. 3) is not implemented and just an empty function in most examples

Hilscher LFWs might feature several DPM communication channels with different functionality (refer to article Firmware Variants). Each channel might be handled by an independent GREEN protocol component. Mostexamples demonstrate the usage of just one DPM communication channel.

List of C-files

Protocol dependent part of the application (cifX API based)

C-module
AppXXX_DemoApplication.c

Protocol dependent part of the application

Implements the functions  Protocol_PacketHandler(),
Protocol_StartConfiguration() and Protocol_EventHandler()

AppXXX_DemoApplicationFunctions.cCollection of protocol specific functions, used in AppXXX_DemoApplication.c

XXX= PNS, EIS, ECS, PLS, etc.


Hardware Dependent Part - RED

The hardware dependent parts might differ significantly between each host hardware platform. An embedded Cortex-M based host controller must be setup differently than a Linux or Windows based PC Host device.

The RED part provide 3 main functiionalities

  1. initialize the system/application and entry point main()
  2. cifX API as base for the application
  3. HOSTAL - hardware abstraction layer

During execution of 1, startup code (typically assembler code in embedded systems) for interrupt setup etc. is executed, the cifX Driver or cifX Toolkit is initialized, communication interfaces (like UART or SPI) are initialized and the application demo is started by call of function  App_DemoApplication().

2), the cifX API is base for the YELLOW application part and GREEN protocol part. In embedded systems typically the cifX Toolkit component is implemented. On Windows or Linux hosts, a Hilscher driver (e.g. DLL), ready to use, can be utilized.
(warning) Note: The example projects, provided by Hilscher, do not contain full cifXToolkit adaptions (adaption of OS_Custom.c) which meet requirements for all use cases. It is always necessary and in the responsibility of the user, to adapt and test the cifXToolkit customization, according to the requirements. Particularly when an RTOS is used, the cifX Toolkit must be adapted respectively. Also usage of interrupt mode requires adaption to cifXToolkit customization functions.

3) The host hardware abstraction layer mainly provides functions for data consumption and production, depending on the available hardware. In general the actual generated data is not relevant, dummy data is sufficient. Furthermore the HOSTAL is responsible to provide a service for cyclic function calls (e.g. by using a timer interrupt) for call of App_IODataHandler()

List of C-files

Hardware (target) dependent components of the application





startup.S
embedded systems
main.c
any platform

HostAbstractionLayer.c


any platform
cifX APIcifX Toolkitembedded systems
driverWindows, Linux, etc

Overview HOSTAL functions:

Function GroupFunctioninput argumentsoutput argumentsreturnapplication usage
InitHOSTAL_Init()--HOSTAL_RESULT_EInitialization of Host Abstraction Layer
DeviceHOSTAL_Device_SetStatusHOSTAL_DEVICE_STATUS_E  eStatus-HOSTAL_RESULT_Econtrol e.g. status LEDs on target board


HOSTAL_Device_ClearStatusHOSTAL_DEVICE_STATUS_E  eStatus-HOSTAL_RESULT_E

HOSTAL_Device_GetStatus-HOSTAL_DEVICE_STATUS_E  eStatusHOSTAL_RESULT_E

ActuatorsHOSTAL_Actuator_SetDatauint8_t bActuatorNumber
uint32_t  ulData
-HOSTAL_RESULT_Econsume input IOData
HOSTAL_Actuator_SetModeuint8_t bActuatorNumber
uint8_t   bMode
-HOSTAL_RESULT_EControl actuator
HOSTAL_Actuator_GetStateuint8_t bActuatorNumberuint16_t* pusStatusCodeHOSTAL_PERIPHERAL_STATE_Eprovide output IOData, trigger alarms/errors
SensorsHOSTAL_Sensor_GetDatauint8_t bSensorNumberuint32_t* pulDataHOSTAL_RESULT_E
HOSTAL_Sensor_SetModeuint8_t bSensorNumber
uint8_t   bMode
-HOSTAL_RESULT_E

HOSTAL_Sensor_GetStateuint8_t bSensorNumberuint16_t* pusStatusCodeHOSTAL_PERIPHERAL_STATE_Eprovide output IOData, trigger alarms/errors
Rotary SwitchHOSTAL_RotarySwitch_GetValueuint8_t bRotarySwitchNumberuint8_t* pbValueHOSTAL_RESULT_Eset fieldbus device address, IP address, etc.
Remanent dataHOSTAL_RemanentData_Storechar* szName
uint8_t* pbData
uint32_t ulDataLen

HOSTAL_RESULT_EStore non volatile data in flash
HOSTAL_RemanentData_Loadchar* szName
uint32_t ulMaxDataSize
uint8_t* pbData
uint32_t* pulDataLen
HOSTAL_RESULT_ERead non volatile data from flash
Callback functions

HOSTAL_Callback_Register

HOSTAL_CALLBACK_TYPE_E eClbType
void(*pfnEventClb)(void* pPrm)
void* pPrm

HOSTAL_RESULT_EIOData handler timer interrupt
HOSTAL_Callbacks_Enable--UI_RESULT_E

HOSTAL_Callbacks_Disable--UI_RESULT_E

HelpersHOSTAL_kbhit--intfor terminal handler
HOSTAL_Sleepuint32_t ulSleepTimeMs-voidtimeouts, wait








Please Note!

The offered example applications are provided "as is" for demonstration purposes only. In particular the code is not fully tested, as required for mass production purposes. It is the responsibility of the user to adapt the code to the custom requirements and test it thoroughly! Please note the disclaimer below and the disclaimer delivered with each software example.

Disclaimer

IMPORTANT! Please read this carefully before you install the software!

Copyright (c) Hilscher Gesellschaft fuer Systemautomation mbH. All Rights Reserved.

Exclusion of Liability for this demo software

The following software is intended for and must only be used for reference and in an evaluation laboratory environment. It is provided without charge and is subject to alterations. Hilscher cannot guarantee uninterrupted use thereof, or that the Software is free of errors and defects. The Software was produced and tested by Hilscher with only evaluation laboratory environment.

Hilscher cannot make any warranty that the Software is functional or free of errors when the Software is used by the user. It is the user's obligation to fully test the software in its environment and to ensure proper functionality, qualification and compliance with component specifications.   


1. Disclaimer of Warranty

There is no warranty for the software, to the extent permitted by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide the software "as is" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the software is with you. Should the software prove defective, you assume the cost of all necessary servicing, repair or correction.


2. Limitation of Liability

In no event unless required by applicable law or agreed to in writing will any copyright holder, or any other party who modifies and/or conveys the software as permitted above, be liable to you for damages, including any general, special, incidental or consequential damages arising out of the use or inability to use the software (including but not limited to loss of data or data being rendered inaccurate or losses sustained by you or third parties or a failure of the software to operate with any other softwares), even if such holder or other party has been advised of the possibility of such damages.


If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Software.

By installing or otherwise using the software, you accept the terms of this Agreement.

If you do not agree to the terms of this Agreement, then do not install or use the Software!