Skip to content

Commit 84ebd89

Browse files
authored
Merge pull request #3345 from BsAtHome/fix_rt-wextra-components
Fix -Wextra in RT componentized code
2 parents d69b118 + 5133dac commit 84ebd89

102 files changed

Lines changed: 252 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/src/hal/comp.adoc

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ component ddt "Compute the derivative of the input function";
3131
pin in float in;
3232
pin out float out;
3333
variable double old;
34+
option period no;
3435
function _;
3536
license "GPL"; // indicates GPL v2 or later
3637
;;
@@ -173,7 +174,7 @@ If neither 'count' nor 'names' is specified, a single numbered instance is creat
173174

174175
Functions are implicitly passed the 'period' parameter which is the time in nanoseconds of the last period to execute the component.
175176
Functions which use floating-point can also refer to 'fperiod' which is the floating-point time in seconds, or (period*1e-9).
176-
This can be useful in components that need the timing information.
177+
This can be useful in components that need the timing information. See also 'option period' below.
177178

178179
== Syntax
179180

@@ -292,18 +293,24 @@ r"\fIexample\fB"
292293

293294
The currently defined options are:
294295

295-
* 'option singleton yes' - (default: no)
296-
Do not create a 'count' module parameter, and always create a single instance.
297-
With 'singleton', items are named 'component-name.item-name' and without 'singleton', items for numbered instances are named 'component-name.<num>.item-name'.
298-
* 'option default_count number' - (default: 1)
299-
Normally, the module parameter 'count' defaults to 1. If specified, the 'count' will default to this value instead.
300-
* 'option count_function yes' - (default: no)
301-
Normally, the number of instances to create is specified in the module parameter 'count';
302-
if 'count_function' is specified, the value returned by the function 'int get_count(void)' is used instead, and the 'count' module parameter is not defined.
303-
* 'option rtapi_app no' - (default: yes)
296+
* 'option singleton yes' - (default: no) +
297+
Do not create a 'count' module parameter, and always create a single instance. With
298+
'singleton', items are named 'component-name.item-name' and without 'singleton', items for
299+
numbered instances are named 'component-name.<num>.item-name'.
300+
301+
* 'option default_count number' - (default: 1) +
302+
Normally, the module parameter 'count' defaults to 1. If specified, the 'count' will default
303+
to this value instead.
304+
305+
* 'option count_function yes' - (default: no) +
306+
Normally, the number of instances to create is specified in the module parameter 'count'; if
307+
'count_function' is specified, the value returned by the function 'int get_count(void)' is
308+
used instead, and the 'count' module parameter is not defined.
309+
310+
* 'option rtapi_app no' - (default: yes) +
304311
Normally, the functions `rtapi_app_main()` and `rtapi_app_exit()` are automatically defined.
305312
With 'option rtapi_app no', they are not, and must be provided in the C code.
306-
Use the following prototypes:
313+
Use the following prototypes: +
307314
+
308315
----
309316
`int rtapi_app_main(void);`
@@ -339,15 +346,15 @@ When implementing your own `rtapi_app_main()`, call the function `int export(cha
339346
This function may process the commandline arguments or take other actions.
340347
Its return type is 'void'; it may call 'exit()' if it wishes to terminate rather than create a HAL component (e.g., because the commandline arguments were invalid).
341348

342-
* 'option extra_link_args "..."' - (default: "")
349+
* 'option extra_link_args "..."' - (default: "") +
343350
This option is ignored if the option 'userspace' (see above) is set to 'no'.
344351
When linking a non-realtime component, the arguments given are inserted in the link line.
345352
Note that because compilation takes place in a temporary directory,
346353
"-L." refers to the temporary directory and not the directory where the .comp source file resides.
347354
This option can be set in the halcompile command-line with -extra-link-args="-L.....".
348355
This alternative provides a way to set extra flags in cases where the input file is a .c file rather than a .comp file.
349356

350-
* 'option extra_compile_args "..."' - (default: "")
357+
* 'option extra_compile_args "..."' - (default: "") +
351358
This option is ignored if the option 'userspace' (see above) is set to 'no'.
352359
When compiling a non-realtime component, the arguments given are inserted in the compiler command line.
353360
If the input file is a .c file this option can be set in the halcompile command-line with --extra-compile-args="-I.....".
@@ -359,6 +366,14 @@ When implementing your own `rtapi_app_main()`, call the function `int export(cha
359366
* 'option tpmod yes' - (default: no) +
360367
Module is a custom Trajectory Planning (tp) module loaded using `[TRAJ]TPMOD=`__modulename__ .
361368

369+
* 'option period no' - (default: yes) +
370+
Control the implicit 'period' parameter of the function(s) defined in the component. A
371+
standard function has an implicit parameter 'period'. Many components do no use the 'period'
372+
parameter and would cause a "unused parameter" compiler warning. Setting 'option period no'
373+
creates a function declaration omitting the 'period' parameter preventing the warning.
374+
Setting this option will also prevent 'fperiod' from being defined, as it depends on
375+
'period'.
376+
362377
If an option's VALUE is not specified, then it is equivalent to specifying 'option … yes'. +
363378
The result of assigning an inappropriate value to an option is undefined. +
364379
The result of using any other option is undefined. +
@@ -432,7 +447,7 @@ they will generally be referred to using the macros below.
432447
The details of `struct __comp_state` and these macros may change from one version of 'halcompile' to the next.
433448

434449
* `FUNCTION(`__name__`)` - Use this macro to begin the definition of a realtime function, which was previously declared with 'function NAME'.
435-
The function includes a parameter 'period' which is the integer number of nanoseconds between calls to the function.
450+
The function includes a parameter 'period' which is the integer number of nanoseconds between calls to the function. See also 'option period' above.
436451
* `EXTRA_SETUP()` - Use this macro to begin the definition of the function called to perform extra setup of this instance.
437452
Return a negative UNIX 'errno' value to indicate failure (e.g., 'return -EBUSY' on failure to reserve an I/O port), or 0 to indicate success.
438453
* `EXTRA_CLEANUP()` - Use this macro to begin the definition of the function called to perform extra cleanup of the component.
@@ -450,7 +465,7 @@ When the item is a conditional item, it is only legal to refer to it when its 'c
450465
* '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.
451466
When 'variable_name' is an array, the normal C-style subscript is used: 'variable_name[idx]'.
452467
* 'data' - If "option data" is specified, this macro allows access to the instance data.
453-
* 'fperiod' - The floating-point number of seconds between calls to this realtime function.
468+
* 'fperiod' - The floating-point number of seconds between calls to this realtime function. See also 'option period' above.
454469
* `FOR_ALL_INSTS() {`...`}` - For non-realtime components.
455470
This macro iterates over all the defined instances.
456471
Inside the body of the loop, the 'pin_name', 'parameter_name', and 'data' macros work as they do in realtime functions.
@@ -505,6 +520,7 @@ The file name must match the component name.
505520
component constant;
506521
pin out float out;
507522
param r float value = 1.0;
523+
option period no;
508524
function _;
509525
license "GPL"; // indicates GPL v2 or later
510526
;;
@@ -526,6 +542,7 @@ component sincos;
526542
pin out float sin_;
527543
pin out float cos_;
528544
pin in float theta;
545+
option period no;
529546
function _;
530547
license "GPL"; // indicates GPL v2 or later
531548
;;
@@ -548,6 +565,7 @@ param r unsigned ioaddr;
548565
549566
function _;
550567
568+
option period no;
551569
option count_function;
552570
option extra_setup;
553571
option extra_cleanup;
@@ -613,6 +631,7 @@ This realtime component illustrates use of fixed-size arrays:
613631
component arraydemo "4-bit Shift register";
614632
pin in bit in;
615633
pin out bit out-# [4];
634+
option period no;
616635
function _ nofp;
617636
license "GPL"; // indicates GPL v2 or later
618637
;;
@@ -654,6 +673,7 @@ pin in bit in-##[16 : personality & 0xff];
654673
pin out bit and if personality & 0x100;
655674
pin out bit or if personality & 0x200;
656675
pin out bit xor if personality & 0x400;
676+
option period no;
657677
function _ nofp;
658678
description """
659679
Experimental general 'logic function' component. Can perform 'and', 'or'
@@ -706,6 +726,7 @@ pin in s32 in;
706726
pin out bit out1;
707727
pin out bit out2;
708728
729+
option period no;
709730
function _;
710731
license "GPL";
711732
;;

src/hal/components/abs.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pin out bit sign "Sign of input, false for positive, true for negative" ;
2121
pin out bit is_positive "TRUE if input is positive, FALSE if input is 0 or negative";
2222
pin out bit is_negative "TRUE if input is negative, FALSE if input is 0 or positive";
2323

24+
option period no;
2425
function _;
2526
license "GPL";
2627
author "John Kasunich";

src/hal/components/abs_s32.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pin out bit sign "Sign of input, false for positive, true for negative" ;
2121
pin out bit is_positive "TRUE if input is positive, FALSE if input is 0 or negative";
2222
pin out bit is_negative "TRUE if input is negative, FALSE if input is 0 or positive";
2323

24+
option period no;
2425
function _ nofp;
2526
license "GPL";
2627
author "Sebastian Kuzminsky";

src/hal/components/abs_s64.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pin out bit sign "Sign of input, false for positive, true for negative" ;
2323
pin out bit is_positive "true if input is positive, false if input is 0 or negative";
2424
pin out bit is_negative "true if input is negative, false if input is 0 or positive";
2525

26+
option period no;
2627
function _ nofp;
2728
license "GPL";
2829
author "ArcEye based on code from Sebastian Kuzminsky";

src/hal/components/and2.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Otherwise,
1414
\\fBout=FALSE\\fR
1515
.RE"""
1616
;
17+
option period no;
1718
function _ nofp;
1819
see_also """
1920
\\fBlogic\\fR(9),

src/hal/components/bin2gray.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pin in unsigned in "binary code in";
44
pin out unsigned out "gray code out";
55
license "GPL";
66
author "Andy Pugh";
7+
option period no;
78
function _ nofp;
89
;;
910
out = (in >> 1) ^ in;

src/hal/components/biquad.comp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ typedef struct {
9898

9999
EXTRA_SETUP()
100100
{
101+
(void)prefix;
102+
(void)extra_arg;
101103
data.lastEnable = 0;
102104

103105
return(0);

src/hal/components/bitslice.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ author "Andy Pugh";
99
license "GPL2+";
1010
function _ nofp;
1111
option personality yes;
12+
option period no;
1213
;;
1314
int i;
1415
for (i = 0; i < personality ; i++){

src/hal/components/bitwise.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pin out u32 out-xnor "The inverse of the bitwise XOR";
1111
author "Andy Pugh";
1212
license "GPL 2+";
1313
function _ nofp;
14+
option period no;
1415
;;
1516

1617
out_and = (in0 & in1);

src/hal/components/bldc.comp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ FUNCTION(_) {
515515
phase_angle -= floor(phase_angle);
516516

517517
if (! (ph & old_ph)){ hall_error = 1;}
518-
if (pattern != old_pattern){hall_error = 0;}
518+
if (pattern != (unsigned)old_pattern){hall_error = 0;}
519519

520520
if (force_trap) break;
521521

@@ -797,7 +797,7 @@ FUNCTION(_) {
797797
return;
798798

799799
case 0x400: // Hall Output
800-
for (i = 0; P[(output_pattern << 3) + i] != ph && i < 8 ; i++) {}
800+
for (i = 0; P[(output_pattern << 3) + i] != ((unsigned)ph & 0xff) && i < 8 ; i++) {}
801801
hall1_out = (i & 0x04);
802802
hall2_out = (i & 0x02);
803803
hall3_out = (i & 0x01);
@@ -849,6 +849,7 @@ FUNCTION(_) {
849849
}
850850

851851
EXTRA_SETUP(){
852+
(void)prefix;
852853
int i;
853854
char c;
854855
for (i = 0; cfg[extra_arg][i] != 0 && i < NUM_TAG ; i++){

0 commit comments

Comments
 (0)