#LyX 1.3 created this file. For more info see http://www.lyx.org/ \lyxformat 221 \textclass book \begin_preamble \usepackage[plainpages=false,pdfpagelabels,colorlinks=true,linkcolor=blue]{hyperref} \end_preamble \language english \inputencoding default \fontscheme bookman \graphics default \float_placement !htbp \paperfontsize default \spacing single \papersize letterpaper \paperpackage a4 \use_geometry 1 \use_amsmath 1 \use_natbib 0 \use_numerical_citations 0 \paperorientation portrait \leftmargin 1in \topmargin 1in \rightmargin 0.8in \bottommargin 0.8in \secnumdepth 1 \tocdepth 5 \paragraph_separation skip \defskip smallskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Chapter \emph on comp \emph default : a tool for creating HAL modules \layout Section Introduction \layout Standard Writing a HAL component can be a tedious process, most of it in setup calls to \family typewriter rtapi_ \family default and \family typewriter hal_ \family default functions and associated error checking. \emph on comp \emph default will write all this code for you, automatically. \layout Standard Compiling a HAL component is also much easier when using \emph on comp \emph default , whether the component is part of the emc2 source tree, or outside it. \layout Standard For instance, the \begin_inset Quotes eld \end_inset ddt \begin_inset Quotes erd \end_inset portion of \family typewriter blocks \family default is around 80 lines of code. The equivalent component is very short when written using the \emph on comp \emph default preprocessor: \layout LyX-Code component ddt "Compute the derivative of the input function"; \newline pin in float in; \newline pin out float out; \newline variable float old; \newline function _; \newline license "GPL"; \newline ;; \newline float tmp = in; \newline out = (tmp - old) / fperiod; \newline old = tmp; \layout Standard and it can be compiled and installed very easily: by simply placing \family typewriter ddt.comp \family default in \family typewriter src/hal/components \family default and running ' \family typewriter make \family default ', or by placing it anywhere on the system and running \family typewriter comp --install ddt.comp \layout Section Definitions \layout Description component A component is a single real-time module, which is loaded with \family typewriter halcmd loadrt \family default . One \family typewriter .comp \family default file specifies one component. \layout Description instance A component can have zero or more instances. Each instance of a component is created equal (they all have the same pins, parameters, functions, and data) but behave independently when their pins, parameters, and data have different values. \layout Description singleton It is possible for a component to be a 'singleton', in which case exactly one instance is created. It seldom makes sense to write a \family typewriter singleton \family default component, unless there can literally only be a single object of that kind in the system (for instance, a component whose purpose is to provide a pin with the current UNIX time, or a hardware driver for the internal PC speaker) \layout Section Instance creation \layout Standard For a singleton, the one instance is created when the component is loaded. \layout Standard For a non-singleton, the ' \family typewriter count \family default ' module parameter determines how many numbered instances are created. \layout Section Syntax \layout Standard A \family typewriter .comp \family default file consists of a number of declarations, followed by \family typewriter ;; \family default on a line of its own, followed by C code implementing the module's functions. \layout Standard Declarations include: \layout Itemize \family typewriter component \emph on HALNAME \emph default \emph on (DOC \emph default ); \layout Itemize \family typewriter pin \emph on PINDIRECTION \emph default \emph on TYPE \emph default \emph on HALNAME \emph default ([ \emph on SIZE \emph default ]|[ \emph on MAXSIZE \emph default : \emph on CONDSIZE] \emph default ) (if \emph on CONDITION \emph default ) (= \emph on STARTVALUE \emph default ) ( \emph on DOC \emph default ); \layout Itemize \family typewriter param \emph on PARAMDIRECTION \emph default \emph on TYPE \emph default \emph on HALNAME \emph default ([ \emph on SIZE \emph default ]|[ \emph on MAXSIZE \emph default : \emph on CONDSIZE] \emph default ) (if \emph on CONDITION) \emph default (= \emph on STARTVALUE \emph default ) ( \emph on DOC \emph default ) ; \layout Itemize \family typewriter function \emph on HALNAME \emph default (fp | nofp) ( \emph on DOC \emph default ); \layout Itemize \family typewriter option \emph on OPT \emph default ( \emph on VALUE \emph default ); \layout Itemize \family typewriter variable \emph on CTYPE NAME \emph default ([ \emph on SIZE \emph default ]); \layout Itemize \family typewriter description DOC; \layout Itemize \family typewriter see_also DOC; \layout Itemize \family typewriter license LICENSE; \layout Standard Parentheses indicate optional items. A vertical bar indicates alternatives. Words in \emph on CAPITALS \emph default indicate variable text, as follows: \layout Description HALNAME An identifier. \begin_deeper \layout Standard When used to create a HAL identifier, any underscores are replaced with dashes, and any trailing dash or period is removed, so that \begin_inset Quotes eld \end_inset this_name_ \begin_inset Quotes erd \end_inset will be turned into \begin_inset Quotes eld \end_inset this-name \begin_inset Quotes erd \end_inset , and if the name is \begin_inset Quotes eld \end_inset \family typewriter _ \family default \begin_inset Quotes erd \end_inset , then a trailing period is removed as well, so that \begin_inset Quotes eld \end_inset \family typewriter function _ \family default \begin_inset Quotes erd \end_inset gives a HAL function name like \family typewriter component. \family default instead of \family typewriter component.. \layout Standard If present, the prefix \family typewriter hal_ \family default is removed from the beginning of the component name when creating pins, parameters and functions. \layout Standard In the HAL identifier for a pin or parameter, # denotes an array item, and must be used in conjunction with a \family typewriter [SIZE] \family default declaration. The hash marks are replaced with a 0-padded number with the same length as the number of # characters. \layout Standard When used to create a C identifier, the following changes are applied to the HALNAME: \layout Enumerate Any # characters, and any \begin_inset Quotes eld \end_inset . \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset _ \begin_inset Quotes erd \end_inset or \begin_inset Quotes eld \end_inset - \begin_inset Quotes erd \end_inset characters immediately before them, are removed. \layout Enumerate Any remaining \begin_inset Quotes eld \end_inset . \begin_inset Quotes erd \end_inset and \begin_inset Quotes eld \end_inset - \begin_inset Quotes erd \end_inset characters are replaced with \begin_inset Quotes eld \end_inset _ \begin_inset Quotes erd \end_inset \layout Enumerate Repeated \begin_inset Quotes eld \end_inset _ \begin_inset Quotes erd \end_inset characters are changed to a single \begin_inset Quotes eld \end_inset _ \begin_inset Quotes erd \end_inset character. \layout Standard A trailing _ is retained, so that HAL identifiers which would otherwise collide with reserved names or keywords (e.g., 'min') can be used. \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard HALNAME \end_inset \begin_inset Text \layout Standard C Identifier \end_inset \begin_inset Text \layout Standard HAL Identifier \end_inset \begin_inset Text \layout Standard x_y_z \end_inset \begin_inset Text \layout Standard x_y_z \end_inset \begin_inset Text \layout Standard x-y-z \end_inset \begin_inset Text \layout Standard x-y.z \end_inset \begin_inset Text \layout Standard x_y_z \end_inset \begin_inset Text \layout Standard x-y.z \end_inset \begin_inset Text \layout Standard x_y_z_ \end_inset \begin_inset Text \layout Standard x_y_z \end_inset \begin_inset Text \layout Standard x-y-z \end_inset \begin_inset Text \layout Standard x.##.y \end_inset \begin_inset Text \layout Standard x_y(MM) \end_inset \begin_inset Text \layout Standard x.MM.z \end_inset \begin_inset Text \layout Standard x.## \end_inset \begin_inset Text \layout Standard x(MM) \end_inset \begin_inset Text \layout Standard x.MM \end_inset \end_inset \end_deeper \layout Description if\SpecialChar ~ CONDITION An expression involving the variable \emph on personality \emph default which is nonzero when the pin or parameter should be created \layout Description SIZE A number that gives the size of an array. The array items are numbered from 0 to \emph on SIZE \emph default -1. \layout Description MAXSIZE\SpecialChar ~ :\SpecialChar ~ CONDSIZE A number that gives the maximum size of the array followed by an expression involving the variable \emph on personality \emph default and which always evaluates to less than \emph on MAXSIZE \emph default . When the array is created its size will be \emph on CONDSIZE \emph default . \layout Description DOC A string that documents the item. String can be a C-style \begin_inset Quotes eld \end_inset double quoted \begin_inset Quotes erd \end_inset string, like \family typewriter "Selects the desired edge: TRUE means falling, FALSE means rising" \family default or a Python-style \begin_inset Quotes eld \end_inset triple quoted \begin_inset Quotes erd \end_inset string, which may include embedded newlines and quote characters, such as: \begin_deeper \layout LyX-Code param rw bit zot=TRUE \newline """The effect of this parameter, also known as "the orb of zot", \newline will require at least two paragraphs to explain. \newline \newline Hopefully these paragraphs have allowed you to understand "zot" \newline better."""; \layout Standard The documentation string is in \begin_inset Quotes eld \end_inset groff -man \begin_inset Quotes erd \end_inset format. For more information on this markup format, see \family typewriter groff_man(7) \family default . Remember that comp interprets backslash escapes in strings, so for instance to set the italic font for the word \emph on example \emph default , write \family typewriter " \backslash \backslash fIexample \backslash \backslash fB" \family default . \end_deeper \layout Description TYPE One of the HAL types: \family typewriter bit \family default , \family typewriter signed \family default , \family typewriter unsigned \family default , or \family typewriter float \family default . The old names \family typewriter s32 \family default and \family typewriter u32 \family default may also be used, but \family typewriter signed \family default and \family typewriter unsigned \family default are preferred. \layout Description PINDIRECTION One of the following: \family typewriter in \family default , \family typewriter out \family default , or \family typewriter io \family default . A component sets a value for an \family typewriter out \family default pin, it reads a value from an \family typewriter in \family default pin, and it may read or set the value of an \family typewriter io \family default pin. \layout Description PARAMDIRECTION One of the following: \family typewriter r \family default or \family typewriter rw \family default . A component sets a value for a \family typewriter r \family default parameter, and it may read or set the value of a \family typewriter rw \family default parameter. \layout Description STARTVALUE Specifies the initial value of a pin or parameter. If it is not specified, then the default is \family typewriter 0 \family default or \family typewriter FALSE \family default , depending on the type of the item. \layout Description fp Indicates that the function performs floating-point calculations. \layout Description nofp Indicates that it only performs integer calculations. If neither is specified, \family typewriter fp \family default is assumed. Neither comp nor gcc can detect the use of floating-point calculations in functions that are tagged \family typewriter nofp \family default . \layout Description OPT,\SpecialChar ~ VALUE Depending on the option name OPT, the valid VALUEs vary. The currently defined options are: \begin_deeper \layout Description option\SpecialChar ~ singleton\SpecialChar ~ yes (default: no) \begin_deeper \layout Standard Do not create a \family typewriter count \family default module parameter, and always create a single instance. With \family typewriter singleton \family default , items are named \family typewriter component-name.item-name \family default and without \family typewriter singleton \family default , items for numbered instances are named \family typewriter component-name..item-name \family default . \end_deeper \layout Description option\SpecialChar ~ default_count\SpecialChar ~ \emph on number \emph default (default: 1) \begin_deeper \layout Standard Normally, the module parameter \family typewriter count \family default defaults to 0. If specified, the \family typewriter count \family default will default to this value instead. \end_deeper \layout Description option\SpecialChar ~ count_function\SpecialChar ~ yes (default: no) \begin_deeper \layout Standard Normally, the number of instances to create is specified in the module parameter \family typewriter count \family default ; if \family typewriter count_function \family default is specified, the value returned by the function \family typewriter int get_count(void) \family default is used instead, and the \family typewriter count \family default module parameter is not defined. \end_deeper \layout Description option\SpecialChar ~ rtapi_app\SpecialChar ~ no (default: yes) \begin_deeper \layout Standard Normally, the functions \family typewriter rtapi_app_main \family default and \family typewriter rtapi_app_exit \family default are automatically defined. With \family typewriter option rtapi_app no \family default , they are not, and must be provided in the C code. \layout Standard When implementing your own \family typewriter rtapi_app_main \family default , call the function \family typewriter int export(char *prefix, long extra_arg) \family default to register the pins, parameters, and functions for \family typewriter prefix \family default . \end_deeper \layout Description option\SpecialChar ~ data\SpecialChar ~ \emph on type \emph default (default: none) \series bold \noun on deprecated \begin_deeper \layout Standard If specified, each instance of the component will have an associated data block of \emph on type \emph default (which can be a simple type like \family typewriter float \family default or the name of a type created with \family typewriter typedef \family default ). \layout Standard In new components, \emph on variable \emph default should be used instead. \end_deeper \end_deeper \layout Description option\SpecialChar ~ extra_setup\SpecialChar ~ yes (default: no) \begin_deeper \begin_deeper \layout Standard If specified, call the function defined by \family typewriter EXTRA_SETUP \family default for each instance. If using the automatically defined \family typewriter rtapi_app_main \family default , \family typewriter extra_arg \family default is the number of this instance. \end_deeper \layout Description option\SpecialChar ~ extra_cleanup\SpecialChar ~ yes (default: no) \begin_deeper \layout Standard If specified, call the function defined by \family typewriter EXTRA_CLEANUP \family default from the automatically defined \family typewriter rtapi_app_exit \family default , or if an error is detected in the automatically defined \family typewriter rtapi_app_main \family default . \end_deeper \layout Description option\SpecialChar ~ userspace\SpecialChar ~ yes (default: no) \begin_deeper \layout Standard If specified, this file describes a userspace component, rather than a real one. A userspace component may not have functions defined by the \family typewriter function \family default directive. Instead, after all the instances are constructed, the C function \family typewriter user_mainloop() \family default is called. When this function returns, the component exits. Typically, \family typewriter user_mainloop() \family default will use \family typewriter FOR_ALL_INSTS() \family default to perform the update action for each instance, then sleep for a short time. Another common action in \family typewriter user_mainloop() \family default may be to call the event handler loop of a GUI toolkit. \end_deeper \layout Description option\SpecialChar ~ userinit\SpecialChar ~ yes (default: no) \begin_deeper \layout Standard If specified, the function \family typewriter userinit(argc,argv) \family default is called before \family typewriter rtapi_app_main() \family default (and thus before the call to \family typewriter hal_init() \family default ). This function may process the commandline arguments or take other actions. Its return type is \family typewriter void \family default ; it may call \family typewriter exit() \family default if it wishes to terminate rather than create a hal component (for instance, because the commandline arguments were invalid). \end_deeper \layout Standard If an option's VALUE is not specified, then it is equivalent to specifying \family typewriter option \SpecialChar \ldots{} yes \family default . The result of assigning an inappropriate value to an option is undefined. The result of using any other option is undefined. \end_deeper \layout Description LICENSE Specify the license of the module, for the documentation and for the MODULE_LICENSE() module declaration. \layout Section Per-instance data storage \layout Description variable\SpecialChar ~ \emph on CTYPE\SpecialChar ~ NAME \emph default ; \layout Description variable\SpecialChar ~ \emph on CTYPE\SpecialChar ~ NAME \emph default [ \emph on SIZE \emph default ]; \layout Description variable\SpecialChar ~ \emph on CTYPE\SpecialChar ~ NAME \emph default \SpecialChar ~ =\SpecialChar ~ \emph on DEFAULT \emph default ; \layout Description variable\SpecialChar ~ \emph on CTYPE\SpecialChar ~ NAME \emph default [ \emph on SIZE \emph default ]\SpecialChar ~ =\SpecialChar ~ \emph on DEFAULT \emph default ; \begin_deeper \layout Standard Declare a per-instance variable \emph on NAME \emph default of type \emph on CTYPE \emph default , optionally as an array of \emph on SIZE \emph default items, and optionally with a default value \emph on DEFAULT \emph default . Items with no \emph on DEFAULT \emph default are initialized to all-bits-zero. \emph on CTYPE \emph default is a simple one-word C type, such as \family typewriter float \family default , \family typewriter u32 \family default , \family typewriter s32 \family default , etc. \end_deeper \layout Standard C++-style one-line comments ( \family typewriter // \SpecialChar \ldots{} \family default ) and C-style multi-line comments ( \family typewriter /* \SpecialChar \ldots{} */ \family default ) are both supported in the declaration section. \layout Section Other restrictions on comp files \layout Standard Though HAL permits a pin, a parameter, and a function to have the same name, comp does not. \layout Section Convenience Macros \layout Standard Based on the items in the declaration section, \emph on comp \emph default creates a C structure called \family typewriter struct state \family default . However, instead of referring to the members of this structure (e.g., \family typewriter *(inst->name) \family default ), they will generally be referred to using the macros below. The details of \family typewriter struct state \family default and these macros may change from one version of \emph on comp \emph default to the next. \layout Description FUNCTION(name) Use this macro to begin the definition of a realtime function which was previously declared with ' \family typewriter function NAME \family default '. The function includes a parameter ' \family typewriter period \family default ' which is the integer number of nanoseconds between calls to the function. \layout Description EXTRA_SETUP() Use this macro to begin the definition of the function called to perform extra setup of this instance. Return a negative Unix \family typewriter errno \family default value to indicate failure (e.g., \family typewriter return -EBUSY \family default on failure to reserve an I/O port), or 0 to indicate success. \layout Description EXTRA_CLEANUP() Use this macro to begin the definition of the function called to perform extra cleanup of the component. Note that this function must clean up all instances of the component, not just one. The 'pin_name', 'parameter_name', and 'data' macros may not be used here. \layout Description \emph on pin_name \layout Description \emph on parameter_name \emph default For each pin \family typewriter pin_name \family default or param \family typewriter parameter_name \family default there is a macro which allows the name to be used on its own to refer to the pin or parameter. \begin_deeper \layout Standard When \family typewriter pin_name \family default or \family typewriter parameter_name \family default is an array, the macro is of the form \emph on pin_name(idx) \emph default or \emph on param_name(idx) \emph default where \emph on idx \emph default is the index into the pin array. When the array is a variable-sized array, it is only legal to refer to items up to its \emph on condsize \emph default . \layout Standard When the item is a conditional item, it is only legal to refer to it when its \emph on condition \emph default evalued to a nonzero value. \end_deeper \layout Description \emph on variable_name \emph default For each variable \family typewriter variable_name \family default there is a macro which allows the name to be used on its own to refer to the variable. When \family typewriter variable_name \family default is an array, the normal C-style subscript is used: \emph on variable_name[idx] \layout Description data If 'option data' is specified, this macro allows access to the instance data. \layout Description fperiod The floating-point number of seconds between calls to this realtime function. \layout Description FOR_ALL_INSTS()\SpecialChar ~ { \family typewriter \SpecialChar \ldots{} \family default } For userspace components. This macro uses the variable \family typewriter struct state *inst \family default to iterate over all the defined instances. Inside the body of the loop, the \series bold \emph on pin_name \series default \emph default , \series bold \emph on parameter_name \series default \emph default , and \series bold data \series default macros work as they do in realtime functions. \layout Section Components with one function \layout Standard If a component has only one function and the string \begin_inset Quotes eld \end_inset FUNCTION \begin_inset Quotes erd \end_inset does not appear anywhere after \family typewriter ;; \family default , then the portion after \family typewriter ;; \family default is all taken to be the body of the component's single function. \layout Section Component \begin_inset Quotes eld \end_inset Personality \begin_inset Quotes erd \end_inset \layout Standard If a component has any pins or parameters with an \begin_inset Quotes eld \end_inset if \emph on condition \emph default \begin_inset Quotes erd \end_inset or \begin_inset Quotes eld \end_inset [ \emph on maxsize : condsize \emph default ] \begin_inset Quotes erd \end_inset , it is called a component with \begin_inset Quotes eld \end_inset \emph on personality \emph default \begin_inset Quotes erd \end_inset . The \begin_inset Quotes eld \end_inset personality \begin_inset Quotes erd \end_inset of each instance is specified when the module is loaded. \begin_inset Quotes eld \end_inset Personality \begin_inset Quotes erd \end_inset can be used to create pins only when needed. For instance, personality is used in the \family typewriter logic \family default component, to allow for a variable number of input pins to each logic gate and to allow for a selection of any of the basic boolean logic functions \series bold and \series default , \series bold or \series default , and \series bold xor \series default . \layout Section Compiling \family typewriter .comp \family default files in the source tree \layout Standard Place the \family typewriter .comp \family default file in the source directory \family typewriter emc2/src/hal/components \family default and re-run \family typewriter make \family default . \family typewriter Comp \family default files are automatically detected by the build system. \layout Standard If a \family typewriter .comp \family default file is a driver for hardware, it may be placed in \family typewriter emc2/src/hal/components \family default and will be built except if emc2 is configured as a userspace simulator. \layout Section Compiling realtime components outside the source tree \layout Standard \family typewriter comp \family default can process, compile, and install a realtime component in a single step, placing \family typewriter rtexample.ko \family default in the emc2 realtime module directory: \layout LyX-Code comp \SpecialChar \- \SpecialChar \- install rtexample.comp \layout Standard Or, it can process and compile in one step, leaving \family typewriter example.ko \family default (or \family typewriter example.so \family default for the simulator) in the current directory: \layout LyX-Code comp --compile rtexample.comp \layout Standard Or it can simply process, leaving \family typewriter example.c \family default in the current directory: \layout LyX-Code comp rtexample.comp \layout Standard \family typewriter comp \family default can also compile and install a component written in C, using the \family typewriter --install \family default and \family typewriter --compile \family default options shown above: \layout LyX-Code comp --install rtexample2.c \layout Standard man-format documentation can also be created from the information in the declaration section: \layout LyX-Code comp --document rtexample.comp \layout Standard The resulting manpage, \family typewriter example.9 \family default can be viewed with \layout LyX-Code man ./example.9 \layout Standard or copied to a standard location for manual pages. \layout Section Compiling userspace components outside the source tree \layout Standard \family typewriter comp \family default can process, compile, install, and document userspace components: \layout LyX-Code comp usrexample.comp \newline comp --compile usrexample.comp \newline comp --install usrexample.comp \newline comp --document usrexample.comp \layout Standard This only works for \family typewriter .comp \family default files, not for \family typewriter .c \family default files. \layout Section Examples \layout Subsection constant \layout Standard This component functions like the one in 'blocks', including the default value of 1.0. The declaration \begin_inset Quotes eld \end_inset function _ \begin_inset Quotes erd \end_inset creates functions named 'constant.0', etc. \layout LyX-Code component constant; \newline pin out float out; \newline param r float value = 1.0; \newline function _; \newline option extra_setup yes; \newline ;; \newline FUNCTION(_) { out = value; } \layout Subsection sincos \layout Standard This component computes the sine and cosine of an input angle in radians. It has different capabilities than the 'sine' and 'cosine' outputs of siggen, because the input is an angle, rather than running freely based on a 'frequency ' parameter. \layout Standard The pins are declared with the names \family typewriter sin_ \family default and \family typewriter cos_ \family default in the source code so that they do not interfere with the functions \family typewriter sin() \family default and \family typewriter cos() \family default . The HAL pins are still called \family typewriter sincos..sin \family default . \layout LyX-Code component sincos; \newline pin out float sin_ out; \newline pin out float cos_ out; \newline pin in float theta in; \newline function _; \newline ;; \newline #include \newline FUNCTION(_) { sin_ = sin(theta); cos_ = cos(theta); } \layout Subsection out8 \layout Standard This component is a driver for a \emph on fictional \emph default card called \begin_inset Quotes eld \end_inset out8 \begin_inset Quotes erd \end_inset , which has 8 pins of digital output which are treated as a single 8-bit value. There can be a varying number of such cards in the system, and they can be at various addresses. The pin is called \family typewriter out_ \family default because \family typewriter out \family default is an identifier used in \family typewriter \family default . It illustrates the use of \family typewriter EXTRA_SETUP \family default and \family typewriter EXTRA_CLEANUP \family default to request an I/O region and then free it in case of error or when the module is unloaded. \layout LyX-Code \begin_inset Include \verbatiminput{out8.comp} preview false \end_inset \layout Subsection hal_loop \layout LyX-Code component hal_loop; \newline pin out float example; \layout Standard This fragment of a component illustrates the use of the \family typewriter hal_ \family default prefix in a component name. \family typewriter loop \family default is the name of a standard Linux kernel module, so a \family typewriter loop \family default component might not successfully load if the Linux \family typewriter loop \family default module was also present on the system. \layout Standard When loaded, \family typewriter halcmd show comp \family default will show a component called \family typewriter hal_loop \family default . However, the pin shown by \family typewriter halcmd show pin \family default will be \family typewriter loop.0.example \family default , not \family typewriter hal-loop.0.example \family default . \layout Subsection arraydemo \layout Standard This realtime component illustrates use of fixed-size arrays: \layout LyX-Code component arraydemo "4-bit Shift register"; \newline pin in bit in; \newline pin out bit out-# [4]; \newline function _ nofp; \newline ;; \newline int i; \newline for(i=3; i>0; i--) out(i) = out(i-1); \newline out(0) = in; \layout Subsection rand \layout Standard This userspace component changes the value on its output pin to a new random value in the range \begin_inset Formula $[0,1)$ \end_inset about once every 1ms. \layout LyX-Code \begin_inset Include \verbatiminput{rand.comp} preview false \end_inset \layout Subsubsection logic \layout Standard This realtime component shows how to use \begin_inset Quotes eld \end_inset personality \begin_inset Quotes erd \end_inset to create variable-size arrays and optional pins. \layout LyX-Code \begin_inset Include \verbatiminput{../../../src/hal/components/logic.comp} preview false \end_inset \layout Standard A typical load line for this component might be \layout LyX-Code loadrt logic count=3 personality=0x102,0x305,0x503 \layout Standard which creates the following pins: \layout Itemize A 2-input AND gate: logic.0.and, logic.0.in-00, logic.0.in-01 \layout Itemize 5-input AND and OR gates: logic.1.and, logic.1.or, logic.1.in-00, logic.1.in-01, logic.1.in-02, logic.1.in-03, logic.1.in-04, \layout Itemize 3-input AND and XOR gates: logic.2.and, logic.2.xor, logic.2.in-00, logic.2.in-01, logic.2.in-02 \the_end