Chapter 5
Generated Code Architecture
©
National Instruments Corporation
5-37
UserCode Block
The purpose of the UserCode Block (UCB) is to interface your existing
code with AutoCode-generated source code. A UCB is typically used to
access low-level device drivers or any algorithm not easily modeled within
the diagram.
Unfortunately, there are various types of UCBs with slightly different
interfaces. The following two categories divide the types of UCBs:
•
UCBs intended to be linked directly back into the SystemBuild
Simulator
•
UCBs intended to be linked with AutoCode-generated code
For a discussion of the details of the UCB interface, refer to Chapter 2,
, and Chapter 3,
.
Phases of the UCB
The UserCode Block has Init, Output, and State update phases. Due to
reasons of efficient code generation in a discrete system, more than one
phase may be enabled for a call to the UCB. Specifically, a UCB in a
discrete system will have both Output and State phases enabled during the
same call to the UCB. In a continuous system, the Output and State phases
are not enabled during the same call and thus the UCB is called once for the
Output phase then again for the State phase.
You can prevent potential problems by coding your UCB such that the code
for each of the phases is in the following order: Init, Output, then State.
Indirect Terms
If any of the terms of a UCB are specified as indirect, either in a continuous
or a discrete model, the UCB will be called twice within the subsystem,
once for just the Output phase and then once for the State phase.
Note
It is possible to get warnings about using a variable before it is set when compiling
code which contains UCBs with indirect terms. This is because the UCB will be ordered
in such a way that the inputs to the indirect terms have not been computed. This is exactly
what is meant with indirect terms and this warning will not cause a computational error,
assuming the UCB obeys its own indirect term specification.