Skip to content

Commit 9ec9ba6

Browse files
committed
Cleanup and doc
1 parent 1c796dd commit 9ec9ba6

7 files changed

Lines changed: 72 additions & 11 deletions

File tree

docs/src/config/python-hal-interface.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ Message level constants:
4848
* `hal.MSG_DBG` - Additionally include debugging information
4949
* `hal.MSG_ALL` - Print all messages encountered, disregarding level
5050

51+
Realtime type constants:
52+
53+
* `hal.REALTIME_TYPE_UNINITIALIZED` - Real time module not running
54+
* `hal.REALTIME_TYPE_NONE` - No realtime available
55+
* `hal.REALTIME_TYPE_RTAI` - RTAI kernel mode
56+
* `hal.REALTIME_TYPE_PREEMPT_DYNAMIC` - Preempt dynamic: avaliable in vanilla kernel, not recommended
57+
* `hal.REALTIME_TYPE_PREEMPT_RT` - Preempt RT
58+
* `hal.REALTIME_TYPE_LXRT` - LXRT, userspace implementation for RTAI
59+
* `hal.REALTIME_TYPE_XENOMAI` - Xenomai 3
60+
* `hal.REALTIME_TYPE_XENOMAI_EVL` - Xenomai 4 aka Xenomai EVL
61+
5162
System information:
5263

5364
* `hal.is_kernelspace` - One (1) if RTAPI runs in the kernel, otherwise zero (0)
@@ -59,6 +70,31 @@ System information:
5970

6071
=== hal methods
6172

73+
hal.is_initialized()::
74+
Returns a boolean to indicate whether hal is initialized. The hal is initialized when there is
75+
at least one component. If this is not the case, many of the following functions will
76+
fail with the error: `Cannot call before creating component`
77+
78+
.Example:
79+
[source,python]
80+
----
81+
#The hal must be initialized to use get_realtime_type()
82+
#If it is not initialized, create a component which will initialize it
83+
#The component will be cleaned up after comp goes out of scope
84+
#Use pid as component identifier, so it is unlikely to collide
85+
#with existing components
86+
comp_name = f"halpy{os.getpid()}"
87+
if not hal.is_initialized():
88+
comp = hal.component(comp_name);
89+
90+
type = hal.get_realtime_type()
91+
----
92+
93+
hal.get_realtime_type()::
94+
Returns the type of the running realtime system.
95+
Might return `hal.REALTIME_TYPE_UNINITIALIZED` if `rtapi_app` is not running.
96+
See xref:_hal_constants[realtime type constants].
97+
6298
hal.component_exists(_name_:string)::
6399
Returns a boolean to indicate whether or not the specified component exist at this time.
64100

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
:manvolnum: 3
2+
3+
= hal_get_realtime_type(3)
4+
5+
== NAME
6+
7+
hal_get_realtime_type - Get the type of the running realtime
8+
9+
== SYNTAX
10+
11+
rtapi_realtime_type_t hal_get_realtime_type()
12+
13+
== RETURN VALUE
14+
15+
*hal_get_realtime_type* returns the type of the running realtime system.
16+
17+
For uspace, this returns *REALTIME_TYPE_UNINITIALIZED* if *rtapi_all* is not running. It is save to assume
18+
this never happens in realtime components. But userspace components can be loaded withouth *rtapi_all* being
19+
started.
20+
21+
For rtai, this always returns *REALTIME_TYPE_RTAI*.

docs/src/man/man3/rtapi_is.3.adoc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rtapi_is - details of rtapi configuration
99
[source,c]
1010
----
1111
int rtapi_is_kernelspace();
12-
int rtapi_is_realtime();
12+
int rtapi_is_realtime(); (DEPRECATED)
1313
----
1414

1515
== DESCRIPTION
@@ -18,15 +18,18 @@ int rtapi_is_realtime();
1818
and zero when they run in userspace (e.g., under uspace).
1919

2020
*rtapi_is_realtime()* returns nonzero when capable of running with realtime guarantees.
21+
22+
(DEPRECATED) use *hal_get_realtime_type()* instead. *rtapi_is_realtime()* works only in realtime context.
23+
2124
For rtai, this always returns nonzero (but actually loading realtime modules will fail if not running under the appropriate kernel).
22-
For uspace, this returns nonzero when the running kernel indicates it is capable of realtime performance.
23-
If *rtapi_app* is not setuid root,
24-
this returns nonzero even though *rtapi_app* will not be able to obtain realtime scheduling or hardware access,
25-
so e.g., attempting to *loadrt* a hardware driver will fail.
25+
For uspace, this returns nonzero when the running kernel indicates it is capable of realtime performance and *rtapi_app* has the
26+
required capabilities or is setuid root.
27+
If *rtapi_app* is not setuid root or setcap with the proper capabilities,
28+
this returns zero.
2629

2730
== REALTIME CONSIDERATIONS
2831

29-
May be called from non-realtime or from realtime setup code.
32+
May only be called from realtime setup code.
3033
*rtapi_is_realtime()* may perform filesystem I/O.
3134

3235
== RETURN VALUE

src/hal/hal_lib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ char *hal_comp_name(int comp_id)
539539

540540
int hal_get_realtime_type() {
541541
if (hal_data == 0) {
542-
rtapi_print_msg(RTAPI_MSG_ERR,
543-
"HAL: ERROR: hal_get_realtime_type called before init\n");
544-
return -EINVAL;
542+
rtapi_print_msg(RTAPI_MSG_ERR,
543+
"HAL: ERROR: hal_get_realtime_type called before init\n");
544+
return -EINVAL;
545545
}
546546
return hal_data->realtime_type;
547547
}

src/hal/hal_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ typedef struct hal_data_t {
275275
SHMFIELD(hal_thread_t) thread_free_ptr; /* list of free thread structs */
276276
int exact_base_period; /* if set, pretend that rtapi satisfied our
277277
period request exactly */
278-
rtapi_realtime_type_t realtime_type; /* reflects the realtime type */
278+
rtapi_realtime_type_t realtime_type; /* reflects the running realtime type */
279279
unsigned char lock; /* hal locking, can be one of the HAL_LOCK_* types */
280280
} hal_data_t;
281281

src/rtapi/rtapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ typedef enum{
10011001

10021002
#ifdef RTAPI
10031003
//Only available in real time context
1004-
//In userspace context, use hal_realtime_type()
1004+
//In userspace context, use hal_get_realtime_type()
10051005
extern int rtapi_is_realtime(void);
10061006
extern rtapi_realtime_type_t rtapi_get_realtime_type(void);
10071007
#endif

src/rtapi/uspace_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ int rtapi_is_kernelspace() { return 0; }
342342

343343
#ifndef RTAPI
344344
//For RTAPI, this function is implemented in uspace_rtapi_main.cc
345+
//Keep it in for now with a warning to avoid link issues
345346
int rtapi_is_realtime() {
346347
rtapi_print_msg(RTAPI_MSG_ERR, "rtapi_is_realtime() only allowed in real time context");
347348
return 0;

0 commit comments

Comments
 (0)