EtherNet/IP™ Adapter  1.04.06
User Reference Manual
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 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.

Main Application

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.

/*
* 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) 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:

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.

Both the main entry point and the EI_APP_mainTask task are implemented 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 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.

PRU Initialization

The function EI_APP_stackInit performs initialization and starting of the PRU firmware. This function is implemented in p 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