@@ -64,16 +64,16 @@ enum {
64
64
#define I2C_MUTEX_UNLOCK ()
65
65
66
66
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 }
69
69
};
70
70
#else
71
71
#define I2C_MUTEX_LOCK () do {} while (xSemaphoreTake(i2c->lock, portMAX_DELAY) != pdPASS)
72
72
#define I2C_MUTEX_UNLOCK () xSemaphoreGive(i2c->lock)
73
73
74
74
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 }
77
77
};
78
78
#endif
79
79
@@ -628,7 +628,17 @@ log_n("Enable Core Debug Level \"Error\"");
628
628
629
629
void i2cDumpI2c (i2c_t * i2c ){
630
630
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 );
632
642
#if !CONFIG_DISABLE_HAL_LOCKS
633
643
log_e ("lock=%p" ,i2c -> lock );
634
644
#endif
@@ -820,12 +830,13 @@ static void IRAM_ATTR i2c_isr_handler_default(void* arg){
820
830
i2c_t * p_i2c = (i2c_t * ) arg ; // recover data
821
831
uint32_t activeInt = p_i2c -> dev -> int_status .val & 0x1FFF ;
822
832
823
- portBASE_TYPE HPTaskAwoken = pdFALSE , xResult ;
833
+ portBASE_TYPE HPTaskAwoken = pdFALSE ;
824
834
825
835
if (p_i2c -> stage == I2C_DONE ){ //get Out
826
836
log_e ("eject int=%p, ena=%p" ,activeInt ,p_i2c -> dev -> int_ena .val );
827
837
p_i2c -> dev -> int_ena .val = 0 ;
828
838
p_i2c -> dev -> int_clr .val = activeInt ; //0x1FFF;
839
+
829
840
return ;
830
841
}
831
842
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,
843
854
intBuff [intPos [p_i2c -> num ]][2 ][p_i2c -> num ] = xTaskGetTickCountFromISR (); // when IRQ fired
844
855
845
856
#endif
846
- uint32_t oldInt = activeInt ;
847
-
857
+
848
858
if (activeInt & I2C_TRANS_START_INT_ST_M ) {
849
859
// p_i2c->byteCnt=0;
850
860
if (p_i2c -> stage == I2C_STARTUP ){
@@ -1017,6 +1027,7 @@ if(!i2c->i2c_event){
1017
1027
}
1018
1028
if (i2c -> i2c_event ) {
1019
1029
uint32_t ret = xEventGroupClearBits (i2c -> i2c_event , 0xFF );
1030
+ if (ret != ESP_OK ) log_e ("Unable to Clear Event Bits=%d" ,ret );
1020
1031
}
1021
1032
else {// failed to create EventGroup
1022
1033
log_e ("eventCreate failed=%p" ,i2c -> i2c_event );
@@ -1094,7 +1105,7 @@ i2c->dev->int_ena.val =
1094
1105
1095
1106
if (!i2c -> intr_handle ){ // create ISR for either peripheral
1096
1107
// log_i("create ISR %d",i2c->num);
1097
- uint32_t ret ;
1108
+ uint32_t ret = 0xFFFFFFFF ; // clear uninitialized var warning
1098
1109
switch (i2c -> num ){
1099
1110
case 0 :
1100
1111
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
1153
1164
uint32_t expected = (totalBytes * 10 * 1000 )/i2cGetFrequency (i2c );
1154
1165
if ((tAfter - tBefore )> (expected + 1 )) { //used some of the timeout Period
1155
1166
// 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 );
1157
1168
i2cDumpI2c (i2c );
1158
1169
i2cDumpInts (i2c -> num );
1159
1170
}
@@ -1242,7 +1253,7 @@ void i2cReleaseISR(i2c_t * i2c){
1242
1253
if (i2c -> intr_handle ){
1243
1254
// log_i("Release ISR %d",i2c->num);
1244
1255
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 );
1246
1257
i2c -> intr_handle = NULL ;
1247
1258
}
1248
1259
}
0 commit comments