@@ -337,6 +337,7 @@ void i2cInitFix(i2c_t * i2c){
337
337
return ;
338
338
}
339
339
I2C_MUTEX_LOCK ();
340
+ i2c -> dev -> ctr .trans_start = 0 ;
340
341
i2cResetFiFo (i2c );
341
342
i2c -> dev -> int_clr .val = 0xFFFFFFFF ;
342
343
i2cSetCmd (i2c , 0 , I2C_CMD_RSTART , 0 , false, false, false);
@@ -347,7 +348,6 @@ void i2cInitFix(i2c_t * i2c){
347
348
{
348
349
log_e ("Busy at initialization!" );
349
350
}
350
- i2c -> dev -> ctr .trans_start = 1 ;
351
351
uint16_t count = 50000 ;
352
352
while ((!i2c -> dev -> command [2 ].done ) && (-- count > 0 ));
353
353
I2C_MUTEX_UNLOCK ();
@@ -365,12 +365,20 @@ void i2cReset(i2c_t* i2c){
365
365
I2C_MUTEX_UNLOCK ();
366
366
}
367
367
368
+ //** 11/2017 Stickbreaker attempt at ISR for I2C hardware
369
+ // liberally stolen from ESP_IDF /drivers/i2c.c
370
+ esp_err_t i2c_isr_free (intr_handle_t handle ){
371
+
372
+ return esp_intr_free (handle );
373
+ }
374
+
368
375
/* Stickbreaker ISR mode debug support
369
376
*/
377
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
370
378
#define INTBUFFMAX 64
371
379
static uint32_t intBuff [INTBUFFMAX ][3 ];
372
380
static uint32_t intPos = 0 ;
373
-
381
+ #endif
374
382
/* Stickbreaker ISR mode support
375
383
*/
376
384
static void IRAM_ATTR fillCmdQueue (i2c_t * i2c , bool INTS ){
@@ -546,7 +554,40 @@ if(INTS){ // don't want to prematurely enable fifo ints until ISR is ready to ha
546
554
547
555
/* Stickbreaker ISR mode debug support
548
556
*/
549
- static void IRAM_ATTR dumpI2c (i2c_t * i2c ){
557
+ void i2cDumpDqData (i2c_t * i2c ){
558
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
559
+ uint16_t a = 0 ;
560
+ char buff [140 ];
561
+ I2C_DATA_QUEUE_t * tdq ;
562
+ while (a < i2c -> queueCount ){
563
+ tdq = & i2c -> dq [a ];
564
+ log_e ("[%d] %x %c %s buf@=%p, len=%d, pos=%d, eventH=%p bits=%x" ,a ,tdq -> ctrl .addr ,(tdq -> ctrl .mode )?'R' :'W' ,(tdq -> ctrl .stop )?"STOP" :"" ,tdq -> data ,tdq -> length ,tdq -> position ,tdq -> queueEvent ,(tdq -> queueEvent )?xEventGroupGetBits (tdq -> queueEvent ):0 );
565
+ uint16_t offset = 0 ;
566
+ while (offset < tdq -> length ){
567
+ memset (buff ,' ' ,140 );
568
+ buff [139 ]= '\0' ;
569
+ uint16_t i = 0 ,j ;
570
+ j = sprintf (buff ,"0x%04x: " ,offset );
571
+ while ((i < 32 )&& (offset < tdq -> length )){
572
+ char ch = tdq -> data [offset ];
573
+ sprintf ((char * )& buff [(i * 3 )+ 41 ],"%02x " ,ch );
574
+ if ((ch < 32 )|| (ch > 126 )) ch = '.' ;
575
+ j += sprintf ((char * )& buff [j ],"%c" ,ch );
576
+ buff [j ]= ' ' ;
577
+ i ++ ;
578
+ offset ++ ;
579
+ }
580
+ log_e ("%s" ,buff );
581
+ }
582
+ a ++ ;
583
+ }
584
+ #else
585
+ log_n ("Enable Core Debug Level \"Error\"" );
586
+ #endif
587
+ }
588
+
589
+
590
+ void i2cDumpI2c (i2c_t * i2c ){
550
591
log_e ("i2c=%p" ,i2c );
551
592
log_e ("dev=%p" ,i2c -> dev );
552
593
log_e ("lock=%p" ,i2c -> lock );
@@ -560,13 +601,7 @@ log_e("dq=%p",i2c->dq);
560
601
log_e ("queueCount=%d" ,i2c -> queueCount );
561
602
log_e ("queuePos=%d" ,i2c -> queuePos );
562
603
log_e ("byteCnt=%d" ,i2c -> byteCnt );
563
- uint16_t a = 0 ;
564
- I2C_DATA_QUEUE_t * tdq ;
565
- while (a < i2c -> queueCount ){
566
- tdq = & i2c -> dq [a ];
567
- log_e ("[%d] %x %c %s buf@=%p, len=%d, pos=%d, eventH=%p bits=%x" ,a ,tdq -> ctrl .addr ,(tdq -> ctrl .mode )?'R' :'W' ,(tdq -> ctrl .stop )?"STOP" :"" ,tdq -> data ,tdq -> length ,tdq -> position ,tdq -> queueEvent ,(tdq -> queueEvent )?xEventGroupGetBits (tdq -> queueEvent ):0 );
568
- a ++ ;
569
- }
604
+ if (i2c -> dq ) i2cDumpDqData (i2c );
570
605
}
571
606
572
607
/* Stickbreaker ISR mode debug support
@@ -657,9 +692,12 @@ while((a < i2c->queueCount)&&!(full || readEncountered)){
657
692
658
693
if (full ) readEncountered = false; //tx possibly needs more
659
694
695
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
696
+
660
697
// update debug buffer tx counts
661
698
cnt += intBuff [intPos ][1 ]>>16 ;
662
699
intBuff [intPos ][1 ] = (intBuff [intPos ][1 ]& 0xFFFF )|(cnt <<16 );
700
+ #endif
663
701
664
702
if (!(full || readEncountered )) a ++ ; // check next buffer for tx
665
703
}
@@ -698,9 +736,11 @@ if(tdq->ctrl.mode==1) { // read
698
736
moveCnt = (tdq -> length - tdq -> position );
699
737
}
700
738
}
739
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
701
740
// update Debug rxCount
702
741
cnt += (intBuff [intPos ][1 ])&& 0xffFF ;
703
742
intBuff [intPos ][1 ] = (intBuff [intPos ][1 ]& 0xFFFF0000 )|cnt ;
743
+ #endif
704
744
}
705
745
else {
706
746
log_e ("RxEmpty(%d) call on TxBuffer? dq=%d" ,moveCnt ,i2c -> queuePos );
@@ -766,11 +806,12 @@ if(p_i2c->stage==I2C_DONE){ //get Out
766
806
log_e ("eject int=%p, ena=%p" ,activeInt ,p_i2c -> dev -> int_ena .val );
767
807
p_i2c -> dev -> int_ena .val = 0 ;
768
808
p_i2c -> dev -> int_clr .val = activeInt ; //0x1FFF;
769
- dumpI2c (p_i2c );
770
- i2cDumpInts ();
809
+ // i2cDumpI2c (p_i2c);
810
+ // i2cDumpInts();
771
811
return ;
772
812
}
773
813
while (activeInt != 0 ) { // Ordering of 'if(activeInt)' statements is important, don't change
814
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
774
815
if (activeInt == (intBuff [intPos ][0 ]& 0x1fff )){
775
816
intBuff [intPos ][0 ] = (((intBuff [intPos ][0 ]>>16 )+ 1 )<<16 )|activeInt ;
776
817
}
@@ -782,7 +823,7 @@ while (activeInt != 0) { // Ordering of 'if(activeInt)' statements is important,
782
823
}
783
824
784
825
intBuff [intPos ][2 ] = xTaskGetTickCountFromISR (); // when IRQ fired
785
-
826
+ #endif
786
827
uint32_t oldInt = activeInt ;
787
828
788
829
if (activeInt & I2C_TRANS_START_INT_ST_M ) {
@@ -891,12 +932,16 @@ while (activeInt != 0) { // Ordering of 'if(activeInt)' statements is important,
891
932
}
892
933
893
934
void i2cDumpInts (){
935
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
894
936
uint32_t b ;
895
937
log_e ("row count INTR TX RX" );
896
938
for (uint32_t a = 1 ;a <=INTBUFFMAX ;a ++ ){
897
939
b = (a + intPos )%INTBUFFMAX ;
898
940
if (intBuff [b ][0 ]!= 0 ) log_e ("[%02d] 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x" ,b ,((intBuff [b ][0 ]>>16 )& 0xFFFF ),(intBuff [b ][0 ]& 0xFFFF ),((intBuff [b ][1 ]>>16 )& 0xFFFF ),(intBuff [b ][1 ]& 0xFFFF ),intBuff [b ][2 ]);
899
941
}
942
+ #else
943
+ log_n ("enable Core Debug Level \"Error\"" );
944
+ #endif
900
945
}
901
946
902
947
i2c_err_t i2cProcQueue (i2c_t * i2c , uint32_t * readCount , uint16_t timeOutMillis ){
@@ -920,11 +965,10 @@ I2C_MUTEX_LOCK();
920
965
*/
921
966
i2c -> stage = I2C_DONE ; // until ready
922
967
923
- for (intPos = 0 ;intPos < INTBUFFMAX ;intPos ++ ){
924
- intBuff [intPos ][0 ]= 0 ;
925
- intBuff [intPos ][1 ]= 0 ;
926
- }
968
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
969
+ memset (intBuff ,0 ,sizeof (intBuff ));
927
970
intPos = 0 ;
971
+ #endif
928
972
929
973
if (!i2c -> i2c_event ){
930
974
i2c -> i2c_event = xEventGroupCreate ();
@@ -1046,7 +1090,7 @@ if(i2c->exitCode!=eBits){ // try to recover from O/S failure
1046
1090
}
1047
1091
1048
1092
if (!(eBits == EVENT_DONE )&& (eBits & ~(EVENT_ERROR_NAK |EVENT_ERROR_DATA_NAK |EVENT_ERROR |EVENT_DONE ))){ // not only Done, therefore error, exclude ADDR NAK, DATA_NAK
1049
- dumpI2c (i2c );
1093
+ i2cDumpI2c (i2c );
1050
1094
i2cDumpInts ();
1051
1095
}
1052
1096
@@ -1081,7 +1125,7 @@ else { // GROSS timeout, shutdown ISR , report Timeout
1081
1125
reason = I2C_ERROR_TIMEOUT ;
1082
1126
eBits = eBits | EVENT_ERROR_TIMEOUT |EVENT_ERROR |EVENT_DONE ;
1083
1127
log_e (" Gross Timeout Dead st=0x%x, ed=0x%x, =%d, max=%d error=%d" ,tBefore ,tAfter ,(tAfter - tBefore ),ticksTimeOut ,i2c -> error );
1084
- dumpI2c (i2c );
1128
+ i2cDumpI2c (i2c );
1085
1129
i2cDumpInts ();
1086
1130
}
1087
1131
@@ -1119,8 +1163,8 @@ return reason;
1119
1163
1120
1164
i2c_err_t i2cReleaseISR (i2c_t * i2c ){
1121
1165
if (i2c -> intr_handle ){
1122
- esp_err_t error = esp_intr_free (i2c -> intr_handle );
1123
- // log_e("released ISR=%d",error);
1166
+ esp_err_t error = i2c_isr_free (i2c -> intr_handle );
1167
+ // log_e("released ISR=%d",error);
1124
1168
i2c -> intr_handle = NULL ;
1125
1169
}
1126
1170
if (i2c -> i2c_event ){
0 commit comments