You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hal: Add halcompupdate to migrate .comp files to the new HAL API
Out-of-tree .comp components using the legacy HAL types (float, bit,
s32, u32, s64, u64, signed, unsigned) and direct pin/param assignment
stop working when the HAL API break is performed (#4099, #4247).
halcompupdate rewrites them to the new API automatically:
* declaration types are converted: float->real, bit->bool, s32->si32,
u32->ui32, s64->sint, u64->uint, signed->si32, unsigned->ui32
('port' is left alone, it has no new-style replacement yet)
* writes to out/io pins and to params become <name>_set(...) calls,
including compound assignments, ++/--, array pins, chained
assignments, *<name>_ptr dereferences and writes inside #define
macros (macro parameters shadow same-named pins)
* legacy C types are modernized (double/real_t -> rtapi_real,
hal_bit_t -> volatile rtapi_bool, ...)
* reads are unchanged and pins are never renamed, so existing HAL
configurations keep working
Constructs that cannot be converted safely are left unchanged with a
warning for manual conversion: taking the address of a pin/param,
direct use of the legacy hal_pin_*_new/hal_param_*_new creation API,
postfix ++/-- whose value is used, and array indices with side
effects.
In-place rewriting is atomic (temp file + rename) and keeps a .bak
backup created with O_EXCL|O_NOFOLLOW.
halcompile now warns once per deprecated type, pointing to
halcompupdate(1), at the spot previously marked for this warning.
Docs: migration section in comp.adoc, new halcompupdate(1) manpage,
SEE ALSO in halcompile(1). Regression test in
tests/halcompile/update-api.
Validated by converting all in-tree components from master: 119/124
compile (the other 5 need in-tree headers and fail identically for
the already-converted versions), and the output matches the hand
conversions in #4247 functionally.
's64' (for 'sint') and 'u64' (for 'uint') are still accepted, as are the aliases 'signed' and 'unsigned'
275
+
(for 'si32' and 'ui32'), but they are deprecated, 'halcompile' will warn about them,
276
+
and they will be removed when the HAL API break is performed.
277
+
See <<sub:hal-comp-migration,Migrating to the new HAL API>>.
272
278
* 'PINDIRECTION' - One of the following: 'in', 'out', or 'io'.
273
279
A component sets a value for an 'out' pin, it reads a value from an 'in' pin, and it may read or set the value of an 'io' pin.
274
280
* 'PARAMDIRECTION' - One of the following: 'r' or 'rw'. A component sets a value for a 'r' parameter, and it may read or set the value of a 'rw' parameter.
@@ -458,6 +464,15 @@ The details of `struct __comp_state` and these macros may change from one versio
458
464
+
459
465
When the item is a conditional item, it is only legal to refer to it when its 'condition' evaluated to a nonzero value.
460
466
467
+
* `pin_name_set(`__value__`)` or `param_name_set(`__value__`)` - For each 'out' or 'io' pin and each parameter
468
+
of a new-style type ('real', 'bool', 'si32', 'ui32', 'sint', 'uint'), there is a macro which sets the value of the pin or parameter.
469
+
For arrays the form is 'pin_name_set(idx, value)'.
470
+
With the new-style types, assigning to an 'out' or 'io' pin or to a parameter with plain C assignment is not possible;
471
+
the '_set' macro must be used instead (reading stays transparent through the bare name).
472
+
The '_set' macro evaluates to the value that was set, so chained use like 'a_set(b_set(x))' works.
473
+
There is also a 'pin_name_ptr' macro, but with new-style types it evaluates to an opaque reference
474
+
which can only be used with the 'hal_get_*' and 'hal_set_*' functions; it cannot be dereferenced.
475
+
461
476
* 'variable_name' - For each variable 'variable_name' there is a macro which allows the name to be used on its own to refer to the variable.
462
477
When 'variable_name' is an array, the normal C-style subscript is used: 'variable_name[idx]'.
463
478
* 'data' - If "option data" is specified, this macro allows access to the instance data.
@@ -466,6 +481,47 @@ When the item is a conditional item, it is only legal to refer to it when its 'c
466
481
This macro iterates over all the defined instances.
467
482
Inside the body of the loop, the 'pin_name', 'parameter_name', and 'data' macros work as they do in realtime functions.
468
483
484
+
[[sub:hal-comp-migration]]
485
+
== Migrating to the new HAL API
486
+
487
+
HAL is moving from direct memory access of pin and parameter values to strongly typed getter/setter access.
488
+
New-style declaration types replace the legacy types:
0 commit comments