Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/hal/components/and.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
component and "Multi input AND gate";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component naming and and or may prove confusing with and2 and or2. That is why I called them and_n and or_n. The underscore is converted into a dash for the hal internals, but if you don't like that, then you can use names=.

So, any particular reason to the naming?

@dirkx dirkx Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None particularly; but _n seeded a bit extra. Changed to _n.

pin in bool in##[128:personality] = 1 "input pins, up to personality-1";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 128 not excessive?

Can you give an example where you'd need more than 40..50 inputs AND'ed together?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the case I have here/that started here was steps control in a 2D conveyer belt/palletrizer is 4x5 position = 20 pallets x (8 mount sensors) + 5 normal interlocks. So I rounded up to the next multiple of 2. Happy to make that 64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other case is a pneumatic sorter where I have two sets(in/out) of blockage/low-pressure/high pressure detects in each of the 41 (don't ask -- I suspect the designer mixed inches v.s metric) linear stations. Though in this case you could roll up each of the 2x3 sets into a 41 OR and then combine each pair with a normal OR into the 3 outputs needed for the pump/tank.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convinced. I guess it would probably be better to use 255 instead of 128. That would give pins in-00 through in-99 and then three digits up til in-254.

The reason for not having this at 256 is that logic uses the last byte (does personality & 0xff). That effectively creates pins 0..254 on the outset in logic.

pin out bool out "output pin; the AND of all inputs";

description """
The *out* pin is set to *TRUE* if all the inputs are all *TRUE*; or *FALSE* if one or more are *FALSE*.

The value for a unconnected pin is TRUE; so it is fine to leave a pin unconnected.

Set the number of pins via personality. The default value is a single *AND* with 8 inputs; so personality=8. The maximum number of inputs is 128 (hardcoded). If there are no inputs specified (personality=0); then the output value
is TRUE.
""";

function _ "Logical AND";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you add a doc string. But in the or you don't. Not consistent. You may also want to elaborate... I think it is rather obvious that it calculates the logical AND. But what makes this so special, that is why you document it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - will fix by removing this for the AND


see_also """
*or*(9),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use emphasis. The post-processor cannot handle it and links will no longer be provided in the html version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin :) took it from one of the other modules; now removed.

and2(9)
and
or2(9).
""";

option period no;
option default_personality 8;
option default_count 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default count is implicitly one. Why set it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin :) took it from one of the other modules - removed :)


license "ASLv2";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of license is that?

It would probably fail for RTAI because anything not GPL will taint the kernel.

Besides, if you need this specific license, then it must also be added to debian/copyright, which needs consensus to ensure compatibility.

@dirkx dirkx Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to GPL; Was the Apache Software License v2

author "Dirk-Willem van Gulik <dirkx(at)webweaving(punto)org";
;;
FUNCTION(_) {
bool tmp = 1;
// we prefer constant time; so do not return 0 on the first 0.
for(int i = 0; i < personality; i++)
tmp = tmp && in(i);
out_set(tmp);
}
33 changes: 33 additions & 0 deletions src/hal/components/or.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
component or "Arbitrary input OR gate";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AND gate you use the term "Multi". Why is this "Arbitrary"? What is arbitrary about these inputs?

Why not retain the comp doc string I wrote?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

pin in bool in##[128:personality] = 0 "in";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc string "in" is a bit thin, isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin :) took it from one of the other modules - elaborated :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - was not able to remove it - as a "" or none will give corrupted output / seems to concatenate the in and out. So have instead made it a more elaborate string.

pin out bool out "output pin; the OR of all inputs";

description """
The *out* pin is set to *TRUE* if any the inputs is *TRUE*; or *FALSE* if all are *FALSE*.

The value for a unconnected pin is FALSE; so it is fine to leave a pin unconnected.

Set the number of pins via personality. The default value is a single *OR* with 8 inputs; so personality=8. The
maximum number of inputs is 128 (hardcoded). If there are no input pins at all (personality=0); then
the output is *FALSE*.
"""
;
function _;
see_also """
and(9), and2(9) and or2(9).
""";

option period no;
option default_personality 8;
option default_count 1;

license "ASLv2";
author "Dirk-Willem van Gulik <dirkx(at)webweaving(punto)org";
;;
FUNCTION(_) {
bool tmp = 0;
// we prefer constant time; so do not return 0 on the first true
for(int i = 0; i < personality; i++)
tmp = tmp || in(i);
out_set(tmp);
}
Loading