Host Application Examples - Structure
- Former user (Deleted)
How to understand the structure of Hilschers host application examples?
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
- Application - YELLOW
- Protocol specific parts - GREEN
- 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.
Nr | Example | Application | Protocol | Hardware Platform |
---|---|---|---|---|
1 | PROFINET simple config | Application Module 1 | Protocol Module Variant 1 | Hardware Module netX 90 APP |
2 | PROFINET extended config | Application Module 1 | Protocol Module Variant 2 | Hardware Module netX 90 APP |
3 | EtherCAT simple config | Application Module 1 | Protocol Module Variant 3 | Hardware Module netX 90 APP |
4 | EtherCAT custom OD | Application Module 1 | Protocol Module Variant 4 | Hardware 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.
Nr | Example | Application | Protocol | Hardware Platform |
---|---|---|---|---|
... | ||||
5 | PROFINET simple config | Application Module 1 | Protocol Module Variant 1 | Hardware Module STM32 |
6 | PROFINET extended config | Application Module 1 | Protocol Module Variant 2 | Hardware 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.c | Body of the application Contains the main loop (cyclic calls of PacketHandler and TerminalHandler) and the IODataHandler |
App_DemoApplicationFunctions.c | Collection of functions used in cifXApplicationDemo.c |
App_PacketCommunication.h | Collection 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.c | Evaluation of system status and generation of alarms and errors |
IO-Data
Output (PLC input) | 10 bytes | provider |
---|---|---|
Cyclic Counter | 2 bytes | global counter variable, handled directly in IODataHandler |
sensor 1 output | 2 bytes | HOSTAL_Sensor_GetData() |
sensor 1 state | 1 byte | HOSTAL_Sensor_GetState() |
sensor 2 output | 2 bytes | HOSTAL_Sensor_GetData() |
sensor 2 state | 1 byte | HOSTAL_Sensor_GetState() |
actuator 1 state | 1 byte | HOSTAL_Actuator_GetState() |
actuator 2 state | 1 byte | HOSTAL_Actuator_GetState() |
Input (PLC output) | 6 bytes | consumer |
---|---|---|
actuator 1 input | 2 bytes | HOSTAL_Actuator_SetData() |
actuator 2 input | 2 bytes | HOSTAL_Actuator_SetData() |
Cyclic counter direction | 1 byte | Handling of global counter variable (Cyclic Counter in output data): up/down counter 0: Cyclic Counter counts up, 1: Cyclic Counter counts down |
Cyclic counter speed | 1 byte | Handling of global counter variable (Cyclic Counter in output data): fast/slow increment/decrement = 0: Cyclic Counter is not incremented/decremented at all |
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:
Protocol_StartConfiguration()
Protocol_PacketHandler()
and subsequentlyAppXXX_Protocol_PacketHandler()
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(), |
AppXXX_DemoApplicationFunctions.c | Collection 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
- initialize the system/application and entry point
main()
- cifX API as base for the application
- 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.
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 API | cifX Toolkit | embedded systems | |
driver | Windows, Linux, etc |
Overview HOSTAL functions:
Function Group | Function | input arguments | output arguments | return | application usage |
---|---|---|---|---|---|
Init | HOSTAL_Init() | - | - | HOSTAL_RESULT_E | Initialization of Host Abstraction Layer |
Device | HOSTAL_Device_SetStatus | HOSTAL_DEVICE_STATUS_E eStatus | - | HOSTAL_RESULT_E | control e.g. status LEDs on target board |
HOSTAL_Device_ClearStatus | HOSTAL_DEVICE_STATUS_E eStatus | - | HOSTAL_RESULT_E | ||
HOSTAL_Device_GetStatus | - | HOSTAL_DEVICE_STATUS_E eStatus | HOSTAL_RESULT_E | ||
Actuators | HOSTAL_Actuator_SetData | uint8_t bActuatorNumber uint32_t ulData | - | HOSTAL_RESULT_E | consume input IOData |
HOSTAL_Actuator_SetMode | uint8_t bActuatorNumber uint8_t bMode | - | HOSTAL_RESULT_E | Control actuator | |
HOSTAL_Actuator_GetState | uint8_t bActuatorNumber | uint16_t* pusStatusCode | HOSTAL_PERIPHERAL_STATE_E | provide output IOData, trigger alarms/errors | |
Sensors | HOSTAL_Sensor_GetData | uint8_t bSensorNumber | uint32_t* pulData | HOSTAL_RESULT_E | |
HOSTAL_Sensor_SetMode | uint8_t bSensorNumber uint8_t bMode | - | HOSTAL_RESULT_E | ||
HOSTAL_Sensor_GetState | uint8_t bSensorNumber | uint16_t* pusStatusCode | HOSTAL_PERIPHERAL_STATE_E | provide output IOData, trigger alarms/errors | |
Rotary Switch | HOSTAL_RotarySwitch_GetValue | uint8_t bRotarySwitchNumber | uint8_t* pbValue | HOSTAL_RESULT_E | set fieldbus device address, IP address, etc. |
Remanent data | HOSTAL_RemanentData_Store | char* szName uint8_t* pbData uint32_t ulDataLen | HOSTAL_RESULT_E | Store non volatile data in flash | |
HOSTAL_RemanentData_Load | char* szName uint32_t ulMaxDataSize | uint8_t* pbData uint32_t* pulDataLen | HOSTAL_RESULT_E | Read non volatile data from flash | |
Callback functions | HOSTAL_Callback_Register | HOSTAL_CALLBACK_TYPE_E eClbType void(*pfnEventClb)(void* pPrm) void* pPrm | HOSTAL_RESULT_E | IOData handler timer interrupt | |
HOSTAL_Callbacks_Enable | - | - | UI_RESULT_E | ||
HOSTAL_Callbacks_Disable | - | - | UI_RESULT_E | ||
Helpers | HOSTAL_kbhit | - | - | int | for terminal handler |
HOSTAL_Sleep | uint32_t ulSleepTimeMs | - | void | timeouts, wait | |
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.
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!