Skip to content

Commit dbb1094

Browse files
authored
Merge pull request #3906 from hansu/add-component-demux_generic
Add generic demultiplexer component (demux_generic)
2 parents 804fdc8 + 04c3a6b commit dbb1094

File tree

5 files changed

+509
-0
lines changed

5 files changed

+509
-0
lines changed

docs/src/hal/components.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ To search in the man pages, use the UNIX tool `apropos`.
230230
| link:../man/man9/counter.9.html[counter] |Counts input pulses (deprecated). Use the <<sec:encoder,encoder>> component. | |
231231
| link:../man/man9/ddt.9.html[ddt] |Computes the derivative of the input function. ||
232232
| link:../man/man9/deadzone.9.html[deadzone] |Returns the center if within the threshold. ||
233+
| link:../man/man9/demux_generic.9.html[demux_generic] | Routes a single input signal to one of multiple outputs. ||
233234
| link:../man/man9/div2.9.html[div2] |Quotient of two floating point inputs. ||
234235
| link:../man/man9/hypot.9.html[hypot] |Three-input hypotenuse (Euclidean distance) calculator. ||
235236
| link:../man/man9/ilowpass.9.html[ilowpass] |Low-pass filter with integer inputs and outputs ||
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
= demux_generic(9)
2+
3+
== NAME
4+
5+
demux_generic - routes a single input signal to one of multiple outputs
6+
7+
== SYNOPSIS
8+
9+
**loadrt demux_generic config="**__<input_type><output_type><size>__[,__<input_type><output_type><size>__],...**"**
10+
11+
Types: **b** = bit, **f** = float, **s** = signed integer, **u** = unsigned integer
12+
13+
Example:
14+
**loadrt demux_generic config="**bb8,fu12**"**
15+
16+
17+
== FUNCTIONS
18+
19+
**demux-gen.**_NN_ Depending on the data types can run in either a floating point or non-floating point thread.
20+
21+
== PINS
22+
23+
demux-gen.NN.sel-bit-00 ───────────────────┐
24+
... ─────────────────┐ │
25+
demux-gen.NN.sel-bit-BB ───────────────┐ │ │
26+
demux-gen.NN.sel-int ─────────────┐ │ │ │
27+
┌───────┴─┴─┴─┴───────┐
28+
│ / o───── ├───── demux-gen.NN.out-[bit/float/s32/u32]-00
29+
demux-gen.NN.in-[bit/float/s32/u32] ─────┤ ─────o o───── ├───── ...
30+
│ o───── ├───── demux-gen.NN.out-[bit/float/s32/u32]-MM
31+
demux-gen.NN.suppress-no-input ─────┤ │
32+
demux-gen.NN.debounce-us ─────┤ │
33+
└─────────────────────┘
34+
35+
**demux-gen**.__N__.**suppress-no-input** bit in::
36+
This suppresses changing the output if all select lines are false.
37+
This stops unwanted jumps in output between transitions of input but makes in00 unavailable.
38+
**demux-gen**.__N__.**debounce-us** unsigned in::
39+
sets debounce time in microseconds, e.g. 100000 = a tenth of a second.
40+
The selection inputs must be stable this long before the output
41+
changes. This helps to ignore 'noisy' switches.
42+
**demux-gen**.__N__.**sel-bit-**__BB__ bit in (BB=0..bit width of _size_)::
43+
**demux-gen**.__N__.**sel-int** unsigned in::
44+
The sel-bit pins are only created when the size of the demux_gen
45+
component is an integer power of two.
46+
Together, these determine to which **out**-__MM__ the **in** value is forwarded.
47+
The bit pins are interpreted as binary bits, and the result is simply
48+
added on to the integer pin input. It is expected that either one or
49+
the other would normally be used. However, the possibility exists to
50+
use a higher-order bit to "shift" the values set by the integer pin.
51+
**demux-gen**.__N__.**in-**[**bit**/**float**/**s32**/**u32**] variable-type in::
52+
The input value which is routed to an output depending on the selection pins.
53+
**demux-gen**.__N__.**out-**[**bit**/**float**/**s32**/**u32**]**-**__MM__ variable-type out (M=0..size-1)::
54+
According to the selection bits and/or the selection number, the selected output
55+
follows the **in** value. The other outputs retain the values they had before
56+
resp. zero if they have not been selected yet. Values will be
57+
converted/truncated according to standard C rules. This means, for
58+
example that a float input greater than 2147483647 will give an S32
59+
output of -2147483648.
60+
61+
== PARAMETERS
62+
63+
**demux-gen**.__N__.**elapsed** float r::
64+
Current value of the internal debounce timer for debugging.
65+
**demux-gen**.__N__.**selected** s32 r::
66+
Current value of the internal selection variable after conversion for debugging.
67+
Possibly useful for setting up gray-code switches.
68+
69+
== DESCRIPTION
70+
71+
This component is a general demultiplexer component.
72+
It allows the creation of arbitrary-size demultiplexers (up to
73+
1024 entries) and also supports differing data types on the input and
74+
output pins. The configuration string is a comma-separated list of
75+
code-letters and numbers, such as "bb4,fu12". This would create a
76+
4-element bit-to-bit demux and a 12-element float-to-unsigned demux.
77+
The code letters are:
78+
79+
**b** = bit,
80+
**f** = float,
81+
**s** = signed integer and
82+
**u** = unsigned integer.
83+
84+
The first letter code is the input type, the second is the
85+
output type. The codes are not case-sensitive. The order of the letters
86+
is significant but the position in the string is not. Do not insert any
87+
spaces in the config string. Any non-zero float value will be converted
88+
to a "true" output in bit form. Be wary that float datatypes can be
89+
very, very, close to zero and not actually be equal to zero.
90+
91+
Each demux has its own HAL function and must be added to a thread
92+
separately. If neither input nor output is of type float then the
93+
function is base-thread (non floating-point) safe. Any demux_generic with
94+
a floating point input or output can only be added to a floating-point
95+
thread.
96+
97+
== SEE ALSO
98+
99+
mux_generic(9)
100+
101+
== AUTHOR
102+
103+
Hans Unzner
104+
105+
== LICENSE
106+
107+
GPL
108+

