Skip to content

Commit

Permalink
Merge pull request #2774 from heeplr/hal_export_functf
Browse files Browse the repository at this point in the history
introduce hal_export_functf()
  • Loading branch information
andypugh authored Dec 11, 2023
2 parents cac8b1b + 4cd038d commit 2c32f7e
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 173 deletions.
1 change: 1 addition & 0 deletions docs/man/man3/hal_export_functf.3hal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.so man3/hal_export_funct.3hal
1 change: 1 addition & 0 deletions docs/po4a.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
[type: man_def] man/man3/hal_del_funct_from_thread.3hal $lang:man/$lang/man3/hal_del_funct_from_thread.3hal
[type: man_def] man/man3/hal_exit.3hal $lang:man/$lang/man3/hal_exit.3hal
[type: man_def] man/man3/hal_export_funct.3hal $lang:man/$lang/man3/hal_export_funct.3hal
[type: man_def] man/man3/hal_export_functf.3hal $lang:man/$lang/man3/hal_export_functf.3hal
[type: man_def] man/man3/hal_float_t.3hal $lang:man/$lang/man3/hal_float_t.3hal
[type: man_def] man/man3/hal_get_lock.3hal $lang:man/$lang/man3/hal_get_lock.3hal
[type: man_def] man/man3/hal_init.3hal $lang:man/$lang/man3/hal_init.3hal
Expand Down
1 change: 1 addition & 0 deletions docs/src/hal/components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ hal_create_thread.3hal
hal_del_funct_from_thread.3hal
hal_exit.3hal
hal_export_funct.3hal
hal_export_functf.3hal
hal_float_t.3hal
hal_get_lock.3hal
hal_init.3hal
Expand Down
48 changes: 23 additions & 25 deletions src/hal/components/boss_plc.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ typedef struct {
hal_bit_t limitNeg;
} Limit;

static int Limit_Export(Limit *this, int compId, int id, char *name, char axis);
static int Limit_Export(Limit *this, int compId, int id, char axis);
static void Limit_Init(Limit *this);
static BOOL Limit_IsActive(Limit *this);
static void Limit_Refresh(Limit *this, hal_bit_t override);
Expand All @@ -225,7 +225,7 @@ typedef struct {
hal_bit_t lastEnable;
} Amp;

static int Amp_Export(Amp *this, int compId, int id, char *name, char axis);
static int Amp_Export(Amp *this, int compId, int id, char axis);
static void Amp_Init(Amp *this);
static void Amp_Refresh(Amp *this, long period, hal_u32_t readyDelay);

