From 0dce05361dad747b2819c7b13be0f917b9c922f1 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Thu, 2 Jul 2026 15:34:57 +0200 Subject: [PATCH] Preliminary - HAL types update and HAL isolation --- docs/po4a.cfg | 21 +++- docs/src/man/man3/hal_param_new-legacy.3.adoc | 62 ------------ docs/src/man/man3/hal_pin_new-legacy.3.adoc | 74 -------------- docs/src/man/man3/hal_type_t-legacy.3.adoc | 66 ------------- src/hal/hal.h | 99 +++++++++++-------- src/hal/hal_lib.c | 58 +++++------ src/hal/hal_priv.h | 3 +- 7 files changed, 110 insertions(+), 273 deletions(-) delete mode 100644 docs/src/man/man3/hal_param_new-legacy.3.adoc delete mode 100644 docs/src/man/man3/hal_pin_new-legacy.3.adoc delete mode 100644 docs/src/man/man3/hal_type_t-legacy.3.adoc diff --git a/docs/po4a.cfg b/docs/po4a.cfg index 61308113169..85f3cf55eef 100644 --- a/docs/po4a.cfg +++ b/docs/po4a.cfg @@ -252,23 +252,43 @@ [type: AsciiDoc_def] src/man/man1/xyzac-trt-gui.1.adoc $lang:build/adoc/$lang/man/man1/xyzac-trt-gui.1.adoc [type: AsciiDoc_def] src/man/man1/xyzbc-trt-gui.1.adoc $lang:build/adoc/$lang/man/man1/xyzbc-trt-gui.1.adoc [type: AsciiDoc_def] src/man/man3/PM_ROTATION_VECTOR.3.adoc $lang:build/adoc/$lang/man/man3/PM_ROTATION_VECTOR.3.adoc +[type: AsciiDoc_def] src/man/man3/hal.3.adoc $lang:build/adoc/$lang/man/man3/hal.3.adoc [type: AsciiDoc_def] src/man/man3/hal_add_funct_to_thread.3.adoc $lang:build/adoc/$lang/man/man3/hal_add_funct_to_thread.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_comp_by_name.3.adoc $lang:build/adoc/$lang/man/man3/hal_comp_by_name.3.adoc [type: AsciiDoc_def] src/man/man3/hal_create_thread.3.adoc $lang:build/adoc/$lang/man/man3/hal_create_thread.3.adoc [type: AsciiDoc_def] src/man/man3/hal_exit.3.adoc $lang:build/adoc/$lang/man/man3/hal_exit.3.adoc [type: AsciiDoc_def] src/man/man3/hal_export_funct.3.adoc $lang:build/adoc/$lang/man/man3/hal_export_funct.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_get_p.3.adoc $lang:build/adoc/$lang/man/man3/hal_get_p.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_get_realtime_type.3.adoc $lang:build/adoc/$lang/man/man3/hal_get_realtime_type.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_get_s.3.adoc $lang:build/adoc/$lang/man/man3/hal_get_s.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_getter.3.adoc $lang:build/adoc/$lang/man/man3/hal_getter.3.adoc [type: AsciiDoc_def] src/man/man3/hal_init.3.adoc $lang:build/adoc/$lang/man/man3/hal_init.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_init_funct_to_thread.3.adoc $lang:build/adoc/$lang/man/man3/hal_init_funct_to_thread.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_list_comp.3.adoc $lang:build/adoc/$lang/man/man3/hal_list_comp.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_list_funct.3.adoc $lang:build/adoc/$lang/man/man3/hal_list_funct.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_list_p.3.adoc $lang:build/adoc/$lang/man/man3/hal_list_p.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_list_p_s.3.adoc $lang:build/adoc/$lang/man/man3/hal_list_p_s.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_list_s.3.adoc $lang:build/adoc/$lang/man/man3/hal_list_s.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_list_thread.3.adoc $lang:build/adoc/$lang/man/man3/hal_list_thread.3.adoc [type: AsciiDoc_def] src/man/man3/hal_malloc.3.adoc $lang:build/adoc/$lang/man/man3/hal_malloc.3.adoc [type: AsciiDoc_def] src/man/man3/hal_param_alias.3.adoc $lang:build/adoc/$lang/man/man3/hal_param_alias.3.adoc [type: AsciiDoc_def] src/man/man3/hal_param_new.3.adoc $lang:build/adoc/$lang/man/man3/hal_param_new.3.adoc [type: AsciiDoc_def] src/man/man3/hal_parport.3.adoc $lang:build/adoc/$lang/man/man3/hal_parport.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_pdir_t.3.adoc $lang:build/adoc/$lang/man/man3/hal_pdir_t.3.adoc [type: AsciiDoc_def] src/man/man3/hal_pin_alias.3.adoc $lang:build/adoc/$lang/man/man3/hal_pin_alias.3.adoc [type: AsciiDoc_def] src/man/man3/hal_pin_new.3.adoc $lang:build/adoc/$lang/man/man3/hal_pin_new.3.adoc [type: AsciiDoc_def] src/man/man3/hal_port.3.adoc $lang:build/adoc/$lang/man/man3/hal_port.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_query_t.3.adoc $lang:build/adoc/$lang/man/man3/hal_query_t.3.adoc [type: AsciiDoc_def] src/man/man3/hal_ready.3.adoc $lang:build/adoc/$lang/man/man3/hal_ready.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_refs_u.3.adoc $lang:build/adoc/$lang/man/man3/hal_refs_u.3.adoc [type: AsciiDoc_def] src/man/man3/hal_set_constructor.3.adoc $lang:build/adoc/$lang/man/man3/hal_set_constructor.3.adoc [type: AsciiDoc_def] src/man/man3/hal_set_lock.3.adoc $lang:build/adoc/$lang/man/man3/hal_set_lock.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_set_p.3.adoc $lang:build/adoc/$lang/man/man3/hal_set_p.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_set_s.3.adoc $lang:build/adoc/$lang/man/man3/hal_set_s.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_setter.3.adoc $lang:build/adoc/$lang/man/man3/hal_setter.3.adoc [type: AsciiDoc_def] src/man/man3/hal_signal_new.3.adoc $lang:build/adoc/$lang/man/man3/hal_signal_new.3.adoc [type: AsciiDoc_def] src/man/man3/hal_start_threads.3.adoc $lang:build/adoc/$lang/man/man3/hal_start_threads.3.adoc +[type: AsciiDoc_def] src/man/man3/hal_statistics.3.adoc $lang:build/adoc/$lang/man/man3/hal_statistics.3.adoc [type: AsciiDoc_def] src/man/man3/hal_stream.3.adoc $lang:build/adoc/$lang/man/man3/hal_stream.3.adoc [type: AsciiDoc_def] src/man/man3/hal_type_t.3.adoc $lang:build/adoc/$lang/man/man3/hal_type_t.3.adoc [type: AsciiDoc_def] src/man/man3/hm2_allocate_bspi_tram.3.adoc $lang:build/adoc/$lang/man/man3/hm2_allocate_bspi_tram.3.adoc @@ -283,7 +303,6 @@ [type: AsciiDoc_def] src/man/man3/hm2_uart_read.3.adoc $lang:build/adoc/$lang/man/man3/hm2_uart_read.3.adoc [type: AsciiDoc_def] src/man/man3/hm2_uart_send.3.adoc $lang:build/adoc/$lang/man/man3/hm2_uart_send.3.adoc [type: AsciiDoc_def] src/man/man3/hm2_uart_setup.3.adoc $lang:build/adoc/$lang/man/man3/hm2_uart_setup.3.adoc -[type: AsciiDoc_def] src/man/man3/hal.3.adoc $lang:build/adoc/$lang/man/man3/hal.3.adoc [type: AsciiDoc_def] src/man/man3/rtapi.3.adoc $lang:build/adoc/$lang/man/man3/rtapi.3.adoc [type: AsciiDoc_def] src/man/man3/rtapi_app_exit.3.adoc $lang:build/adoc/$lang/man/man3/rtapi_app_exit.3.adoc [type: AsciiDoc_def] src/man/man3/rtapi_app_main.3.adoc $lang:build/adoc/$lang/man/man3/rtapi_app_main.3.adoc diff --git a/docs/src/man/man3/hal_param_new-legacy.3.adoc b/docs/src/man/man3/hal_param_new-legacy.3.adoc deleted file mode 100644 index 7f9e4bcae64..00000000000 --- a/docs/src/man/man3/hal_param_new-legacy.3.adoc +++ /dev/null @@ -1,62 +0,0 @@ -:manvolnum: 3 - -= hal_param_new-legacy(3) - -== NAME - -hal_param_new-legacy, hal_param_bit_new-legacy, hal_param_float_new-legacy, hal_param_u32_new-legacy, -hal_param_s32_new-legacy, hal_param_bit_newf-legacy, hal_param_float_newf-legacy, hal_param_u32_newf-legacy, -hal_param_s32_newf-legacy - creates a HAL parameter - -== SYNTAX - -int hal_param_bit_new(const char* _name_, hal_param_dir_t _dir_, hal_bit_t* _data_addr_, int _comp_id_) - -int hal_param_float_new(const char* _name_, hal_param_dir_t _dir_, hal_float_t* _data_addr_, int _comp_id_) - -int hal_param_u32_new(const char* _name_, hal_param_dir_t _dir_, hal_u32_t* _data_addr_, int _comp_id_) - -int hal_param_s32_new(const char* _name_, hal_param_dir_t _dir_, hal_s32_t* _data_addr_, int _comp_id_) - -int hal_param_bit_newf(hal_param_dir_t _dir_, hal_bit_t* _data_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_param_float_newf(hal_param_dir_t _dir_, hal_float_t* _data_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_param_u32_newf(hal_param_dir_t _dir_, hal_u32_t * _data_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_param_s32_newf(hal_param_dir_t _dir_, hal_s32_t * _data_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_param_new(const char* _name_, hal_type_t _type_, hal_param_dir_t _dir_, void* _data_addr_, int _comp_id_) - -== ARGUMENTS - -_name_:: - The name to give to the created parameter. -_dir_:: - The direction of the parameter, from the viewpoint of the component. - It may be one of *HAL_RO*, or *HAL_RW*. - A component may assign a value to any parameter, - but other programs (such as halcmd) may only assign a value to a parameter that is *HAL_RW*. -_data_addr_:: - The address of the data, which must lie within memory allocated by *hal_malloc*. -_comp_id_:: - A HAL component identifier returned by an earlier call to *hal_init*. -_fmt, ..._:: - A printf-style format string and arguments. -_type_:: - The type of the parameter, as specified in *hal_type_t(3)*. - -== DESCRIPTION - -The *hal_param_new* family of functions create a new _param_ object. - -There are functions for each of the data types that the HAL supports. -Pins may only be linked to signals of the same type. - -== RETURN VALUE - -Returns a HAL status code. - -== SEE ALSO - -hal_type_t(3) diff --git a/docs/src/man/man3/hal_pin_new-legacy.3.adoc b/docs/src/man/man3/hal_pin_new-legacy.3.adoc deleted file mode 100644 index 82a4cbce2a2..00000000000 --- a/docs/src/man/man3/hal_pin_new-legacy.3.adoc +++ /dev/null @@ -1,74 +0,0 @@ -:manvolnum: 3 - -= hal_pin_new-legacy(3) - -== NAME - -hal_pin_new-legacy, hal_pin_bit_new-legacy, hal_pin_float_new-legacy, hal_pin_u32_new-legacy, -hal_pin_s32_new-legacy, hal_pin_port_new-legacy, hal_pin_bit_newf-legacy, -hal_pin_float_newf-legacy, hal_pin_u32_newf-legacy, hal_pin_s32_newf-legacy, -hal_pin_port_newf-legacy - creates a HAL pin - -== SYNTAX - -int hal_pin_bit_new(const char* _name_, hal_pin_dir_t _dir_, hal_bit_t** _data_ptr_addr_, int _comp_id_) - -int hal_pin_float_new(const char* _name_, hal_pin_dir_t _dir_, hal_float_t** _data_ptr_addr_, int _comp_id_) - -int hal_pin_u32_new(const char* _name_, hal_pin_dir_t _dir_, hal_u32_t** _data_ptr_addr_, int _comp_id_) - -int hal_pin_s32_new(const char* _name_, hal_pin_dir_t _dir_, hal_s32_t** _data_ptr_addr_, int _comp_id_) - -int hal_pin_port_new(const char* _name_, hal_pin_dir_t _dir_, hal_port_t** _data_ptr_addr_, int _comp_id_) - -int hal_pin_bit_newf(hal_pin_dir_t _dir_, hal_bit_t** _data_ptr_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_pin_float_newf(hal_pin_dir_t _dir_, hal_float_t** _data_ptr_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_pin_u32_newf(hal_pin_dir_t _dir_, hal_u32_t** _data_ptr_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_pin_s32_newf(hal_pin_dir_t _dir_, hal_s32_t** _data_ptr_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_pin_port_newf(hal_pin_dir_t _dir_, hal_port_t** _data_ptr_addr_, int _comp_id_, const char* _fmt_, _..._) - -int hal_pin_new(const char* _name_, hal_type_t _type_, hal_pin_dir_t _dir_, void** _data_ptr_addr_, int _comp_id_) - -== ARGUMENTS - -name:: - Name of the pin. -dir:: - The direction of the pin, from the viewpoint of the component. - It may be one of *HAL_IN*, *HAL_OUT*, or *HAL_IO*. - Any number of *HAL_IN* or *HAL_IO* pins may be connected to the same signal, - but at most one *HAL_OUT* pin is permitted. - A component may assign a value to a pin that is *HAL_OUT* or *HAL_IO*, - but may not assign a value to a pin that is *HAL_IN*. -data_ptr_addr:: - The address of the pointer-to-data, which must lie within memory - allocated by *hal_malloc*. -comp_id:: - HAL component identifier returned by an earlier call to *hal_init*. -fmt,:: - printf-style format string and arguments -type:: - The type of the param, as specified in *hal_type_t(3)*. - -== DESCRIPTION - -The *hal_pin_new* family of functions create a new _pin_ object. -Once a pin has been created, it can be linked to a signal object using *hal_link*. -A pin contains a pointer, and the component that owns the pin -can dereference the pointer to access whatever signal is linked to the pin. -(If no signal is linked, it points to a dummy signal.) - -There are functions for each of the data types that the HAL supports. -Pins may only be linked to signals of the same type. - -== RETURN VALUE - -Returns 0 on success, or a negative errno value on failure. - -== SEE ALSO - -hal_type_t(3), hal_link(3) diff --git a/docs/src/man/man3/hal_type_t-legacy.3.adoc b/docs/src/man/man3/hal_type_t-legacy.3.adoc deleted file mode 100644 index 3973cc75fd6..00000000000 --- a/docs/src/man/man3/hal_type_t-legacy.3.adoc +++ /dev/null @@ -1,66 +0,0 @@ -:manvolnum: 3 - -= hal_type_t-legacy(3) - -== NAME - -hal_type_t-legacy, hal_bool-legacy, hal_bit_t-legacy, hal_s32_t-legacy, hal_u32_t-legacy, -hal_port_t-legacy, hal_float_t-legacy, real_t-legacy, ireal_t-legacy - typedefs for HAL datatypes - -== DESCRIPTION - -typedef ... *hal_bool;*:: - A type which may have a value of 0 or nonzero. -typedef ... *hal_bit_t;*:: - A volatile type which may have a value of 0 or nonzero. -typedef ... *hal_s32_t*;:: - A volatile type which may have a value from -2147483648 to 2147483647. -typedef ... *hal_u32_t*;:: - A volatile type which may have a value from 0 to 4294967295. -typedef ... *hal_port_t*;:: - A volatile handle to a port object. Used with hal_port* functions. -typedef ... *hal_float_t*;:: - A volatile floating-point type, which typically has the same precision - and range as the C type *double*. -typedef ... *real_t*;:: - A nonvolatile floating-point type with at least as much precision as - *hal_float_t*. -typedef ... *ireal_t*;:: - A nonvolatile unsigned integral type the same size as *hal_float_t*. -typedef enum *hal_type_t*;:: - - *HAL_BIT*;; - Corresponds to the type *hal_bit_t*. - *HAL_FLOAT*;; - Corresponds to the type *hal_float_t*. - *HAL_S32*;; - Corresponds to the type *hal_s32_t*. - *HAL_U32*;; - Corresponds to the type *hal_u32_t*. - -== NOTES - -*hal_bit_t* is typically a typedef to an integer type whose range is -larger than just 0 and 1. When testing the value of a *hal_bit_t*, never -compare it to 1. Prefer one of the following: - -* if(b) -* if(b != 0) - -It is often useful to refer to a type that can represent all the values -as a HAL type, but without the volatile qualifier. The following types -correspond with the HAL types: - -hal_bit_t:: int -hal_s32_t:: __s32 -hal_u32_t:: __u32 -hal_float_t:: hal_real_t -hal_port_t:: int - -Take care not to use the types *s32* and *u32*. These will compile in -kernel modules but not in userspace, and not for realtime components -when using uspace realtime. - -== SEE ALSO - -hal_pin_new(3), hal_param_new(3) diff --git a/src/hal/hal.h b/src/hal/hal.h index d1c23da2bda..d9b26eadb01 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -127,6 +127,24 @@ */ +// +// The HAL_API_VERSION define can be used to determine what features are +// available in the HAL library API. It can be used to make code build on both +// old and new LinuxCNC versions if you need to keep everything in one +// source-tree. +// Currently only two versions are possible: +// a) No define present +// The HAL API is for LinuxCNC up to and including version 2.9. The integer +// pins and params are 32-bit only. +// +// b) HAL_API_VERSION == 1 +// The HAL API if for LinuxCNC 2.10 and later. It supports the getter, +// setter and query API. Any access to the underlying data or HAL's private +// inners is not allowed. HAL pins and params are opaque structures. The +// underlying data size of integers is 64-bit. +// +#define HAL_API_VERSION 1 + #include "rtapi.h" RTAPI_BEGIN_DECLS @@ -282,7 +300,7 @@ const char *hal_strerror(int err); /** hal_comp_name() returns the name of the given component, or NULL if comp_id is not a loaded component */ -extern char* hal_comp_name(int comp_id); +extern const char *hal_comp_name(int comp_id); /** hal_get_realtime_type() returns the type of the running real time */ @@ -373,6 +391,7 @@ typedef enum { typedef hal_pdir_t hal_pin_dir_t; typedef hal_pdir_t hal_param_dir_t; +#define __HAL_DEPRECATED(msg) __attribute__((deprecated(msg))) #define __HAL_ALWAYS_INLINE __attribute__((always_inline)) // @@ -400,15 +419,15 @@ static inline __HAL_ALWAYS_INLINE bool hal_pdir_is_neither(hal_pdir_t v) { // compiler. // ==> Remove when we get rid of old hal_*_t typedefs. <== typedef rtapi_real real_t; -typedef rtapi_u64 ireal_t __attribute__((aligned(8))); // integral type as wide as real_t / hal_float_t +typedef rtapi_u64 ireal_t __attribute__((aligned(8))) __attribute__((deprecated)); // integral type as wide as real_t / hal_float_t typedef volatile bool hal_bit_t; typedef volatile rtapi_u32 hal_u32_t; typedef volatile rtapi_s32 hal_s32_t; typedef volatile rtapi_u64 hal_u64_t; typedef volatile rtapi_s64 hal_s64_t; -typedef volatile real_t hal_float_t; -typedef volatile int hal_port_t; +typedef volatile rtapi_real hal_float_t; +typedef volatile rtapi_port hal_port_t; /** HAL "data union" structure ** This structure may hold any type of hal data @@ -660,17 +679,17 @@ extern unsigned char hal_get_lock(void); On failure they return a negative error code. */ extern int hal_pin_bit_new(const char *name, hal_pin_dir_t dir, - hal_bit_t ** data_ptr_addr, int comp_id); + hal_bit_t ** data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_bool()"); extern int hal_pin_float_new(const char *name, hal_pin_dir_t dir, - hal_float_t ** data_ptr_addr, int comp_id); + hal_float_t ** data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_real()"); extern int hal_pin_u32_new(const char *name, hal_pin_dir_t dir, - hal_u32_t ** data_ptr_addr, int comp_id); + hal_u32_t ** data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_ui32()"); extern int hal_pin_s32_new(const char *name, hal_pin_dir_t dir, - hal_s32_t ** data_ptr_addr, int comp_id); + hal_s32_t ** data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_si32()"); extern int hal_pin_u64_new(const char *name, hal_pin_dir_t dir, - hal_u64_t ** data_ptr_addr, int comp_id); + hal_u64_t ** data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_uint()"); extern int hal_pin_s64_new(const char *name, hal_pin_dir_t dir, - hal_s64_t ** data_ptr_addr, int comp_id); + hal_s64_t ** data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_sint()"); extern int hal_pin_port_new(const char *name, hal_pin_dir_t dir, hal_port_t ** data_ptr_addr, int comp_id); @@ -683,22 +702,22 @@ extern int hal_pin_port_new(const char *name, hal_pin_dir_t dir, */ extern int hal_pin_bit_newf(hal_pin_dir_t dir, hal_bit_t ** data_ptr_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_pin_new_bool()"); extern int hal_pin_float_newf(hal_pin_dir_t dir, hal_float_t ** data_ptr_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_pin_new_real()"); extern int hal_pin_u32_newf(hal_pin_dir_t dir, hal_u32_t ** data_ptr_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_pin_new_ui32()"); extern int hal_pin_s32_newf(hal_pin_dir_t dir, hal_s32_t ** data_ptr_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_pin_new_si32()"); extern int hal_pin_u64_newf(hal_pin_dir_t dir, hal_u64_t ** data_ptr_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_pin_new_uint()"); extern int hal_pin_s64_newf(hal_pin_dir_t dir, hal_s64_t ** data_ptr_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_pin_new_sint()"); extern int hal_pin_port_newf(hal_pin_dir_t dir, hal_port_t** data_ptr_addr, int comp_id, const char *fmt, ...) __attribute__((format(printf,4,5))); @@ -720,7 +739,7 @@ extern int hal_pin_port_newf(hal_pin_dir_t dir, it returns a negative error code. */ extern int hal_pin_new(const char *name, hal_type_t type, hal_pin_dir_t dir, - void **data_ptr_addr, int comp_id); + void **data_ptr_addr, int comp_id) __HAL_DEPRECATED("Use hal_pin_new_XXXX()"); /** There is no 'hal_pin_delete()' function. Once a component has created a pin, that pin remains as long as the component exists. @@ -824,37 +843,37 @@ extern int hal_unlink(const char *pin_name); On failure they return a negative error code. */ extern int hal_param_bit_new(const char *name, hal_param_dir_t dir, - hal_bit_t * data_addr, int comp_id); + hal_bit_t * data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_bool()"); extern int hal_param_float_new(const char *name, hal_param_dir_t dir, - hal_float_t * data_addr, int comp_id); + hal_float_t * data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_real()"); extern int hal_param_u32_new(const char *name, hal_param_dir_t dir, - hal_u32_t * data_addr, int comp_id); + hal_u32_t * data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_ui32()"); extern int hal_param_s32_new(const char *name, hal_param_dir_t dir, - hal_s32_t * data_addr, int comp_id); + hal_s32_t * data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_si32()"); extern int hal_param_u64_new(const char *name, hal_param_dir_t dir, - hal_u64_t * data_addr, int comp_id); + hal_u64_t * data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_uint()"); extern int hal_param_s64_new(const char *name, hal_param_dir_t dir, - hal_s64_t * data_addr, int comp_id); + hal_s64_t * data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_sint()"); /** printf_style-style versions of hal_param_XXX_new */ extern int hal_param_bit_newf(hal_param_dir_t dir, hal_bit_t * data_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_param_new_bool()"); extern int hal_param_float_newf(hal_param_dir_t dir, hal_float_t * data_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_param_new_real()"); extern int hal_param_u32_newf(hal_param_dir_t dir, hal_u32_t * data_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_param_new_ui32()"); extern int hal_param_s32_newf(hal_param_dir_t dir, hal_s32_t * data_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_param_new_si32()"); extern int hal_param_u64_newf(hal_param_dir_t dir, hal_u64_t * data_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_param_new_uint()"); extern int hal_param_s64_newf(hal_param_dir_t dir, hal_s64_t * data_addr, int comp_id, const char *fmt, ...) - __attribute__((format(printf,4,5))); + __attribute__((format(printf,4,5))) __HAL_DEPRECATED("Use hal_param_new_sint()"); /** 'hal_param_new()' creates a new 'parameter' object. It is a generic @@ -877,7 +896,7 @@ extern int hal_param_s64_newf(hal_param_dir_t dir, it returns a negative error code. */ extern int hal_param_new(const char *name, hal_type_t type, hal_param_dir_t dir, - void *data_addr, int comp_id); + void *data_addr, int comp_id) __HAL_DEPRECATED("Use hal_param_new_XXXX()"); /** There is no 'hal_param_delete()' function. Once a component has created a parameter, that parameter remains as long as the @@ -893,12 +912,12 @@ extern int hal_param_new(const char *name, hal_type_t type, hal_param_dir_t dir, On success, the hal_param_xxx_set() functions return 0, and on failure they return a negative error code. */ -extern int hal_param_bit_set(const char *name, int value); -extern int hal_param_float_set(const char *name, double value); -extern int hal_param_u32_set(const char *name, unsigned long value); -extern int hal_param_s32_set(const char *name, signed long value); -extern int hal_param_u64_set(const char *name, unsigned long value); -extern int hal_param_s64_set(const char *name, signed long value); +int hal_param_bit_set(const char *name, int value) __HAL_DEPRECATED("Use hal_set_p()"); +int hal_param_float_set(const char *name, double value) __HAL_DEPRECATED("Use hal_set_p()"); +int hal_param_u32_set(const char *name, unsigned long value) __HAL_DEPRECATED("Use hal_set_p()"); +int hal_param_s32_set(const char *name, signed long value) __HAL_DEPRECATED("Use hal_set_p()"); +int hal_param_u64_set(const char *name, unsigned long value) __HAL_DEPRECATED("Use hal_set_p()"); +int hal_param_s64_set(const char *name, signed long value) __HAL_DEPRECATED("Use hal_set_p()"); /** 'hal_param_alias()' assigns an alternate name, aka an alias, to a parameter. Once assigned, the parameter can be referred to by @@ -922,7 +941,7 @@ extern int hal_param_alias(const char *pin_name, const char *alias); If successful, hal_param_set() returns 0. On failure it returns a negative error code. */ -extern int hal_param_set(const char *name, hal_type_t type, void *value_addr); +int hal_param_set(const char *name, hal_type_t type, void *value_addr) __HAL_DEPRECATED("Use hal_set_p()"); /*********************************************************************** * PIN/SIG/PARAM GETTER FUNCTIONS * @@ -937,7 +956,7 @@ extern int hal_param_set(const char *name, hal_type_t type, void *value_addr); */ extern int hal_get_pin_value_by_name( - const char *name, hal_type_t *type, hal_data_u **data, bool *connected); + const char *name, hal_type_t *type, hal_data_u **data, bool *connected) __HAL_DEPRECATED("Use hal_get_p()"); /** 'hal_get_signal_value_by_name()' returns the value of any arbitrary HAL * signal by signal name. @@ -948,7 +967,7 @@ extern int hal_get_pin_value_by_name( */ extern int hal_get_signal_value_by_name( - const char *name, hal_type_t *type, hal_data_u **data, bool *has_writers); + const char *name, hal_type_t *type, hal_data_u **data, bool *has_writers) __HAL_DEPRECATED("Use hal_get_s()"); /** 'hal_get_param_value_by_name()' returns the value of any arbitrary HAL * parameter by parameter name. @@ -958,7 +977,7 @@ extern int hal_get_signal_value_by_name( */ extern int hal_get_param_value_by_name( - const char *name, hal_type_t *type, hal_data_u **data); + const char *name, hal_type_t *type, hal_data_u **data) __HAL_DEPRECATED("Use hal_get_p()"); /*********************************************************************** diff --git a/src/hal/hal_lib.c b/src/hal/hal_lib.c index c4aa81eb636..ce3301e51c7 100644 --- a/src/hal/hal_lib.c +++ b/src/hal/hal_lib.c @@ -778,10 +778,10 @@ const char *hal_strerror(int err) } } -char *hal_comp_name(int comp_id) +const char *hal_comp_name(int comp_id) { hal_comp_t *comp; - char *result = NULL; + const char *result = NULL; halpr_mutex_acquire(); comp = halpr_find_comp_by_id(comp_id); if(comp) result = comp->name; @@ -837,6 +837,10 @@ unsigned char hal_get_lock() { /* wrapper functs for typed pins - these call the generic funct below */ +// We don't want our library to emit the deprecation warning. +// We already know it and need to provide them until removed. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" int hal_pin_bit_new(const char *name, hal_pin_dir_t dir, hal_bit_t ** data_ptr_addr, int comp_id) { @@ -961,6 +965,7 @@ int hal_pin_s64_newf(hal_pin_dir_t dir, va_end(ap); return ret; } +#pragma GCC diagnostic pop int hal_pin_port_newf(hal_pin_dir_t dir, hal_port_t **data_ptr_addr, int comp_id, const char *fmt, ...) @@ -1062,6 +1067,10 @@ int hal_pin_new_port(int compid, hal_pdir_t dir, hal_sint_t *ref, const char *fm /* this is a generic function that does the majority of the work. */ +// We don't want our library to emit the deprecation warning. +// We already know it and need to provide them until removed. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" int hal_pin_new(const char *name, hal_type_t type, hal_pin_dir_t dir, void **data_ptr_addr, int comp_id) { @@ -1132,8 +1141,9 @@ int hal_pin_new(const char *name, hal_type_t type, hal_pin_dir_t dir, // Overlapping pin/parameter name // This is a problem because setp does not distinguish and // cannot set pin or param when the names collide. + halpr_mutex_release(); rtapi_print_msg(RTAPI_MSG_ERR, "HAL: ERROR: pin '%s' also is the name of a parameter\n", name); - // We continue, as was done before... + return -EEXIST; } /* validate passed in pointer - must point to HAL shmem */ if (! SHMCHK(data_ptr_addr)) { @@ -1201,6 +1211,7 @@ int hal_pin_new(const char *name, hal_type_t type, hal_pin_dir_t dir, next = *prev; } } +#pragma GCC diagnostic pop int hal_pin_alias(const char *pin_name, const char *alias) { @@ -1693,6 +1704,10 @@ int hal_unlink(const char *pin_name) /* wrapper functs for typed params - these call the generic funct below */ +// We don't want our library to emit the deprecation warning. +// We already know it and need to provide them until removed. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" int hal_param_bit_new(const char *name, hal_param_dir_t dir, hal_bit_t * data_addr, int comp_id) { @@ -1807,6 +1822,7 @@ int hal_param_s64_newf(hal_param_dir_t dir, hal_s64_t * data_addr, va_end(ap); return ret; } +#pragma GCC diagnostic pop /* this is a generic function that does the majority of the work. */ @@ -1874,8 +1890,9 @@ static int hal_param_new_anyapi(const char *name, hal_type_t type, hal_pdir_t di // Overlapping pin/parameter name // This is a problem because setp does not distinguish and // cannot set pin or param when the names collide. + halpr_mutex_release(); rtapi_print_msg(RTAPI_MSG_ERR, "HAL: ERROR: parameter '%s' also is the name of a pin\n", name); - // We continue, as was done before... + return -EEXIST; } /* validate passed in pointer - must point to HAL shmem */ if (! SHMCHK(data_addr)) { @@ -2062,6 +2079,10 @@ int hal_param_new_fake(int compid, hal_refs_u *ref) /* wrapper functs for typed params - these call the generic funct below */ +// We don't want our library to emit the deprecation warning. +// We already know it and need to provide them until removed. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" int hal_param_bit_set(const char *name, int value) { return hal_param_set(name, HAL_BIT, &value); @@ -2173,6 +2194,7 @@ int hal_param_set(const char *name, hal_type_t type, void *value_addr) halpr_mutex_release(); return 0; } +#pragma GCC diagnostic pop int hal_param_alias(const char *param_name, const char *alias) { @@ -4517,14 +4539,6 @@ static bool hal_port_compute_copy(unsigned read, } -// hal_port_alloc() is DEPRECATED -// Access to port allocation is done by hal_set_s() on the signal that has the -// port pins connected. -int hal_port_alloc(unsigned size, hal_port_t *port) -{ - return halpr_port_alloc(size, port); -} - int halpr_port_alloc(unsigned size, hal_port_t *port) { if(!port || size < 1 || size > HAL_PORT_SIZE_MAX) return -EINVAL; @@ -5176,6 +5190,7 @@ EXPORT_SYMBOL(hal_pin_new_uint); EXPORT_SYMBOL(hal_pin_new_real); EXPORT_SYMBOL(hal_pin_new_port); +// Old style pin creation has been deprecated. EXPORT_SYMBOL(hal_pin_bit_new); EXPORT_SYMBOL(hal_pin_float_new); EXPORT_SYMBOL(hal_pin_u32_new); @@ -5199,6 +5214,7 @@ EXPORT_SYMBOL(hal_signal_delete); EXPORT_SYMBOL(hal_link); EXPORT_SYMBOL(hal_unlink); +// Old style parameter creation has been deprecated. EXPORT_SYMBOL(hal_param_bit_new); EXPORT_SYMBOL(hal_param_float_new); EXPORT_SYMBOL(hal_param_u32_new); @@ -5222,6 +5238,8 @@ EXPORT_SYMBOL(hal_param_new_uint); EXPORT_SYMBOL(hal_param_new_real); EXPORT_SYMBOL(hal_param_new_fake); +// Parameter set functions have been deprecated. +// Use the generic hal_set_p() instead. EXPORT_SYMBOL(hal_param_bit_set); EXPORT_SYMBOL(hal_param_float_set); EXPORT_SYMBOL(hal_param_u32_set); @@ -5245,25 +5263,9 @@ EXPORT_SYMBOL(hal_del_funct_from_thread); EXPORT_SYMBOL(hal_start_threads); EXPORT_SYMBOL(hal_stop_threads); -EXPORT_SYMBOL(hal_shmem_base); -EXPORT_SYMBOL(halpr_find_comp_by_name); -EXPORT_SYMBOL(halpr_find_pin_by_name); -EXPORT_SYMBOL(halpr_find_sig_by_name); -EXPORT_SYMBOL(halpr_find_param_by_name); -EXPORT_SYMBOL(halpr_find_thread_by_name); -EXPORT_SYMBOL(halpr_find_funct_by_name); -EXPORT_SYMBOL(halpr_find_comp_by_id); - -EXPORT_SYMBOL(halpr_find_pin_by_owner); -EXPORT_SYMBOL(halpr_find_param_by_owner); -EXPORT_SYMBOL(halpr_find_funct_by_owner); - -EXPORT_SYMBOL(halpr_find_pin_by_sig); - EXPORT_SYMBOL(hal_pin_alias); EXPORT_SYMBOL(hal_param_alias); -EXPORT_SYMBOL(hal_port_alloc); EXPORT_SYMBOL(hal_port_read); EXPORT_SYMBOL(hal_port_peek); EXPORT_SYMBOL(hal_port_peek_commit); diff --git a/src/hal/hal_priv.h b/src/hal/hal_priv.h index fde9ba88fd3..f98d1e29caa 100644 --- a/src/hal/hal_priv.h +++ b/src/hal/hal_priv.h @@ -525,7 +525,7 @@ extern hal_funct_t *halpr_find_funct_by_owner(hal_comp_t * owner, extern hal_pin_t *halpr_find_pin_by_sig(hal_sig_t * sig, hal_pin_t * start); -/** hal_port_alloc allocates a new empty hal_port having a buffer of size bytes. +/** halpr_port_alloc allocates a new empty hal_port having a buffer of size bytes. Returns a negative value on failure. On success zero (0) is returned and the newly allocated hal_port_t is returned in the port argument and can be used with all other hal_port functions. @@ -533,7 +533,6 @@ extern hal_pin_t *halpr_find_pin_by_sig(hal_sig_t * sig, hal_pin_t * start); should use hal_set_s() to allocate the port once the pins are connected to the signal. */ -extern int hal_port_alloc(unsigned size, hal_port_t *port); int halpr_port_alloc(unsigned size, hal_port_t *port); // Recursive HAL mutex (replaces old mutex)