Skip to content

Commit 681d94e

Browse files
author
Luca Toniolo
committed
hal_struct: fix man page: use AsciiDoc source, not hand-written troff
Replace the hand-written troff files in docs/man/man3/ with a proper AsciiDoc source at docs/src/man/man3/hal_struct_newf.3.adoc, matching the format used by all other HAL man pages. Register the new page in docs/po4a.cfg so the build generates the troff and translations from it.
1 parent b1c9d38 commit 681d94e

File tree

5 files changed

+104
-131
lines changed

5 files changed

+104
-131
lines changed

docs/man/man3/hal_struct_attach.3

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/man/man3/hal_struct_detach.3

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/man/man3/hal_struct_newf.3

Lines changed: 0 additions & 129 deletions
This file was deleted.

docs/po4a.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
[type: AsciiDoc_def] src/man/man3/hal_signal_new.3.adoc $lang:src/$lang/man/man3/hal_signal_new.3.adoc
264264
[type: AsciiDoc_def] src/man/man3/hal_start_threads.3.adoc $lang:src/$lang/man/man3/hal_start_threads.3.adoc
265265
[type: AsciiDoc_def] src/man/man3/hal_stream.3.adoc $lang:src/$lang/man/man3/hal_stream.3.adoc
266+
[type: AsciiDoc_def] src/man/man3/hal_struct_newf.3.adoc $lang:src/$lang/man/man3/hal_struct_newf.3.adoc
266267
[type: AsciiDoc_def] src/man/man3/hal_type_t.3.adoc $lang:src/$lang/man/man3/hal_type_t.3.adoc
267268
[type: AsciiDoc_def] src/man/man3/hm2_allocate_bspi_tram.3.adoc $lang:src/$lang/man/man3/hm2_allocate_bspi_tram.3.adoc
268269
[type: AsciiDoc_def] src/man/man3/hm2_bspi_set_read_function.3.adoc $lang:src/$lang/man/man3/hm2_bspi_set_read_function.3.adoc
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
:manvolnum: 3
2+
3+
= hal_struct_newf(3)
4+
5+
== NAME
6+
7+
hal_struct_newf, hal_struct_attach, hal_struct_detach - named opaque blobs in HAL shared memory
8+
9+
== SYNTAX
10+
11+
int hal_struct_newf(int _comp_id_, long int _size_, const void *_defval_, const char *_fmt_, _..._)
12+
13+
int hal_struct_attach(const char *_name_, void **_memptr_)
14+
15+
int hal_struct_detach(const char *_name_)
16+
17+
== ARGUMENTS
18+
19+
_comp_id_::
20+
A HAL component identifier returned by an earlier call to *hal_init*.
21+
22+
_size_::
23+
The number of bytes to allocate in HAL shared memory for the data blob.
24+
25+
_defval_::
26+
A pointer to an initialiser of _size_ bytes that is copied into the
27+
newly allocated blob. If NULL the blob is zero-initialised.
28+
29+
_fmt, ..._::
30+
A printf-style format string and arguments that form the name of the entry.
31+
The resulting name must be no longer than HAL_NAME_LEN characters.
32+
33+
_name_::
34+
The name of the struct entry to find, as passed to *hal_struct_newf*.
35+
36+
_memptr_::
37+
Address of a pointer that will be set to point at the data blob on success.
38+
39+
== DESCRIPTION
40+
41+
HAL struct entries are named, reference-counted opaque blobs that live in HAL
42+
shared memory. They occupy a separate namespace from pins, signals, and
43+
parameters and are therefore not visible in *halcmd show pin* or
44+
*halcmd show param* output. Use *halcmd show struct* to inspect them.
45+
46+
*hal_struct_newf* allocates _size_ bytes from HAL shared memory, optionally
47+
initialises the region from _defval_ (or zeroes if NULL), and registers it
48+
under the printf-formatted name. The function must be called before
49+
*hal_ready(3)*. There is no corresponding delete function; the data lives for
50+
the lifetime of the HAL shared memory block. The entry metadata is reclaimed
51+
automatically when the owning component calls *hal_exit(3)*.
52+
53+
*hal_struct_attach* finds the entry by name, increments its reference count,
54+
and stores a pointer to the data blob in _*memptr_. It may be called from
55+
both realtime and userspace contexts after *hal_init(3)*.
56+
57+
*hal_struct_detach* decrements the reference count. Calling it when the
58+
reference count is already zero is an error. The data is not freed.
59+
60+
== RETURN VALUE
61+
62+
All three functions return 0 on success. On failure they return a negative
63+
HAL status code:
64+
65+
*-EINVAL*::
66+
Bad argument, duplicate name (*hal_struct_newf*), component is already ready
67+
(*hal_struct_newf*), or detach underflow (*hal_struct_detach*).
68+
69+
*-ENOMEM*::
70+
Name too long, or HAL shared memory exhausted.
71+
72+
*-ENOENT*::
73+
No entry with the given name found (*hal_struct_attach* or *hal_struct_detach*).
74+
75+
== EXAMPLE
76+
77+
RT side (in _rtapi_app_main_):
78+
79+
----
80+
typedef struct { double value; int count; } my_params_t;
81+
static my_params_t *params;
82+
83+
my_params_t defaults = { 1.0, 0 };
84+
if (hal_struct_newf(comp_id, sizeof(*params), &defaults,
85+
"%s.params", prefix) < 0)
86+
return -1;
87+
if (hal_struct_attach(prefix ".params", (void **)&params) < 0)
88+
return -1;
89+
----
90+
91+
Userspace side:
92+
93+
----
94+
my_params_t *params;
95+
if (hal_struct_attach("mycomp.params", (void **)&params) < 0)
96+
return -1;
97+
/* read params->value, params->count ... */
98+
hal_struct_detach("mycomp.params");
99+
----
100+
101+
== SEE ALSO
102+
103+
hal_init(3), hal_malloc(3), hal_exit(3), halcmd(1)

0 commit comments

Comments
 (0)