Expand Down Expand Up @@ -313,11 +313,11 @@ typedef struct {
// These methods are used for initialization.
static int Plc_Init(Plc *this);
static int Plc_Export(Plc *this, int compId, int id);
static int Plc_ExportFeed(Plc *this, int compId, int id, char *name);
static int Plc_ExportLimits(Plc *this, int compId, int id, char *name);
static int Plc_ExportAmps(Plc *this, int compId, int id, char *name);
static int Plc_ExportSpindle(Plc *this, int compId, int id, char *name);
static int Plc_ExportJog(Plc *this, int compId, int id, char *name);
static int Plc_ExportFeed(Plc *this, int compId, int id);
static int Plc_ExportLimits(Plc *this, int compId, int id);
static int Plc_ExportAmps(Plc *this, int compId, int id);
static int Plc_ExportSpindle(Plc *this, int compId, int id);
static int Plc_ExportJog(Plc *this, int compId, int id);

// These methods are exported to the HAL.
static void Plc_Refresh(void *this, long period);
Expand Down Expand Up @@ -468,7 +468,6 @@ static int
Plc_Export(Plc *this, int compId, int id)
{
int msgLevel, error;
char name[HAL_NAME_LEN + 1];

// This function exports a lot of stuff, which results in a lot of
// logging if msg_level is at INFO or ALL. So we save the current value
Expand All @@ -478,27 +477,26 @@ Plc_Export(Plc *this, int compId, int id)
rtapi_set_msg_level(RTAPI_MSG_WARN);

// Export pins and parameters.
error = Plc_ExportFeed(this, compId, id, name);
error = Plc_ExportFeed(this, compId, id);

if(!error){
error = Plc_ExportLimits(this, compId, id, name);
error = Plc_ExportLimits(this, compId, id);
}

if(!error){
error = Plc_ExportAmps(this, compId, id, name);
error = Plc_ExportAmps(this, compId, id);
}

if(!error){
error = Plc_ExportSpindle(this, compId, id, name);
error = Plc_ExportSpindle(this, compId, id);
}
if(!error){
error = Plc_ExportJog(this, compId, id, name);
error = Plc_ExportJog(this, compId, id);
}

// Export functions.
if(!error){
rtapi_snprintf(name, sizeof(name), "boss_plc.%d.refresh", id);
error = hal_export_funct(name, Plc_Refresh, this, 1, 0, compId);
error = hal_export_functf(Plc_Refresh, this, 1, 0, compId, "boss_plc.%d.refresh", id);
}

// Restore saved message level.
Expand All @@ -509,7 +507,7 @@ Plc_Export(Plc *this, int compId, int id)


static int
Plc_ExportFeed(Plc *this, int compId, int id, char *name)
Plc_ExportFeed(Plc *this, int compId, int id)
{
int error;

Expand Down Expand Up @@ -578,7 +576,7 @@ Plc_ExportFeed(Plc *this, int compId, int id, char *name)


static int
Plc_ExportLimits(Plc *this, int compId, int id, char *name)
Plc_ExportLimits(Plc *this, int compId, int id)
{
int error;

Expand All @@ -592,11 +590,11 @@ Plc_ExportLimits(Plc *this, int compId, int id, char *name)
}

if(!error){
error = Limit_Export(&this->xLimit, compId, id, name, axisNames[0]);
error = Limit_Export(&this->xLimit, compId, id, axisNames[0]);
}

if(!error){
error = Limit_Export(&this->yLimit, compId, id, name, axisNames[1]);
error = Limit_Export(&this->yLimit, compId, id, axisNames[1]);
}

if(!error){
Expand Down Expand Up @@ -642,7 +640,7 @@ Plc_ExportLimits(Plc *this, int compId, int id, char *name)


static int
Plc_ExportAmps(Plc *this, int compId, int id, char *name)
Plc_ExportAmps(Plc *this, int compId, int id)
{
int error, i;
Amp *pAmp;
Expand All @@ -652,15 +650,15 @@ Plc_ExportAmps(Plc *this, int compId, int id, char *name)

pAmp = this->amps;
for(i = 0; i < NUM_AXIS && !error; i++, pAmp++){
error = Amp_Export(pAmp, compId, id, name, axisNames[i]);
error = Amp_Export(pAmp, compId, id, axisNames[i]);
}

return(error);
}


static int
Plc_ExportSpindle(Plc *this, int compId, int id, char *name)
Plc_ExportSpindle(Plc *this, int compId, int id)
{
int error;

Expand Down Expand Up @@ -742,7 +740,7 @@ Plc_ExportSpindle(Plc *this, int compId, int id, char *name)


static int
Plc_ExportJog(Plc *this, int compId, int id, char *name)
Plc_ExportJog(Plc *this, int compId, int id)
{
int error, i;

Expand Down Expand Up @@ -969,7 +967,7 @@ Plc_RefreshJog(Plc *this, long period)
******************************************************************************/

static int
Limit_Export(Limit *this, int compId, int id, char *name, char axis)
Limit_Export(Limit *this, int compId, int id, char axis)
{
int error;

Expand Down Expand Up @@ -1084,7 +1082,7 @@ Limit_Refresh(Limit *this, hal_bit_t override)
******************************************************************************/

static int
Amp_Export(Amp *this, int compId, int id, char *name, char axis)
Amp_Export(Amp *this, int compId, int id, char axis)
{
int error;

Expand Down
11 changes: 4 additions & 7 deletions src/hal/components/debounce.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ static void debounce(void *arg, long period)
static int export_group(int num, debounce_group_t * addr, int group_size)
{
int n, retval, msg;
char buf[HAL_NAME_LEN + 1];

/* This function exports a lot of stuff, which results in a lot of
logging if msg_level is at INFO or ALL. So we save the current value
Expand All @@ -246,19 +245,17 @@ static int export_group(int num, debounce_group_t * addr, int group_size)
return -1;
}
/* export param variable for delay */
rtapi_snprintf(buf, sizeof(buf), "debounce.%d.delay", num);
retval = hal_param_s32_new(buf, HAL_RW, &(addr->delay), comp_id);
retval = hal_param_s32_newf(HAL_RW, &(addr->delay), comp_id, "debounce.%d.delay", num);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"DEBOUNCE: ERROR: '%s' param export failed\n", buf);
"DEBOUNCE: ERROR: 'debounce.%d.delay' param export failed\n", num);
return retval;
}
/* export function */
rtapi_snprintf(buf, sizeof(buf), "debounce.%d", num);
retval = hal_export_funct(buf, debounce, addr, 0, 0, comp_id);
retval = hal_export_functf(debounce, addr, 0, 0, comp_id, "debounce.%d", num);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"DEBOUNCE: ERROR: '%s' funct export failed\n", buf);
"DEBOUNCE: ERROR: 'debounce.%d' funct export failed\n", num);
return -1;
}
/* set default parameter values */
Expand Down
8 changes: 2 additions & 6 deletions src/hal/components/mux_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,8 @@ int rtapi_app_main(void){
inst->out_type = inst->in_type;
}

retval = rtapi_snprintf(hal_name, HAL_NAME_LEN, "mux-gen.%02i", i);
if (retval >= HAL_NAME_LEN) {
goto fail0;
}
if (inst->in_type == HAL_FLOAT || inst->out_type == HAL_FLOAT) {
retval = hal_export_funct(hal_name, write_fp, inst, 1, 0, comp_id);
retval = hal_export_functf(write_fp, inst, 1, 0, comp_id, "mux-gen.%02i", i);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "mux_generic: ERROR: function export"
" failed\n");
Expand All @@ -182,7 +178,7 @@ int rtapi_app_main(void){
}
else
{
retval = hal_export_funct(hal_name, write_nofp, inst, 0, 0, comp_id);
retval = hal_export_functf(write_nofp, inst, 0, 0, comp_id, "mux-gen.%02i", i);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "mux_generic: ERROR: function export"
" failed\n");
Expand Down
4 changes: 1 addition & 3 deletions src/hal/components/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ static void calc_pid(void *arg, long period)
static int export_pid(hal_pid_t * addr, char * prefix)
{
int retval, msg;
char buf[HAL_NAME_LEN + 1];

/* This function exports a lot of stuff, which results in a lot of
logging if msg_level is at INFO or ALL. So we save the current value
Expand Down Expand Up @@ -963,9 +962,8 @@ static int export_pid(hal_pid_t * addr, char * prefix)
*(addr->pTuneStart) = 0;
#endif /* AUTO_TUNER */
/* export function for this loop */
rtapi_snprintf(buf, sizeof(buf), "%s.do-pid-calcs", prefix);
retval =
hal_export_funct(buf, calc_pid, addr, 1, 0, comp_id);
hal_export_functf(calc_pid, addr, 1, 0, comp_id, "%s.do-pid-calcs", prefix);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
NAME ": ERROR: do_pid_calcs funct export failed\n");
Expand Down
3 changes: 1 addition & 2 deletions src/hal/components/sampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ static int init_sampler(int num, sampler_t *str)
pptr++;
}
/* export update function */
rtapi_snprintf(buf, sizeof(buf), "sampler.%d", num);
retval = hal_export_funct(buf, sample, str, usefp, 0, comp_id);
retval = hal_export_functf(sample, str, usefp, 0, comp_id, "sampler.%d", num);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"SAMPLER: ERROR: function export failed\n");
Expand Down
6 changes: 2 additions & 4 deletions src/hal/components/siggen.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ static void calc_siggen(void *arg, long period)
static int export_siggen(int num, hal_siggen_t * addr,char* prefix)
{
int retval;
char buf[HAL_NAME_LEN + 1];

/* export pins */
retval = hal_pin_float_newf(HAL_OUT, &(addr->square), comp_id,
Expand Down Expand Up @@ -342,10 +341,9 @@ static int export_siggen(int num, hal_siggen_t * addr,char* prefix)
*(addr->offset) = 0.0;
addr->index = 0.0;
/* export function for this loop */
rtapi_snprintf(buf, sizeof(buf), "%s.update", prefix);
retval =
hal_export_funct(buf, calc_siggen, &(siggen_array[num]), 1, 0,
comp_id);
hal_export_functf(calc_siggen, &(siggen_array[num]), 1, 0,
comp_id, "%s.update", prefix);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"SIGGEN: ERROR: update funct export failed\n");
Expand Down
3 changes: 1 addition & 2 deletions src/hal/components/streamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ static int init_streamer(int num, streamer_t *str)
pptr++;
}
/* export update function */
rtapi_snprintf(buf, sizeof(buf), "streamer.%d", num);
retval = hal_export_funct(buf, update, str, usefp, 0, comp_id);
retval = hal_export_functf(update, str, usefp, 0, comp_id, "streamer.%d", num);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"STREAMER: ERROR: function export failed\n");
Expand Down
6 changes: 2 additions & 4 deletions src/hal/components/supply.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ static void update_supply(void *arg, long l)
static int export_supply(int num, hal_supply_t * addr)
{
int retval;
char buf[HAL_NAME_LEN + 1];

/* export pins */
retval = hal_pin_bit_newf(HAL_OUT, &(addr->q), comp_id, "supply.%d.q", num);
Expand Down Expand Up @@ -195,10 +194,9 @@ static int export_supply(int num, hal_supply_t * addr)
*(addr->d) = 0;
*(addr->value) = 0.0;
/* export function for this loop */
rtapi_snprintf(buf, sizeof(buf), "supply.%d.update", num);
retval =
hal_export_funct(buf, update_supply, &(supply_array[num]), 1, 0,
comp_id);
hal_export_functf(update_supply, &(supply_array[num]), 1, 0,
comp_id, "supply.%d.update", num);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"SUPPLY: ERROR: update funct export failed\n");
Expand Down
13 changes: 4 additions & 9 deletions src/hal/drivers/hal_ax5214h.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ int rtapi_app_main(void)
{
char *cp;
char *argv[MAX_TOK];
char name[HAL_NAME_LEN + 1];
int n, retval;

/* test for config string */
Expand Down Expand Up @@ -235,22 +234,18 @@ int rtapi_app_main(void)
}
/* export functions for each board */
for (n = 0; n < num_boards; n++) {
/* make read function name */
rtapi_snprintf(name, sizeof(name), "ax5214h.%d.read", n);
/* export read function */
retval = hal_export_funct(name, read_board, &(board_array[n]),
0, 0, comp_id);
retval = hal_export_functf(read_board, &(board_array[n]),
0, 0, comp_id, "ax5214h.%d.read", n);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"AX5214H: ERROR: port %d read funct export failed\n", n);
hal_exit(comp_id);
return -1;
}
/* make write function name */
rtapi_snprintf(name, sizeof(name), "ax5214h.%d.write", n);
/* export write function */
retval = hal_export_funct(name, write_board, &(board_array[n]),
0, 0, comp_id);
retval = hal_export_functf(write_board, &(board_array[n]),
0, 0, comp_id, "ax5214h.%d.write", n);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"AX5214H: ERROR: port %d write funct export failed\n", n);
Expand Down
7 changes: 2 additions & 5 deletions src/hal/drivers/hal_bb_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ int configure_gpio_port(int n) {
}

