Skip to content

Commit 7bb01c1

Browse files
authored
Merge pull request #15333 from OpenNuvoton/nuvoton_fix_i2c_role_switch
Nuvoton: I2C: Fix potential role switch failure
2 parents 807fd79 + dbc0f5b commit 7bb01c1

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
441441
case 0x08: // Start
442442
case 0x10: // Master Repeat Start
443443
if (i2c_ctl & I2C_CTL0_STA_Msk) {
444-
return 0;
444+
goto cleanup;
445445
} else {
446446
break;
447447
}
448448
case 0xF8: // Bus Released
449449
if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) {
450-
return 0;
450+
goto cleanup;
451451
} else {
452452
break;
453453
}
@@ -458,6 +458,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
458458
}
459459
}
460460

461+
cleanup:
462+
461463
i2c_enable_int(obj);
462464

463465
return err;

targets/TARGET_NUVOTON/TARGET_M251/i2c_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
425425
case 0x08: // Start
426426
case 0x10: // Master Repeat Start
427427
if (i2c_ctl & I2C_CTL0_STA_Msk) {
428-
return 0;
428+
goto cleanup;
429429
} else {
430430
break;
431431
}
432432
case 0xF8: // Bus Released
433433
if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) {
434-
return 0;
434+
goto cleanup;
435435
} else {
436436
break;
437437
}
@@ -442,6 +442,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
442442
}
443443
}
444444

445+
cleanup:
446+
445447
i2c_enable_int(obj);
446448

447449
return err;

targets/TARGET_NUVOTON/TARGET_M261/i2c_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
430430
case 0x08: // Start
431431
case 0x10: // Master Repeat Start
432432
if (i2c_ctl & I2C_CTL0_STA_Msk) {
433-
return 0;
433+
goto cleanup;
434434
} else {
435435
break;
436436
}
437437
case 0xF8: // Bus Released
438438
if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) {
439-
return 0;
439+
goto cleanup;
440440
} else {
441441
break;
442442
}
@@ -447,6 +447,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
447447
}
448448
}
449449

450+
cleanup:
451+
450452
i2c_enable_int(obj);
451453

452454
return err;

targets/TARGET_NUVOTON/TARGET_M451/i2c_api.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
448448
case 0x08: // Start
449449
case 0x10: // Master Repeat Start
450450
if (i2c_ctl & I2C_CTL_STA_Msk) {
451-
return 0;
451+
goto cleanup;
452452
}
453453
else {
454454
break;
455455
}
456456
case 0xF8: // Bus Released
457457
if (i2c_ctl & (I2C_CTL_STA_Msk | I2C_CTL_STO_Msk) == I2C_CTL_STO_Msk) {
458-
return 0;
458+
goto cleanup;
459459
}
460460
else {
461461
break;
@@ -472,8 +472,10 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
472472
}
473473
}
474474

475+
cleanup:
476+
475477
i2c_enable_int(obj);
476-
478+
477479
return err;
478480
}
479481

targets/TARGET_NUVOTON/TARGET_M480/i2c_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
432432
case 0x08: // Start
433433
case 0x10: // Master Repeat Start
434434
if (i2c_ctl & I2C_CTL0_STA_Msk) {
435-
return 0;
435+
goto cleanup;
436436
} else {
437437
break;
438438
}
439439
case 0xF8: // Bus Released
440440
if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) {
441-
return 0;
441+
goto cleanup;
442442
} else {
443443
break;
444444
}
@@ -449,6 +449,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
449449
}
450450
}
451451

452+
cleanup:
453+
452454
i2c_enable_int(obj);
453455

454456
return err;

targets/TARGET_NUVOTON/TARGET_NANO100/i2c_api.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
468468
case 0x08: // Start
469469
case 0x10: // Master Repeat Start
470470
if (i2c_ctl & I2C_CON_START_Msk) {
471-
return 0;
471+
goto cleanup;
472472
}
473473
else {
474474
break;
475475
}
476476
case 0xF8: // Bus Released
477477
if ((i2c_ctl & (I2C_CON_START_Msk | I2C_CON_STOP_Msk)) == I2C_CON_STOP_Msk) {
478-
return 0;
478+
goto cleanup;
479479
}
480480
else {
481481
break;
@@ -492,8 +492,10 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
492492
}
493493
}
494494

495+
cleanup:
496+
495497
i2c_enable_int(obj);
496-
498+
497499
return err;
498500
}
499501

targets/TARGET_NUVOTON/TARGET_NUC472/i2c_api.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
465465
case 0x08: // Start
466466
case 0x10: // Master Repeat Start
467467
if (i2c_ctl & I2C_CTL_STA_Msk) {
468-
return 0;
468+
goto cleanup;
469469
}
470470
else {
471471
break;
472472
}
473473
case 0xF8: // Bus Released
474474
if (i2c_ctl & (I2C_CTL_STA_Msk | I2C_CTL_STO_Msk) == I2C_CTL_STO_Msk) {
475-
return 0;
475+
goto cleanup;
476476
}
477477
else {
478478
break;
@@ -489,8 +489,10 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync)
489489
}
490490
}
491491

492+
cleanup:
493+
492494
i2c_enable_int(obj);
493-
495+
494496
return err;
495497
}
496498

0 commit comments

Comments
 (0)