Callbacks and events, Integrating the, Application with an operating system in – Echelon LonTal Stack User Manual
Page 120
108
Developing a LonTalk Stack Device Application
o
Future versions or fixes to the LonTalk Stack might affect these
API files
Callbacks and Events
The LonTalk API uses two types of notifications for occurrences within the
system: callbacks and events.
The LonTalk API uses a callback when the API needs a return value from the
application immediately. A callback can occur in one of the LonTalk host stack
contexts (tasks or threads).
When you implement a callback handler function to process a callback, you must
ensure that the function completes its work as quickly as possible. Generally, a
callback handler function must not call LonTalk API functions or perform
time-intensive operations.
The LonTalk API uses an event to deliver a one-way notification to the
application. The protocol stack does not wait for the processing of the event to
complete before continuing.
The LonTalk host stack holds events in an internal queue for processing. Thus,
the application program must periodically call the LonEventPump() function to
process the event queue. This function also calls the related event handler
functions.
Because event processing in the event handler functions is not tied to the context
of the protocol stack, an event handler function can call LonTalk API functions or
perform time-intensive operations. An event handler function runs within the
same context (task or thread) as its caller (the LonEventPump() function).
See Appendix D, LonTalk API, for a list of the callback handler functions and
event handler functions.
Integrating the Application with an Operating System
The LonTalk host stack requires a LonTalk Stack application to use an operating
system or include code that implements key operating system services. The
LonTalk Host stack does not require the operating system to be a real-time
operating system.
To allow the LonTalk Host stack to use any operating system, the LonTalk Host
stack library is linked with the Operating System Abstraction Layer (OSAL)
files, Osal.h and Osal.c (Windows) or PosixOsal.c (Linux). The OSAL files
provide macros and C functions for general operating system functions, such as
creating semaphores and waiting for events. The OSAL functions also include
error handling and basic debug tracing for the operating system functions.
Your LonTalk Stack application can call the OSAL functions when it needs to call
operating system functions, or it can call the operating system functions directly.
By calling OSAL functions, your LonTalk Stack application can be more easily
ported to another operating system, if needed.
The OSAL function prototypes are generic, and do not depend on the operating
system’s syntax. For example, to create a binary semaphore, your application
can call the OsalCreateBinarySemaphore() function, which in turn calls the
operating system’s function to create the semaphore. The OSAL function assigns