Skip to content

Commit

Permalink
eliminate unneeded rtapi_snprintf(); use new hal_export_functf()
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Dec 10, 2023
1 parent a0b0bba commit 4cd038d
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 148 deletions.
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
10 changes: 3 additions & 7 deletions src/hal/drivers/hal_gm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,22 +1096,18 @@ ExportMixed(void *arg, int comp_id)
static int ExportFunctions(void *arg, int comp_id, int boardId)
{
int error;
char str[HAL_NAME_LEN + 1];
gm_device_t *device = (gm_device_t *)arg;

rtapi_snprintf(str, sizeof(str), "gm.%d.write", boardId);
error = hal_export_funct(str, write, device, 1, 0, comp_id);
error = hal_export_functf(write, device, 1, 0, comp_id, "gm.%d.write", boardId);

if(error == 0)
{
rtapi_snprintf(str, sizeof(str), "gm.%d.read", boardId);
error = hal_export_funct(str, read, device, 1, 0, comp_id);
error = hal_export_functf(read, device, 1, 0, comp_id, "gm.%d.read", boardId);
}

if(error == 0)
{
rtapi_snprintf(str, sizeof(str), "gm.%d.RS485", boardId);
error = hal_export_funct(str, RS485, device, 1, 0, comp_id);
error = hal_export_functf(RS485, device, 1, 0, comp_id, "gm.%d.RS485", boardId);
}

return error;
Expand Down
10 changes: 3 additions & 7 deletions src/hal/drivers/hal_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ int build_chips_collection(char *name, hal_gpio_bulk_t **ptr, int *count){
int rtapi_app_main(void){
int retval = 0;
int i, c;
char hal_name[HAL_NAME_LEN];
const char *line_name;

#ifdef __KERNEL__
Expand Down Expand Up @@ -277,16 +276,13 @@ int rtapi_app_main(void){
}
}

rtapi_snprintf(hal_name, HAL_NAME_LEN, "hal_gpio.read");
retval += hal_export_funct(hal_name, hal_gpio_read, gpio, 0, 0, comp_id);
rtapi_snprintf(hal_name, HAL_NAME_LEN, "hal_gpio.write");
retval += hal_export_funct(hal_name, hal_gpio_write, gpio, 0, 0, comp_id);
retval += hal_export_funct("hal_gpio.read", hal_gpio_read, gpio, 0, 0, comp_id);
retval += hal_export_funct("hal_gpio.write", hal_gpio_write, gpio, 0, 0, comp_id);

if (reset_active){
gpio->reset_ns = hal_malloc(sizeof(hal_u32_t));
rtapi_snprintf(hal_name, HAL_NAME_LEN, "hal_gpio.reset");
retval += hal_param_u32_newf(HAL_RW, gpio->reset_ns, comp_id, "hal_gpio.reset_ns");
retval += hal_export_funct(hal_name, hal_gpio_reset, gpio, 0, 0, comp_id);
retval += hal_export_funct("hal_gpio.reset", hal_gpio_reset, gpio, 0, 0, comp_id);
}
if (retval < 0){
rtapi_print_msg(RTAPI_MSG_ERR, "hal_gpio: failed to export functions\n");
Expand Down
23 changes: 6 additions & 17 deletions src/hal/drivers/hal_motenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ static int
Device_ExportEncoderPinsParametersFunctions(Device *this, int componentId, int boardId)
{
int halError, channel;
char name[HAL_NAME_LEN + 1];

// Export pins and parameters.
halError = 0;
Expand Down Expand Up @@ -529,8 +528,7 @@ Device_ExportEncoderPinsParametersFunctions(Device *this, int componentId, int b

// Export functions.
if(!halError){
rtapi_snprintf(name, sizeof(name), "motenc.%d.encoder-read", boardId);
halError = hal_export_funct(name, Device_EncoderRead, this, 1, 0, componentId);
halError = hal_export_functf(Device_EncoderRead, this, 1, 0, componentId, "motenc.%d.encoder-read", boardId);
}

if(halError){
Expand All @@ -546,7 +544,6 @@ static int
Device_ExportDacPinsParametersFunctions(Device *this, int componentId, int boardId)
{
int halError, channel;
char name[HAL_NAME_LEN + 1];

// Export pins and parameters.
halError = 0;
Expand All @@ -573,8 +570,7 @@ Device_ExportDacPinsParametersFunctions(Device *this, int componentId, int board

// Export functions.
if(!halError){
rtapi_snprintf(name, sizeof(name), "motenc.%d.dac-write", boardId);
halError = hal_export_funct(name, Device_DacWrite, this, 1, 0, componentId);
halError = hal_export_functf(Device_DacWrite, this, 1, 0, componentId, "motenc.%d.dac-write", boardId);
}

if(halError){
Expand All @@ -590,7 +586,6 @@ static int
Device_ExportAdcPinsParametersFunctions(Device *this, int componentId, int boardId)
{
int halError, channel;
char name[HAL_NAME_LEN + 1];

// Export pins and parameters.
halError = 0;
Expand All @@ -617,8 +612,7 @@ Device_ExportAdcPinsParametersFunctions(Device *this, int componentId, int board

// Export functions.
if(!halError){
rtapi_snprintf(name, sizeof(name), "motenc.%d.adc-read", boardId);
halError = hal_export_funct(name, Device_AdcRead, this, 1, 0, componentId);
halError = hal_export_functf(Device_AdcRead, this, 1, 0, componentId, "motenc.%d.adc-read", boardId);
}

if(halError){
Expand All @@ -634,7 +628,6 @@ static int
Device_ExportDigitalInPinsParametersFunctions(Device *this, int componentId, int boardId)
{
int halError, channel;
char name[HAL_NAME_LEN + 1];

// Export pins and parameters.
halError = 0;
Expand All @@ -655,8 +648,7 @@ Device_ExportDigitalInPinsParametersFunctions(Device *this, int componentId, int

// Export functions.
if(!halError){
rtapi_snprintf(name, sizeof(name), "motenc.%d.digital-in-read", boardId);
halError = hal_export_funct(name, Device_DigitalInRead, this, 0, 0, componentId);
halError = hal_export_funct(Device_DigitalInRead, this, 0, 0, componentId, "motenc.%d.digital-in-read", boardId);
}

if(halError){
Expand All @@ -672,7 +664,6 @@ static int
Device_ExportDigitalOutPinsParametersFunctions(Device *this, int componentId, int boardId)
{
int halError, channel;
char name[HAL_NAME_LEN + 1];

// Export pins and parameters.
halError = 0;
Expand All @@ -694,8 +685,7 @@ Device_ExportDigitalOutPinsParametersFunctions(Device *this, int componentId, in

// Export functions.
if(!halError){
rtapi_snprintf(name, sizeof(name), "motenc.%d.digital-out-write", boardId);
halError = hal_export_funct(name, Device_DigitalOutWrite, this, 0, 0, componentId);
halError = hal_export_functf(Device_DigitalOutWrite, this, 0, 0, componentId, "motenc.%d.digital-out-write", boardId);
}

if(halError){
Expand Down Expand Up @@ -743,8 +733,7 @@ Device_ExportMiscPinsParametersFunctions(Device *this, int componentId, int boar

// Export functions.
if(!halError){
rtapi_snprintf(name, sizeof(name), "motenc.%d.misc-update", boardId);
halError = hal_export_funct(name, Device_MiscUpdate, this, 0, 0, componentId);
halError = hal_export_functf(Device_MiscUpdate, this, 0, 0, componentId, "motenc.%d.misc-update", boardId);
}

if(halError){
Expand Down
Loading

0 comments on commit 4cd038d

Please sign in to comment.