This section dissects the example application that is shipped as part of the EtherNet/IP Adapter SDK. The example discussed here does not cover CIP Sync functionality but focuses on a Generic Device (Device Type Number 0x2B) that provides digital I/O functionality via an LED array available on the evaluation board.
The example itself is primarily implemented in the file App.c
with board specific functionality located in files AppPerm.c
and Board.c
. Additional example code is contained in the file AppClass71.c
and the corresponding header file demonstrating the creation of classes, instances, and attributes and modifying their parameter values.
The primary task of main is the initialization of the Texas Instruments driver porting layer (DPL), the system controller interface (SCI), and all the peripheral drivers. After this intial initialization, a task is constructed that implements the CIP and EtherNet/IP functionality.
This task, EI_APP_mainTask
, initializes and opens all peripheral drivers, depending on the SysConfig settings for the project. To enable UART console output, verify that your SysConfig settings are as follows:
These settings result in the following code in ti_drivers_open_close.c
including the declaration of the handle gUartHandle
that is later used in the example code to access the UART.
In EI_APP_maintTask
(App.c) a corresponding callback function is registered by calling OSAL_registerPrintOut
. In the callback function strings are then written to the console output by calling UART_write
from the Texas Instruments driver library:
EI_APP_mainTask
then proceeds with executing EI_APP_init
to set up the EtherNet/IP Adapter. After the initialization, it enters a loop that cyclically processes the Ethernet/IP stack.
Both the main
entry point and the EI_APP_mainTask
task are implemented in App.c
.
In the EI_APP_init
initialization function, calls to the EtherNet/IP adapter API are made the create the inter structures required by the EtherNet/IP stack. EI_API_ADP_new
creates the new adapter, and in EI_API_ADP_setErrorHandlerFunc
the stack error handler is registered.
Based on the definition of QUICK_CONNECT in the predefined symbols section of Code Composer Studio support for the QuickConnect functionality will become available.
After further application specific initialization, a new CIP node is created by calling EI_API_CIP_NODE_new
. Note that this function must be called after EI_API_ADP_new
.
EI_APP_init
is implemented in App.c
.
The function EI_APP_stackInit
performs initialization and starting of the PRU firmware. This function is implemented in p App.c.
EI_APP_cipCreateCallback
creates callback functions for non-volatile data storage and for reset services. Note that the callback function itself taking care of non-volatile data is implemented in AppPerm.c
.
Finally, CIP specific content, such as classes, instances, attributes, and assemblies, is created in EI_APP_cipSetup
. Together with EI_APP_cipGenerateContent
this function will be that requires adaptation by the end user, depending on the device functionality that is to be implemented.
Also, the created attributes are added to the assemblies for cyclic CIP IO data exchange.