src/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,8 @@ obj-$(CONFIG_BOSS_PLC) += boss_plc.o
878878
boss_plc-objs := hal/components/boss_plc.o $(MATHSTUB)
879879
obj-$(CONFIG_DEBOUNCE) += debounce.o
880880
debounce-objs := hal/components/debounce.o $(MATHSTUB)
881+
obj-$(CONFIG_DEMUX_GENERIC) += demux_generic.o
882+
demux_generic-objs := hal/components/demux_generic.o $(MATHSTUB)
881883
obj-$(CONFIG_ENCODER) += encoder.o
882884
encoder-objs := hal/components/encoder.o $(MATHSTUB)
883885
obj-$(CONFIG_ENUM) += enum.o
@@ -1303,6 +1305,7 @@ endif
13031305
../rtlib/classicladder_rt$(MODULE_EXT): $(addprefix objects/rt,$(classicladder_rt-objs))
13041306
../rtlib/boss_plc$(MODULE_EXT): $(addprefix objects/rt,$(boss_plc-objs))
13051307
../rtlib/debounce$(MODULE_EXT): $(addprefix objects/rt,$(debounce-objs))
1308+
../rtlib/demux_generic$(MODULE_EXT): $(addprefix objects/rt,$(demux_generic-objs))
13061309
../rtlib/encoder$(MODULE_EXT): $(addprefix objects/rt,$(encoder-objs))
13071310
../rtlib/enum$(MODULE_EXT): $(addprefix objects/rt,$(enum-objs))
13081311
../rtlib/counter$(MODULE_EXT): $(addprefix objects/rt,$(counter-objs))

src/Makefile.inc.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ CONFIG_MOTMOD=m
176176
CONFIG_BLOCKS=m
177177
CONFIG_BOSS_PLC=m
178178
CONFIG_DEBOUNCE=m
179+
CONFIG_DEMUX_GENERIC=m
179180
CONFIG_ENCODER=m
180181
CONFIG_ENUM=m
181182
CONFIG_COUNTER=m

0 commit comments

Comments
 (0)