Initializing the Stack

The application must initialize the LayGO protocol stack to make protocol services available. The application initializes the stack by calling the API function lgo_InitializeStack(). Stack initialization accomplishes a number of important tasks:

Buffer pool initialization
The LSX uses fixed size, static allocated buffers for data transmission and internal stack communication. During initialization, the buffer pool is allocated based on a user-supplied configuration profile.
Hardware initialization
The installed communication hardware is located, tested and initialized based on a user-supplied configuration profile.
Layer initialization
Each protocol layer is called to initialize its internal data structures. The default configuration profile for each layer is established at this time.
System time initialization
The stack keeps its own internal system time for the operation of timers used by the protocol layers.
Stack activation control
The protocol stack is normally activated by a timer. If this method of activation is chosen, the timer routine that activates the stack is installed.

Prior to initializing the stack, the application can set configuration parameters for the hardware, buffer pool, system stack and protocol layers. Configuration profiles can be prepared in advance and loaded from disk at runtime using the API function lgo_ConfigureStack(). (Configuration files are created and edited using the utility program edcfg. See Using edcfg in the LayGO Configuration Manual). Alternatively, lgo_SetDefaultConfiguration() can be used to configure the stack without using configuration files.

Once the stack has been initialized, a call to lgo_EnableStack() enables stack activation.

The function dlg_InitializeStack() in the dlaygo sample program, illustrates a typical sequence of events.

At program termination, lgo_UninitializeStack() must be called to free memory and other system resources, shut down the communication hardware and uninstall any interrupt service routines. If the application terminates using the standard C Library function exit(), the standard C Library function atexit() can be used to register a function which will automatically call lgo_UninitializeStack() at termination. In some operating environments, if an application aborts without performing its exit routine, the computer may need to be rebooted.

The dlaygo sample program illustrates this technique by registering the function dlg_AtExit() using atexit().