Initializing the ftxl device, Periodically calling the event pump – Echelon FTXL User Manual

Page 93

Advertising
background image

FTXL User’s Guide

81

process FTXL events. This function then calls event handler functions (such as

LonNvUpdateOccurred() or LonNvUpdateCompleted()).

The following sections describe the tasks that an FTXL application performs

during its life cycle.

Initializing the FTXL Device

Before your application initializes the FTXL LonTalk protocol stack, it must
initialize the C runtime environment and the operating system.
Your application must call the LonInit() function once during device startup. The

implementation of this function is generated by the LonTalk Interface Developer
utility, and is included in the FtxlDev.c file. This function initializes the FTXL

LonTalk API, the FTXL LonTalk protocol stack, and the FTXL Transceiver. The
main application thread must call this function before it calls any other FTXL

LonTalk API functions.
The LonInit() registers the FTXL device interface data with the FTXL LonTalk
protocol stack. This data defines the network parameters and device interface. If

your application needs to change the network parameters or change the device

interface, it can call the LonExit() function to shut down the FTXL LonTalk
protocol stack, and then call the LonInit() function to restart the protocol stack

with the updated interface.
Add a call the LonInit() function to the beginning of the application’s main
thread. If this function is successful, your application can begin normal

operations, including calling the event pump, as described in

Periodically Calling

the Event Pump

.

Example:

void myMainThread(void) {

LonApiError

sts;

sts = LonInit();

if (sts == LonApiNoError) {

// begin normal operations

}

}

Periodically Calling the Event Pump

As described in

Callbacks and Events

on page 76, your FTXL application must

periodically call the LonEventPump() function to check if there are any
L

ON

W

ORKS

events to process. This function calls specific API functions based on

the type of event, then calls event handler functions to notify the application

layer of these network events. You can call this function from the idle loop
within the main application thread or from any point in your application that is

processed periodically. However, you must call this function from the same

application context (task or thread) that called the the LonInit() function.

The FTXL LonTalk API calls the LonEventReady() callback handler function

whenever an event has been posted. This function is typically called from an

FTXL LonTalk protocol stack task or thread, and you must not call the
LonEventPump() function directly from the callback. However, your application

could define an operating system event which is signaled by the

LonEventReady() callback handler function. From within your application’s

Advertising