int rtapi_app_main(void) {
char name[HAL_NAME_LEN + 1];
int n, retval;
char *data, *token;

Expand Down Expand Up @@ -359,16 +358,14 @@ int rtapi_app_main(void) {


// export functions
rtapi_snprintf(name, sizeof(name), "bb_gpio.write");
retval = hal_export_funct(name, write_port, port_data, 0, 0, comp_id);
retval = hal_export_funct("bb_gpio.write", write_port, port_data, 0, 0, comp_id);
if(retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: port %d write funct export failed\n", modname, n);
hal_exit(comp_id);
return -1;
}

rtapi_snprintf(name, sizeof(name), "bb_gpio.read");
retval = hal_export_funct(name, read_port, port_data, 0, 0, comp_id);
retval = hal_export_funct("bb_gpio.read", read_port, port_data, 0, 0, comp_id);
if(retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: port %d read funct export failed\n", modname, n);
hal_exit(comp_id);
Expand Down
6 changes: 2 additions & 4 deletions src/hal/drivers/hal_evoreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ static void update_port(void *arg, long period);

int rtapi_app_main(void)
{
char name[HAL_NAME_LEN + 1];
int n,i , retval, num_dac, num_enc;

unsigned int base=0x300;
Expand Down Expand Up @@ -255,9 +254,8 @@ int rtapi_app_main(void)


/* STEP 4: export function */
rtapi_snprintf(name, sizeof(name), "evoreg.%d.update", n + 1);
retval = hal_export_funct(name, update_port, &(port_data_array[n]), 1, 0,
comp_id);
retval = hal_export_functf(update_port, &(port_data_array[n]), 1, 0,
comp_id, "evoreg.%d.update", n + 1);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"EVOREG: ERROR: port %d write funct export failed\n", n + 1);
Expand Down
Loading

0 comments on commit 2c32f7e

Please sign in to comment.