Skip to content

Commit 7abc481

Browse files
author
Meet Patel
committed
refactor(ulp_riscv): Modify ESP_EARLY_LOG to ESP_LOG and move it outside critical section
Moved the error logs outside critical section for i2c communication errors like READ fail, WRITE fail etc. in the ulp_riscv_i2c component Also changed the error log API from ESP_EARLY_LOG to ESP_LOG, so we can support tag based filtering and enabling/disabling of logs Closes #17425
1 parent 65a6e9c commit 7abc481

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

components/ulp/ulp_riscv/ulp_riscv_i2c.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -321,6 +321,7 @@ void ulp_riscv_i2c_master_read_from_device(uint8_t *data_rd, size_t size)
321321
uint32_t i = 0;
322322
uint32_t cmd_idx = 0;
323323
esp_err_t ret = ESP_OK;
324+
uint32_t status = 0;
324325

325326
if (size == 0) {
326327
// Quietly return
@@ -379,17 +380,20 @@ void ulp_riscv_i2c_master_read_from_device(uint8_t *data_rd, size_t size)
379380
/* Clear the Rx data interrupt bit */
380381
SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, RTC_I2C_RX_DATA_INT_CLR);
381382
} else {
382-
ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Read Failed!");
383-
uint32_t status = READ_PERI_REG(RTC_I2C_INT_RAW_REG);
384-
ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status);
385-
ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG));
383+
status = READ_PERI_REG(RTC_I2C_INT_RAW_REG);
386384
SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, status);
387385
break;
388386
}
389387
}
390388

391389
portEXIT_CRITICAL(&rtc_i2c_lock);
392390

391+
if (ret != ESP_OK) {
392+
ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Read Failed!");
393+
ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status);
394+
ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG));
395+
}
396+
393397
/* Clear the RTC I2C transmission bits */
394398
CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START_FORCE);
395399
CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START);
@@ -417,6 +421,7 @@ void ulp_riscv_i2c_master_write_to_device(uint8_t *data_wr, size_t size)
417421
uint32_t i = 0;
418422
uint32_t cmd_idx = 0;
419423
esp_err_t ret = ESP_OK;
424+
uint32_t status = 0;
420425

421426
if (size == 0) {
422427
// Quietly return
@@ -455,17 +460,21 @@ void ulp_riscv_i2c_master_write_to_device(uint8_t *data_wr, size_t size)
455460
/* Clear the Tx data interrupt bit */
456461
SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, RTC_I2C_TX_DATA_INT_CLR);
457462
} else {
458-
ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Write Failed!");
459-
uint32_t status = READ_PERI_REG(RTC_I2C_INT_RAW_REG);
460-
ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status);
461-
ESP_EARLY_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG));
463+
status = READ_PERI_REG(RTC_I2C_INT_RAW_REG);
462464
SET_PERI_REG_MASK(RTC_I2C_INT_CLR_REG, status);
463465
break;
464466
}
465467
}
466468

467469
portEXIT_CRITICAL(&rtc_i2c_lock);
468470

471+
/* In case of error, print the status after critical section */
472+
if (ret != ESP_OK) {
473+
ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: Write Failed!");
474+
ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x%"PRIx32"", status);
475+
ESP_LOGE(RTCI2C_TAG, "ulp_riscv_i2c: RTC I2C Status Reg 0x%"PRIx32"", READ_PERI_REG(RTC_I2C_STATUS_REG));
476+
}
477+
469478
/* Clear the RTC I2C transmission bits */
470479
CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START_FORCE);
471480
CLEAR_PERI_REG_MASK(SENS_SAR_I2C_CTRL_REG, SENS_SAR_I2C_START);

0 commit comments

Comments
 (0)