EtherNet/IP™ Adapter  2.01.00
Dissecting the EtherNet/IP Adapter Example

Scope

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 files appProduct.c and 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.

Main Application

The primary task of main is the initialization of the Texas Instruments driver porting layer (DPL), the selection of the PRU-ICSS instance, PHY devices, and the configuration of the task priorities. After this intial setup, a task is constructed that implements the CIP and EtherNet/IP functionality.

This task, implemented in function 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.

/*
* UART
*/
/* UART Driver handles */
UART_Handle gUartHandle[CONFIG_UART_NUM_INSTANCES];
/* UART Driver Parameters */
UART_Params gUartParams[CONFIG_UART_NUM_INSTANCES] =
{
{
.baudRate = 115200,
.dataLength = UART_LEN_8,
.stopBits = UART_STOPBITS_1,
.parityType = UART_PARITY_NONE,
:
:
:

In EI_APP_maintTask (app.c) CUST_DRIVERS_init is called to initialize different drivers suh as QSPI, I2C, and UART. Furthermore a corresponding callback function for UART output can 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:

OSAL_registerPrintOut(NULL, EI_APP_osPrintfCb);
void EI_APP_osPrintfCb(void* pContext_p, const char* __restrict pFormat_p, va_list argptr_p)
{
/* @cppcheck_justify{unusedVariable} false-positive: variable is used */
//cppcheck-suppress unusedVariable
int32_t transferOK;
/* @cppcheck_justify{unusedVariable} false-positive: variable is used */
//cppcheck-suppress unusedVariable
UART_Transaction transaction;
OSALUNREF_PARM(pContext_p);
UART_Transaction_init(&transaction);
memset(aOutStream_s, 0, sizeof(aOutStream_s));
(void)vsnprintf(aOutStream_s, sizeof(aOutStream_s), pFormat_p, argptr_p);
transaction.count = strlen(aOutStream_s);
transaction.buf = (void *)aOutStream_s;
transaction.args = NULL;
transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &transaction);
(void)transferOK;
}

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.

The main entry point is implemented in appProduct.c and the EI_APP_mainTask function in app.c.

EtherNet/IP Adapter Application Initialization

In the EI_APP_init initialization function, calls to the EtherNet/IP adapter API are made the create the internal 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 TIME_SYNC in the predefined symbols section of Code Composer Studio support for the Time Sync functionality will become available. Depending on an equivalent test for QUICK_CONNECT quickconnect functionality will be enabled.

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.

PRU Initialization

The function EI_APP_stackInit performs initialization and starting of the PRU firmware. This function is implemented in app.c.

Create Callback Functions for predefined CIP Objects

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.

Create Vendor specific Content and Callback Functions for predefined CIP Objects

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.

Create Vendor specific Instances and Attributes

Web Server Task

Starting with version 2.1, the EtherNet/IP stack contains an example how to implement a small HTTP server application. The corresonding code can be found in the files appWebServer.c, appWebServer.h, and appWebServerData.h. The HTML definitions for the page layout are contained in appWebServerData.h.

The web server and the corresponding background task are enabled by adding CPU_LOAD_MONITOR == 1 to the list of predefined symbols in Code Composer Studio.