Skip to content

Commit a396ffc

Browse files
authored
Fix error msg, Compiler Warning
Time out recover was generating a confusing error message when DEBUG level was set, Clarify meaning. Thanks to @valki2 When Arduino 1.8.5 configured for maximum compiler warning, my sloppy code generates multiple errors. :grimace: Thanks @PicoEmma I fixed most of the warnings, but I haven't figure out how to clear one type of them. I use a structure to decode a peripheral memory register, the compiler reports it as an: > C:\Users\e\Documents\Arduino\hardware\espressif\esp32\cores\esp32\esp32-hal-i2c.c: In function 'dumpCmdQueue': C:\Users\e\Documents\Arduino\hardware\espressif\esp32\cores\esp32\esp32-hal-i2c.c:399:17: warning: variable 'c' set but not used [-Wunused-but-set-variable] I2C_COMMAND_t c; ^ Chuck.
1 parent fc33cc0 commit a396ffc

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

cores/esp32/esp32-hal-i2c.c

+22-11
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ enum {
6464
#define I2C_MUTEX_UNLOCK()
6565

6666
static i2c_t _i2c_bus_array[2] = {
67-
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE_FIXED), 0,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0},
68-
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE_FIXED), 1,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0}
67+
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE_FIXED), 0,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0,0},
68+
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE_FIXED), 1,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0,0}
6969
};
7070
#else
7171
#define I2C_MUTEX_LOCK() do {} while (xSemaphoreTake(i2c->lock, portMAX_DELAY) != pdPASS)
7272
#define I2C_MUTEX_UNLOCK() xSemaphoreGive(i2c->lock)
7373

7474
static i2c_t _i2c_bus_array[2] = {
75-
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE_FIXED), NULL, 0,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0},
76-
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE_FIXED), NULL, 1,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0}
75+
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE_FIXED), NULL, 0,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0,0},
76+
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE_FIXED), NULL, 1,I2C_NONE,I2C_NONE,I2C_ERROR_OK,NULL,NULL,NULL,0,0,0,0}
7777
};
7878
#endif
7979

@@ -628,7 +628,17 @@ log_n("Enable Core Debug Level \"Error\"");
628628

629629
void i2cDumpI2c(i2c_t * i2c){
630630
log_e("i2c=%p",i2c);
631-
log_e("dev=%p date=%p",i2c->dev,i2c->dev->date);
631+
char levelText[8];
632+
switch(ARDUHAL_LOG_LEVEL){
633+
case 0 : levelText = sprintf("NONE"); break;
634+
case 1 : levelText = sprintf("ERROR"); break;
635+
case 2 : levelText = sprintf("WARN"); break;
636+
case 3 : levelText = sprintf("INFO"); break;
637+
case 4 : levelText = sprintf("DEBUG"); break;
638+
case 5 : levelText = sprintf("VERBOSE"); break;
639+
default : levelText = sprintf("uk=%d",ARDUHAL_LOG_LEVEL);
640+
}
641+
log_e("dev=%p date=%p level=%s",i2c->dev,i2c->dev->date,levelText);
632642
#if !CONFIG_DISABLE_HAL_LOCKS
633643
log_e("lock=%p",i2c->lock);
634644
#endif
@@ -820,12 +830,13 @@ static void IRAM_ATTR i2c_isr_handler_default(void* arg){
820830
i2c_t* p_i2c = (i2c_t*) arg; // recover data
821831
uint32_t activeInt = p_i2c->dev->int_status.val&0x1FFF;
822832

823-
portBASE_TYPE HPTaskAwoken = pdFALSE,xResult;
833+
portBASE_TYPE HPTaskAwoken = pdFALSE;
824834

825835
if(p_i2c->stage==I2C_DONE){ //get Out
826836
log_e("eject int=%p, ena=%p",activeInt,p_i2c->dev->int_ena.val);
827837
p_i2c->dev->int_ena.val = 0;
828838
p_i2c->dev->int_clr.val = activeInt; //0x1FFF;
839+
829840
return;
830841
}
831842
while (activeInt != 0) { // Ordering of 'if(activeInt)' statements is important, don't change
@@ -843,8 +854,7 @@ while (activeInt != 0) { // Ordering of 'if(activeInt)' statements is important,
843854
intBuff[intPos[p_i2c->num]][2][p_i2c->num] = xTaskGetTickCountFromISR(); // when IRQ fired
844855

845856
#endif
846-
uint32_t oldInt =activeInt;
847-
857+
848858
if (activeInt & I2C_TRANS_START_INT_ST_M) {
849859
// p_i2c->byteCnt=0;
850860
if(p_i2c->stage==I2C_STARTUP){
@@ -1017,6 +1027,7 @@ if(!i2c->i2c_event){
10171027
}
10181028
if(i2c->i2c_event) {
10191029
uint32_t ret=xEventGroupClearBits(i2c->i2c_event, 0xFF);
1030+
if(ret != ESP_OK) log_e("Unable to Clear Event Bits=%d",ret);
10201031
}
10211032
else {// failed to create EventGroup
10221033
log_e("eventCreate failed=%p",i2c->i2c_event);
@@ -1094,7 +1105,7 @@ i2c->dev->int_ena.val =
10941105

10951106
if(!i2c->intr_handle){ // create ISR for either peripheral
10961107
// log_i("create ISR %d",i2c->num);
1097-
uint32_t ret;
1108+
uint32_t ret=0xFFFFFFFF; // clear uninitialized var warning
10981109
switch(i2c->num){
10991110
case 0:
11001111
ret = esp_intr_alloc(ETS_I2C_EXT0_INTR_SOURCE, 0, &i2c_isr_handler_default, i2c, &i2c->intr_handle);
@@ -1153,7 +1164,7 @@ if(eBits&EVENT_DONE){ // no gross timeout
11531164
uint32_t expected =(totalBytes*10*1000)/i2cGetFrequency(i2c);
11541165
if((tAfter-tBefore)>(expected+1)) { //used some of the timeout Period
11551166
// expected can be zero due to small packets
1156-
log_e("TimeoutRecovery: expected=%ums, actual=%ums",expected,(tAfter-tBefore));
1167+
log_d("used TimeoutRecovery: expected=%ums, actual=%ums, configured=%ums ",expected,(tAfter-tBefore),timeOutMillis);
11571168
i2cDumpI2c(i2c);
11581169
i2cDumpInts(i2c->num);
11591170
}
@@ -1242,7 +1253,7 @@ void i2cReleaseISR(i2c_t * i2c){
12421253
if(i2c->intr_handle){
12431254
// log_i("Release ISR %d",i2c->num);
12441255
esp_err_t error =esp_intr_free(i2c->intr_handle);
1245-
// log_e("released ISR=%d",error);
1256+
if(error!=ESP_OK) log_e("Error releasing ISR=%d",error);
12461257
i2c->intr_handle=NULL;
12471258
}
12481259
}

0 commit comments

Comments
 (0)