Skip to content

Commit fa2c769

Browse files
committed
refactor: port mode
Remove unused code and duplicated lines for setting port.
1 parent ef8865b commit fa2c769

File tree

1 file changed

+12
-50
lines changed

1 file changed

+12
-50
lines changed

src/iolm.c

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -391,34 +391,6 @@ iolink_smi_errortypes_t wait_smi_cnf (enum evt_type wait_evt, uint32_t ms)
391391
return errortype;
392392
}
393393

394-
395-
static uint8_t iolink_config_port_sdci_auto(uint8_t port_no)
396-
{
397-
arg_block_portconfiglist_t port_cfg;
398-
399-
iolink_common_config (
400-
&port_cfg,
401-
0,
402-
0,
403-
0 /* AFAP (As fast as possible) */,
404-
IOLINK_PORTMODE_IOL_AUTO,
405-
IOLINK_VALIDATION_CHECK_NO);
406-
407-
iolink_error_t err = SMI_PortConfiguration_req (
408-
port_no+1,
409-
IOLINK_ARG_BLOCK_ID_VOID_BLOCK,
410-
sizeof (arg_block_portconfiglist_t),
411-
(arg_block_t *)&port_cfg);
412-
413-
414-
if ( (err != IOLINK_ERROR_NONE) ||
415-
(wait_smi_cnf ( PortCnf, SMI_PORT_CFG_TIMEOUT) != IOLINK_SMI_ERRORTYPE_NONE))
416-
{
417-
return 1;
418-
}
419-
return 0;
420-
}
421-
422394
static uint8_t iolink_config_port_sdci(uint8_t port_no,
423395
uint16_t vid,
424396
uint32_t did,
@@ -511,6 +483,16 @@ static uint8_t iolink_config_port_inactive (uint8_t portno)
511483
return 0;
512484
}
513485

486+
487+
static uint8_t iolink_set_sdci(uint8_t port_no) {
488+
return iolink_config_port_sdci(port_no,
489+
user_port_cfg[port_no].vid,
490+
user_port_cfg[port_no].did,
491+
user_port_cfg[port_no].cycle_time_us,
492+
user_port_cfg[port_no].portmode,
493+
user_port_cfg[port_no].validation);
494+
}
495+
514496
static uint8_t iolink_config_port (uint8_t port_no,
515497
iolink_portmode_t port_mode)
516498
{
@@ -525,7 +507,7 @@ static uint8_t iolink_config_port (uint8_t port_no,
525507
break;
526508
case IOLINK_PORTMODE_IOL_MAN:
527509
case IOLINK_PORTMODE_IOL_AUTO:
528-
res = iolink_config_port_sdci_auto (port_no);
510+
res = iolink_set_sdci (port_no);
529511
break;
530512
case IOLINK_PORTMODE_DEACTIVE:
531513
res = iolink_config_port_inactive (port_no);
@@ -534,15 +516,6 @@ static uint8_t iolink_config_port (uint8_t port_no,
534516
return res;
535517
}
536518

537-
static uint8_t iolink_set_sdci(uint8_t port_no) {
538-
return iolink_config_port_sdci(port_no,
539-
user_port_cfg[port_no].vid,
540-
user_port_cfg[port_no].did,
541-
user_port_cfg[port_no].cycle_time_us,
542-
user_port_cfg[port_no].portmode,
543-
user_port_cfg[port_no].validation);
544-
}
545-
546519
void iolm_set_port_evt_cb(iolm_port_evt_cb cb, void * arg) {
547520
port_evt_cb = cb;
548521
port_evt_arg = arg;
@@ -605,18 +578,7 @@ int iolm_init(const struct iolm_port_cfg * init_cfg){
605578
iolink_dl_instantiate (port,0,0);
606579

607580
uint8_t port_res;
608-
switch(user_port_cfg[port_no].portmode) {
609-
case IOLINK_PORTMODE_DEACTIVE:
610-
case IOLINK_PORTMODE_DI_CQ:
611-
case IOLINK_PORTMODE_DO_CQ:
612-
port_res = iolink_config_port(port_no, user_port_cfg[port_no].portmode);
613-
break;
614-
case IOLINK_PORTMODE_IOL_MAN:
615-
case IOLINK_PORTMODE_IOL_AUTO:
616-
port_res = iolink_set_sdci(port_no);
617-
break;
618-
619-
}
581+
port_res = iolink_config_port(port_no, user_port_cfg[port_no].portmode);
620582
if (port_res != 0) {
621583
LOG_ERR("Port %d config failed", port_no);
622584
return -EIO;

0 commit comments

Comments
 (0)